diff --git a/api/cesium_entity.py b/api/cesium_entity.py index 05a92bb..08bfc91 100644 --- a/api/cesium_entity.py +++ b/api/cesium_entity.py @@ -7,6 +7,7 @@ def __init__(self, color="white", wireframe=False, tracked=True, + active=True, pathColor="blue", alpha=1, useRPY=False, @@ -24,6 +25,7 @@ def __init__(self, self.useRPY = useRPY self.useXYZ = useXYZ self.tracked = tracked + self.active = active self.scale = scale self.viewModel = viewModel self.id = CesiumEntity.next_id @@ -76,6 +78,11 @@ def fromJson(cls, json): else: tracked = True + if "active" in json: + active = json['active'] + else: + active = True + if "scale" in json: scale = json['scale'] else: @@ -92,6 +99,7 @@ def fromJson(cls, json): useRPY=useRPY, useXYZ=useXYZ, tracked=tracked, + active=active, scale=scale, viewModel=viewModel) @@ -105,6 +113,7 @@ def toJson(self): "useXYZ": self.useXYZ, "useRPY": self.useRPY, "tracked": self.tracked, + "active": self.active, "scale": self.scale, "position": self.position, "attitude": self.attitude diff --git a/api/store.py b/api/store.py index 333c318..ecf632f 100644 --- a/api/store.py +++ b/api/store.py @@ -83,6 +83,7 @@ def getEntitiesProps(self): "color": e.color, "wireframe": e.wireframe, "tracked": e.tracked, + "active": e.active, "pathColor": e.pathColor}) except Exception as error: err = str(error) diff --git a/src/components/EntityConfig.js b/src/components/EntityConfig.js index deca307..689d5f7 100644 --- a/src/components/EntityConfig.js +++ b/src/components/EntityConfig.js @@ -14,6 +14,7 @@ function EntityConfig({ useXYZ, useRPY, tracked, + active, scale, position, attitude, @@ -24,12 +25,15 @@ function EntityConfig({ const [options, setOptions] = useState([]); const [positionOptions, setPositionOptions] = useState([]); const [attitudeOptions, setAttitudeOptions] = useState([]); + const [disabled, setDisabled] = useState(true); + const mockPlot = new PlotData(0, null); useEffect(() => { getOptions(); getTables(); hideUnusedFields(); + setDisabled(!active); // eslint-disable-next-line }, []); @@ -103,6 +107,11 @@ function EntityConfig({ coordinatesContainer.style.display = useXYZ ? "none" : "block"; }; + const handleActiveChange = (e) => { + const checked = e.target.checked; + setDisabled(!checked); + } + return ( <fieldset id={`entity-${eId}`}> <Row> @@ -122,6 +131,7 @@ function EntityConfig({ placeholder="Name" id={`name-${eId}`} defaultValue={name} + disabled={disabled} /> </InputGroup> </Col> @@ -133,6 +143,7 @@ function EntityConfig({ placeholder="Color" id={`color-${eId}`} defaultValue={color} + disabled={disabled} /> </InputGroup> </Col> @@ -147,6 +158,7 @@ function EntityConfig({ step={0.1} id={`alpha-${eId}`} defaultValue={alpha} + disabled={disabled} /> </InputGroup> </Col> @@ -160,6 +172,7 @@ function EntityConfig({ step={0.1} id={`scale-${eId}`} defaultValue={scale} + disabled={disabled} /> </InputGroup> </Col> @@ -174,6 +187,7 @@ function EntityConfig({ placeholder="Path Color" id={`pathColor-${eId}`} defaultValue={pathColor} + disabled={disabled} /> </InputGroup> </Col> @@ -184,6 +198,7 @@ function EntityConfig({ label="Wireframe" id={`wireframe-${eId}`} defaultChecked={wireframe} + disabled={disabled} /> </Col> @@ -194,6 +209,17 @@ function EntityConfig({ id={`tracked-${eId}`} name="tracked" defaultChecked={tracked} + disabled={disabled} + /> + </Col> + + <Col> + <Form.Check + type="switch" + label="Active" + id={`active-${eId}`} + defaultChecked={active} + onChange={handleActiveChange} /> </Col> </Row> @@ -206,6 +232,7 @@ function EntityConfig({ placeholder="Position table" onChange={handlePositionTableSelect} defaultValue={{ label: position["table"] }} + isDisabled={disabled} /> <Form.Check id={`useXYZ-${eId}`} @@ -213,6 +240,7 @@ function EntityConfig({ label="use X/Y/Z" defaultChecked={useXYZ} onChange={handlePositionTypeChanged} + disabled={disabled} /> <Form.Group id={`XYZ-${eId}`}> <Row> @@ -222,6 +250,7 @@ function EntityConfig({ placeholder="X" id={`x-${eId}`} defaultValue={{ label: position["x"] ?? "Select X" }} + isDisabled={disabled} /> </Col> <Col> @@ -230,6 +259,7 @@ function EntityConfig({ placeholder="Y" id={`y-${eId}`} defaultValue={{ label: position["y"] ?? "Select Y" }} + isDisabled={disabled} /> </Col> <Col> @@ -238,6 +268,7 @@ function EntityConfig({ placeholder="Z" id={`z-${eId}`} defaultValue={{ label: position["z"] ?? "Select Z" }} + isDisabled={disabled} /> </Col> </Row> @@ -253,6 +284,7 @@ function EntityConfig({ defaultValue={{ label: position["longitude"] ?? "Select Longitude", }} + isDisabled={disabled} /> </Col> <Col> @@ -263,6 +295,7 @@ function EntityConfig({ defaultValue={{ label: position["lattitude"] ?? "Select Latitude", }} + isDisabled={disabled} /> </Col> <Col> @@ -273,6 +306,7 @@ function EntityConfig({ defaultValue={{ label: position["altitude"] ?? "Select Altitude", }} + isDisabled={disabled} /> </Col> </Row> @@ -286,6 +320,7 @@ function EntityConfig({ placeholder="Position table" onChange={handleAttitudeTableSelect} defaultValue={{ label: attitude["table"] }} + isDisabled={disabled} /> <Form.Check @@ -294,6 +329,7 @@ function EntityConfig({ label="use roll/pitch/yaw" defaultChecked={useRPY} onChange={handleAttitudeTypeChanged} + disabled={disabled} /> <Form.Group id={`RPY-${eId}`}> <Row> @@ -303,6 +339,7 @@ function EntityConfig({ placeholder="Roll" id={`roll-${eId}`} defaultValue={{ label: attitude["roll"] ?? "Select Roll" }} + isDisabled={disabled} /> </Col> <Col> @@ -311,6 +348,7 @@ function EntityConfig({ placeholder="Pitch" id={`pitch-${eId}`} defaultValue={{ label: attitude["pitch"] ?? "Select Pitch" }} + isDisabled={disabled} /> </Col> <Col> @@ -319,6 +357,7 @@ function EntityConfig({ placeholder="Yaw" id={`yaw-${eId}`} defaultValue={{ label: attitude["yaw"] ?? "Select Yaw" }} + isDisabled={disabled} /> </Col> </Row> @@ -331,6 +370,7 @@ function EntityConfig({ placeholder="Qx" id={`qx-${eId}`} defaultValue={{ label: attitude["q1"] ?? "Select Qx" }} + isDisabled={disabled} /> </Col> <Col> @@ -339,6 +379,7 @@ function EntityConfig({ placeholder="Qy" id={`qy-${eId}`} defaultValue={{ label: attitude["q2"] ?? "Select Qy" }} + isDisabled={disabled} /> </Col> <Col> @@ -347,6 +388,7 @@ function EntityConfig({ placeholder="Qz" id={`qz-${eId}`} defaultValue={{ label: attitude["q3"] ?? "Select Qz" }} + isDisabled={disabled} /> </Col> <Col> @@ -355,6 +397,7 @@ function EntityConfig({ placeholder="Qw" id={`qw-${eId}`} defaultValue={{ label: attitude["q0"] ?? "Select Qw" }} + isDisabled={disabled} /> </Col> </Row> diff --git a/src/components/View3D.js b/src/components/View3D.js index 68c3d27..2deb3a7 100644 --- a/src/components/View3D.js +++ b/src/components/View3D.js @@ -49,14 +49,19 @@ function View3D({ socket, detached }) { const response = await fetch( `http://localhost:${PORT}/entities_props` ).then((res) => res.json()); - if (response.ok) response.data.forEach(initEntity); - else toast.error(response.error); + if (response.ok) { + response.data.forEach(item => { + if (item.active) initEntity(item); + }); + } else { + toast.error(response.error); + } }; - const initEntity = (e, index) => { + const initEntity = (e) => { entities.push(new Entity(e)); - entities[index].loadPath(scene, index); - entities[index].loadObj(scene, index); + entities[entities.length - 1].loadPath(scene); + entities[entities.length - 1].loadObj(scene); }; const getTrackedEntity = () => { @@ -142,7 +147,7 @@ function View3D({ socket, detached }) { }; const setupKeyControls = () => { - document.onkeydown = function (e) { + document.onkeydown = function(e) { const target = getTrackedEntity(); switch (e.code) { case "ArrowRight": @@ -162,7 +167,7 @@ function View3D({ socket, detached }) { } }; - document.onkeyup = function (e) { + document.onkeyup = function(e) { const target = getTrackedEntity(); switch (e.code) { case "ArrowRight": diff --git a/src/controllers/Entity.js b/src/controllers/Entity.js index 6237d03..73889be 100644 --- a/src/controllers/Entity.js +++ b/src/controllers/Entity.js @@ -26,6 +26,7 @@ export default class Entity { this.alpha = e.alpha; this.wireframe = e.wireframe; this.tracked = e.tracked; + this.active = e.active; this.scale = e.scale; this.setReference(e); // using a single loop to do all the mapping @@ -99,7 +100,7 @@ export default class Entity { //////////////////// Drawing the entity's path // - loadPath(scene, idx) { + loadPath(scene) { const geometry = new THREE.BufferGeometry(); geometry.setAttribute( "position", @@ -157,10 +158,10 @@ export default class Entity { setReference(e) { // we set the first position as the reference if (e.useXYZ) { - this.ref_x = 0; - this.ref_y = 0; - this.ref_z = 0; - + this.ref_x = 0; + this.ref_y = 0; + this.ref_z = 0; + } else { this.ref_x = 0; this.ref_y = 0; diff --git a/src/views/Entities.js b/src/views/Entities.js index db161c0..4b59182 100644 --- a/src/views/Entities.js +++ b/src/views/Entities.js @@ -42,6 +42,7 @@ function Entities() { const _useRPY = document.getElementById(`useRPY-${eId}`).checked; const wireframe = document.getElementById(`wireframe-${eId}`).checked; const tracked = document.getElementById(`tracked-${eId}`).checked; + const active = document.getElementById(`active-${eId}`).checked; const position = _useXYZ ? { @@ -80,6 +81,7 @@ function Entities() { wireframe: wireframe, color: getValue(`color-${eId}`), tracked: tracked, + active: active, scale: parseFloat(getValue(`scale-${eId}`)), position: position, attitude: attitude, @@ -93,7 +95,8 @@ function Entities() { .then((res) => { var tracked_entity_type = JSON.parse(localStorage.getItem("tracked_entity_type")) ?? "last-tracked"; res.id = uuid(); - res.tracked = tracked_entity_type === "last-created"; + res.tracked = tracked_entity_type === "last-created" || current_entities.length === 0; + res.active = true; setCurrentEntities([...current_entities, res]); }); }; @@ -180,6 +183,7 @@ function Entities() { useRPY={e.useRPY} useXYZ={e.useXYZ} tracked={e.tracked} + active={e.active} scale={e.scale} position={e.position} attitude={e.attitude}