Hi, I try create widget for example line widget by state. I create line widget on scene next I remove it and I would like to create the same widget in the same place on scene from state of the widget but I don’t know how I can because I get error:
"No vtk class found for Object of type vtkWidgetState"
and "Cannot read properties of null (reading 'getWidgetForView')"
my try is:
state = widget.getState().widgetState - (I get key and value with parameters of widget)
widgetManager.addWidget(vtk(state));
Someone help me and tell me how can I create widget and other elements by state?
I assume you are trying to serialize and deserialize widget states. AFAIK calling getState() on a vtkWidgetState instance and then trying to rehydrate with vtk(state) won’t work as intended. I think vtkWidgetState isn’t registered as a constructor, since you can build many different kinds (class shapes) of vtkWidgetState.
Your better option is to construct your own serialization and deserialization methods, like so:
state = {
linePoint1: widget.getWidgetState().getLinePoint1().getOrigin(),
linePoint2: widget.getWidgetState().getLinePoint2().getOrigin(),
};
... // create a new widget state called "widgetState"
widgetState.getLinePoint1().setOrigin(...state.linePoint1);
widgetState.getLinePoint2().setOrigin(...state.linePoint2);
Thanks for your answer it work but when I create line I have handles and I start from point 1 and end in point 2 (screen with green handles) if I recreate the line by state I’ve not the handles. Could you give me tips why?