Part: [skip ci] split classes of Shapes.py file into files for feature, view provider and command classes

This commit is contained in:
wmayer
2020-11-12 12:17:47 +01:00
parent a5c80b6eca
commit a8aeb0ce78
5 changed files with 116 additions and 54 deletions

View File

@@ -0,0 +1,62 @@
# ***************************************************************************
# * *
# * Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
# * *
# * 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())

View File

@@ -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())

View File

@@ -0,0 +1,46 @@
# ***************************************************************************
# * *
# * Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
# * *
# * 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

View File

@@ -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

View File

@@ -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)))