Arch: Added specials snap

* Remove Arch option to snap to wall base (reimplemented below)
* Added new Specials snap button
* Special snap snaps to wall baselines, structure basepoints, and contents of SnapPoints property, if existing
This commit is contained in:
Yorik van Havre
2016-08-22 13:49:54 -03:00
parent d143dcd2db
commit 031bf0ec10
8 changed files with 196 additions and 67 deletions

View File

@@ -240,6 +240,7 @@ class _Equipment(ArchComponent.Component):
#obj.addProperty("Part::PropertyPartShape","SideView","Arch","an optional 2D shape representing a side view of this equipment")
obj.addProperty("App::PropertyString","Model","Arch","The model description of this equipment")
obj.addProperty("App::PropertyString","Url","Arch","The url of the product page of this equipment")
obj.addProperty("App::PropertyVectorList","SnapPoints","Arch","Additional snap points for this equipment")
self.Type = "Equipment"
obj.Role = Roles
obj.Proxy = self

View File

@@ -66,7 +66,7 @@ class ArchWorkbench(Workbench):
self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel',
'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center',
'Draft_Snap_Extension','Draft_Snap_Near','Draft_Snap_Ortho',
'Draft_Snap_Extension','Draft_Snap_Near','Draft_Snap_Ortho','Draft_Snap_Special',
'Draft_Snap_Dimensions','Draft_Snap_WorkingPlane']
def QT_TRANSLATE_NOOP(scope, text): return text

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>414</width>
<height>696</height>
<width>407</width>
<height>646</height>
</rect>
</property>
<property name="windowTitle">
@@ -20,35 +20,6 @@
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Snapping</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="Gui::PrefCheckBox" name="gui::prefcheckbox_6">
<property name="text">
<string>Snap to baselines of Arch objects (override with CTRL)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ArchSnapToBase</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">

View File

@@ -97,7 +97,8 @@ class Snapper:
'angle':'quad',
'center':'quad',
'ortho':'quad',
'intersection':'quad'}
'intersection':'quad',
'special':'quad'}
else:
self.mk = {'passive':'circle',
'extension':'circle',
@@ -109,7 +110,8 @@ class Snapper:
'angle':'square',
'center':'dot',
'ortho':'dot',
'intersection':'dot'}
'intersection':'dot',
'special':'dot'}
self.cursors = {'passive':':/icons/Snap_Near.svg',
'extension':':/icons/Snap_Extension.svg',
'parallel':':/icons/Snap_Parallel.svg',
@@ -120,7 +122,8 @@ class Snapper:
'angle':':/icons/Snap_Angle.svg',
'center':':/icons/Snap_Center.svg',
'ortho':':/icons/Snap_Ortho.svg',
'intersection':':/icons/Snap_Intersection.svg'}
'intersection':':/icons/Snap_Intersection.svg',
'special':':/icons/Snap_Special.svg'}
def snap(self,screenpos,lastpoint=None,active=True,constrain=False,noTracker=False):
"""snap(screenpos,lastpoint=None,active=True,constrain=False,noTracker=False): returns a snapped
@@ -263,36 +266,9 @@ class Snapper:
# active snapping
comp = self.snapInfo['Component']
archSnap = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("ArchSnapToBase",True)
if (Draft.getType(obj) == "Wall") and (not oldActive) and archSnap:
# special snapping for wall: only to its base shape (except when CTRL is pressed)
edges = []
for o in [obj]+obj.Additions:
if Draft.getType(o) == "Wall":
if o.Base:
edges.extend(o.Base.Shape.Edges)
for edge in edges:
snaps.extend(self.snapToEndpoints(edge))
snaps.extend(self.snapToMidpoint(edge))
snaps.extend(self.snapToPerpendicular(edge,lastpoint))
snaps.extend(self.snapToIntersection(edge))
snaps.extend(self.snapToElines(edge,eline))
elif (Draft.getType(obj) == "Structure") and (not oldActive) and archSnap:
# special snapping for struct: only to its base point (except when CTRL is pressed)
if obj.Base:
for edge in obj.Base.Shape.Edges:
snaps.extend(self.snapToEndpoints(edge))
snaps.extend(self.snapToMidpoint(edge))
snaps.extend(self.snapToPerpendicular(edge,lastpoint))
snaps.extend(self.snapToIntersection(edge))
snaps.extend(self.snapToElines(edge,eline))
else:
b = obj.Placement.Base
snaps.append([b,'endpoint',self.toWP(b)])
elif obj.isDerivedFrom("Part::Feature"):
if obj.isDerivedFrom("Part::Feature"):
snaps.extend(self.snapToSpecials(obj))
if Draft.getType(obj) == "Polygon":
# special snapping for polygons: add the center
@@ -806,7 +782,36 @@ class Snapper:
return [p,'passive',p]
else:
return []
def snapToSpecials(self,obj):
"returns special snap locations, if any"
snaps = []
if self.isEnabled("special"):
if (Draft.getType(obj) == "Wall"):
# special snapping for wall: snap to its base shape if it is linear
if obj.Base:
if not obj.Base.Shape.Solids:
for v in obj.Base.Shape.Vertexes:
snaps.append([v.Point,'special',self.toWP(v.Point)])
elif (Draft.getType(obj) == "Structure"):
# special snapping for struct: only to its base point
if obj.Base:
if not obj.Base.Shape.Solids:
for v in obj.Base.Shape.Vertexes:
snaps.append([v.Point,'special',self.toWP(v.Point)])
else:
b = obj.Placement.Base
snaps.append([b,'special',self.toWP(b)])
elif hasattr(obj,"SnapPoints"):
for p in obj.SnapPoints:
p2 = obj.Placement.multVec(p)
snaps.append([p2,'spacial',p2])
return snaps
def getScreenDist(self,dist,cursor):
"returns a distance in 3D space from a screen pixels distance"
view = Draft.get3DView()

View File

@@ -4711,6 +4711,18 @@ class Draft_Snap_Ortho():
if b.objectName() == "SnapButtonortho":
b.toggle()
class Draft_Snap_Special():
def GetResources(self):
return {'Pixmap' : 'Snap_Special',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Snap_Special", "Special"),
'ToolTip' : QtCore.QT_TRANSLATE_NOOP("Draft_Snap_Special", "Snaps to special locations of objects")}
def Activated(self):
if hasattr(FreeCADGui,"Snapper"):
if hasattr(FreeCADGui.Snapper,"toolbarButtons"):
for b in FreeCADGui.Snapper.toolbarButtons:
if b.objectName() == "SnapButtonspecial":
b.toggle()
class Draft_Snap_Dimensions():
def GetResources(self):
return {'Pixmap' : 'Snap_Dimensions',
@@ -4805,6 +4817,7 @@ FreeCADGui.addCommand('Draft_Snap_Center',Draft_Snap_Center())
FreeCADGui.addCommand('Draft_Snap_Extension',Draft_Snap_Extension())
FreeCADGui.addCommand('Draft_Snap_Near',Draft_Snap_Near())
FreeCADGui.addCommand('Draft_Snap_Ortho',Draft_Snap_Ortho())
FreeCADGui.addCommand('Draft_Snap_Special',Draft_Snap_Special())
FreeCADGui.addCommand('Draft_Snap_Dimensions',Draft_Snap_Dimensions())
FreeCADGui.addCommand('Draft_Snap_WorkingPlane',Draft_Snap_WorkingPlane())

View File

@@ -86,7 +86,7 @@ class DraftWorkbench (Workbench):
self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel',
'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center',
'Draft_Snap_Extension','Draft_Snap_Near','Draft_Snap_Ortho',
'Draft_Snap_Extension','Draft_Snap_Near','Draft_Snap_Ortho','Draft_Snap_Special',
'Draft_Snap_Dimensions','Draft_Snap_WorkingPlane']
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft creation tools"),self.cmdList)
self.appendToolbar(QT_TRANSLATE_NOOP("Workbench","Draft modification tools"),self.modList)

View File

@@ -60,6 +60,7 @@
<file>icons/Snap_Near.svg</file>
<file>icons/Snap_Dimensions.svg</file>
<file>icons/Snap_WorkingPlane.svg</file>
<file>icons/Snap_Special.svg</file>
<file>icons/Draft_Clone.svg</file>
<file>icons/Draft_Heal.svg</file>
<file>icons/Draft_Ellipse.svg</file>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.3 KiB