Skip to content

Commit

Permalink
Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 3, 2015
2 parents 6c18757 + 9b9526e commit 4cfc2a1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/Mod/Arch/ArchComponent.py
Expand Up @@ -114,7 +114,7 @@ def removeFromComponent(compobject,subobject):
l = compobject.Subtractions
l.append(subobject)
compobject.Subtractions = l
if Draft.getType(subobject) != "Window":
if (Draft.getType(subobject) != "Window") and (not Draft.isClone(subobject,"Window",True)):
subobject.ViewObject.hide()


Expand Down Expand Up @@ -511,7 +511,7 @@ def hideSubobjects(self,obj,prop):
if prop in ["Additions","Subtractions"]:
if hasattr(obj,prop):
for o in getattr(obj,prop):
if Draft.getType(o) != "Window":
if (Draft.getType(o) != "Window") and (not Draft.isClone(o,"Window",True)):
if (Draft.getType(obj) == "Wall"):
if (Draft.getType(o) == "Roof"):
continue
Expand Down Expand Up @@ -549,11 +549,11 @@ def processSubShapes(self,obj,base,placement=None):
add.Placement = add.Placement.multiply(placement)
base = base.fuse(add)

elif (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
elif (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window",True)):
f = o.Proxy.getSubVolume(o)
if f:
if base.Solids and f.Solids:
if placemen:
if placement:
f.Placement = f.Placement.multiply(placement)
base = base.cut(f)

Expand Down Expand Up @@ -581,7 +581,7 @@ def processSubShapes(self,obj,base,placement=None):
base = None

if base:
if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window",True)):
# windows can be additions or subtractions, treated the same way
f = o.Proxy.getSubVolume(o)
if f:
Expand Down Expand Up @@ -645,7 +645,7 @@ def updateData(self,obj,prop):
def onChanged(self,vobj,prop):
if prop == "Visibility":
for obj in vobj.Object.Additions+vobj.Object.Subtractions:
if Draft.getType(obj) == "Window":
if (Draft.getType(obj) == "Window") or (Draft.isClone(obj,"Window",True)):
obj.ViewObject.Visibility = vobj.Visibility
return

Expand Down
77 changes: 56 additions & 21 deletions src/Mod/Draft/Draft.py
Expand Up @@ -237,15 +237,18 @@ def get3DView():
return v[0]
return None

def isClone(obj,objtype):
"""isClone(obj,objtype): returns True if the given object is
a clone of an object of the given type"""
def isClone(obj,objtype,recursive=False):
"""isClone(obj,objtype,[recursive]): returns True if the given object is
a clone of an object of the given type. If recursive is True, also check if
the clone is a clone of clone (of clone...) of the given type."""
if getType(obj) == "Clone":
if len(obj.Objects) == 1:
if getType(obj.Objects[0]) == objtype:
return True
elif recursive and (getType(obj.Objects[0]) == "Clone"):
return isClone(obj.Objects[0],objtype,recursive)
return False

def getGroupNames():
"returns a list of existing groups in the document"
glist = []
Expand Down Expand Up @@ -581,17 +584,19 @@ def getMovableChildren(objectslist,recursive=False):
recursive is True, all descendents are considered, otherwise only direct children.'''
added = []
for obj in objectslist:
children = obj.OutList
if hasattr(obj,"Proxy"):
if obj.Proxy:
if hasattr(obj.Proxy,"getSiblings"):
children.extend(obj.Proxy.getSiblings(obj))
for child in children:
if hasattr(child,"MoveWithHost"):
if child.MoveWithHost:
added.append(child)
if recursive:
added.extend(getMovableChildren(children))
if getType(obj) != "Clone":
# clones should never move their children
children = obj.OutList
if hasattr(obj,"Proxy"):
if obj.Proxy:
if hasattr(obj.Proxy,"getSiblings"):
children.extend(obj.Proxy.getSiblings(obj))
for child in children:
if hasattr(child,"MoveWithHost"):
if child.MoveWithHost:
added.append(child)
if recursive:
added.extend(getMovableChildren(children))
return added

def makeCircle(radius, placement=None, face=True, startangle=None, endangle=None, support=None):
Expand Down Expand Up @@ -4639,6 +4644,7 @@ def __init__(self,obj):
obj.addProperty("App::PropertyVector","IntervalAxis","Draft","Distance and orientation of intervals in Axis direction")
obj.addProperty("App::PropertyVector","Center","Draft","Center point")
obj.addProperty("App::PropertyAngle","Angle","Draft","Angle to cover with copies")
obj.addProperty("App::PropertyBool","Fuse","Draft","Specifies if copies must be fused (slower)")
obj.ArrayType = ['ortho','polar']
obj.NumberX = 1
obj.NumberY = 1
Expand All @@ -4650,22 +4656,27 @@ def __init__(self,obj):
obj.IntervalZ = Vector(0,0,0)
obj.Angle = 360
obj.Axis = Vector(0,0,1)
obj.Fuse = False

def execute(self,obj):
import DraftGeomUtils
if hasattr(obj,"Fuse"):
fuse = obj.Fuse
else:
fuse = False
if obj.Base:
pl = obj.Placement
if obj.ArrayType == "ortho":
sh = self.rectArray(obj.Base.Shape,obj.IntervalX,obj.IntervalY,
obj.IntervalZ,obj.NumberX,obj.NumberY,obj.NumberZ)
obj.IntervalZ,obj.NumberX,obj.NumberY,obj.NumberZ,fuse)
else:
av = obj.IntervalAxis if hasattr(obj,"IntervalAxis") else None
sh = self.polarArray(obj.Base.Shape,obj.Center,obj.Angle.Value,obj.NumberPolar,obj.Axis,av)
sh = self.polarArray(obj.Base.Shape,obj.Center,obj.Angle.Value,obj.NumberPolar,obj.Axis,av,fuse)
obj.Shape = sh
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl

def rectArray(self,shape,xvector,yvector,zvector,xnum,ynum,znum):
def rectArray(self,shape,xvector,yvector,zvector,xnum,ynum,znum,fuse=False):
import Part
base = [shape.copy()]
for xcount in range(xnum):
Expand All @@ -4688,9 +4699,15 @@ def rectArray(self,shape,xvector,yvector,zvector,xnum,ynum,znum):
nshape = shape.copy()
nshape.translate(currentzvector)
base.append(nshape)
return Part.makeCompound(base)
if fuse:
fshape = base.pop()
for s in base:
fshape = fshape.fuse(s)
return fshape.removeSplitter()
else:
return Part.makeCompound(base)

def polarArray(self,shape,center,angle,num,axis,axisvector):
def polarArray(self,shape,center,angle,num,axis,axisvector,fuse=False):
#print("angle ",angle," num ",num)
import Part
if angle == 360:
Expand All @@ -4708,7 +4725,14 @@ def polarArray(self,shape,center,angle,num,axis,axisvector):
if not DraftVecUtils.isNull(axisvector):
nshape.translate(FreeCAD.Vector(axisvector).multiply(i+1))
base.append(nshape)
return Part.makeCompound(base)
if fuse:
fshape = base.pop()
for s in base:
fshape = fshape.fuse(s)
return fshape.removeSplitter()
else:
return Part.makeCompound(base)


class _PathArray(_DraftObject):
"The Draft Path Array object"
Expand Down Expand Up @@ -4949,6 +4973,17 @@ def execute(self,obj):
obj.Shape = Part.makeCompound(shapes)
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl

def getSubVolume(self,obj,placement=None):
# this allows clones of arch windows to return a subvolume too
if obj.Objects:
if hasattr(obj.Objects[0],"Proxy"):
if hasattr(obj.Objects[0].Proxy,"getSubVolume"):
if not placement:
# clones must displace the original subvolume too
placement = obj.Placement
return obj.Objects[0].Proxy.getSubVolume(obj.Objects[0],placement)
return None

class _ViewProviderClone(_ViewProviderDraftAlt):
"a view provider that displays a Clone icon instead of a Draft icon"
Expand Down

0 comments on commit 4cfc2a1

Please sign in to comment.