def substituteobj(oldobj, newobj):
    '''Replaces all links to oldobj in the document with links to newobj.
    Returns a tuple (list_replaced, list_not_replaced)'''
    deps_of_new = getAllDependencies(newobj) + [newobj]
    list_not_replaced = []
    list_replaced = []
    for dep in oldobj.InList:
        if dep in deps_of_new:
            #we are about to make an object newobj depends on, to depend on newobj.
            #This will create a circular graph, so we must skip this.
            print "not replacing " + oldobj.Name + " with " + newobj.Name + " in " + dep.Name
            list_not_replaced.append(dep)
        else:
            print "replacing " + oldobj.Name + " with " + newobj.Name + " in " + dep.Name
            list_replaced.append(dep)
            replaceobj(dep, oldobj, newobj)
    return (list_replaced, list_not_replaced)
def substituteobj(oldobj, newobj):
    '''Replaces all links to oldobj in the document with links to newobj.
    Returns a tuple (list_replaced, list_not_replaced)'''
    deps_of_new = getAllDependencies(newobj) + [newobj]
    list_not_replaced = []
    list_replaced = []
    for dep in oldobj.InList:
        if dep in deps_of_new:
            #we are about to make an object newobj depends on, to depend on newobj. 
            #This will create a circular graph, so we must skip this.
            print "not replacing "+oldobj.Name+" with " + newobj.Name +" in " + dep.Name
            list_not_replaced.append(dep)
        else:
            print "replacing "+oldobj.Name+" with " + newobj.Name +" in " + dep.Name
            list_replaced.append(dep)
            replaceobj(dep, oldobj, newobj)
    return (list_replaced, list_not_replaced)
Example #3
0
def expandplacementsmatrix(obj, matrix):
    '''expand afine transformation down the feature tree'''
    ownmatrix = matrix.multiply(obj.Placement.toMatrix())
    if obj.isDerivedFrom('Part::Feature') and \
        isinstance(obj.Proxy,MatrixTransform):
        innermatrix = ownmatrix.multiply(obj.Matrix)
        if likeprimitive(obj.Base, True):  #this matrix is needed
            obj.Placement = FreeCAD.Placement()
            obj.Matrix = innermatrix
        else:  #the inner object is not a primitive
            expandplacementsmatrix(obj.Base, innermatrix)
            #remove the matrix object
            for parent in obj.Base.InList:
                replaceobj.replaceobj(parent, obj, obj.Base)
            out.Document.removeObject(obj.Name)
    elif likeprimitive(obj, True):
        #if isspecialorthogonalpython(fcsubmatrix(ownmatrix)):
        if isspecialorthogonal(ownmatrix):
            obj.Placement = FreeCAD.Placement()
            #this should never happen unless matrices cancel out
            obj.Placement = FreeCAD.Placement(ownmatrix)
        else:
            newobj = doc.addObject("Part::FeaturePython", 'exp_trans')
            MatrixTransform(newobj, ownmatrix,
                            obj)  #This object is not mutable GUI
            ViewProviderTree(newobj.ViewObject)
            for parent in obj.InList:
                replaceobj.replaceobj(
                    parent, obj,
                    newobj)  # register the new object in the feature tree
            obj.Placement = FreeCAD.Placement()
    else:  #not a primitive
        for outobj in obj.OutList:
            if outobj.isDerivedFrom('Part::Feature') and \
                    isinstance(obj.Proxy,MatrixTransform):
                newmatrix = ownmatrix.multiply(obj.Matrix).multiply(\
                            outobj.Base.Placement.toMatrix())
                if likeprimitive(outobj.Base,
                                 True):  #child of is like primtitive
                    outobj.Matrix = newmatrix
                    outobj.Base.Placement = FreeCAD.Placement()
                else:  #remove the MatrixTransformation
                    plainobj = outobj.Base
                    for parent in outobj.InList:
                        replaceobj.replaceobj(parent, outobj, plainobj)
                    outobj.Document.removeObject(outobj.Name)
                    expandplacementsmatrix(outobj, newmatrix)
            else:
                expandplacementsmatrix(outobj, ownmatrix)
        obj.Placement = FreeCAD.Placement()
def expandplacementsmatrix(obj,matrix):
    '''expand afine transformation down the feature tree'''
    ownmatrix=matrix.multiply(obj.Placement.toMatrix())
    if obj.isDerivedFrom('Part::Feature') and \
        isinstance(obj.Proxy,MatrixTransform):
        innermatrix=ownmatrix.multiply(obj.Matrix)
        if likeprimitive(obj.Base,True): #this matrix is needed
            obj.Placement=FreeCAD.Placement()
            obj.Matrix = innermatrix
        else: #the inner object is not a primitive
            expandplacementsmatrix(obj.Base,innermatrix)
            #remove the matrix object
            for parent in obj.Base.InList:
                replaceobj.replaceobj(parent,obj,obj.Base)
            out.Document.removeObject(obj.Name)
    elif likeprimitive(obj,True):
        #if isspecialorthogonalpython(fcsubmatrix(ownmatrix)):
        if isspecialorthogonal(ownmatrix):
            obj.Placement=FreeCAD.Placement()
            #this should never happen unless matrices cancel out
            obj.Placement=FreeCAD.Placement(ownmatrix)
        else:
            newobj=doc.addObject("Part::FeaturePython",'exp_trans')
            MatrixTransform(newobj,ownmatrix,obj) #This object is not mutable GUI
            ViewProviderTree(newobj.ViewObject)
            for parent in obj.InList:
                replaceobj.replaceobj(parent,obj,newobj) # register the new object in the feature tree
            obj.Placement=FreeCAD.Placement()
    else: #not a primitive
        for outobj in obj.OutList:
            if outobj.isDerivedFrom('Part::Feature') and \
                    isinstance(obj.Proxy,MatrixTransform):
                newmatrix = ownmatrix.multiply(obj.Matrix).multiply(\
                            outobj.Base.Placement.toMatrix())
                if likeprimitive(outobj.Base,True): #child of is like primtitive
                    outobj.Matrix = newmatrix
                    outobj.Base.Placement=FreeCAD.Placement()
                else: #remove the MatrixTransformation
                    plainobj=outobj.Base
                    for parent in outobj.InList:
                        replaceobj.replaceobj(parent,outobj,plainobj)
                    outobj.Document.removeObject(outobj.Name)
                    expandplacementsmatrix(outobj,newmatrix)
            else:
                expandplacementsmatrix(outobj,ownmatrix)
        obj.Placement=FreeCAD.Placement()