FreeCAD

Форк
0
/
gui_shape2dview.py 
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

27
This creates a 2D shape in the 3D view itself. This projection
28
can be further used to create a technical drawing using
29
the 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
# @{
37
from PySide.QtCore import QT_TRANSLATE_NOOP
38

39
import FreeCADGui as Gui
40
import DraftVecUtils
41
import Draft_rc
42
import draftguitools.gui_base_original as gui_base_original
43
import draftguitools.gui_tool_utils as gui_tool_utils
44

45
from draftutils.messages import _msg
46
from draftutils.translate import translate
47

48
# The module is used to prevent complaints from code checkers (flake8)
49
True if Draft_rc.__name__ else False
50

51

52
class Shape2DView(gui_base_original.Modifier):
53
    """Gui Command for the Shape2DView tool."""
54

55
    def GetResources(self):
56
        """Set icon, menu and tooltip."""
57

58
        return {'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

62
    def Activated(self):
63
        """Execute when the command is called."""
64
        super().Activated(name="Project 2D view")
65
        if not self.ui:
66
            return
67
        if not Gui.Selection.getSelection():
68
            self.ui.selectUi(on_close_call=self.finish)
69
            _msg(translate("draft", "Select an object to project"))
70
            self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)
71
        else:
72
            self.proceed()
73

74
    def proceed(self):
75
        """Proceed with the command if one object was selected."""
76
        if self.call is not None:
77
            self.end_callbacks(self.call)
78
        faces = []
79
        objs = []
80
        vec = Gui.ActiveDocument.ActiveView.getViewDirection().negative()
81
        sel = Gui.Selection.getSelectionEx()
82
        for s in sel:
83
            objs.append(s.Object)
84
            for e in s.SubElementNames:
85
                if "Face" in e:
86
                    faces.append(int(e[4:]) - 1)
87
        # print(objs, faces)
88
        commitlist = []
89
        Gui.addModule("Draft")
90
        if 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 += ")"
97
            commitlist.append("sv = " + _cmd)
98
        else:
99
            n = 0
100
            for o in objs:
101
                _cmd = "Draft.make_shape2dview"
102
                _cmd += "("
103
                _cmd += "FreeCAD.ActiveDocument." + o.Name + ", "
104
                _cmd += DraftVecUtils.toString(vec)
105
                _cmd += ")"
106
                commitlist.append("sv" + str(n) + " = " + _cmd)
107
                n += 1
108
        if commitlist:
109
            commitlist.append("FreeCAD.ActiveDocument.recompute()")
110
            self.commit(translate("draft", "Create 2D view"),
111
                        commitlist)
112
        self.finish()
113

114

115
Gui.addCommand('Draft_Shape2DView', Shape2DView())
116

117
## @}
118

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

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

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

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