+ unify DLL export defines to namespace names
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5000 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
88
src/Mod/TemplatePyMod/Automation.py
Normal file
88
src/Mod/TemplatePyMod/Automation.py
Normal file
@@ -0,0 +1,88 @@
|
||||
# FreeCAD TemplatePyMod module
|
||||
# (c) 2010 Werner Mayer LGPL
|
||||
|
||||
"""
|
||||
The module can be executed with:
|
||||
FreeCAD -P <path_to_file> Automation.py
|
||||
FreeCADCmd -P <path_to_file> Automation.py
|
||||
"""
|
||||
|
||||
import FreeCAD, Part
|
||||
|
||||
def makeSnapshotWithGui():
|
||||
from PyQt4 import QtGui
|
||||
import FreeCADGui
|
||||
|
||||
def getMainWindow():
|
||||
toplevel = QtGui.qApp.topLevelWidgets()
|
||||
for i in toplevel:
|
||||
if i.metaObject().className() == "Gui::MainWindow":
|
||||
return i
|
||||
raise Exception("No main window found")
|
||||
|
||||
mw=getMainWindow()
|
||||
mw.hide()
|
||||
#mw.showMinimized()
|
||||
|
||||
# Create a test geometry and add it to the document
|
||||
obj=Part.makeCone(10,8,10)
|
||||
doc = FreeCAD.newDocument()
|
||||
Part.show(obj)
|
||||
|
||||
# switch off animation so that the camera is moved to the final position immediately
|
||||
view = FreeCADGui.getDocument(doc.Name).activeView()
|
||||
view.setAnimationEnabled(False)
|
||||
view.viewAxometric()
|
||||
view.fitAll()
|
||||
view.saveImage('crystal.png',800,600,'Current')
|
||||
FreeCAD.closeDocument(doc.Name)
|
||||
# close the application
|
||||
QtGui.qApp.quit()
|
||||
|
||||
def makeSnapshotWithoutGui():
|
||||
from pivy import coin
|
||||
|
||||
# create a test geometry and create an IV representation as string
|
||||
box=Part.makeCone(10,8,10)
|
||||
iv=box.writeInventor()
|
||||
|
||||
# load it into a buffer
|
||||
inp=coin.SoInput()
|
||||
inp.setBuffer(iv)
|
||||
|
||||
# and create a scenegraph
|
||||
data = coin.SoDB.readAll(inp)
|
||||
base = coin.SoBaseColor()
|
||||
base.rgb.setValue(0.6,0.7,1.0)
|
||||
data.insertChild(base,0)
|
||||
|
||||
# add light and camera so that the rendered geometry is visible
|
||||
root = coin.SoSeparator()
|
||||
light = coin.SoDirectionalLight()
|
||||
cam = coin.SoOrthographicCamera()
|
||||
root.addChild(cam)
|
||||
root.addChild(light)
|
||||
root.addChild(data)
|
||||
|
||||
# do the rendering now
|
||||
axo = coin.SbRotation(-0.353553, -0.146447, -0.353553, -0.853553)
|
||||
viewport=coin.SbViewportRegion(400,400)
|
||||
cam.orientation.setValue(axo)
|
||||
cam.viewAll(root,viewport)
|
||||
off=coin.SoOffscreenRenderer(viewport)
|
||||
root.ref()
|
||||
off.render(root)
|
||||
root.unref()
|
||||
|
||||
# export the image, PS is always available
|
||||
off.writeToPostScript("crystal.ps")
|
||||
|
||||
# Other formats are only available if simage package is installed
|
||||
if off.isWriteSupported("PNG"):
|
||||
print "Save as PNG"
|
||||
off.writeToFile("crystal.png","PNG")
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
makeSnapshotWithGui()
|
||||
else:
|
||||
makeSnapshotWithoutGui()
|
||||
21
src/Mod/TemplatePyMod/CMakeLists.txt
Normal file
21
src/Mod/TemplatePyMod/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
|
||||
fc_copy_to_mod_path("TemplatePyMod"
|
||||
InitGui.py
|
||||
Init.py
|
||||
Commands.py
|
||||
PythonQt.py
|
||||
Tests.py
|
||||
DocumentObject.py
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
Init.py
|
||||
InitGui.py
|
||||
Commands.py
|
||||
FeaturePython.py
|
||||
PythonQt.py
|
||||
Tests.py
|
||||
DESTINATION
|
||||
Mod/TemplatePyMod)
|
||||
206
src/Mod/TemplatePyMod/Commands.py
Normal file
206
src/Mod/TemplatePyMod/Commands.py
Normal file
@@ -0,0 +1,206 @@
|
||||
# FreeCAD TemplatePyMod module
|
||||
# (c) 2007 Juergen Riegel LGPL
|
||||
|
||||
#
|
||||
|
||||
|
||||
# import FreeCAD modules
|
||||
import FreeCAD, FreeCADGui,inspect
|
||||
|
||||
# helper -------------------------------------------------------------------
|
||||
|
||||
def addCommand(name,cmdObject):
|
||||
(list,num) = inspect.getsourcelines(cmdObject.Activated)
|
||||
pos = 0
|
||||
# check for indentation
|
||||
while(list[1][pos] == ' ' or list[1][pos] == '\t'):
|
||||
pos += 1
|
||||
source = ""
|
||||
for i in range(len(list)-1):
|
||||
source += list[i+1][pos:]
|
||||
FreeCADGui.addCommand(name,cmdObject,source)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# The command classes
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TemplatePyMod_Cmd1:
|
||||
"Example command class"
|
||||
def Activated(self):
|
||||
print "TemplatePyMod_Cmd1 activated ;-) "
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1', 'MenuText': 'Example command', 'ToolTip': 'Very unimportand example command'}
|
||||
|
||||
|
||||
class TemplatePyMod_Cmd2:
|
||||
"Example command class"
|
||||
def Activated(self):
|
||||
d = FreeCAD.ActiveDocument
|
||||
v = FreeCADGui.ActiveDocument.ActiveView
|
||||
class PolygonCreator:
|
||||
def __init__(self, doc, view, max):
|
||||
self.doc = doc
|
||||
self.view = view
|
||||
self.call = view.addEventCallback("SoMouseButtonEvent",self.addVertex)
|
||||
self.max = max
|
||||
self.node=[]
|
||||
self.count=0
|
||||
self.poly=None
|
||||
|
||||
def addVertex(self, d):
|
||||
if (d["State"] == "DOWN"):
|
||||
pos = d["Position"]
|
||||
self.node.append(self.view.getPoint(pos[0],pos[1]))
|
||||
self.count = self.count+1
|
||||
if (self.count == 1):
|
||||
import Part,PartGui
|
||||
self.poly=self.doc.addObject("Part::Polygon","Polygon")
|
||||
self.poly.Nodes = self.node
|
||||
self.poly.Close=True
|
||||
else:
|
||||
self.poly.Nodes = self.node
|
||||
self.doc.recompute()
|
||||
if (self.count == self.max):
|
||||
self.node=[]
|
||||
self.view.removeEventCallback("SoMouseButtonEvent",self.call)
|
||||
|
||||
p=PolygonCreator(d,v,10)
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument == None:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool2', 'MenuText': 'Create polygon...', 'ToolTip': 'Create a polygon by clicking inside the viewer'}
|
||||
|
||||
|
||||
class TemplatePyMod_Cmd3:
|
||||
"Import PyQt4"
|
||||
def Activated(self):
|
||||
import PythonQt
|
||||
from PyQt4 import QtGui
|
||||
mw=QtGui.qApp.activeWindow()
|
||||
QtGui.QMessageBox.information(mw,"PyQt","""PyQt was loaded successfully.\n
|
||||
Load the PyQt sandbox now...""")
|
||||
FreeCADGui.activateWorkbench("PythonQtWorkbench")
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'python', 'MenuText': 'Import PyQt4', 'ToolTip': 'Add a workbench for PyQt4 samples'}
|
||||
|
||||
class SphereCreator:
|
||||
def __init__(self):
|
||||
import Part
|
||||
self.pt = Part
|
||||
self.mode = False
|
||||
FreeCAD.Console.PrintMessage("Create instance of SphereCreator\n")
|
||||
|
||||
def __del__(self):
|
||||
FreeCAD.Console.PrintMessage("Delete instance of SphereCreator\n")
|
||||
|
||||
def enter(self):
|
||||
if (self.mode):
|
||||
return
|
||||
FreeCAD.Console.PrintMessage("Enter sphere creation mode\n")
|
||||
self.av = FreeCADGui.ActiveDocument.ActiveView
|
||||
self.cb = self.av.addEventCallback("SoMouseButtonEvent",self.create)
|
||||
self.ex = self.av.addEventCallback("SoKeyboardEvent",self.exit)
|
||||
self.mode = True
|
||||
|
||||
def leave(self):
|
||||
if (not self.mode):
|
||||
return
|
||||
FreeCAD.Console.PrintMessage("Leave sphere creation mode\n")
|
||||
self.av.removeEventCallback("SoMouseButtonEvent",self.cb)
|
||||
self.av.removeEventCallback("SoKeyboardEvent",self.ex)
|
||||
self.mode = False
|
||||
|
||||
def create(self, info):
|
||||
down = (info["State"] == "DOWN")
|
||||
pos = info["Position"]
|
||||
if (down):
|
||||
pnt = self.av.getPoint(pos[0],pos[1])
|
||||
FreeCAD.Console.PrintMessage("Clicked on position: ("+str(pos[0])+", "+str(pos[0])+")")
|
||||
msg = " -> (%f,%f,%f)\n" % (pnt.x, pnt.y, pnt.z)
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
sph=self.pt.makeSphere(1.0, pnt)
|
||||
self.pt.show(sph)
|
||||
|
||||
def exit(self, info):
|
||||
esc = (info["Key"] == "ESCAPE")
|
||||
if (esc):
|
||||
self.leave()
|
||||
|
||||
|
||||
class TemplatePyMod_Cmd4:
|
||||
def __init__(self):
|
||||
self.sc = SphereCreator()
|
||||
|
||||
def __del__(self):
|
||||
FreeCAD.Console.PrintError('TemplatePyMod_Cmd4 was destroyed\n')
|
||||
|
||||
def Activated(self):
|
||||
if FreeCADGui.ActiveDocument != None:
|
||||
self.sc.enter()
|
||||
else:
|
||||
FreeCAD.Console.PrintWarning('A 3d view must be created\n')
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'python', 'MenuText': 'Create spheres...', 'ToolTip': 'Click on the screen to create a sphere'}
|
||||
|
||||
|
||||
myRenderArea = None
|
||||
class TemplatePyMod_Cmd5:
|
||||
"Example command class"
|
||||
def Activated(self):
|
||||
from pivy.sogui import *
|
||||
from pivy.coin import *
|
||||
|
||||
global myRenderArea
|
||||
if myRenderArea == None:
|
||||
root = SoSeparator()
|
||||
myCamera = SoPerspectiveCamera()
|
||||
myMaterial = SoMaterial()
|
||||
root.addChild(myCamera)
|
||||
root.addChild(SoDirectionalLight())
|
||||
#myMaterial.diffuseColor = (1.0, 0.0, 0.0) # Red
|
||||
root.addChild(myMaterial)
|
||||
root.addChild(SoCone())
|
||||
|
||||
# Create a renderArea in which to see our scene graph.
|
||||
# The render area will appear within the main window.
|
||||
myRenderArea = SoGuiRenderArea()
|
||||
|
||||
# Make myCamera see everything.
|
||||
myCamera.viewAll(root, myRenderArea.getViewportRegion())
|
||||
|
||||
# Put our scene in myRenderArea, change the title
|
||||
myRenderArea.setSceneGraph(root)
|
||||
myRenderArea.setTitle("Hello Cone")
|
||||
myRenderArea.show()
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Std_Tool1', 'MenuText': 'Render area', 'ToolTip': 'Show render area'}
|
||||
|
||||
|
||||
class TemplatePyMod_Cmd6:
|
||||
def Activated(self):
|
||||
import FeaturePython
|
||||
FeaturePython.makeBox()
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'python', 'MenuText': 'Create a box', 'ToolTip': 'Use Box feature class which is completely written in Python'}
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Adds the commands to the FreeCAD command manager
|
||||
#---------------------------------------------------------------------------
|
||||
addCommand('TemplatePyMod_Cmd1',TemplatePyMod_Cmd1())
|
||||
addCommand('TemplatePyMod_Cmd2',TemplatePyMod_Cmd2())
|
||||
addCommand('TemplatePyMod_Cmd3',TemplatePyMod_Cmd3())
|
||||
FreeCADGui.addCommand('TemplatePyMod_Cmd4',TemplatePyMod_Cmd4())
|
||||
FreeCADGui.addCommand('TemplatePyMod_Cmd5',TemplatePyMod_Cmd5())
|
||||
FreeCADGui.addCommand('TemplatePyMod_Cmd6',TemplatePyMod_Cmd6())
|
||||
|
||||
179
src/Mod/TemplatePyMod/DocumentObject.py
Normal file
179
src/Mod/TemplatePyMod/DocumentObject.py
Normal file
@@ -0,0 +1,179 @@
|
||||
# FreeCAD module provding base classes for document objects and view provider
|
||||
# (c) 2011 Werner Mayer LGPL
|
||||
|
||||
class DocumentObject(object):
|
||||
def __init__(self):
|
||||
self.__object__=None
|
||||
def execute(self):
|
||||
raise Exception("Not yet implemented")
|
||||
#def onChanged(self,prop):
|
||||
# return None
|
||||
#def __getattr__(self, attr):
|
||||
# if hasattr(self.__object__,attr):
|
||||
# return getattr(self.__object__,attr)
|
||||
# else:
|
||||
# return object.__getattribute__(self,attr)
|
||||
def addProperty(self,type,name='',group='',doc='',attr=0,readonly=False,hidden=False):
|
||||
self.__object__.addProperty(type,name,group,doc,attr,readonly,hidden)
|
||||
def supportedProperties(self):
|
||||
return self.__object__.supportedProperties()
|
||||
def isDerivedFrom(self, obj):
|
||||
return self.__object__.isDerivedFrom(obj)
|
||||
def getAllDerivedFrom(self):
|
||||
return self.__object__.getAllDerivedFrom()
|
||||
def getProperty(self,attr):
|
||||
return self.__object__.getPropertyByName(attr)
|
||||
def getTypeOfProperty(self,attr):
|
||||
return self.__object__.getTypeOfProperty(attr)
|
||||
def getGroupOfProperty(self,attr):
|
||||
return self.__object__.getGroupOfProperty(attr)
|
||||
def getDocumentationOfProperty(self,attr):
|
||||
return self.__object__.getDocumentationOfProperty(attr)
|
||||
def touch(self):
|
||||
return self.__object__.touch()
|
||||
def purgeTouched(self):
|
||||
return self.__object__.purgeTouched()
|
||||
def __setstate__(self,value):
|
||||
return None
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@property
|
||||
def PropertiesList(self):
|
||||
return self.__object__.PropertiesList
|
||||
@property
|
||||
def Type(self):
|
||||
return self.__object__.Type
|
||||
@property
|
||||
def Module(self):
|
||||
return self.__object__.Module
|
||||
@property
|
||||
def Content(self):
|
||||
return self.__object__.Content
|
||||
@property
|
||||
def MemSize(self):
|
||||
return self.__object__.MemSize
|
||||
@property
|
||||
def Name(self):
|
||||
return self.__object__.Name
|
||||
@property
|
||||
def Document(self):
|
||||
return self.__object__.Document
|
||||
@property
|
||||
def State(self):
|
||||
return self.__object__.State
|
||||
@property
|
||||
def ViewObject(self):
|
||||
return self.__object__.ViewObject
|
||||
@ViewObject.setter
|
||||
def ViewObject(self,value):
|
||||
self.__object__.ViewObject=value
|
||||
@property
|
||||
def InList(self):
|
||||
return self.__object__.InList
|
||||
@property
|
||||
def OutList(self):
|
||||
return self.__object__.OutList
|
||||
|
||||
class ViewProvider(object):
|
||||
def __init__(self):
|
||||
self.__vobject__=None
|
||||
#def getIcon(self):
|
||||
# return ""
|
||||
#def claimChildren(self):
|
||||
# return []
|
||||
#def setEdit(self,mode):
|
||||
# return False
|
||||
#def unsetEdit(self,mode):
|
||||
# return False
|
||||
#def attach(self):
|
||||
# return None
|
||||
#def updateData(self, prop):
|
||||
# return None
|
||||
#def onChanged(self, prop):
|
||||
# return None
|
||||
def addDisplayMode(self,node,mode):
|
||||
self.__vobject__.addDisplayMode(node,mode)
|
||||
#def getDefaultDisplayMode(self):
|
||||
# return ""
|
||||
#def getDisplayModes(self):
|
||||
# return []
|
||||
#def setDisplayMode(self,mode):
|
||||
# return mode
|
||||
def addProperty(self,type,name='',group='',doc='',attr=0,readonly=False,hidden=False):
|
||||
self.__vobject__.addProperty(type,name,group,doc,attr,readonly,hidden)
|
||||
def update(self):
|
||||
self.__vobject__.update()
|
||||
def show(self):
|
||||
self.__vobject__.show()
|
||||
def hide(self):
|
||||
self.__vobject__.hide()
|
||||
def isVisible(self):
|
||||
return self.__vobject__.isVisible()
|
||||
def toString(self):
|
||||
return self.__vobject__.toString()
|
||||
def startEditing(self,mode=0):
|
||||
return self.__vobject__.startEditing(mode)
|
||||
def finishEditing(self):
|
||||
self.__vobject__.finishEditing()
|
||||
def isEditing(self):
|
||||
self.__vobject__.isEditing()
|
||||
def setTransformation(self,trsf):
|
||||
return self.__vobject__.setTransformation(trsf)
|
||||
def supportedProperties(self):
|
||||
return self.__vobject__.supportedProperties()
|
||||
def isDerivedFrom(self, obj):
|
||||
return self.__vobject__.isDerivedFrom(obj)
|
||||
def getAllDerivedFrom(self):
|
||||
return self.__vobject__.getAllDerivedFrom()
|
||||
def getProperty(self,attr):
|
||||
return self.__vobject__.getPropertyByName(attr)
|
||||
def getTypeOfProperty(self,attr):
|
||||
return self.__vobject__.getTypeOfProperty(attr)
|
||||
def getGroupOfProperty(self,attr):
|
||||
return self.__vobject__.getGroupOfProperty(attr)
|
||||
def getDocumentationOfProperty(self,attr):
|
||||
return self.__vobject__.getDocumentationOfProperty(attr)
|
||||
@property
|
||||
def Annotation(self):
|
||||
return self.__vobject__.Annotation
|
||||
@property
|
||||
def RootNode(self):
|
||||
return self.__vobject__.RootNode
|
||||
@property
|
||||
def DisplayModes(self):
|
||||
return self.__vobject__.listDisplayModes()
|
||||
@property
|
||||
def PropertiesList(self):
|
||||
return self.__vobject__.PropertiesList
|
||||
@property
|
||||
def Type(self):
|
||||
return self.__vobject__.Type
|
||||
@property
|
||||
def Module(self):
|
||||
return self.__vobject__.Module
|
||||
@property
|
||||
def Content(self):
|
||||
return self.__vobject__.Content
|
||||
@property
|
||||
def MemSize(self):
|
||||
return self.__vobject__.MemSize
|
||||
@property
|
||||
def Object(self):
|
||||
return self.__vobject__.Object
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
class MyFeature(DocumentObject):
|
||||
def execute(self):
|
||||
print "Execute my feature"
|
||||
def onChanged(self,prop):
|
||||
print "Property %s has changed" % (prop)
|
||||
|
||||
def testMethod():
|
||||
import FreeCAD
|
||||
doc=FreeCAD.newDocument()
|
||||
obj=MyFeature()
|
||||
doc.addObject("Mesh::FeaturePython","MyName",obj,None)
|
||||
obj.addProperty("App::PropertyLinkList","Layers","Base", "Layers")
|
||||
744
src/Mod/TemplatePyMod/FeaturePython.py
Normal file
744
src/Mod/TemplatePyMod/FeaturePython.py
Normal file
@@ -0,0 +1,744 @@
|
||||
"""
|
||||
Examples for a feature class and its view provider.
|
||||
|
||||
***************************************************************************
|
||||
* Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License (GPL) *
|
||||
* 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. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = "Werner Mayer <wmayer@users.sourceforge.net>"
|
||||
|
||||
import FreeCAD, Part, math
|
||||
from FreeCAD import Base
|
||||
from pivy import coin
|
||||
|
||||
class PartFeature:
|
||||
def __init__(self, obj):
|
||||
obj.Proxy = self
|
||||
|
||||
class Box(PartFeature):
|
||||
def __init__(self, obj):
|
||||
PartFeature.__init__(self, obj)
|
||||
''' Add some custom properties to our box feature '''
|
||||
obj.addProperty("App::PropertyLength","Length","Box","Length of the box").Length=1.0
|
||||
obj.addProperty("App::PropertyLength","Width","Box","Width of the box").Width=1.0
|
||||
obj.addProperty("App::PropertyLength","Height","Box", "Height of the box").Height=1.0
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
''' Print the name of the property that has changed '''
|
||||
FreeCAD.Console.PrintMessage("Change property: " + str(prop) + "\n")
|
||||
if prop == "Length" or prop == "Width" or prop == "Height":
|
||||
fp.Shape = Part.makeBox(fp.Length,fp.Width,fp.Height)
|
||||
|
||||
def execute(self, fp):
|
||||
''' Print a short message when doing a recomputation, this method is mandatory '''
|
||||
FreeCAD.Console.PrintMessage("Recompute Python Box feature\n")
|
||||
fp.Shape = Part.makeBox(fp.Length,fp.Width,fp.Height)
|
||||
|
||||
class ViewProviderBox:
|
||||
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 updateData(self, fp, prop):
|
||||
''' If a property of the handled feature has changed we have the chance to handle this here '''
|
||||
return
|
||||
|
||||
def getDisplayModes(self,obj):
|
||||
''' Return a list of display modes. '''
|
||||
modes=[]
|
||||
return modes
|
||||
|
||||
def getDefaultDisplayMode(self):
|
||||
''' Return the name of the default display mode. It must be defined in getDisplayModes. '''
|
||||
return "Shaded"
|
||||
|
||||
def setDisplayMode(self,mode):
|
||||
''' Map the display mode defined in attach with those defined in getDisplayModes.
|
||||
Since they have the same names nothing needs to be done. This method is optinal.
|
||||
'''
|
||||
return mode
|
||||
|
||||
def onChanged(self, vp, prop):
|
||||
''' Print the name of the property that has changed '''
|
||||
FreeCAD.Console.PrintMessage("Change property: " + str(prop) + "\n")
|
||||
|
||||
def getIcon(self):
|
||||
''' Return the icon in XMP format which will appear in the tree view. This method is optional
|
||||
and if not defined a default icon is shown.
|
||||
'''
|
||||
return """
|
||||
/* XPM */
|
||||
static const char * ViewProviderBox_xpm[] = {
|
||||
"16 16 6 1",
|
||||
" c None",
|
||||
". c #141010",
|
||||
"+ c #615BD2",
|
||||
"@ c #C39D55",
|
||||
"# c #000000",
|
||||
"$ c #57C355",
|
||||
" ........",
|
||||
" ......++..+..",
|
||||
" .@@@@.++..++.",
|
||||
" .@@@@.++..++.",
|
||||
" .@@ .++++++.",
|
||||
" ..@@ .++..++.",
|
||||
"###@@@@ .++..++.",
|
||||
"##$.@@$#.++++++.",
|
||||
"#$#$.$$$........",
|
||||
"#$$####### ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
" #$#$$$$$# ",
|
||||
" ##$$$$$# ",
|
||||
" ####### "};
|
||||
"""
|
||||
|
||||
def __getstate__(self):
|
||||
''' When saving the document this object gets stored using Python's cPickle module.
|
||||
Since we have some un-pickable here -- the Coin stuff -- we must define this method
|
||||
to return a tuple of all pickable objects or None.
|
||||
'''
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
''' When restoring the pickled object from document we have the chance to set some
|
||||
internals here. Since no data were pickled nothing needs to be done here.
|
||||
'''
|
||||
return None
|
||||
|
||||
|
||||
def makeBox():
|
||||
FreeCAD.newDocument()
|
||||
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Box")
|
||||
Box(a)
|
||||
ViewProviderBox(a.ViewObject)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class Line:
|
||||
def __init__(self, obj):
|
||||
''' Add two point properties '''
|
||||
obj.addProperty("App::PropertyVector","p1","Line","Start point")
|
||||
obj.addProperty("App::PropertyVector","p2","Line","End point").p2=FreeCAD.Vector(1,0,0)
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
''' Print a short message when doing a recomputation, this method is mandatory '''
|
||||
fp.Shape = Part.makeLine(fp.p1,fp.p2)
|
||||
|
||||
class ViewProviderLine:
|
||||
def __init__(self, obj):
|
||||
''' Set this object to the proxy object of the actual view provider '''
|
||||
obj.Proxy = self
|
||||
|
||||
def getDefaultDisplayMode(self):
|
||||
''' Return the name of the default display mode. It must be defined in getDisplayModes. '''
|
||||
return "Flat Lines"
|
||||
|
||||
def makeLine():
|
||||
FreeCAD.newDocument()
|
||||
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Line")
|
||||
Line(a)
|
||||
#ViewProviderLine(a.ViewObject)
|
||||
a.ViewObject.Proxy=0 # just set it to something different from None
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class Octahedron:
|
||||
def __init__(self, obj):
|
||||
"Add some custom properties to our box feature"
|
||||
obj.addProperty("App::PropertyLength","Length","Octahedron","Length of the octahedron").Length=1.0
|
||||
obj.addProperty("App::PropertyLength","Width","Octahedron","Width of the octahedron").Width=1.0
|
||||
obj.addProperty("App::PropertyLength","Height","Octahedron", "Height of the octahedron").Height=1.0
|
||||
obj.addProperty("Part::PropertyPartShape","Shape","Octahedron", "Shape of the octahedron")
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
# Define six vetices for the shape
|
||||
v1 = FreeCAD.Vector(0,0,0)
|
||||
v2 = FreeCAD.Vector(fp.Length,0,0)
|
||||
v3 = FreeCAD.Vector(0,fp.Width,0)
|
||||
v4 = FreeCAD.Vector(fp.Length,fp.Width,0)
|
||||
v5 = FreeCAD.Vector(fp.Length/2,fp.Width/2,fp.Height/2)
|
||||
v6 = FreeCAD.Vector(fp.Length/2,fp.Width/2,-fp.Height/2)
|
||||
|
||||
# Make the wires/faces
|
||||
f1 = self.make_face(v2,v1,v5)
|
||||
f2 = self.make_face(v4,v2,v5)
|
||||
f3 = self.make_face(v3,v4,v5)
|
||||
f4 = self.make_face(v1,v3,v5)
|
||||
f5 = self.make_face(v1,v2,v6)
|
||||
f6 = self.make_face(v2,v4,v6)
|
||||
f7 = self.make_face(v4,v3,v6)
|
||||
f8 = self.make_face(v3,v1,v6)
|
||||
shell=Part.makeShell([f1,f2,f3,f4,f5,f6,f7,f8])
|
||||
solid=Part.makeSolid(shell)
|
||||
fp.Shape = solid
|
||||
# helper mehod to create the faces
|
||||
def make_face(self,v1,v2,v3):
|
||||
wire = Part.makePolygon([v1,v2,v3,v1])
|
||||
face = Part.Face(wire)
|
||||
return face
|
||||
|
||||
class ViewProviderOctahedron:
|
||||
def __init__(self, obj):
|
||||
"Set this object to the proxy object of the actual view provider"
|
||||
obj.addProperty("App::PropertyColor","Color","Octahedron","Color of the octahedron").Color=(1.0,0.0,0.0)
|
||||
obj.Proxy = self
|
||||
|
||||
def attach(self, obj):
|
||||
"Setup the scene sub-graph of the view provider, this method is mandatory"
|
||||
self.shaded = coin.SoGroup()
|
||||
self.wireframe = coin.SoGroup()
|
||||
self.color = coin.SoBaseColor()
|
||||
|
||||
self.data=coin.SoCoordinate3()
|
||||
self.face=coin.SoIndexedFaceSet()
|
||||
|
||||
self.shaded.addChild(self.color)
|
||||
self.shaded.addChild(self.data)
|
||||
self.shaded.addChild(self.face)
|
||||
obj.addDisplayMode(self.shaded,"Shaded");
|
||||
style=coin.SoDrawStyle()
|
||||
style.style = coin.SoDrawStyle.LINES
|
||||
self.wireframe.addChild(style)
|
||||
self.wireframe.addChild(self.color)
|
||||
self.wireframe.addChild(self.data)
|
||||
self.wireframe.addChild(self.face)
|
||||
obj.addDisplayMode(self.wireframe,"Wireframe");
|
||||
self.onChanged(obj,"Color")
|
||||
|
||||
def updateData(self, fp, prop):
|
||||
"If a property of the handled feature has changed we have the chance to handle this here"
|
||||
# fp is the handled feature, prop is the name of the property that has changed
|
||||
if prop == "Shape":
|
||||
s = fp.getPropertyByName("Shape")
|
||||
self.data.point.setNum(6)
|
||||
cnt=0
|
||||
for i in s.Vertexes:
|
||||
self.data.point.set1Value(cnt,i.X,i.Y,i.Z)
|
||||
cnt=cnt+1
|
||||
|
||||
self.face.coordIndex.set1Value(0,0)
|
||||
self.face.coordIndex.set1Value(1,2)
|
||||
self.face.coordIndex.set1Value(2,1)
|
||||
self.face.coordIndex.set1Value(3,-1)
|
||||
|
||||
self.face.coordIndex.set1Value(4,3)
|
||||
self.face.coordIndex.set1Value(5,2)
|
||||
self.face.coordIndex.set1Value(6,0)
|
||||
self.face.coordIndex.set1Value(7,-1)
|
||||
|
||||
self.face.coordIndex.set1Value(8,4)
|
||||
self.face.coordIndex.set1Value(9,2)
|
||||
self.face.coordIndex.set1Value(10,3)
|
||||
self.face.coordIndex.set1Value(11,-1)
|
||||
|
||||
self.face.coordIndex.set1Value(12,1)
|
||||
self.face.coordIndex.set1Value(13,2)
|
||||
self.face.coordIndex.set1Value(14,4)
|
||||
self.face.coordIndex.set1Value(15,-1)
|
||||
|
||||
self.face.coordIndex.set1Value(16,1)
|
||||
self.face.coordIndex.set1Value(17,5)
|
||||
self.face.coordIndex.set1Value(18,0)
|
||||
self.face.coordIndex.set1Value(19,-1)
|
||||
|
||||
self.face.coordIndex.set1Value(20,0)
|
||||
self.face.coordIndex.set1Value(21,5)
|
||||
self.face.coordIndex.set1Value(22,3)
|
||||
self.face.coordIndex.set1Value(23,-1)
|
||||
|
||||
self.face.coordIndex.set1Value(24,3)
|
||||
self.face.coordIndex.set1Value(25,5)
|
||||
self.face.coordIndex.set1Value(26,4)
|
||||
self.face.coordIndex.set1Value(27,-1)
|
||||
|
||||
self.face.coordIndex.set1Value(28,4)
|
||||
self.face.coordIndex.set1Value(29,5)
|
||||
self.face.coordIndex.set1Value(30,1)
|
||||
self.face.coordIndex.set1Value(31,-1)
|
||||
|
||||
def getDisplayModes(self,obj):
|
||||
"Return a list of display modes."
|
||||
modes=[]
|
||||
modes.append("Shaded")
|
||||
modes.append("Wireframe")
|
||||
return modes
|
||||
|
||||
def getDefaultDisplayMode(self):
|
||||
"Return the name of the default display mode. It must be defined in getDisplayModes."
|
||||
return "Shaded"
|
||||
|
||||
def setDisplayMode(self,mode):
|
||||
return mode
|
||||
|
||||
def onChanged(self, vp, prop):
|
||||
"Here we can do something when a single property got changed"
|
||||
FreeCAD.Console.PrintMessage("Change property: " + str(prop) + "\n")
|
||||
if prop == "Color":
|
||||
c = vp.getPropertyByName("Color")
|
||||
self.color.rgb.setValue(c[0],c[1],c[2])
|
||||
|
||||
def getIcon(self):
|
||||
return """
|
||||
/* XPM */
|
||||
static const char * ViewProviderBox_xpm[] = {
|
||||
"16 16 6 1",
|
||||
" c None",
|
||||
". c #141010",
|
||||
"+ c #615BD2",
|
||||
"@ c #C39D55",
|
||||
"# c #000000",
|
||||
"$ c #57C355",
|
||||
" ........",
|
||||
" ......++..+..",
|
||||
" .@@@@.++..++.",
|
||||
" .@@@@.++..++.",
|
||||
" .@@ .++++++.",
|
||||
" ..@@ .++..++.",
|
||||
"###@@@@ .++..++.",
|
||||
"##$.@@$#.++++++.",
|
||||
"#$#$.$$$........",
|
||||
"#$$####### ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
" #$#$$$$$# ",
|
||||
" ##$$$$$# ",
|
||||
" ####### "};
|
||||
"""
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
return None
|
||||
|
||||
def makeOctahedron():
|
||||
FreeCAD.newDocument()
|
||||
a=FreeCAD.ActiveDocument.addObject("App::FeaturePython","Octahedron")
|
||||
Octahedron(a)
|
||||
ViewProviderOctahedron(a.ViewObject)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class PointFeature:
|
||||
def __init__(self, obj):
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
''' Print the name of the property that has changed '''
|
||||
return
|
||||
|
||||
def execute(self, fp):
|
||||
''' Print a short message when doing a recomputation, this method is mandatory '''
|
||||
return
|
||||
|
||||
class ViewProviderPoints:
|
||||
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 updateData(self, fp, prop):
|
||||
''' If a property of the handled feature has changed we have the chance to handle this here '''
|
||||
return
|
||||
|
||||
def getDisplayModes(self,obj):
|
||||
''' Return a list of display modes. '''
|
||||
modes=[]
|
||||
return modes
|
||||
|
||||
def getDefaultDisplayMode(self):
|
||||
''' Return the name of the default display mode. It must be defined in getDisplayModes. '''
|
||||
return "Points"
|
||||
|
||||
def setDisplayMode(self,mode):
|
||||
''' Map the display mode defined in attach with those defined in getDisplayModes.
|
||||
Since they have the same names nothing needs to be done. This method is optinal.
|
||||
'''
|
||||
return mode
|
||||
|
||||
def onChanged(self, vp, prop):
|
||||
''' Print the name of the property that has changed '''
|
||||
return
|
||||
|
||||
def getIcon(self):
|
||||
''' Return the icon in XMP format which will appear in the tree view. This method is optional
|
||||
and if not defined a default icon is shown.
|
||||
'''
|
||||
return """
|
||||
/* XPM */
|
||||
static const char * ViewProviderBox_xpm[] = {
|
||||
"16 16 6 1",
|
||||
" c None",
|
||||
". c #141010",
|
||||
"+ c #615BD2",
|
||||
"@ c #C39D55",
|
||||
"# c #000000",
|
||||
"$ c #57C355",
|
||||
" ........",
|
||||
" ......++..+..",
|
||||
" .@@@@.++..++.",
|
||||
" .@@@@.++..++.",
|
||||
" .@@ .++++++.",
|
||||
" ..@@ .++..++.",
|
||||
"###@@@@ .++..++.",
|
||||
"##$.@@$#.++++++.",
|
||||
"#$#$.$$$........",
|
||||
"#$$####### ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
" #$#$$$$$# ",
|
||||
" ##$$$$$# ",
|
||||
" ####### "};
|
||||
"""
|
||||
|
||||
def __getstate__(self):
|
||||
''' When saving the document this object gets stored using Python's cPickle module.
|
||||
Since we have some un-pickable here -- the Coin stuff -- we must define this method
|
||||
to return a tuple of all pickable objects or None.
|
||||
'''
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
''' When restoring the pickled object from document we have the chance to set some
|
||||
internals here. Since no data were pickled nothing needs to be done here.
|
||||
'''
|
||||
return None
|
||||
|
||||
|
||||
def makePoints():
|
||||
FreeCAD.newDocument()
|
||||
import Mesh
|
||||
m=Mesh.createSphere(5.0).Points
|
||||
import Points
|
||||
p=Points.Points()
|
||||
|
||||
l=[]
|
||||
for s in m:
|
||||
l.append(s.Vector)
|
||||
|
||||
p.addPoints(l)
|
||||
|
||||
|
||||
a=FreeCAD.ActiveDocument.addObject("Points::FeaturePython","Points")
|
||||
a.Points=p
|
||||
PointFeature(a)
|
||||
ViewProviderPoints(a.ViewObject)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class MeshFeature:
|
||||
def __init__(self, obj):
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
''' Print the name of the property that has changed '''
|
||||
return
|
||||
|
||||
def execute(self, fp):
|
||||
''' Print a short message when doing a recomputation, this method is mandatory '''
|
||||
return
|
||||
|
||||
class ViewProviderMesh:
|
||||
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 getDefaultDisplayMode(self):
|
||||
''' Return the name of the default display mode. It must be defined in getDisplayModes. '''
|
||||
return "Shaded"
|
||||
|
||||
def getIcon(self):
|
||||
''' Return the icon in XMP format which will appear in the tree view. This method is optional
|
||||
and if not defined a default icon is shown.
|
||||
'''
|
||||
return """
|
||||
/* XPM */
|
||||
static const char * ViewProviderBox_xpm[] = {
|
||||
"16 16 6 1",
|
||||
" c None",
|
||||
". c #141010",
|
||||
"+ c #615BD2",
|
||||
"@ c #C39D55",
|
||||
"# c #000000",
|
||||
"$ c #57C355",
|
||||
" ........",
|
||||
" ......++..+..",
|
||||
" .@@@@.++..++.",
|
||||
" .@@@@.++..++.",
|
||||
" .@@ .++++++.",
|
||||
" ..@@ .++..++.",
|
||||
"###@@@@ .++..++.",
|
||||
"##$.@@$#.++++++.",
|
||||
"#$#$.$$$........",
|
||||
"#$$####### ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
"#$$#$$$$$# ",
|
||||
" #$#$$$$$# ",
|
||||
" ##$$$$$# ",
|
||||
" ####### "};
|
||||
"""
|
||||
|
||||
def __getstate__(self):
|
||||
''' When saving the document this object gets stored using Python's cPickle module.
|
||||
Since we have some un-pickable here -- the Coin stuff -- we must define this method
|
||||
to return a tuple of all pickable objects or None.
|
||||
'''
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
''' When restoring the pickled object from document we have the chance to set some
|
||||
internals here. Since no data were pickled nothing needs to be done here.
|
||||
'''
|
||||
return None
|
||||
|
||||
|
||||
def makeMesh():
|
||||
FreeCAD.newDocument()
|
||||
import Mesh
|
||||
|
||||
a=FreeCAD.ActiveDocument.addObject("Mesh::FeaturePython","Mesh")
|
||||
a.Mesh=Mesh.createSphere(5.0)
|
||||
MeshFeature(a)
|
||||
ViewProviderMesh(a.ViewObject)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class Molecule:
|
||||
def __init__(self, obj):
|
||||
''' Add two point properties '''
|
||||
obj.addProperty("App::PropertyVector","p1","Line","Start point")
|
||||
obj.addProperty("App::PropertyVector","p2","Line","End point").p2=FreeCAD.Vector(1,0,0)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "p1" or prop == "p2":
|
||||
''' Print the name of the property that has changed '''
|
||||
fp.Shape = Part.makeLine(fp.p1,fp.p2)
|
||||
|
||||
def execute(self, fp):
|
||||
''' Print a short message when doing a recomputation, this method is mandatory '''
|
||||
fp.Shape = Part.makeLine(fp.p1,fp.p2)
|
||||
|
||||
class ViewProviderMolecule:
|
||||
def __init__(self, obj):
|
||||
''' Set this object to the proxy object of the actual view provider '''
|
||||
obj.Proxy = self
|
||||
sep1=coin.SoSeparator()
|
||||
self.trl1=coin.SoTranslation()
|
||||
sep1.addChild(self.trl1)
|
||||
sep1.addChild(coin.SoSphere())
|
||||
sep2=coin.SoSeparator()
|
||||
self.trl2=coin.SoTranslation()
|
||||
sep2.addChild(self.trl2)
|
||||
sep2.addChild(coin.SoSphere())
|
||||
obj.RootNode.addChild(sep1)
|
||||
obj.RootNode.addChild(sep2)
|
||||
|
||||
def updateData(self, fp, prop):
|
||||
"If a property of the handled feature has changed we have the chance to handle this here"
|
||||
# fp is the handled feature, prop is the name of the property that has changed
|
||||
if prop == "p1":
|
||||
p = fp.getPropertyByName("p1")
|
||||
self.trl1.translation=(p.x,p.y,p.z)
|
||||
elif prop == "p2":
|
||||
p = fp.getPropertyByName("p2")
|
||||
self.trl2.translation=(p.x,p.y,p.z)
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
return None
|
||||
|
||||
def makeMolecule():
|
||||
FreeCAD.newDocument()
|
||||
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Molecule")
|
||||
Molecule(a)
|
||||
ViewProviderMolecule(a.ViewObject)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class CircleSet:
|
||||
def __init__(self, obj):
|
||||
obj.addProperty("Part::PropertyPartShape","Shape","Circle","Shape")
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
pass
|
||||
|
||||
|
||||
class ViewProviderCircleSet:
|
||||
def __init__(self, obj):
|
||||
''' Set this object to the proxy object of the actual view provider '''
|
||||
obj.Proxy = self
|
||||
|
||||
def attach(self, obj):
|
||||
self.coords=coin.SoCoordinate3()
|
||||
self.lines=coin.SoLineSet()
|
||||
obj.RootNode.addChild(self.coords)
|
||||
obj.RootNode.addChild(self.lines)
|
||||
|
||||
def updateData(self, fp, prop):
|
||||
if prop == "Shape":
|
||||
edges=p = fp.getPropertyByName("Shape").Edges
|
||||
pts=[]
|
||||
ver=[]
|
||||
for i in edges:
|
||||
length=i.Length
|
||||
ver.append(10)
|
||||
for j in range(10):
|
||||
v=i.valueAt(j/9.0*length)
|
||||
pts.append((v.x,v.y,v.z))
|
||||
|
||||
self.coords.point.setValues(pts)
|
||||
self.lines.numVertices.setValues(ver)
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
return None
|
||||
|
||||
def makeCircleSet():
|
||||
x=0.5
|
||||
comp=Part.Compound([])
|
||||
for j in range (630):
|
||||
y=0.5
|
||||
for i in range (630):
|
||||
c = Part.makeCircle(0.1, Base.Vector(x,y,0), Base.Vector(0,0,1))
|
||||
#Part.show(c)
|
||||
comp.add(c)
|
||||
y=y+0.5
|
||||
x=x+0.5
|
||||
|
||||
FreeCAD.newDocument()
|
||||
a=FreeCAD.ActiveDocument.addObject("App::FeaturePython","Circles")
|
||||
c=CircleSet(a)
|
||||
v=ViewProviderCircleSet(a.ViewObject)
|
||||
a.Shape=comp
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class EnumTest:
|
||||
def __init__(self, obj):
|
||||
''' Add enum properties '''
|
||||
obj.addProperty("App::PropertyEnumeration","Enum","","Enumeration").Enum=["One","Two","Three"]
|
||||
obj.addProperty("App::PropertyEnumeration","Enum2","","Enumeration2").Enum2=["One","Two","Three"]
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
return
|
||||
|
||||
class ViewProviderEnumTest:
|
||||
def __init__(self, obj):
|
||||
''' Set this object to the proxy object of the actual view provider '''
|
||||
obj.addProperty("App::PropertyEnumeration","Enum3","","Enumeration3").Enum3=["One","Two","Three"]
|
||||
obj.addProperty("App::PropertyEnumeration","Enum4","","Enumeration4").Enum4=["One","Two","Three"]
|
||||
obj.Proxy = self
|
||||
|
||||
def updateData(self, fp, prop):
|
||||
print "prop updated:",prop
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
return None
|
||||
|
||||
def makeEnumTest():
|
||||
FreeCAD.newDocument()
|
||||
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Enum")
|
||||
EnumTest(a)
|
||||
ViewProviderEnumTest(a.ViewObject)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
class DistanceBolt:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Length, Edges, Radius, Height '''
|
||||
obj.addProperty("App::PropertyInteger","Edges","Bolt","Number of edges of the outline").Edges=6
|
||||
obj.addProperty("App::PropertyLength","Length","Bolt","Length of the edges of the outline").Length=10.0
|
||||
obj.addProperty("App::PropertyLength","Radius","Bolt","Radius of the inner circle").Radius=4.0
|
||||
obj.addProperty("App::PropertyLength","Height","Bolt","Height of the extrusion").Height=20.0
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "Edges" or prop == "Length" or prop == "Radius" or prop == "Height":
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
edges = fp.Edges
|
||||
if edges < 3:
|
||||
edges = 3
|
||||
length = fp.Length
|
||||
radius = fp.Radius
|
||||
height = fp.Height
|
||||
|
||||
m=Base.Matrix()
|
||||
m.rotateZ(math.radians(360.0/edges))
|
||||
|
||||
# create polygon
|
||||
polygon = []
|
||||
v=Base.Vector(length,0,0)
|
||||
for i in range(edges):
|
||||
polygon.append(v)
|
||||
v = m.multiply(v)
|
||||
polygon.append(v)
|
||||
wire = Part.makePolygon(polygon)
|
||||
|
||||
# create circle
|
||||
circ=Part.makeCircle(radius)
|
||||
|
||||
# Create the face with the polygon as outline and the circle as hole
|
||||
face=Part.Face([wire,Part.Wire(circ)])
|
||||
|
||||
# Extrude in z to create the final solid
|
||||
extrude=face.extrude(Base.Vector(0,0,height))
|
||||
fp.Shape = extrude
|
||||
|
||||
def makeDistanceBolt():
|
||||
FreeCAD.newDocument()
|
||||
bolt=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Distance_Bolt")
|
||||
bolt.Label = "Distance bolt"
|
||||
DistanceBolt(bolt)
|
||||
bolt.ViewObject.Proxy=0
|
||||
|
||||
10
src/Mod/TemplatePyMod/Init.py
Normal file
10
src/Mod/TemplatePyMod/Init.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# FreeCAD TemplatePyMod module
|
||||
# (c) 2007 Juergen Riegel LGPL
|
||||
|
||||
# Get the Parameter Group of this module
|
||||
ParGrp = App.ParamGet("System parameter:Modules").GetGroup("Test")
|
||||
|
||||
# Set the needed information
|
||||
ParGrp.SetString("HelpIndex", "Test/Help/index.html")
|
||||
ParGrp.SetString("WorkBenchName", "Test functions")
|
||||
|
||||
50
src/Mod/TemplatePyMod/InitGui.py
Normal file
50
src/Mod/TemplatePyMod/InitGui.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# TemplatePyMod gui init module
|
||||
# (c) 2007 Juergen Riegel LGPL
|
||||
#
|
||||
|
||||
|
||||
class TemplatePyModWorkbench ( Workbench ):
|
||||
"Test workbench object"
|
||||
Icon = """
|
||||
/* XPM */
|
||||
static const char *test_icon[]={
|
||||
"16 16 2 1",
|
||||
"a c #000000",
|
||||
". c None",
|
||||
"................",
|
||||
"................",
|
||||
"..############..",
|
||||
"..############..",
|
||||
"..############..",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"......####......",
|
||||
"................",
|
||||
"................"};
|
||||
"""
|
||||
MenuText = "Python sandbox"
|
||||
ToolTip = "Python template workbench"
|
||||
|
||||
def Initialize(self):
|
||||
import Commands
|
||||
|
||||
self.appendToolbar("TemplateTools",["TemplatePyMod_Cmd1","TemplatePyMod_Cmd2","TemplatePyMod_Cmd3","TemplatePyMod_Cmd4","TemplatePyMod_Cmd5"])
|
||||
|
||||
menu = ["ModulePy &Commands","PyModuleCommands"]
|
||||
list = ["TemplatePyMod_Cmd1","TemplatePyMod_Cmd2","TemplatePyMod_Cmd3","TemplatePyMod_Cmd5","TemplatePyMod_Cmd6"]
|
||||
self.appendCommandbar("PyModuleCommands",list)
|
||||
self.appendMenu(menu,list)
|
||||
|
||||
Log ('Loading TemplatePyMod module... done\n')
|
||||
def Activated(self):
|
||||
Msg("TemplatePyModWorkbench::Activated()\n")
|
||||
def Deactivated(self):
|
||||
Msg("TemplatePyModWorkbench::Deactivated()\n")
|
||||
|
||||
Gui.addWorkbench(TemplatePyModWorkbench)
|
||||
15
src/Mod/TemplatePyMod/Makefile.am
Normal file
15
src/Mod/TemplatePyMod/Makefile.am
Normal file
@@ -0,0 +1,15 @@
|
||||
# Change data dir from default ($(prefix)/share) to $(prefix)
|
||||
datadir = $(prefix)/Mod/TemplatePyMod
|
||||
data_DATA = \
|
||||
Init.py \
|
||||
InitGui.py \
|
||||
Commands.py \
|
||||
FeaturePython.py \
|
||||
DocumentObject.py \
|
||||
Mesh2Shape.py \
|
||||
PythonQt.py \
|
||||
Tests.py
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(data_DATA) \
|
||||
CMakeLists.txt
|
||||
38
src/Mod/TemplatePyMod/Mesh2Shape.py
Normal file
38
src/Mod/TemplatePyMod/Mesh2Shape.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# FreeCAD TemplatePyMod module
|
||||
# (c) 2010 Werner Mayer LGPL
|
||||
|
||||
|
||||
import Mesh,Part,MeshPart
|
||||
|
||||
faces = []
|
||||
mesh = App.ActiveDocument.ActiveObject.Mesh
|
||||
segments = mesh.getPlanes(0.00001) # use rather strict tolerance here
|
||||
|
||||
for i in segments:
|
||||
if len(i) > 0:
|
||||
# a segment can have inner holes
|
||||
wires = MeshPart.wireFromSegment(mesh, i)
|
||||
# we assume that the exterior boundary is that one with the biggest bounding box
|
||||
if len(wires) > 0:
|
||||
ext=None
|
||||
max_length=0
|
||||
for i in wires:
|
||||
if i.BoundBox.DiagonalLength > max_length:
|
||||
max_length = i.BoundBox.DiagonalLength
|
||||
ext = i
|
||||
|
||||
wires.remove(ext)
|
||||
# all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
|
||||
for i in wires:
|
||||
i.reverse()
|
||||
|
||||
# make sure that the exterior wires comes as first in the lsit
|
||||
wires.insert(0, ext)
|
||||
faces.append(Part.Face(wires))
|
||||
|
||||
|
||||
shell=Part.Compound(faces)
|
||||
Part.show(shell)
|
||||
#solid = Part.Solid(Part.Shell(faces))
|
||||
#Part.show(solid)
|
||||
|
||||
121
src/Mod/TemplatePyMod/PythonQt.py
Normal file
121
src/Mod/TemplatePyMod/PythonQt.py
Normal file
@@ -0,0 +1,121 @@
|
||||
"""
|
||||
Examples for customizing the FreeCAD application with PyQt facilities.
|
||||
|
||||
***************************************************************************
|
||||
* Copyright (c) 2007 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License (GPL) *
|
||||
* 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. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = "Werner Mayer <werner.wm.mayer@gmx.de>"
|
||||
|
||||
from PyQt4 import QtCore,QtGui
|
||||
import FreeCAD,FreeCADGui, __main__
|
||||
|
||||
class MainWindow:
|
||||
def __init__(self):
|
||||
self.app = QtGui.qApp
|
||||
self.mw = self.app.activeWindow()
|
||||
self.dock = {}
|
||||
|
||||
def setWindowTitle(self, name):
|
||||
self.mw.setWindowTitle(name)
|
||||
|
||||
def addCalendar(self):
|
||||
d = QtGui.QDockWidget()
|
||||
d.setWindowTitle("Calendar")
|
||||
c = QtGui.QCalendarWidget()
|
||||
d.setWidget(c)
|
||||
self.mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,d)
|
||||
self.dock[d] = c
|
||||
|
||||
def information(self, title, text):
|
||||
QtGui.QMessageBox.information(self.mw, title, text)
|
||||
|
||||
def warning(self, title, text):
|
||||
QtGui.QMessageBox.warning(self.mw, title, text)
|
||||
|
||||
def critical(self, title, text):
|
||||
QtGui.QMessageBox.critical(self.mw, title, text)
|
||||
|
||||
def question(self, title, text):
|
||||
QtGui.QMessageBox.question(self.mw, title, text)
|
||||
|
||||
def aboutQt(self):
|
||||
QtGui.QMessageBox.aboutQt(self.mw, self.mw.tr("About Qt"))
|
||||
|
||||
|
||||
class PythonQtWorkbench (__main__.Workbench):
|
||||
"Python Qt workbench object"
|
||||
Icon = "python"
|
||||
MenuText = "PyQt sandbox"
|
||||
ToolTip = "Python Qt workbench"
|
||||
|
||||
def __init__(self):
|
||||
self.mw = QtGui.qApp.activeWindow()
|
||||
self.dock = {}
|
||||
self.item = []
|
||||
|
||||
def information(self):
|
||||
QtGui.QMessageBox.information(self.mw, "Info", "This is an information")
|
||||
|
||||
def warning(self):
|
||||
QtGui.QMessageBox.warning(self.mw, "Warning", "This is a warning")
|
||||
|
||||
def critical(self):
|
||||
QtGui.QMessageBox.critical(self.mw, "Error", "This is an error")
|
||||
|
||||
def Initialize(self):
|
||||
self.menu = QtGui.QMenu()
|
||||
self.menu.setTitle("Python Qt")
|
||||
self.item.append(self.menu.addAction("Test 1"))
|
||||
self.item.append(self.menu.addAction("Test 2"))
|
||||
self.item.append(self.menu.addAction("Test 3"))
|
||||
|
||||
QtCore.QObject.connect(self.item[0], QtCore.SIGNAL("triggered()"), self.information)
|
||||
QtCore.QObject.connect(self.item[1], QtCore.SIGNAL("triggered()"), self.warning)
|
||||
QtCore.QObject.connect(self.item[2], QtCore.SIGNAL("triggered()"), self.critical)
|
||||
|
||||
def Activated(self):
|
||||
self.__title__ = self.mw.windowTitle()
|
||||
self.mw.setWindowTitle("FreeCAD -- PythonQt")
|
||||
|
||||
d = QtGui.QDockWidget()
|
||||
d.setWindowTitle("Calendar")
|
||||
c = QtGui.QCalendarWidget()
|
||||
d.setWidget(c)
|
||||
self.mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,d)
|
||||
self.dock[d] = c
|
||||
|
||||
bar = self.mw.menuBar()
|
||||
a=bar.actions()
|
||||
for i in a:
|
||||
if i.objectName() == "&Windows":
|
||||
break
|
||||
bar.insertMenu(i, self.menu)
|
||||
self.menu.setTitle("Python Qt")
|
||||
self.menu.menuAction().setVisible(True)
|
||||
|
||||
def Deactivated(self):
|
||||
self.mw.setWindowTitle(self.__title__)
|
||||
self.dock.clear()
|
||||
|
||||
FreeCADGui.addWorkbench(PythonQtWorkbench)
|
||||
105
src/Mod/TemplatePyMod/TaskPanel.py
Normal file
105
src/Mod/TemplatePyMod/TaskPanel.py
Normal file
@@ -0,0 +1,105 @@
|
||||
# FreeCAD TemplatePyMod module
|
||||
# (c) 2011 Werner Mayer LGPL
|
||||
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
from PyQt4 import QtGui,QtCore
|
||||
|
||||
class MyLineEdit(QtGui.QLineEdit):
|
||||
pass
|
||||
|
||||
class TaskWatcher:
|
||||
def __init__(self):
|
||||
self.commands = ["Part_Box", "Part_Sphere", "Part_Cylinder"]
|
||||
self.title = "Create primitives"
|
||||
self.icon = "Part_Sphere"
|
||||
self.widgets = [MyLineEdit()]
|
||||
self.widgets[0].setText("Line edit inside task box")
|
||||
def shouldShow(self):
|
||||
return App.ActiveDocument is not None
|
||||
|
||||
class TaskLineEdit:
|
||||
def __init__(self):
|
||||
self.widgets = [MyLineEdit()]
|
||||
self.widgets[0].setText("Line edit with no task box")
|
||||
def shouldShow(self):
|
||||
return True
|
||||
|
||||
class TaskWatcherFilter:
|
||||
def __init__(self):
|
||||
self.commands = ["Sketcher_NewSketch", "PartDesign_Fillet", "PartDesign_Chamfer"]
|
||||
self.filter = "SELECT Part::Feature SUBELEMENT Face COUNT 1"
|
||||
self.title = "Face tools"
|
||||
self.icon = "Part_Box"
|
||||
|
||||
class TaskPanel:
|
||||
def __init__(self):
|
||||
self.ui = App.getResourceDir() + "Mod/TemplatePyMod/TaskPanel.ui"
|
||||
|
||||
def accept(self):
|
||||
return True
|
||||
|
||||
def reject(self):
|
||||
return True
|
||||
|
||||
def clicked(self, index):
|
||||
pass
|
||||
|
||||
def open(self):
|
||||
pass
|
||||
|
||||
def needsFullSpace(self):
|
||||
return False
|
||||
|
||||
def isAllowedAlterSelection(self):
|
||||
return True
|
||||
|
||||
def isAllowedAlterView(self):
|
||||
return True
|
||||
|
||||
def isAllowedAlterDocument(self):
|
||||
return True
|
||||
|
||||
def getStandardButtons(self):
|
||||
return int(QtGui.QDialogButtonBox.Ok)
|
||||
|
||||
def helpRequested(self):
|
||||
pass
|
||||
|
||||
def setupUi(self):
|
||||
mw = self.getMainWindow()
|
||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||
form.pushButton = form.findChild(QtGui.QPushButton, "pushButton")
|
||||
form.listWidget = form.findChild(QtGui.QListWidget, "listWidget")
|
||||
self.form = form
|
||||
#Connect Signals and Slots
|
||||
QtCore.QObject.connect(form.pushButton, QtCore.SIGNAL("clicked()"), self.addElement)
|
||||
|
||||
def getMainWindow(self):
|
||||
"returns the main window"
|
||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
||||
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
||||
# returned
|
||||
toplevel = QtGui.qApp.topLevelWidgets()
|
||||
for i in toplevel:
|
||||
if i.metaObject().className() == "Gui::MainWindow":
|
||||
return i
|
||||
raise Exception("No main window found")
|
||||
|
||||
def addElement(self):
|
||||
item=QtGui.QInputDialog.getText(self.form, 'Add item', 'Enter:')
|
||||
if item[1]:
|
||||
self.form.listWidget.addItem(item[0])
|
||||
|
||||
class TaskCalendar:
|
||||
def __init__(self):
|
||||
self.form = QtGui.QCalendarWidget()
|
||||
|
||||
|
||||
def createTask():
|
||||
Gui.Control.addTaskWatcher([TaskWatcher(), TaskLineEdit(), TaskWatcherFilter()])
|
||||
panel = TaskCalendar()
|
||||
#panel = TaskPanel()
|
||||
Gui.Control.showDialog(panel)
|
||||
#panel.setupUi()
|
||||
return panel
|
||||
44
src/Mod/TemplatePyMod/TaskPanel.ui
Normal file
44
src/Mod/TemplatePyMod/TaskPanel.ui
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TaskPanel</class>
|
||||
<widget class="QWidget" name="TaskPanel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>307</width>
|
||||
<height>268</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>205</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
111
src/Mod/TemplatePyMod/Tests.py
Normal file
111
src/Mod/TemplatePyMod/Tests.py
Normal file
@@ -0,0 +1,111 @@
|
||||
# FreeCAD TemplatePyMod module
|
||||
# (c) 2007 Juergen Riegel LGPL
|
||||
|
||||
|
||||
import FreeCAD, unittest
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# define the test cases for this module
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class ParameterTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.TestPar = FreeCAD.ParamGet("System parameter:Test")
|
||||
|
||||
def testGroup(self):
|
||||
#FreeCAD.PrintLog("Base::ParameterTestCase::testGroup\n")
|
||||
# check on Group creation
|
||||
Temp = self.TestPar.GetGroup("44")
|
||||
self.failUnless(self.TestPar.HasGroup("44"),"Test on created group failed")
|
||||
# check on Deletion
|
||||
self.TestPar.RemGroup("44")
|
||||
self.failUnless(not self.TestPar.HasGroup("44"),"Test on delete group failed")
|
||||
Temp =0
|
||||
|
||||
#check on special conditions
|
||||
def testInt(self):
|
||||
#FreeCAD.PrintLog("Base::ParameterTestCase::testInt\n")
|
||||
#Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# check on Int
|
||||
self.TestPar.SetInt("44",4711)
|
||||
self.failUnless(self.TestPar.GetInt("44") == 4711,"In and out error at Int")
|
||||
# check on Deletion
|
||||
self.TestPar.RemInt("44")
|
||||
self.failUnless(self.TestPar.GetInt("44",1) == 1,"Deletion error at Int")
|
||||
|
||||
|
||||
def testBool(self):
|
||||
#FreeCAD.PrintLog("Base::ParameterTestCase::testBool\n")
|
||||
# check on Int
|
||||
self.TestPar.SetBool("44",1)
|
||||
self.failUnless(self.TestPar.GetBool("44") == 1,"In and out error at Bool")
|
||||
# check on Deletion
|
||||
self.TestPar.RemBool("44")
|
||||
self.failUnless(self.TestPar.GetBool("44",0) == 0,"Deletion error at Bool")
|
||||
|
||||
def testFloat(self):
|
||||
#FreeCAD.PrintLog("Base::ParameterTestCase::testFloat\n")
|
||||
#Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# check on Int
|
||||
self.TestPar.SetFloat("44",4711.4711)
|
||||
self.failUnless(self.TestPar.GetFloat("44") == 4711.4711,"In and out error at Float")
|
||||
# check on Deletion
|
||||
self.TestPar.RemFloat("44")
|
||||
self.failUnless(self.TestPar.GetFloat("44",1.1) == 1.1,"Deletion error at Float")
|
||||
|
||||
def testString(self):
|
||||
#FreeCAD.PrintLog("Base::ParameterTestCase::testFloat\n")
|
||||
#Temp = FreeCAD.ParamGet("System parameter:Test/44")
|
||||
# check on Int
|
||||
self.TestPar.SetString("44","abcdefgh")
|
||||
self.failUnless(self.TestPar.GetString("44") == "abcdefgh","In and out error at String")
|
||||
# check on Deletion
|
||||
self.TestPar.RemString("44")
|
||||
self.failUnless(self.TestPar.GetString("44","hallo") == "hallo","Deletion error at String")
|
||||
|
||||
def testNesting(self):
|
||||
# Parameter testing
|
||||
#FreeCAD.PrintLog("Base::ParameterTestCase::testNesting\n")
|
||||
for i in range(50):
|
||||
self.TestPar.SetFloat(`i`,4711.4711)
|
||||
self.TestPar.SetInt(`i`,4711)
|
||||
self.TestPar.SetBool(`i`,1)
|
||||
Temp = self.TestPar.GetGroup(`i`)
|
||||
for l in range(50):
|
||||
Temp.SetFloat(`l`,4711.4711)
|
||||
Temp.SetInt(`l`,4711)
|
||||
Temp.SetBool(`l`,1)
|
||||
Temp = 0
|
||||
|
||||
def testExportImport(self):
|
||||
# Parameter testing
|
||||
#FreeCAD.PrintLog("Base::ParameterTestCase::testNesting\n")
|
||||
self.TestPar.SetFloat("ExTest",4711.4711)
|
||||
self.TestPar.SetInt("ExTest",4711)
|
||||
self.TestPar.SetString("ExTest","4711")
|
||||
self.TestPar.SetBool("ExTest",1)
|
||||
Temp = self.TestPar.GetGroup("ExTest")
|
||||
Temp.SetFloat("ExTest",4711.4711)
|
||||
Temp.SetInt("ExTest",4711)
|
||||
Temp.SetString("ExTest","4711")
|
||||
Temp.SetBool("ExTest",1)
|
||||
self.TestPar.Export("ExportTest.FCExport")
|
||||
Temp = self.TestPar.GetGroup("ImportTest")
|
||||
Temp.Import("ExportTest.FCExport")
|
||||
self.failUnless(Temp.GetFloat("ExTest") == 4711.4711,"ExportImport error")
|
||||
Temp = 0
|
||||
|
||||
def tearDown(self):
|
||||
#remove all
|
||||
TestPar = FreeCAD.ParamGet("System parameter:Test")
|
||||
TestPar.Clear()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user