def update(self,fp,edges=None): import pipeCmd, frameCmd from DraftVecUtils import rounded from math import degrees if not edges and hasattr(fp.Base,'Shape'): edges=fp.Base.Shape.Edges if not edges: FreeCAD.Console.PrintError('Base has not valid edges\n') return pipes=list() for e in edges: #---Create the tube--- p=pipeCmd.makePipe([fp.PSize,fp.OD,fp.thk,e.Length],pos=e.valueAt(0),Z=e.tangentAt(0)) p.PRating=fp.PRating p.PSize=fp.PSize pipeCmd.moveToPyLi(p,fp.Label) pipes.append(p) n=len(pipes)-1 if n and not frameCmd.isParallel(frameCmd.beamAx(pipes[n]),frameCmd.beamAx(pipes[n-1])): #---Create the curve--- propList=[fp.PSize,fp.OD,fp.thk,90,fp.BendRadius] c=pipeCmd.makeElbowBetweenThings(edges[n],edges[n-1],propList) if c: portA,portB=[c.Placement.multVec(port) for port in c.Ports] #---Trim the tube--- p1,p2=pipes[-2:] frameCmd.extendTheBeam(p1,portA) frameCmd.extendTheBeam(p2,portB) pipeCmd.moveToPyLi(c,fp.Label)
def update(self, fp, edges=None): import pipeCmd, frameCmd from DraftVecUtils import rounded from math import degrees if not edges and hasattr(fp.Base, 'Shape'): edges = fp.Base.Shape.Edges if not edges: FreeCAD.Console.PrintError('Base has not valid edges\n') return pipes = list() for e in edges: #---Create the tube--- p = pipeCmd.makePipe([fp.PSize, fp.OD, fp.thk, e.Length], pos=e.valueAt(0), Z=e.tangentAt(0)) p.PRating = fp.PRating p.PSize = fp.PSize pipeCmd.moveToPyLi(p, fp.Label) pipes.append(p) n = len(pipes) - 1 if n and not frameCmd.isParallel(frameCmd.beamAx(pipes[n]), frameCmd.beamAx(pipes[n - 1])): #---Create the curve--- propList = [fp.PSize, fp.OD, fp.thk, 90, fp.BendRadius] c = pipeCmd.makeElbowBetweenThings(edges[n], edges[n - 1], propList) portA, portB = [c.Placement.multVec(port) for port in c.Ports] #---Trim the tube--- p1, p2 = pipes[-2:] frameCmd.extendTheBeam(p1, portA) frameCmd.extendTheBeam(p2, portB) pipeCmd.moveToPyLi(c, fp.Label)
def update(self, fp, edges=None): import pipeCmd, frameCmd from DraftVecUtils import rounded from math import degrees if not edges and hasattr(fp.Base, 'Shape'): edges = fp.Base.Shape.Edges if not edges: FreeCAD.Console.PrintError('Base has not valid edges\n') return pipes = list() for e in edges: #---Create the tube--- p = pipeCmd.makePipe([fp.PSize, fp.OD, fp.thk, e.Length], pos=e.valueAt(0), Z=e.tangentAt(0)) p.PRating = fp.PRating p.PSize = fp.PSize pipeCmd.moveToPyLi(p, fp.Label) pipes.append(p) n = len(pipes) - 1 if n and not frameCmd.isParallel(frameCmd.beamAx(pipes[n]), frameCmd.beamAx(pipes[n - 1])): #---Create the curve: method 1--- #P=rounded(frameCmd.intersectionCLines(pipes[n-1],pipes[n])) #alternative -> P=pipes[n].Placement.Base #dir1=rounded((frameCmd.beamAx(pipes[n-1]).multiply(pipes[n-1].Height/2)+pipes[n-1].Placement.Base)-P).normalize() #dir2=rounded((frameCmd.beamAx(pipes[n]).multiply(pipes[n].Height/2)+pipes[n].Placement.Base)-P).normalize() #ang=180.0-degrees(dir1.getAngle(dir2)) #propList=[fp.PSize,fp.OD,fp.thk,ang,fp.BendRadius] #c=pipeCmd.makeElbow(propList,P,dir1.negative().cross(dir2.negative())) #elbBisect=rounded(frameCmd.beamAx(c,FreeCAD.Vector(1,1,0))).normalize() # if not rounded, it fails with linux when sketch is vertical!(?) #rot=FreeCAD.Rotation(elbBisect,frameCmd.bisect(dir1,dir2)) #c.Placement.Rotation=rot.multiply(c.Placement.Rotation) #---Create the curve: method 2--- propList = [fp.PSize, fp.OD, fp.thk, 90, fp.BendRadius] c = pipeCmd.makeElbowBetweenThings( edges[n], edges[n - 1], propList) #before was ...(p1,p2,propList) portA = c.Placement.multVec(c.Ports[0]) portB = c.Placement.multVec(c.Ports[1]) #---Trim the tube: method 1--- #for tube in pipes[-2:]: # vectA=c.Placement.Rotation.multVec(c.Ports[0]) # if frameCmd.isParallel(vectA,frameCmd.beamAx(tube)): # frameCmd.extendTheBeam(tube,portA) # else: # frameCmd.extendTheBeam(tube,portB) #---Trim the tube: method 2--- p1, p2 = pipes[-2:] frameCmd.extendTheBeam(p1, portA) frameCmd.extendTheBeam(p2, portB) pipeCmd.moveToPyLi(c, fp.Label)
def redraw(self,fp,OD=60.3,thk=3,BR=None): if not BR: BR=0.75*OD edges=copy(fp.Base.Shape.Edges) from pipeCmd import makePipe, makeElbowBetweenThings #---Create the tubes--- tubes=list() for e in edges: t=makePipe([fp.PSize,OD,thk,e.Length],pos=e.valueAt(0),Z=e.tangentAt(0)) t.PRating=fp.PRating t.PSize=fp.PSize tubes.append(t) fp.Tubes=tubes #---Create the curves--- curves=list() for t in range(len(edges)-1): c=makeElbowBetweenThings(edges[t],edges[t+1],[fp.PSize,OD,thk,90,BR]) c.PRating=fp.PRating c.PSize=fp.PSize curves.append(c) fp.Curves=curves
def insert(self): # insert the curve #self.lastElbow=None self.lastAngle=0 self.dial.setValue(0) DN=OD=thk=PRating=None d=self.pipeDictList[self.sizeList.currentRow()] try: if float(self.edit1.text())>180: self.edit1.setText("180") ang=float(self.edit1.text()) except: ang=float(pq(d['BendAngle'])) selex=FreeCADGui.Selection.getSelectionEx() if len(selex)==0: # no selection -> insert one elbow at origin propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),ang,float(pq(d['BendRadius']))] FreeCAD.activeDocument().openTransaction('Insert elbow in (0,0,0)') self.lastElbow=pipeCmd.makeElbow(propList) if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) FreeCAD.activeDocument().commitTransaction() elif len(selex)==1 and len(selex[0].SubObjects)==1: #one selection -> ... if hasattr(selex[0].Object,'PType') and selex[0].Object.PType in ['Pipe','Elbow','Cap','Reduct']: DN=selex[0].Object.PSize OD=float(selex[0].Object.OD) thk=float(selex[0].Object.thk) BR=None for prop in self.pipeDictList: if prop['PSize']==DN: BR=float(pq(prop['BendRadius'])) if BR==None: BR=1.5*OD/2 propList=[DN,OD,thk,ang,BR] else: propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),ang,float(pq(d['BendRadius']))] if selex[0].SubObjects[0].ShapeType=="Vertex": # ...on vertex FreeCAD.activeDocument().openTransaction('Insert elbow on vertex') self.lastElbow=pipeCmd.makeElbow(propList,selex[0].SubObjects[0].Point) if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) FreeCAD.activeDocument().commitTransaction() elif selex[0].SubObjects[0].ShapeType=="Edge" and selex[0].SubObjects[0].curvatureAt(0)!=0: # ...on center of curved edge P=selex[0].SubObjects[0].centerOfCurvatureAt(0) N=selex[0].SubObjects[0].normalAt(0).cross(selex[0].SubObjects[0].tangentAt(0)).normalize() FreeCAD.activeDocument().openTransaction('Insert elbow on curved edge') self.lastElbow=pipeCmd.makeElbow(propList,P) # ,Z) if pipeCmd.isPipe(selex[0].Object): ax=selex[0].Object.Shape.Solids[0].CenterOfMass-P rot=FreeCAD.Rotation(self.lastElbow.Ports[0],ax) self.lastElbow.Placement.Rotation=rot.multiply(self.lastElbow.Placement.Rotation) Port0=pipeCmd.getElbowPort(self.lastElbow) self.lastElbow.Placement.move(P-Port0) elif pipeCmd.isElbow(selex[0].Object): p0,p1=[selex[0].Object.Placement.Rotation.multVec(p) for p in selex[0].Object.Ports] if frameCmd.isParallel(p0,N): self.lastElbow.Placement.Rotation=FreeCAD.Rotation(self.lastElbow.Ports[0],p0*-1) else: self.lastElbow.Placement.Rotation=FreeCAD.Rotation(self.lastElbow.Ports[0],p1*-1) self.lastElbow.Placement.move(P-pipeCmd.getElbowPort(self.lastElbow)) else: rot=FreeCAD.Rotation(self.lastElbow.Ports[0],N) self.lastElbow.Placement.Rotation=rot.multiply(self.lastElbow.Placement.Rotation) self.lastElbow.Placement.move(self.lastElbow.Placement.Rotation.multVec(self.lastElbow.Ports[0])*-1) if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) FreeCAD.activeDocument().recompute() FreeCAD.activeDocument().commitTransaction() else: # multiple selection -> insert one elbow at intersection of two edges or beams or pipes ## # selection of axes things=[] for objEx in selex: # if the profile is not defined and the selection is one piping object, take its profile for elbow if OD==thk==None and hasattr(objEx.Object,'PType') and objEx.Object.PType in ['Pipe','Elbow','Cap','Reduct']: DN=objEx.Object.PSize OD=objEx.Object.OD thk=objEx.Object.thk PRating=objEx.Object.PRating # if the object is a beam or pipe, append it to the "things".. if len(frameCmd.beams([objEx.Object]))==1: things.append(objEx.Object) else: # ..else append its edges for edge in frameCmd.edges([objEx]): things.append(edge) if len(things)>=2: break FreeCAD.activeDocument().openTransaction('Insert elbow on intersection') try: #create the feature if None in [DN,OD,thk,PRating]: propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),ang,float(pq(d['BendRadius']))] self.lastElbow=pipeCmd.makeElbowBetweenThings(*things[:2],propList=propList) self.lastElbow.PRating=self.ratingList.item(self.ratingList.currentRow()).text() else: for prop in self.pipeDictList: if prop['PSize']==DN: BR=float(pq(prop['BendRadius'])) if BR==None: BR=1.5*OD/2 propList=[DN,OD,thk,ang,BR] self.lastElbow=pipeCmd.makeElbowBetweenThings(*things[:2],propList=propList) self.lastElbow.PRating=PRating if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) except: FreeCAD.Console.PrintError('Creation of elbow is failed\n') FreeCAD.activeDocument().commitTransaction() #### FreeCAD.activeDocument().recompute()