Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to disable an entity #93

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/cesium_entity.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions api/store.py
Original file line number Diff line number Diff line change
@@ -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)
43 changes: 43 additions & 0 deletions src/components/EntityConfig.js
Original file line number Diff line number Diff line change
@@ -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,13 +232,15 @@ function EntityConfig({
placeholder="Position table"
onChange={handlePositionTableSelect}
defaultValue={{ label: position["table"] }}
isDisabled={disabled}
/>
<Form.Check
id={`useXYZ-${eId}`}
type="switch"
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>
19 changes: 12 additions & 7 deletions src/components/View3D.js
Original file line number Diff line number Diff line change
@@ -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":
11 changes: 6 additions & 5 deletions src/controllers/Entity.js
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 5 additions & 1 deletion src/views/Entities.js
Original file line number Diff line number Diff line change
@@ -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}