From a2404d1ac7483074143edc873abd4c658556e2d9 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 15 Apr 2013 11:29:45 -0300 Subject: [PATCH] Included more modules in sphinx docs --- src/Doc/sphinx/Document.rst | 5 +- src/Doc/sphinx/DocumentObject.rst | 18 +++++++ src/Doc/sphinx/FreeCAD.rst | 9 ---- src/Doc/sphinx/Matrix.rst | 10 ++++ src/Doc/sphinx/Placement.rst | 10 ++++ src/Doc/sphinx/Vector.rst | 10 ++++ src/Doc/sphinx/ViewProvider.rst | 10 ++++ src/Doc/sphinx/conf.py | 6 ++- src/Doc/sphinx/index.rst | 5 ++ src/Mod/TemplatePyMod/DocumentObject.py | 71 +++++++++++++++++++++++++ 10 files changed, 142 insertions(+), 12 deletions(-) create mode 100644 src/Doc/sphinx/DocumentObject.rst create mode 100644 src/Doc/sphinx/Matrix.rst create mode 100644 src/Doc/sphinx/Placement.rst create mode 100644 src/Doc/sphinx/Vector.rst create mode 100644 src/Doc/sphinx/ViewProvider.rst diff --git a/src/Doc/sphinx/Document.rst b/src/Doc/sphinx/Document.rst index 3e82c8379e..2b8a9d3650 100644 --- a/src/Doc/sphinx/Document.rst +++ b/src/Doc/sphinx/Document.rst @@ -4,5 +4,6 @@ The FreeCAD Document .. toctree:: :maxdepth: 4 -.. automodule:: ActiveDocument - :members: +.. automodule:: DocumentObject + + diff --git a/src/Doc/sphinx/DocumentObject.rst b/src/Doc/sphinx/DocumentObject.rst new file mode 100644 index 0000000000..c329182214 --- /dev/null +++ b/src/Doc/sphinx/DocumentObject.rst @@ -0,0 +1,18 @@ +The FreeCAD Document Object +=========================== + +.. toctree:: + :maxdepth: 4 + +.. automodule:: DocumentObject + + .. autoclass:: DocumentObject + :members: + + .. method:: __setstate__(value) + + allows to save custom attributes of this object as strings, so they can be saved when saving the FreeCAD document + + .. method:: __getstate__() + + reads values previously saved with __setstate__() diff --git a/src/Doc/sphinx/FreeCAD.rst b/src/Doc/sphinx/FreeCAD.rst index eff8e09cfe..1a280b6d53 100644 --- a/src/Doc/sphinx/FreeCAD.rst +++ b/src/Doc/sphinx/FreeCAD.rst @@ -7,14 +7,5 @@ The FreeCAD module .. automodule:: FreeCAD :members: - .. autoclass:: Vector - :members: - - .. autoclass:: Matrix - :members: - - .. autoclass:: Placement - :members: - .. autoclass:: Console :members: diff --git a/src/Doc/sphinx/Matrix.rst b/src/Doc/sphinx/Matrix.rst new file mode 100644 index 0000000000..90e4e8ba3f --- /dev/null +++ b/src/Doc/sphinx/Matrix.rst @@ -0,0 +1,10 @@ +The Matrix object +================= + +.. toctree:: + :maxdepth: 4 + +.. automodule:: FreeCAD + + .. autoclass:: Matrix + :members: diff --git a/src/Doc/sphinx/Placement.rst b/src/Doc/sphinx/Placement.rst new file mode 100644 index 0000000000..56d596e981 --- /dev/null +++ b/src/Doc/sphinx/Placement.rst @@ -0,0 +1,10 @@ +The Placement object +==================== + +.. toctree:: + :maxdepth: 4 + +.. automodule:: FreeCAD + + .. autoclass:: Placement + :members: diff --git a/src/Doc/sphinx/Vector.rst b/src/Doc/sphinx/Vector.rst new file mode 100644 index 0000000000..f7b8d9287b --- /dev/null +++ b/src/Doc/sphinx/Vector.rst @@ -0,0 +1,10 @@ +The Vector object +================= + +.. toctree:: + :maxdepth: 4 + +.. automodule:: FreeCAD + + .. autoclass:: Vector + :members: diff --git a/src/Doc/sphinx/ViewProvider.rst b/src/Doc/sphinx/ViewProvider.rst new file mode 100644 index 0000000000..675dbce697 --- /dev/null +++ b/src/Doc/sphinx/ViewProvider.rst @@ -0,0 +1,10 @@ +The View Provider object +======================== + +.. toctree:: + :maxdepth: 4 + +.. automodule:: DocumentObject + + .. autoclass:: ViewProvider + :members: diff --git a/src/Doc/sphinx/conf.py b/src/Doc/sphinx/conf.py index 77e697346e..52c32f05d0 100644 --- a/src/Doc/sphinx/conf.py +++ b/src/Doc/sphinx/conf.py @@ -53,9 +53,13 @@ elif commands.getstatusoutput("locate FreeCAD/lib")[0] == 0: path = commands.getstatusoutput("locate FreeCAD/lib")[1].split()[0] sys.path.append(path) +# locate TemplatePyMod +if commands.getstatusoutput("locate TemplatePyMod")[0] == 0: + path = commands.getstatusoutput("locate TemplatePyMod")[1].split()[0] + sys.path.append(path) + import FreeCAD, FreeCADGui FreeCADGui.showMainWindow() # this is needed for complete import of GUI modules -from FreeCAD import Document # -- General configuration ----------------------------------------------------- diff --git a/src/Doc/sphinx/index.rst b/src/Doc/sphinx/index.rst index c4004f32ef..ff12b26347 100644 --- a/src/Doc/sphinx/index.rst +++ b/src/Doc/sphinx/index.rst @@ -13,7 +13,12 @@ This is the complete python API reference of the FreeCAD appication FreeCAD.rst FreeCADGui.rst + Vector.rst + Placement.rst + Matrix.rst Document.rst + DocumentObject.rst + ViewProvider.rst Mesh.rst Part.rst Sketch.rst diff --git a/src/Mod/TemplatePyMod/DocumentObject.py b/src/Mod/TemplatePyMod/DocumentObject.py index fd27737f2a..25785aec07 100644 --- a/src/Mod/TemplatePyMod/DocumentObject.py +++ b/src/Mod/TemplatePyMod/DocumentObject.py @@ -2,9 +2,20 @@ # (c) 2011 Werner Mayer LGPL class DocumentObject(object): + """The Document object is the base class for all FreeCAD objects. + Example of use: + + import FreeCAD + + doc=FreeCAD.newDocument() + + myobj = doc.addObject("Mesh::FeaturePython","MyName") + + myobj.addProperty("App::PropertyLinkList","Layers","Base", "Layers")""" def __init__(self): self.__object__=None def execute(self): + "this method is executed on object creation and whenever the document is recomputed" raise Exception("Not yet implemented") #def onChanged(self,prop): # return None @@ -14,67 +25,98 @@ class DocumentObject(object): # else: # return object.__getattribute__(self,attr) def addProperty(self,type,name='',group='',doc='',attr=0,readonly=False,hidden=False): + "adds a new property to this object" self.__object__.addProperty(type,name,group,doc,attr,readonly,hidden) def supportedProperties(self): + "lists the property types supported by this object" return self.__object__.supportedProperties() def isDerivedFrom(self, obj): + """returns True if this object is derived from the given C++ class, for + example Part::Feature""" return self.__object__.isDerivedFrom(obj) def getAllDerivedFrom(self): + "returns all parent C++ classes of this object" return self.__object__.getAllDerivedFrom() def getProperty(self,attr): + "returns the value of a given property" return self.__object__.getPropertyByName(attr) def getTypeOfProperty(self,attr): + "returns the type of a given property" return self.__object__.getTypeOfProperty(attr) def getGroupOfProperty(self,attr): + "returns the group of a given property" return self.__object__.getGroupOfProperty(attr) def getDocumentationOfProperty(self,attr): + "returns the documentation string of a given property" return self.__object__.getDocumentationOfProperty(attr) def touch(self): + "marks this object to be recomputed" return self.__object__.touch() def purgeTouched(self): + "removes the to-be-recomputed flag of this object" return self.__object__.purgeTouched() def __setstate__(self,value): + """allows to save custom attributes of this object as strings, so + they can be saved when saving the FreeCAD document""" return None def __getstate__(self): + """reads values previously saved with __setstate__()""" return None @property def PropertiesList(self): + "lists the current properties of this object" return self.__object__.PropertiesList @property def Type(self): + "shows the C++ class of this object" return self.__object__.Type @property def Module(self): + "gives the module this object is defined in" return self.__object__.Module @property def Content(self): + """shows the contents of the properties of this object as an xml string. + This is the content that is saved when the file is saved by FreeCAD""" return self.__object__.Content @property def MemSize(self): + "shows the amount of memory this object uses" return self.__object__.MemSize @property def Name(self): + "the name ofthis object, unique in the FreeCAD document" return self.__object__.Name @property def Document(self): + "the document this object is part of" return self.__object__.Document @property def State(self): + "shows if this object is valid (presents no errors)" return self.__object__.State @property def ViewObject(self): return self.__object__.ViewObject @ViewObject.setter def ViewObject(self,value): + """returns or sets the ViewObject associated with this object. Returns + None if FreeCAD is running in console mode""" self.__object__.ViewObject=value @property def InList(self): + "lists the parents of this object" return self.__object__.InList @property def OutList(self): + "lists the children of this object" return self.__object__.OutList class ViewProvider(object): + """The ViewProvider is the counterpart of the DocumentObject in + the GUI space. It is only present when FreeCAD runs in GUI mode. + It contains all that is needed to represent the DocumentObject in + the 3D view and the FreeCAD interface""" def __init__(self): self.__vobject__=None #def getIcon(self): @@ -92,6 +134,7 @@ class ViewProvider(object): #def onChanged(self, prop): # return None def addDisplayMode(self,node,mode): + "adds a coin node as a display mode to this object" self.__vobject__.addDisplayMode(node,mode) #def getDefaultDisplayMode(self): # return "" @@ -100,65 +143,93 @@ class ViewProvider(object): #def setDisplayMode(self,mode): # return mode def addProperty(self,type,name='',group='',doc='',attr=0,readonly=False,hidden=False): + "adds a new property to this object" self.__vobject__.addProperty(type,name,group,doc,attr,readonly,hidden) def update(self): + "this method is executed whenever any of the properties of this ViewProvider changes" self.__vobject__.update() def show(self): + "switches this object to visible" self.__vobject__.show() def hide(self): + "switches this object to invisible" self.__vobject__.hide() def isVisible(self): + "shows wether this object is visible or invisible" return self.__vobject__.isVisible() def toString(self): + "returns a string representation of the coin node of this object" return self.__vobject__.toString() def startEditing(self,mode=0): + "sets this object in edit mode" return self.__vobject__.startEditing(mode) def finishEditing(self): + "leaves edit mode for this object" self.__vobject__.finishEditing() def isEditing(self): + "shows wether this object is in edit mode" self.__vobject__.isEditing() def setTransformation(self,trsf): + "defines a transformation for this object" return self.__vobject__.setTransformation(trsf) def supportedProperties(self): + "lists the property types this ViewProvider supports" return self.__vobject__.supportedProperties() def isDerivedFrom(self, obj): + """returns True if this object is derived from the given C++ class, for + example Part::Feature""" return self.__vobject__.isDerivedFrom(obj) def getAllDerivedFrom(self): + "returns all parent C++ classes of this object" return self.__vobject__.getAllDerivedFrom() def getProperty(self,attr): + "returns the value of a given property" return self.__vobject__.getPropertyByName(attr) def getTypeOfProperty(self,attr): + "returns the type of a given property" return self.__vobject__.getTypeOfProperty(attr) def getGroupOfProperty(self,attr): + "returns the group of a given property" return self.__vobject__.getGroupOfProperty(attr) def getDocumentationOfProperty(self,attr): + "returns the documentation string of a given property" return self.__vobject__.getDocumentationOfProperty(attr) @property def Annotation(self): + "returns the Annotation coin node of this object" return self.__vobject__.Annotation @property def RootNode(self): + "returns the Root coin node of this object" return self.__vobject__.RootNode @property def DisplayModes(self): + "lists the display modes of this object" return self.__vobject__.listDisplayModes() @property def PropertiesList(self): + "lists the current properties of this object" return self.__vobject__.PropertiesList @property def Type(self): + "shows the C++ class of this object" return self.__vobject__.Type @property def Module(self): + "gives the module this object is defined in" return self.__vobject__.Module @property def Content(self): + """shows the contents of the properties of this object as an xml string. + This is the content that is saved when the file is saved by FreeCAD""" return self.__vobject__.Content @property def MemSize(self): + "shows the amount of memory this object uses" return self.__vobject__.MemSize @property def Object(self): + "returns the DocumentObject this ViewProvider is associated to" return self.__vobject__.Object