Render constraint lists dynamically
This commit is contained in:
parent
cc126fc527
commit
ce9b114dd6
@ -12,7 +12,7 @@ fn load_gen_assemb(assembly: &Assembly) {
|
|||||||
label: String::from("Castor"),
|
label: String::from("Castor"),
|
||||||
color: [1.00_f32, 0.25_f32, 0.00_f32],
|
color: [1.00_f32, 0.25_f32, 0.00_f32],
|
||||||
representation: engine::sphere(0.5, 0.5, 0.0, 1.0),
|
representation: engine::sphere(0.5, 0.5, 0.0, 1.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -22,7 +22,7 @@ fn load_gen_assemb(assembly: &Assembly) {
|
|||||||
label: String::from("Pollux"),
|
label: String::from("Pollux"),
|
||||||
color: [0.00_f32, 0.25_f32, 1.00_f32],
|
color: [0.00_f32, 0.25_f32, 1.00_f32],
|
||||||
representation: engine::sphere(-0.5, -0.5, 0.0, 1.0),
|
representation: engine::sphere(-0.5, -0.5, 0.0, 1.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -32,7 +32,7 @@ fn load_gen_assemb(assembly: &Assembly) {
|
|||||||
label: String::from("Ursa major"),
|
label: String::from("Ursa major"),
|
||||||
color: [0.25_f32, 0.00_f32, 1.00_f32],
|
color: [0.25_f32, 0.00_f32, 1.00_f32],
|
||||||
representation: engine::sphere(-0.5, 0.5, 0.0, 0.75),
|
representation: engine::sphere(-0.5, 0.5, 0.0, 0.75),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -42,7 +42,7 @@ fn load_gen_assemb(assembly: &Assembly) {
|
|||||||
label: String::from("Ursa minor"),
|
label: String::from("Ursa minor"),
|
||||||
color: [0.25_f32, 1.00_f32, 0.00_f32],
|
color: [0.25_f32, 1.00_f32, 0.00_f32],
|
||||||
representation: engine::sphere(0.5, -0.5, 0.0, 0.5),
|
representation: engine::sphere(0.5, -0.5, 0.0, 0.5),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -52,7 +52,7 @@ fn load_gen_assemb(assembly: &Assembly) {
|
|||||||
label: String::from("Deimos"),
|
label: String::from("Deimos"),
|
||||||
color: [0.75_f32, 0.75_f32, 0.00_f32],
|
color: [0.75_f32, 0.75_f32, 0.00_f32],
|
||||||
representation: engine::sphere(0.0, 0.15, 1.0, 0.25),
|
representation: engine::sphere(0.0, 0.15, 1.0, 0.25),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -62,7 +62,7 @@ fn load_gen_assemb(assembly: &Assembly) {
|
|||||||
label: String::from("Phobos"),
|
label: String::from("Phobos"),
|
||||||
color: [0.00_f32, 0.75_f32, 0.50_f32],
|
color: [0.00_f32, 0.75_f32, 0.50_f32],
|
||||||
representation: engine::sphere(0.0, -0.15, -1.0, 0.25),
|
representation: engine::sphere(0.0, -0.15, -1.0, 0.25),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -77,7 +77,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: "Central".to_string(),
|
label: "Central".to_string(),
|
||||||
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
||||||
representation: engine::sphere(0.0, 0.0, 0.0, 1.0),
|
representation: engine::sphere(0.0, 0.0, 0.0, 1.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -87,7 +87,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: "Assembly plane".to_string(),
|
label: "Assembly plane".to_string(),
|
||||||
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
||||||
representation: engine::sphere_with_offset(0.0, 0.0, 1.0, 0.0, 0.0),
|
representation: engine::sphere_with_offset(0.0, 0.0, 1.0, 0.0, 0.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -97,7 +97,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: "Side 1".to_string(),
|
label: "Side 1".to_string(),
|
||||||
color: [1.00_f32, 0.00_f32, 0.25_f32],
|
color: [1.00_f32, 0.00_f32, 0.25_f32],
|
||||||
representation: engine::sphere_with_offset(1.0, 0.0, 0.0, 1.0, 0.0),
|
representation: engine::sphere_with_offset(1.0, 0.0, 0.0, 1.0, 0.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -107,7 +107,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: "Side 2".to_string(),
|
label: "Side 2".to_string(),
|
||||||
color: [0.25_f32, 1.00_f32, 0.00_f32],
|
color: [0.25_f32, 1.00_f32, 0.00_f32],
|
||||||
representation: engine::sphere_with_offset(-0.5, a, 0.0, 1.0, 0.0),
|
representation: engine::sphere_with_offset(-0.5, a, 0.0, 1.0, 0.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -117,7 +117,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: "Side 3".to_string(),
|
label: "Side 3".to_string(),
|
||||||
color: [0.00_f32, 0.25_f32, 1.00_f32],
|
color: [0.00_f32, 0.25_f32, 1.00_f32],
|
||||||
representation: engine::sphere_with_offset(-0.5, -a, 0.0, 1.0, 0.0),
|
representation: engine::sphere_with_offset(-0.5, -a, 0.0, 1.0, 0.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -127,7 +127,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: "Corner 1".to_string(),
|
label: "Corner 1".to_string(),
|
||||||
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
||||||
representation: engine::sphere(-4.0/3.0, 0.0, 0.0, 1.0/3.0),
|
representation: engine::sphere(-4.0/3.0, 0.0, 0.0, 1.0/3.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -137,7 +137,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: "Corner 2".to_string(),
|
label: "Corner 2".to_string(),
|
||||||
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
||||||
representation: engine::sphere(2.0/3.0, -4.0/3.0 * a, 0.0, 1.0/3.0),
|
representation: engine::sphere(2.0/3.0, -4.0/3.0 * a, 0.0, 1.0/3.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -147,7 +147,7 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||||||
label: String::from("Corner 3"),
|
label: String::from("Corner 3"),
|
||||||
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
||||||
representation: engine::sphere(2.0/3.0, 4.0/3.0 * a, 0.0, 1.0/3.0),
|
representation: engine::sphere(2.0/3.0, 4.0/3.0 * a, 0.0, 1.0/3.0),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -19,7 +19,7 @@ pub struct Element {
|
|||||||
pub label: String,
|
pub label: String,
|
||||||
pub color: ElementColor,
|
pub color: ElementColor,
|
||||||
pub representation: DVector<f64>,
|
pub representation: DVector<f64>,
|
||||||
pub constraints: BTreeSet<ConstraintKey>,
|
pub constraints: Signal<BTreeSet<ConstraintKey>>,
|
||||||
|
|
||||||
// the configuration matrix column index that was assigned to this element
|
// the configuration matrix column index that was assigned to this element
|
||||||
// last time the assembly was realized
|
// last time the assembly was realized
|
||||||
@ -97,7 +97,7 @@ impl Assembly {
|
|||||||
label: format!("Sphere {}", id_num),
|
label: format!("Sphere {}", id_num),
|
||||||
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
||||||
representation: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.5, -0.5]),
|
representation: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.5, -0.5]),
|
||||||
constraints: BTreeSet::default(),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
index: 0
|
index: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -106,10 +106,11 @@ impl Assembly {
|
|||||||
pub fn insert_constraint(&self, constraint: Constraint) {
|
pub fn insert_constraint(&self, constraint: Constraint) {
|
||||||
let subjects = constraint.subjects;
|
let subjects = constraint.subjects;
|
||||||
let key = self.constraints.update(|csts| csts.insert(constraint));
|
let key = self.constraints.update(|csts| csts.insert(constraint));
|
||||||
self.elements.update(|elts| {
|
let subject_constraints = self.elements.with(
|
||||||
elts[subjects.0].constraints.insert(key);
|
|elts| (elts[subjects.0].constraints, elts[subjects.1].constraints)
|
||||||
elts[subjects.1].constraints.insert(key);
|
);
|
||||||
});
|
subject_constraints.0.update(|csts| csts.insert(key));
|
||||||
|
subject_constraints.1.update(|csts| csts.insert(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- realization ---
|
// --- realization ---
|
||||||
|
@ -76,7 +76,10 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
|||||||
let u_coord = format!("{:.3}", u).replace("-", "\u{2212}");
|
let u_coord = format!("{:.3}", u).replace("-", "\u{2212}");
|
||||||
View::from(div().children(u_coord))
|
View::from(div().children(u_coord))
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<_>>();
|
||||||
let constrained = element.constraints.len() > 0;
|
let constrained = element.constraints.map(|csts| csts.len() > 0);
|
||||||
|
let constraint_list = element.constraints.map(
|
||||||
|
|csts| csts.clone().into_iter().collect()
|
||||||
|
);
|
||||||
let details_node = create_node_ref();
|
let details_node = create_node_ref();
|
||||||
view! {
|
view! {
|
||||||
li {
|
li {
|
||||||
@ -101,7 +104,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
|||||||
}
|
}
|
||||||
event.prevent_default();
|
event.prevent_default();
|
||||||
},
|
},
|
||||||
"ArrowRight" if constrained => {
|
"ArrowRight" if constrained.get() => {
|
||||||
let _ = details_node
|
let _ = details_node
|
||||||
.get()
|
.get()
|
||||||
.unchecked_into::<web_sys::Element>()
|
.unchecked_into::<web_sys::Element>()
|
||||||
@ -150,7 +153,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
|||||||
}
|
}
|
||||||
ul(class="constraints") {
|
ul(class="constraints") {
|
||||||
Keyed(
|
Keyed(
|
||||||
list=element.constraints.into_iter().collect::<Vec<_>>(),
|
list=constraint_list,
|
||||||
view=move |cst_key| view! {
|
view=move |cst_key| view! {
|
||||||
ConstraintOutlineItem(
|
ConstraintOutlineItem(
|
||||||
constraint_key=cst_key,
|
constraint_key=cst_key,
|
||||||
@ -200,8 +203,7 @@ pub fn Outline() -> View {
|
|||||||
key.clone(),
|
key.clone(),
|
||||||
elt.id.clone(),
|
elt.id.clone(),
|
||||||
elt.label.clone(),
|
elt.label.clone(),
|
||||||
elt.rep.into_iter().map(|u| u.to_bits()).collect::<Vec<_>>(),
|
elt.representation.into_iter().map(|u| u.to_bits()).collect::<Vec<_>>()
|
||||||
elt.constraints.clone()
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user