Skip to content

Commit f29da44

Browse files
authored
Merge pull request #433 from laurennlam/add_line_widget
Add line widget
2 parents 1670e25 + 08f2865 commit f29da44

File tree

12 files changed

+975
-5
lines changed

12 files changed

+975
-5
lines changed

Sources/Common/DataModel/Box/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ function vtkBox(publicAPI, model) {
172172
}
173173
return distance;
174174
};
175+
176+
publicAPI.addBounds = (...bounds) => {
177+
let boundsArray = [];
178+
179+
if (Array.isArray(bounds[0])) {
180+
boundsArray = bounds[0];
181+
} else {
182+
for (let i = 0; i < bounds.length; i++) {
183+
boundsArray.push(bounds[i]);
184+
}
185+
}
186+
187+
if (boundsArray.length !== 6) {
188+
return;
189+
}
190+
191+
model.bbox.addBounds(...boundsArray);
192+
model.bbox.modified();
193+
};
175194
}
176195

177196
// ----------------------------------------------------------------------------

Sources/Interaction/Widgets/AbstractWidget/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function vtkAbstractWidget(publicAPI, model) {
5656
// Enable listening events
5757
publicAPI.listenEvents();
5858

59+
model.widgetRep.getBounds();
5960
model.widgetRep.buildRepresentation();
6061
model.currentRenderer.addViewProp(model.widgetRep);
6162
} else {
@@ -75,6 +76,13 @@ function vtkAbstractWidget(publicAPI, model) {
7576
model.currentRenderer = null;
7677
}
7778
};
79+
80+
publicAPI.get2DPointerPosition = () => {
81+
const pos = model.interactor.getEventPosition(model.interactor.getPointerIndex());
82+
const boundingContainer = model.interactor.getCanvas().getBoundingClientRect();
83+
const position = [pos.x - boundingContainer.left, pos.y + boundingContainer.top];
84+
return position;
85+
};
7886
}
7987

8088
// ----------------------------------------------------------------------------

Sources/Interaction/Widgets/HandleRepresentation/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function extend(publicAPI, model, initialValues = {}) {
8383
model.pointPlacer = vtkPointPlacer.newInstance();
8484
model.interactionState = InteractionState.OUTSIDE;
8585

86-
macro.setGet(publicAPI, model, ['activeRepresentation']);
86+
macro.setGet(publicAPI, model, ['activeRepresentation', 'tolerance']);
8787

8888
// Object methods
8989
vtkHandleRepresentation(publicAPI, model);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const State = {
2+
OUTSIDE: 0,
3+
ONP1: 1,
4+
ONP2: 2,
5+
TRANSLATINGP1: 3,
6+
TRANSLATINGP2: 4,
7+
ONLINE: 5,
8+
SCALING: 6,
9+
};
10+
11+
export const Restrict = {
12+
NONE: 0,
13+
X: 1,
14+
Y: 2,
15+
Z: 3,
16+
};
17+
18+
export default {
19+
State,
20+
Restrict,
21+
};

0 commit comments

Comments
 (0)