Skip to content

Commit

Permalink
Merge pull request #29 from PTCInc/nodes-groundplane
Browse files Browse the repository at this point in the history
moveNode API from frame and resetNodes API from hardwareInterface
  • Loading branch information
benptc authored May 2, 2019
2 parents 27ffb28 + 7d638c7 commit a43bbe0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
31 changes: 30 additions & 1 deletion libraries/hardwareInterfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function Frame() {
exports.getIP = function () {
var ip = require("ip");
return ip.address();
}
};

exports.write = function (objectName, frameName, nodeName, value, mode, unit, unitMin, unitMax) {

Expand Down Expand Up @@ -480,11 +480,40 @@ exports.removeNode = function (objectName, frameName, nodeName) {
}
};

/**
* Removes all nodes from the specified frame
* (pushUpdatesToDevices needs to be called afterwards)
* @param {string} objectName
* @param {string} frameName
*/
exports.resetNodes = function (objectName, frameName) {
var objectID = utilities.getObjectIdFromTarget(objectName, objectsPath);
var frameID = objectID + frameName;
if (!_.isUndefined(objectID) && !_.isNull(objectID)) {
if (objects.hasOwnProperty(objectID)) {
if (objects[objectID].frames.hasOwnProperty(frameID)) {
objects[objectID].frames[frameID].nodes = {};
}
}
}
};

/**
* Changes the node's position to become relative to the ground plane origin instead of the frame
* Defaults to true if last parameter is excluded. Explicitly pass in false to de-attach from ground plane and go back to frame.
* (pushUpdatesToDevices needs to be called afterwards)
* @param {string} objectName
* @param {string} frameName
* @param {string} nodeName
* @param {bool} shouldAttachToGroundPlane
*/
exports.attachNodeToGroundPlane = function (objectName, frameName, nodeName, shouldAttachToGroundPlane) {
var objectID = utilities.getObjectIdFromTarget(objectName, objectsPath);
var frameID = objectID + frameName;
var nodeID = objectID + frameName + nodeName;

if (typeof shouldAttachToGroundPlane === 'undefined') { shouldAttachToGroundPlane = true; } // defaults to true

if (!_.isUndefined(objectID) && !_.isNull(objectID)) {
if (objects.hasOwnProperty(objectID)) {
if (objects[objectID].frames.hasOwnProperty(frameID)) {
Expand Down
15 changes: 15 additions & 0 deletions libraries/objectDefaultFiles/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
this.sendGlobalMessage = makeSendStub('sendGlobalMessage');
this.sendResetNodes = makeSendStub('sendResetNodes');
this.sendCreateNode = makeSendStub('sendCreateNode');
this.sendMoveNode = makeSendStub('sendMoveNode');
this.subscribeToMatrix = makeSendStub('subscribeToMatrix');
this.subscribeToAcceleration = makeSendStub('subscribeToAcceleration');
this.setFullScreenOn = makeSendStub('setFullScreenOn');
Expand Down Expand Up @@ -868,6 +869,20 @@
}), '*');
};

this.sendMoveNode = function (name, x, y) {
parent.postMessage(JSON.stringify({
version: realityObject.version,
node: realityObject.node,
frame: realityObject.frame,
object: realityObject.object,
moveNode: {
name: name,
x: x,
y: y
}
}), '*');
};

// subscriptions
this.subscribeToMatrix = function() {
realityObject.sendMatrix = true;
Expand Down

0 comments on commit a43bbe0

Please sign in to comment.