コード例 #1
0
ファイル: Duplicate.py プロジェクト: DeepSOIC/Part-o-magic
def duplicateObjects(objects, top_objects, target_cnt):
    with Transaction("PoM Duplicate"):
        keeper = Observer.suspend()
        
        objset = set(objects)
        doc = objects[0].Document
        namelist = [obj.Name for obj in doc.TopologicalSortedObjects if obj in objset][::-1]
        
        tmp_prj = FCProject.fromFC(doc, namelist)
        map = tmp_prj.mergeToFC(doc)
        for obj in top_objects:
            new_top_obj = doc.getObject(map[obj.Name])
            Containers.addObjectTo(target_cnt, new_top_obj, b_advance_tip= True)
        keeper.release()
コード例 #2
0
ファイル: Duplicate.py プロジェクト: luzpaz/Part-o-magic
def duplicateObjects(objects, top_objects, target_cnt):
    with Transaction("PoM Duplicate"):
        keeper = Observer.suspend()

        objset = set(objects)
        doc = objects[0].Document
        namelist = [
            obj.Name for obj in doc.TopologicalSortedObjects if obj in objset
        ][::-1]

        tmp_prj = FCProject.fromFC(doc, namelist)
        map = tmp_prj.mergeToFC(doc)
        for obj in top_objects:
            new_top_obj = doc.getObject(map[obj.Name])
            Containers.addObjectTo(target_cnt, new_top_obj, b_advance_tip=True)
        keeper.release()
コード例 #3
0
def addObjectTo(container, feature):
    if hasattr(App, 'ActiveContainer'):
        # New FreeCAD. Feature is added to the container automatically. All that's left to do is call advanceTip().
        return container

    if container.isDerivedFrom("App::Document"):
        return container

    # close editing before addition.
    #  Adding to container while editing causes editing to close anyway. But we want do do
    #  that ourself, so that we know that we need to re-open it.
    bool_editingclosed = False
    if hasattr(Gui.ActiveDocument, "getInEdit"):
        if Gui.ActiveDocument.getInEdit():
            if Gui.ActiveDocument.getInEdit().Object is feature:
                Gui.ActiveDocument.resetEdit()
                bool_editingclosed = True

    #actual addition
    added = False
    actual_container = container
    while not added:
        try:
            GT.addObjectTo(actual_container, feature, b_advance_tip=False)
            added = True
        except App.Base.FreeCADError as err:
            #assuming it's a "not allowed" error
            #try adding to upper level container. Until Document is reached, which should never fail with FreeCADError
            actual_container = GT.getContainer(actual_container)
    if actual_container is not container:
        msgbox(
            "Part-o-magic",
            u"Cannot add the new object of type {typ} to '{container}'. Feature added to '{actual_container}' instead."
            .format(container=container.Label,
                    actual_container=actual_container.Label,
                    typ=feature.TypeId))

    # re-open editing that we had closed...
    if bool_editingclosed:
        Gui.ActiveDocument.setEdit(feature)

    return actual_container
コード例 #4
0
ファイル: Observer.py プロジェクト: DeepSOIC/Part-o-magic
def addObjectTo(container, feature):
    if hasattr(App, 'ActiveContainer'):
        # New FreeCAD. Feature is added to the container automatically. All that's left to do is call advanceTip().
        return container

    if container.isDerivedFrom("App::Document"):
        return container
    
    # close editing before addition.
    #  Adding to container while editing causes editing to close anyway. But we want do do 
    #  that ourself, so that we know that we need to re-open it.
    bool_editingclosed = False
    if hasattr(Gui.ActiveDocument,"getInEdit"):
        if Gui.ActiveDocument.getInEdit():
            if Gui.ActiveDocument.getInEdit().Object is feature:
                Gui.ActiveDocument.resetEdit()
                bool_editingclosed = True
    
    #actual addition
    added = False
    actual_container = container
    while not added:
        try:
            GT.addObjectTo(actual_container, feature, b_advance_tip = False)
            added = True
        except App.Base.FreeCADError as err:
            #assuming it's a "not allowed" error
            #try adding to upper level container. Until Document is reached, which should never fail with FreeCADError
            actual_container = GT.getContainer(actual_container)
    if actual_container is not container:
        msgbox("Part-o-magic",u"Cannot add the new object of type {typ} to '{container}'. Feature added to '{actual_container}' instead."
                              .format(container= container.Label, actual_container= actual_container.Label, typ= feature.TypeId))
        
    # re-open editing that we had closed...
    if bool_editingclosed:
        Gui.ActiveDocument.setEdit(feature)
    
    return actual_container