FreeCAD

Форк
0
115 строк · 4.9 Кб
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 split line and wire objects."""
26
## @package gui_split
27
# \ingroup draftguitools
28
# \brief Provides GUI tools to split line and wire objects.
29

30
## \addtogroup draftguitools
31
# @{
32
from PySide.QtCore import QT_TRANSLATE_NOOP
33

34
import FreeCAD as App
35
import FreeCADGui as Gui
36
import Draft_rc
37
import DraftVecUtils
38
import draftguitools.gui_base_original as gui_base_original
39
import draftguitools.gui_tool_utils as gui_tool_utils
40

41
from draftutils.messages import _toolmsg
42
from draftutils.translate import translate
43

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

47

48
class Split(gui_base_original.Modifier):
49
    """Gui Command for the Split tool."""
50

51
    def GetResources(self):
52
        """Set icon, menu and tooltip."""
53

54
        return {'Pixmap': 'Draft_Split',
55
                'Accel': "S, P",
56
                'MenuText': QT_TRANSLATE_NOOP("Draft_Split", "Split"),
57
                'ToolTip': QT_TRANSLATE_NOOP("Draft_Split", "Splits the selected line or polyline into two independent lines\nor polylines by clicking anywhere along the original object.\nIt works best when choosing a point on a straight segment and not a corner vertex.")}
58

59
    def Activated(self):
60
        """Execute when the command is called."""
61
        super(Split, self).Activated(name="Split")
62
        if not self.ui:
63
            return
64
        _toolmsg(translate("draft", "Click anywhere on a line to split it."))
65
        self.call = self.view.addEventCallback("SoEvent", self.action)
66

67
    def action(self, arg):
68
        """Handle the 3D scene events.
69

70
        This is installed as an EventCallback in the Inventor view.
71

72
        Parameters
73
        ----------
74
        arg: dict
75
            Dictionary with strings that indicates the type of event received
76
            from the 3D view.
77
        """
78
        if arg["Type"] == "SoKeyboardEvent":
79
            if arg["Key"] == "ESCAPE":
80
                self.finish()
81
        elif arg["Type"] == "SoLocation2Event":
82
            gui_tool_utils.getPoint(self, arg)
83
            gui_tool_utils.redraw3DView()
84
        elif (arg["Type"] == "SoMouseButtonEvent"
85
              and arg["Button"] == "BUTTON1"
86
              and arg["State"] == "DOWN"):
87
            self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg)
88
            if "Edge" in info["Component"]:
89
                return self.proceed(info)
90

91
    def proceed(self, info):
92
        """Proceed with execution of the command after click on an edge."""
93
        self.end_callbacks(self.call)
94
        wire = App.ActiveDocument.getObject(info["Object"])
95
        edge_index = int(info["Component"][4:])
96

97
        Gui.addModule("Draft")
98
        _cmd = "Draft.split"
99
        _cmd += "("
100
        _cmd += "FreeCAD.ActiveDocument." + wire.Name + ", "
101
        _cmd += DraftVecUtils.toString(self.point) + ", "
102
        _cmd += str(edge_index)
103
        _cmd += ")"
104
        _cmd_list = ["s = " + _cmd,
105
                     "FreeCAD.ActiveDocument.recompute()"]
106

107
        self.commit(translate("draft", "Split line"),
108
                    _cmd_list)
109

110
        self.finish()
111

112

113
Gui.addCommand('Draft_Split', Split())
114

115
## @}
116

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

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

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

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