| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | """Provides GUI tools to create polar Array objects.""" |
| | |
| | |
| | |
| |
|
| | |
| | |
| | from pivy import coin |
| | from PySide.QtCore import QT_TRANSLATE_NOOP |
| |
|
| | import FreeCAD as App |
| | import FreeCADGui as Gui |
| | from draftguitools import gui_base |
| | from draftutils import gui_utils |
| | from drafttaskpanels import task_polararray |
| |
|
| |
|
| | class PolarArray(gui_base.GuiCommandBase): |
| | """Gui command for the PolarArray tool.""" |
| |
|
| | def __init__(self): |
| | super().__init__(name="PolarArray") |
| | self.location = None |
| | self.mouse_event = None |
| | self.callback_move = None |
| | self.callback_click = None |
| | self.ui = None |
| | self.point = App.Vector() |
| |
|
| | def GetResources(self): |
| | """Set icon, menu and tooltip.""" |
| | return { |
| | "Pixmap": "Draft_PolarArray", |
| | "MenuText": QT_TRANSLATE_NOOP("Draft_PolarArray", "Polar Array"), |
| | "ToolTip": QT_TRANSLATE_NOOP( |
| | "Draft_PolarArray", "Creates copies of the selected object in a polar pattern" |
| | ), |
| | } |
| |
|
| | def Activated(self): |
| | """Execute when the command is called. |
| | |
| | We add callbacks that connect the 3D view with |
| | the widgets of the task panel. |
| | """ |
| | super().Activated() |
| |
|
| | self.location = coin.SoLocation2Event.getClassTypeId() |
| | self.mouse_event = coin.SoMouseButtonEvent.getClassTypeId() |
| | self.callback_move = self.view.addEventCallbackPivy(self.location, self.move) |
| | self.callback_click = self.view.addEventCallbackPivy(self.mouse_event, self.click) |
| |
|
| | self.ui = task_polararray.TaskPanelPolarArray() |
| | |
| | |
| | self.ui.source_command = self |
| | task = Gui.Control.showDialog(self.ui) |
| | task.setDocumentName(Gui.ActiveDocument.Document.Name) |
| | task.setAutoCloseOnDeletedDocument(True) |
| |
|
| | def move(self, event_cb): |
| | """Execute as a callback when the pointer moves in the 3D view. |
| | |
| | It should automatically update the coordinates in the widgets |
| | of the task panel. |
| | """ |
| | event = event_cb.getEvent() |
| | mousepos = event.getPosition().getValue() |
| | ctrl = event.wasCtrlDown() |
| | self.point = Gui.Snapper.snap(mousepos, active=ctrl) |
| | if self.ui: |
| | self.ui.display_point(self.point) |
| |
|
| | def click(self, event_cb=None): |
| | """Execute as a callback when the pointer clicks on the 3D view. |
| | |
| | It should act as if the Enter key was pressed, or the OK button |
| | was pressed in the task panel. |
| | """ |
| | if event_cb: |
| | event = event_cb.getEvent() |
| | if ( |
| | event.getState() != coin.SoMouseButtonEvent.DOWN |
| | or event.getButton() != coin.SoMouseButtonEvent.BUTTON1 |
| | ): |
| | return |
| | if self.ui and self.point: |
| | |
| | |
| | |
| | self.ui.accept() |
| |
|
| | def completed(self): |
| | """Execute when the command is terminated. |
| | |
| | We should remove the callbacks that were added to the 3D view |
| | and then close the task panel. |
| | """ |
| | try: |
| | self.view.removeEventCallbackPivy(self.location, self.callback_move) |
| | self.view.removeEventCallbackPivy(self.mouse_event, self.callback_click) |
| | gui_utils.end_all_events() |
| | except RuntimeError: |
| | |
| | pass |
| | self.callback_move = None |
| | self.callback_click = None |
| | if Gui.Control.activeDialog(): |
| | Gui.Control.closeDialog() |
| | self.finish() |
| |
|
| |
|
| | Gui.addCommand("Draft_PolarArray", PolarArray()) |
| |
|
| | |
| |
|