FreeCAD
117 строк · 5.3 Кб
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 project an object into a 2D plane.
26
27This creates a 2D shape in the 3D view itself. This projection
28can be further used to create a technical drawing using
29the TechDraw Workbench.
30"""
31## @package gui_shape2dview
32# \ingroup draftguitools
33# \brief Provides GUI tools to project an object into a 2D plane.
34
35## \addtogroup draftguitools
36# @{
37from PySide.QtCore import QT_TRANSLATE_NOOP38
39import FreeCADGui as Gui40import DraftVecUtils41import Draft_rc42import draftguitools.gui_base_original as gui_base_original43import draftguitools.gui_tool_utils as gui_tool_utils44
45from draftutils.messages import _msg46from draftutils.translate import translate47
48# The module is used to prevent complaints from code checkers (flake8)
49True if Draft_rc.__name__ else False50
51
52class Shape2DView(gui_base_original.Modifier):53"""Gui Command for the Shape2DView tool."""54
55def GetResources(self):56"""Set icon, menu and tooltip."""57
58return {'Pixmap': 'Draft_2DShapeView',59'MenuText': QT_TRANSLATE_NOOP("Draft_Shape2DView", "Shape 2D view"),60'ToolTip': QT_TRANSLATE_NOOP("Draft_Shape2DView", "Creates a 2D projection of the selected objects on the XY plane.\nThe initial projection direction is the negative of the current active view direction.\nYou can select individual faces to project, or the entire solid, and also include hidden lines.\nThese projections can be used to create technical drawings with the TechDraw Workbench.")}61
62def Activated(self):63"""Execute when the command is called."""64super().Activated(name="Project 2D view")65if not self.ui:66return67if not Gui.Selection.getSelection():68self.ui.selectUi(on_close_call=self.finish)69_msg(translate("draft", "Select an object to project"))70self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)71else:72self.proceed()73
74def proceed(self):75"""Proceed with the command if one object was selected."""76if self.call is not None:77self.end_callbacks(self.call)78faces = []79objs = []80vec = Gui.ActiveDocument.ActiveView.getViewDirection().negative()81sel = Gui.Selection.getSelectionEx()82for s in sel:83objs.append(s.Object)84for e in s.SubElementNames:85if "Face" in e:86faces.append(int(e[4:]) - 1)87# print(objs, faces)88commitlist = []89Gui.addModule("Draft")90if len(objs) == 1 and faces:91_cmd = "Draft.make_shape2dview"92_cmd += "("93_cmd += "FreeCAD.ActiveDocument." + objs[0].Name + ", "94_cmd += DraftVecUtils.toString(vec) + ", "95_cmd += "facenumbers=" + str(faces)96_cmd += ")"97commitlist.append("sv = " + _cmd)98else:99n = 0100for o in objs:101_cmd = "Draft.make_shape2dview"102_cmd += "("103_cmd += "FreeCAD.ActiveDocument." + o.Name + ", "104_cmd += DraftVecUtils.toString(vec)105_cmd += ")"106commitlist.append("sv" + str(n) + " = " + _cmd)107n += 1108if commitlist:109commitlist.append("FreeCAD.ActiveDocument.recompute()")110self.commit(translate("draft", "Create 2D view"),111commitlist)112self.finish()113
114
115Gui.addCommand('Draft_Shape2DView', Shape2DView())116
117## @}
118