diff --git a/src/Mod/Part/BasicShapes/CommandShapes.py b/src/Mod/Part/BasicShapes/CommandShapes.py new file mode 100644 index 0000000000..b49e00b1df --- /dev/null +++ b/src/Mod/Part/BasicShapes/CommandShapes.py @@ -0,0 +1,62 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2020 Werner Mayer * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "BasicShapes.CommandShapes" +__author__ = "Werner Mayer" +__url__ = "http://www.freecadweb.org" +__doc__ = "Basic shapes" + + +import FreeCAD +from FreeCAD import Qt +import FreeCADGui + +import Part +from . import Shapes +from . import ViewProviderShapes +import math +import sys + + + +class CommandTube: + """Command for creating Tube.""" + def GetResources(self): + return {'MenuText': Qt.QT_TRANSLATE_NOOP("Part_Tube","Create tube"), + 'Accel': "", + 'CmdType': "AlterDoc:Alter3DView:AlterSelection", + 'Pixmap': "Part_Tube", + 'ToolTip': Qt.QT_TRANSLATE_NOOP("Part_Tube","Creates a tube")} + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create tube") + tube = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Tube") + Shapes.TubeFeature(tube) + ViewProviderShapes.ViewProviderTube(tube.ViewObject) + FreeCAD.ActiveDocument.commitTransaction() + FreeCAD.ActiveDocument.recompute() + + def IsActive(self): + return not FreeCAD.ActiveDocument is None + + +FreeCADGui.addCommand('Part_Tube', CommandTube()) diff --git a/src/Mod/Part/BasicShapes/Shapes.py b/src/Mod/Part/BasicShapes/Shapes.py index 0607ead9ae..a8140b6074 100644 --- a/src/Mod/Part/BasicShapes/Shapes.py +++ b/src/Mod/Part/BasicShapes/Shapes.py @@ -26,11 +26,7 @@ __url__ = "http://www.freecadweb.org" __doc__ = "Basic shapes" -import FreeCAD -from FreeCAD import Qt import Part -import math -import sys def makeTube(outerRadius, innerRadius, height): outer_cylinder = Part.makeCylinder(outerRadius, height) @@ -53,52 +49,3 @@ class TubeFeature: if fp.InnerRadius >= fp.OuterRadius: raise ValueError("Inner radius must be smaller than outer radius") fp.Shape = makeTube(fp.OuterRadius, fp.InnerRadius, fp.Height) - - -# Only if GUI is running -if FreeCAD.GuiUp: - import FreeCADGui - - - class ViewProviderTube: - def __init__(self, obj): - ''' Set this object to the proxy object of the actual view provider ''' - obj.Proxy = self - - def attach(self, obj): - ''' Setup the scene sub-graph of the view provider, this method is mandatory ''' - return - - def getIcon(self): - return ":/icons/parametric/Part_Tube_Parametric.svg" - - def __getstate__(self): - return None - - def __setstate__(self,state): - return None - - - class CommandTube: - """Command for creating Tube.""" - def GetResources(self): - return {'MenuText': Qt.QT_TRANSLATE_NOOP("Part_Tube","Create tube"), - 'Accel': "", - 'CmdType': "AlterDoc:Alter3DView:AlterSelection", - 'Pixmap': "Part_Tube", - 'ToolTip': Qt.QT_TRANSLATE_NOOP("Part_Tube","Creates a tube")} - - def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create tube") - tube = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Tube") - TubeFeature(tube) - ViewProviderTube(tube.ViewObject) - FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() - - def IsActive(self): - return not FreeCAD.ActiveDocument is None - - - FreeCADGui.addCommand('Part_Tube', CommandTube()) - diff --git a/src/Mod/Part/BasicShapes/ViewProviderShapes.py b/src/Mod/Part/BasicShapes/ViewProviderShapes.py new file mode 100644 index 0000000000..540063195a --- /dev/null +++ b/src/Mod/Part/BasicShapes/ViewProviderShapes.py @@ -0,0 +1,46 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2020 Werner Mayer * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "BasicShapes.ViewProviderShapes" +__author__ = "Werner Mayer" +__url__ = "http://www.freecadweb.org" +__doc__ = "Basic shapes" + + + +class ViewProviderTube: + def __init__(self, obj): + ''' Set this object to the proxy object of the actual view provider ''' + obj.Proxy = self + + def attach(self, obj): + ''' Setup the scene sub-graph of the view provider, this method is mandatory ''' + return + + def getIcon(self): + return ":/icons/parametric/Part_Tube_Parametric.svg" + + def __getstate__(self): + return None + + def __setstate__(self,state): + return None diff --git a/src/Mod/Part/CMakeLists.txt b/src/Mod/Part/CMakeLists.txt index 3e69359e06..77a8a82b24 100644 --- a/src/Mod/Part/CMakeLists.txt +++ b/src/Mod/Part/CMakeLists.txt @@ -31,6 +31,13 @@ set(BasicShapes_Scripts BasicShapes/Shapes.py ) +if(BUILD_GUI) + list (APPEND BasicShapes_Scripts + BasicShapes/CommandShapes.py + BasicShapes/ViewProviderShapes.py + ) +endif(BUILD_GUI) + set(BOPTools_Scripts BOPTools/__init__.py BOPTools/GeneralFuseResult.py diff --git a/src/Mod/Part/InitGui.py b/src/Mod/Part/InitGui.py index 866f1fdf12..5e3fecaea6 100644 --- a/src/Mod/Part/InitGui.py +++ b/src/Mod/Part/InitGui.py @@ -43,7 +43,7 @@ class PartWorkbench(Gui.Workbench): import PartGui try: - import BasicShapes.Shapes + import BasicShapes.CommandShapes except ImportError as err: App.Console.PrintError("'BasicShapes' package cannot be loaded. " "{err}\n".format(err=str(err)))