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
* GUI change: tool and process settings can be combined into tasks
* added export of EMC tool definitions
* fixed "overlap" calculation
* 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, ...)
* reduced memory consumption of toolpaths for python 2.6 or above
......
......@@ -460,9 +460,12 @@ class ProjectGui:
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)
# scale model
self.gui.get_object("Scale up").connect("clicked", self.scale_model, True)
self.gui.get_object("Scale down").connect("clicked", self.scale_model, False)
self.gui.get_object("Scale factor").set_value(2)
self.gui.get_object("ScalePercent").set_value(100)
self.gui.get_object("ScaleModelButton").connect("clicked", self.scale_model)
# 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
for name, objname in (("show_model", "ShowModelCheckBox"),
("show_axes", "ShowAxesCheckBox"),
......@@ -629,6 +632,11 @@ class ProjectGui:
window_box.reorder_child(self.menubar, 0)
# some more initialization
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_tool_table()
self.disable_invalid_process_settings()
......@@ -637,8 +645,7 @@ class ProjectGui:
self.update_tasklist_controls()
self.update_save_actions()
self.update_unit_labels()
if not self.no_dialog:
self.window.show()
self.switch_scale_axis()
def progress_activity_guard(func):
def wrapper(self, *args, **kwargs):
......@@ -1168,14 +1175,74 @@ class ProjectGui:
GuiCommon.shift_model(self.model, shift_x, shift_y, shift_z)
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
def scale_model(self, widget, scale_up=True):
value = self.gui.get_object("Scale factor").get_value()
if (value == 0) or (value == 1):
def scale_model_axis_fit(self, widget):
proportionally = self.gui.get_object("ScaleDimensionsProportionally").get_active()
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
if not scale_up:
value = 1/value
GuiCommon.scale_model(self.model, value)
GuiCommon.scale_model(self.model, factor_x, factor_y, factor_z)
# move the model to its previous center
self._set_model_center(old_center)
self.update_view()
@gui_activity_guard
......@@ -1282,6 +1349,7 @@ class ProjectGui:
self.settings.set("safety_height", (2 * self.model.maxz - self.model.minz))
# do some initialization
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.update_view)
......
......@@ -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))
model.transform(matrix)
def scale_model(model, scale):
matrix = ((scale, 0, 0, 0), (0, scale, 0, 0), (0, 0, scale, 0))
def scale_model(model, scale_x, scale_y=None, scale_z=None):
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)
def dependency_details_gtk():
......
......@@ -125,6 +125,23 @@
</row>
</data>
</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">
<property name="title" translatable="yes">PyCAM</property>
<property name="destroy_with_parent">True</property>
......@@ -467,6 +484,7 @@
<child>
<object class="GtkHBox" id="hbox6">
<property name="visible">True</property>
<property name="spacing">1</property>
<child>
<object class="GtkLabel" id="ScaleFactorLabel">
<property name="visible">True</property>
......@@ -479,51 +497,118 @@
</packing>
</child>
<child>
<object class="GtkSpinButton" id="Scale factor">
<object class="GtkSpinButton" id="ScalePercent">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property>
<property name="adjustment">scale factor</property>
<property name="climb_rate">1</property>
<property name="adjustment">scale_percent_value</property>
<property name="numeric">True</property>
<property name="update_policy">if-valid</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</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>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Scale down">
<property name="label" translatable="yes">Shrink</property>
<object class="GtkButton" id="ScaleModelButton">
<property name="label" translatable="yes">Scale Model</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Scale up">
<property name="label" translatable="yes">Enlarge</property>
<object class="GtkHSeparator" id="hseparator6">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">2</property>
<property name="position">2</property>
</packing>
</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>
</child>
</object>
......@@ -531,7 +616,7 @@
<child type="label">
<object class="GtkLabel" id="Scale frame">
<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>
</object>
</child>
......@@ -566,6 +651,7 @@
<object class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
......@@ -720,18 +806,21 @@
<child>
<object class="GtkAlignment" id="alignment5">
<property name="visible">True</property>
<property name="yalign">1</property>
<property name="yscale">0</property>
<property name="left_padding">8</property>
<child>
<object class="GtkVBox" id="vbox6">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="n_rows">4</property>
<property name="n_columns">3</property>
<property name="column_spacing">1</property>
<property name="row_spacing">1</property>
<property name="row_spacing">3</property>
<child>
<object class="GtkSpinButton" id="minx">
<property name="visible">True</property>
......@@ -1660,25 +1749,25 @@ This combination is added to the above task list.</property>
</object>
</child>
</object>
<object class="GtkAdjustment" id="scale factor">
<property name="value">1</property>
<object class="GtkAdjustment" id="scale_percent_value">
<property name="value">100</property>
<property name="lower">1</property>
<property name="upper">1000</property>
<property name="step_increment">1</property>
<property name="step_increment">25</property>
</object>
<object class="GtkAdjustment" id="shift-x">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="shift-y">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="shift-z">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkWindow" id="view3dwindow">
......@@ -1979,38 +2068,38 @@ This combination is added to the above task list.</property>
</child>
</object>
<object class="GtkAdjustment" id="min-x">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="min-y">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="min-z">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="max-x">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="max-y">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="max-z">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="feedrate">
<property name="lower">1</property>
<property name="upper">1000</property>
<property name="upper">10000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="speed">
......@@ -2020,12 +2109,12 @@ This combination is added to the above task list.</property>
</object>
<object class="GtkAdjustment" id="toolradius">
<property name="lower">0.0001</property>
<property name="upper">100</property>
<property name="upper">500</property>
<property name="step_increment">0.10000000000000001</property>
</object>
<object class="GtkAdjustment" id="torusradius">
<property name="lower">0.0001</property>
<property name="upper">100</property>
<property name="upper">500</property>
<property name="step_increment">0.050000000000000003</property>
</object>
<object class="GtkAdjustment" id="DrillProgressMaxFPS">
......@@ -2047,8 +2136,8 @@ This combination is added to the above task list.</property>
<property name="step_increment">5</property>
</object>
<object class="GtkAdjustment" id="SafetyHeightValue">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="lower">-2000</property>
<property name="upper">2000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAction" id="LoadModel">
......@@ -3991,4 +4080,10 @@ ODE is required for this setting.</property>
<property name="label">_Export EMC tools</property>
<property name="stock_id">gtk-execute</property>
</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>
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