Skip to content

Commit 6b5728f

Browse files
committed
Fix error with editing xacros
1 parent 4a3654b commit 6b5728f

File tree

2 files changed

+54
-50
lines changed

2 files changed

+54
-50
lines changed

src/controls.ts

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,46 @@ export class URDFControls extends GUI {
4848
return this._jointsFolder;
4949
}
5050

51-
createWorkspaceControls(workingPath: string) {
52-
if (!workingPath) {
53-
return;
54-
}
51+
private _isEmpty(obj: Object): Boolean {
52+
return Object.keys(obj).length === 0;
53+
}
5554

56-
this._workingPath = workingPath;
57-
const workspaceSettings = {
58-
'Path': this._workingPath,
59-
'set path': () => {}
55+
createWorkspaceControls(workingPath: string = '') {
56+
if (this._isEmpty(this.controls.path)) {
57+
this._workingPath = workingPath;
58+
const workspaceSettings = {
59+
'Path': this._workingPath,
60+
'set path': () => {}
61+
}
62+
this._workspaceFolder.add(workspaceSettings, 'Path');
63+
this.controls.path = this._workspaceFolder.add(workspaceSettings, 'set path');
64+
this._workspaceFolder.open();
6065
}
61-
this._workspaceFolder.add(workspaceSettings, 'Path');
62-
this.controls.path = this._workspaceFolder.add(workspaceSettings, 'set path');
63-
this._workspaceFolder.open();
6466
return this.controls.path;
6567
}
6668

6769
createSceneControls(
6870
bgColor = new Color(0x263238),
6971
gridColor = new Color(0x263238)
7072
) {
71-
72-
const sceneSettings = {
73-
'Background': this._convertColor2Array(bgColor),
74-
'Grid': this._convertColor2Array(gridColor),
75-
'Height': 0
76-
};
77-
78-
this.controls.scene.background = this._sceneFolder.addColor(sceneSettings, 'Background');
79-
this.controls.scene.grid = this._sceneFolder.addColor(sceneSettings, 'Grid');
80-
81-
const minHeight = -2;
82-
const maxHeight = 5;
83-
const stepSize = 0.1;
84-
this.controls.scene.height = this._sceneFolder.add(
85-
sceneSettings, 'Height', minHeight, maxHeight, stepSize);
86-
87-
this._sceneFolder.open();
73+
if (this._isEmpty(this.controls.scene.background)) {
74+
const sceneSettings = {
75+
'Background': this._convertColor2Array(bgColor),
76+
'Grid': this._convertColor2Array(gridColor),
77+
'Height': 0
78+
};
79+
80+
this.controls.scene.background = this._sceneFolder.addColor(sceneSettings, 'Background');
81+
this.controls.scene.grid = this._sceneFolder.addColor(sceneSettings, 'Grid');
82+
83+
const minHeight = -2;
84+
const maxHeight = 5;
85+
const stepSize = 0.1;
86+
this.controls.scene.height = this._sceneFolder.add(
87+
sceneSettings, 'Height', minHeight, maxHeight, stepSize);
88+
89+
this._sceneFolder.open();
90+
}
8891
return this.controls.scene;
8992
}
9093

@@ -101,27 +104,29 @@ export class URDFControls extends GUI {
101104
}
102105

103106
createJointControls(joints: Joints) {
104-
Object.keys(joints).forEach((name: string) => {
105-
// Skip joints which should not be moved
106-
if (joints[name].jointType === 'fixed') {
107-
return;
108-
}
109-
110-
const limitMin = Number(joints[name].limit.lower);
111-
const limitMax = Number(joints[name].limit.upper);
112-
113-
// Skip joint if the limits are not defined
114-
if ( limitMin === 0 && limitMax === 0 ) {
115-
return;
116-
}
117-
118-
const stepSize = ( limitMax - limitMin ) / 20;
119-
const initValue = joints[name].jointValue[0];
120-
121-
this.controls.joints[name] = this._jointsFolder.add(
122-
{[name]: initValue}, name, limitMin, limitMax, stepSize);
123-
});
124-
this._jointsFolder.open();
107+
if (this._isEmpty(this.controls.joints)) {
108+
Object.keys(joints).forEach((name: string) => {
109+
// Skip joints which should not be moved
110+
if (joints[name].jointType === 'fixed') {
111+
return;
112+
}
113+
114+
const limitMin = Number(joints[name].limit.lower);
115+
const limitMax = Number(joints[name].limit.upper);
116+
117+
// Skip joint if the limits are not defined
118+
if ( limitMin === 0 && limitMax === 0 ) {
119+
return;
120+
}
121+
122+
const stepSize = ( limitMax - limitMin ) / 20;
123+
const initValue = joints[name].jointValue[0];
124+
125+
this.controls.joints[name] = this._jointsFolder.add(
126+
{[name]: initValue}, name, limitMin, limitMax, stepSize);
127+
});
128+
this._jointsFolder.open();
129+
}
125130
return this.controls.joints;
126131
}
127132
}

src/robot.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export class URDFLoadingManager extends LoadingManager {
5555
}
5656
});
5757

58-
// TODO: needs review
5958
this._xacroLoader.workingPath = PageConfig.getBaseUrl()
6059
+ '/files' + this._workingPath;
6160
}

0 commit comments

Comments
 (0)