if (!model.widgetRep) { return; } // Use the representations from the line widget // for the point widgets to avoid creating // default representations when setting the // interactor below model.point1Widget.setWidgetRep(model.widgetRep.getPoint1Representation()); model.point2Widget.setWidgetRep(model.widgetRep.getPoint2Representation());
publicAPI.selectAction = (callData) => { const position = [callData.position.x, callData.position.y];
if (model.widgetState === WidgetState.START) { const pos3D = model.point1Widget .getWidgetRep() .displayToWorld(position, 0); // The first time we click, the method is called twice if (model.currentHandle < 1) { model.widgetRep.setLineVisibility(1); model.widgetRep.setPoint1WorldPosition(pos3D); // Trick to avoid a line with a zero length // If the line has a zero length, it appears with bad extremities pos3D[0] += 0.000000001; model.widgetRep.setPoint2WorldPosition(pos3D);
publicAPI.setCurrentHandle(model.currentHandle + 1); } else { model.widgetRep.setPoint2Visibility(1); model.widgetRep.setPoint2WorldPosition(pos3D); // When two points are placed, we go back to the native model.widgetState = WidgetState.MANIPULATE;
publicAPI.setCurrentHandle(-1); } } else { const state = model.widgetRep.computeInteractionState(position); if (state === InteractionState.OUTSIDE) { return; } model.widgetState = WidgetState.ACTIVE;
publicAPI.moveAction = (callData) => { const position = [callData.position.x, callData.position.y]; let modified = false;
if (model.widgetState === WidgetState.MANIPULATE) { // In MANIPULATE, we are hovering above the widget // Check if above a sphere and enable/disable if needed const state = model.widgetRep.computeInteractionState(position); modified = publicAPI.updateHandleWidgets(state); } elseif (model.widgetState === WidgetState.START) { // In START, we are placing the sphere widgets. // Move current handle along the mouse position. model.widgetRep.complexWidgetInteraction(position); const pos3D = model.point1Widget .getWidgetRep() .displayToWorld(position, 0); if (model.currentHandle === 0) { model.widgetRep.setPoint1WorldPosition(pos3D); } else { model.widgetRep.setPoint2WorldPosition(pos3D); } modified = true; } elseif (model.widgetState === WidgetState.ACTIVE) { // In ACTIVE, we are moving a sphere widget. // Update the line extremities to follow the spheres. model.widgetRep.setPoint1WorldPosition( model.point1Widget.getWidgetRep().getWorldPosition() ); model.widgetRep.setPoint2WorldPosition( model.point2Widget.getWidgetRep().getWorldPosition() ); modified = true; }
if (modified) { publicAPI.invokeInteractionEvent(); publicAPI.render(); } };