Пример #1
0
def removeShape(objs, mark=True):
    """takes an arch object (wall or structure) built on a cubic shape, and removes
    the inner shape, keeping its length, width and height as parameters."""
    import DraftGeomUtils

    if not isinstance(objs, list):
        objs = [objs]
    for obj in objs:
        if DraftGeomUtils.isCubic(obj.Shape):
            dims = DraftGeomUtils.getCubicDimensions(obj.Shape)
            if dims:
                name = obj.Name
                tp = Draft.getType(obj)
                print tp
                if tp == "Structure":
                    FreeCAD.ActiveDocument.removeObject(name)
                    import ArchStructure

                    str = ArchStructure.makeStructure(length=dims[1], width=dims[2], height=dims[3], name=name)
                    str.Placement = dims[0]
                elif tp == "Wall":
                    FreeCAD.ActiveDocument.removeObject(name)
                    import ArchWall

                    length = dims[1]
                    width = dims[2]
                    v1 = Vector(length / 2, 0, 0)
                    v2 = v1.negative()
                    v1 = dims[0].multVec(v1)
                    v2 = dims[0].multVec(v2)
                    line = Draft.makeLine(v1, v2)
                    wal = ArchWall.makeWall(line, width=width, height=dims[3], name=name)
        else:
            if mark:
                obj.ViewObject.ShapeColor = (1.0, 0.0, 0.0, 1.0)
Пример #2
0
def removeShape(objs,mark=True):
    '''takes an arch object (wall or structure) built on a cubic shape, and removes
    the inner shape, keeping its length, width and height as parameters.'''
    import DraftGeomUtils
    if not isinstance(objs,list):
        objs = [objs]
    for obj in objs:
        if DraftGeomUtils.isCubic(obj.Shape):
            dims = DraftGeomUtils.getCubicDimensions(obj.Shape)
            if dims:
                name = obj.Name
                tp = Draft.getType(obj)
                print tp
                if tp == "Structure":
                    FreeCAD.ActiveDocument.removeObject(name)
                    import ArchStructure
                    str = ArchStructure.makeStructure(length=dims[1],width=dims[2],height=dims[3],name=name)
                    str.Placement = dims[0]
                elif tp == "Wall":
                    FreeCAD.ActiveDocument.removeObject(name)
                    import ArchWall
                    length = dims[1]
                    width = dims[2]
                    v1 = Vector(length/2,0,0)
                    v2 = v1.negative()
                    v1 = dims[0].multVec(v1)
                    v2 = dims[0].multVec(v2)
                    line = Draft.makeLine(v1,v2)
                    wal = ArchWall.makeWall(line,width=width,height=dims[3],name=name)
        else:
            if mark:
                obj.ViewObject.ShapeColor = (1.0,0.0,0.0,1.0)
Пример #3
0
    def processSubShapes(self, obj, base):
        "Adds additions and subtractions to a base shape"
        import Draft

        # treat additions
        for o in obj.Additions:

            if base:
                if base.isNull():
                    base = None

            # special case, both walls with coinciding endpoints
            import ArchWall
            js = ArchWall.mergeShapes(o, obj)
            if js:
                add = js.cut(base)
                base = base.fuse(add)

            elif (Draft.getType(o) == "Window") or (Draft.isClone(o,
                                                                  "Window")):
                f = o.Proxy.getSubVolume(o)
                if f:
                    if base.Solids and f.Solids:
                        base = base.cut(f)

            elif o.isDerivedFrom("Part::Feature"):
                if o.Shape:
                    if not o.Shape.isNull():
                        if o.Shape.Solids:
                            if base:
                                if base.Solids:
                                    base = base.fuse(o.Shape)
                            else:
                                base = o.Shape

        # treat subtractions
        for o in obj.Subtractions:

            if base:
                if base.isNull():
                    base = None

            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(
                        o, "Window")):
                    # windows can be additions or subtractions, treated the same way
                    f = o.Proxy.getSubVolume(o)
                    if f:
                        if base.Solids and f.Solids:
                            base = base.cut(f)

                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                base = base.cut(o.Shape)
        return base
    def processSubShapes(self,obj,base):
        "Adds additions and subtractions to a base shape"
        import Draft

        # treat additions
        for o in obj.Additions:
            
            if base:
                if base.isNull():
                    base = None
                    
            # special case, both walls with coinciding endpoints
            import ArchWall
            js = ArchWall.mergeShapes(o,obj)
            if js:
                add = js.cut(base)
                base = base.fuse(add)

            elif (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                f = o.Proxy.getSubVolume(o)
                if f:
                    if base.Solids and f.Solids:
                        base = base.cut(f)
                        
            elif o.isDerivedFrom("Part::Feature"):
                if o.Shape:
                    if not o.Shape.isNull():
                        if o.Shape.Solids:
                            if base:
                                if base.Solids:
                                    base = base.fuse(o.Shape)
                            else:
                                base = o.Shape
        
        # treat subtractions
        for o in obj.Subtractions:
            
            if base:
                if base.isNull():
                    base = None
            
            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                        # windows can be additions or subtractions, treated the same way
                        f = o.Proxy.getSubVolume(o)
                        if f:
                            if base.Solids and f.Solids:
                                base = base.cut(f)
                            
                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                    base = base.cut(o.Shape)
        return base
Пример #5
0
 def create_wall(self):
     sel = Gui.Selection.getSelection()
     slabs = []
     for s in sel:
         if (hasattr(s, "Proxy") and hasattr(s.Proxy, "Type")
                 and s.Proxy.Type == "Beam"):
             slabs.append(s)
     if not slabs:
         return None
     weight = self.form.weight.value()
     height = self.form.height_box.value()
     create_blocks = self.form.create_blocks.isChecked()
     loadpat = self.form.loadpat.currentText()
     mat = FreeCAD.ActiveDocument.findObjects(
         Type='App::MaterialObjectPython')
     if not mat:
         import Arch
         mat = Arch.makeMaterial('Bricks')
         mat.Color = (0.89, .89, 0.)
     else:
         mat = mat[0]
     for s in slabs:
         wall = ArchWall.makeWall(baseobj=s, height=height * 1000)
         wall.addProperty('App::PropertyInteger', 'weight', 'Wall')
         wall.addProperty('App::PropertyString', 'loadpat', 'Wall')
         wall.loadpat = loadpat
         wall.weight = weight
         wall.Base.ViewObject.Visibility = True
         wall.Material = mat
         wall.Width = 300
         if create_blocks:
             wall.MakeBlocks = True
             wall.BlockHeight = 400
             wall.BlockLength = 800
             wall.OffsetSecond = 400
             wall.Joint = 40
             wall.ViewObject.DisplayMode = 'Flat Lines'
             wall.ViewObject.LineWidth = 1
         else:
             wall.ViewObject.DisplayMode = 'Shaded'
             wall.ViewObject.Transparency = 60
     FreeCAD.ActiveDocument.recompute()
Пример #6
0
    def processSubShapes(self, obj, base, placement=None):
        "Adds additions and subtractions to a base shape"
        import Draft, Part
        #print "Processing subshapes of ",obj.Label, " : ",obj.Additions

        if placement:
            if placement.isNull():
                placement = None
            else:
                placement = FreeCAD.Placement(placement)
                placement = placement.inverse()

        # treat additions
        for o in obj.Additions:

            if not base:
                if o.isDerivedFrom("Part::Feature"):
                    base = o.Shape
            else:
                if base.isNull():
                    if o.isDerivedFrom("Part::Feature"):
                        base = o.Shape
                else:
                    # special case, both walls with coinciding endpoints
                    import ArchWall
                    js = ArchWall.mergeShapes(o, obj)
                    if js:
                        add = js.cut(base)
                        if placement:
                            add.Placement = add.Placement.multiply(placement)
                        base = base.fuse(add)

                    elif (Draft.getType(o) == "Window") or (Draft.isClone(
                            o, "Window", True)):
                        if hasattr(o.Proxy, "getSubVolume"):
                            f = o.Proxy.getSubVolume(o)
                            if f:
                                if base.Solids and f.Solids:
                                    if placement:
                                        f.Placement = f.Placement.multiply(
                                            placement)
                                    base = base.cut(f)

                    elif o.isDerivedFrom("Part::Feature"):
                        if o.Shape:
                            if not o.Shape.isNull():
                                if o.Shape.Solids:
                                    s = o.Shape.copy()
                                    if placement:
                                        s.Placement = s.Placement.multiply(
                                            placement)
                                    if base:
                                        if base.Solids:
                                            try:
                                                base = base.fuse(s)
                                            except Part.OCCError:
                                                print "Arch: unable to fuse object ", obj.Name, " with ", o.Name
                                    else:
                                        base = s

        # treat subtractions
        for o in obj.Subtractions:

            if base:
                if base.isNull():
                    base = None

            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(
                        o, "Window", True)):
                    # windows can be additions or subtractions, treated the same way
                    f = o.Proxy.getSubVolume(o)
                    if f:
                        if base.Solids and f.Solids:
                            if placement:
                                f.Placement = f.Placement.multiply(placement)
                            base = base.cut(f)

                elif (Draft.getType(o) == "Roof") or (Draft.isClone(o,
                                                                    "Roof")):
                    # roofs define their own special subtraction volume
                    f = o.Proxy.getSubVolume(o)
                    if f:
                        if base.Solids and f.Solids:
                            base = base.cut(f)

                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                s = o.Shape.copy()
                                if placement:
                                    s.Placement = s.Placement.multiply(
                                        placement)
                                try:
                                    base = base.cut(s)
                                except Part.OCCError:
                                    print "Arch: unable to cut object ", o.Name, " from ", obj.Name
        return base
    def processSubShapes(self,obj,base,placement=None):
        "Adds additions and subtractions to a base shape"
        import Draft,Part
        #print "Processing subshapes of ",obj.Label, " : ",obj.Additions
        
        if placement:
            if placement.isNull():
                placement = None
            else:
                placement = FreeCAD.Placement(placement)
                placement = placement.inverse()

        # treat additions
        for o in obj.Additions:
            
            if not base:
                if o.isDerivedFrom("Part::Feature"):
                    base = o.Shape
            else:             
                if base.isNull():
                    if o.isDerivedFrom("Part::Feature"):
                        base = o.Shape
                else:  
                    # special case, both walls with coinciding endpoints
                    import ArchWall
                    js = ArchWall.mergeShapes(o,obj)
                    if js:
                        add = js.cut(base)
                        if placement:
                            add.Placement = add.Placement.multiply(placement)
                        base = base.fuse(add)

                    elif (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                        f = o.Proxy.getSubVolume(o)
                        if f:
                            if base.Solids and f.Solids:
                                if placemen:
                                    f.Placement = f.Placement.multiply(placement)
                                base = base.cut(f)
                                
                    elif o.isDerivedFrom("Part::Feature"):
                        if o.Shape:
                            if not o.Shape.isNull():
                                if o.Shape.Solids:
                                    s = o.Shape.copy()
                                    if placement:
                                        s.Placement = s.Placement.multiply(placement)
                                    if base:
                                        if base.Solids:
                                            try:
                                                base = base.fuse(s)
                                            except:
                                                print "Arch: unable to fuse object ",obj.Name, " with ", o.Name
                                    else:
                                        base = s
        
        # treat subtractions
        for o in obj.Subtractions:
            
            if base:
                if base.isNull():
                    base = None
            
            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                        # windows can be additions or subtractions, treated the same way
                        f = o.Proxy.getSubVolume(o)
                        if f:
                            if base.Solids and f.Solids:
                                if placement:
                                    f.Placement = f.Placement.multiply(placement)
                                base = base.cut(f)

                elif (Draft.getType(o) == "Roof") or (Draft.isClone(o,"Roof")):
                    # roofs define their own special subtraction volume
                    f = o.Proxy.getSubVolume(o)
                    if f:
                        if base.Solids and f.Solids:
                            base = base.cut(f)
                            
                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                    s = o.Shape.copy()
                                    if placement:
                                        s.Placement = s.Placement.multiply(placement)
                                    try:
                                        base = base.cut(s)
                                    except:
                                        print "Arch: unable to cut object ",o.Name, " from ", obj.Name
        return base
Пример #8
0
    def processSubShapes(self,obj,base,pl=None):
        "Adds additions and subtractions to a base shape"
        import Draft
        
        if pl:
            if pl.isNull():
                pl = None
            else:
                pl = FreeCAD.Placement(pl)
                pl = pl.inverse()

        # treat additions
        for o in obj.Additions:
            
            if base:
                if base.isNull():
                    base = None
                    
            # special case, both walls with coinciding endpoints
            import ArchWall
            js = ArchWall.mergeShapes(o,obj)
            if js:
                add = js.cut(base)
                if pl:
                    add.Placement = add.Placement.multiply(pl)
                base = base.fuse(add)

            elif (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                f = o.Proxy.getSubVolume(o)
                if f:
                    if base.Solids and f.Solids:
                        if pl:
                            f.Placement = f.Placement.multiply(pl)
                        base = base.cut(f)
                        
            elif o.isDerivedFrom("Part::Feature"):
                if o.Shape:
                    if not o.Shape.isNull():
                        if o.Shape.Solids:
                            s = o.Shape.copy()
                            if pl:
                                s.Placement = s.Placement.multiply(pl)
                            if base:
                                if base.Solids:
                                    base = base.fuse(s)
                            else:
                                base = s
        
        # treat subtractions
        for o in obj.Subtractions:
            
            if base:
                if base.isNull():
                    base = None
            
            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                        # windows can be additions or subtractions, treated the same way
                        f = o.Proxy.getSubVolume(o)
                        if f:
                            if base.Solids and f.Solids:
                                if pl:
                                    f.Placement = f.Placement.multiply(pl)
                                base = base.cut(f)
                            
                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                    s = o.Shape.copy()
                                    if pl:
                                        s.Placement = s.Placement.multiply(pl)
                                    base = base.cut(s)
        return base
    def processSubShapes(self,obj,base):
        "Adds additions and subtractions to a base shape"
        import Draft

        # treat additions
        for o in obj.Additions:
            
            if base:
                if base.isNull():
                    base = None
                    
            # special case, both walls with coinciding endpoints
            import ArchWall
            js = ArchWall.mergeShapes(o,obj)
            if js:
                add = js.cut(base)
                base = base.fuse(add)

            elif (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                if base:
                    # windows can be additions or subtractions, treated the same way
                    if hasattr(self,"Width"):
                        width = self.Width
                    else:
                        b = base.BoundBox
                        width = max(b.XLength,b.YLength,b.ZLength)
                    if Draft.isClone(o,"Window"):
                        window = o.Objects[0]
                    else:
                        window = o
                    if window.Base and width:
                        f = self.getSubVolume(window.Base,width)
                        if f:
                            if base.Solids and f.Solids:
                                base = base.cut(f)
                        
            elif o.isDerivedFrom("Part::Feature"):
                if o.Shape:
                    if not o.Shape.isNull():
                        if o.Shape.Solids:
                            if base:
                                if base.Solids:
                                    base = base.fuse(o.Shape)
                            else:
                                base = o.Shape
        
        # treat subtractions
        for o in obj.Subtractions:
            
            if base:
                if base.isNull():
                    base = None
            
            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window")):
                        # windows can be additions or subtractions, treated the same way
                        if hasattr(self,"Width"):
                            width = self.Width
                        else:
                            b = base.BoundBox
                            width = max(b.XLength,b.YLength,b.ZLength)
                        if Draft.isClone(o,"Window"):
                            window = o.Objects[0]
                        else:
                            window = o
                        if window.Base and width:
                            f = self.getSubVolume(window.Base,width)
                            if f:
                                if base.Solids and f.Solids:
                                    base = base.cut(f)
                            
                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                    base = base.cut(o.Shape)
        return base
Пример #10
0
    def processSubShapes(self,obj,base,placement=None):
        "Adds additions and subtractions to a base shape"
        import Draft,Part
        #print("Processing subshapes of ",obj.Label, " : ",obj.Additions)

        if placement:
            if placement.isIdentity():
                placement = None
            else:
                placement = FreeCAD.Placement(placement)
                placement = placement.inverse()

        # treat additions
        for o in obj.Additions:

            if not base:
                if o.isDerivedFrom("Part::Feature"):
                    base = o.Shape
            else:
                if base.isNull():
                    if o.isDerivedFrom("Part::Feature"):
                        base = o.Shape
                else:
                    # special case, both walls with coinciding endpoints
                    import ArchWall
                    js = ArchWall.mergeShapes(o,obj)
                    if js:
                        add = js.cut(base)
                        if placement:
                            add.Placement = add.Placement.multiply(placement)
                        base = base.fuse(add)

                    elif o.isDerivedFrom("Part::Feature"):
                        if o.Shape:
                            if not o.Shape.isNull():
                                if o.Shape.Solids:
                                    s = o.Shape.copy()
                                    if placement:
                                        s.Placement = s.Placement.multiply(placement)
                                    if base:
                                        if base.Solids:
                                            try:
                                                base = base.fuse(s)
                                            except Part.OCCError:
                                                print("Arch: unable to fuse object ", obj.Name, " with ", o.Name)
                                    else:
                                        base = s

        # treat subtractions
        subs = obj.Subtractions
        for link in obj.InList:
            if hasattr(link,"Hosts"):
                for host in link.Hosts:
                    if host == obj:
                        subs.append(link)
        for o in subs:

            if base:
                if base.isNull():
                    base = None

            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window",True)):
                        # windows can be additions or subtractions, treated the same way
                        f = o.Proxy.getSubVolume(o)
                        if f:
                            if base.Solids and f.Solids:
                                if placement:
                                    f.Placement = f.Placement.multiply(placement)
                                if len(base.Solids) > 1:
                                    base = Part.makeCompound([sol.cut(f) for sol in base.Solids])
                                else:
                                    base = base.cut(f)

                elif (Draft.getType(o) == "Roof") or (Draft.isClone(o,"Roof")):
                    # roofs define their own special subtraction volume
                    f = o.Proxy.getSubVolume(o)
                    if f:
                        if base.Solids and f.Solids:
                            if len(base.Solids) > 1:
                                base = Part.makeCompound([sol.cut(f) for sol in base.Solids])
                            else:
                                base = base.cut(f)

                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                    s = o.Shape.copy()
                                    if placement:
                                        s.Placement = s.Placement.multiply(placement)
                                    try:
                                        if len(base.Solids) > 1:
                                            base = Part.makeCompound([sol.cut(s) for sol in base.Solids])
                                        else:
                                            base = base.cut(s)
                                    except Part.OCCError:
                                        print("Arch: unable to cut object ",o.Name, " from ", obj.Name)
        return base
Пример #11
0
def make_copy(obj, force=None, reparent=False):
    """makeCopy(object, [force], [reparent])
    
    Make an exact copy of an object and return it.
    
    Parameters
    ----------
    obj :
        Object to copy.

    force :
        TODO: Describe.

    reparent :
        TODO: Describe.
    """
    if not App.ActiveDocument:
        App.Console.PrintError("No active document. Aborting\n")
        return

    if (utils.get_type(obj) == "Rectangle") or (force == "Rectangle"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        Rectangle(newobj)
        if App.GuiUp:
            ViewProviderRectangle(newobj.ViewObject)

    elif (utils.get_type(obj) == "Point") or (force == "Point"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        Point(newobj)
        if App.GuiUp:
            ViewProviderPoint(newobj.ViewObject)

    elif (utils.get_type(obj) in ["Dimension", "LinearDimension"
                                  ]) or (force == "Dimension"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        LinearDimension(newobj)
        if App.GuiUp:
            ViewProviderLinearDimension(newobj.ViewObject)

    elif (utils.get_type(obj) == "Wire") or (force == "Wire"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        Wire(newobj)
        if App.GuiUp:
            ViewProviderWire(newobj.ViewObject)

    elif (utils.get_type(obj) == "Circle") or (force == "Circle"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        Circle(newobj)
        if App.GuiUp:
            ViewProviderDraft(newobj.ViewObject)

    elif (utils.get_type(obj) == "Polygon") or (force == "Polygon"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        Polygon(newobj)
        if App.GuiUp:
            ViewProviderDraft(newobj.ViewObject)

    elif (utils.get_type(obj) == "BSpline") or (force == "BSpline"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        BSpline(newobj)
        if App.GuiUp:
            ViewProviderWire(newobj.ViewObject)

    elif (utils.get_type(obj) == "Block") or (force == "BSpline"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        Block(newobj)
        if App.GuiUp:
            ViewProviderDraftPart(newobj.ViewObject)

    # drawingview became obsolete with v 0.19
    # TODO: uncomment after splitting DrawingView object from draft py

    #elif (utils.get_type(obj) == "DrawingView") or (force == "DrawingView"):
    #_name = utils.get_real_name(obj.Name)
    #newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
    #DrawingView(newobj)

    elif (utils.get_type(obj) == "Structure") or (force == "Structure"):
        import ArchStructure
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        ArchStructure._Structure(newobj)
        if App.GuiUp:
            ArchStructure._ViewProviderStructure(newobj.ViewObject)

    elif (utils.get_type(obj) == "Wall") or (force == "Wall"):
        import ArchWall
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        ArchWall._Wall(newobj)
        if App.GuiUp:
            ArchWall._ViewProviderWall(newobj.ViewObject)

    elif (utils.get_type(obj) == "Window") or (force == "Window"):
        import ArchWindow
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        ArchWindow._Window(newobj)
        if App.GuiUp:
            ArchWindow._ViewProviderWindow(newobj.ViewObject)

    elif (utils.get_type(obj) == "Panel") or (force == "Panel"):
        import ArchPanel
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject(obj.TypeId, _name)
        ArchPanel._Panel(newobj)
        if App.GuiUp:
            ArchPanel._ViewProviderPanel(newobj.ViewObject)

    elif (utils.get_type(obj) == "Sketch") or (force == "Sketch"):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject("Sketcher::SketchObject", _name)
        for geo in obj.Geometry:
            newobj.addGeometry(geo)
        for con in obj.Constraints:
            newobj.addConstraint(con)

    elif hasattr(obj, 'Shape'):
        _name = utils.get_real_name(obj.Name)
        newobj = App.ActiveDocument.addObject("Part::Feature", _name)
        newobj.Shape = obj.Shape

    else:
        print("Error: Object type cannot be copied")
        return None

    for p in obj.PropertiesList:
        if not p in ["Proxy", "ExpressionEngine"]:
            if p in newobj.PropertiesList:
                if not "ReadOnly" in newobj.getEditorMode(p):
                    try:
                        setattr(newobj, p, obj.getPropertyByName(p))
                    except AttributeError:
                        try:
                            setattr(newobj, p, obj.getPropertyByName(p).Value)
                        except AttributeError:
                            pass

    if reparent:
        parents = obj.InList
        if parents:
            for par in parents:
                if par.isDerivedFrom("App::DocumentObjectGroup"):
                    par.addObject(newobj)
                else:
                    for prop in par.PropertiesList:
                        if getattr(par, prop) == obj:
                            setattr(par, prop, newobj)

    gui_utils.format_object(newobj, obj)
    return newobj
Пример #12
0
    def processSubShapes(self, obj, base, pl=None):
        "Adds additions and subtractions to a base shape"
        import Draft

        if pl:
            if pl.isNull():
                pl = None
            else:
                pl = FreeCAD.Placement(pl)
                pl = pl.inverse()

        # treat additions
        for o in obj.Additions:

            if base:
                if base.isNull():
                    base = None

            # special case, both walls with coinciding endpoints
            import ArchWall
            js = ArchWall.mergeShapes(o, obj)
            if js:
                add = js.cut(base)
                if pl:
                    add.Placement = add.Placement.multiply(pl)
                base = base.fuse(add)

            elif (Draft.getType(o) == "Window") or (Draft.isClone(o,
                                                                  "Window")):
                f = o.Proxy.getSubVolume(o)
                if f:
                    if base.Solids and f.Solids:
                        if pl:
                            f.Placement = f.Placement.multiply(pl)
                        base = base.cut(f)

            elif o.isDerivedFrom("Part::Feature"):
                if o.Shape:
                    if not o.Shape.isNull():
                        if o.Shape.Solids:
                            s = o.Shape.copy()
                            if pl:
                                s.Placement = s.Placement.multiply(pl)
                            if base:
                                if base.Solids:
                                    base = base.fuse(s)
                            else:
                                base = s

        # treat subtractions
        for o in obj.Subtractions:

            if base:
                if base.isNull():
                    base = None

            if base:
                if (Draft.getType(o) == "Window") or (Draft.isClone(
                        o, "Window")):
                    # windows can be additions or subtractions, treated the same way
                    f = o.Proxy.getSubVolume(o)
                    if f:
                        if base.Solids and f.Solids:
                            if pl:
                                f.Placement = f.Placement.multiply(pl)
                            base = base.cut(f)

                elif o.isDerivedFrom("Part::Feature"):
                    if o.Shape:
                        if not o.Shape.isNull():
                            if o.Shape.Solids and base.Solids:
                                s = o.Shape.copy()
                                if pl:
                                    s.Placement = s.Placement.multiply(pl)
                                base = base.cut(s)
        return base