ShowWB: fix header uniformity

Make headers uniform + remote trailing whitespace
This commit is contained in:
luzpaz
2023-01-21 18:02:30 +00:00
committed by Uwe
parent 3a6794a317
commit 3971ea23d1
13 changed files with 223 additions and 239 deletions

View File

@@ -1,6 +1,5 @@
#/***************************************************************************
# * Copyright (c) Victor Titov (DeepSOIC) *
# * (vv.titov@gmail.com) 2018 *
# * Copyright (c) 2018 Victor Titov (DeepSOIC) <vv.titov@gmail.com> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
@@ -27,24 +26,24 @@ class Container(object):
"""Container class: a unified interface for container objects, such as Group, Part, Body, or Document.
This is a temporary implementation."""
Object = None #DocumentObject or Document, the actual container
def __init__(self, obj):
self.Object = obj
def self_check(self):
if self.Object is None:
raise ValueError("Null!")
if not isAContainer(self.Object, links_too= True):
raise NotAContainerError(self.Object)
def getAllChildren(self):
"""Returns all objects directly contained by the container. all = static + dynamic."""
return self.getStaticChildren() + self.getDynamicChildren()
def getStaticChildren(self):
"""Returns children tightly bound to the container, such as Origin. The key thing
"""Returns children tightly bound to the container, such as Origin. The key thing
about them is that they are not supposed to be removed or added from/to the container."""
self.self_check()
container = self.Object
if container.isDerivedFrom('App::Document'):
@@ -66,7 +65,7 @@ class Container(object):
"""Returns dynamic children, i.e. the stuff that can be removed from the container."""
self.self_check()
container = self.Object
if container.isDerivedFrom('App::Document'):
# find all objects not contained by any Part or Body
result = set(container.Objects)
@@ -92,28 +91,28 @@ class Container(object):
return result
raise RuntimeError("getDynamicChildren: unexpected container type!")
def isACS(self):
"""isACS(): returns true if the container forms internal coordinate system."""
self.self_check()
container = self.Object
if container.isDerivedFrom('App::Document'):
return True #Document is a special thing... is it a CS or not is a matter of coding convenience.
return True #Document is a special thing... is it a CS or not is a matter of coding convenience.
elif container.hasExtension('App::GeoFeatureGroupExtension'):
return True
elif container.hasChildElement(): # Link
return True
else:
return False
def isAVisGroup(self):
"""isAVisGroup(): returns True if the container consumes viewproviders of children, and thus affects their visibility."""
self.self_check()
container = self.Object
if container.isDerivedFrom('App::Document'):
return True #Document is a special thing... Return value is a matter of coding convenience.
return True #Document is a special thing... Return value is a matter of coding convenience.
elif container.hasExtension('App::GeoFeatureGroupExtension'):
return True
elif container.isDerivedFrom('App::Origin'):
@@ -122,7 +121,7 @@ class Container(object):
return True
else:
return False
def getCSChildren(self):
if not self.isACS():
raise TypeError("Container is not a coordinate system")
@@ -148,22 +147,22 @@ class Container(object):
def hasObject(self, obj):
"""Returns True if the container contains specified object directly."""
return obj in self.getAllChildren()
def hasObjectRecursive(self, obj):
return self.Object in ContainerChain(obj)
def _getMetacontainerChildren(container, isrightcontainer_func):
"""Gathers up children of metacontainer - a container structure formed by containers of specific type.
"""Gathers up children of metacontainer - a container structure formed by containers of specific type.
For example, coordinate systems form a kind of container structure.
container: instance of Container class
isrightcontainer_func: a function f(cnt)->bool, where cnt is a Container object."""
result = []
list_traversing_now = [container] #list of Container instances
list_to_be_traversed_next = [] #list of Container instances
visited_containers = set([container.Object]) #set of DocumentObjects
while len(list_traversing_now) > 0:
list_to_be_traversed_next = []
for itcnt in list_traversing_now:
@@ -175,19 +174,19 @@ def _getMetacontainerChildren(container, isrightcontainer_func):
if not isrightcontainer_func(newcnt):
list_to_be_traversed_next.append(newcnt)
list_traversing_now = list_to_be_traversed_next
return result
def isAContainer(obj, links_too = False):
'''isAContainer(obj, links_too): returns True if obj is an object container, such as
Group, Part, Body. The important characteristic of an object being a
container is that it can be activated to receive new objects. Documents
'''isAContainer(obj, links_too): returns True if obj is an object container, such as
Group, Part, Body. The important characteristic of an object being a
container is that it can be activated to receive new objects. Documents
are considered containers, too.
If links_too, App::Link objects are considered containers, too. Then, container tree
If links_too, App::Link objects are considered containers, too. Then, container tree
isn't necessarily a tree.'''
if obj.isDerivedFrom('App::Document'):
return True
if obj.hasExtension('App::GroupExtension'):
@@ -208,27 +207,27 @@ def ContainerOf(obj):
if cnt is not None and dep is not cnt:
raise ContainerTreeError("Container tree is not a tree")
cnt = dep
if cnt is None:
if cnt is None:
return obj.Document
return cnt
def getVisGroupOf(obj):
chain = VisGroupChain(obj)
return chain[-1]
#from Part-o-magic... over-engineered, but proven to work
def ContainerChain(feat):
'''ContainerChain(feat): container path to feat (not including feat itself).
Last container directly contains the feature.
'''ContainerChain(feat): container path to feat (not including feat itself).
Last container directly contains the feature.
Example of output: [<document>,<SuperPart>,<Part>,<Body>]'''
if feat.isDerivedFrom('App::Document'):
return []
list_traversing_now = [feat]
set_of_deps = set()
list_of_deps = []
while len(list_traversing_now) > 0:
list_to_be_traversed_next = []
for feat in list_traversing_now:
@@ -241,7 +240,7 @@ def ContainerChain(feat):
if len(list_to_be_traversed_next) > 1:
raise ContainerTreeError("Container tree is not a tree")
list_traversing_now = list_to_be_traversed_next
return [feat.Document] + list_of_deps[::-1]
def CSChain(feat):