Commit 82cca76c authored by sumpfralle's avatar sumpfralle

switched most model-related plugins to the new model manager interface


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1107 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 2fe7f67e
......@@ -45,6 +45,8 @@ class ModelExtrusion(pycam.Plugins.PluginBase):
extrusion_frame.unparent()
self.core.register_event("model-change-after",
self._update_extrude_widgets)
self.core.register_event("model-selection-changed",
self._update_extrude_widgets)
self.core.register_ui("model_handling", "Extrusion",
extrusion_frame, 5)
self.gui.get_object("ExtrudeButton").connect("clicked",
......@@ -66,24 +68,30 @@ class ModelExtrusion(pycam.Plugins.PluginBase):
self.core.unregister_event("model-change-after",
self._update_extrude_widgets)
def _get_extrudable_models(self):
models = self.core.get("models").get_selected()
extrudables = []
for model in models:
if (not model is None) and hasattr(model, "extrude"):
extrudables.append(model)
return extrudables
def _update_extrude_widgets(self):
model = self.core.get("model")
is_extrudable = (not model is None) \
and hasattr(model, "extrude")
extrude_widget = self.gui.get_object("ModelExtrusionFrame")
if is_extrudable:
if self._get_extrudable_models():
extrude_widget.show()
else:
extrude_widget.hide()
def _extrude_model(self, widget=None):
model = self.core.get("model")
if not model:
models = self._get_extrudable_models()
if not models:
return
self.core.get("update_progress")("Extruding model")
self.core.get("update_progress")("Extruding models")
extrusion_type_selector = self.gui.get_object("ExtrusionTypeSelector")
type_model = extrusion_type_selector.get_model()
type_active = extrusion_type_selector.get_active()
# TODO: progress bar for main/sub if more than one model is selected
if type_active >= 0:
type_string = type_model[type_active][0]
height = self.gui.get_object("ExtrusionHeight").get_value()
......@@ -102,6 +110,7 @@ class ModelExtrusion(pycam.Plugins.PluginBase):
else:
self.log.error("Unknown extrusion type selected: %s" % type_string)
return
for model in models:
new_model = model.extrude(stepping=grid_size, func=func,
callback=self.core.get("update_progress"))
if new_model:
......
......@@ -36,6 +36,9 @@ class ModelPlaneMirror(pycam.Plugins.PluginBase):
self.core.register_ui("model_handling", "Mirror", mirror_box, 0)
self.gui.get_object("PlaneMirrorButton").connect("clicked",
self._plane_mirror)
self.core.register_event("model-selection-changed",
self._update_plane_widgets)
self._update_plane_widgets()
return True
def teardown(self):
......@@ -43,6 +46,13 @@ class ModelPlaneMirror(pycam.Plugins.PluginBase):
self.core.unregister_ui("model_handling",
self.gui.get_object("ModelMirrorBox"))
def _update_plane_widgets(self):
plane_widget = self.gui.get_object("ModelMirrorBox")
if self.core.get("models").get_selected():
plane_widget.show()
else:
plane_widget.hide()
def _plane_mirror(self, widget=None):
model = self.core.get("model")
if not model:
......
......@@ -40,6 +40,9 @@ class ModelPolygons(pycam.Plugins.PluginBase):
self._toggle_direction)
self.gui.get_object("DirectionsGuessButton").connect("clicked",
self._revise_directions)
self.core.register_event("model-selection-changed",
self._update_polygon_controls)
self._update_polygon_controls()
return True
def teardown(self):
......@@ -47,30 +50,39 @@ class ModelPolygons(pycam.Plugins.PluginBase):
self.core.unregister_ui("model_handling",
self.gui.get_object("ModelPolygonFrame"))
def _get_polygon_models(self):
models = []
for model in self.core.get("models").get_selected():
if model and hasattr(model, "reverse_directions"):
models.append(model)
return models
def _update_polygon_controls(self):
model = self.core.get("model")
is_reversible = model and hasattr(model, "reverse_directions")
models = self._get_polygon_models()
frame = self.gui.get_object("ModelPolygonFrame")
if is_reversible:
if models:
frame.show()
else:
frame.hide()
def _toggle_direction(self, widget=None):
model = self.core.get("model")
if not model or not hasattr(model, "reverse_directions"):
models = self._get_polygon_models()
if not models:
return
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Reversing directions of contour model")
# TODO: main/sub progress bar for multiple models
for model in models:
model.reverse_directions(callback=self.core.get("update_progress"))
self.core.emit_event("model-change-after")
def _revise_directions(self, widget=None):
model = self.core.get("model")
if not model or not hasattr(model, "revise_directions"):
models = self._get_polygon_models()
if not models:
return
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Analyzing directions of contour model")
for model in models:
model.revise_directions(callback=self.core.get("update_progress"))
self.core.emit_event("model-change-after")
......@@ -53,6 +53,9 @@ class ModelPosition(pycam.Plugins.PluginBase):
align_model_button.grab_default())
obj.connect("focus-out-event", lambda widget, data: \
align_model_button.get_toplevel().set_default(None))
self.core.register_event("model-selection-changed",
self._update_position_widgets)
self._update_position_widgets()
return True
def teardown(self):
......@@ -60,22 +63,31 @@ class ModelPosition(pycam.Plugins.PluginBase):
self.core.unregister_ui("model_handling",
self.gui.get_object("ModelPositionBox"))
def _update_position_widgets(self):
widget = self.gui.get_object("ModelPositionBox")
if self.core.get("models").get_selected():
widget.show()
else:
widget.hide()
def _shift_model(self, widget=None):
model = self.core.get("model")
if not model:
models = self.core.get("models").get_selected()
if not models:
return
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Aligning model")
self.core.get("disable_progress_cancel_button")()
shift = [self.gui.get_object("ShiftPosition%s" % axis).get_value()
for axis in "XYZ"]
# TODO: main/sub progress bar for multiple models
for model in models:
model.shift(shift[0], shift[1], shift[2],
callback=self.core.get("update_progress"))
self.core.emit_event("model-change-after")
def _align_model(self, widget=None):
model = self.core.get("model")
if not model:
models = self.core.get("models").get_selected()
if not models:
return
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Shifting model")
......@@ -98,6 +110,8 @@ class ModelPosition(pycam.Plugins.PluginBase):
else:
shift = dest - max_axis
shift_values.append(shift)
# TODO: main/sub progress bar for multiple models
for model in models:
model.shift(shift_values[0], shift_values[1], shift_values[2],
callback=self.core.get("update_progress"))
self.core.emit_event("model-change-after")
......
......@@ -41,6 +41,9 @@ class ModelProjection(pycam.Plugins.PluginBase):
self._update_controls)
self.gui.get_object("ProjectionButton").connect("clicked",
self._projection)
self.core.register_event("model-selection-changed",
self._update_controls)
self._update_controls()
return True
def teardown(self):
......@@ -50,20 +53,29 @@ class ModelProjection(pycam.Plugins.PluginBase):
self.core.unregister_event("model-change-after",
self._update_controls)
def _get_projectable_models(self):
models = self.core.get("models").get_selected()
projectables = []
for model in models:
if (not model is None) and hasattr(model, "get_waterline_contour"):
projectables.append(model)
return projectables
def _update_controls(self):
model = self.core.get("model")
is_projectable = model and hasattr(model, "get_waterline_contour")
models = self._get_projectable_models()
control = self.gui.get_object("ModelProjectionFrame")
if is_projectable:
if models:
control.show()
else:
control.hide()
def _projection(self, widget=None):
model = self.core.get("model")
if not model or not hasattr(model, "get_waterline_contour"):
models = self._get_projectable_models()
if not models:
return
self.core.get("update_progress")("Calculating 2D projection")
# TODO: main/sub progress for multiple models
for model in models:
for objname, z_level in (("ProjectionModelTop", model.maxz),
("ProjectionModelMiddle", (model.minz + model.maxz) / 2.0),
("ProjectionModelBottom", model.minz),
......
......@@ -38,6 +38,9 @@ class ModelRotation(pycam.Plugins.PluginBase):
-10)
self.gui.get_object("RotateModelButton").connect("clicked",
self._rotate_model)
self.core.register_event("model-selection-changed",
self._update_controls)
self._update_controls()
return True
def teardown(self):
......@@ -45,9 +48,16 @@ class ModelRotation(pycam.Plugins.PluginBase):
self.core.unregister_ui("model_handling",
self.gui.get_object("ModelRotationBox"))
def _update_controls(self):
widget = self.gui.get_object("ModelRotationBox")
if self.core.get("models").get_selected():
widget.show()
else:
widget.hide()
def _rotate_model(self, widget=None):
model = self.core.get("model")
if not model:
models = self.core.get("models").get_selected()
if not models:
return
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Rotating model")
......@@ -65,6 +75,8 @@ class ModelRotation(pycam.Plugins.PluginBase):
break
matrix = pycam.Geometry.Matrix.get_rotation_matrix_axis_angle(
axis_vector, angle, use_radians=False)
# TODO: main/sub progress for multiple models
for model in models:
model.transform_by_matrix(matrix,
callback=self.core.get("update_progress"))
self.core.emit_event("model-change-after")
......
......@@ -35,7 +35,7 @@ class ModelScaling(pycam.Plugins.PluginBase):
scale_box.unparent()
self.core.register_ui("model_handling", "Scale", scale_box, -5)
self.core.register_event("model-change-after",
self._update_scale_dimensions)
self._update_scale_controls)
update_model = lambda widget=None: self.core.emit_event(
"model-change-after")
scale_percent = self.gui.get_object("ScalePercent")
......@@ -65,6 +65,9 @@ class ModelScaling(pycam.Plugins.PluginBase):
self._scale_model, 100 * 25.4)
self.gui.get_object("ScaleMMInch").connect("clicked",
self._scale_model, 100 / 25.4)
self.core.register_event("model-selection-changed",
self._update_scale_controls)
self._update_scale_controls()
return True
def teardown(self):
......@@ -72,15 +75,21 @@ class ModelScaling(pycam.Plugins.PluginBase):
self.core.unregister_ui("model_handling",
self.gui.get_object("ModelScaleBox"))
def _update_scale_dimensions(self):
model = self.core.get("model")
if not model:
def _update_scale_controls(self):
models = self.core.get("models").get_selected()
scale_box = self.gui.get_object("ModelScaleBox")
if not models:
scale_box.hide()
return
else:
scale_box.show()
# scale controls
axis_control = self.gui.get_object("ScaleDimensionAxis")
scale_button = self.gui.get_object("ScaleSelectedAxisButton")
scale_value = self.gui.get_object("ScaleDimensionControl")
index = axis_control.get_active()
# TODO: get dimension of multiple models
model = models[0]
dims = (model.maxx - model.minx, model.maxy - model.miny,
model.maxz - model.minz)
value = dims[index]
......@@ -91,8 +100,8 @@ class ModelScaling(pycam.Plugins.PluginBase):
scale_value.set_value(value)
def _scale_model(self, widget=None, percent=None):
model = self.core.get("model")
if not model:
models = self.core.get("models").get_selected()
if not models:
return
if percent is None:
percent = self.gui.get_object("ScalePercent").get_value()
......@@ -102,22 +111,28 @@ class ModelScaling(pycam.Plugins.PluginBase):
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Scaling model")
self.core.get("disable_progress_cancel_button")()
# TODO: main/sub progress for multiple models
for model in models:
model.scale(factor, callback=self.core.get("update_progress"))
self.core.emit_event("model-change-after")
def _scale_model_axis_fit(self, widget=None, proportionally=False):
model = self.core.get("model")
if not model:
models = self.core.get("models").get_selected()
if not models:
return
value = self.gui.get_object("ScaleDimensionValue").get_value()
index = self.gui.get_object("ScaleDimensionAxis").get_active()
axes = "xyz"
axis_suffix = axes[index]
# TODO: use dimension of multiple models
model = models[0]
factor = value / (getattr(model, "max" + axis_suffix) - \
getattr(model, "min" + axis_suffix))
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Scaling model")
self.core.get("disable_progress_cancel_button")()
# TODO: main/sub progress for multiple models
for model in models:
if proportionally:
model.scale(factor, callback=self.core.get("update_progress"))
else:
......@@ -132,6 +147,5 @@ class ModelScaling(pycam.Plugins.PluginBase):
return
model.scale(factor_x, factor_y, factor_z,
callback=self.core.get("update_progress"))
# move the model to its previous center
self.core.emit_event("model-change-after")
......@@ -36,6 +36,9 @@ class ModelSwapAxes(pycam.Plugins.PluginBase):
self.core.register_ui("model_handling", "Swap axes", swap_box, 0)
self.gui.get_object("SwapAxesButton").connect("clicked",
self._swap_axes)
self.core.register_event("model-selection-changed",
self._update_controls)
self._update_controls()
return True
def teardown(self):
......@@ -43,9 +46,16 @@ class ModelSwapAxes(pycam.Plugins.PluginBase):
self.core.unregister_ui("model_handling",
self.gui.get_object("ModelSwapBox"))
def _update_controls(self):
box = self.gui.get_object("ModelSwapBox")
if self.core.get("models").get_selected():
box.show()
else:
box.hide()
def _swap_axes(self, widget=None):
model = self.core.get("model")
if not model:
models = self.core.get("models").get_selected()
if not models:
return
self.core.emit_event("model-change-before")
self.core.get("update_progress")("Swap axes of model")
......@@ -54,9 +64,9 @@ class ModelSwapAxes(pycam.Plugins.PluginBase):
("YZ", "y_swap_z")):
if self.gui.get_object("SwapAxes%s" % axes).get_active():
break
# TODO: main/sub progress for multiple models
for model in models:
model.transform_by_template(template,
callback=self.core.get("update_progress"))
self.core.emit_event("model-change-after")
......@@ -61,6 +61,11 @@ class Models(pycam.Plugins.ListPluginBase):
self._visualize_visible_state)
self.gui.get_object("ModelNameColumn").connect("edited",
self._edit_model_name)
selection = self._modelview.get_selection()
selection.connect("changed",
lambda widget, event: self.core.emit_event(event),
"model-selection-changed")
selection.set_mode(gtk.SELECTION_MULTIPLE)
self._treemodel = self.gui.get_object("ModelList")
self._treemodel.clear()
def update_model():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment