Exemplo n.º 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()
Exemplo n.º 2
0
 def update(self,fp,edges=None):
   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=pCmd.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
     pCmd.moveToPyLi(p,fp.Label)
     pipes.append(p)
     n=len(pipes)-1
     if n and not fCmd.isParallel(fCmd.beamAx(pipes[n]),fCmd.beamAx(pipes[n-1])):
       #---Create the curve---
       propList=[fp.PSize,fp.OD,fp.thk,90,fp.BendRadius]
       c=pCmd.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:]
         fCmd.extendTheBeam(p1,portA)
         fCmd.extendTheBeam(p2,portB)
         pCmd.moveToPyLi(c,fp.Label)
Exemplo n.º 3
0
 def addSelection(self, doc, obj, sub, pnt):
     lastSel = FreeCAD.getDocument(doc).getObject(obj)
     subLastSel = lastSel.Shape.getElement(sub)
     if lastSel.TypeId == 'Part::FeaturePython' and hasattr(
             lastSel, "Height") and subLastSel.ShapeType == "Edge":
         self.edges.append(subLastSel)
         self.beams.append(lastSel)
         FreeCAD.Console.PrintMessage('Edge/beam pair nr.' +
                                      str(len(self.edges)) +
                                      '  selected.\n')
     if (len(self.edges) == len(self.beams) == 2):
         if fCmd.isOrtho(*self.edges):
             self.beams.reverse()
             FreeCAD.ActiveDocument.openTransaction('Adjust angle')
             for i in range(len(self.edges)):
                 fCmd.extendTheBeam(self.beams[i], self.edges[i])
             FreeCAD.ActiveDocument.commitTransaction()
             FreeCAD.Console.PrintWarning("Adjustment executed.\n")
         else:
             FreeCAD.Console.PrintError("Edges must be orthogonal.\n")
         self.edges = []
         self.beams = []
         FreeCADGui.Selection.clearSelection()
         FreeCAD.activeDocument().recompute()
         FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n")
Exemplo n.º 4
0
 def addSelection(self, doc, obj, sub, pnt):
     lastSel = FreeCAD.getDocument(doc).getObject(obj)
     subLastSel = lastSel.Shape.getElement(sub)
     if lastSel.TypeId == 'Part::FeaturePython' and hasattr(
             lastSel, "Height") and self.target != None:
         fCmd.extendTheBeam(lastSel, self.target)
     if self.target == None and subLastSel.ShapeType in [
             "Edge", "Face", "Vertex"
     ]:
         self.target = subLastSel
         FreeCAD.Console.PrintMessage('Target selected.\n')
Exemplo n.º 5
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
Exemplo n.º 6
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')
Exemplo n.º 7
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)