Commit 585f7a34 authored by sumpfralle's avatar sumpfralle

added a "Change Unit" dialog that allows the user to scale the model,...

added a "Change Unit" dialog that allows the user to scale the model, processing dimensions or tool dimensions accordingly


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@332 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 339d7538
Version 0.2.5 - NOT RELEASED
* changing the unit (mm/inch) now opens a dialog for scaling the model,
processing dimensions or tool dimensions accordingly
* changed name of configuration setting "overlap" to "overlap_percent"
(you may need to change this name in your custom config files)
......
......@@ -115,7 +115,9 @@ class ProjectGui:
self.settings = pycam.Gui.Settings.Settings()
self.gui_is_active = False
self.view3d = None
self.no_dialog = no_dialog
# during initialization any dialog (e.g. "Unit change") is not allowed
# we set the final value later
self.no_dialog = True
self._batch_queue = []
self._progress_running = False
self._progress_cancel_requested = False
......@@ -165,6 +167,10 @@ class ProjectGui:
# "about" window
self.about_window = self.gui.get_object("AboutWindow")
self.gui.get_object("About").connect("activate", self.toggle_about_window, True)
# "unit change" window
self.unit_change_window = self.gui.get_object("UnitChangeDialog")
self.gui.get_object("UnitChangeApply").connect("clicked", self.change_unit_apply)
self.unit_change_window.connect("delete_event", self.change_unit_apply, False)
# we assume, that the last child of the window is the "close" button
# TODO: fix this ugly hack!
self.gui.get_object("AboutWindowButtons").get_children()[-1].connect("clicked", self.toggle_about_window, False)
......@@ -176,17 +182,20 @@ class ProjectGui:
self.process_list = []
self.tool_list = []
self.task_list = []
self._last_unit = None
# add some dummies - to be implemented later ...
self.settings.add_item("model", lambda: self.model)
self.settings.add_item("toolpath", lambda: self.toolpath)
self.settings.add_item("cutter", lambda: self.cutter)
# unit control (mm/inch)
unit_field = self.gui.get_object("unit_control")
unit_field.connect("changed", self.update_view)
unit_field.connect("changed", self.update_unit_labels)
unit_field.connect("changed", self.change_unit_init)
def set_unit(text):
unit_field.set_active(0 if text == "mm" else 1)
self._last_unit = text
self.settings.add_item("unit", unit_field.get_active_text, set_unit)
self.gui.get_object("UnitChangeSelectAll").connect("clicked", self.change_unit_set_selection, True)
self.gui.get_object("UnitChangeSelectNone").connect("clicked", self.change_unit_set_selection, False)
# boundary mode (move inside/along/around the boundaries)
boundary_mode_control = self.gui.get_object("BoundaryModeControl")
def set_boundary_mode(value):
......@@ -374,6 +383,7 @@ class ProjectGui:
self.load_preferences()
self.load_task_settings()
self.update_all_controls()
self.no_dialog = no_dialog
if not self.no_dialog:
self.window.show()
......@@ -844,6 +854,71 @@ class ProjectGui:
self.update_tool_controls()
self.update_tasklist_table()
def change_unit_init(self, widget=None):
new_unit = self.gui.get_object("unit_control").get_active_text()
if self._last_unit is None:
# first initialization
self._last_unit = new_unit
return
if self._last_unit == new_unit:
# don't show the dialog if the conversion would make no sense
return
if self.no_dialog:
# without the dialog we don't scale anything
return
# show a dialog asking for a possible model scaling due to the unit change
self.unit_change_window.show()
def change_unit_set_selection(self, widget, state):
for key in ("UnitChangeModel", "UnitChangeProcesses", "UnitChangeTools"):
self.gui.get_object(key).set_active(state)
def change_unit_apply(self, widget=None, data=None, apply_scale=True):
if self.no_dialog:
# without the dialog we don't scale anything
return
new_unit = self.gui.get_object("unit_control").get_active_text()
factors = {
("mm", "inch"): 1 / 25.4,
("inch", "mm"): 25.4,
}
conversion = (self._last_unit, new_unit)
if conversion in factors.keys():
factor = factors[conversion]
if apply_scale:
if self.gui.get_object("UnitChangeModel").get_active():
# transform the model if it is selected
# keep the original center of the model
old_center = self._get_model_center()
self.model.scale(factor)
self._set_model_center(old_center)
if self.gui.get_object("UnitChangeProcesses").get_active():
# scale the boundaries and keep their center
s = self.settings
center_x = (s.get("maxx") + s.get("minx")) / 2.0
center_y = (s.get("maxy") + s.get("miny")) / 2.0
center_z = (s.get("maxz") + s.get("minz")) / 2.0
s.set("minx", center_x + (s.get("minx") - center_x) * factor)
s.set("maxx", center_x + (s.get("maxx") - center_x) * factor)
s.set("miny", center_y + (s.get("miny") - center_y) * factor)
s.set("maxy", center_y + (s.get("maxy") - center_y) * factor)
s.set("minz", center_z + (s.get("minz") - center_z) * factor)
s.set("maxz", center_z + (s.get("maxz") - center_z) * factor)
# scale the process settings
for process in self.process_list:
for key in ("safety_height", "material_allowance", "step_down"):
process[key] *= factor
if self.gui.get_object("UnitChangeTools").get_active():
# scale all tool dimensions
for tool in self.tool_list:
for key in ("tool_radius", "torus_radius", "feedrate"):
tool[key] *= factor
self.unit_change_window.hide()
# store the current unit (for the next run of this function)
self._last_unit = new_unit
# update all labels containing the unit size
self.update_unit_labels()
def update_unit_labels(self, widget=None, data=None):
# we can't just use the "unit" setting, since we need the plural of "inch"
if self.settings.get("unit") == "mm":
......
......@@ -4373,4 +4373,167 @@ ODE is required for this setting.</property>
<property name="upper">10</property>
<property name="step_increment">1</property>
</object>
<object class="GtkDialog" id="UnitChangeDialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Unit change compensation</property>
<property name="modal">True</property>
<property name="type_hint">normal</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox5">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkFrame" id="UnitChangeFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment28">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="vbox24">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="UnitChangeHelpLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Switching the unit size causes a change of the real world size of the various dimensions within PyCAM.
This change can be compensated by applying the unit conversion factor to the current dimensions.
Any selected group of dimensions will be scaled accordingly.</property>
<property name="wrap">True</property>
<property name="width_chars">40</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="UnitChangeModel">
<property name="label" translatable="yes">Model</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="UnitChangeProcesses">
<property name="label" translatable="yes">Boundaries and process settings</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="UnitChangeTools">
<property name="label" translatable="yes">Tools</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox2">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="UnitChangeSelectAll">
<property name="label">gtk-select-all</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="UnitChangeSelectNone">
<property name="label">gtk-clear</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="padding">4</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="UnitChangeFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Change of unit size&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area5">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkButton" id="UnitChangeApply">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">UnitChangeApply</action-widget>
</action-widgets>
</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