FreeCAD

Форк
0
/
gui_wire2spline.py 
112 строк · 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 convert polylines to B-splines and back.
26

27
These tools work on polylines and B-splines which have multiple points.
28

29
Essentially, the points of the original object are extracted
30
and passed to the `make_wire` or `make_bspline` functions,
31
depending on the desired result.
32
"""
33
## @package gui_wire2spline
34
# \ingroup draftguitools
35
# \brief Provides GUI tools to convert polylines to B-splines and back.
36

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

41
import FreeCADGui as Gui
42
import Draft_rc
43
import Draft
44
import draftutils.utils as utils
45
import draftguitools.gui_base_original as gui_base_original
46

47
from draftutils.translate import translate
48

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

52

53
class WireToBSpline(gui_base_original.Modifier):
54
    """Gui Command for the Wire to BSpline tool."""
55

56
    def __init__(self):
57
        super().__init__()
58
        self.running = False
59

60
    def GetResources(self):
61
        """Set icon, menu and tooltip."""
62

63
        return {'Pixmap': 'Draft_WireToBSpline',
64
                'MenuText': QT_TRANSLATE_NOOP("Draft_WireToBSpline", "Wire to B-spline"),
65
                'ToolTip': QT_TRANSLATE_NOOP("Draft_WireToBSpline", "Converts a selected polyline to a B-spline, or a B-spline to a polyline.")}
66

67
    def Activated(self):
68
        """Execute when the command is called."""
69
        if self.running:
70
            self.finish()
71

72
        # TODO: iterate over all selected items to transform
73
        # many objects. As it is right now, it only works on the first object
74
        # in the selection.
75
        # Also, it is recommended to use the `self.commit` function
76
        # in order to properly open a transaction and commit it.
77
        selection = Gui.Selection.getSelection()
78
        if selection:
79
            if utils.getType(selection[0]) in ['Wire', 'BSpline']:
80
                super(WireToBSpline, self).Activated(name="Convert polyline/B-spline")
81
                if self.doc:
82
                    self.obj = Gui.Selection.getSelection()
83
                    if self.obj:
84
                        self.obj = self.obj[0]
85
                        self.pl = None
86
                        if "Placement" in self.obj.PropertiesList:
87
                            self.pl = self.obj.Placement
88
                        self.Points = self.obj.Points
89
                        self.closed = self.obj.Closed
90
                        n = None
91
                        if utils.getType(self.obj) == 'Wire':
92
                            n = Draft.make_bspline(self.Points,
93
                                                   closed=self.closed,
94
                                                   placement=self.pl)
95
                        elif utils.getType(self.obj) == 'BSpline':
96
                            self.bs2wire = True
97
                            n = Draft.make_wire(self.Points,
98
                                                closed=self.closed,
99
                                                placement=self.pl,
100
                                                face=None,
101
                                                support=None,
102
                                                bs2wire=self.bs2wire)
103
                        if n:
104
                            Draft.formatObject(n, self.obj)
105
                            self.doc.recompute()
106
                    else:
107
                        self.finish()
108

109

110
Gui.addCommand('Draft_WireToBSpline', WireToBSpline())
111

112
## @}
113

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

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

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

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