Example #1
0
 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)
Example #2
0
 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)
Example #3
0
def makeElbowBetweenThings(thing1=None, thing2=None, propList=None):
    '''
  makeElbowBetweenThings(thing1, thing2, propList=None):
  Place one elbow at the intersection of thing1 and thing2.
  Things can be any combination of intersecting beams, pipes or edges.
  If nothing is passed as argument, the function attempts to take the
  first two edges selected in the view.
  propList is one optional list with 5 elements:
    DN (string): nominal diameter
    OD (float): outside diameter
    thk (float): shell thickness
    BA (float): bend angle - that will be recalculated! -
    BR (float): bend radius
  Default is "DN50 (SCH-STD)"
  Remember: property PRating must be defined afterwards
  '''
    if not (thing1 and thing2):
        thing1, thing2 = frameCmd.edges()[:2]
    P = frameCmd.intersectionCLines(thing1, thing2)
    directions = list()
    try:
        for thing in [thing1, thing2]:
            if frameCmd.beams([thing]):
                directions.append(
                    rounded(
                        (frameCmd.beamAx(thing).multiply(thing.Height / 2) +
                         thing.Placement.Base) - P))
            elif hasattr(thing, 'ShapeType') and thing.ShapeType == 'Edge':
                directions.append(rounded(thing.CenterOfMass - P))
    except:
        return None
    ang = 180 - degrees(directions[0].getAngle(directions[1]))
    if ang == 0 or ang == 180: return None
    if not propList:
        propList = ["DN50", 60.3, 3.91, ang, 45.24]
    else:
        propList[3] = ang
    elb = makeElbow(propList, P,
                    directions[0].negative().cross(directions[1].negative()))
    # mate the elbow ends with the pipes or edges
    b = frameCmd.bisect(directions[0], directions[1])
    elbBisect = rounded(frameCmd.beamAx(elb, FreeCAD.Vector(
        1, 1, 0)))  #if not rounded, fail in plane xz
    rot = FreeCAD.Rotation(elbBisect, b)
    elb.Placement.Rotation = rot.multiply(elb.Placement.Rotation)
    # trim the adjacent tubes
    #FreeCAD.activeDocument().recompute() # may delete this row?
    portA = elb.Placement.multVec(elb.Ports[0])
    portB = elb.Placement.multVec(elb.Ports[1])
    for tube in [t for t in [thing1, thing2] if frameCmd.beams([t])]:
        vectA = tube.Shape.Solids[0].CenterOfMass - portA
        vectB = tube.Shape.Solids[0].CenterOfMass - portB
        if frameCmd.isParallel(vectA, frameCmd.beamAx(tube)):
            frameCmd.extendTheBeam(tube, portA)
        else:
            frameCmd.extendTheBeam(tube, portB)
    return elb
Example #4
0
 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)
Example #5
0
 def insert(self):      # insert the pipe
   self.lastPipe=None
   d=self.pipeDictList[self.sizeList.currentRow()]
   FreeCAD.activeDocument().openTransaction('Insert pipe')
   if self.edit1.text():
     self.H=float(self.edit1.text())
   self.sli.setValue(100)
   if len(frameCmd.edges())==0: #..no edges selected
     propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),self.H]
     vs=[v for sx in FreeCADGui.Selection.getSelectionEx() for so in sx.SubObjects for v in so.Vertexes]
     if len(vs)==0: # ...no vertexes selected
       self.lastPipe=pipeCmd.makePipe(propList)
       if self.combo.currentText()!='<none>':
         pipeCmd.moveToPyLi(self.lastPipe,self.combo.currentText())
     else:
       for v in vs: # ... one or more vertexes
         self.lastPipe=pipeCmd.makePipe(propList,v.Point)
       if self.combo.currentText()!='<none>':
         pipeCmd.moveToPyLi(self.lastPipe,self.combo.currentText())
   else:
     selex=FreeCADGui.Selection.getSelectionEx()
     for objex in selex:
       o=objex.Object # SELECT PROPERTIES ACCORDING OBJECT
       if hasattr(o,'PSize') and hasattr(o,'OD') and hasattr(o,'thk'):
         propList=[o.PSize,o.OD,o.thk,self.H]
       else:
         propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),self.H]
       for edge in frameCmd.edges([objex]): # ...one or more edges...
         if edge.curvatureAt(0)==0: # ...straight edges
           pL=propList
           pL[3]=edge.Length
           self.lastPipe=pipeCmd.makePipe(pL,edge.valueAt(0),edge.tangentAt(0))
         else: # ...curved edges
           pos=edge.centerOfCurvatureAt(0)
           Z=edge.tangentAt(0).cross(edge.normalAt(0))
           if pipeCmd.isElbow(o):
             p0,p1=[o.Placement.Rotation.multVec(p) for p in o.Ports]
             if not frameCmd.isParallel(Z,p0):
               Z=p1
           self.lastPipe=pipeCmd.makePipe(propList,pos,Z)
         if self.combo.currentText()!='<none>':
           pipeCmd.moveToPyLi(self.lastPipe,self.combo.currentText())
   self.H=float(self.lastPipe.Height)
   self.edit1.setText(str(float(self.H)))
   FreeCAD.activeDocument().commitTransaction()
   FreeCAD.activeDocument().recompute()
Example #6
0
def setWP():
    'function to change working plane'
    import FreeCAD, FreeCADGui, frameCmd
    normal = point = None
    curves = []
    straight = []
    Z = FreeCAD.Vector(0, 0, 1)
    for edge in frameCmd.edges():
        if edge.curvatureAt(0) != 0:
            curves.append(edge)
        else:
            straight.append(edge)
    # define normal: 1st from face->2nd from curve->3rd from straight edges
    if frameCmd.faces():
        normal = frameCmd.faces()[0].normalAt(0, 0)
    elif curves:
        normal = curves[0].tangentAt(0).cross(curves[0].normalAt(0))
    elif len(straight) > 1:
        if straight and not frameCmd.isParallel(straight[0].tangentAt(0),
                                                straight[1].tangentAt(0)):
            normal = straight[0].tangentAt(0).cross(straight[1].tangentAt(0))
    elif FreeCADGui.Selection.getSelection():
        normal = FreeCAD.DraftWorkingPlane.getRotation().multVec(Z)
    else:
        normal = Z
    # define point: 1st from vertex->2nd from centerOfCurvature->3rd from intersection->4th from center of edge
    points = [
        v.Point for sx in FreeCADGui.Selection.getSelectionEx()
        for v in sx.SubObjects if v.ShapeType == 'Vertex'
    ]
    if not points:
        points = [edge.centerOfCurvatureAt(0) for edge in curves]
    if not points and len(straight) > 1:
        inters = frameCmd.intersectionCLines(straight[0], straight[1])
        if inters:
            points.append(inters)
    if not points and len(straight):
        points.append(straight[0].CenterOfMass)
    if points:
        point = points[0]
    else:
        point = FreeCAD.Vector()
    # move the draft WP
    FreeCAD.DraftWorkingPlane.alignToPointAndAxis(point, normal)
    FreeCADGui.Snapper.setGrid()
Example #7
0
def setWP():
  'function to change working plane'
  import FreeCAD, FreeCADGui, frameCmd
  normal=point=None
  curves=[]
  straight=[]
  Z=FreeCAD.Vector(0,0,1)
  for edge in frameCmd.edges():
    if edge.curvatureAt(0)!=0:
      curves.append(edge)
    else:
      straight.append(edge)
  # define normal: 1st from face->2nd from curve->3rd from straight edges
  if frameCmd.faces():
    normal=frameCmd.faces()[0].normalAt(0,0)
  elif curves:
    normal=curves[0].tangentAt(0).cross(curves[0].normalAt(0))
  elif len(straight)>1:
    if straight and not frameCmd.isParallel(straight[0].tangentAt(0),straight[1].tangentAt(0)):
      normal=straight[0].tangentAt(0).cross(straight[1].tangentAt(0))
  elif FreeCADGui.Selection.getSelection():
    normal=FreeCAD.DraftWorkingPlane.getRotation().multVec(Z)
  else:
    normal=Z
  # define point: 1st from vertex->2nd from centerOfCurvature->3rd from intersection->4th from center of edge
  points=[v.Point for sx in FreeCADGui.Selection.getSelectionEx() for v in sx.SubObjects if v.ShapeType=='Vertex']
  if not points:
    points=[edge.centerOfCurvatureAt(0) for edge in curves]
  if not points and len(straight)>1:
    inters=frameCmd.intersectionCLines(straight[0],straight[1])
    if inters:
      points.append(inters)
  if not points and len(straight):
    points.append(straight[0].CenterOfMass)
  if points:
    point=points[0]
  else:
    point=FreeCAD.Vector()
  # move the draft WP
  FreeCAD.DraftWorkingPlane.alignToPointAndAxis(point,normal)
  FreeCADGui.Snapper.setGrid()
Example #8
0
 def insert(self):
   r=self.pipeDictList[self.sizeList.currentRow()]
   pos=Z=H=None
   selex=FreeCADGui.Selection.getSelectionEx()
   pipes=[p.Object for p in selex if hasattr(p.Object,'PType') and p.Object.PType=='Pipe']
   if len(pipes)>1 and frameCmd.isParallel(frameCmd.beamAx(pipes[0]),frameCmd.beamAx(pipes[1])):  # if at least 2 pipes are selected...
     if pipes[0].OD>=pipes[1].OD:
       p1,p2=pipes[:2]
     else:
       p2,p1=pipes[:2]
     DN=p1.PSize
     OD1=float(p1.OD)
     OD2=float(p2.OD)
     thk1=float(p1.thk)
     thk2=float(p2.thk)
     H=float(pq(self.findDN(DN)['H']))
     Z=p2.Shape.Solids[0].CenterOfMass-p1.Shape.Solids[0].CenterOfMass
     Z.normalize()
     pos=p1.Shape.Solids[0].CenterOfMass+Z*float(p1.Height/2)
   elif len(pipes)>0:            # if 1 pipe is selected...
     DN=pipes[0].PSize
     OD1=float(pipes[0].OD)
     OD2=float(pq(self.OD2list.currentItem().text()))
     thk1=float(pipes[0].thk)
     thk2=float(pq(r['thk2'].split('>')[self.OD2list.currentRow()]))
     H=float(pq(self.findDN(DN)['H']))
     curves=[e for e in frameCmd.edges() if e.curvatureAt(0)>0]
     if len(curves): #...and 1 curve is selected...
       pos=curves[0].centerOfCurvatureAt(0)
     else: #...or no curve is selected...
       pos=pipes[0].Placement.Base
     Z= pos-pipes[0].Shape.Solids[0].CenterOfMass
   else:                         # if no pipe is selected...
     DN=r['PSize']
     OD1=float(pq(r['OD']))
     OD2=float(pq(self.OD2list.currentItem().text()))
     thk1=float(pq(r['thk']))
     try:
       thk2=float(pq(r['thk2'].split('>')[self.OD2list.currentRow()]))
     except:
       thk2=thk1
     H=pq(r['H'])
     if frameCmd.edges():    #...but 1 curve is selected...
       edge=frameCmd.edges()[0]
       if edge.curvatureAt(0)>0:
         pos=edge.centerOfCurvatureAt(0)
         Z=edge.tangentAt(0).cross(edge.normalAt(0))
       else:
         pos=edge.valueAt(0)
         Z=edge.tangentAt(0)
     elif selex and selex[0].SubObjects[0].ShapeType=="Vertex": #...or 1 vertex..
       pos=selex[0].SubObjects[0].Point
   if not H: # calculate length if it's not defined
     H=float(3*(OD1-OD2))
   propList=[DN,OD1,OD2,thk1,thk2,H]
   FreeCAD.activeDocument().openTransaction('Insert reduction')
   if self.cb1.isChecked():
     self.lastReduct=pipeCmd.makeReduct(propList,pos,Z,False)
   else:
     self.lastReduct=pipeCmd.makeReduct(propList,pos,Z)
   FreeCAD.activeDocument().commitTransaction()
   FreeCAD.activeDocument().recompute()
   if self.combo.currentText()!='<none>':
     pipeCmd.moveToPyLi(self.lastReduct,self.combo.currentText())
Example #9
0
 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()