FreeCAD
139 строк · 5.9 Кб
1# ***************************************************************************
2# * (c) 2019 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
3# * *
4# * This file is part of the FreeCAD CAx development system. *
5# * *
6# * This program is free software; you can redistribute it and/or modify *
7# * it under the terms of the GNU Lesser General Public License (LGPL) *
8# * as published by the Free Software Foundation; either version 2 of *
9# * the License, or (at your option) any later version. *
10# * for detail see the LICENCE text file. *
11# * *
12# * FreeCAD is distributed in the hope that it will be useful, *
13# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15# * GNU Library General Public License for more details. *
16# * *
17# * You should have received a copy of the GNU Library General Public *
18# * License along with FreeCAD; if not, write to the Free Software *
19# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
20# * USA *
21# * *
22# ***************************************************************************
23"""Provides GUI tools to create polar Array objects."""
24## @package gui_polararray
25# \ingroup draftguitools
26# \brief Provides GUI tools to create polar Array objects.
27
28## \addtogroup draftguitools
29# @{
30from pivy import coin31from PySide.QtCore import QT_TRANSLATE_NOOP32
33import FreeCAD as App34import FreeCADGui as Gui35import Draft36import Draft_rc # include resources, icons, ui files37from draftguitools import gui_base38from draftutils import gui_utils39from draftutils import todo40from draftutils.messages import _log41from draftutils.translate import translate42from drafttaskpanels import task_polararray43
44# The module is used to prevent complaints from code checkers (flake8)
45bool(Draft_rc.__name__)46
47
48class PolarArray(gui_base.GuiCommandBase):49"""Gui command for the PolarArray tool."""50
51def __init__(self):52super().__init__()53self.command_name = "Polar array"54self.location = None55self.mouse_event = None56self.view = None57self.callback_move = None58self.callback_click = None59self.ui = None60self.point = App.Vector()61
62def GetResources(self):63"""Set icon, menu and tooltip."""64return {'Pixmap': 'Draft_PolarArray',65'MenuText': QT_TRANSLATE_NOOP("Draft_PolarArray", "Polar array"),66'ToolTip': QT_TRANSLATE_NOOP("Draft_PolarArray", "Creates copies of the selected object, and places the copies in a polar pattern\ndefined by a center of rotation and its angle.\n\nThe array can be turned into an orthogonal or a circular array by changing its type.")}67
68def Activated(self):69"""Execute when the command is called.70
71We add callbacks that connect the 3D view with
72the widgets of the task panel.
73"""
74_log("GuiCommand: {}".format(self.command_name))75
76self.location = coin.SoLocation2Event.getClassTypeId()77self.mouse_event = coin.SoMouseButtonEvent.getClassTypeId()78self.view = Draft.get3DView()79self.callback_move = \80self.view.addEventCallbackPivy(self.location, self.move)81self.callback_click = \82self.view.addEventCallbackPivy(self.mouse_event, self.click)83
84self.ui = task_polararray.TaskPanelPolarArray()85# The calling class (this one) is saved in the object86# of the interface, to be able to call a function from within it.87self.ui.source_command = self88# Gui.Control.showDialog(self.ui)89todo.ToDo.delay(Gui.Control.showDialog, self.ui)90
91def move(self, event_cb):92"""Execute as a callback when the pointer moves in the 3D view.93
94It should automatically update the coordinates in the widgets
95of the task panel.
96"""
97event = event_cb.getEvent()98mousepos = event.getPosition().getValue()99ctrl = event.wasCtrlDown()100self.point = Gui.Snapper.snap(mousepos, active=ctrl)101if self.ui:102self.ui.display_point(self.point)103
104def click(self, event_cb=None):105"""Execute as a callback when the pointer clicks on the 3D view.106
107It should act as if the Enter key was pressed, or the OK button
108was pressed in the task panel.
109"""
110if event_cb:111event = event_cb.getEvent()112if (event.getState() != coin.SoMouseButtonEvent.DOWN113or event.getButton() != coin.SoMouseButtonEvent.BUTTON1):114return115if self.ui and self.point:116# The accept function of the interface117# should call the completed function118# of the calling class (this one).119self.ui.accept()120
121def completed(self):122"""Execute when the command is terminated.123
124We should remove the callbacks that were added to the 3D view
125and then close the task panel.
126"""
127self.view.removeEventCallbackPivy(self.location,128self.callback_move)129self.view.removeEventCallbackPivy(self.mouse_event,130self.callback_click)131gui_utils.end_all_events()132if Gui.Control.activeDialog():133Gui.Control.closeDialog()134self.finish()135
136
137Gui.addCommand('Draft_PolarArray', PolarArray())138
139## @}
140