Esempio n. 1
0
 def selectAction(self):
   self.objs=FreeCADGui.Selection.getSelection()
   L=direct=None
   pl=FreeCAD.Placement()
   # define general size of arrow
   if self.arrow: self.arrow.closeArrow()
   M=100.0
   moveSet=[o for o in FreeCADGui.Selection.getSelection() if hasattr(o,'Shape')]
   if moveSet:
     bb=moveSet[0].Shape.BoundBox
     for o in moveSet: bb=bb.united(o.Shape.BoundBox)
     edgesLens=[e.Length for o in moveSet for e in o.Shape.Edges]
     M=(bb.XLength+bb.YLength+bb.ZLength)/6.0
     # define placement of arrow
     orig=bb.Center
     orig[2]=bb.ZMax+bb.ZLength*0.1
     pl.move(orig)
   # define direction and displacement
   if self.form.edit1.text(): L=float(self.form.edit1.text())
   if frameCmd.faces():
     f=frameCmd.faces()[0]
     if L: direct=f.normalAt(0,0).normalize()*L
     else: direct=f.normalAt(0,0).normalize()*math.sqrt(f.Area)
   elif frameCmd.edges():
     e=frameCmd.edges()[0]
     if L: direct=e.tangentAt(0)*L
     else: direct=e.tangentAt(0).multiply(e.Length)
   # create the arrow_move object
   if direct: 
     pl.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),direct).multiply(pl.Rotation)
     self.arrow=arrow_move(pl=pl,direct=direct,M=M,objs=self.objs)
Esempio n. 2
0
def placeoTherElbow(c, v1=None, v2=None, P=None):
    '''
  Like placeTheElbow() but with more math.
  '''
    if not (v1 and v2):
        v1, v2 = [e.tangentAt(0) for e in frameCmd.edges()]
        try:
            P = frameCmd.intersectionCLines(*frameCmd.edges())
        except:
            pass
    if hasattr(c, 'PType') and hasattr(c, 'BendAngle') and v1 and v2:
        v1.normalize()
        v2.normalize()
        ortho = rounded(frameCmd.ortho(v1, v2))
        bisect = rounded(v2 - v1)
        cBisect = rounded(c.Ports[1] + c.Ports[0])  # math
        cZ = c.Ports[0].cross(c.Ports[1])  # more math
        ang = degrees(v1.getAngle(v2))
        c.BendAngle = ang
        rot1 = FreeCAD.Rotation(rounded(frameCmd.beamAx(c, cZ)), ortho)
        c.Placement.Rotation = rot1.multiply(c.Placement.Rotation)
        rot2 = FreeCAD.Rotation(rounded(frameCmd.beamAx(c, cBisect)), bisect)
        c.Placement.Rotation = rot2.multiply(c.Placement.Rotation)
        if not P:
            P = c.Placement.Base
        c.Placement.Base = P
Esempio n. 3
0
def placeTheElbow(c, v1=None, v2=None, P=None):
    '''
  placeTheElbow(c,v1,v2,P=None)
  Puts the curve C between vectors v1 and v2.
  If point P is given, translates it in there.
  NOTE: v1 and v2 oriented in the same direction along the path!
  '''
    if not (v1 and v2):
        v1, v2 = [e.tangentAt(0) for e in frameCmd.edges()]
        try:
            P = frameCmd.intersectionCLines(*frameCmd.edges())
        except:
            pass
    if hasattr(c, 'PType') and hasattr(c, 'BendAngle') and v1 and v2:
        v1.normalize()
        v2.normalize()
        ortho = rounded(frameCmd.ortho(v1, v2))
        bisect = rounded(v2 - v1)
        ang = degrees(v1.getAngle(v2))
        c.BendAngle = ang
        rot1 = FreeCAD.Rotation(
            rounded(frameCmd.beamAx(c, FreeCAD.Vector(0, 0, 1))), ortho)
        c.Placement.Rotation = rot1.multiply(c.Placement.Rotation)
        rot2 = FreeCAD.Rotation(
            rounded(frameCmd.beamAx(c, FreeCAD.Vector(1, 1, 0))), bisect)
        c.Placement.Rotation = rot2.multiply(c.Placement.Rotation)
        if not P:
            P = c.Placement.Base
        c.Placement.Base = P
Esempio n. 4
0
 def insert(self):
   d=self.pipeDictList[self.sizeList.currentRow()]
   FreeCAD.activeDocument().openTransaction('Insert cap')
   if len(frameCmd.edges())==0:
     propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk']))]
     vs=[v for sx in FreeCADGui.Selection.getSelectionEx() for so in sx.SubObjects for v in so.Vertexes]
     if len(vs)==0:   # nothing is selected
       self.lastCap=pipeCmd.makeCap(propList)
       if self.combo.currentText()!='<none>':
         pipeCmd.moveToPyLi(self.lastCap,self.combo.currentText())
     else:
       for v in vs:   # vertexes are selected
         self.lastCap=pipeCmd.makeCap(propList,v.Point)
       if self.combo.currentText()!='<none>':
         pipeCmd.moveToPyLi(self.lastCap,self.combo.currentText())
   else:
     for edge in frameCmd.edges():
       if edge.curvatureAt(0)!=0:   # curved edges are selected...
         objs=[o for o in FreeCADGui.Selection.getSelection() if hasattr(o,'PSize') and hasattr(o,'OD') and hasattr(o,'thk')]
         Z=None
         if len(objs)>0:  # ...pype objects are selected
           propList=[objs[0].PSize,objs[0].OD,objs[0].thk]
           Z=edge.centerOfCurvatureAt(0)-objs[0].Shape.Solids[0].CenterOfMass
         else:            # ...no pype objects are selected
           propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk']))]
           Z=edge.tangentAt(0).cross(edge.normalAt(0))
         self.lastCap=pipeCmd.makeCap(propList,edge.centerOfCurvatureAt(0),Z)
       if self.combo.currentText()!='<none>':
         pipeCmd.moveToPyLi(self.lastCap,self.combo.currentText())
   FreeCAD.activeDocument().commitTransaction()
   FreeCAD.activeDocument().recompute()
Esempio n. 5
0
def alignTheTube():
    '''
  Mates the selected 2 circular edges
  of 2 separate objects.
  '''
    try:
        t1, t2 = FreeCADGui.Selection.getSelection()[:2]
        d1, d2 = frameCmd.edges()[:2]
        if d1.curvatureAt(0) != 0 and d2.curvatureAt(0) != 0:
            n1 = d1.tangentAt(0).cross(d1.normalAt(0))
            n2 = d2.tangentAt(0).cross(d2.normalAt(0))
        else:
            return
    except:
        FreeCAD.Console.PrintError("Wrong selection.\n")
        return None
    rot = FreeCAD.Rotation(n2, n1)
    t2.Placement.Rotation = rot.multiply(t2.Placement.Rotation)
    #traslazione centri di curvatura
    d1, d2 = frameCmd.edges()  #redo selection to get new positions
    dist = d1.centerOfCurvatureAt(0) - d2.centerOfCurvatureAt(0)
    t2.Placement.move(dist)
    #verifica posizione relativa
    try:
        com1, com2 = [t.Shape.Solids[0].CenterOfMass for t in [t1, t2]]
        if isElbow(t2):
            pass
        elif (com1 -
              d1.centerOfCurvatureAt(0)).dot(com2 -
                                             d1.centerOfCurvatureAt(0)) > 0:
            reverseTheTube(FreeCADGui.Selection.getSelectionEx()[:2][1])
    except:
        pass
Esempio n. 6
0
 def selectAction(self):
     edged = [
         objex for objex in FreeCADGui.Selection.getSelectionEx()
         if frameCmd.edges([objex])
     ]
     if edged:
         self.Axis = frameCmd.edges([edged[0]])[0]
         self.deleteArrow()
         from polarUtilsCmd import arrow
         where = FreeCAD.Placement()
         where.Base = self.Axis.valueAt(self.Axis.LastParameter)
         where.Rotation = FreeCAD.Rotation(
             FreeCAD.Vector(0, 0, 1),
             self.Axis.tangentAt(self.Axis.LastParameter))
         size = [
             self.Axis.Length / 20.0, self.Axis.Length / 10.0,
             self.Axis.Length / 20.0
         ]
         self.arrow = arrow(pl=where,
                            scale=size,
                            offset=self.Axis.Length / 10.0)
         if self.Axis.curvatureAt(0):
             O = self.Axis.centerOfCurvatureAt(0)
             n = self.Axis.tangentAt(0).cross(self.Axis.normalAt(0))
             from Part import Edge, Line
             self.Axis = (Edge(
                 Line(FreeCAD.Vector(O), FreeCAD.Vector(O + n))))
         self.form.lab1.setText(edged[0].Object.Label + ": edge")
Esempio n. 7
0
def rotateTheTubeEdge(ang=45):
    if len(frameCmd.edges()) > 0 and frameCmd.edges()[0].curvatureAt(0) != 0:
        originalPos = frameCmd.edges()[0].centerOfCurvatureAt(0)
        obj = FreeCADGui.Selection.getSelection()[0]
        rotateTheTubeAx(vShapeRef=shapeReferenceAxis(), angle=ang)
        newPos = frameCmd.edges()[0].centerOfCurvatureAt(0)
        obj.Placement.move(originalPos - newPos)
Esempio n. 8
0
def placeThePype(pypeObject, port=0, target=None, targetPort=0):
  '''
  placeThePype(pypeObject, port=None, target=None, targetPort=0)
    pypeObject: a FeaturePython with PType property
    port: an optional port of pypeObject
  Aligns pypeObject's Placement to the Port of another pype which is selected in the viewport.
  The pype shall be selected to the circular edge nearest to the port concerned.
  '''
  pos=Z=FreeCAD.Vector()
  if target and hasattr(target,'PType') and hasattr(target,'Ports'): # target is given
    pos=portsPos(target)[targetPort]
    Z=portsDir(target)[targetPort]
  else: # find target
    try:
      selex=FreeCADGui.Selection.getSelectionEx()
      target=selex[0].Object
      so=selex[0].SubObjects[0]
    except:
      FreeCAD.Console.PrintError('No geometry selected\n')
      return
    if type(so)==Part.Vertex: pick=so.Point
    else: pick=so.CenterOfMass
    if hasattr(target,'PType') and hasattr(target,'Ports'): # ...selection is another pype-object
      pos, Z = nearestPort(target, pick)[1:]
    elif frameCmd.edges([selex[0]]): # one or more edges selected...
      edge=frameCmd.edges([selex[0]])[0]
      if edge.curvatureAt(0)!=0: # ...and the first is curve
        pos=edge.centerOfCurvatureAt(0)
        Z=edge.tangentAt(0).cross(edge.normalAt(0))
  # now place pypeObject on target
  pOport=pypeObject.Ports[port]
  if pOport==FreeCAD.Vector():
    pOport=pypeObject.Ports[port]
    if pOport==FreeCAD.Vector(): pOport=FreeCAD.Vector(0,0,-1)
  pypeObject.Placement=FreeCAD.Placement(pos+Z*pOport.Length,FreeCAD.Rotation(pOport*-1,Z))
Esempio n. 9
0
 def selectAction(self):
   self.objs=FreeCADGui.Selection.getSelection()
   L=direct=None
   pl=FreeCAD.Placement()
   # define general size of arrow
   if self.arrow: self.arrow.closeArrow()
   M=100.0
   moveSet=[o for o in FreeCADGui.Selection.getSelection() if hasattr(o,'Shape')]
   if moveSet:
     bb=moveSet[0].Shape.BoundBox
     for o in moveSet: bb=bb.united(o.Shape.BoundBox)
     edgesLens=[e.Length for o in moveSet for e in o.Shape.Edges]
     M=(bb.XLength+bb.YLength+bb.ZLength)/6.0
     # define placement of arrow
     orig=bb.Center
     orig[2]=bb.ZMax+bb.ZLength*0.1
     pl.move(orig)
   # define direction and displacement
   #if self.form.edit1.text(): L=float(self.form.edit1.text())
   if frameCmd.faces():
     direct=frameCmd.faces()[0].normalAt(0,0)
     #f=frameCmd.faces()[0]
     #if L: direct=f.normalAt(0,0).normalize()*L
     #else: direct=f.normalAt(0,0).normalize()*math.sqrt(f.Area)
   elif frameCmd.edges():
     direct=frameCmd.edges()[0].tangentAt(0)
     #e=frameCmd.edges()[0]
     #if L: direct=e.tangentAt(0)*L
     #else: direct=e.tangentAt(0).multiply(e.Length)
   # create the arrow_move object
   if direct: 
     pl.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),direct).multiply(pl.Rotation)
     self.arrow=arrow_move(self.form.edit1,pl=pl,direct=direct,M=M,objs=self.objs)
Esempio n. 10
0
 def accept(self):
   if self.beam!=None and len(frameCmd.edges())>0:
     FreeCAD.activeDocument().openTransaction('Fill frame')
     if self.form.radio1.isChecked():
       frameCmd.placeTheBeam(self.beam,frameCmd.edges()[0])
     else:
       for edge in frameCmd.edges():
         struct=FreeCAD.activeDocument().copyObject(self.beam,True)
         frameCmd.placeTheBeam(struct,edge)
       FreeCAD.activeDocument().recompute()
     FreeCAD.ActiveDocument.recompute()
     FreeCAD.activeDocument().commitTransaction()
Esempio n. 11
0
 def accept(self):
   if self.beam!=None and len(frameCmd.edges())>0:
     FreeCAD.activeDocument().openTransaction('Fill frame')
     if self.form.radio1.isChecked():
       frameCmd.placeTheBeam(self.beam,frameCmd.edges()[0])
     else:
       for edge in frameCmd.edges():
         struct=FreeCAD.activeDocument().copyObject(self.beam,True)
         frameCmd.placeTheBeam(struct,edge)
       FreeCAD.activeDocument().recompute()
     FreeCAD.ActiveDocument.recompute()
     FreeCAD.activeDocument().commitTransaction()
Esempio n. 12
0
def simpleSurfBend(path=None,profile=None):
  'select the centerline and the O.D. and let it sweep'
  curva=FreeCAD.activeDocument().addObject("Part::Feature","CurvaSemplice")
  if path==None or profile==None:
    curva.Shape=Part.makeSweepSurface(*frameCmd.edges()[:2])
  elif path.ShapeType==profile.ShapeType=='Edge':
    curva.Shape=Part.makeSweepSurface(path,profile)
Esempio n. 13
0
def makeBranch(base=None,
               DN="DN50",
               PRating="SCH-STD",
               OD=60.3,
               thk=3,
               BR=None,
               lab="Traccia",
               color=(0.8, 0.8, 0.8)):
    '''
  makeBranch(base=None, DN="DN50",PRating="SCH-STD",OD=60.3,thk=3,BR=None, lab="Traccia" color=(0.8,0.8,0.8))
  Draft function for PypeBranch.
  '''
    if not BR:
        BR = 0.75 * OD
    if not base:
        if FreeCADGui.Selection.getSelection():
            obj = FreeCADGui.Selection.getSelection()[0]
            isWire = hasattr(obj, 'Shape') and type(obj.Shape) == Part.Wire
            isSketch = hasattr(
                obj, 'TypeId') and obj.TypeId == 'Sketcher::SketchObject'
            if isWire or isSketch:
                base = obj
            if isWire:
                drawAsCenterLine(obj)
        elif frameCmd.edges():
            path = makeW()
            base = path
    if base:
        a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", lab)
        pipeFeatures.PypeBranch(a, base, DN, PRating, OD, thk, BR)
        pipeFeatures.ViewProviderPypeBranch(a.ViewObject)
        return a
    else:
        FreeCAD.Console.PrintError('Select a valid path.\n')
Esempio n. 14
0
def makeNozzle(DN='DN50', H=200, OD=60.3, thk=3,D=160, d=62, df=132,f=14,t=15,n=4):
  '''
  makeNozzle(DN,OD,thk,D,df,f,t,n)
    DN (string): nominal diameter
    OD (float): pipe outside diameter
    thk (float): pipe wall thickness
    D (float): flange diameter
    d (float): flange hole
    df (float): bolts holes distance
    f (float): bolts holes diameter
    t (float): flange thickness
    n (int): nr. of bolts
  '''
  selex=FreeCADGui.Selection.getSelectionEx()
  for sx in selex: 
    #e=sx.SubObjects[0]
    s=sx.Object
    curved=[e for e in frameCmd.edges([sx]) if e.curvatureAt(0)]
    for e in curved:
      pipe=makePipe([DN,OD,thk,H], pos=e.centerOfCurvatureAt(0),Z=e.tangentAt(0).cross(e.normalAt(0)))
      FreeCAD.ActiveDocument.recompute()
      flange=makeFlange([DN,'S.O.',D,d,df,f,t,n],pos=portsPos(pipe)[1],Z=portsDir(pipe)[1])
      pipe.MapReversed = False
      pipe.Support = [(s,frameCmd.edgeName(s,e)[1])]
      pipe.MapMode = 'Concentric'
      FreeCADGui.Selection.clearSelection()
      FreeCADGui.Selection.addSelection(pipe)
      FreeCADGui.Selection.addSelection(flange)
      flange.Support = [(pipe,'Edge1')]
      flange.MapReversed = True
      flange.MapMode = 'Concentric'
      FreeCAD.ActiveDocument.recompute()
Esempio n. 15
0
 def addBeams(self):
     # find selected FB
     try:
         FB = findFB(baseName=FreeCADGui.Selection.getSelection()[0].Name)
     except:
         return
     if FB:
         beamsList = FB.Beams
         for edge in frameCmd.edges():
             i = indexEdge(edge, FB.Base.Shape.Edges)
             beam = makeStructure(FB.Profile)
             beam.addProperty("App::PropertyFloat", "tailOffset",
                              "FrameBranch", "The extension of the tail")
             beam.addProperty("App::PropertyFloat", "headOffset",
                              "FrameBranch", "The extension of the head")
             beam.addProperty("App::PropertyFloat", "spin", "FrameBranch",
                              "The rotation of the section")
             beam.addExtension("Part::AttachExtensionPython", beam)
             beam.Support = [(FB.Base, 'Edge' + str(i + 1))]
             beam.MapMode = 'NormalToEdge'
             beam.MapReversed = True
             beamsList[i] = str(beam.Name)
         FB.Beams = beamsList
         FreeCAD.ActiveDocument.recompute()
         FreeCAD.ActiveDocument.recompute()
Esempio n. 16
0
def makeW():
    edges = frameCmd.edges()
    if len(edges) > 1:
        # patch for FC 0.17:
        first = edges[0]
        points = list()
        while len(edges) > 1:
            points.append(frameCmd.intersectionCLines(edges.pop(0), edges[0]))
        if edges[0].valueAt(0) == points[-1]:
            points.append(edges[0].valueAt(edges[0].LastParameter))
        else:
            points.append(edges[0].valueAt(0))
        if first.valueAt(0) == points[0]:
            points.insert(0, first.valueAt(first.LastParameter))
        else:
            points.insert(0, first.valueAt(0))  # END
        from Draft import makeWire
        try:
            p = makeWire(points)
        except:
            FreeCAD.Console.PrintError('Missing intersection\n')
            return None
        p.Label = 'Path'
        drawAsCenterLine(p)
        return p
    elif FreeCADGui.Selection.getSelection():
        obj = FreeCADGui.Selection.getSelection()[0]
        if hasattr(obj, 'Shape') and type(obj.Shape) == Part.Wire:
            drawAsCenterLine(obj)
        return obj
    else:
        return None
Esempio n. 17
0
def alignTheTube():
    '''
  Mates the selected 2 circular edges
  of 2 separate objects.
  '''
    try:
        t1 = FreeCADGui.Selection.getSelection()[0]
        t2 = FreeCADGui.Selection.getSelection()[-1]
    except:
        FreeCAD.Console.PrintError("Select at least one object.\n")
        return None
    #if hasattr(t2,'PType'): # align with placeThePype
    #try:
    #objex=FreeCADGui.Selection.getSelectionEx()[-1]
    #if type(objex.SubObjects[0])==Part.Vertex:
    #pick=objex.SubObjects[0].Point
    #else:
    #pick=objex.SubObjects[0].CenterOfMass
    #print(nearestPort(t2, pick)[0]) #debug
    #placeThePype(t2, nearestPort(t2, pick)[0])
    #except:
    #placeThePype(t2)
    #else: # mate the curved edges
    d1, d2 = frameCmd.edges()[:2]
    if d1.curvatureAt(0) != 0 and d2.curvatureAt(0) != 0:
        n1 = d1.tangentAt(0).cross(d1.normalAt(0))
        n2 = d2.tangentAt(0).cross(d2.normalAt(0))
    else:
        FreeCAD.Console.PrintError("Select 2 curved edges.\n")
        return None
    rot = FreeCAD.Rotation(n2, n1)
    t2.Placement.Rotation = rot.multiply(t2.Placement.Rotation)
    #traslazione centri di curvatura
    d1, d2 = frameCmd.edges()  #redo selection to get new positions
    dist = d1.centerOfCurvatureAt(0) - d2.centerOfCurvatureAt(0)
    t2.Placement.move(dist)
    #verifica posizione relativa
    try:
        com1, com2 = [t.Shape.Solids[0].CenterOfMass for t in [t1, t2]]
        if isElbow(t2):
            pass
        elif (com1 -
              d1.centerOfCurvatureAt(0)).dot(com2 -
                                             d1.centerOfCurvatureAt(0)) > 0:
            reverseTheTube(FreeCADGui.Selection.getSelectionEx()[:2][1])
    except:
        pass
Esempio n. 18
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()
Esempio n. 19
0
 def insert(self):
   tubes=[t for t in frameCmd.beams() if hasattr(t,'PSize')]
   if len(tubes)>0 and tubes[0].PSize in [prop['PSize'] for prop in self.pipeDictList]:
     for prop in self.pipeDictList:
       if prop['PSize']==tubes[0].PSize:
         d=prop
         break
   else:
     d=self.pipeDictList[self.sizeList.currentRow()]
   propList=[d['PSize'],d['FlangeType'],float(pq(d['D'])),float(pq(d['d'])),float(pq(d['df'])),float(pq(d['f'])),float(pq(d['t'])),int(d['n'])]
   FreeCAD.activeDocument().openTransaction('Insert flange')
   if len(frameCmd.edges())==0:
     vs=[v for sx in FreeCADGui.Selection.getSelectionEx() for so in sx.SubObjects for v in so.Vertexes]
     if len(vs)==0:
       self.lastFlange=pipeCmd.makeFlange(propList)
       self.lastFlange.PRating=self.PRating
       if self.combo.currentText()!='<none>':
         pipeCmd.moveToPyLi(self.lastFlange,self.combo.currentText())
     else:
       for v in vs:
         self.lastFlange=pipeCmd.makeFlange(propList,v.Point)
         self.lastFlange.PRating=self.PRating
         if self.combo.currentText()!='<none>':
           pipeCmd.moveToPyLi(self.lastFlange,self.combo.currentText())
   elif tubes:
     selex=FreeCADGui.Selection.getSelectionEx()
     for sx in selex:
       if hasattr(sx.Object,'PType') and sx.Object.PType=='Pipe' and frameCmd.edges([sx]):
         for edge in frameCmd.edges([sx]):
           if edge.curvatureAt(0)!=0:
             self.lastFlange=pipeCmd.makeFlange(propList,edge.centerOfCurvatureAt(0),sx.Object.Shape.Solids[0].CenterOfMass-edge.centerOfCurvatureAt(0))
             self.lastFlange.PRating=self.PRating
             if self.combo.currentText()!='<none>':
               pipeCmd.moveToPyLi(self.lastFlange,self.combo.currentText())
     FreeCAD.activeDocument().commitTransaction()
     FreeCAD.activeDocument().recompute()
     return
   else:
     for edge in frameCmd.edges():
       if edge.curvatureAt(0)!=0:
         self.lastFlange=pipeCmd.makeFlange(propList,edge.centerOfCurvatureAt(0),edge.tangentAt(0).cross(edge.normalAt(0)))
         self.lastFlange.PRating=self.PRating
         if self.combo.currentText()!='<none>':
           pipeCmd.moveToPyLi(self.lastFlange,self.combo.currentText())
   FreeCAD.activeDocument().commitTransaction()
   FreeCAD.activeDocument().recompute()
Esempio n. 20
0
 def selectAction(self):
   edged = [objex for objex in FreeCADGui.Selection.getSelectionEx() if frameCmd.edges([objex])]
   if edged:
     self.Axis=frameCmd.edges([edged[0]])[0]
     self.deleteArrow()
     from polarUtilsCmd import arrow
     where=FreeCAD.Placement()
     where.Base=self.Axis.valueAt(self.Axis.LastParameter)
     where.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),self.Axis.tangentAt(self.Axis.LastParameter))
     size=[self.Axis.Length/20.0,self.Axis.Length/10.0,self.Axis.Length/20.0]
     self.arrow=arrow(pl=where,scale=size,offset=self.Axis.Length/10.0)
     if self.Axis.curvatureAt(0):
       O=self.Axis.centerOfCurvatureAt(0)
       n=self.Axis.tangentAt(0).cross(self.Axis.normalAt(0))
       from Part import Edge, Line
       self.Axis=(Edge(Line(FreeCAD.Vector(O),FreeCAD.Vector(O+n))))
     self.form.lab1.setText(edged[0].Object.Label+": edge")
Esempio n. 21
0
def makePypeLine2(DN="DN50",
                  PRating="SCH-STD",
                  OD=60.3,
                  thk=3,
                  BR=None,
                  lab="Tubatura",
                  pl=None,
                  color=(0.8, 0.8, 0.8)):
    '''
  makePypeLine2(DN="DN50",PRating="SCH-STD",OD=60.3,thk=3,BR=None, lab="Tubatura",pl=None, color=(0.8,0.8,0.8))
  Adds a PypeLine2 object creating pipes over the selected edges.
  Default tube is "DN50", "SCH-STD"
  Bending Radius is set to 0.75*OD.
  '''
    if not BR:
        BR = 0.75 * OD
    # create the pypeLine group
    if not pl:
        a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", lab)
        pipeFeatures.PypeLine2(a, DN, PRating, OD, thk, BR, lab)
        pipeFeatures.ViewProviderPypeLine(a.ViewObject)  # a.ViewObject.Proxy=0
        a.ViewObject.ShapeColor = color
        if len(FreeCADGui.Selection.getSelection()) == 1:
            obj = FreeCADGui.Selection.getSelection()[0]
            isWire = hasattr(obj, 'Shape') and type(obj.Shape) == Part.Wire
            isSketch = hasattr(
                obj, 'TypeId') and obj.TypeId == 'Sketcher::SketchObject'
            if isWire or isSketch:
                a.Base = obj
                a.Proxy.update(a)
            if isWire:
                #moveToPyLi(obj,a.Label) TEMPORARY: disabled for PypeLine3
                drawAsCenterLine(obj)
        elif frameCmd.edges():
            path = makeW()
            #moveToPyLi(path,a.Label) TEMPORARY: disabled for PypeLine3
            a.Base = path
            a.Proxy.update(a)
    else:
        a = FreeCAD.ActiveDocument.getObjectsByLabel(pl)[0]
        group = FreeCAD.ActiveDocument.getObjectsByLabel(a.Group)[0]
        a.Proxy.update(a, frameCmd.edges())
        FreeCAD.Console.PrintWarning("Objects added to pypeline's group " +
                                     a.Group + "\n")
    return a
Esempio n. 22
0
 def getLength(self):
   roundDigits=3
   if len(frameCmd.edges())>0:
     edge=frameCmd.edges()[0]
     self.form.edit4.setText(str(edge.Length))
     self.form.edit5.setText('1')
     dx,dy,dz=list(edge.tangentAt(0))
     self.form.edit1.setText(str(round(dx,roundDigits)))
     self.form.edit2.setText(str(round(dy,roundDigits)))
     self.form.edit3.setText(str(round(dz,roundDigits)))
     FreeCADGui.Selection.clearSelection()
     self.deleteArrow()
     from polarUtilsCmd import arrow
     where=FreeCAD.Placement()
     where.Base=edge.valueAt(0)
     where.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),edge.tangentAt(0))
     size=[edge.Length/20.0,edge.Length/10.0,edge.Length/20.0]
     self.arrow=arrow(pl=where,scale=size,offset=edge.Length/2.0)
Esempio n. 23
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
Esempio n. 24
0
 def selectAction(self):
     shapes = [
         y for x in FreeCADGui.Selection.getSelectionEx()
         for y in x.SubObjects if hasattr(y, 'ShapeType')
     ][:2]
     if len(shapes) > 1:
         self.getDistance()
     elif len(frameCmd.edges()) > 0:
         self.getLength()
Esempio n. 25
0
 def getLength(self):
   roundDigits=3
   if len(frameCmd.edges())>0:
     edge=frameCmd.edges()[0]
     self.form.edit4.setText(str(edge.Length))
     self.form.edit5.setText('1')
     dx,dy,dz=list(edge.tangentAt(0))
     self.form.edit1.setText(str(round(dx,roundDigits)))
     self.form.edit2.setText(str(round(dy,roundDigits)))
     self.form.edit3.setText(str(round(dz,roundDigits)))
     FreeCADGui.Selection.clearSelection()
     self.deleteArrow()
     from polarUtilsCmd import arrow
     where=FreeCAD.Placement()
     where.Base=edge.valueAt(0)
     where.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),edge.tangentAt(0))
     size=[edge.Length/20.0,edge.Length/10.0,edge.Length/20.0]
     self.arrow=arrow(pl=where,scale=size,offset=edge.Length/2.0)
Esempio n. 26
0
 def pickAction(self,path=None,event=None,arg=None):
   FreeCAD.activeDocument().openTransaction('Quick move')
   if event.wasCtrlDown(): k=-1*float(self.edit.text())
   else: k=1*float(self.edit.text())
   sel=FreeCADGui.Selection.getSelection()
   if sel: self.objs=[o for o in sel if hasattr(o,'Shape')]
   if event.wasCtrlDown() and event.wasAltDown():
     if frameCmd.edges(): 
       self.edge=frameCmd.edges()[0]
       for o in self.objs: frameCmd.rotateTheBeamAround(o, self.edge, 90)
     elif self.edge:
       for o in self.objs: frameCmd.rotateTheBeamAround(o, self.edge, 90)
   else:
     for o in self.objs: o.Placement.move(self.direct*k)
     self.Placement.move(self.direct*k)
     pl,direct,M=[self.Placement,self.direct,self.scale]
     self.closeArrow()
     self.__init__(self.edit, pl,direct,M,self.objs)
   FreeCAD.activeDocument().commitTransaction()
Esempio n. 27
0
 def pickAction(self,path=None,event=None,arg=None):
   FreeCAD.activeDocument().openTransaction('Quick move')
   if event.wasCtrlDown(): k=-1
   else: k=1
   sel=FreeCADGui.Selection.getSelection()
   if sel: self.objs=[o for o in sel if hasattr(o,'Shape')]
   if event.wasCtrlDown() and event.wasAltDown():
     if frameCmd.edges(): 
       self.edge=frameCmd.edges()[0]
       for o in self.objs: frameCmd.rotateTheBeamAround(o, self.edge, 90)
     elif self.edge:
       for o in self.objs: frameCmd.rotateTheBeamAround(o, self.edge, 90)
   else:
     for o in self.objs: o.Placement.move(self.direct*k)
     self.Placement.move(self.direct*k)
     pl,direct,M=[self.Placement,self.direct,self.scale]
     self.closeArrow()
     self.__init__(pl,direct,M,self.objs)
   FreeCAD.activeDocument().commitTransaction()
Esempio n. 28
0
def makeW():
    edges = frameCmd.edges()
    if len(edges) > 1:
        # patch for FC 0.17:
        first = edges[0]
        points = list()
        while len(edges) > 1:
            points.append(frameCmd.intersectionCLines(edges.pop(0), edges[0]))
        if edges[0].valueAt(0) == points[-1]:
            points.append(edges[0].valueAt(edges[0].LastParameter))
        else:
            points.append(edges[0].valueAt(0))
        if first.valueAt(0) == points[0]:
            points.insert(0, first.valueAt(first.LastParameter))
        else:
            points.insert(0, first.valueAt(0))  # END
        #P0=edges[0].valueAt(0)
        #P1=edges[0].valueAt(edges[0].LastParameter)
        #Pint=frameCmd.intersectionCLines(edges[0],edges[1])
        #d0=Pint-P0
        #d1=Pint-P1
        #if d1.Length>d0.Length:
        #P0=P1
        #eds=list()
        #for i in range(len(edges)-1):
        #P1=frameCmd.intersectionCLines(edges[i],edges[i+1])
        #eds.append(Part.Edge(Part.Line(P0,P1)))
        #P0=P1
        #P1=edges[-1].valueAt(edges[-1].LastParameter)
        #P2=edges[-1].valueAt(0)
        #d1=P1-P0
        #d2=P2-P0
        #if d1.Length<d2.Length:
        #P1=P2
        #eds.append(Part.Edge(Part.Line(P0,P1)))
        #for e in eds:
        #print(type(e))
        #w=Part.Wire(eds)
        #points=[e.valueAt(0) for e in w.Edges]
        #last=e.Edges[-1]
        #points.append(last.valueAt(last.LastParameter))
        from Draft import makeWire
        try:
            p = makeWire(points)
        except:
            FreeCAD.Console.PrintError('Missing intersection\n')
            return None
        p.Label = 'Path'
        drawAsCenterLine(p)
        return p
    else:
        FreeCAD.Console.PrintError('Not enough edges/n')
        return None
Esempio n. 29
0
 def trim(self):
   if len(frameCmd.beams())==1:
     pipe=frameCmd.beams()[0]
     comPipeEdges=[e.CenterOfMass for e in pipe.Shape.Edges]
     eds=[e for e in frameCmd.edges() if not e.CenterOfMass in comPipeEdges]
     FreeCAD.activeDocument().openTransaction('Trim pipes')
     for edge in eds:
       frameCmd.extendTheBeam(frameCmd.beams()[0],edge)
     FreeCAD.activeDocument().commitTransaction()
     FreeCAD.activeDocument().recompute()
   else:
     FreeCAD.Console.PrintError("Wrong selection\n")
Esempio n. 30
0
 def Activated(self):
     import FreeCAD, FreeCADGui, frameCmd, frameObservers
     edges = frameCmd.edges()
     if len(edges) >= 2 and len(FreeCADGui.Selection.getSelection()) >= 2:
         e1 = edges.pop(0)
         beams = FreeCADGui.Selection.getSelection()[1:]
         if len(edges) == len(beams):
             pairs = [(beams[i], edges[i]) for i in range(len(beams))]
             FreeCAD.activeDocument().openTransaction('AlignEdge')
             for p in pairs:
                 frameCmd.joinTheBeamsEdges(p[0], e1, p[1])
             FreeCAD.activeDocument().commitTransaction()
     else:
         FreeCADGui.Selection.clearSelection()
         s = frameObservers.alignEdgeObserver()
         FreeCADGui.Selection.addObserver(s)
Esempio n. 31
0
 def Activated(self):
   import FreeCAD, FreeCADGui, frameCmd, frameObservers
   edges=frameCmd.edges()
   if len(edges)>=2 and len(FreeCADGui.Selection.getSelection())>=2:
     e1=edges.pop(0)
     beams=FreeCADGui.Selection.getSelection()[1:]
     if len(edges)==len(beams):
       pairs=[(beams[i],edges[i]) for i in range(len(beams))]
       FreeCAD.activeDocument().openTransaction('AlignEdge')
       for p in pairs:
         frameCmd.joinTheBeamsEdges(p[0],e1,p[1])
       FreeCAD.activeDocument().commitTransaction()
   else:
     FreeCADGui.Selection.clearSelection()
     s=frameObservers.alignEdgeObserver()
     FreeCADGui.Selection.addObserver(s)
Esempio n. 32
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()
Esempio n. 33
0
def makeRoute(n=Z):
  curvedEdges=[e for e in frameCmd.edges() if e.curvatureAt(0)!=0]
  if curvedEdges:
    s=FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','pipeRoute')
    s.MapMode = "SectionOfRevolution"
    s.Support = [frameCmd.edgeName()]
  else:
    return None
  if frameCmd.faces(): 
    n=frameCmd.faces()[0].normalAt(0,0)
  x=s.Placement.Rotation.multVec(X)
  z=s.Placement.Rotation.multVec(Z)
  t=x.dot(n)*x+z.dot(n)*z
  alfa=degrees(z.getAngle(t))
  if t.Length>0.000000001:
    s.AttachmentOffset.Rotation=s.AttachmentOffset.Rotation.multiply(FreeCAD.Rotation(Y,alfa))
  FreeCAD.ActiveDocument.recompute()
  FreeCADGui.activeDocument().setEdit(s.Name)
Esempio n. 34
0
 def makeSingle(self):
   FreeCAD.activeDocument().openTransaction('Insert Single Struct')
   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)
   if frameCmd.faces():
     Z=FreeCAD.Vector(0,0,1)
     for f in frameCmd.faces():
       beam=makeStructure(profile)
       beam.Placement=FreeCAD.Placement(f.CenterOfMass,FreeCAD.Rotation(Z,f.normalAt(0,0)))
       if self.form.editLength.text(): beam.Height=float(self.form.editLength.text())
   else:
     for e in frameCmd.edges():
       beam=makeStructure(profile)
       frameCmd.placeTheBeam(beam,e)
       if self.form.editLength.text(): beam.Height=float(self.form.editLength.text())
   FreeCAD.ActiveDocument.recompute()
Esempio n. 35
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 frameCmd.edges([objEx]):
      if edge.curvatureAt(0):
        disp=edge.centerOfCurvatureAt(0)-objEx.Object.Placement.Base
        break
      elif frameCmd.beams([objEx.Object]):
        ax=frameCmd.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)
Esempio n. 36
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()
Esempio n. 37
0
 def accept(self):
     fname = self.form.listFiles.currentItem().text()
     row = None
     pos = None
     Z = None
     if self.form.comboDirs.currentText() == '<shapes>': sdir = ''
     else: sdir = self.form.comboDirs.currentText()
     if fname in self.filesListed:
         for r in self.pipeDictList:
             if r["fileName"] == fname:
                 row = r
                 break
         name = row["name"]
         ports = row["ports"]
     else:
         name = fname.split('.')[0]
         ports = '0:0:0'
     selex = FreeCADGui.Selection.getSelectionEx()
     if selex:
         vxs = [
             v for sx in selex for so in sx.SubObjects for v in so.Vertexes
         ]
         cedges = [e for e in frameCmd.edges() if e.curvatureAt(0) != 0]
         faces = frameCmd.faces()
         if faces:
             x = (faces[0].ParameterRange[0] +
                  faces[0].ParameterRange[1]) / 2
             y = (faces[0].ParameterRange[2] +
                  faces[0].ParameterRange[3]) / 2
             pos = faces[0].valueAt(x, y)
             Z = faces[0].normalAt(x, y)
         elif cedges:
             pos = cedges[0].centerOfCurvatureAt(0)
             Z = cedges[0].tangentAt(0).cross(cedges[0].normalAt(0))
         elif vxs:
             pos = vxs[0].Point
     self.lastThing = makeThing(name, join(sdir, fname), ports, pos, Z)
     if row:
         self.lastThing.Kv = float(row["Kv"])
         self.lastThing.PSize = row["DN"]
         self.lastThing.PRating = row["PN"]
Esempio n. 38
0
 def addBeams(self):
   # find selected FB
   try:
     FB=findFB(baseName=FreeCADGui.Selection.getSelection()[0].Name)
   except:
     return
   if FB:
     beamsList=FB.Beams
     for edge in frameCmd.edges():
       i=indexEdge(edge,FB.Base.Shape.Edges)
       beam=makeStructure(FB.Profile)
       beam.addProperty("App::PropertyFloat","tailOffset","FrameBranch","The extension of the tail")
       beam.addProperty("App::PropertyFloat","headOffset","FrameBranch","The extension of the head")
       beam.addProperty("App::PropertyFloat","spin","FrameBranch","The rotation of the section")
       beam.addExtension("Part::AttachExtensionPython",beam)
       beam.Support=[(FB.Base,'Edge'+str(i+1))]
       beam.MapMode='NormalToEdge'
       beam.MapReversed=True
       beamsList[i]=str(beam.Name)
     FB.Beams=beamsList
     FreeCAD.ActiveDocument.recompute()
     FreeCAD.ActiveDocument.recompute()
Esempio n. 39
0
 def insert(self):
   from pipeCmd import moveToPyLi
   if self.combo.currentText()=='<new>':
     name=self.edit1.text()
     if not name: name='Telaio'
     a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
     FrameLine(a)
     a.ViewObject.Proxy=0
     self.combo.addItem(a.Label)
     self.combo.setCurrentIndex(self.combo.count()-1)
     if self.sectList.selectedItems():
       self.getProfile()
   elif self.sectList.selectedItems():
     prof= FreeCAD.ActiveDocument.getObjectsByLabel(self.sectList.selectedItems()[0].text())[0]
     for e in frameCmd.edges():
       if self.cb1.isChecked():
         s=makeStructure(FreeCAD.ActiveDocument.copyObject(prof))
       else:
         s=makeStructure(prof)
       frameCmd.placeTheBeam(s,e)
       moveToPyLi(s,self.current.Name)
     FreeCAD.ActiveDocument.recompute()
Esempio n. 40
0
 def makeSingle(self):
     FreeCAD.activeDocument().openTransaction('Insert Single Struct')
     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)
     if frameCmd.faces():
         Z = FreeCAD.Vector(0, 0, 1)
         for f in frameCmd.faces():
             beam = makeStructure(profile)
             beam.Placement = FreeCAD.Placement(
                 f.CenterOfMass, FreeCAD.Rotation(Z, f.normalAt(0, 0)))
             if self.form.editLength.text():
                 beam.Height = float(self.form.editLength.text())
     else:
         for e in frameCmd.edges():
             beam = makeStructure(profile)
             frameCmd.placeTheBeam(beam, e)
             if self.form.editLength.text():
                 beam.Height = float(self.form.editLength.text())
     FreeCAD.ActiveDocument.recompute()
Esempio n. 41
0
 def accept(self):
   fname=self.form.listFiles.currentItem().text()
   row=None
   pos=None
   Z=None
   if self.form.comboDirs.currentText()=='<shapes>': sdir=''
   else: sdir=self.form.comboDirs.currentText()
   if fname in self.filesListed:
     for r in self.pipeDictList:
       if r["fileName"]==fname:
         row=r
         break
     name=row["name"]
     ports=row["ports"]
   else:
     name=fname.split('.')[0]
     ports='0:0:0'
   selex=FreeCADGui.Selection.getSelectionEx()
   if selex:
     vxs=[v for sx in selex for so in sx.SubObjects for v in so.Vertexes]
     cedges=[e for e in frameCmd.edges() if e.curvatureAt(0)!=0]
     faces=frameCmd.faces()
     if faces:
       x=(faces[0].ParameterRange[0]+faces[0].ParameterRange[1])/2
       y=(faces[0].ParameterRange[2]+faces[0].ParameterRange[3])/2
       pos=faces[0].valueAt(x,y)
       Z=faces[0].normalAt(x,y)
     elif cedges:
       pos=cedges[0].centerOfCurvatureAt(0)
       Z=cedges[0].tangentAt(0).cross(cedges[0].normalAt(0))
     elif vxs:
       pos=vxs[0].Point
   self.lastThing=makeThing(name,join(sdir,fname),ports,pos,Z)
   if row:
     self.lastThing.Kv=float(row["Kv"])
     self.lastThing.PSize=row["DN"]
     self.lastThing.PRating=row["PN"]
Esempio n. 42
0
 def selectAction(self):
   shapes=[y for x in FreeCADGui.Selection.getSelectionEx() for y in x.SubObjects if hasattr(y,'ShapeType')][:2]
   if len(shapes)>1:
     self.getDistance()
   elif len(frameCmd.edges())>0:
     self.getLength()