예제 #1
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
예제 #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
예제 #3
0
 def Activated (self):
   import frameCmd, pipeCmd
   if len(frameCmd.beams())>1:
     p1,p2=frameCmd.beams()[:2]
     try:
       P=frameCmd.intersectionCLines(p1,p2)
       com1=p1.Shape.Solids[0].CenterOfMass
       com2=p2.Shape.Solids[0].CenterOfMass
       v1=P-com1
       v2=com2-P
       curves=[e for e in FreeCADGui.Selection.getSelection() if hasattr(e,'PType') and hasattr(e,'BendAngle')]
       if curves:
         FreeCAD.ActiveDocument.openTransaction('Place one curve')
         pipeCmd.placeoTherElbow(curves[0],v1,v2,P)
         FreeCAD.ActiveDocument.recompute() # recompute for the elbow
         port1,port2=pipeCmd.portsPos(curves[0])
         if (com1-port1).Length<(com1-port2).Length:
           frameCmd.extendTheBeam(p1,port1)
           frameCmd.extendTheBeam(p2,port2)
         else:
           frameCmd.extendTheBeam(p1,port2)
           frameCmd.extendTheBeam(p2,port1)
         FreeCAD.ActiveDocument.recompute() # recompute for the pipes
         FreeCAD.ActiveDocument.commitTransaction()
       else:
         FreeCAD.Console.PrintError('Select at least one elbow')
     except:
       FreeCAD.Console.PrintError('Intersection point not found\n')
   else:
     FreeCAD.Console.PrintError('Select two intersecting pipes\n')
예제 #4
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
예제 #5
0
 def Activated(self):
     import frameCmd, pipeCmd
     if len(frameCmd.beams()) > 1:
         p1, p2 = frameCmd.beams()[:2]
         try:
             P = frameCmd.intersectionCLines(p1, p2)
             com1 = p1.Shape.Solids[0].CenterOfMass
             com2 = p2.Shape.Solids[0].CenterOfMass
             v1 = P - com1
             v2 = com2 - P
             curves = [
                 e for e in FreeCADGui.Selection.getSelection()
                 if hasattr(e, 'PType') and hasattr(e, 'BendAngle')
             ]
             if curves:
                 FreeCAD.ActiveDocument.openTransaction('Place one curve')
                 pipeCmd.placeoTherElbow(curves[0], v1, v2, P)
                 FreeCAD.ActiveDocument.recompute(
                 )  # recompute for the elbow
                 port1, port2 = pipeCmd.portsPos(curves[0])
                 if (com1 - port1).Length < (com1 - port2).Length:
                     frameCmd.extendTheBeam(p1, port1)
                     frameCmd.extendTheBeam(p2, port2)
                 else:
                     frameCmd.extendTheBeam(p1, port2)
                     frameCmd.extendTheBeam(p2, port1)
                 FreeCAD.ActiveDocument.recompute(
                 )  # recompute for the pipes
                 FreeCAD.ActiveDocument.commitTransaction()
             else:
                 FreeCAD.Console.PrintError('Select at least one elbow')
         except:
             FreeCAD.Console.PrintError('Intersection point not found\n')
     else:
         FreeCAD.Console.PrintError('Select two intersecting pipes\n')
예제 #6
0
def flattenTheTube(obj=None, v1=None, v2=None, X=None):
    '''
  flattenTheTube(obj=None,v1=None,v2=None, X=None)
  Put obj in the same plane defined by vectors v1 and v2 and move it to X.
    obj: the object to be rotated
    v1, v2: the vectors of the plane
    X: the Placement.Base
  If no parameter is defined: v1, v2 are the axis of the first two beams 
  in the selections set, X is their intersection and obj is the first other
  object in the selection set. 
  '''
    if None in [obj, v1, v2]:
        try:
            sel = FreeCADGui.Selection.getSelection()
            t1, t2 = frameCmd.beams()[:2]
            v1 = frameCmd.beamAx(t1)
            v2 = frameCmd.beamAx(t2)
            sel.remove(t1)
            sel.remove(t2)
            obj = sel[0]
            X = frameCmd.intersectionCLines(t1, t2)
        except:
            FreeCAD.Console.PrintError('Not enough arguments\n')
            return
    obj.Placement.Rotation = FreeCAD.Rotation(
        frameCmd.beamAx(obj), v1.cross(v2)).multiply(obj.Placement.Rotation)
    obj.Placement.Base = X
예제 #7
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
예제 #8
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
예제 #9
0
def extendTheTubes2intersection(pipe1=None,pipe2=None,both=True):
  '''
  Does what it says; also with beams.
  If arguments are None, it picks the first 2 selected beams().
  '''
  if not (pipe1 and pipe2):
    try:
      pipe1,pipe2=frameCmd.beams()[:2]
    except:
      FreeCAD.Console.PrintError('Insufficient arguments for extendTheTubes2intersection\n')
  P=frameCmd.intersectionCLines(pipe1,pipe2)
  if P!=None:
    frameCmd.extendTheBeam(pipe1,P)
    if both:
      frameCmd.extendTheBeam(pipe2,P)
예제 #10
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()
예제 #11
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()