Пример #1
0
 def trim(self):
   FreeCAD.ActiveDocument.openTransaction('Trim FB')
   for target in self.targets:
     for b in frameCmd.beams():
       if hasattr(b,'tailOffset') and hasattr(b,'headOffset'):
         edge=b.Support[0][0].Shape.getElement(b.Support[0][1][0])
         ax=edge.tangentAt(0).normalize() #frameCmd.beamAx(b).normalize()
         tail=edge.valueAt(0) #b.Placement.Base
         head=edge.valueAt(edge.LastParameter) #tail+ax*float(b.Height)
         if target.ShapeType=="Vertex":
           P=target.Point
         elif target.ShapeType=="Face" and not frameCmd.isOrtho(target,ax):
           P=frameCmd.intersectionPlane(tail,ax,target)
         elif hasattr(target,"CenterOfMass"):
           P=target.CenterOfMass
         else: 
           P=None
         if P:
           #print P
           #print ax.Length
           deltaTail=(P-tail).dot(ax)
           deltaHead=(P-head).dot(ax)
           #print "D-tail = %.1f; D-head = %.1f" %(deltaTail,deltaHead)
           if abs(deltaTail)<abs(deltaHead):
             b.tailOffset=-deltaTail
           else:
             b.headOffset=deltaHead
   refresh()
   FreeCAD.ActiveDocument.commitTransaction()
Пример #2
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')
Пример #3
0
 def trim(self):
     FreeCAD.ActiveDocument.openTransaction('Trim FB')
     for target in self.targets:
         for b in frameCmd.beams():
             if hasattr(b, 'tailOffset') and hasattr(b, 'headOffset'):
                 edge = b.Support[0][0].Shape.getElement(b.Support[0][1][0])
                 ax = edge.tangentAt(
                     0).normalize()  #frameCmd.beamAx(b).normalize()
                 tail = edge.valueAt(0)  #b.Placement.Base
                 head = edge.valueAt(
                     edge.LastParameter)  #tail+ax*float(b.Height)
                 if target.ShapeType == "Vertex":
                     P = target.Point
                 elif target.ShapeType == "Face" and not frameCmd.isOrtho(
                         target, ax):
                     P = frameCmd.intersectionPlane(tail, ax, target)
                 elif hasattr(target, "CenterOfMass"):
                     P = target.CenterOfMass
                 else:
                     P = None
                 if P:
                     #print P
                     #print ax.Length
                     deltaTail = (P - tail).dot(ax)
                     deltaHead = (P - head).dot(ax)
                     #print "D-tail = %.1f; D-head = %.1f" %(deltaTail,deltaHead)
                     if abs(deltaTail) < abs(deltaHead):
                         b.tailOffset = -deltaTail
                     else:
                         b.headOffset = deltaHead
     refresh()
     FreeCAD.ActiveDocument.commitTransaction()
Пример #4
0
 def addSelection(self, doc, obj, sub, pnt):
     lastSel = FreeCAD.getDocument(doc).getObject(obj)
     subLastSel = lastSel.Shape.getElement(sub)
     if lastSel.TypeId == 'Part::FeaturePython' and hasattr(
             lastSel, "Height") and subLastSel.ShapeType == "Edge":
         self.edges.append(subLastSel)
         self.beams.append(lastSel)
         FreeCAD.Console.PrintMessage('Edge/beam pair nr.' +
                                      str(len(self.edges)) +
                                      '  selected.\n')
     if (len(self.edges) == len(self.beams) == 2):
         if frameCmd.isOrtho(*self.edges):
             self.beams.reverse()
             FreeCAD.ActiveDocument.openTransaction('Adjust angle')
             for i in range(len(self.edges)):
                 frameCmd.extendTheBeam(self.beams[i], self.edges[i])
             FreeCAD.ActiveDocument.commitTransaction()
             FreeCAD.Console.PrintWarning("Adjustment executed.\n")
         else:
             FreeCAD.Console.PrintError("Edges must be orthogonal.\n")
         self.edges = []
         self.beams = []
         FreeCADGui.Selection.clearSelection()
         FreeCAD.activeDocument().recompute()
         FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n")
Пример #5
0
 def addSelection(self,doc,obj,sub,pnt):
   lastSel=FreeCAD.getDocument(doc).getObject(obj)
   subLastSel=lastSel.Shape.getElement(sub)
   if lastSel.TypeId=='Part::FeaturePython' and hasattr(lastSel,"Height") and subLastSel.ShapeType=="Edge":
     self.edges.append(subLastSel)
     self.beams.append(lastSel)
     FreeCAD.Console.PrintMessage('Edge/beam pair nr.'+str(len(self.edges))+'  selected.\n')
   if (len(self.edges)==len(self.beams)==2):
     if frameCmd.isOrtho(*self.edges):
       self.beams.reverse()
       FreeCAD.ActiveDocument.openTransaction('Adjust angle')
       for i in range(len(self.edges)):
       	frameCmd.extendTheBeam(self.beams[i],self.edges[i])
       FreeCAD.ActiveDocument.commitTransaction()
       FreeCAD.Console.PrintWarning("Adjustment executed.\n")
     else:
       FreeCAD.Console.PrintError("Edges must be orthogonal.\n")
     self.edges=[]
     self.beams=[]
     FreeCADGui.Selection.clearSelection()
     FreeCAD.activeDocument().recompute()
     FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n")