forked from glen/dyna3
Compare commits
No commits in common. "regulators-always-valid" and "main" have entirely different histories.
regulators
...
main
4 changed files with 124 additions and 222 deletions
|
@ -3,8 +3,7 @@
|
||||||
--text-bright: white;
|
--text-bright: white;
|
||||||
--text-invalid: #f58fc2; /* bright pink */
|
--text-invalid: #f58fc2; /* bright pink */
|
||||||
--border: #555; /* light gray */
|
--border: #555; /* light gray */
|
||||||
--border-focus-dark: #aaa; /* bright gray */
|
--border-focus: #aaa; /* bright gray */
|
||||||
--border-focus-light: white;
|
|
||||||
--border-invalid: #70495c; /* dusky pink */
|
--border-invalid: #70495c; /* dusky pink */
|
||||||
--selection-highlight: #444; /* medium gray */
|
--selection-highlight: #444; /* medium gray */
|
||||||
--page-background: #222; /* dark gray */
|
--page-background: #222; /* dark gray */
|
||||||
|
@ -24,7 +23,7 @@ body {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
float: left;
|
float: left;
|
||||||
width: 500px;
|
width: 450px;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
|
@ -78,12 +77,12 @@ summary.selected {
|
||||||
background-color: var(--selection-highlight);
|
background-color: var(--selection-highlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
summary > div, .regulator {
|
summary > div, .constraint {
|
||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
padding-bottom: 4px;
|
padding-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.element, .regulator {
|
.element, .constraint {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
|
@ -108,7 +107,7 @@ details[open]:has(li) .element-switch::after {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.regulator-label {
|
.constraint-label {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,34 +123,26 @@ details[open]:has(li) .element-switch::after {
|
||||||
width: 56px;
|
width: 56px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.regulator {
|
.constraint {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.regulator-type {
|
.constraint.invalid {
|
||||||
padding: 2px 8px 0px 8px;
|
color: var(--text-invalid);
|
||||||
font-size: 10pt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.regulator-input {
|
.constraint > input[type=checkbox] {
|
||||||
|
margin: 0px 8px 0px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.constraint > input[type=text] {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
background-color: inherit;
|
background-color: inherit;
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.regulator-input::placeholder {
|
.constraint.invalid > input[type=text] {
|
||||||
color: inherit;
|
|
||||||
opacity: 54%;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.regulator-input.constraint {
|
|
||||||
background-color: var(--display-background);
|
|
||||||
}
|
|
||||||
|
|
||||||
.regulator-input.invalid {
|
|
||||||
color: var(--text-invalid);
|
|
||||||
border-color: var(--border-invalid);
|
border-color: var(--border-invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +154,7 @@ details[open]:has(li) .element-switch::after {
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
.regulator-input.invalid + .status::after, details:has(.invalid):not([open]) .status::after {
|
.invalid > .status::after, details:has(.invalid):not([open]) .status::after {
|
||||||
content: '⚠';
|
content: '⚠';
|
||||||
color: var(--text-invalid);
|
color: var(--text-invalid);
|
||||||
}
|
}
|
||||||
|
@ -180,11 +171,5 @@ canvas {
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas:focus {
|
canvas:focus {
|
||||||
border-color: var(--border-focus-dark);
|
border-color: var(--border-focus);
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
input:focus {
|
|
||||||
border-color: var(--border-focus-light);
|
|
||||||
outline: none;
|
|
||||||
}
|
}
|
|
@ -1,14 +1,7 @@
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use web_sys::{console, wasm_bindgen::JsValue};
|
use web_sys::{console, wasm_bindgen::JsValue};
|
||||||
|
|
||||||
use crate::{
|
use crate::{engine, AppState, assembly::{Assembly, Constraint, Element}};
|
||||||
engine,
|
|
||||||
AppState,
|
|
||||||
assembly::{
|
|
||||||
Assembly,
|
|
||||||
Element
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* DEBUG */
|
/* DEBUG */
|
||||||
// load an example assembly for testing. this code will be removed once we've
|
// load an example assembly for testing. this code will be removed once we've
|
||||||
|
@ -197,8 +190,44 @@ pub fn AddRemove() -> View {
|
||||||
(subject_vec[0].clone(), subject_vec[1].clone())
|
(subject_vec[0].clone(), subject_vec[1].clone())
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
state.assembly.insert_new_regulator(subjects);
|
let lorentz_prod = create_signal(0.0);
|
||||||
|
let lorentz_prod_valid = create_signal(false);
|
||||||
|
let active = create_signal(true);
|
||||||
|
state.assembly.insert_constraint(Constraint {
|
||||||
|
subjects: subjects,
|
||||||
|
lorentz_prod: lorentz_prod,
|
||||||
|
lorentz_prod_text: create_signal(String::new()),
|
||||||
|
lorentz_prod_valid: lorentz_prod_valid,
|
||||||
|
active: active,
|
||||||
|
});
|
||||||
state.selection.update(|sel| sel.clear());
|
state.selection.update(|sel| sel.clear());
|
||||||
|
|
||||||
|
/* DEBUG */
|
||||||
|
// print updated constraint list
|
||||||
|
console::log_1(&JsValue::from("Constraints:"));
|
||||||
|
state.assembly.constraints.with(|csts| {
|
||||||
|
for (_, cst) in csts.into_iter() {
|
||||||
|
console::log_5(
|
||||||
|
&JsValue::from(" "),
|
||||||
|
&JsValue::from(cst.subjects.0),
|
||||||
|
&JsValue::from(cst.subjects.1),
|
||||||
|
&JsValue::from(":"),
|
||||||
|
&JsValue::from(cst.lorentz_prod.get_untracked())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// update the realization when the constraint becomes active
|
||||||
|
// and valid, or is edited while active and valid
|
||||||
|
create_effect(move || {
|
||||||
|
console::log_1(&JsValue::from(
|
||||||
|
format!("Constraint ({}, {}) updated", subjects.0, subjects.1)
|
||||||
|
));
|
||||||
|
lorentz_prod.track();
|
||||||
|
if active.get() && lorentz_prod_valid.get() {
|
||||||
|
state.assembly.realize();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
) { "🔗" }
|
) { "🔗" }
|
||||||
select(bind:value=assembly_name) { /* DEBUG */ // example assembly chooser
|
select(bind:value=assembly_name) { /* DEBUG */ // example assembly chooser
|
||||||
|
|
|
@ -5,11 +5,11 @@ use std::{collections::BTreeSet, sync::atomic::{AtomicU64, Ordering}};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
||||||
|
|
||||||
use crate::engine::{Q, local_unif_to_std, realize_gram, ConfigSubspace, PartialMatrix};
|
use crate::engine::{realize_gram, local_unif_to_std, ConfigSubspace, PartialMatrix};
|
||||||
|
|
||||||
// the types of the keys we use to access an assembly's elements and regulators
|
// the types of the keys we use to access an assembly's elements and constraints
|
||||||
pub type ElementKey = usize;
|
pub type ElementKey = usize;
|
||||||
pub type RegulatorKey = usize;
|
pub type ConstraintKey = usize;
|
||||||
|
|
||||||
pub type ElementColor = [f32; 3];
|
pub type ElementColor = [f32; 3];
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ pub struct Element {
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub color: ElementColor,
|
pub color: ElementColor,
|
||||||
pub representation: Signal<DVector<f64>>,
|
pub representation: Signal<DVector<f64>>,
|
||||||
pub regulators: Signal<BTreeSet<RegulatorKey>>,
|
pub constraints: Signal<BTreeSet<ConstraintKey>>,
|
||||||
|
|
||||||
// a serial number, assigned by `Element::new`, that uniquely identifies
|
// a serial number, assigned by `Element::new`, that uniquely identifies
|
||||||
// each element
|
// each element
|
||||||
|
@ -61,7 +61,7 @@ impl Element {
|
||||||
label: label,
|
label: label,
|
||||||
color: color,
|
color: color,
|
||||||
representation: create_signal(representation),
|
representation: create_signal(representation),
|
||||||
regulators: create_signal(BTreeSet::default()),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
serial: serial,
|
serial: serial,
|
||||||
column_index: None
|
column_index: None
|
||||||
}
|
}
|
||||||
|
@ -111,43 +111,13 @@ impl Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `set_point_spec` is always a valid specification of `set_point`
|
#[derive(Clone)]
|
||||||
// ┌────────────┬─────────────────────────────────────────────────────┐
|
pub struct Constraint {
|
||||||
// │`set_point` │ `set_point_spec` │
|
|
||||||
// ┝━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┥
|
|
||||||
// │`Some(x)` │ a string that parses to the floating-point value `x`│
|
|
||||||
// ├────────────┼─────────────────────────────────────────────────────┤
|
|
||||||
// │`None` │ the empty string │
|
|
||||||
// └────────────┴─────────────────────────────────────────────────────┘
|
|
||||||
#[derive(Clone, Copy)]
|
|
||||||
pub struct Regulator {
|
|
||||||
pub subjects: (ElementKey, ElementKey),
|
pub subjects: (ElementKey, ElementKey),
|
||||||
pub measurement: ReadSignal<f64>,
|
pub lorentz_prod: Signal<f64>,
|
||||||
pub set_point: ReadSignal<Option<f64>>,
|
pub lorentz_prod_text: Signal<String>,
|
||||||
|
pub lorentz_prod_valid: Signal<bool>,
|
||||||
set_point_writable: Signal<Option<f64>>,
|
pub active: Signal<bool>
|
||||||
set_point_spec: Signal<String>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Regulator {
|
|
||||||
pub fn get_set_point_spec_clone(&self) -> String {
|
|
||||||
self.set_point_spec.get_clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_set_point_spec_clone_untracked(&self) -> String {
|
|
||||||
self.set_point_spec.get_clone_untracked()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn try_specify_set_point(&self, spec: String) -> bool {
|
|
||||||
match spec.parse::<f64>() {
|
|
||||||
Err(_) if !spec.is_empty() => false,
|
|
||||||
set_pt => {
|
|
||||||
self.set_point_writable.set(set_pt.ok());
|
|
||||||
self.set_point_spec.set(spec);
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the velocity is expressed in uniform coordinates
|
// the velocity is expressed in uniform coordinates
|
||||||
|
@ -161,9 +131,9 @@ type AssemblyMotion<'a> = Vec<ElementMotion<'a>>;
|
||||||
// a complete, view-independent description of an assembly
|
// a complete, view-independent description of an assembly
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Assembly {
|
pub struct Assembly {
|
||||||
// elements and regulators
|
// elements and constraints
|
||||||
pub elements: Signal<Slab<Element>>,
|
pub elements: Signal<Slab<Element>>,
|
||||||
pub regulators: Signal<Slab<Regulator>>,
|
pub constraints: Signal<Slab<Constraint>>,
|
||||||
|
|
||||||
// solution variety tangent space. the basis vectors are stored in
|
// solution variety tangent space. the basis vectors are stored in
|
||||||
// configuration matrix format, ordered according to the elements' column
|
// configuration matrix format, ordered according to the elements' column
|
||||||
|
@ -185,13 +155,13 @@ impl Assembly {
|
||||||
pub fn new() -> Assembly {
|
pub fn new() -> Assembly {
|
||||||
Assembly {
|
Assembly {
|
||||||
elements: create_signal(Slab::new()),
|
elements: create_signal(Slab::new()),
|
||||||
regulators: create_signal(Slab::new()),
|
constraints: create_signal(Slab::new()),
|
||||||
tangent: create_signal(ConfigSubspace::zero(0)),
|
tangent: create_signal(ConfigSubspace::zero(0)),
|
||||||
elements_by_id: create_signal(FxHashMap::default())
|
elements_by_id: create_signal(FxHashMap::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- inserting elements and regulators ---
|
// --- inserting elements and constraints ---
|
||||||
|
|
||||||
// insert an element into the assembly without checking whether we already
|
// insert an element into the assembly without checking whether we already
|
||||||
// have an element with the same identifier. any element that does have the
|
// have an element with the same identifier. any element that does have the
|
||||||
|
@ -234,62 +204,14 @@ impl Assembly {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_regulator(&self, regulator: Regulator) {
|
pub fn insert_constraint(&self, constraint: Constraint) {
|
||||||
let subjects = regulator.subjects;
|
let subjects = constraint.subjects;
|
||||||
let key = self.regulators.update(|regs| regs.insert(regulator));
|
let key = self.constraints.update(|csts| csts.insert(constraint));
|
||||||
let subject_regulators = self.elements.with(
|
let subject_constraints = self.elements.with(
|
||||||
|elts| (elts[subjects.0].regulators, elts[subjects.1].regulators)
|
|elts| (elts[subjects.0].constraints, elts[subjects.1].constraints)
|
||||||
);
|
);
|
||||||
subject_regulators.0.update(|regs| regs.insert(key));
|
subject_constraints.0.update(|csts| csts.insert(key));
|
||||||
subject_regulators.1.update(|regs| regs.insert(key));
|
subject_constraints.1.update(|csts| csts.insert(key));
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert_new_regulator(self, subjects: (ElementKey, ElementKey)) {
|
|
||||||
// create and insert a new regulator
|
|
||||||
let measurement = self.elements.map(
|
|
||||||
move |elts| {
|
|
||||||
let reps = (
|
|
||||||
elts[subjects.0].representation.get_clone(),
|
|
||||||
elts[subjects.1].representation.get_clone()
|
|
||||||
);
|
|
||||||
reps.0.dot(&(&*Q * reps.1))
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let set_point_writable = create_signal(None);
|
|
||||||
let set_point = *set_point_writable;
|
|
||||||
self.insert_regulator(Regulator {
|
|
||||||
subjects: subjects,
|
|
||||||
measurement: measurement,
|
|
||||||
set_point: set_point,
|
|
||||||
set_point_writable: set_point_writable,
|
|
||||||
set_point_spec: create_signal(String::new())
|
|
||||||
});
|
|
||||||
|
|
||||||
/* DEBUG */
|
|
||||||
// print updated regulator list
|
|
||||||
console::log_1(&JsValue::from("Regulators:"));
|
|
||||||
self.regulators.with(|regs| {
|
|
||||||
for (_, reg) in regs.into_iter() {
|
|
||||||
console::log_5(
|
|
||||||
&JsValue::from(" "),
|
|
||||||
&JsValue::from(reg.subjects.0),
|
|
||||||
&JsValue::from(reg.subjects.1),
|
|
||||||
&JsValue::from(":"),
|
|
||||||
&JsValue::from(reg.set_point.get_untracked())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// update the realization when the regulator becomes a constraint, or is
|
|
||||||
// edited while acting as a constraint
|
|
||||||
create_effect(move || {
|
|
||||||
console::log_1(&JsValue::from(
|
|
||||||
format!("Updated constraint with subjects ({}, {})", subjects.0, subjects.1)
|
|
||||||
));
|
|
||||||
if set_point.with(|set_pt| set_pt.is_some()) {
|
|
||||||
self.realize();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- realization ---
|
// --- realization ---
|
||||||
|
@ -306,16 +228,13 @@ impl Assembly {
|
||||||
let (gram, guess) = self.elements.with_untracked(|elts| {
|
let (gram, guess) = self.elements.with_untracked(|elts| {
|
||||||
// set up the off-diagonal part of the Gram matrix
|
// set up the off-diagonal part of the Gram matrix
|
||||||
let mut gram_to_be = PartialMatrix::new();
|
let mut gram_to_be = PartialMatrix::new();
|
||||||
self.regulators.with_untracked(|regs| {
|
self.constraints.with_untracked(|csts| {
|
||||||
for (_, reg) in regs {
|
for (_, cst) in csts {
|
||||||
match reg.set_point.get_untracked() {
|
if cst.active.get_untracked() && cst.lorentz_prod_valid.get_untracked() {
|
||||||
Some(set_pt) => {
|
let subjects = cst.subjects;
|
||||||
let subjects = reg.subjects;
|
let row = elts[subjects.0].column_index.unwrap();
|
||||||
let row = elts[subjects.0].column_index.unwrap();
|
let col = elts[subjects.1].column_index.unwrap();
|
||||||
let col = elts[subjects.1].column_index.unwrap();
|
gram_to_be.push_sym(row, col, cst.lorentz_prod.get_untracked());
|
||||||
gram_to_be.push_sym(row, col, set_pt);
|
|
||||||
},
|
|
||||||
None => ()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,87 +1,56 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use web_sys::{
|
use web_sys::{
|
||||||
|
Event,
|
||||||
|
HtmlInputElement,
|
||||||
KeyboardEvent,
|
KeyboardEvent,
|
||||||
MouseEvent,
|
MouseEvent,
|
||||||
wasm_bindgen::JsCast
|
wasm_bindgen::JsCast
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{AppState, assembly, assembly::{Constraint, ConstraintKey, ElementKey}};
|
||||||
AppState,
|
|
||||||
assembly,
|
|
||||||
assembly::{
|
|
||||||
Regulator,
|
|
||||||
RegulatorKey,
|
|
||||||
ElementKey
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// an editable view of a regulator
|
// an editable view of the Lorentz product representing a constraint
|
||||||
#[component(inline_props)]
|
#[component(inline_props)]
|
||||||
fn RegulatorInput(regulator: Regulator) -> View {
|
fn LorentzProductInput(constraint: Constraint) -> View {
|
||||||
let valid = create_signal(true);
|
|
||||||
let value = create_signal(regulator.get_set_point_spec_clone_untracked());
|
|
||||||
|
|
||||||
// this closure resets the input value to the regulator's set point
|
|
||||||
// specification, which is always a valid specification
|
|
||||||
let reset_value = move || {
|
|
||||||
batch(|| {
|
|
||||||
valid.set(true);
|
|
||||||
value.set(regulator.get_set_point_spec_clone());
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// reset the input value whenever the regulator's set point specification
|
|
||||||
// is updated
|
|
||||||
create_effect(reset_value);
|
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
input(
|
input(
|
||||||
r#type="text",
|
r#type="text",
|
||||||
class=move || {
|
bind:value=constraint.lorentz_prod_text,
|
||||||
if valid.get() {
|
on:change=move |event: Event| {
|
||||||
match regulator.set_point.get() {
|
let target: HtmlInputElement = event.target().unwrap().unchecked_into();
|
||||||
Some(_) => "regulator-input constraint",
|
match target.value().parse::<f64>() {
|
||||||
None => "regulator-input"
|
Ok(lorentz_prod) => batch(|| {
|
||||||
}
|
constraint.lorentz_prod.set(lorentz_prod);
|
||||||
} else {
|
constraint.lorentz_prod_valid.set(true);
|
||||||
"regulator-input invalid"
|
}),
|
||||||
}
|
Err(_) => constraint.lorentz_prod_valid.set(false)
|
||||||
},
|
};
|
||||||
placeholder=regulator.measurement.with(|result| result.to_string()),
|
|
||||||
bind:value=value,
|
|
||||||
on:change=move |_| valid.set(
|
|
||||||
regulator.try_specify_set_point(value.get_clone_untracked())
|
|
||||||
),
|
|
||||||
on:keydown={
|
|
||||||
move |event: KeyboardEvent| {
|
|
||||||
match event.key().as_str() {
|
|
||||||
"Escape" => reset_value(),
|
|
||||||
_ => ()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// a list item that shows a regulator in an outline view of an element
|
// a list item that shows a constraint in an outline view of an element
|
||||||
#[component(inline_props)]
|
#[component(inline_props)]
|
||||||
fn RegulatorOutlineItem(regulator_key: RegulatorKey, element_key: ElementKey) -> View {
|
fn ConstraintOutlineItem(constraint_key: ConstraintKey, element_key: ElementKey) -> View {
|
||||||
let state = use_context::<AppState>();
|
let state = use_context::<AppState>();
|
||||||
let assembly = &state.assembly;
|
let assembly = &state.assembly;
|
||||||
let regulator = assembly.regulators.with(|regs| regs[regulator_key]);
|
let constraint = assembly.constraints.with(|csts| csts[constraint_key].clone());
|
||||||
let other_subject = if regulator.subjects.0 == element_key {
|
let other_subject = if constraint.subjects.0 == element_key {
|
||||||
regulator.subjects.1
|
constraint.subjects.1
|
||||||
} else {
|
} else {
|
||||||
regulator.subjects.0
|
constraint.subjects.0
|
||||||
};
|
};
|
||||||
let other_subject_label = assembly.elements.with(|elts| elts[other_subject].label.clone());
|
let other_subject_label = assembly.elements.with(|elts| elts[other_subject].label.clone());
|
||||||
|
let class = constraint.lorentz_prod_valid.map(
|
||||||
|
|&lorentz_prod_valid| if lorentz_prod_valid { "constraint" } else { "constraint invalid" }
|
||||||
|
);
|
||||||
view! {
|
view! {
|
||||||
li(class="regulator") {
|
li(class=class.get()) {
|
||||||
div(class="regulator-label") { (other_subject_label) }
|
input(r#type="checkbox", bind:checked=constraint.active)
|
||||||
div(class="regulator-type") { "Inversive distance" }
|
div(class="constraint-label") { (other_subject_label) }
|
||||||
RegulatorInput(regulator=regulator)
|
LorentzProductInput(constraint=constraint)
|
||||||
div(class="status")
|
div(class="status")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,9 +74,9 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
).collect::<Vec<_>>()
|
).collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let regulated = element.regulators.map(|regs| regs.len() > 0);
|
let constrained = element.constraints.map(|csts| csts.len() > 0);
|
||||||
let regulator_list = element.regulators.map(
|
let constraint_list = element.constraints.map(
|
||||||
|regs| regs.clone().into_iter().collect()
|
|csts| csts.clone().into_iter().collect()
|
||||||
);
|
);
|
||||||
let details_node = create_node_ref();
|
let details_node = create_node_ref();
|
||||||
view! {
|
view! {
|
||||||
|
@ -122,7 +91,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
state.select(key, event.shift_key());
|
state.select(key, event.shift_key());
|
||||||
event.prevent_default();
|
event.prevent_default();
|
||||||
},
|
},
|
||||||
"ArrowRight" if regulated.get() => {
|
"ArrowRight" if constrained.get() => {
|
||||||
let _ = details_node
|
let _ = details_node
|
||||||
.get()
|
.get()
|
||||||
.unchecked_into::<web_sys::Element>()
|
.unchecked_into::<web_sys::Element>()
|
||||||
|
@ -169,16 +138,16 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
div(class="status")
|
div(class="status")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ul(class="regulators") {
|
ul(class="constraints") {
|
||||||
Keyed(
|
Keyed(
|
||||||
list=regulator_list,
|
list=constraint_list,
|
||||||
view=move |reg_key| view! {
|
view=move |cst_key| view! {
|
||||||
RegulatorOutlineItem(
|
ConstraintOutlineItem(
|
||||||
regulator_key=reg_key,
|
constraint_key=cst_key,
|
||||||
element_key=key
|
element_key=key
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
key=|reg_key| reg_key.clone()
|
key=|cst_key| cst_key.clone()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,9 +155,9 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// a component that lists the elements of the current assembly, showing each
|
// a component that lists the elements of the current assembly, showing the
|
||||||
// element's regulators in a collapsible sub-list. its implementation is based
|
// constraints on each element as a collapsible sub-list. its implementation
|
||||||
// on Kate Morley's HTML + CSS tree views:
|
// is based on Kate Morley's HTML + CSS tree views:
|
||||||
//
|
//
|
||||||
// https://iamkate.com/code/tree-views/
|
// https://iamkate.com/code/tree-views/
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Reference in a new issue