Exemplo n.º 1
0
 def insert(self):
   selex=FreeCADGui.Selection.getSelectionEx()
   if len(selex)==0:
     d=self.pipeDictList[self.sizeList.currentRow()]
     propList=[d['PSize'],self.PRating,float(pq(d['C'])),float(pq(d['H'])),float(pq(d['d']))]
     FreeCAD.activeDocument().openTransaction('Insert clamp in (0,0,0)')
     ub=pipeCmd.makeUbolt(propList)
     if self.combo.currentText()!='<none>':
       pipeCmd.moveToPyLi(ub,self.combo.currentText())
     FreeCAD.activeDocument().commitTransaction()
     FreeCAD.activeDocument().recompute()
   else:
     FreeCAD.activeDocument().openTransaction('Insert clamp on tube')
     for objex in selex:
       if hasattr(objex.Object,'PType') and objex.Object.PType=='Pipe':
         d=[typ for typ in self.pipeDictList if typ['PSize']==objex.Object.PSize]
         if len(d)>0:
           d=d[0]
         else:
           d=self.pipeDictList[self.sizeList.currentRow()]
         propList=[d['PSize'],self.PRating,float(pq(d['C'])),float(pq(d['H'])),float(pq(d['d']))]
         H=float(objex.Object.Height)
         gap=H-float(pq(d['C']))
         steps=[gap*self.cb1.isChecked(),H/2*self.cb2.isChecked(),(H-gap)*self.cb3.isChecked()]
         for s in steps:
           if s:
             ub=pipeCmd.makeUbolt(propList,pos=objex.Object.Placement.Base, Z=frameCmd.beamAx(objex.Object))
             ub.Placement.move(frameCmd.beamAx(objex.Object).multiply(s))
             if self.refNorm:
               pipeCmd.rotateTheTubeAx(obj=ub,angle=degrees(self.refNorm.getAngle((frameCmd.beamAx(ub,FreeCAD.Vector(0,1,0))))))
             if self.combo.currentText()!='<none>':
               pipeCmd.moveToPyLi(ub,self.combo.currentText())
     FreeCAD.activeDocument().commitTransaction()
   FreeCAD.activeDocument().recompute()
Exemplo n.º 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)
             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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def insert(self):
   d=self.pipeDictList[self.sizeList.currentRow()]
   FreeCAD.activeDocument().openTransaction('Insert pype-branch')
   plLabel=self.edit1.text()
   if not plLabel: plLabel="Traccia"
   a=pipeCmd.makeBranch(DN=d["PSize"],PRating=self.PRating,OD=float(d["OD"]),thk=float(d["thk"]), lab=plLabel, color=self.color)
   if self.combo.currentText()!='<none>':
     pipeCmd.moveToPyLi(a,self.combo.currentText())
   FreeCAD.activeDocument().commitTransaction()
   FreeCAD.ActiveDocument.recompute()
   FreeCAD.ActiveDocument.recompute()
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def breakPipe(self):
   p2nd=None
   FreeCAD.activeDocument().openTransaction('Break pipes')
   if self.edit1.text()[-1]=='%':
     pipes=[p for p in frameCmd.beams() if pipeCmd.isPipe(p)]
     for p in pipes:
       p2nd=pipeCmd.breakTheTubes(float(p.Height)*float(self.edit1.text().rstrip('%').strip())/100,pipes=[p],gap=float(self.edit2.text()))
       if p2nd and self.combo.currentText()!='<none>':
         for p in p2nd:
           pipeCmd.moveToPyLi(p,self.combo.currentText())
   else:
     p2nd=pipeCmd.breakTheTubes(float(self.edit1.text()),gap=float(self.edit2.text()))
     if p2nd and self.combo.currentText()!='<none>':
       for p in p2nd:
         pipeCmd.moveToPyLi(p,self.combo.currentText())
   FreeCAD.activeDocument().commitTransaction()
   FreeCAD.activeDocument().recompute()
Exemplo n.º 7
0
 def update(self,fp,copyProfile=True):
   if hasattr(fp.Base,'Shape'):
     edges=fp.Base.Shape.Edges
     if not edges:
       FreeCAD.Console.PrintError('Base has not valid edges\n')
       return
   group=FreeCAD.activeDocument().getObjectsByLabel(fp.Group)[0]
   if fp.Profile:
     FreeCAD.activeDocument().openTransaction('Update frameLine')
     for e in edges:
       if copyProfile:
         p=FreeCAD.activeDocument().copyObject(fp.Profile,True)
       else:
         p=fp.Profile
       beam=makeStructure(p)
       frameCmd.placeTheBeam(beam,e)
       pipeCmd.moveToPyLi(beam,fp.Name)
     FreeCAD.activeDocument().commitTransaction()
   FreeCAD.activeDocument().recompute()
Exemplo n.º 8
0
 def update(self, fp, copyProfile=True):
     if hasattr(fp.Base, 'Shape'):
         edges = fp.Base.Shape.Edges
         if not edges:
             FreeCAD.Console.PrintError('Base has not valid edges\n')
             return
     group = FreeCAD.activeDocument().getObjectsByLabel(fp.Group)[0]
     if fp.Profile:
         FreeCAD.activeDocument().openTransaction('Update frameLine')
         for e in edges:
             if copyProfile:
                 p = FreeCAD.activeDocument().copyObject(fp.Profile, True)
             else:
                 p = fp.Profile
             beam = makeStructure(p)
             frameCmd.placeTheBeam(beam, e)
             pipeCmd.moveToPyLi(beam, fp.Name)
         FreeCAD.activeDocument().commitTransaction()
     FreeCAD.activeDocument().recompute()
Exemplo n.º 9
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()
Exemplo n.º 10
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()
Exemplo n.º 11
0
 def getBase(self):
   if self.combo.currentText()!="<new>":                                           
     pl=FreeCAD.ActiveDocument.getObjectsByLabel(self.combo.currentText())[0]    
     sel=FreeCADGui.Selection.getSelection()
     if sel:
       base=sel[0]
       isWire=hasattr(base,'Shape') and type(base.Shape)==Part.Wire
       isSketch=hasattr(base,'TypeId') and base.TypeId=='Sketcher::SketchObject'
       if isWire or isSketch:
         FreeCAD.activeDocument().openTransaction('Assign Base')
         pl.Base=base
         if isWire:
           pipeCmd.drawAsCenterLine(pl.Base)
           pipeCmd.moveToPyLi(pl.Base,self.combo.currentText())
         FreeCAD.activeDocument().commitTransaction()
       else:
         FreeCAD.Console.PrintError('Not valid Base: select a Wire or a Sketch.\n')
     else:
       pl.Base=None
       FreeCAD.Console.PrintWarning(pl.Label+'-> deleted Base\n')
   else:
     FreeCAD.Console.PrintError('Please choose or create a PypeLine first\n')
Exemplo n.º 12
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()
Exemplo n.º 13
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()
Exemplo n.º 14
0
 def insert(self):
     from frameCmd import makeFrameLine, edges, placeTheBeam
     from pipeCmd import moveToPyLi
     if self.combo.currentText() == '<new>':
         n = self.edit1.text()
         if n:
             a = makeFrameLine(name=n)
         else:
             a = makeFrameLine()
         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 edges():
             if self.cb1.isChecked():
                 s = makeStructure(FreeCAD.ActiveDocument.copyObject(prof))
             else:
                 s = makeStructure(prof)
             placeTheBeam(s, e)
             moveToPyLi(s, self.current.Name)
         FreeCAD.ActiveDocument.recompute()
Exemplo n.º 15
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()
Exemplo n.º 16
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())
Exemplo n.º 17
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()