def derivedExecute(self,obj): old_pos = App.Vector() try: old_pos = lattice2BaseFeature.getPlacementsList(obj, suppressWarning= True)[0].Base except Exception: pass #retrieving position may fail if the object is recomputed for the very first time import lattice2GeomUtils ori = lattice2GeomUtils.makeOrientationFromLocalAxesUni(obj.Priority, obj.XDir_wanted * 1.0, obj.YDir_wanted * 1.0, obj.ZDir_wanted * 1.0) # multiply vectors by 1.0 to copy them, to block mutation plm = App.Placement(old_pos, ori) obj.XDir_actual = ori.multVec(App.Vector(1,0,0)) obj.YDir_actual = ori.multVec(App.Vector(0,1,0)) obj.ZDir_actual = ori.multVec(App.Vector(0,0,1)) return [plm]
def derivedExecute(self, obj): old_pos = App.Vector() try: old_pos = lattice2BaseFeature.getPlacementsList( obj, suppressWarning=True)[0].Base except Exception: pass #retrieving position may fail if the object is recomputed for the very first time import lattice2GeomUtils ori = lattice2GeomUtils.makeOrientationFromLocalAxesUni( obj.Priority, obj.XDir_wanted * 1.0, obj.YDir_wanted * 1.0, obj.ZDir_wanted * 1.0) # multiply vectors by 1.0 to copy them, to block mutation plm = App.Placement(old_pos, ori) obj.XDir_actual = ori.multVec(App.Vector(1, 0, 0)) obj.YDir_actual = ori.multVec(App.Vector(0, 1, 0)) obj.ZDir_actual = ori.multVec(App.Vector(0, 0, 1)) return [plm]
def derivedExecute(self, obj): #validity check if not lattice2BaseFeature.isObjectLattice(screen(obj.Base)): lattice2Executer.warning( obj, "A lattice object is expected as Base, but a generic shape was provided. It will be treated as a lattice object; results may be unexpected." ) toolShape = screen(obj.Tool).Shape if lattice2BaseFeature.isObjectLattice(screen(obj.Tool)): lattice2Executer.warning( obj, "A lattice object was provided as Tool. It will be converted into points; orientations will be ignored." ) leaves = LCE.AllLeaves(toolShape) points = [Part.Vertex(leaf.Placement.Base) for leaf in leaves] toolShape = Part.makeCompound(points) leaves = LCE.AllLeaves(screen(obj.Base).Shape) input = [leaf.Placement for leaf in leaves] output = [] #variable to receive the final list of placements #cache settings elev = float(obj.PosElevation) posIsKeep = obj.TranslateMode == 'keep' posIsProjected = obj.TranslateMode == 'projected' posIsMixed = obj.TranslateMode == 'mixed' mixF = float(obj.PosMixFraction) oriIsKeep = obj.OrientMode == 'keep' oriIsAlongGap = obj.OrientMode == 'along gap' oriIsTangentPlane = obj.OrientMode == 'tangent plane' oriIsAlongU = obj.OrientMode == 'along u' oriIsAlongV = obj.OrientMode == 'along v' isMultiSol = obj.Multisolution == 'use all' for plm in input: v = Part.Vertex(plm.Base) projection = v.distToShape(toolShape) (dist, gaps, infos) = projection for iSol in range(0, len(gaps)): (posKeep, posPrj) = gaps[iSol] (dummy, dummy, dummy, el_topo, el_index, el_params) = infos[iSol] # Fetch all possible parameters (some may not be required, depending on modes) normal = posKeep - posPrj if normal.Length < DistConfusion: normal = None tangU = None tangV = None if el_topo == 'Face': face = toolShape.Faces[el_index] if normal is None: normal = face.normalAt(*el_params) (tangU, tangV) = face.tangentAt(*el_params) elif el_topo == "Edge": edge = toolShape.Edges[el_index] tangU = edge.tangentAt(el_params) if normal is not None: normal.normalize() #mode logic - compute new placement if posIsKeep: pos = plm.Base elif posIsProjected: pos = posPrj elif posIsMixed: pos = posKeep * mixF + posPrj * (1 - mixF) else: raise ValueError("Positioning mode not implemented: " + obj.TranslateMode) if abs(elev) > DistConfusion: if normal is None: raise ValueError( "Normal vector not available for a placement resting on " + el_topo + ". Normal vector is required for nonzero position elevation." ) pos += normal * elev if oriIsKeep: ori = plm.Rotation elif oriIsAlongGap: if normal is None: raise ValueError( "Normal vector not available for a placement resting on " + el_topo + ". Normal vector is required for orientation mode '" + obj.OrientMode + "'") ori = Utils.makeOrientationFromLocalAxesUni("X", XAx=normal * (-1.0)) elif oriIsTangentPlane: if normal is None: raise ValueError( "Normal vector not available for a placement resting on " + el_topo + ". Normal vector is required for orientation mode '" + obj.OrientMode + "'") ori = Utils.makeOrientationFromLocalAxesUni("Z", ZAx=normal) elif oriIsAlongU: if normal is None: raise ValueError( "Normal vector not available for a placement resting on " + el_topo + ". Normal vector is required for orientation mode '" + obj.OrientMode + "'") if tangU is None: raise ValueError( "TangentU vector not available for point on " + el_topo + ". TangentU vector is required for orientation mode '" + obj.OrientMode + "'") ori = Utils.makeOrientationFromLocalAxesUni("ZX", ZAx=normal, XAx=tangU) elif oriIsAlongV: if normal is None: raise ValueError( "Normal vector not available for a placement resting on " + el_topo + ". Normal vector is required for orientation mode '" + obj.OrientMode + "'") if tangV is None: raise ValueError( "TangentV vector not available for point on " + el_topo + ". TangentV vector is required for orientation mode '" + obj.OrientMode + "'") ori = Utils.makeOrientationFromLocalAxesUni("ZX", ZAx=normal, XAx=tangV) else: raise ValueError("Orientation mode not implemented: " + obj.OrientMode) output.append(App.Placement(pos, ori)) if not isMultiSol: break return output
def derivedExecute(self,obj): #validity check if not lattice2BaseFeature.isObjectLattice(obj.Base): lattice2Executer.warning(obj,"A lattice object is expected as Base, but a generic shape was provided. It will be treated as a lattice object; results may be unexpected.") toolShape = obj.Tool.Shape if lattice2BaseFeature.isObjectLattice(obj.Tool): lattice2Executer.warning(obj,"A lattice object was provided as Tool. It will be converted into points; orientations will be ignored.") leaves = LCE.AllLeaves(toolShape) points = [Part.Vertex(leaf.Placement.Base) for leaf in leaves] toolShape = Part.makeCompound(points) leaves = LCE.AllLeaves(obj.Base.Shape) input = [leaf.Placement for leaf in leaves] output = [] #variable to receive the final list of placements #cache settings elev = float(obj.PosElevation) posIsKeep = obj.TranslateMode == 'keep' posIsProjected = obj.TranslateMode == 'projected' posIsMixed = obj.TranslateMode == 'mixed' mixF = float(obj.PosMixFraction) oriIsKeep = obj.OrientMode == 'keep' oriIsAlongGap = obj.OrientMode == 'along gap' oriIsTangentPlane = obj.OrientMode == 'tangent plane' oriIsAlongU = obj.OrientMode == 'along u' oriIsAlongV = obj.OrientMode == 'along v' isMultiSol = obj.Multisolution == 'use all' for plm in input: v = Part.Vertex(plm.Base) projection = v.distToShape(toolShape) (dist, gaps, infos) = projection for iSol in range(0,len(gaps)): (posKeep, posPrj) = gaps[iSol] (dummy, dummy, dummy, el_topo, el_index, el_params) = infos[iSol] # Fetch all possible parameters (some may not be required, depending on modes) normal = posKeep - posPrj if normal.Length < DistConfusion: normal = None tangU = None tangV = None if el_topo == 'Face': face = toolShape.Faces[el_index] if normal is None: normal = face.normalAt(*el_params) (tangU, tangV) = face.tangentAt(*el_params) elif el_topo == "Edge": edge = toolShape.Edges[el_index] tangU = edge.tangentAt(el_params) if normal is not None: normal.normalize() #mode logic - compute new placement if posIsKeep: pos = plm.Base elif posIsProjected: pos = posPrj elif posIsMixed: pos = posKeep*mixF + posPrj*(1-mixF) else: raise ValueError("Positioning mode not implemented: " + obj.TranslateMode ) if abs(elev) > DistConfusion: if normal is None: raise ValueError("Normal vector not available for a placement resting on " + el_topo +". Normal vector is required for nonzero position elevation.") pos += normal * elev if oriIsKeep: ori = plm.Rotation elif oriIsAlongGap: if normal is None: raise ValueError("Normal vector not available for a placement resting on " + el_topo +". Normal vector is required for orientation mode '"+obj.OrientMode+"'") ori = Utils.makeOrientationFromLocalAxesUni("X",XAx= normal*(-1.0)) elif oriIsTangentPlane: if normal is None: raise ValueError("Normal vector not available for a placement resting on " + el_topo +". Normal vector is required for orientation mode '"+obj.OrientMode+"'") ori = Utils.makeOrientationFromLocalAxesUni("Z",ZAx= normal) elif oriIsAlongU: if normal is None: raise ValueError("Normal vector not available for a placement resting on " + el_topo +". Normal vector is required for orientation mode '"+obj.OrientMode+"'") if tangU is None: raise ValueError("TangentU vector not available for point on " + el_topo +". TangentU vector is required for orientation mode '"+obj.OrientMode+"'") ori = Utils.makeOrientationFromLocalAxesUni("ZX",ZAx= normal, XAx= tangU) elif oriIsAlongV: if normal is None: raise ValueError("Normal vector not available for a placement resting on " + el_topo +". Normal vector is required for orientation mode '"+obj.OrientMode+"'") if tangV is None: raise ValueError("TangentV vector not available for point on " + el_topo +". TangentV vector is required for orientation mode '"+obj.OrientMode+"'") ori = Utils.makeOrientationFromLocalAxesUni("ZX",ZAx= normal, XAx= tangV) else: raise ValueError("Orientation mode not implemented: " + obj.OrientMode ) output.append(App.Placement(pos,ori)) if not isMultiSol: break return output