Added support for multi base model to Engrave.
This commit is contained in:
@@ -100,7 +100,8 @@ class ObjectChamfer(PathEngraveBase.ObjectOp):
|
||||
|
||||
self.basewires.extend(basewires)
|
||||
|
||||
for w in self.adjustWirePlacement(obj, base, basewires):
|
||||
#for w in self.adjustWirePlacement(obj, base, basewires):
|
||||
for w in basewires:
|
||||
self.adjusted_basewires.append(w)
|
||||
wire = PathOpTools.offsetWire(w, base.Shape, offset, True)
|
||||
if wire:
|
||||
|
||||
@@ -36,7 +36,7 @@ from PySide import QtCore
|
||||
|
||||
__doc__ = "Class and implementation of Path Engrave operation"
|
||||
|
||||
if False:
|
||||
if True:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
else:
|
||||
@@ -75,30 +75,29 @@ class ObjectEngrave(PathEngraveBase.ObjectOp):
|
||||
PathLog.track()
|
||||
|
||||
job = PathUtils.findParentJob(obj)
|
||||
if job and job.Base:
|
||||
obj.BaseObject = job.Base
|
||||
|
||||
jobshapes = []
|
||||
zValues = self.getZValues(obj)
|
||||
|
||||
try:
|
||||
if self.baseobject.isDerivedFrom('Sketcher::SketchObject') or \
|
||||
self.baseobject.isDerivedFrom('Part::Part2DObject') or \
|
||||
hasattr(self.baseobject, 'ArrayType'):
|
||||
if len(self.model) == 1 and self.model[0].isDerivedFrom('Sketcher::SketchObject') or \
|
||||
self.model[0].isDerivedFrom('Part::Part2DObject') or \
|
||||
hasattr(self.model[0], 'ArrayType'):
|
||||
PathLog.track()
|
||||
|
||||
self.commandlist.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid}))
|
||||
|
||||
# we only consider the outer wire if this is a Face
|
||||
wires = []
|
||||
for w in self.baseobject.Shape.Wires:
|
||||
for w in self.model[0].Shape.Wires:
|
||||
wires.append(Part.Wire(w.Edges))
|
||||
self.buildpathocc(obj, wires, zValues)
|
||||
self.wires = wires
|
||||
|
||||
elif isinstance(self.baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet
|
||||
elif len(self.model) == 1 and isinstance(self.model[0].Proxy, ArchPanel.PanelSheet): # process the sheet
|
||||
PathLog.track()
|
||||
wires = []
|
||||
for tag in self.baseobject.Proxy.getTags(self.baseobject, transform=True):
|
||||
for tag in self.model[0].Proxy.getTags(self.model[0], transform=True):
|
||||
self.commandlist.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid}))
|
||||
tagWires = []
|
||||
for w in tag.Wires:
|
||||
@@ -124,18 +123,28 @@ class ObjectEngrave(PathEngraveBase.ObjectOp):
|
||||
for edgelist in Part.sortEdges(edges):
|
||||
basewires.append(Part.Wire(edgelist))
|
||||
|
||||
wires.extend(self.adjustWirePlacement(obj, base, basewires))
|
||||
#wires.extend(self.adjustWirePlacement(obj, base, basewires))
|
||||
wires.extend(basewires)
|
||||
self.buildpathocc(obj, wires, zValues)
|
||||
self.wires = wires
|
||||
elif not obj.BaseShapes:
|
||||
PathLog.track()
|
||||
raise ValueError(translate('PathEngrave', "Unknown baseobject type for engraving (%s)") % (obj.Base))
|
||||
if not obj.Base and not obj.BaseShapes:
|
||||
for base in self.model:
|
||||
PathLog.track(base.Label)
|
||||
if base.isDerivedFrom('Part::Part2DObject'):
|
||||
jobshapes.append(base)
|
||||
|
||||
if obj.BaseShapes:
|
||||
if not jobshapes:
|
||||
raise ValueError(translate('PathEngrave', "Unknown baseobject type for engraving (%s)") % (obj.Base))
|
||||
|
||||
if obj.BaseShapes or jobshapes:
|
||||
PathLog.track()
|
||||
wires = []
|
||||
for shape in obj.BaseShapes:
|
||||
shapeWires = self.adjustWirePlacement(obj, shape, shape.Shape.Wires)
|
||||
for shape in obj.BaseShapes + jobshapes:
|
||||
PathLog.track(shape.Label)
|
||||
#shapeWires = self.adjustWirePlacement(obj, shape, shape.Shape.Wires)
|
||||
shapeWires = shape.Shape.Wires
|
||||
self.buildpathocc(obj, shapeWires, zValues)
|
||||
wires.extend(shapeWires)
|
||||
self.wires = wires
|
||||
|
||||
@@ -46,32 +46,33 @@ else:
|
||||
def translate(context, text, disambig=None):
|
||||
return QtCore.QCoreApplication.translate(context, text, disambig)
|
||||
|
||||
def adjustPlacement(obj, shape, wires):
|
||||
job = PathUtils.findParentJob(obj)
|
||||
if hasattr(shape, 'MapMode') and 'Deactivated' != shape.MapMode:
|
||||
if hasattr(shape, 'Support') and 1 == len(shape.Support) and 1 == len(shape.Support[0][1]):
|
||||
pmntShape = shape.Placement
|
||||
pmntSupport = shape.Support[0][0].getGlobalPlacement()
|
||||
#pmntSupport = shape.Support[0][0].Placement
|
||||
pmntBase = job.Base.Placement
|
||||
pmnt = pmntBase.multiply(pmntSupport.inverse().multiply(pmntShape))
|
||||
#PathLog.debug("pmnt = %s" % pmnt)
|
||||
newWires = []
|
||||
for w in wires:
|
||||
edges = []
|
||||
for e in w.Edges:
|
||||
e = e.copy()
|
||||
e.Placement = FreeCAD.Placement()
|
||||
edges.append(e)
|
||||
w = Part.Wire(edges)
|
||||
w.Placement = pmnt
|
||||
newWires.append(w)
|
||||
wires = newWires
|
||||
else:
|
||||
PathLog.warning(translate("PathEngrave", "Attachment not supported by engraver"))
|
||||
else:
|
||||
PathLog.debug("MapMode: %s" % (shape.MapMode if hasattr(shape, 'MapMode') else 'None'))
|
||||
return wires
|
||||
#def adjustPlacement(obj, shape, wires):
|
||||
# job = PathUtils.findParentJob(obj)
|
||||
# if hasattr(shape, 'MapMode') and 'Deactivated' != shape.MapMode:
|
||||
# if hasattr(shape, 'Support') and 1 == len(shape.Support) and 1 == len(shape.Support[0][1]):
|
||||
# pmntShape = shape.Placement
|
||||
# pmntSupport = shape.Support[0][0].getGlobalPlacement()
|
||||
# #pmntSupport = shape.Support[0][0].Placement
|
||||
# pmntBase = job.Base.Placement
|
||||
# pmnt = pmntBase.multiply(pmntSupport.inverse().multiply(pmntShape))
|
||||
# #PathLog.debug("pmnt = %s" % pmnt)
|
||||
# newWires = []
|
||||
# for w in wires:
|
||||
# edges = []
|
||||
# for e in w.Edges:
|
||||
# e = e.copy()
|
||||
# e.Placement = FreeCAD.Placement()
|
||||
# edges.append(e)
|
||||
# w = Part.Wire(edges)
|
||||
# w.Placement = pmnt
|
||||
# newWires.append(w)
|
||||
# wires = newWires
|
||||
# else:
|
||||
# PathLog.warning(translate("PathEngrave", "Attachment not supported by engraver"))
|
||||
# else:
|
||||
# PathLog.debug("MapMode: %s" % (shape.MapMode if hasattr(shape, 'MapMode') else 'None'))
|
||||
# return wires
|
||||
|
||||
|
||||
class ObjectOp(PathOp.ObjectOp):
|
||||
'''Proxy base class for engrave operations.'''
|
||||
@@ -150,15 +151,16 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
params.update({'Z': z, 'F': self.horizFeed})
|
||||
self.commandlist.append(Path.Command(cmd.Name, params))
|
||||
|
||||
def opSetDefaultValues(self, obj, job):
|
||||
'''opSetDefaultValues(obj, job) ... set depths for engraving'''
|
||||
def opSetDefaultValues(self, obj):
|
||||
'''opSetDefaultValues(obj) ... set depths for engraving'''
|
||||
if PathOp.FeatureDepths & self.opFeatures(obj):
|
||||
if job and job.Base:
|
||||
bb = job.Base.Shape.BoundBox
|
||||
job = PathUtils.findParentJob(obj)
|
||||
if job and len(job.Model.Group) > 0:
|
||||
bb = job.Proxy.modelBoundBox(job)
|
||||
obj.OpStartDepth = bb.ZMax
|
||||
obj.OpFinalDepth = bb.ZMax - max(obj.StepDown.Value, 0.1)
|
||||
else:
|
||||
obj.OpFinalDepth = -0.1
|
||||
|
||||
def adjustWirePlacement(self, obj, shape, wires):
|
||||
return adjustPlacement(obj, shape, wires)
|
||||
#def adjustWirePlacement(self, obj, shape, wires):
|
||||
# return adjustPlacement(obj, shape, wires)
|
||||
|
||||
@@ -28,6 +28,7 @@ import PathScripts.PathEngrave as PathEngrave
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathOpGui as PathOpGui
|
||||
import PathScripts.PathSelection as PathSelection
|
||||
import PathScripts.PathUtils as PathUtils
|
||||
|
||||
from PySide import QtCore, QtGui
|
||||
|
||||
@@ -55,22 +56,30 @@ class TaskPanelBaseGeometryPage(PathOpGui.TaskPanelBaseGeometryPage):
|
||||
added = False
|
||||
shapes = self.obj.BaseShapes
|
||||
for sel in selection:
|
||||
if sel.Object in shapes:
|
||||
job = PathUtils.findParentJob(self.obj)
|
||||
base = job.Proxy.resourceClone(job, sel.Object)
|
||||
if not base:
|
||||
PathLog.notice((translate("Path", "%s is not a Base Model object of the job %s")+"\n") % (sel.Object.Label, job.Label))
|
||||
continue
|
||||
if base in shapes:
|
||||
PathLog.notice((translate("Path", "Base shape %s already in the list")+"\n") % (sel.Object.Label))
|
||||
continue
|
||||
if sel.Object.isDerivedFrom('Part::Part2DObject'):
|
||||
if base.isDerivedFrom('Part::Part2DObject'):
|
||||
if sel.HasSubObjects:
|
||||
# selectively add some elements of the drawing to the Base
|
||||
for sub in sel.SubElementNames:
|
||||
if 'Vertex' in sub:
|
||||
PathLog.info(translate("Path", "Ignoring vertex"))
|
||||
else:
|
||||
self.obj.Proxy.addBase(self.obj, sel.Object, sub)
|
||||
self.obj.Proxy.addBase(self.obj, base, sub)
|
||||
else:
|
||||
self.obj.Base = [(p,el) for p,el in self.obj.Base if p != sel.Object]
|
||||
shapes.append(sel.Object)
|
||||
# when adding an entire shape to BaseShapes we can take its sub shapes out of Base
|
||||
self.obj.Base = [(p,el) for p,el in self.obj.Base if p != base]
|
||||
shapes.append(base)
|
||||
self.obj.BaseShapes = shapes
|
||||
added = True
|
||||
else:
|
||||
# user wants us to engrave an edge of face of a base model
|
||||
base = self.super().addBaseGeometry(selection)
|
||||
added = added or base
|
||||
|
||||
|
||||
@@ -252,6 +252,15 @@ class ObjectJob:
|
||||
'''Return the base objects, not their clones.'''
|
||||
return [self.baseObject(obj, base) for base in obj.Model.Group]
|
||||
|
||||
def resourceClone(self, obj, base):
|
||||
'''resourceClone(obj, base) ... Return the resource clone for base if it exists.'''
|
||||
if isResourceClone(obj, base, None):
|
||||
return base
|
||||
for b in obj.Model.Group:
|
||||
if base == b.Objects[0]:
|
||||
return b
|
||||
return None
|
||||
|
||||
def setFromTemplateFile(self, obj, template):
|
||||
'''setFromTemplateFile(obj, template) ... extract the properties from the given template file and assign to receiver.
|
||||
This will also create any TCs stored in the template.'''
|
||||
|
||||
@@ -38,7 +38,7 @@ from PySide import QtCore, QtGui
|
||||
def translate(context, text, disambig=None):
|
||||
return QtCore.QCoreApplication.translate(context, text, disambig)
|
||||
|
||||
if False:
|
||||
if True:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
else:
|
||||
@@ -76,6 +76,7 @@ class JobCreate:
|
||||
expandJobs = False
|
||||
index = 0
|
||||
for base in sorted(PathJob.ObjectJob.baseCandidates(), key=lambda o: o.Label):
|
||||
PathLog.track(base.Label)
|
||||
if not base in xxx and not PathJob.isResourceClone(job, base, None) and not hasattr(base, 'StockType'):
|
||||
item = QtGui.QTreeWidgetItem([base.Label])
|
||||
item.setData(0, self.DataObject, base)
|
||||
|
||||
@@ -35,22 +35,32 @@ other than PathLog, then it probably doesn't belong here.
|
||||
import PathScripts.PathLog as PathLog
|
||||
import sys
|
||||
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
if False:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
else:
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
|
||||
# NotValidBaseTypeIds = ['Sketcher::SketchObject']
|
||||
NotValidBaseTypeIds = []
|
||||
|
||||
NotValidBaseTypeIds = ['Sketcher::SketchObject']
|
||||
|
||||
def isValidBaseObject(obj):
|
||||
'''isValidBaseObject(obj) ... returns true if the object can be used as a base for a job.'''
|
||||
if hasattr(obj, 'getParentGeoFeatureGroup') and obj.getParentGeoFeatureGroup():
|
||||
# Can't link to anything inside a geo feature group anymore
|
||||
PathLog.debug("%s is inside a geo feature group" % obj.Label)
|
||||
return False
|
||||
if hasattr(obj, 'TypeId') and 'App::Part' == obj.TypeId:
|
||||
return obj.Group and any(hasattr(o, 'Shape') for o in obj.Group)
|
||||
if not hasattr(obj, 'Shape'):
|
||||
PathLog.debug("%s has no shape" % obj.Label)
|
||||
return False
|
||||
if obj.TypeId in NotValidBaseTypeIds:
|
||||
PathLog.debug("%s is blacklisted (%s)" % (obj.Label, obj.TypeId))
|
||||
return False
|
||||
if hasattr(obj, 'Sheets') or hasattr(obj, 'TagText'): # Arch.Panels and Arch.PanelCut
|
||||
PathLog.debug("%s is not an Arch.Panel" % (obj.Label))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user