diff --git a/src/Mod/Arch/ArchComponent.py b/src/Mod/Arch/ArchComponent.py index 3c7039a62f..e0b41ddea4 100644 --- a/src/Mod/Arch/ArchComponent.py +++ b/src/Mod/Arch/ArchComponent.py @@ -1146,6 +1146,18 @@ class ViewProviderComponent: return def attach(self,vobj): + """Adds display modes' data to the coin scenegraph. + + Adds each display mode as a coin node, whose parent is this view + provider. + + Each display mode's node includes the data needed to display the object + in that mode. This might include colors of faces, or the draw style of + lines. This data is stored as additional coin nodes which are children + of the display mode node. + + Adds the HiRes display mode. + """ from pivy import coin self.Object = vobj.Object @@ -1157,11 +1169,43 @@ class ViewProviderComponent: return def getDisplayModes(self,vobj): + """Defines the display modes unique to the Arch Component. + + Defines mode HiRes, which displays the component as a mesh, intended as + a more visually appealing version of the component. + + Returns + ------- + list of str + List containing the names of the new display modes. + """ modes=["HiRes"] return modes def setDisplayMode(self,mode): + """Method called when the display mode changes. + + Called when the display mode changes, this method can be used to set + data that wasn't available when .attach() was called. + + When HiRes is set as display mode, displays the component as a copy of + the mesh associated as the HiRes property of the host object. See + ArchComponent.Component's properties. + + If no shape is set in the HiRes propery, just displays the object as + the Flat Lines display mode. + + Parameters + ---------- + mode: str + The name of the display mode the view provider has switched to. + + Returns + ------- + str: + The name of the display mode the view provider has switched to. + """ if hasattr(self,"meshnode"): if self.meshnode: @@ -1212,6 +1256,16 @@ class ViewProviderComponent: return None def claimChildren(self): + """Defines which objects will appear as children in the tree view. + + Sets the host object's Base object as a child, and sets any additions + or subtractions as children. + + Returns + ------- + list of s: + The objects claimed as children. + """ if hasattr(self,"Object"): c = [] @@ -1230,6 +1284,7 @@ class ViewProviderComponent: if Draft.getType(s) == "Roof": continue c.append(s) + for link in ["Armatures","Group"]: if hasattr(self.Object,link): objlink = getattr(self.Object,link) @@ -1246,6 +1301,22 @@ class ViewProviderComponent: return [] def setEdit(self,vobj,mode): + """Method called when the document requests the object to enter edit mode. + + Edit mode is entered when a user double clicks on an object in the tree + view, or when they use the menu option [Edit -> Toggle Edit Mode]. + + Parameters + ---------- + mode: int or str + The edit mode the document has requested. Set to 0 when requested via + a double click or [Edit -> Toggle Edit Mode]. + + Returns + ------- + bool + If edit mode was entered. + """ if mode == 0: taskd = ComponentTaskPanel() @@ -1256,11 +1327,31 @@ class ViewProviderComponent: return False def unsetEdit(self,vobj,mode): + """Method called when the document requests the object exit edit mode. + + Returns + ------- + False + """ FreeCADGui.Control.closeDialog() return False def setupContextMenu(self,vobj,menu): + """Adds the component specific options to the context menu. + + The context menu is the drop down menu that opens when the user right + clicks on the component in the tree view. + + Adds a menu choice to call the Arch_ToggleSubs Gui command. See + ArchCommands._ToggleSubs + + Parameters + ---------- + menu: + The context menu already assembled prior to this method being + called. + """ from PySide import QtCore,QtGui action1 = QtGui.QAction(QtGui.QIcon(":/icons/Arch_ToggleSubs.svg"),translate("Arch","Toggle subcomponents"),menu) @@ -1268,10 +1359,26 @@ class ViewProviderComponent: menu.addAction(action1) def toggleSubcomponents(self): + """Simple wrapper to call Arch_ToggleSubs when the relevant context + menu choice is selected.""" FreeCADGui.runCommand("Arch_ToggleSubs") def areDifferentColors(self,a,b): + """Checks if two diffuse colors are almost the same. + + Parameters + ---------- + a: tuple + The first DiffuseColor value to compare. + a: tuple + The second DiffuseColor value to compare. + + Returns + ------- + bool: + True if colors are different, false if they are similar. + """ if len(a) != len(b): return True @@ -1281,12 +1388,40 @@ class ViewProviderComponent: return False def colorize(self,obj,force=False): + """If an object is a clone, sets it it to copy the color of it's parent. + + Will only change the color of the clone if the clone and it's parent + have colors that are distinguishably different from each other. + + Parameters + ---------- + obj: + The object to change the color of. + force: bool + If true, forces the colorisation even if the two objects have very + similar colors. + """ if obj.CloneOf: - if self.areDifferentColors(obj.ViewObject.DiffuseColor,obj.CloneOf.ViewObject.DiffuseColor) or force: + if (self.areDifferentColors(obj.ViewObject.DiffuseColor, + obj.CloneOf.ViewObject.DiffuseColor) + or force): + obj.ViewObject.DiffuseColor = obj.CloneOf.ViewObject.DiffuseColor def getHosts(self): + """Returns the hosts of the view provider's host object. + + Note that in this case, the hosts are the objects referenced by Arch + Rebar's "Host" and/or "Hosts" properties specifically. Only Arch Rebar + has these properies. + + Returns + ------- + list of + The Arch Structures hosting this component. + """ + hosts = [] if hasattr(self,"Object"): @@ -1304,15 +1439,36 @@ class ViewProviderComponent: class ArchSelectionObserver: + """Selection observer used throughout the Arch module. - """ArchSelectionObserver([origin,watched,hide,nextCommand]): The ArchSelectionObserver - object can be added as a selection observer to the FreeCAD Gui. If watched is given (a - document object), the observer will be triggered only when that object is selected/unselected. - If hide is True, the watched object will be hidden. If origin is given (a document - object), that object will have its visibility/selectability restored. If nextCommand - is given (a FreeCAD command), it will be executed on leave.""" + When a nextCommand is specified, the observer fires a Gui command when + anything is selected. + + When a watched object is specified, the observer will only fire when this + watched object is selected. + """ def __init__(self,origin=None,watched=None,hide=True,nextCommand=None): + """Initalises the ArchSelectionObserver object. + + Parameters + ---------- + watched: , optional + If no watched value is provided, functionality relating to origin + and hide parameters will not occur. Only the nextCommand will fire. + + When a watched value is provided, the selection observer will only + fire when the watched object has been selected. + hide: bool + Sets if the watched object should be hidden. + origin: