Skip to content

Commit

Permalink
Merge pull request #319 from openworm/release/2.3.1
Browse files Browse the repository at this point in the history
Release/2.3.1
  • Loading branch information
tarelli authored Jul 1, 2020
2 parents 601150f + d2ef514 commit 9dc3027
Show file tree
Hide file tree
Showing 12 changed files with 696 additions and 628 deletions.
65 changes: 49 additions & 16 deletions js/communication/geppettoJupyter/PythonControlledCapability.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,36 @@ define(function (require) {

}

shouldComponentUpdate (nextProps, nextState) {
switch (this.state.componentType) {
case 'AutoComplete':
return ((this.state.searchText !== nextState.searchText) || (this.state.model !== nextState.model));
case 'Checkbox':
return ((this.state.checked !== nextState.checked) || (this.state.model !== nextState.model));
default:
return ((this.state.value !== nextState.value) || (this.state.model !== nextState.model));
componentDidMount () {
super.componentDidMount()
this.UNRELIABLE_SyncDefaultValueWithPython()
}

/*
* since we don't know when a component will be synched with python,
* we can't know when to check if this.state.value should be replaced
* with this.props.default
*/
UNRELIABLE_SyncDefaultValueWithPython (timeInterval = 100, attemps = 0) {
if (attemps < 3) {
setTimeout(() => {
if (this.props.default && this.state.value === '') {
if (this.syncValueWithPython) {
// this function is added by jupyter_geppetto after the component is synched with python
this.syncValueWithPython(this.props.default);
} else {
this.UNRELIABLE_SyncDefaultValueWithPython(timeInterval * 2, attemps + 1)
}
}
}, timeInterval)
} else {
console.warn(`Tried to sync default value for ${this.props.model} and failed after 3 attemps.`)
}
}

UNSAFE_componentWillReceiveProps (nextProps) {
this.disconnectFromPython();
this.id = (nextProps.id == undefined) ? nextProps.model : nextProps.id;

GEPPETTO.ComponentFactory.addExistingComponent(this.state.componentType, this);
this.connectToPython(this.state.componentType, nextProps.model);
if ((this.state.searchText != nextProps.searchText) && (nextProps.searchText != undefined)) {
Expand Down Expand Up @@ -151,9 +166,24 @@ define(function (require) {
break;
}
if (this.props.validate) {
this.props.validate(this.state.value).then(errorState => {
this.setState(errorState);
});
this.props.validate(this.state.value)
.then(response => {
if (this.state.errorState !== response.errorMsg) {
this.setState({ errorState: response.errorMsg });
}
});
}

if (
/*
* If the component changes id without unmounting,
* then default values will never be synched with python
*/
this.props.model === prevProps.model
&& this.state.value === ''
&& this.props.default
) {
this.UNRELIABLE_SyncDefaultValueWithPython(1000)
}
}

Expand Down Expand Up @@ -213,9 +243,12 @@ define(function (require) {
this.setState({ value: targetValue });

if (this.props.validate) {
this.props.validate(targetValue).then(errorState => {
this.setState(errorState);
});
this.props.validate(targetValue)
.then(response => {
if (response.errorMsg !== this.state.errorMsg) {
this.setState({ errorMsg: response.errorMsg });
}
});
}

// For textfields value is retrieved from the event. For dropdown value is retrieved from the value
Expand Down Expand Up @@ -253,7 +286,7 @@ define(function (require) {
if (wrappedComponentProps.realType == 'func' || wrappedComponentProps.realType == 'float') {
wrappedComponentProps['helperText'] = this.state.errorMsg;
}
if (getNameFromWrappedComponent(WrappedComponent) != 'ListComponent') {
if (!getNameFromWrappedComponent(WrappedComponent).includes('ListComponent')) {
delete wrappedComponentProps.realType;
}

Expand Down
50 changes: 1 addition & 49 deletions js/components/interface/3dCanvas/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ define(function (require) {
this.animationRunning = false;
}

startAnimation () {
if (this.props.minimiseAnimation !== undefined || this.props.minimiseAnimation) {
this.engine.animationRunning = true;
this.engine.animate();
}
}

stopAnimation () {
if (this.props.minimiseAnimation !== undefined || this.props.minimiseAnimation) {
this.engine.animationRunning = false;
this.engine.animate();
}
}

/**
* Displays all the passed instances in this canvas component
* @param instances an array of instances
Expand Down Expand Up @@ -128,7 +114,6 @@ define(function (require) {
* @param object
*/
removeObject (object) {
this.startAnimation();
this.engine.removeObject(object);
}

Expand All @@ -155,7 +140,6 @@ define(function (require) {
* @return {Canvas}
*/
selectInstance (instancePath, geometryIdentifier) {
this.startAnimation();
this.engine.selectInstance(instancePath, geometryIdentifier);
return this;
}
Expand All @@ -167,7 +151,6 @@ define(function (require) {
* @returns {Canvas}
*/
deselectInstance (instancePath) {
this.startAnimation();
this.engine.deselectInstance(instancePath);
return this;
}
Expand All @@ -178,7 +161,6 @@ define(function (require) {
* @returns {Canvas}
*/
assignRandomColor (instance) {
this.startAnimation();
this.engine.assignRandomColor(instance);
return this;
}
Expand All @@ -189,7 +171,6 @@ define(function (require) {
* @return {Canvas}
*/
zoomTo (instances) {
this.startAnimation();
this.engine.zoomTo(instances);
return this;
}
Expand All @@ -200,7 +181,6 @@ define(function (require) {
* @return {Canvas}
*/
setWireframe (wireframe) {
this.startAnimation();
this.engine.setWireframe(wireframe);
return this;
}
Expand All @@ -211,7 +191,6 @@ define(function (require) {
* @return {Canvas}
*/
enablePicking (pickingEnabled) {
this.startAnimation();
this.engine.enablePicking(pickingEnabled);
return this;
}
Expand Down Expand Up @@ -244,7 +223,6 @@ define(function (require) {
* @returns {Canvas}
*/
add3DPlane (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, textureURL) {
this.startAnimation();
return this.engine.add3DPlane(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, textureURL);
}

Expand All @@ -267,7 +245,6 @@ define(function (require) {
* @returns {Canvas}
*/
modify3DPlane (object, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4) {
this.startAnimation();
return this.engine.modify3DPlane(object, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4);
}

Expand All @@ -277,7 +254,6 @@ define(function (require) {
* @param {boolean} mode - Show or hide connection lines
*/
showConnectionLines (instancePath, mode) {
this.startAnimation();
this.engine.showConnectionLines(instancePath, mode);
return this;
}
Expand All @@ -289,7 +265,6 @@ define(function (require) {
* @return {Canvas}
*/
showInstance (instancePath) {
this.startAnimation();
this.engine.showInstance(instancePath);
return this;
}
Expand All @@ -301,7 +276,6 @@ define(function (require) {
* @return {Canvas}
*/
hideInstance (instancePath) {
this.startAnimation();
this.engine.hideInstance(instancePath);
return this;
}
Expand All @@ -312,7 +286,6 @@ define(function (require) {
* @return {Canvas}
*/
hideAllInstances () {
this.startAnimation();
this.engine.hideAllInstances();
return this;
}
Expand All @@ -324,7 +297,6 @@ define(function (require) {
* @return {Canvas}
*/
setBackgroundColor (color) {
this.startAnimation();
this.viewState.custom.backgroundColor = color;
this.setDirty(true);
$(this.getContainer()).css("background", color);
Expand All @@ -341,7 +313,6 @@ define(function (require) {
* @return {Canvas}
*/
setColor (path, color, recursion) {
this.startAnimation();
if (recursion === undefined) {
recursion = false;
}
Expand Down Expand Up @@ -647,7 +618,7 @@ define(function (require) {
* @return {Canvas}
*/
autoRotate () {
this.engine.autoRotate();
this.engine.autoRotate({ movieFilter: this.props.movieFilter });
return this;
}

Expand Down Expand Up @@ -831,24 +802,6 @@ define(function (require) {

var that = this;

if (this.props.minimiseAnimation !== undefined || this.props.minimiseAnimation) {
$("#" + this.props.id + "_component").on("mouseover", function (event, ui) {
that.startAnimation();
});

$("#" + this.props.id + "_component").on("mouseout", function (event, ui) {
that.stopAnimation();
});

GEPPETTO.on(GEPPETTO.Events.selectInstance, () => {
this.stopAnimation();
}, this);

GEPPETTO.on(GEPPETTO.Events.deselectInstance, () => {
this.stopAnimation();
}, this);
}

window.addEventListener('resize', function () {
var [width, height] = that.setContainerDimensions();
that.engine.setSize(width, height);
Expand All @@ -873,7 +826,6 @@ define(function (require) {
this.resetCamera();
this.initialCameraReset = false;
}
this.startAnimation();
}, this);

this.initialCameraReset = true;
Expand Down
14 changes: 7 additions & 7 deletions js/components/interface/3dCanvas/ThreeDEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ define(['jquery'], function () {
this.needsUpdate = false;
this.pickingEnabled = true; // flag to enable disable 3d picking
this.linesUserInput = false;
this.animationRunning = true;
this.linesUserPreference = undefined;
this.hoverListeners = undefined;
this.THREE = THREE;
Expand Down Expand Up @@ -1514,15 +1513,19 @@ define(['jquery'], function () {
* Rotate the camera around the selection
*
*/
autoRotate: function () {
autoRotate: function (props) {
var that = this;
if (this.rotate == null) {
this.movieMode(true);
if (props.movieFilter === undefined || props.movieFilter === true) {
this.movieMode(true);
}
this.rotate = setInterval(function () {
that.incrementCameraRotate(0.01, 0)
}, 100);
} else {
this.movieMode(false);
if (props.movieFilter === undefined || props.movieFilter === true) {
this.movieMode(false);
}
clearInterval(this.rotate);
this.rotate = null;
}
Expand All @@ -1535,9 +1538,6 @@ define(['jquery'], function () {
var that = this;
that.debugUpdate = that.needsUpdate;
// so that we log only the cycles when we are updating the scene
if (!this.animationRunning) {
return;
}

that.controls.update();

Expand Down
Loading

0 comments on commit 9dc3027

Please sign in to comment.