| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | """Provides GUI tools to set up the working plane and its grid.""" |
| | |
| | |
| | |
| |
|
| | |
| | |
| | from PySide import QtGui |
| | from PySide.QtCore import QT_TRANSLATE_NOOP |
| |
|
| | import FreeCAD as App |
| | import FreeCADGui as Gui |
| | import Part |
| | import WorkingPlane |
| |
|
| | from FreeCAD import Units |
| | from drafttaskpanels import task_selectplane |
| | from draftutils import gui_utils |
| | from draftutils import params |
| | from draftutils import utils |
| | from draftutils.messages import _toolmsg |
| | from draftutils.todo import todo |
| | from draftutils.translate import translate |
| |
|
| | __title__ = "FreeCAD Draft Workbench GUI Tools - Working plane-related tools" |
| | __author__ = "Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline, " "Dmitry Chigrin" |
| | __url__ = "https://www.freecad.org" |
| |
|
| |
|
| | class Draft_SelectPlane: |
| | """The Draft_SelectPlane FreeCAD command definition.""" |
| |
|
| | def GetResources(self): |
| | """Set icon, menu and tooltip.""" |
| | return { |
| | "Pixmap": "Draft_SelectPlane", |
| | "Accel": "W, P", |
| | "MenuText": QT_TRANSLATE_NOOP("Draft_SelectPlane", "Working Plane"), |
| | "ToolTip": QT_TRANSLATE_NOOP( |
| | "Draft_SelectPlane", |
| | "Defines the working plane from 3 vertices, 1 or more shapes, or an object", |
| | ), |
| | } |
| |
|
| | def IsActive(self): |
| | """Return True when this command should be available.""" |
| | return bool(gui_utils.get_3d_view()) |
| |
|
| | def Activated(self): |
| | """Execute when the command is called.""" |
| | |
| | if App.activeDraftCommand is not None: |
| | App.activeDraftCommand.finish() |
| |
|
| | App.activeDraftCommand = self |
| | self.call = None |
| |
|
| | |
| | self.wp = WorkingPlane.get_working_plane() |
| | self.view = self.wp._view |
| | self.grid = None |
| | if hasattr(Gui, "Snapper"): |
| | Gui.Snapper.setTrackers() |
| | self.grid = Gui.Snapper.grid |
| | self.offset = 0 |
| | self.center = params.get_param("CenterPlaneOnView") |
| |
|
| | |
| | self.taskd = task_selectplane.SelectPlaneTaskPanel() |
| | self.taskd.reject = self.reject |
| | form = self.taskd.form |
| |
|
| | |
| | form.fieldOffset.setText(Units.Quantity(self.offset, Units.Length).UserString) |
| | form.checkCenter.setChecked(self.center) |
| | try: |
| | q = Units.Quantity(params.get_param("gridSpacing")) |
| | except ValueError: |
| | q = Units.Quantity("1 mm") |
| | form.fieldGridSpacing.setText(q.UserString) |
| | form.fieldGridMainLine.setValue(params.get_param("gridEvery")) |
| | form.fieldGridExtension.setValue(params.get_param("gridSize")) |
| | form.fieldSnapRadius.setValue(params.get_param("snapRange")) |
| |
|
| | |
| | form.setWindowIcon(QtGui.QIcon(":/icons/Draft_SelectPlane.svg")) |
| | form.buttonTop.setIcon(QtGui.QIcon(":/icons/view-top.svg")) |
| | form.buttonFront.setIcon(QtGui.QIcon(":/icons/view-front.svg")) |
| | form.buttonSide.setIcon(QtGui.QIcon(":/icons/view-right.svg")) |
| | form.buttonAlign.setIcon(QtGui.QIcon(":/icons/view-isometric.svg")) |
| | form.buttonAuto.setIcon(QtGui.QIcon(":/icons/view-axonometric.svg")) |
| | form.buttonMove.setIcon(QtGui.QIcon(":/icons/Draft_Move.svg")) |
| | form.buttonCenter.setIcon(QtGui.QIcon(":/icons/view-fullscreen.svg")) |
| | form.buttonPrevious.setIcon(QtGui.QIcon(":/icons/sel-back.svg")) |
| | form.buttonNext.setIcon(QtGui.QIcon(":/icons/sel-forward.svg")) |
| |
|
| | |
| | color = params.get_param("gridColor") |
| | form.buttonColor.setProperty("color", QtGui.QColor(utils.rgba_to_argb(color))) |
| |
|
| | |
| | form.buttonTop.clicked.connect(self.on_click_top) |
| | form.buttonFront.clicked.connect(self.on_click_front) |
| | form.buttonSide.clicked.connect(self.on_click_side) |
| | form.buttonAlign.clicked.connect(self.on_click_align) |
| | form.buttonAuto.clicked.connect(self.on_click_auto) |
| | form.buttonMove.clicked.connect(self.on_click_move) |
| | form.buttonCenter.clicked.connect(self.on_click_center) |
| | form.buttonPrevious.clicked.connect(self.on_click_previous) |
| | form.buttonNext.clicked.connect(self.on_click_next) |
| | form.fieldOffset.textEdited.connect(self.on_set_offset) |
| | if hasattr(form.checkCenter, "checkStateChanged"): |
| | form.checkCenter.checkStateChanged.connect(self.on_set_center) |
| | else: |
| | form.checkCenter.stateChanged.connect(self.on_set_center) |
| | form.fieldGridSpacing.textEdited.connect(self.on_set_grid_size) |
| | form.fieldGridMainLine.valueChanged.connect(self.on_set_main_line) |
| | form.fieldGridExtension.valueChanged.connect(self.on_set_extension) |
| | form.fieldSnapRadius.valueChanged.connect(self.on_set_snap_radius) |
| | form.buttonColor.changed.connect(self.on_color_changed) |
| |
|
| | |
| | form.buttonPrevious.setEnabled(self.wp._has_previous()) |
| | form.buttonNext.setEnabled(self.wp._has_next()) |
| |
|
| | |
| | if Gui.Selection.hasSelection(): |
| | if self.wp.align_to_selection(self.offset): |
| | Gui.Selection.clearSelection() |
| | self.finish() |
| | return |
| |
|
| | |
| | todo.delay(Gui.Control.showDialog, self.taskd) |
| | todo.delay(form.setFocus, None) |
| | _toolmsg( |
| | translate( |
| | "draft", |
| | "Select 3 vertices, one or more shapes or an object to define a working plane", |
| | ) |
| | ) |
| | self.call = self.view.addEventCallback("SoEvent", self.action) |
| |
|
| | def finish(self): |
| | """Execute when the command is terminated.""" |
| | App.activeDraftCommand = None |
| | Gui.Control.closeDialog() |
| | if hasattr(Gui, "Snapper"): |
| | Gui.Snapper.off() |
| | |
| | if self.call: |
| | try: |
| | self.view.removeEventCallback("SoEvent", self.call) |
| | except RuntimeError: |
| | |
| | pass |
| | self.call = None |
| |
|
| | def reject(self): |
| | """Execute when clicking the Cancel button.""" |
| | self.finish() |
| |
|
| | def action(self, arg): |
| | """Set the callbacks for the view.""" |
| | if arg["Type"] == "SoKeyboardEvent" and arg["Key"] == "ESCAPE": |
| | self.reject() |
| | if ( |
| | arg["Type"] == "SoMouseButtonEvent" |
| | and (arg["State"] == "UP") |
| | and (arg["Button"] == "BUTTON1") |
| | ): |
| | self.check_selection() |
| |
|
| | def check_selection(self): |
| | """Check the selection, if it is usable, finish the command.""" |
| | if self.wp.align_to_selection(self.offset): |
| | Gui.Selection.clearSelection() |
| | self.finish() |
| |
|
| | def on_click_top(self): |
| | self.wp.set_to_top(self.offset, self.center) |
| | self.finish() |
| |
|
| | def on_click_front(self): |
| | self.wp.set_to_front(self.offset, self.center) |
| | self.finish() |
| |
|
| | def on_click_side(self): |
| | self.wp.set_to_side(self.offset, self.center) |
| | self.finish() |
| |
|
| | def on_click_align(self): |
| | self.wp.set_to_view(self.offset, self.center) |
| | self.finish() |
| |
|
| | def on_click_auto(self): |
| | self.wp.set_to_auto() |
| | self.finish() |
| |
|
| | def on_click_move(self): |
| | sels = Gui.Selection.getSelectionEx("", 0) |
| | if ( |
| | len(sels) == 1 |
| | and len(sels[0].SubObjects) == 1 |
| | and sels[0].SubObjects[0].ShapeType == "Vertex" |
| | ): |
| | vert = Part.getShape( |
| | sels[0].Object, sels[0].SubElementNames[0], needSubElement=True, retType=0 |
| | ) |
| | self.wp.set_to_position(vert.Point) |
| | Gui.Selection.clearSelection() |
| | self.finish() |
| | else: |
| | |
| | self.wp.center_on_view() |
| | self.finish() |
| |
|
| | def on_click_center(self): |
| | self.wp.align_view() |
| | self.finish() |
| |
|
| | def on_click_previous(self): |
| | self.wp._previous() |
| | self.finish() |
| |
|
| | def on_click_next(self): |
| | self.wp._next() |
| | self.finish() |
| |
|
| | def on_set_offset(self, text): |
| | try: |
| | q = Units.Quantity(text) |
| | except Exception: |
| | pass |
| | else: |
| | self.offset = q.Value |
| |
|
| | def on_set_center(self, val): |
| | self.center = bool(getattr(val, "value", val)) |
| | params.set_param("CenterPlaneOnView", self.center) |
| |
|
| | def on_set_grid_size(self, text): |
| | try: |
| | q = Units.Quantity(text) |
| | except Exception: |
| | pass |
| | else: |
| | params.set_param("gridSpacing", q.UserString) |
| | |
| | if self.grid is not None: |
| | self.grid.show_during_command = True |
| | self.grid.on() |
| |
|
| | def on_set_main_line(self, i): |
| | if i > 1: |
| | params.set_param("gridEvery", i) |
| | |
| | if self.grid is not None: |
| | self.grid.show_during_command = True |
| | self.grid.on() |
| |
|
| | def on_set_extension(self, i): |
| | if i > 1: |
| | params.set_param("gridSize", i) |
| | |
| | if self.grid is not None: |
| | self.grid.show_during_command = True |
| | self.grid.on() |
| |
|
| | def on_set_snap_radius(self, i): |
| | params.set_param("snapRange", i) |
| | if hasattr(Gui, "Snapper"): |
| | Gui.Snapper.showradius() |
| |
|
| | def on_color_changed(self): |
| | color = utils.argb_to_rgba(self.taskd.form.buttonColor.property("color").rgba()) |
| | params.set_param("gridColor", color) |
| |
|
| |
|
| | Gui.addCommand("Draft_SelectPlane", Draft_SelectPlane()) |
| |
|
| | |
| |
|