Here is a very raw (i'm a real noob) implementation of what i wanted.
The wall can move every children accordingly, and they are always represented "in place".
Long road before this could become usable, but... why not working on it?
Code: Select all
class MyWall(object):
def __init__(self, obj=None):
#self.Type = 'wall'
if obj:
obj.Proxy = self
self.Object = obj
self.attach(obj)
def __getstate__(self):
return
def __setstate__(self,_state):
return
def execute(self,obj):
print("running Execute")
"builds the wall shape"
import Part
if hasattr(obj,"Length") and hasattr(obj,"Width") and hasattr(obj,"Height"):
wall_shape = Part.makeBox(obj.Length,obj.Width, obj.Height)
obj.Shape = wall_shape
children_shapes= []
for child in obj.Group:
if hasattr(child, "Shape"):
children_shapes.append(child.Shape)
children_shapes.append(wall_shape)
obj.Shape = Part.Compound(children_shapes)
def attach(self,obj):
print("running obj attach method")
obj.addExtension('App::OriginGroupExtensionPython', None)
obj.Origin = FreeCAD.ActiveDocument.addObject('App::Origin','Origin')
def onDocumentRestored(self, obj):
self.Object = obj
class ViewProviderMyWall(object):
def __init__(self,vobj=None):
if vobj:
vobj.Proxy = self
self.attach(vobj)
else:
self.ViewObject = None
def updateData(self, obj, prop):
return
def attach(self,vobj):
print("running vobj attach method")
vobj.addExtension('Gui::ViewProviderOriginGroupExtensionPython', None)
self.ViewObject = vobj
def __getstate__(self):
return None
def __setstate__(self, _state):
return None
def getDefaultDisplayMode(self):
"""
Return the name of the default display mode. It must be defined in getDisplayModes.
"""
return "Flat Lines"
obj = App.ActiveDocument.addObject('Part::FeaturePython', 'Wall', MyWall(), ViewProviderMyWall(), True)
obj.addProperty('App::PropertyString', 'Description', 'Base', 'Box description').Description = ""
obj.addProperty('App::PropertyLength', 'Length', 'Dimensions', 'Box length').Length = 10.0
obj.addProperty('App::PropertyLength', 'Width', 'Dimensions', 'Box width').Width = '2 mm'
obj.addProperty('App::PropertyLength', 'Height', 'Dimensions', 'Box height').Height = '1 cm'
obj.addProperty('App::PropertyAngle', 'FirstAngle', 'Dimensions', 'Box height').FirstAngle = '90 deg'
obj.addProperty('App::PropertyAngle', 'LastAngle', 'Dimensions', 'Box height').LastAngle = '90 deg'