def nearestPort(self, point=None): ''' nearestPort (point=None) Returns the Port nearest to point or to the selected geometry. (<portNr>, <portPos>, <portDir>) ''' obj = FreeCAD.ActiveDocument.getObject(self.Name) if not point and FreeCADGui.ActiveDocument: try: selex = FreeCADGui.Selection.getSelectionEx() target = selex[0].Object so = selex[0].SubObjects[0] except: FreeCAD.Console.PrintError('No geometry selected\n') return None if type(so) == Part.Vertex: point = so.Point else: point = so.CenterOfMass if point: pos = pipeCmd.portsPos(obj)[0] Z = pipeCmd.portsDir(obj)[0] i = nearest = 0 if len(obj.Ports) > 1: for p in pipeCmd.portsPos(obj)[1:]: i += 1 if (p - point).Length < (pos - point).Length: pos = p Z = pipeCmd.portsDir(obj)[i] nearest = i return nearest, pos, Z
def execute(self, fp): tubes = fp.Tubes curves = fp.Curves edges = fp.Base.Shape.Edges from math import degrees from DraftVecUtils import rounded from frameCmd import bisect, beamAx, extendTheBeam, ortho i = 0 L = 0 portA, portB = [FreeCAD.Vector()] * 2 while i < len(curves) and i < len(edges): v1, v2 = [e.tangentAt(0) for e in edges[i:i + 2]] P = edges[i + 1].valueAt( 0) #frameCmd.intersectionCLines(*edges[i:i+2]) pipeCmd.placeTheElbow(curves[i], v1, v2, P) if not i: tubes[i].Placement.Base = edges[i].valueAt(0) else: tubes[i].Placement.Base = pipeCmd.portsPos(curves[i - 1])[1] tubes[i].Placement.Rotation = FreeCAD.Rotation( FreeCAD.Vector(0, 0, 1), edges[i].tangentAt(0)) L = min([(tubes[i].Placement.Base - port).Length for port in pipeCmd.portsPos(curves[i])]) tubes[i].Height = L #.Length i += 1 tubes[-1].Placement.Base = pipeCmd.portsPos(curves[-1])[1] tubes[-1].Placement.Rotation = FreeCAD.Rotation( FreeCAD.Vector(0, 0, 1), edges[-1].tangentAt(0)) L = tubes[-1].Placement.Base - edges[i].valueAt(edges[i].LastParameter) tubes[-1].Height = L.Length
def nearestPort (self,point=None): ''' nearestPort (point=None) Returns the Port nearest to point or to the selected geometry. (<portNr>, <portPos>, <portDir>) ''' obj=FreeCAD.ActiveDocument.getObject(self.Name) if not point and FreeCADGui.ActiveDocument: try: selex=FreeCADGui.Selection.getSelectionEx() target=selex[0].Object so=selex[0].SubObjects[0] except: FreeCAD.Console.PrintError('No geometry selected\n') return None if type(so)==Part.Vertex: point=so.Point else: point=so.CenterOfMass if point: pos=pipeCmd.portsPos(obj)[0]; Z=pipeCmd.portsDir(obj)[0] i=nearest=0 if len(obj.Ports)>1: for p in pipeCmd.portsPos(obj)[1:] : i+=1 if (p-point).Length<(pos-point).Length: pos=p Z=pipeCmd.portsDir(obj)[i] nearest=i return nearest, pos, Z
def Activated(self): import frameCmd, pipeCmd if len(frameCmd.beams()) > 1: p1, p2 = frameCmd.beams()[:2] try: P = frameCmd.intersectionCLines(p1, p2) com1 = p1.Shape.Solids[0].CenterOfMass com2 = p2.Shape.Solids[0].CenterOfMass v1 = P - com1 v2 = com2 - P curves = [ e for e in FreeCADGui.Selection.getSelection() if hasattr(e, 'PType') and hasattr(e, 'BendAngle') ] if curves: FreeCAD.ActiveDocument.openTransaction('Place one curve') pipeCmd.placeoTherElbow(curves[0], v1, v2, P) FreeCAD.ActiveDocument.recompute( ) # recompute for the elbow port1, port2 = pipeCmd.portsPos(curves[0]) if (com1 - port1).Length < (com1 - port2).Length: frameCmd.extendTheBeam(p1, port1) frameCmd.extendTheBeam(p2, port2) else: frameCmd.extendTheBeam(p1, port2) frameCmd.extendTheBeam(p2, port1) FreeCAD.ActiveDocument.recompute( ) # recompute for the pipes FreeCAD.ActiveDocument.commitTransaction() else: FreeCAD.Console.PrintError('Select at least one elbow') except: FreeCAD.Console.PrintError('Intersection point not found\n') else: FreeCAD.Console.PrintError('Select two intersecting pipes\n')
def Activated (self): import frameCmd, pipeCmd if len(frameCmd.beams())>1: p1,p2=frameCmd.beams()[:2] try: P=frameCmd.intersectionCLines(p1,p2) com1=p1.Shape.Solids[0].CenterOfMass com2=p2.Shape.Solids[0].CenterOfMass v1=P-com1 v2=com2-P curves=[e for e in FreeCADGui.Selection.getSelection() if hasattr(e,'PType') and hasattr(e,'BendAngle')] if curves: FreeCAD.ActiveDocument.openTransaction('Place one curve') pipeCmd.placeoTherElbow(curves[0],v1,v2,P) FreeCAD.ActiveDocument.recompute() # recompute for the elbow port1,port2=pipeCmd.portsPos(curves[0]) if (com1-port1).Length<(com1-port2).Length: frameCmd.extendTheBeam(p1,port1) frameCmd.extendTheBeam(p2,port2) else: frameCmd.extendTheBeam(p1,port2) frameCmd.extendTheBeam(p2,port1) FreeCAD.ActiveDocument.recompute() # recompute for the pipes FreeCAD.ActiveDocument.commitTransaction() else: FreeCAD.Console.PrintError('Select at least one elbow') except: FreeCAD.Console.PrintError('Intersection point not found\n') else: FreeCAD.Console.PrintError('Select two intersecting pipes\n')
def __init__(self, name, pype, portNr, scale=100): self.stop = False self.pype = pype self.portDir = pipeCmd.portsDir(pype)[portNr] self.portPos = pipeCmd.portsPos(pype)[portNr] rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), self.portDir.negative()) placement = FreeCAD.Placement(self.portPos, rot) super(arrow_insert, self).__init__(pl=placement, scale=[-scale, scale, scale / 5], offset=-scale, name=name)