FreeCAD
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
27These tools work on polylines and B-splines which have multiple points.
28
29Essentially, the points of the original object are extracted
30and passed to the `make_wire` or `make_bspline` functions,
31depending 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# @{
39from PySide.QtCore import QT_TRANSLATE_NOOP40
41import FreeCADGui as Gui42import Draft_rc43import Draft44import draftutils.utils as utils45import draftguitools.gui_base_original as gui_base_original46
47from draftutils.translate import translate48
49# The module is used to prevent complaints from code checkers (flake8)
50True if Draft_rc.__name__ else False51
52
53class WireToBSpline(gui_base_original.Modifier):54"""Gui Command for the Wire to BSpline tool."""55
56def __init__(self):57super().__init__()58self.running = False59
60def GetResources(self):61"""Set icon, menu and tooltip."""62
63return {'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
67def Activated(self):68"""Execute when the command is called."""69if self.running:70self.finish()71
72# TODO: iterate over all selected items to transform73# many objects. As it is right now, it only works on the first object74# in the selection.75# Also, it is recommended to use the `self.commit` function76# in order to properly open a transaction and commit it.77selection = Gui.Selection.getSelection()78if selection:79if utils.getType(selection[0]) in ['Wire', 'BSpline']:80super(WireToBSpline, self).Activated(name="Convert polyline/B-spline")81if self.doc:82self.obj = Gui.Selection.getSelection()83if self.obj:84self.obj = self.obj[0]85self.pl = None86if "Placement" in self.obj.PropertiesList:87self.pl = self.obj.Placement88self.Points = self.obj.Points89self.closed = self.obj.Closed90n = None91if utils.getType(self.obj) == 'Wire':92n = Draft.make_bspline(self.Points,93closed=self.closed,94placement=self.pl)95elif utils.getType(self.obj) == 'BSpline':96self.bs2wire = True97n = Draft.make_wire(self.Points,98closed=self.closed,99placement=self.pl,100face=None,101support=None,102bs2wire=self.bs2wire)103if n:104Draft.formatObject(n, self.obj)105self.doc.recompute()106else:107self.finish()108
109
110Gui.addCommand('Draft_WireToBSpline', WireToBSpline())111
112## @}
113