Commit 12f29a38 authored by sumpfralle's avatar sumpfralle

improved GUI for model scaling:

 * use percent value instead of a factor with up/down scaling (more intuitive)
 * added separate scaling along a specific axis (proportional or not)
increased value ranges of input controls up to 2000 (e.g. 2 meters or 166 feet)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@283 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 9f8faa97
Version 0.2.3 - UNRELEASED Version 0.2.3 - UNRELEASED
* GUI change: tool and process settings can be combined into tasks * GUI change: tool and process settings can be combined into tasks
* added export of EMC tool definitions
* fixed "overlap" calculation * fixed "overlap" calculation
* added a warning dialog (GUI) for missing dependencies during startup (especially useful for Windows) * added a warning dialog (GUI) for missing dependencies during startup (especially useful for Windows)
* improved GUI for model scaling
* prevent invalid input values (zero tool radius, ...) * prevent invalid input values (zero tool radius, ...)
* reduced memory consumption of toolpaths for python 2.6 or above * reduced memory consumption of toolpaths for python 2.6 or above
......
...@@ -460,9 +460,12 @@ class ProjectGui: ...@@ -460,9 +460,12 @@ class ProjectGui:
self.gui.get_object("Shift Model").connect("clicked", self.shift_model, True) self.gui.get_object("Shift Model").connect("clicked", self.shift_model, True)
self.gui.get_object("Shift To Origin").connect("clicked", self.shift_model, False) self.gui.get_object("Shift To Origin").connect("clicked", self.shift_model, False)
# scale model # scale model
self.gui.get_object("Scale up").connect("clicked", self.scale_model, True) self.gui.get_object("ScalePercent").set_value(100)
self.gui.get_object("Scale down").connect("clicked", self.scale_model, False) self.gui.get_object("ScaleModelButton").connect("clicked", self.scale_model)
self.gui.get_object("Scale factor").set_value(2) # scale model to an axis dimension
self.gui.get_object("ScaleDimensionAxis").connect("changed", self.switch_scale_axis)
self.gui.get_object("ScaleDimensionButton").connect("clicked", self.scale_model_axis_fit)
self.gui.get_object("ScaleDimensionsProportionally").set_active(True)
# visual and general settings # visual and general settings
for name, objname in (("show_model", "ShowModelCheckBox"), for name, objname in (("show_model", "ShowModelCheckBox"),
("show_axes", "ShowAxesCheckBox"), ("show_axes", "ShowAxesCheckBox"),
...@@ -629,6 +632,11 @@ class ProjectGui: ...@@ -629,6 +632,11 @@ class ProjectGui:
window_box.reorder_child(self.menubar, 0) window_box.reorder_child(self.menubar, 0)
# some more initialization # some more initialization
self.load_settings() self.load_settings()
self.update_all_controls()
if not self.no_dialog:
self.window.show()
def update_all_controls(self):
self.update_toolpath_table() self.update_toolpath_table()
self.update_tool_table() self.update_tool_table()
self.disable_invalid_process_settings() self.disable_invalid_process_settings()
...@@ -637,8 +645,7 @@ class ProjectGui: ...@@ -637,8 +645,7 @@ class ProjectGui:
self.update_tasklist_controls() self.update_tasklist_controls()
self.update_save_actions() self.update_save_actions()
self.update_unit_labels() self.update_unit_labels()
if not self.no_dialog: self.switch_scale_axis()
self.window.show()
def progress_activity_guard(func): def progress_activity_guard(func):
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
...@@ -1168,14 +1175,74 @@ class ProjectGui: ...@@ -1168,14 +1175,74 @@ class ProjectGui:
GuiCommon.shift_model(self.model, shift_x, shift_y, shift_z) GuiCommon.shift_model(self.model, shift_x, shift_y, shift_z)
self.update_view() self.update_view()
def _get_model_center(self):
if self.model is None:
return None
else:
return ((self.model.maxx + self.model.minx) / 2,
(self.model.maxy + self.model.miny) / 2,
(self.model.maxz + self.model.minz) / 2)
def _set_model_center(self, center):
new_x, new_y, new_z = center
old_x, old_y, old_z = self._get_model_center()
GuiCommon.shift_model(self.model, new_x - old_x, new_y - old_y, new_z - old_z)
@gui_activity_guard
def scale_model(self, widget=None, percent=None):
if percent is None:
percent = self.gui.get_object("ScalePercent").get_value()
factor = percent / 100.0
if (factor <= 0) or (factor == 1):
return
old_center = self._get_model_center()
GuiCommon.scale_model(self.model, factor)
self._set_model_center(old_center)
self.update_view()
@gui_activity_guard
def switch_scale_axis(self, widget=None):
if self.model is None:
return
index = self.gui.get_object("ScaleDimensionAxis").get_active()
if index == 0:
# x axis
value = self.model.maxx - self.model.minx
elif index == 1:
# y axis
value = self.model.maxy - self.model.miny
elif index == 2:
# z axis
value = self.model.maxz - self.model.minz
else:
return
self.gui.get_object("ScaleDimensionValue").set_value(value)
@gui_activity_guard @gui_activity_guard
def scale_model(self, widget, scale_up=True): def scale_model_axis_fit(self, widget):
value = self.gui.get_object("Scale factor").get_value() proportionally = self.gui.get_object("ScaleDimensionsProportionally").get_active()
if (value == 0) or (value == 1): value = self.gui.get_object("ScaleDimensionValue").get_value()
index = self.gui.get_object("ScaleDimensionAxis").get_active()
axes = "xyz"
axis_suffix = axes[index]
factor = value / (getattr(self.model, "max" + axis_suffix) - getattr(self.model, "min" + axis_suffix))
# store the original center of the model
old_center = self._get_model_center()
if proportionally:
GuiCommon.scale_model(self.model, factor)
else:
factor_x, factor_y, factor_z = (1, 1, 1)
if index == 0:
factor_x = factor
elif index == 1:
factor_y = factor
elif index == 2:
factor_z = factor
else:
return return
if not scale_up: GuiCommon.scale_model(self.model, factor_x, factor_y, factor_z)
value = 1/value # move the model to its previous center
GuiCommon.scale_model(self.model, value) self._set_model_center(old_center)
self.update_view() self.update_view()
@gui_activity_guard @gui_activity_guard
...@@ -1282,6 +1349,7 @@ class ProjectGui: ...@@ -1282,6 +1349,7 @@ class ProjectGui:
self.settings.set("safety_height", (2 * self.model.maxz - self.model.minz)) self.settings.set("safety_height", (2 * self.model.maxz - self.model.minz))
# do some initialization # do some initialization
self.append_to_queue(self.reset_bounds) self.append_to_queue(self.reset_bounds)
self.append_to_queue(self.update_all_controls)
self.append_to_queue(self.toggle_3d_view, value=True) self.append_to_queue(self.toggle_3d_view, value=True)
self.append_to_queue(self.update_view) self.append_to_queue(self.update_view)
......
...@@ -44,8 +44,12 @@ def shift_model(model, shift_x, shift_y, shift_z): ...@@ -44,8 +44,12 @@ def shift_model(model, shift_x, shift_y, shift_z):
matrix = ((1, 0, 0, shift_x), (0, 1, 0, shift_y), (0, 0, 1, shift_z)) matrix = ((1, 0, 0, shift_x), (0, 1, 0, shift_y), (0, 0, 1, shift_z))
model.transform(matrix) model.transform(matrix)
def scale_model(model, scale): def scale_model(model, scale_x, scale_y=None, scale_z=None):
matrix = ((scale, 0, 0, 0), (0, scale, 0, 0), (0, 0, scale, 0)) if scale_y is None:
scale_y = scale_x
if scale_z is None:
scale_z = scale_x
matrix = ((scale_x, 0, 0, 0), (0, scale_y, 0, 0), (0, 0, scale_z, 0))
model.transform(matrix) model.transform(matrix)
def dependency_details_gtk(): def dependency_details_gtk():
......
...@@ -125,6 +125,23 @@ ...@@ -125,6 +125,23 @@
</row> </row>
</data> </data>
</object> </object>
<object class="GtkListStore" id="ScaleDimensionAxisValue">
<columns>
<!-- column-name value -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">x</col>
</row>
<row>
<col id="0" translatable="yes">y</col>
</row>
<row>
<col id="0" translatable="yes">z</col>
</row>
</data>
</object>
<object class="GtkWindow" id="ProjectWindow"> <object class="GtkWindow" id="ProjectWindow">
<property name="title" translatable="yes">PyCAM</property> <property name="title" translatable="yes">PyCAM</property>
<property name="destroy_with_parent">True</property> <property name="destroy_with_parent">True</property>
...@@ -467,6 +484,7 @@ ...@@ -467,6 +484,7 @@
<child> <child>
<object class="GtkHBox" id="hbox6"> <object class="GtkHBox" id="hbox6">
<property name="visible">True</property> <property name="visible">True</property>
<property name="spacing">1</property>
<child> <child>
<object class="GtkLabel" id="ScaleFactorLabel"> <object class="GtkLabel" id="ScaleFactorLabel">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -479,51 +497,118 @@ ...@@ -479,51 +497,118 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkSpinButton" id="Scale factor"> <object class="GtkSpinButton" id="ScalePercent">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property> <property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property> <property name="adjustment">scale_percent_value</property>
<property name="adjustment">scale factor</property>
<property name="climb_rate">1</property>
<property name="numeric">True</property> <property name="numeric">True</property>
<property name="update_policy">if-valid</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="ScalePercentUnitLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">%</property>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="Scale down"> <object class="GtkButton" id="ScaleModelButton">
<property name="label" translatable="yes">Shrink</property> <property name="label" translatable="yes">Scale Model</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="Scale up"> <object class="GtkHSeparator" id="hseparator6">
<property name="label" translatable="yes">Enlarge</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="padding">2</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkHBox" id="hbox18">
<property name="visible">True</property>
<property name="spacing">3</property>
<child>
<object class="GtkComboBox" id="ScaleDimensionAxis">
<property name="visible">True</property>
<property name="model">ScaleDimensionAxisValue</property>
<property name="active">0</property>
<child>
<object class="GtkCellRendererText" id="ScaleDimensionColumn"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="ScaleDimensionControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="adjustment">ScaleDimensionValue</property>
<property name="digits">2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ScaleDimensionsProportionally">
<property name="label" translatable="yes">proportionally</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Scale the model along all axes proportionally.</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ScaleDimensionButton">
<property name="label" translatable="yes">Fit Dimension</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="position">5</property>
</packing>
</child>
</object> </object>
</child> </child>
</object> </object>
...@@ -531,7 +616,7 @@ ...@@ -531,7 +616,7 @@
<child type="label"> <child type="label">
<object class="GtkLabel" id="Scale frame"> <object class="GtkLabel" id="Scale frame">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Scale Model&lt;/b&gt;</property> <property name="label" translatable="yes">&lt;b&gt;Model Dimensions&lt;/b&gt;</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
</object> </object>
</child> </child>
...@@ -566,6 +651,7 @@ ...@@ -566,6 +651,7 @@
<object class="GtkVBox" id="vbox3"> <object class="GtkVBox" id="vbox3">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">3</property>
<child> <child>
<object class="GtkTable" id="table1"> <object class="GtkTable" id="table1">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -720,18 +806,21 @@ ...@@ -720,18 +806,21 @@
<child> <child>
<object class="GtkAlignment" id="alignment5"> <object class="GtkAlignment" id="alignment5">
<property name="visible">True</property> <property name="visible">True</property>
<property name="yalign">1</property>
<property name="yscale">0</property>
<property name="left_padding">8</property> <property name="left_padding">8</property>
<child> <child>
<object class="GtkVBox" id="vbox6"> <object class="GtkVBox" id="vbox6">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">3</property>
<child> <child>
<object class="GtkTable" id="table2"> <object class="GtkTable" id="table2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="n_rows">4</property> <property name="n_rows">4</property>
<property name="n_columns">3</property> <property name="n_columns">3</property>
<property name="column_spacing">1</property> <property name="column_spacing">1</property>
<property name="row_spacing">1</property> <property name="row_spacing">3</property>
<child> <child>
<object class="GtkSpinButton" id="minx"> <object class="GtkSpinButton" id="minx">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -1660,25 +1749,25 @@ This combination is added to the above task list.</property> ...@@ -1660,25 +1749,25 @@ This combination is added to the above task list.</property>
</object> </object>
</child> </child>
</object> </object>
<object class="GtkAdjustment" id="scale factor"> <object class="GtkAdjustment" id="scale_percent_value">
<property name="value">1</property> <property name="value">100</property>
<property name="lower">1</property> <property name="lower">1</property>
<property name="upper">1000</property> <property name="upper">1000</property>
<property name="step_increment">1</property> <property name="step_increment">25</property>
</object> </object>
<object class="GtkAdjustment" id="shift-x"> <object class="GtkAdjustment" id="shift-x">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="shift-y"> <object class="GtkAdjustment" id="shift-y">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="shift-z"> <object class="GtkAdjustment" id="shift-z">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkWindow" id="view3dwindow"> <object class="GtkWindow" id="view3dwindow">
...@@ -1979,38 +2068,38 @@ This combination is added to the above task list.</property> ...@@ -1979,38 +2068,38 @@ This combination is added to the above task list.</property>
</child> </child>
</object> </object>
<object class="GtkAdjustment" id="min-x"> <object class="GtkAdjustment" id="min-x">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="min-y"> <object class="GtkAdjustment" id="min-y">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="min-z"> <object class="GtkAdjustment" id="min-z">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="max-x"> <object class="GtkAdjustment" id="max-x">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="max-y"> <object class="GtkAdjustment" id="max-y">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="max-z"> <object class="GtkAdjustment" id="max-z">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="feedrate"> <object class="GtkAdjustment" id="feedrate">
<property name="lower">1</property> <property name="lower">1</property>
<property name="upper">1000</property> <property name="upper">10000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="speed"> <object class="GtkAdjustment" id="speed">
...@@ -2020,12 +2109,12 @@ This combination is added to the above task list.</property> ...@@ -2020,12 +2109,12 @@ This combination is added to the above task list.</property>
</object> </object>
<object class="GtkAdjustment" id="toolradius"> <object class="GtkAdjustment" id="toolradius">
<property name="lower">0.0001</property> <property name="lower">0.0001</property>
<property name="upper">100</property> <property name="upper">500</property>
<property name="step_increment">0.10000000000000001</property> <property name="step_increment">0.10000000000000001</property>
</object> </object>
<object class="GtkAdjustment" id="torusradius"> <object class="GtkAdjustment" id="torusradius">
<property name="lower">0.0001</property> <property name="lower">0.0001</property>
<property name="upper">100</property> <property name="upper">500</property>
<property name="step_increment">0.050000000000000003</property> <property name="step_increment">0.050000000000000003</property>
</object> </object>
<object class="GtkAdjustment" id="DrillProgressMaxFPS"> <object class="GtkAdjustment" id="DrillProgressMaxFPS">
...@@ -2047,8 +2136,8 @@ This combination is added to the above task list.</property> ...@@ -2047,8 +2136,8 @@ This combination is added to the above task list.</property>
<property name="step_increment">5</property> <property name="step_increment">5</property>
</object> </object>
<object class="GtkAdjustment" id="SafetyHeightValue"> <object class="GtkAdjustment" id="SafetyHeightValue">
<property name="lower">-1000</property> <property name="lower">-2000</property>
<property name="upper">1000</property> <property name="upper">2000</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAction" id="LoadModel"> <object class="GtkAction" id="LoadModel">
...@@ -3991,4 +4080,10 @@ ODE is required for this setting.</property> ...@@ -3991,4 +4080,10 @@ ODE is required for this setting.</property>
<property name="label">_Export EMC tools</property> <property name="label">_Export EMC tools</property>
<property name="stock_id">gtk-execute</property> <property name="stock_id">gtk-execute</property>
</object> </object>
<object class="GtkAdjustment" id="ScaleDimensionValue">
<property name="lower">0.01</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
</interface> </interface>
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