Skip to content

Commit

Permalink
Draft: AutoGroup system
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jan 25, 2017
1 parent bebda4c commit 9a6191f
Show file tree
Hide file tree
Showing 22 changed files with 1,611 additions and 66 deletions.
4 changes: 3 additions & 1 deletion src/Mod/Arch/ArchBuilding.py
Expand Up @@ -244,7 +244,9 @@ def Activated(self):
ss += "]"
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Building"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeBuilding("+ss+")")
FreeCADGui.doCommand("obj = Arch.makeBuilding("+ss+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down
8 changes: 6 additions & 2 deletions src/Mod/Arch/ArchCommands.py
Expand Up @@ -1290,9 +1290,11 @@ def Activated(self):
if sel:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Component"))
FreeCADGui.addModule("Arch")
FreeCADGui.addModule("Draft")
FreeCADGui.Control.closeDialog()
for o in sel:
FreeCADGui.doCommand("Arch.makeComponent(FreeCAD.ActiveDocument."+o.Name+")")
FreeCADGui.doCommand("obj = Arch.makeComponent(FreeCAD.ActiveDocument."+o.Name+")")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand All @@ -1313,9 +1315,11 @@ def Activated(self):
if sel:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Component"))
FreeCADGui.addModule("Arch")
FreeCADGui.addModule("Draft")
FreeCADGui.Control.closeDialog()
for o in sel:
FreeCADGui.doCommand("Arch.cloneComponent(FreeCAD.ActiveDocument."+o.Name+")")
FreeCADGui.doCommand("obj = Arch.cloneComponent(FreeCAD.ActiveDocument."+o.Name+")")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Arch/ArchEquipment.py
Expand Up @@ -192,7 +192,9 @@ def Activated(self):
base = s[0].Name
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Equipment")))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeEquipment(FreeCAD.ActiveDocument." + base + ")")
FreeCADGui.doCommand("obj = Arch.makeEquipment(FreeCAD.ActiveDocument." + base + ")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
# get diffuse color info from base object
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Arch/ArchFloor.py
Expand Up @@ -103,7 +103,9 @@ def Activated(self):
ss += "]"
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Floor"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeFloor("+ss+")")
FreeCADGui.doCommand("obj = Arch.makeFloor("+ss+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Arch/ArchFrame.py
Expand Up @@ -84,7 +84,9 @@ def Activated(self):
if len(s) == 2:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Frame"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeFrame(FreeCAD.ActiveDocument."+s[0].Name+",FreeCAD.ActiveDocument."+s[1].Name+")")
FreeCADGui.doCommand("obj = Arch.makeFrame(FreeCAD.ActiveDocument."+s[0].Name+",FreeCAD.ActiveDocument."+s[1].Name+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Arch/ArchPanel.py
Expand Up @@ -151,8 +151,10 @@ def Activated(self):
return
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Panel")))
FreeCADGui.addModule("Arch")
FreeCADGui.addModule("Draft")
for obj in sel:
FreeCADGui.doCommand("Arch.makePanel(FreeCAD.ActiveDocument." + obj.Name + ",thickness=" + str(self.Thickness) + ")")
FreeCADGui.doCommand("obj = Arch.makePanel(FreeCAD.ActiveDocument." + obj.Name + ",thickness=" + str(self.Thickness) + ")")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
Expand Down
12 changes: 9 additions & 3 deletions src/Mod/Arch/ArchPipe.py
Expand Up @@ -117,12 +117,16 @@ def Activated(self):
if len(obj.Shape.Wires) == 1:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Pipe"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makePipe(FreeCAD.ActiveDocument."+obj.Name+")")
FreeCADGui.doCommand("obj = Arch.makePipe(FreeCAD.ActiveDocument."+obj.Name+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
else:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Pipe"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makePipe()")
FreeCADGui.doCommand("obj = Arch.makePipe()")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down Expand Up @@ -159,7 +163,9 @@ def Activated(self):
o += "]"
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Connector"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makePipeConnector("+o+")")
FreeCADGui.doCommand("obj = Arch.makePipeConnector("+o+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down
8 changes: 6 additions & 2 deletions src/Mod/Arch/ArchRoof.py
Expand Up @@ -139,15 +139,19 @@ def Activated(self):
idx = int(sel.SubElementNames[0][4:])
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Roof"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+","+str(idx)+")")
FreeCADGui.doCommand("obj = Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+","+str(idx)+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
if obj.isDerivedFrom("Part::Feature"):
if obj.Shape.Wires:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Roof"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+")")
FreeCADGui.doCommand("obj = Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Arch/ArchSite.py
Expand Up @@ -290,7 +290,9 @@ def Activated(self):
ss += "]"
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Site"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeSite("+ss+")")
FreeCADGui.doCommand("obj = Arch.makeSite("+ss+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down
6 changes: 4 additions & 2 deletions src/Mod/Arch/ArchSpace.py
Expand Up @@ -229,9 +229,11 @@ def Activated(self):
if sel:
FreeCADGui.Control.closeDialog()
if len(sel) == 1:
FreeCADGui.doCommand("Arch.makeSpace(FreeCADGui.Selection.getSelection())")
FreeCADGui.doCommand("obj = Arch.makeSpace(FreeCADGui.Selection.getSelection())")
else:
FreeCADGui.doCommand("Arch.makeSpace(FreeCADGui.Selection.getSelectionEx())")
FreeCADGui.doCommand("obj = Arch.makeSpace(FreeCADGui.Selection.getSelectionEx())")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
else:
Expand Down
6 changes: 4 additions & 2 deletions src/Mod/Arch/ArchStairs.py
Expand Up @@ -91,9 +91,11 @@ def Activated(self):
FreeCADGui.addModule("Arch")
if len(FreeCADGui.Selection.getSelection()) == 1:
n = FreeCADGui.Selection.getSelection()[0].Name
FreeCADGui.doCommand("Arch.makeStairs(baseobj=FreeCAD.ActiveDocument."+n+")")
FreeCADGui.doCommand("obj = Arch.makeStairs(baseobj=FreeCAD.ActiveDocument."+n+")")
else:
FreeCADGui.doCommand("Arch.makeStairs(steps="+str(p.GetInt("StairsSteps",17))+")")
FreeCADGui.doCommand("obj = Arch.makeStairs(steps="+str(p.GetInt("StairsSteps",17))+")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()

Expand Down
12 changes: 9 additions & 3 deletions src/Mod/Arch/ArchStructure.py
Expand Up @@ -155,17 +155,21 @@ def Activated(self):
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Structural System")))
FreeCADGui.addModule("Arch")
if st:
FreeCADGui.doCommand("Arch.makeStructuralSystem(" + ArchCommands.getStringList(st) + "," + ArchCommands.getStringList(ax) + ")")
FreeCADGui.doCommand("obj = Arch.makeStructuralSystem(" + ArchCommands.getStringList(st) + "," + ArchCommands.getStringList(ax) + ")")
else:
FreeCADGui.doCommand("Arch.makeStructuralSystem(axes=" + ArchCommands.getStringList(ax) + ")")
FreeCADGui.doCommand("obj = Arch.makeStructuralSystem(axes=" + ArchCommands.getStringList(ax) + ")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
elif not(ax) and not(st):
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Structure")))
FreeCADGui.addModule("Arch")
for obj in sel:
FreeCADGui.doCommand("Arch.makeStructure(FreeCAD.ActiveDocument." + obj.Name + ")")
FreeCADGui.doCommand("obj = Arch.makeStructure(FreeCAD.ActiveDocument." + obj.Name + ")")
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
Expand Down Expand Up @@ -226,6 +230,8 @@ def getPoint(self,point=None,obj=None):
FreeCADGui.doCommand('s = Arch.makeStructure(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')')
FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point))
FreeCADGui.doCommand('s.Placement.Rotation=s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)')
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(s)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
if self.continueCmd:
Expand Down
10 changes: 7 additions & 3 deletions src/Mod/Arch/ArchWall.py
Expand Up @@ -198,12 +198,14 @@ def Activated(self):
if selobj.HasSubObjects:
if "Face" in selobj.SubElementNames[0]:
idx = int(selobj.SubElementNames[0][4:])
FreeCADGui.doCommand("Arch.makeWall(FreeCAD.ActiveDocument."+selobj.Object.Name+",face="+str(idx)+")")
FreeCADGui.doCommand("obj = Arch.makeWall(FreeCAD.ActiveDocument."+selobj.Object.Name+",face="+str(idx)+")")
spacedone = True
if not spacedone:
FreeCADGui.doCommand('Arch.makeWall(FreeCAD.ActiveDocument.'+selobj.Object.Name+')')
FreeCADGui.doCommand('obj = Arch.makeWall(FreeCAD.ActiveDocument.'+selobj.Object.Name+')')
else:
FreeCADGui.doCommand('Arch.makeWall(FreeCAD.ActiveDocument.'+selobj.Object.Name+')')
FreeCADGui.doCommand('obj = Arch.makeWall(FreeCAD.ActiveDocument.'+selobj.Object.Name+')')
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(obj)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
done = True
Expand Down Expand Up @@ -273,6 +275,8 @@ def addDefault(self,l):
FreeCADGui.doCommand('base.addGeometry(trace)')
FreeCADGui.doCommand('wall = Arch.makeWall(base,width='+str(self.Width)+',height='+str(self.Height)+',align="'+str(self.Align)+'")')
FreeCADGui.doCommand('wall.Normal = FreeCAD.DraftWorkingPlane.axis')
FreeCADGui.addModule("Draft")
FreeCADGui.doCommand("Draft.autogroup(wall)")

def update(self,point,info):
"this function is called by the Snapper when the mouse is moved"
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/InitGui.py
Expand Up @@ -57,7 +57,7 @@ def Initialize(self):
"Draft_Clone"]
self.draftextratools = ["Draft_WireToBSpline","Draft_AddPoint","Draft_DelPoint","Draft_ShapeString",
"Draft_PathArray","Draft_Mirror","Draft_Stretch"]
self.draftcontexttools = ["Draft_ApplyStyle","Draft_ToggleDisplayMode","Draft_AddToGroup",
self.draftcontexttools = ["Draft_ApplyStyle","Draft_ToggleDisplayMode","Draft_AddToGroup","Draft_AutoGroup",
"Draft_SelectGroup","Draft_SelectPlane",
"Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine",
"Draft_FinishLine","Draft_CloseLine"]
Expand Down
31 changes: 26 additions & 5 deletions src/Mod/Draft/Draft.py
Expand Up @@ -233,7 +233,7 @@ def getGroupNames():
glist = []
doc = FreeCAD.ActiveDocument
for obj in doc.Objects:
if obj.TypeId == "App::DocumentObjectGroup":
if obj.isDerivedFrom("App::DocumentObjectGroup") or (getType(obj) in ["Floor","Building","Site"]):
glist.append(obj.Name)
return glist

Expand All @@ -243,6 +243,23 @@ def ungroup(obj):
grp = FreeCAD.ActiveDocument.getObject(g)
if grp.hasObject(obj):
grp.removeObject(obj)

def autogroup(obj):
"adds a given object to the autogroup, if applicable"
if FreeCAD.GuiUp:
if hasattr(FreeCADGui,"draftToolBar"):
if hasattr(FreeCADGui.draftToolBar,"autogroup") and (not FreeCADGui.draftToolBar.isConstructionMode()):
if FreeCADGui.draftToolBar.autogroup != None:
g = FreeCAD.ActiveDocument.getObject(FreeCADGui.draftToolBar.autogroup)
if g:
found = False
for o in g.Group:
if o.Name == obj.Name:
found = True
if not found:
gr = g.Group
gr.append(obj)
g.Group = gr

def dimSymbol(symbol=None,invert=False):
"returns the current dim symbol from the preferences as a pivy SoMarkerSet"
Expand Down Expand Up @@ -1168,6 +1185,7 @@ def extrude(obj,vector,solid=False):
if gui:
obj.ViewObject.Visibility = False
formatObject(newobj,obj)
select(newobj)
FreeCAD.ActiveDocument.recompute()
return newobj

Expand Down Expand Up @@ -1203,6 +1221,7 @@ def fuse(object1,object2):
object1.ViewObject.Visibility = False
object2.ViewObject.Visibility = False
formatObject(obj,object1)
select(obj)
FreeCAD.ActiveDocument.recompute()
return obj

Expand All @@ -1215,6 +1234,7 @@ def cut(object1,object2):
object1.ViewObject.Visibility = False
object2.ViewObject.Visibility = False
formatObject(obj,object1)
select(obj)
FreeCAD.ActiveDocument.recompute()
return obj

Expand Down Expand Up @@ -1282,7 +1302,7 @@ def move(objectslist,vector,copy=False):
if copy and getParam("selectBaseObjects",False):
select(objectslist)
else:
select(newobjlist)
select(newobjlist)
if len(newobjlist) == 1: return newobjlist[0]
return newobjlist

Expand Down Expand Up @@ -1438,7 +1458,8 @@ def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy
elif (obj.TypeId == "App::Annotation"):
factor = delta.x * delta.y * delta.z * obj.ViewObject.FontSize.Value
obj.ViewObject.Fontsize = factor
if copy: formatObject(newobj,obj)
if copy:
formatObject(newobj,obj)
newobjlist.append(newobj)
if copy and getParam("selectBaseObjects",False):
select(objectslist)
Expand Down Expand Up @@ -2775,6 +2796,7 @@ def makePoint(X=0, Y=0, Z=0,color=None,name = "Point", point_size= 5):
obj.ViewObject.PointColor = (float(color[0]), float(color[1]), float(color[2]))
obj.ViewObject.PointSize = point_size
obj.ViewObject.Visibility = True
select(obj)
FreeCAD.ActiveDocument.recompute()
return obj

Expand Down Expand Up @@ -2968,6 +2990,7 @@ def makeFacebinder(selectionset,name="Facebinder"):
_ViewProviderFacebinder(fb.ViewObject)
faces = []
fb.Proxy.addSubobjects(fb,selectionset)
select(fb)
return fb


Expand Down Expand Up @@ -3330,7 +3353,6 @@ def makeWires(objectslist):
deleteList = []
for n in names:
FreeCAD.ActiveDocument.removeObject(n)

return [addList,deleteList]

def downgrade(objects,delete=False,force=None):
Expand Down Expand Up @@ -3531,7 +3553,6 @@ def splitWires(objects):
deleteList = []
for n in names:
FreeCAD.ActiveDocument.removeObject(n)

return [addList,deleteList]


Expand Down

0 comments on commit 9a6191f

Please sign in to comment.