Exemple #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():
     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)
Exemple #2
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)
Exemple #3
0
 def selectAction(self):
     if frameCmd.faces():
         a = [(o, frameCmd.faces([o])[0])
              for o in FreeCADGui.Selection.getSelectionEx()
              if frameCmd.faces([o])][0]
         self.faceRef = a[1]
         self.form.label.setText(a[0].Object.Label + ':Face')
         FreeCADGui.Selection.clearSelection()
Exemple #4
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 frameCmd.faces() if type(f.Surface) == Part.Plane
        ][0]
        pipe = [p for p in frameCmd.beams() if hasattr(p, 'OD')][0]
    try:
        if type(refFace.Surface) == Part.Plane and frameCmd.isOrtho(
                refFace, frameCmd.beamAx(pipe)) and hasattr(pipe, 'OD'):
            dist = rounded(
                refFace.normalAt(0, 0).multiply(
                    refFace.normalAt(0, 0).dot(pipe.Placement.Base -
                                               refFace.CenterOfMass) -
                    float(pipe.OD) / 2))
            if support:
                support.Placement.move(dist)
            else:
                pipe.Placement.move(dist.multiply(-1))
        else:
            FreeCAD.Console.PrintError(
                'Face is not flat or not parallel to axis of pipe\n')
    except:
        FreeCAD.Console.PrintError('Wrong selection\n')
Exemple #5
0
 def getReference(self):
   selex=FreeCADGui.Selection.getSelectionEx()
   for sx in selex:
     if sx.SubObjects:
       planes=[f for f in frameCmd.faces([sx]) if type(f.Surface)==Part.Plane]
       if len(planes)>0:
         self.refNorm=rounded(planes[0].normalAt(0,0))
         self.lab1.setText("ref. Face on "+sx.Object.Label)
Exemple #6
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()
Exemple #7
0
 def accept(self):
     faces = frameCmd.faces()
     beams = frameCmd.beams()
     if len(faces) == len(beams) > 0 and self.faceRef:
         FreeCAD.activeDocument().openTransaction('AlignFlange')
         for i in range(len(beams)):
             frameCmd.rotTheBeam(beams[i], self.faceRef, faces[i])
         FreeCAD.activeDocument().recompute()
         FreeCAD.activeDocument().commitTransaction()
Exemple #8
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)
Exemple #9
0
 def accept(self):
   faces=frameCmd.faces()
   objs=FreeCADGui.Selection.getSelection() #beams=frameCmd.beams()
   if len(faces)==len(objs)>0 and self.faceRef:
     FreeCAD.activeDocument().openTransaction('AlignFlange')
     for i in range(len(objs)):
       frameCmd.rotTheBeam(objs[i],self.faceRef,faces[i])
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
Exemple #10
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()
Exemple #11
0
 def Activated(self):
     import pipeCmd, frameCmd
     from Part import Plane
     refFace = [f for f in frameCmd.faces() if type(f.Surface) == Plane][0]
     FreeCAD.activeDocument().openTransaction('Lay-down the pipe')
     for b in frameCmd.beams():
         if pipeCmd.isPipe(b):
             pipeCmd.laydownTheTube(b, refFace)
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
Exemple #12
0
 def Activated (self):
   import pipeCmd, frameCmd
   from Part import Plane
   refFace=[f for f in frameCmd.faces() if type(f.Surface)==Plane][0]
   FreeCAD.activeDocument().openTransaction('Lay-down the pipe')
   for b in frameCmd.beams():
     if pipeCmd.isPipe(b):
       pipeCmd.laydownTheTube(b,refFace)
   FreeCAD.activeDocument().recompute()
   FreeCAD.activeDocument().commitTransaction()
Exemple #13
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()
 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()
Exemple #15
0
 def Activated (self):
   import pipeCmd, frameCmd
   from Part import Plane
   selex=FreeCADGui.Selection.getSelectionEx()
   for sx in selex:
     sxFaces=[f for f in frameCmd.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 frameCmd.beams():
     if pipeCmd.isPipe(b):
       pipeCmd.laydownTheTube(b,refFace,support)
       break
   FreeCAD.activeDocument().recompute()
   FreeCAD.activeDocument().commitTransaction()
Exemple #16
0
 def Activated (self):
   import pipeCmd, frameCmd
   from Part import Plane
   selex=FreeCADGui.Selection.getSelectionEx()
   for sx in selex:
     sxFaces=[f for f in frameCmd.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 frameCmd.beams():
     if pipeCmd.isPipe(b):
       pipeCmd.laydownTheTube(b,refFace,support)
       break
   FreeCAD.activeDocument().recompute()
   FreeCAD.activeDocument().commitTransaction()
Exemple #17
0
 def Activated(self):
   import FreeCAD, FreeCADGui, frameCmd, frameObservers
   selex=Gui.Selection.getSelectionEx()
   faces=frameCmd.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)):
       frameCmd.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=frameObservers.levelBeamObserver()
     FreeCADGui.Selection.addObserver(s)
 def Activated(self):
     import FreeCAD, FreeCADGui, frameCmd, frameObservers
     selex = Gui.Selection.getSelectionEx()
     faces = frameCmd.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)):
             frameCmd.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 = frameObservers.levelBeamObserver()
         FreeCADGui.Selection.addObserver(s)
Exemple #19
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"]
Exemple #20
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"]
Exemple #21
0
 def selectAction(self):
   if frameCmd.faces():
     a=[(o,frameCmd.faces([o])[0]) for o in FreeCADGui.Selection.getSelectionEx() if frameCmd.faces([o])][0]
     self.faceRef=a[1]
     self.form.label.setText(a[0].Object.Label+':Face')
     FreeCADGui.Selection.clearSelection()