FreeCAD

Форк
0
162 строки · 7.0 Кб
1
# ***************************************************************************
2
# *   (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net>                  *
3
# *   (c) 2009, 2010 Ken Cline <cline@frii.com>                             *
4
# *   (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de>           *
5
# *                                                                         *
6
# *   This file is part of the FreeCAD CAx development system.              *
7
# *                                                                         *
8
# *   This program is free software; you can redistribute it and/or modify  *
9
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
10
# *   as published by the Free Software Foundation; either version 2 of     *
11
# *   the License, or (at your option) any later version.                   *
12
# *   for detail see the LICENCE text file.                                 *
13
# *                                                                         *
14
# *   FreeCAD is distributed in the hope that it will be useful,            *
15
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
16
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
17
# *   GNU Library General Public License for more details.                  *
18
# *                                                                         *
19
# *   You should have received a copy of the GNU Library General Public     *
20
# *   License along with FreeCAD; if not, write to the Free Software        *
21
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
22
# *   USA                                                                   *
23
# *                                                                         *
24
# ***************************************************************************
25
"""Provides GUI tools to create simple Point objects.
26

27
A point is just a simple vertex with a position in 3D space.
28

29
Its visual properties can be changed, like display size on screen
30
and color.
31
"""
32
## @package gui_points
33
# \ingroup draftguitools
34
# \brief Provides GUI tools to create simple Point objects.
35

36
## \addtogroup draftguitools
37
# @{
38
import pivy.coin as coin
39
from PySide.QtCore import QT_TRANSLATE_NOOP
40

41
import FreeCAD as App
42
import FreeCADGui as Gui
43
import Draft_rc
44
from draftguitools import gui_base_original
45
from draftutils import gui_utils
46
from draftutils import params
47
from draftutils import todo
48
from draftutils import utils
49
from draftutils.translate import translate
50

51
# The module is used to prevent complaints from code checkers (flake8)
52
True if Draft_rc.__name__ else False
53

54

55
class Point(gui_base_original.Creator):
56
    """Gui Command for the Point tool."""
57

58
    def GetResources(self):
59
        """Set icon, menu and tooltip."""
60

61
        return {'Pixmap': 'Draft_Point',
62
                'MenuText': QT_TRANSLATE_NOOP("Draft_Point", "Point"),
63
                'ToolTip': QT_TRANSLATE_NOOP("Draft_Point", "Creates a point object. Click anywhere on the 3D view.")}
64

65
    def Activated(self):
66
        """Execute when the command is called."""
67
        super().Activated(name="Point")
68
        if self.ui:
69
            self.ui.pointUi(title=translate("draft", self.featureName), icon="Draft_Point")
70
            self.ui.isRelative.hide()
71
            self.ui.continueCmd.show()
72
        # adding 2 callback functions
73
        self.callbackClick = self.view.addEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.click)
74
        self.callbackMove = self.view.addEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.move)
75

76
    def move(self, event_cb):
77
        """Execute as a callback when the pointer moves in the 3D view.
78

79
        It should automatically update the coordinates in the widgets
80
        of the task panel.
81
        """
82
        event = event_cb.getEvent()
83
        mousepos = event.getPosition().getValue()
84
        ctrl = event.wasCtrlDown()
85
        self.point = Gui.Snapper.snap(mousepos, active=ctrl)
86
        if self.ui:
87
            self.ui.displayPoint(self.point)
88

89
    def numericInput(self, numx, numy, numz):
90
        """Validate the entry fields in the user interface.
91

92
        This function is called by the toolbar or taskpanel interface
93
        when valid x, y, and z have been entered in the input fields.
94
        """
95
        self.point = App.Vector(numx, numy, numz)
96
        self.click()
97

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

101
        It should act as if the Enter key was pressed, or the OK button
102
        was pressed in the task panel.
103
        """
104
        if event_cb:
105
            event = event_cb.getEvent()
106
            if (event.getState() != coin.SoMouseButtonEvent.DOWN or
107
                event.getButton() != event.BUTTON1):
108
                return
109
        if self.point:
110
            Gui.addModule("Draft")
111
            if params.get_param("UsePartPrimitives"):
112
                # Insert a Part::Primitive object
113
                _cmd = 'FreeCAD.ActiveDocument.'
114
                _cmd += 'addObject("Part::Vertex", "Point")'
115
                _cmd_list = ['point = ' + _cmd,
116
                             'point.X = ' + str(self.point[0]),
117
                             'point.Y = ' + str(self.point[1]),
118
                             'point.Z = ' + str(self.point[2]),
119
                             'Draft.autogroup(point)',
120
                             'Draft.select(point)',
121
                             'FreeCAD.ActiveDocument.recompute()']
122
                self.commit(translate("draft", "Create Point"), _cmd_list)
123
            else:
124
                # Insert a Draft point
125
                _cmd = 'Draft.make_point'
126
                _cmd += '('
127
                _cmd += str(self.point[0]) + ', '
128
                _cmd += str(self.point[1]) + ', '
129
                _cmd += str(self.point[2])
130
                _cmd += ')'
131
                _cmd_list = ['point = ' + _cmd,
132
                             'Draft.autogroup(point)',
133
                             'FreeCAD.ActiveDocument.recompute()']
134
                self.commit(translate("draft", "Create Point"), _cmd_list)
135
            self.finish(cont=None)
136

137
    def finish(self, cont=False):
138
        """Terminate the operation.
139

140
        Parameters
141
        ----------
142
        cont: bool or None, optional
143
            Restart (continue) the command if `True`, or if `None` and
144
            `ui.continueMode` is `True`.
145
        """
146
        if self.callbackClick:
147
            self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
148
        if self.callbackMove:
149
            self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
150
        if self.callbackClick or self.callbackMove:
151
            # Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
152
            gui_utils.end_all_events()
153
        self.callbackClick = None
154
        self.callbackMove = None
155
        super().finish()
156
        if cont or (cont is None and self.ui and self.ui.continueMode):
157
            self.Activated()
158

159

160
Gui.addCommand('Draft_Point', Point())
161

162
## @}
163

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

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

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

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