Exemple #1
0
 def accept(self):            # extend
   if self.target!=None and len(fCmd.beams())>0:
     FreeCAD.activeDocument().openTransaction('Extend beam')
     for beam in fCmd.beams():
       fCmd.extendTheBeam(beam,self.target)
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
Exemple #2
0
def flatten(p1=None, p2=None, c=None):
  if not (p1 and p2) and len(fCmd.beams())>1:
    p1,p2=fCmd.beams()[:2]
  else: FreeCAD.Console.PrintError('Select two intersecting pipes\n')
  if not c:
    curves=[e for e in FreeCADGui.Selection.getSelection() if hasattr(e,'PType') and hasattr(e,'BendAngle')]
    if curves: c=curves[0]
  else: FreeCAD.Console.PrintError('Select at least one elbow')
  try:
    P=fCmd.intersectionCLines(p1,p2)
    com1=p1.Shape.Solids[0].CenterOfMass
    com2=p2.Shape.Solids[0].CenterOfMass
    v1=P-com1
    v2=com2-P
    FreeCAD.ActiveDocument.openTransaction('Place one curve')
    placeoTherElbow(curves[0],v1,v2,P)
    FreeCAD.ActiveDocument.recompute() # recompute for the elbow
    port1,port2=portsPos(curves[0])
    if (com1-port1).Length<(com1-port2).Length:
      fCmd.extendTheBeam(p1,port1)
      fCmd.extendTheBeam(p2,port2)
    else:
      fCmd.extendTheBeam(p1,port2)
      fCmd.extendTheBeam(p2,port1)
    FreeCAD.ActiveDocument.recompute() # recompute for the pipes
    FreeCAD.ActiveDocument.commitTransaction()
  except:
    FreeCAD.Console.PrintError('Intersection point not found\n')
Exemple #3
0
 def getProfile(self):
   if self.current:
     if fCmd.beams():
       self.current.Profile=fCmd.beams()[0].Base
     elif self.sectList.selectedItems():
       prof= FreeCAD.ActiveDocument.getObjectsByLabel(self.sectList.selectedItems()[0].text())[0]
       if prof.Shape.ShapeType=='Wire' and self.cb2.isChecked():
         prof.Placement.move(FreeCAD.Vector(0,0,0)-prof.Shape.CenterOfMass)
       prof.Placement.Rotation=FreeCAD.Base.Rotation()
       self.current.Profile=prof
Exemple #4
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=fCmd.edges()[:2]
  P=fCmd.intersectionCLines(thing1,thing2)
  directions=list()
  try:
    for thing in [thing1,thing2]:
      if fCmd.beams([thing]):
        directions.append(rounded((fCmd.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=fCmd.bisect(directions[0],directions[1])
  elbBisect=rounded(fCmd.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 fCmd.beams([t])]:
    vectA=tube.Shape.Solids[0].CenterOfMass-portA
    vectB=tube.Shape.Solids[0].CenterOfMass-portB
    if fCmd.isParallel(vectA,fCmd.beamAx(tube)):
      fCmd.extendTheBeam(tube,portA)
    else:
      fCmd.extendTheBeam(tube,portB)
  return elb
Exemple #5
0
 def selectAction(self):
     if self.labTail:
         self.labTail.removeLabel()
         self.labTail = None
     self.L = fCmd.getDistance()
     if self.L:
         self.form.edit1.setText("%.3f" % self.L)
     elif fCmd.beams():
         beam = fCmd.beams()[0]
         self.L = float(beam.Height)
         self.form.edit1.setText("%.3f" % self.L)
     else:
         self.form.edit1.setText('')
     self.form.slider.setValue(0)
Exemple #6
0
 def stretchTail(self):
   beams=fCmd.beams()
   if beams:
     L=float(beams[0].Height)/2
     ext=L*(self.form.sliTail.value()/100.0)
     self.form.editTail.setText("%.3f" %ext)
     self.changeTailOffset()
Exemple #7
0
 def stretchHead(self):
   beams=fCmd.beams()
   if beams:
     L=float(beams[0].Height)/2
     ext=L*(self.form.sliHead.value()/100.0)
     self.form.editHead.setText("%.3f" %ext)
     self.changeHeadOffset()
Exemple #8
0
 def trim(self):
   FreeCAD.ActiveDocument.openTransaction('Trim FB')
   for target in self.targets:
     for b in fCmd.beams():
       if hasattr(b,'tailOffset') and hasattr(b,'headOffset'):
         edge=b.Support[0][0].Shape.getElement(b.Support[0][1][0])
         ax=edge.tangentAt(0).normalize() #fCmd.beamAx(b).normalize()
         tail=edge.valueAt(0) #b.Placement.Base
         head=edge.valueAt(edge.LastParameter) #tail+ax*float(b.Height)
         if target.ShapeType=="Vertex":
           P=target.Point
         elif target.ShapeType=="Face" and not fCmd.isOrtho(target,ax):
           P=fCmd.intersectionPlane(tail,ax,target)
         elif hasattr(target,"CenterOfMass"):
           P=target.CenterOfMass
         else: 
           P=None
         if P:
           deltaTail=(P-tail).dot(ax)
           deltaHead=(P-head).dot(ax)
           if abs(deltaTail)<abs(deltaHead):
             b.tailOffset=-deltaTail
           else:
             b.headOffset=deltaHead
   refresh()
   FreeCAD.ActiveDocument.commitTransaction()
Exemple #9
0
 def changeTailOffset(self):
   for beam in fCmd.beams():
     if hasattr(beam,'tailOffset'): 
       beam.tailOffset=float(self.form.editTail.text())
       FB=findFB(beam.Name)
       FB.touch()
   FreeCAD.ActiveDocument.recompute()
   FreeCAD.ActiveDocument.recompute()
Exemple #10
0
 def changeAngle(self):
   for beam in fCmd.beams():
     if hasattr(beam,'spin'): 
       FB=findFB(beam.Name)
       beam.spin=float(self.form.editAngle.text())
       FB.touch()
   FreeCAD.ActiveDocument.recompute()
   FreeCAD.ActiveDocument.recompute()
Exemple #11
0
 def Activated(self):
   import FreeCAD, fCmd
   if len(fCmd.beams())>1:
     FreeCAD.activeDocument().openTransaction('rotJoin')
     fCmd.rotjoinTheBeam()
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
   else:
     FreeCAD.Console.PrintError('Please select two edges of beams before\n')
Exemple #12
0
 def purge(self,fp):
   group=FreeCAD.activeDocument().getObjectsByLabel(fp.Group)[0]
   beams2purge=fCmd.beams(group.OutList)
   if beams2purge:
     for b in beams2purge:
       profiles=b.OutList
       FreeCAD.ActiveDocument.removeObject(b.Name)
       for p in profiles:
         FreeCAD.ActiveDocument.removeObject(p.Name)
Exemple #13
0
 def Activated(self):
     import pCmd, fCmd
     from Part import Plane
     refFace = [f for f in fCmd.faces() if type(f.Surface) == Plane][0]
     FreeCAD.activeDocument().openTransaction('Lay-down the pipe')
     for b in fCmd.beams():
         if pCmd.isPipe(b):
             pCmd.laydownTheTube(b, refFace)
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
Exemple #14
0
 def onPushButton1(self):
   from math import pi, degrees
   import fCmd
   try:
     obj=self.Selection.getSelection()[0]
     self.labName.setText(obj.Label)
     self.labBaseVal.setText(str("P = %.1f,%.1f,%.1f"%tuple(obj.Placement.Base)))
     self.labRotAng.setText(str("%.2f " %(degrees(obj.Placement.Rotation.Angle))))
     ax=obj.Placement.Rotation.Axis
     self.labRotAx.setText(str("v = (%(x).2f,%(y).2f,%(z).2f)" %{'x':ax.x,'y':ax.y,'z':ax.z}))
     shapes=[y for x in self.Selection.getSelectionEx() for y in x.SubObjects if hasattr(y,'ShapeType')]
     if len(shapes)==1:
       sub=shapes[0]
       if sub.ShapeType=='Edge':
         if sub.curvatureAt(0)==0:
           self.labSubObj.setText(sub.ShapeType+':\tL = %.1f mm' %sub.Length)
         else:
           x,y,z=sub.centerOfCurvatureAt(0)
           d=2/sub.curvatureAt(0)
           self.labSubObj.setText(sub.ShapeType+':\tD = %.1f mm\n\tC = %.1f,%.1f,%.1f' %(d,x,y,z))
       elif sub.ShapeType=='Face':
         self.labSubObj.setText(sub.ShapeType+':\tA = %.1f mm2' %sub.Area)
       elif sub.ShapeType=='Vertex':
         self.labSubObj.setText(sub.ShapeType+': pos = (%(x).1f,%(y).1f,%(z).1f)' %{'x':sub.X,'y':sub.Y,'z':sub.Z})
     elif len(shapes)>1:
       self.labSubObj.setText(shapes[0].ShapeType+' to '+shapes[1].ShapeType+': distance = %.1f mm' %(shapes[0].distToShape(shapes[1])[0]))
     else:
       self.labSubObj.setText(' ')
     if len(fCmd.beams())==1:
       b=fCmd.beams()[0]
       self.labBeam.setText(b.Label+":\tL=%.2f"%(b.Height))
       self.labProfile.setText("Profile: "+b.Profile)
     elif len(fCmd.beams())>1:
       b1,b2=fCmd.beams()[:2]
       self.labBeam.setText(b1.Label+"^"+b2.Label+": %.2f"%(degrees(fCmd.beamAx(b1).getAngle(fCmd.beamAx(b2)))))
       self.labProfile.setText("")
     else:
       self.labBeam.setText("")
       self.labProfile.setText("")
   except:
     pass
Exemple #15
0
def extendTheTubes2intersection(pipe1=None,pipe2=None,both=True):
  '''
  Does what it says; also with beams.
  If arguments are None, it picks the first 2 selected beams().
  '''
  if not (pipe1 and pipe2):
    try:
      pipe1,pipe2=fCmd.beams()[:2]
    except:
      FreeCAD.Console.PrintError('Insufficient arguments for extendTheTubes2intersection\n')
  P=fCmd.intersectionCLines(pipe1,pipe2)
  if P!=None:
    fCmd.extendTheBeam(pipe1,P)
    if both:
      fCmd.extendTheBeam(pipe2,P)
Exemple #16
0
 def Activated(self):
     import pCmd, fCmd
     from Part import Plane
     selex = FreeCADGui.Selection.getSelectionEx()
     for sx in selex:
         sxFaces = [f for f in fCmd.faces([sx]) if type(f.Surface) == Plane]
         if len(sxFaces) > 0:
             refFace = sxFaces[0]
             support = sx.Object
     FreeCAD.activeDocument().openTransaction('Raise-up the support')
     for b in fCmd.beams():
         if pCmd.isPipe(b):
             pCmd.laydownTheTube(b, refFace, support)
             break
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
Exemple #17
0
def doFlanges(propList=["DN50", "SO", 160, 60.3, 132, 14, 15, 4, 0, 0, 0, 0, 0], pypeline=None):
  '''
    propList = [
      DN (string): nominal diameter
      FlangeType (string): type of Flange
      D (float): flange diameter
      d (float): bore diameter
      df (float): bolts holes distance
      f (float): bolts holes diameter
      t (float): flange thickness
      n (int): nr. of bolts
      trf (float): raised-face thikness - OPTIONAL -
      drf (float): raised-face diameter - OPTIONAL -
      twn (float): welding-neck thikness - OPTIONAL -
      dwn (float): welding-neck diameter - OPTIONAL -
      ODp (float): outside diameter of pipe for wn flanges - OPTIONAL -
    pypeline = string
  '''
  flist=[]
  tubes=[t for t in fCmd.beams() if hasattr(t,'PSize')]
  FreeCAD.activeDocument().openTransaction('Insert flange')
  if len(fCmd.edges())==0:
    vs=[v for sx in FreeCADGui.Selection.getSelectionEx() for so in sx.SubObjects for v in so.Vertexes]
    if len(vs)==0:
      flist.append(makeFlange(propList))
    else:
      for v in vs:
        flist.append(makeFlange(propList,v.Point))
  elif tubes:
    selex=FreeCADGui.Selection.getSelectionEx()
    for sx in selex:
      if isPipe(sx.Object) and fCmd.edges([sx]):
        for edge in fCmd.edges([sx]):
          if edge.curvatureAt(0)!=0:
            flist.append(makeFlange(propList,edge.centerOfCurvatureAt(0),sx.Object.Shape.Solids[0].CenterOfMass-edge.centerOfCurvatureAt(0)))
  else:
    for edge in fCmd.edges():
      if edge.curvatureAt(0)!=0:
        flist.append(makeFlange(propList,edge.centerOfCurvatureAt(0),edge.tangentAt(0).cross(edge.normalAt(0))))
  if pypeline:
    for f in flist:
      moveToPyLi(f,pypeline)
  FreeCAD.activeDocument().commitTransaction()
  FreeCAD.activeDocument().recompute()
  return flist
Exemple #18
0
 def accept(self):
   if self.labTail:
     self.labTail.removeLabel()
     self.labTail=None
   self.L=fCmd.getDistance()
   if self.form.edit1.text():
     length=float(self.form.edit1.text())
     FreeCAD.activeDocument().openTransaction('Stretch beam')
     for beam in fCmd.beams():
       delta=float(beam.Height)-length
       fCmd.stretchTheBeam(beam,length)
       if self.form.tail.isChecked():
         disp=fCmd.beamAx(beam).multiply(delta)
         beam.Placement.move(disp)
       elif self.form.both.isChecked():
         disp=fCmd.beamAx(beam).multiply(delta/2.0)
         beam.Placement.move(disp)
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
Exemple #19
0
def breakTheTubes(point,pipes=[],gap=0):
  '''
  breakTheTube(point,pipes=[],gap=0)
  Breaks the "pipes" at "point" leaving a "gap".
  '''
  pipes2nd=list()
  if not pipes:
    pipes=[p for p in fCmd.beams() if isPipe(p)]
  if pipes:
    for pipe in pipes:
      if point<float(pipe.Height) and gap<(float(pipe.Height)-point):
        propList=[pipe.PSize,float(pipe.OD),float(pipe.thk),float(pipe.Height)-point-gap]
        pipe.Height=point
        Z=fCmd.beamAx(pipe)
        pos=pipe.Placement.Base+Z*(float(pipe.Height)+gap)
        pipe2nd=makePipe(propList,pos,Z)
        pipes2nd.append(pipe2nd)
    #FreeCAD.activeDocument().recompute()
  return pipes2nd
Exemple #20
0
def reverseTheTube(objEx):
  '''
  reverseTheTube(objEx)
  Reverse the orientation of objEx spinning it 180 degrees around the x-axis
  of its shape.
  If an edge is selected, it's used as pivot.
  '''
  disp=None
  selectedEdges=[e for e in objEx.SubObjects if e.ShapeType=='Edge']
  if selectedEdges:
    for edge in fCmd.edges([objEx]):
      if edge.curvatureAt(0):
        disp=edge.centerOfCurvatureAt(0)-objEx.Object.Placement.Base
        break
      elif fCmd.beams([objEx.Object]):
        ax=fCmd.beamAx(objEx.Object)
        disp=ax*((edge.CenterOfMass-objEx.Object.Placement.Base).dot(ax))
  rotateTheTubeAx(objEx.Object,FreeCAD.Vector(1,0,0),180)
  if disp:
    objEx.Object.Placement.move(disp*2)
Exemple #21
0
def laydownTheTube(pipe=None, refFace=None, support=None):
  '''
  laydownTheTube(pipe=None, refFace=None, support=None)
  Makes one pipe touch one face if the center-line is parallel to it.
  If support is not None, support is moved towards pipe.
  '''
  if not(pipe and refFace):  # without argument take from selection set
    refFace=[f for f in fCmd.faces() if type(f.Surface)==Part.Plane][0]
    pipe=[p for p in fCmd.beams() if hasattr(p,'OD')] [0]
  try:
    if type(refFace.Surface)==Part.Plane and fCmd.isOrtho(refFace,fCmd.beamAx(pipe)) and hasattr(pipe,'OD'):
      dist=rounded(refFace.normalAt(0,0).multiply(refFace.normalAt(0,0).dot(pipe.Placement.Base-refFace.CenterOfMass)-float(pipe.OD)/2))
      if support:
        support.Placement.move(dist)
      else:
        pipe.Placement.move(dist.multiply(-1))
    else:
      FreeCAD.Console.PrintError('Face is not flat or not parallel to axis of pipe\n')
  except:
    FreeCAD.Console.PrintError('Wrong selection\n')
Exemple #22
0
 def changeProfile(self):
   # find selected FB
   try:
     FB=findFB(baseName=FreeCADGui.Selection.getSelection()[0].Name)
     if not FB:
       FB=findFB(beamName=fCmd.beams()[0].Name)
   except:
     FreeCAD.Console.PrintError('Nothing selected\n')
     return
   if FB and self.form.listSizes.selectedItems():
     if self.SType=='<by sketch>':
       profile=FreeCAD.ActiveDocument.getObjectsByLabel(self.form.listSizes.currentItem().text())[0]
     else:
       prop=self.sectDictList[self.form.listSizes.currentRow()]
       profile=newProfile(prop)
     name=FB.Profile.Name
     FB.Profile=profile
     FB.Proxy.redraw(FB)
     FreeCAD.ActiveDocument.removeObject(name)
     FreeCAD.ActiveDocument.recompute()
     FreeCAD.ActiveDocument.recompute()
   else:
     FreeCAD.Console.PrintError('No frameBranch or profile selected\n')
Exemple #23
0
 def removeBeams(self):
   for beam in fCmd.beams():
     FB=findFB(beamName=beam.Name)
     if FB:
       i=FB.Beams.index(beam.Name)
       FB.Proxy.remove(i)
Exemple #24
0
def doElbow(propList=['DN50',60.3,3,90,45.225], pypeline=None):
  '''
    propList = [
      DN (string): nominal diameter
      OD (float): outside diameter
      thk (float): shell thickness
      BA (float): bend angle
      BR (float): bend radius ]
    pypeline = string
  '''
  elist=[]
  FreeCAD.activeDocument().openTransaction('Insert elbow')
  selex=FreeCADGui.Selection.getSelectionEx()
  if len(selex)==0:     # no selection -> insert one elbow at origin
    elist.append(makeElbow(propList))
  elif len(selex)==1 and len(selex[0].SubObjects)==1:  #one selection -> ...
    if selex[0].SubObjects[0].ShapeType=="Vertex":   # ...on vertex
      elist.append(makeElbow(propList,selex[0].SubObjects[0].Point))
    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()
      elb=makeElbow(propList,P)
      if isPipe(selex[0].Object): #..on the edge of a pipe
        ax=selex[0].Object.Shape.Solids[0].CenterOfMass-P
        rot=FreeCAD.Rotation(elb.Ports[0],ax)
        elb.Placement.Rotation=rot.multiply(elb.Placement.Rotation)
        Port0=getElbowPort(elb)
        elb.Placement.move(P-Port0)
      elif isElbow(selex[0].Object): #..on the edge of an elbow
        p0,p1=[selex[0].Object.Placement.Rotation.multVec(p) for p in selex[0].Object.Ports]
        if fCmd.isParallel(p0,N):
          elb.Placement.Rotation=FreeCAD.Rotation(elb.Ports[0],p0*-1)
        else:
          elb.Placement.Rotation=FreeCAD.Rotation(elb.Ports[0],p1*-1)
        delta=getElbowPort(elb)
        elb.Placement.move(P-delta)
      else: #..on any other curved edge
        print('hello')
        rot=FreeCAD.Rotation(elb.Ports[0],N)
        elb.Placement.Rotation=rot.multiply(elb.Placement.Rotation)
        # elb.Placement.move(elb.Placement.Rotation.multVec(elb.Ports[0])*-1)
        v=portsDir(elb)[0].negative()*elb.Ports[0].Length
        elb.Placement.move(v)
      elist.append(elb)
      FreeCAD.activeDocument().recompute()
  else:       # multiple selection -> insert one elbow at intersection of two edges or beams or pipes ##
    things=[]
    for objEx in selex:
      if len(fCmd.beams([objEx.Object]))==1:  # if the object is a beam or pipe, append it to the "things"..
        things.append(objEx.Object)
      else:                                   # ..else append its edges
        for edge in fCmd.edges([objEx]):
          things.append(edge)
      if len(things)>=2:
        break
    try:                                      #create the feature
      elb=elist.append(makeElbowBetweenThings(*things[:2],propList=propList))
    except:
      FreeCAD.Console.PrintError('Creation of elbow is failed\n')
  if pypeline:
    for e in elist:
      moveToPyLi(e,pypeline)
  FreeCAD.activeDocument().commitTransaction()
  FreeCAD.activeDocument().recompute()
  return elist
Exemple #25
0
 def selectAction(self):
   if len(fCmd.beams())>0:
     self.beam=fCmd.beams()[0]
     self.form.label.setText(self.beam.Label+':'+self.beam.Profile)
     FreeCADGui.Selection.removeSelection(self.beam)
Exemple #26
0
 def writeTail(self):
   if fCmd.beams():
     beam=fCmd.beams()[0]
     from uCmd import label3D
     self.labTail=label3D(pl=beam.Placement, text='____TAIL')
Exemple #27
0
 def refresh(self):
   obj=findFB(fCmd.beams()[0].Name)
   if not obj: obj=findFB(baseName=FreeCADGui.Selection.getSelection()[0])
   if obj: obj.Proxy.redraw(obj)
   FreeCAD.ActiveDocument.recompute()
   FreeCAD.ActiveDocument.recompute()