Skip to content

Commit

Permalink
Draft/Arch related changes
Browse files Browse the repository at this point in the history
* Add Draft_LinkArray and Draft_PathLinkArray that uses link for both
  data and visualization, which supports linking external objects

* Add link group support for draft snap

* Fix ArchWindows expression ambiguity
  • Loading branch information
realthunder committed Jul 14, 2019
1 parent 660c931 commit efd53e8
Show file tree
Hide file tree
Showing 9 changed files with 2,047 additions and 115 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchWindow.py
Expand Up @@ -358,7 +358,7 @@ def doorFrame(s,width,height,h1,w1,o1):
s.renameConstraint(58,'Frame8')
s.renameConstraint(59,'Frame9')
s.renameConstraint(60,'F10')
s.setExpression('Constraints.F10','-Constraints.Frame5')
s.setExpression('.Constraints.F10','-.Constraints.Frame5')
fw = str(w2)
if w2 == w1:
fw = "0.00+V"
Expand Down
374 changes: 272 additions & 102 deletions src/Mod/Draft/Draft.py

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions src/Mod/Draft/DraftSnap.py
Expand Up @@ -234,8 +234,8 @@ def snap(self,screenpos,lastpoint=None,active=True,constrain=False,noTracker=Fal
self.trackLine.p1(lastpoint)

# checking if parallel to one of the edges of the last objects or to a polar direction
eline = None
if active:
eline = None
point,eline = self.snapToPolar(point,lastpoint)
point,eline = self.snapToExtensions(point,lastpoint,constrain,eline)

Expand Down Expand Up @@ -273,14 +273,21 @@ def cycleSnapObject(self):

def snapToObject(self, lastpoint, active, constrain, eline, point, oldActive):
# we have an object to snap to
snaps = []

obj = FreeCAD.ActiveDocument.getObject(self.snapInfo['Object'])
parent = self.snapInfo.get('ParentObject',None)
if parent:
subname = self.snapInfo['SubName']
obj = parent.getSubObject(subname,retType=1)
else:
obj = FreeCAD.ActiveDocument.getObject(self.snapInfo['Object'])
parent = obj
subname = self.snapInfo['Component']
if not obj:
self.spoint = self.cstr(lastpoint, constrain, point)
self.spoint = cstr(point)
self.running = False
return self.spoint

snaps = []
self.lastSnappedObject = obj

if hasattr(obj.ViewObject,"Selectable"):
Expand All @@ -303,11 +310,10 @@ def snapToObject(self, lastpoint, active, constrain, eline, point, oldActive):
# active snapping
comp = self.snapInfo['Component']

if obj.isDerivedFrom("Part::Feature"):
shape = Part.getShape(parent,subname,
needSubElement=True,noElementMap=True)

# applying global placements
shape = obj.Shape.copy()
shape.Placement = obj.getGlobalPlacement()
if not shape.isNull():

snaps.extend(self.snapToSpecials(obj,lastpoint,eline))

Expand Down
36 changes: 34 additions & 2 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -4800,6 +4800,10 @@ def proceed(self):
class Array(Modifier):
"The Shape2DView FreeCAD command definition"

def __init__(self,useLink=False):
Modifier.__init__(self)
self.useLink = useLink

def GetResources(self):
return {'Pixmap' : 'Draft_Array',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Array", "Array"),
Expand All @@ -4822,14 +4826,29 @@ def proceed(self):
obj = FreeCADGui.Selection.getSelection()[0]
FreeCADGui.addModule("Draft")
self.commit(translate("draft","Array"),
['obj = Draft.makeArray(FreeCAD.ActiveDocument.'+obj.Name+',FreeCAD.Vector(1,0,0),FreeCAD.Vector(0,1,0),2,2)',
['obj = Draft.makeArray(FreeCAD.ActiveDocument.{},FreeCAD.Vector(1,0,0),FreeCAD.Vector(0,1,0),2,2,useLink={})'.format(obj.Name,self.useLink),
'Draft.autogroup(obj)',
'FreeCAD.ActiveDocument.recompute()'])
self.finish()

class LinkArray(Array):
"The Shape2DView FreeCAD command definition"

def __init__(self):
Array.__init__(self,True)

def GetResources(self):
return {'Pixmap' : 'Draft_LinkArray',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_LinkArray", "LinkArray"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_LinkArray", "Creates a polar or rectangular link array from a selected object")}

class PathArray(Modifier):
"The PathArray FreeCAD command definition"

def __init__(self,useLink=False):
Modifier.__init__(self)
self.useLink = useLink

def GetResources(self):
return {'Pixmap' : 'Draft_PathArray',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_PathArray", "PathArray"),
Expand Down Expand Up @@ -4858,11 +4877,22 @@ def proceed(self):
defCount = 4
defAlign = False
FreeCAD.ActiveDocument.openTransaction("PathArray")
Draft.makePathArray(base,path,defCount,defXlate,defAlign,pathsubs)
Draft.makePathArray(base,path,defCount,defXlate,defAlign,pathsubs,useLink=self.useLink)
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute() # feature won't appear until recompute.
self.finish()

class PathLinkArray(PathArray):
"The PathLinkArray FreeCAD command definition"

def __init__(self):
PathArray.__init__(self,True)

def GetResources(self):
return {'Pixmap' : 'Draft_PathLinkArray',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_PathLinkArray", "PathLinkArray"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_PathLinkArray", "Creates links of a selected object along a selected path.")}

class PointArray(Modifier):
"The PointArray FreeCAD command definition"

Expand Down Expand Up @@ -5846,8 +5876,10 @@ def IsActive(self):
FreeCADGui.addCommand('Draft_WireToBSpline',WireToBSpline())
FreeCADGui.addCommand('Draft_Draft2Sketch',Draft2Sketch())
FreeCADGui.addCommand('Draft_Array',Array())
FreeCADGui.addCommand('Draft_LinkArray',LinkArray())
FreeCADGui.addCommand('Draft_Clone',Draft_Clone())
FreeCADGui.addCommand('Draft_PathArray',PathArray())
FreeCADGui.addCommand('Draft_PathLinkArray',PathLinkArray())
FreeCADGui.addCommand('Draft_PointArray',PointArray())
FreeCADGui.addCommand('Draft_Heal',Heal())
FreeCADGui.addCommand('Draft_Mirror',Mirror())
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/DraftTrackers.py
Expand Up @@ -723,6 +723,7 @@ def __init__(self,pos=Vector(0,0,0),name=None,idx=0,objcol=None,\
else:
selnode = coin.SoType.fromName("SoFCSelection").createInstance()
if name:
selnode.useNewSelection = False
selnode.documentName.setValue(FreeCAD.ActiveDocument.Name)
selnode.objectName.setValue(name)
selnode.subElementName.setValue("EditNode"+str(idx))
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Draft/InitGui.py
Expand Up @@ -86,8 +86,8 @@ def QT_TRANSLATE_NOOP(scope, text):
self.modList = ["Draft_Move","Draft_Rotate","Draft_Offset",
"Draft_Trimex", "Draft_Join", "Draft_Split", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
"Draft_Edit","Draft_Edit_Improved","Draft_WireToBSpline","Draft_AddPoint",
"Draft_DelPoint","Draft_Shape2DView","Draft_Draft2Sketch","Draft_Array",
"Draft_PathArray", "Draft_PointArray","Draft_Clone",
"Draft_DelPoint","Draft_Shape2DView","Draft_Draft2Sketch","Draft_Array","Draft_LinkArray",
"Draft_PathArray","Draft_PathLinkArray","Draft_PointArray","Draft_Clone",
"Draft_Drawing","Draft_Mirror","Draft_Stretch"]
self.treecmdList = ["Draft_ApplyStyle","Draft_ToggleDisplayMode","Draft_AddToGroup",
"Draft_SelectGroup","Draft_SelectPlane",
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Draft/Resources/Draft.qrc
Expand Up @@ -44,11 +44,13 @@
<file>icons/Draft_Wipe.svg</file>
<file>icons/Draft_Draft2Sketch.svg</file>
<file>icons/Draft_Array.svg</file>
<file>icons/Draft_LinkArray.svg</file>
<file>icons/Draft_Cursor.svg</file>
<file>icons/Draft_Dot.svg</file>
<file>icons/Draft_Point.svg</file>
<file>icons/Draft_Snap.svg</file>
<file>icons/Draft_PathArray.svg</file>
<file>icons/Draft_PathLinkArray.svg</file>
<file>icons/Draft_PointArray.svg</file>
<file>icons/Draft_VisGroup.svg</file>
<file>icons/Snap_Lock.svg</file>
Expand Down

0 comments on commit efd53e8

Please sign in to comment.