Пример #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 fCmd.faces():
     direct=fCmd.faces()[0].normalAt(0,0)
   elif fCmd.edges():
     direct=fCmd.edges()[0].tangentAt(0)
   # 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,self.form.edit2,pl=pl,direct=direct,M=M,objs=self.objs)
Пример #2
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 fCmd.faces():
     Z=FreeCAD.Vector(0,0,1)
     for f in fCmd.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())
   elif fCmd.edges():
     for e in fCmd.edges():
       beam=makeStructure(profile)
       fCmd.placeTheBeam(beam,e)
       if self.form.editLength.text(): beam.Height=float(self.form.editLength.text())
   elif [v for sx in FreeCADGui.Selection.getSelectionEx() for so in sx.SubObjects for v in so.Vertexes]:
     vs=[v for sx in FreeCADGui.Selection.getSelectionEx() for so in sx.SubObjects for v in so.Vertexes]
     for v in vs:
       beam=makeStructure(profile)
       beam.Placement.Base=v.Point
   else:
     beam=makeStructure(profile)
     if self.form.editLength.text(): beam.Height=float(self.form.editLength.text())
   FreeCAD.ActiveDocument.recompute()
Пример #3
0
 def selectAction(self):
     if fCmd.faces():
         a = [(o, fCmd.faces([o])[0])
              for o in FreeCADGui.Selection.getSelectionEx()
              if fCmd.faces([o])][0]
         self.faceRef = a[1]
         self.form.label.setText(a[0].Object.Label + ':Face')
         FreeCADGui.Selection.clearSelection()
Пример #4
0
def doPipes(propList=['DN50',60.3,3,1000], pypeline=None):
  '''
    propList = [
      DN (string): nominal diameter
      OD (float): outside diameter
      thk (float): shell thickness
      H (float): length of pipe ]
    pypeline = string
  '''
  FreeCAD.activeDocument().openTransaction('Insert pipe')
  plist=list()
  if len(fCmd.edges())==0: #..no edges selected
    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
      plist.append(makePipe(propList))
    else: # ... one or more vertexes
      for v in vs: plist.append(makePipe(propList,v.Point))
  else:
    selex=FreeCADGui.Selection.getSelectionEx()
    for objex in selex:
      o=objex.Object
      if fCmd.faces(): # Face selected...
        for face in fCmd.faces():
          x=(face.ParameterRange[0]+face.ParameterRange[1])/2
          y=(face.ParameterRange[2]+face.ParameterRange[3])/2
          plist.append(makePipe(propList,face.valueAt(x,y),face.normalAt(x,y)))
        FreeCAD.activeDocument().commitTransaction()
        FreeCAD.activeDocument().recompute()
      else:
        for edge in fCmd.edges([objex]): # ...one or more edges...
          if edge.curvatureAt(0)==0: # ...straight edges
            pL=propList
            pL[3]=edge.Length
            plist.append(makePipe(pL,edge.valueAt(0),edge.tangentAt(0)))
          else: # ...curved edges
            pos=edge.centerOfCurvatureAt(0)
            Z=edge.tangentAt(0).cross(edge.normalAt(0))
            if isElbow(o):
              p0,p1=[o.Placement.Rotation.multVec(p) for p in o.Ports]
              if not fCmd.isParallel(Z,p0):
                Z=p1
            plist.append(makePipe(propList,pos,Z))
  if pypeline:
    for p in plist:
      moveToPyLi(p,pypeline)
  FreeCAD.activeDocument().commitTransaction()
  FreeCAD.activeDocument().recompute()
  return plist
Пример #5
0
def setWP():  #TARGET [working]: deal with App::Parts
    'function to change working plane'
    import FreeCAD, FreeCADGui, fCmd
    normal = point = None
    curves = []
    straight = []
    Z = FreeCAD.Vector(0, 0, 1)
    for edge in fCmd.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 fCmd.faces():
        normal = fCmd.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 fCmd.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 = fCmd.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()
Пример #6
0
 def accept(self):
   faces=fCmd.faces()
   objs=FreeCADGui.Selection.getSelection() #beams=fCmd.beams()
   if len(faces)==len(objs)>0 and self.faceRef:
     FreeCAD.activeDocument().openTransaction('AlignFlange')
     for i in range(len(objs)):
       fCmd.rotTheBeam(objs[i],self.faceRef,faces[i])
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
Пример #7
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()
Пример #8
0
def makeRoute(n=Z):
  curvedEdges=[e for e in fCmd.edges() if e.curvatureAt(0)!=0]
  if curvedEdges:
    s=FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject',translate("Sketcher::SketchObject",'pipeRoute'))
    s.MapMode = "SectionOfRevolution"
    sup=fCmd.edgeName()
    s.Support = [sup]
    if fCmd.isPartOfPart(sup[0]): #TARGET [working]: takes care if support belongs to App::Part
      part=fCmd.isPartOfPart(sup[0])
      FreeCAD.Console.PrintMessage('*** '+sup[0].Label+' is part of '+part.Label+' ***\n') #debug
      #s.AttachmentOffset=part.Placement.multiply(s.AttachmentOffset)
  else:
    return None
  if fCmd.faces():
    n=fCmd.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)
Пример #9
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()
Пример #10
0
 def Activated(self):
   import FreeCAD, FreeCADGui, fCmd, fObservers
   selex=Gui.Selection.getSelectionEx()
   faces=fCmd.faces(selex)
   beams=[sx.Object for sx in selex]
   if len(faces)==len(beams)>1:
     FreeCAD.activeDocument().openTransaction('LevelTheBeams')
     beams.pop(0)
     fBase=faces.pop(0)
     for i in range(len(beams)):
       fCmd.levelTheBeam(beams[i],[fBase,faces[i]])
     FreeCAD.activeDocument().commitTransaction()
   elif len(faces)!=len(beams):
     FreeCAD.Console.PrintError('Select only one face for each beam.\n')
   else:
     FreeCADGui.Selection.clearSelection()
     s=fObservers.levelBeamObserver()
     FreeCADGui.Selection.addObserver(s)
Пример #11
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')
Пример #12
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 fCmd.edges() if e.curvatureAt(0) != 0]
         faces = fCmd.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"]