Skip to content

Commit

Permalink
Merge pull request #433 from laurennlam/add_line_widget
Browse files Browse the repository at this point in the history
Add line widget
  • Loading branch information
martinken authored Nov 29, 2017
2 parents 1670e25 + 08f2865 commit f29da44
Show file tree
Hide file tree
Showing 12 changed files with 975 additions and 5 deletions.
19 changes: 19 additions & 0 deletions Sources/Common/DataModel/Box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ function vtkBox(publicAPI, model) {
}
return distance;
};

publicAPI.addBounds = (...bounds) => {
let boundsArray = [];

if (Array.isArray(bounds[0])) {
boundsArray = bounds[0];
} else {
for (let i = 0; i < bounds.length; i++) {
boundsArray.push(bounds[i]);
}
}

if (boundsArray.length !== 6) {
return;
}

model.bbox.addBounds(...boundsArray);
model.bbox.modified();
};
}

// ----------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions Sources/Interaction/Widgets/AbstractWidget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function vtkAbstractWidget(publicAPI, model) {
// Enable listening events
publicAPI.listenEvents();

model.widgetRep.getBounds();
model.widgetRep.buildRepresentation();
model.currentRenderer.addViewProp(model.widgetRep);
} else {
Expand All @@ -75,6 +76,13 @@ function vtkAbstractWidget(publicAPI, model) {
model.currentRenderer = null;
}
};

publicAPI.get2DPointerPosition = () => {
const pos = model.interactor.getEventPosition(model.interactor.getPointerIndex());
const boundingContainer = model.interactor.getCanvas().getBoundingClientRect();
const position = [pos.x - boundingContainer.left, pos.y + boundingContainer.top];
return position;
};
}

// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Sources/Interaction/Widgets/HandleRepresentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function extend(publicAPI, model, initialValues = {}) {
model.pointPlacer = vtkPointPlacer.newInstance();
model.interactionState = InteractionState.OUTSIDE;

macro.setGet(publicAPI, model, ['activeRepresentation']);
macro.setGet(publicAPI, model, ['activeRepresentation', 'tolerance']);

// Object methods
vtkHandleRepresentation(publicAPI, model);
Expand Down
21 changes: 21 additions & 0 deletions Sources/Interaction/Widgets/LineRepresentation/Constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const State = {
OUTSIDE: 0,
ONP1: 1,
ONP2: 2,
TRANSLATINGP1: 3,
TRANSLATINGP2: 4,
ONLINE: 5,
SCALING: 6,
};

export const Restrict = {
NONE: 0,
X: 1,
Y: 2,
Z: 3,
};

export default {
State,
Restrict,
};
Loading

0 comments on commit f29da44

Please sign in to comment.