FreeCAD

Форк
0
/
gui_polararray.py 
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
# @{
30
from pivy import coin
31
from PySide.QtCore import QT_TRANSLATE_NOOP
32

33
import FreeCAD as App
34
import FreeCADGui as Gui
35
import Draft
36
import Draft_rc  # include resources, icons, ui files
37
from draftguitools import gui_base
38
from draftutils import gui_utils
39
from draftutils import todo
40
from draftutils.messages import _log
41
from draftutils.translate import translate
42
from drafttaskpanels import task_polararray
43

44
# The module is used to prevent complaints from code checkers (flake8)
45
bool(Draft_rc.__name__)
46

47

48
class PolarArray(gui_base.GuiCommandBase):
49
    """Gui command for the PolarArray tool."""
50

51
    def __init__(self):
52
        super().__init__()
53
        self.command_name = "Polar array"
54
        self.location = None
55
        self.mouse_event = None
56
        self.view = None
57
        self.callback_move = None
58
        self.callback_click = None
59
        self.ui = None
60
        self.point = App.Vector()
61

62
    def GetResources(self):
63
        """Set icon, menu and tooltip."""
64
        return {'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

68
    def Activated(self):
69
        """Execute when the command is called.
70

71
        We add callbacks that connect the 3D view with
72
        the widgets of the task panel.
73
        """
74
        _log("GuiCommand: {}".format(self.command_name))
75

76
        self.location = coin.SoLocation2Event.getClassTypeId()
77
        self.mouse_event = coin.SoMouseButtonEvent.getClassTypeId()
78
        self.view = Draft.get3DView()
79
        self.callback_move = \
80
            self.view.addEventCallbackPivy(self.location, self.move)
81
        self.callback_click = \
82
            self.view.addEventCallbackPivy(self.mouse_event, self.click)
83

84
        self.ui = task_polararray.TaskPanelPolarArray()
85
        # The calling class (this one) is saved in the object
86
        # of the interface, to be able to call a function from within it.
87
        self.ui.source_command = self
88
        # Gui.Control.showDialog(self.ui)
89
        todo.ToDo.delay(Gui.Control.showDialog, self.ui)
90

91
    def move(self, event_cb):
92
        """Execute as a callback when the pointer moves in the 3D view.
93

94
        It should automatically update the coordinates in the widgets
95
        of the task panel.
96
        """
97
        event = event_cb.getEvent()
98
        mousepos = event.getPosition().getValue()
99
        ctrl = event.wasCtrlDown()
100
        self.point = Gui.Snapper.snap(mousepos, active=ctrl)
101
        if self.ui:
102
            self.ui.display_point(self.point)
103

104
    def click(self, event_cb=None):
105
        """Execute as a callback when the pointer clicks on the 3D view.
106

107
        It should act as if the Enter key was pressed, or the OK button
108
        was pressed in the task panel.
109
        """
110
        if event_cb:
111
            event = event_cb.getEvent()
112
            if (event.getState() != coin.SoMouseButtonEvent.DOWN
113
                    or event.getButton() != coin.SoMouseButtonEvent.BUTTON1):
114
                return
115
        if self.ui and self.point:
116
            # The accept function of the interface
117
            # should call the completed function
118
            # of the calling class (this one).
119
            self.ui.accept()
120

121
    def completed(self):
122
        """Execute when the command is terminated.
123

124
        We should remove the callbacks that were added to the 3D view
125
        and then close the task panel.
126
        """
127
        self.view.removeEventCallbackPivy(self.location,
128
                                          self.callback_move)
129
        self.view.removeEventCallbackPivy(self.mouse_event,
130
                                          self.callback_click)
131
        gui_utils.end_all_events()
132
        if Gui.Control.activeDialog():
133
            Gui.Control.closeDialog()
134
            self.finish()
135

136

137
Gui.addCommand('Draft_PolarArray', PolarArray())
138

139
## @}
140

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.