Ejemplo n.º 1
0
def p_multmatrix_action(p):
    'multmatrix_action : multmatrix LPAREN matrix RPAREN OBRACE block_list EBRACE'
    if printverbose: print "MultMatrix"
    transform_matrix = FreeCAD.Matrix()
    if printverbose: print "Multmatrix"
    if printverbose: print p[3]
    m1l = sum(p[3], [])
    if any('x' in me for me in m1l):  #hexfloats
        m1l = [float.fromhex(me) for me in m1l]
        matrixisrounded = False
    elif max((len(me) for me in m1l)) >= 14:  #might have double precision
        m1l = [float(me) for me in m1l]  # assume precise output
        m1l = [(0 if (abs(me) < 1e-15) else me) for me in m1l]
        matrixisrounded = False
    else:  #trucanted numbers
        m1l = [round(float(me), 12) for me in m1l]  #round
        matrixisrounded = True
    transform_matrix = FreeCAD.Matrix(*tuple(m1l))
    if printverbose: print transform_matrix
    if printverbose: print "Apply Multmatrix"
    #   If more than one object on the stack for multmatrix fuse first
    if (len(p[6]) == 0):
        part = placeholder('group', [], '{}')
    elif (len(p[6]) > 1):
        part = fuse(p[6], "Matrix Union")
    else:
        part = p[6][0]
    if (isspecialorthogonalpython(fcsubmatrix(transform_matrix))):
        if printverbose: print "special orthogonal"
        if matrixisrounded:
            if printverbose: print "rotation rounded"
            plm = FreeCAD.Placement(transform_matrix)
            plm = FreeCAD.Placement(plm.Base, roundrotation(plm.Rotation))
            part.Placement = plm.multiply(part.Placement)
        else:
            part.Placement=FreeCAD.Placement(transform_matrix).multiply(\
                    part.Placement)
        new_part = part
    elif isrotoinversionpython(fcsubmatrix(transform_matrix)):
        if printverbose: print "orthogonal and inversion"
        cmat, axisvec = decomposerotoinversion(transform_matrix)
        new_part = doc.addObject("Part::Mirroring", 'mirr_%s' % part.Name)
        new_part.Source = part
        new_part.Normal = axisvec
        if matrixisrounded:
            if printverbose: print "rotation rounded"
            plm = FreeCAD.Placement(cmat)
            new_part.Placement = FreeCAD.Placement(plm.Base,
                                                   roundrotation(plm.Rotation))
        else:
            new_part.Placement = FreeCAD.Placement(cmat)
        new_part.Label = "mirrored %s" % part.Label
        if gui:
            part.ViewObject.hide()
    elif FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
        GetBool('useMultmatrixFeature'):
        from OpenSCADFeatures import MatrixTransform
        new_part = doc.addObject("Part::FeaturePython", 'Matrix Deformation')
        MatrixTransform(new_part, transform_matrix, part)
        if gui:
            if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
                GetBool('useViewProviderTree'):
                from OpenSCADFeatures import ViewProviderTree
                ViewProviderTree(new_part.ViewObject)
            else:
                new_part.ViewObject.Proxy = 0
            part.ViewObject.hide()
    else:
        if printverbose: print "Transform Geometry"
        #       Need to recompute to stop transformGeometry causing a crash
        doc.recompute()
        new_part = doc.addObject("Part::Feature", "Matrix Deformation")
        #  new_part.Shape = part.Base.Shape.transformGeometry(transform_matrix)
        new_part.Shape = part.Shape.transformGeometry(transform_matrix)
        if gui:
            part.ViewObject.hide()
    if False:
        #   Does not fix problemfile or beltTighener although later is closer
        newobj = doc.addObject("Part::FeaturePython", 'RefineMultMatrix')
        RefineShape(newobj, new_part)
        if gui:
            newobj.ViewObject.Proxy = 0
            new_part.ViewObject.hide()
        p[0] = [newobj]
    else:
        p[0] = [new_part]
    if printverbose: print "Multmatrix applied"