FreeCAD
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# @{
32from PySide.QtCore import QT_TRANSLATE_NOOP
33
34import FreeCAD as App
35import FreeCADGui as Gui
36import Draft_rc
37import DraftVecUtils
38import draftguitools.gui_base_original as gui_base_original
39import draftguitools.gui_tool_utils as gui_tool_utils
40
41from draftutils.messages import _toolmsg
42from draftutils.translate import translate
43
44# The module is used to prevent complaints from code checkers (flake8)
45True if Draft_rc.__name__ else False
46
47
48class Split(gui_base_original.Modifier):
49"""Gui Command for the Split tool."""
50
51def GetResources(self):
52"""Set icon, menu and tooltip."""
53
54return {'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
59def Activated(self):
60"""Execute when the command is called."""
61super(Split, self).Activated(name="Split")
62if not self.ui:
63return
64_toolmsg(translate("draft", "Click anywhere on a line to split it."))
65self.call = self.view.addEventCallback("SoEvent", self.action)
66
67def action(self, arg):
68"""Handle the 3D scene events.
69
70This is installed as an EventCallback in the Inventor view.
71
72Parameters
73----------
74arg: dict
75Dictionary with strings that indicates the type of event received
76from the 3D view.
77"""
78if arg["Type"] == "SoKeyboardEvent":
79if arg["Key"] == "ESCAPE":
80self.finish()
81elif arg["Type"] == "SoLocation2Event":
82gui_tool_utils.getPoint(self, arg)
83gui_tool_utils.redraw3DView()
84elif (arg["Type"] == "SoMouseButtonEvent"
85and arg["Button"] == "BUTTON1"
86and arg["State"] == "DOWN"):
87self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg)
88if "Edge" in info["Component"]:
89return self.proceed(info)
90
91def proceed(self, info):
92"""Proceed with execution of the command after click on an edge."""
93self.end_callbacks(self.call)
94wire = App.ActiveDocument.getObject(info["Object"])
95edge_index = int(info["Component"][4:])
96
97Gui.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
107self.commit(translate("draft", "Split line"),
108_cmd_list)
109
110self.finish()
111
112
113Gui.addCommand('Draft_Split', Split())
114
115## @}
116