Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(polylinewidget): makes Angle and Distance widgets inherits from PolyLineWidget #2392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomsuchel
Copy link
Contributor

Context

Angle and Distance widgets were basically PolyLineWidgets but with a hard-coded limit on their number of points, and a method to compute an angle/distance. The behavior.js file was almost the same between the 3 widgets, which was a potential source of bugs or difference on behaviors.

Results

  • Refactors PolyLineWidget so it can support having a max number of points.
  • Makes AngleWidget and DistanceWidget inherits from PolyLineWidget by limiting their maxPoints to 2 and 3.
  • Remove a lot of duplicate code (behavior.js and state.js) in Angle and Distance widgets.

Changes

  • PolyLineWidget: add getMaxPoints / setMaxPoints

PR and Code Checklist

  • semantic-release commit messages
  • Run npm run reformat to have correctly formatted code

Testing

  • This change adds or fixes unit tests
  • Tested environment:
    • vtk.js: v24.6.0
    • OS: Ubuntu 20.04 LTS
    • Browser: Chromium 98.0.4697.0

…rom PolyLineWidget

Refactors PolyLineWidget so it can support having a max number of points. Makes AngleWidget and
DistanceWidget inherits from PolyLineWidget by limiting their maxPoints to 2 and 3. Remove a lot of
duplicate code between Angle and Distance widgets.
@tomsuchel
Copy link
Contributor Author

@Julesdevops

function canPlacePoints() {
return model.getMaxPoints()
? model.widgetState.getHandleList().length < model.getMaxPoints()
: true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!model.getMaxPoints() || model.widgetState.getHandleList().length < model.getMaxPoints()

@@ -144,6 +155,11 @@ export default function widgetBehavior(publicAPI, model) {
model._interactor.render();
}

// Don't make any more points
if (!canPlacePoints()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you were simply dragging a point, should you also "lose focus" ?

@@ -162,7 +178,7 @@ export default function widgetBehavior(publicAPI, model) {
// --------------------------------------------------------------------------

publicAPI.grabFocus = () => {
if (!model.hasFocus) {
if (!model.hasFocus && canPlacePoints()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean you can't grab focus if you are dragging a point ?


vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues);
macro.setGet(publicAPI, model, ['manipulator']);
macro.setGet(publicAPI, model, ['manipulator', 'maxPoints']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to document that setting maxpoint at run time won't reduce the number of points

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants