Esempio n. 1
0
    def execute(self,obj):
        "builds the wall shape"
        
        if self.clone(obj):
            return

        import Part, DraftGeomUtils
        base = None
        pl = obj.Placement
        extdata = self.getExtrusionData(obj)
        if extdata:
            base = extdata[0]
            extv = extdata[2].Rotation.multVec(extdata[1])
            if isinstance(base,list):
                shps = []
                for b in base:
                    b.Placement = extdata[2].multiply(b.Placement)
                    b = b.extrude(extv)
                    shps.append(b)
                base = Part.makeCompound(shps)
            else:
                base.Placement = extdata[2].multiply(base.Placement)
                base = base.extrude(extv)
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                elif obj.Base.Shape.Solids:
                    base = obj.Base.Shape.copy()
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(translate("Arch","This mesh is an invalid solid")+"\n")
                            obj.Base.ViewObject.show()
        if not base:
            FreeCAD.Console.PrintError(translate("Arch","Error: Invalid base object")+"\n")
            return

        base = self.processSubShapes(obj,base,pl)
        self.applyShape(obj,base,pl)

        # set the length property
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.Edges:
                    if not obj.Base.Shape.Faces:
                        if hasattr(obj.Base.Shape,"Length"):
                            l = obj.Base.Shape.Length
                            if obj.Length.Value != l:
                                obj.Length = l
Esempio n. 2
0
    def execute(self, obj):
        "builds the wall shape"

        if self.clone(obj):
            return

        import Part, DraftGeomUtils
        base = None
        pl = obj.Placement
        extdata = self.getExtrusionData(obj)
        if extdata:
            base = extdata[0]
            base.Placement = extdata[2].multiply(base.Placement)
            extv = extdata[2].Rotation.multVec(extdata[1])
            base = base.extrude(extv)
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                elif obj.Base.Shape.Solids:
                    base = obj.Base.Shape.copy()
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (
                                not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(
                                translate("Arch",
                                          "This mesh is an invalid solid") +
                                "\n")
                            obj.Base.ViewObject.show()
        if not base:
            FreeCAD.Console.PrintError(
                translate("Arch", "Error: Invalid base object") + "\n")
            return

        base = self.processSubShapes(obj, base, pl)
        self.applyShape(obj, base, pl)

        # set the length property
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.Edges:
                    if not obj.Base.Shape.Faces:
                        if hasattr(obj.Base.Shape, "Length"):
                            l = obj.Base.Shape.Length
                            if obj.Length.Value != l:
                                obj.Length = l
    def execute(self, obj):
        "creates the structure shape"

        import Part, DraftGeomUtils

        if self.clone(obj):
            return

        import Part, DraftGeomUtils

        base = None
        pl = obj.Placement
        extdata = self.getExtrusionData(obj)
        if extdata:
            base = extdata[0]
            base.Placement = extdata[2].multiply(base.Placement)
            extv = extdata[2].Rotation.multVec(extdata[1])
            if obj.Tool:
                try:
                    base = obj.Tool.Shape.copy().makePipe(obj.Base.Shape.copy())
                except Part.OCCError:
                    FreeCAD.Console.PrintError(
                        translate("Arch", "Error: The base shape couldn't be extruded along this tool object") + "\n"
                    )
                    return
            else:
                base = base.extrude(extv)
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                elif obj.Base.Shape.Solids:
                    base = obj.Base.Shape.copy()
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(translate("Arch", "This mesh is an invalid solid") + "\n")
                            obj.Base.ViewObject.show()
        if not base:
            FreeCAD.Console.PrintError(translate("Arch", "Error: Invalid base object") + "\n")
            return

        base = self.processSubShapes(obj, base, pl)
        self.applyShape(obj, base, pl)
Esempio n. 4
0
    def execute(self,obj):

        "creates the structure shape"

        import Part, DraftGeomUtils

        if self.clone(obj):
            return

        import Part, DraftGeomUtils
        base = None
        pl = obj.Placement
        extdata = self.getExtrusionData(obj)
        if extdata:
            base = extdata[0]
            base.Placement = extdata[2].multiply(base.Placement)
            extv = extdata[2].Rotation.multVec(extdata[1])
            if obj.Tool:
                try:
                    base = obj.Tool.Shape.copy().makePipe(obj.Base.Shape.copy())
                except Part.OCCError:
                    FreeCAD.Console.PrintError(translate("Arch","Error: The base shape couldn't be extruded along this tool object")+"\n")
                    return
            else:
                base = base.extrude(extv)
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                elif obj.Base.Shape.Solids:
                    base = obj.Base.Shape.copy()
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(translate("Arch","This mesh is an invalid solid")+"\n")
                            obj.Base.ViewObject.show()
        if (not base) and (not obj.Additions):
            #FreeCAD.Console.PrintError(translate("Arch","Error: Invalid base object")+"\n")
            return

        base = self.processSubShapes(obj,base,pl)
        self.applyShape(obj,base,pl)
Esempio n. 5
0
    def execute(self, obj):
        "builds the wall shape"

        if self.clone(obj):
            return

        import Part, DraftGeomUtils
        pl = obj.Placement
        normal, length, width, height = self.getDefaultValues(obj)
        base = None
        face = None

        if obj.Base:
            # computing a shape from a base object
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return

                if hasattr(obj, "Face"):
                    if obj.Face > 0:
                        if len(obj.Base.Shape.Faces) >= obj.Face:
                            face = obj.Base.Shape.Faces[obj.Face - 1]
                if face:
                    # case 1: this wall is based on a specific face of its base object
                    normal = face.normalAt(0, 0)
                    if normal.getAngle(Vector(0, 0, 1)) > math.pi / 4:
                        normal.multiply(width)
                        base = face.extrude(normal)
                        if obj.Align == "Center":
                            base.translate(normal.negative().multiply(0.5))
                        elif obj.Align == "Right":
                            base.translate(normal.negative())
                    else:
                        normal.multiply(height)
                        base = face.extrude(normal)
                elif obj.Base.Shape.Solids:
                    # case 2: the base is already a solid
                    base = obj.Base.Shape.copy()
                elif obj.Base.Shape.Edges:
                    # case 3: the base is flat, we need to extrude it
                    if not obj.Base.Shape.Faces:
                        # set the length property
                        if hasattr(obj.Base.Shape, "Length"):
                            l = obj.Base.Shape.Length
                            if obj.Length != l:
                                obj.Length = l
                    profiles = self.getProfiles(obj)
                    if profiles:
                        normal.multiply(height)
                        base = profiles.pop()
                        base.fix(0.1, 0, 1)
                        base = base.extrude(normal)
                        for p in profiles:
                            p.fix(0.1, 0, 1)
                            p = p.extrude(normal)
                            base = base.fuse(p)
                    else:
                        base = None
                else:
                    base = None
                    FreeCAD.Console.PrintError(
                        str(translate("Arch", "Error: Invalid base object")))

            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (
                                not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(
                                str(
                                    translate(
                                        "Arch",
                                        "This mesh is an invalid solid")))
                            obj.Base.ViewObject.show()
        else:
            # computing a shape from scratch
            if length and width and height:
                base = Part.makeBox(length, width, height)

        base = self.processSubShapes(obj, base, pl)
        self.applyShape(obj, base, pl)
Esempio n. 6
0
    def execute(self,obj):

        "builds the wall shape"

        if self.clone(obj):
            return

        import Part, DraftGeomUtils
        base = None
        pl = obj.Placement
        extdata = self.getExtrusionData(obj)
        if extdata:
            bplates = extdata[0]
            extv = extdata[2].Rotation.multVec(extdata[1])
            if isinstance(bplates,list):
                shps = []
                for b in bplates:
                    b.Placement = extdata[2].multiply(b.Placement)
                    b = b.extrude(extv)
                    shps.append(b)
                base = Part.makeCompound(shps)
            else:
                bplates.Placement = extdata[2].multiply(bplates.Placement)
                base = bplates.extrude(extv)
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                elif obj.Base.Shape.Solids:
                    base = obj.Base.Shape.copy()

                # blocks calculation
                elif hasattr(obj,"MakeBlocks") and hasattr(self,"basewires"):
                    if obj.MakeBlocks and self.basewires and extdata and obj.Width and obj.BlockLength.Value and obj.BlockHeight.Value:
                        #print "calculating blocks"
                        if len(self.basewires) == 1:
                            blocks = []
                            n = FreeCAD.Vector(extv)
                            n.normalize()
                            cuts1 = []
                            cuts2 = []
                            for i in range(2):
                                if i == 0:
                                    offset = obj.OffsetFirst.Value
                                else:
                                    offset = obj.OffsetSecond.Value
                                for edge in self.basewires[0].Edges:
                                    while offset < (edge.Length-obj.Joint.Value):
                                        #print i," Edge ",edge," : ",edge.Length," - ",offset
                                        if offset:
                                            t = edge.tangentAt(offset)
                                            p = t.cross(n)
                                            p.multiply(1.1*obj.Width.Value)
                                            p1 = edge.valueAt(offset).add(p)
                                            p2 = edge.valueAt(offset).add(p.negative())
                                            sh = Part.LineSegment(p1,p2).toShape()
                                            if obj.Joint.Value:
                                                sh = sh.extrude(t.multiply(obj.Joint.Value))
                                            sh = sh.extrude(n)
                                            if i == 0:
                                                cuts1.append(sh)
                                            else:
                                                cuts2.append(sh)
                                        offset += (obj.BlockLength.Value+obj.Joint.Value)
                                    else:
                                        offset -= (edge.Length-obj.Joint.Value)
                            if cuts1 and cuts2:
                                if isinstance(bplates,list):
                                    bplates = bplates[0]
                                fsize = obj.BlockHeight.Value+obj.Joint.Value
                                bvec = FreeCAD.Vector(n)
                                bvec.multiply(obj.BlockHeight.Value)
                                svec = FreeCAD.Vector(n)
                                svec.multiply(fsize)
                                plate1 = bplates.cut(cuts1).Faces
                                blocks1 = Part.makeCompound([f.extrude(bvec) for f in plate1])
                                plate2 = bplates.cut(cuts2).Faces
                                blocks2 = Part.makeCompound([f.extrude(bvec) for f in plate2])
                                interval = extv.Length/(fsize)
                                entires = int(interval)
                                rest = (interval - entires)
                                for i in range(entires):
                                    if i % 2: # odd
                                        b = blocks2.copy()
                                    else:
                                        b = blocks1.copy()
                                    if i:
                                        t = FreeCAD.Vector(svec)
                                        t.multiply(i)
                                        b.translate(t)
                                    blocks.append(b)
                                if rest:
                                    rest = extv.Length-(entires*fsize)
                                    rvec = FreeCAD.Vector(n)
                                    rvec.multiply(rest)
                                    if entires % 2:
                                        b = Part.makeCompound([f.extrude(rvec) for f in plate2])
                                    else:
                                        b = Part.makeCompound([f.extrude(rvec) for f in plate1])
                                    t = FreeCAD.Vector(svec)
                                    t.multiply(entires)
                                    b.translate(t)
                                    blocks.append(b)
                                if blocks:
                                    base = Part.makeCompound(blocks)
                            else:
                                FreeCAD.Console.PrintWarning(translate("Arch","Error computing block cuts for wall")+obj.Label+"\n")
                        else:
                            FreeCAD.Console.PrintWarning(translate("Arch","Cannot compute blocks for wall")+obj.Label+"\n")

            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(translate("Arch","This mesh is an invalid solid")+"\n")
                            obj.Base.ViewObject.show()
        if not base:
            FreeCAD.Console.PrintError(translate("Arch","Error: Invalid base object")+"\n")
            return

        base = self.processSubShapes(obj,base,pl)
        self.applyShape(obj,base,pl)

        # count blocks
        if hasattr(obj,"MakeBlocks"):
            if obj.MakeBlocks:
                fvol = obj.BlockLength.Value * obj.BlockHeight.Value * obj.Width.Value
                if fvol:
                    #print("base volume:",fvol)
                    #for s in base.Solids:
                        #print(abs(s.Volume - fvol))
                    ents = [s for s in base.Solids if abs(s.Volume - fvol) < 1]
                    obj.CountEntire = len(ents)
                    obj.CountBroken = len(base.Solids) - len(ents)
                else:
                    obj.CountEntire = 0
                    obj.CountBroken = 0

        # set the length property
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.Edges:
                    if not obj.Base.Shape.Faces:
                        if hasattr(obj.Base.Shape,"Length"):
                            l = obj.Base.Shape.Length
                            if obj.Length.Value != l:
                                obj.Length = l
Esempio n. 7
0
    def createGeometry(self, obj):
        import Part, DraftGeomUtils

        # getting default values
        height = width = length = 1
        if hasattr(obj, "Length"):
            if obj.Length:
                length = obj.Length
        if hasattr(obj, "Width"):
            if obj.Width:
                width = obj.Width
        if hasattr(obj, "Height"):
            if obj.Height:
                height = obj.Height

        # creating base shape
        pl = obj.Placement
        base = None
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Normal == Vector(0, 0, 0):
                    p = FreeCAD.Placement(obj.Base.Placement)
                    normal = p.Rotation.multVec(Vector(0, 0, 1))
                else:
                    normal = Vector(obj.Normal)
                normal = normal.multiply(height)
                base = obj.Base.Shape.copy()
                if base.Solids:
                    pass
                elif base.Faces:
                    base = base.extrude(normal)
                elif (len(base.Wires) == 1):
                    if base.Wires[0].isClosed():
                        base = Part.Face(base.Wires[0])
                        base = base.extrude(normal)
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids:
                            base = sh
        else:
            if obj.Normal == Vector(0, 0, 0):
                normal = Vector(0, 0, 1)
            else:
                normal = Vector(obj.Normal)
            normal = normal.multiply(height)
            l2 = length / 2 or 0.5
            w2 = width / 2 or 0.5
            v1 = Vector(-l2, -w2, 0)
            v2 = Vector(l2, -w2, 0)
            v3 = Vector(l2, w2, 0)
            v4 = Vector(-l2, w2, 0)
            base = Part.makePolygon([v1, v2, v3, v4, v1])
            base = Part.Face(base)
            base = base.extrude(normal)

        base = self.processSubShapes(obj, base)

        if base:
            # applying axes
            pts = self.getAxisPoints(obj)
            apl = self.getAxisPlacement(obj)
            if pts:
                fsh = []
                for i in range(len(pts)):
                    if hasattr(obj, "Exclude"):
                        if i in obj.Exclude:
                            continue
                    sh = base.copy()
                    if apl:
                        sh.Placement.Rotation = apl.Rotation
                    sh.translate(pts[i])
                    fsh.append(sh)
                    obj.Shape = Part.makeCompound(fsh)

            # finalizing

            else:
                if base:
                    if not base.isNull():
                        if base.isValid() and base.Solids:
                            if base.Volume < 0:
                                base.reverse()
                            if base.Volume < 0:
                                FreeCAD.Console.PrintError(
                                    str(
                                        translate(
                                            "Arch",
                                            "Couldn't compute the wall shape"))
                                )
                                return
                            base = base.removeSplitter()
                            obj.Shape = base
                if not DraftGeomUtils.isNull(pl):
                    obj.Placement = pl
Esempio n. 8
0
    def execute(self,obj):
        "creates the structure shape"

        import Part, DraftGeomUtils
        
        if self.clone(obj):
            return

        normal,length,width,height = self.getDefaultValues(obj)

        # creating base shape
        pl = obj.Placement
        base = None
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                if hasattr(obj,"Tool"):
                    if obj.Tool:
                        try:
                            base = obj.Tool.Shape.copy().makePipe(obj.Base.Shape.copy())
                        except Part.OCCError:
                            FreeCAD.Console.PrintError(translate("Arch","Error: The base shape couldn't be extruded along this tool object"))
                            return
                if not base:
                    if not height:
                        return
                    if obj.Normal == Vector(0,0,0):
                        p = FreeCAD.Placement(obj.Base.Placement)
                        normal = p.Rotation.multVec(normal)
                    else:
                        normal = Vector(obj.Normal)
                    normal = normal.multiply(height)
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif base.Faces:
                        base = base.extrude(normal)
                    elif (len(base.Wires) == 1):
                        if base.Wires[0].isClosed():
                            try:
                                base = Part.Face(base.Wires[0])
                                base = base.extrude(normal)
                            except Part.OCCError:
                                FreeCAD.Console.PrintError(obj.Label+" : "+str(translate("Arch","Unable to extrude the base shape\n")))
                                return

            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(str(translate("Arch","This mesh is an invalid solid")))
                            obj.Base.ViewObject.show()
        else:
            base = self.getProfiles(obj)
            if base:
                if length > height:
                    normal = normal.multiply(length)
                else:
                    normal = normal.multiply(height)
                base = Part.Face(base[0])
                base = base.extrude(normal)

        base = self.processSubShapes(obj,base,pl)
        self.applyShape(obj,base,pl)
Esempio n. 9
0
    def execute(self, obj):
        "creates the structure shape"

        import Part, DraftGeomUtils

        if self.clone(obj):
            return

        normal, length, width, height = self.getDefaultValues(obj)

        # creating base shape
        pl = obj.Placement
        base = None
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                if hasattr(obj, "Tool"):
                    if obj.Tool:
                        try:
                            base = obj.Tool.Shape.copy().makePipe(
                                obj.Base.Shape.copy())
                        except Part.OCCError:
                            FreeCAD.Console.PrintError(
                                translate(
                                    "Arch",
                                    "Error: The base shape couldn't be extruded along this tool object"
                                ))
                            return
                if not base:
                    if not height:
                        return
                    if obj.Normal == Vector(0, 0, 0):
                        if len(obj.Base.Shape.Faces) > 0:
                            normal = obj.Base.Shape.Faces[0].normalAt(.5, .5)
                        else:
                            normal = DraftGeomUtils.getNormal(obj.Base.Shape)
                            if not normal:
                                normal = FreeCAD.Vector(0, 0, 1)
                            #p = FreeCAD.Placement(obj.Base.Placement)
                            #normal = p.Rotation.multVec(normal)
                    else:
                        normal = Vector(obj.Normal)
                    normal = normal.multiply(height)
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif base.Faces:
                        base = base.extrude(normal)
                    elif (len(base.Wires) == 1):
                        if base.Wires[0].isClosed():
                            try:
                                base = Part.Face(base.Wires[0])
                                base = base.extrude(normal)
                            except Part.OCCError:
                                FreeCAD.Console.PrintError(
                                    obj.Label + " : " + str(
                                        translate(
                                            "Arch",
                                            "Unable to extrude the base shape\n"
                                        )))
                                return

            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (
                                not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(
                                str(
                                    translate(
                                        "Arch",
                                        "This mesh is an invalid solid")))
                            obj.Base.ViewObject.show()
        else:
            base = self.getProfiles(obj)
            if base:
                if length > height:
                    normal = normal.multiply(length)
                else:
                    normal = normal.multiply(height)
                base = Part.Face(base[0])
                base = base.extrude(normal)

        base = self.processSubShapes(obj, base, pl)
        self.applyShape(obj, base, pl)
Esempio n. 10
0
    def execute(self, obj):
        "creates the panel shape"

        import Part, DraftGeomUtils

        # base tests
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if not obj.Base.Mesh.isSolid():
                    return
        else:
            if obj.Length.Value:
                length = obj.Length.Value
            else:
                return
            if obj.Width.Value:
                width = obj.Width.Value
            else:
                return
        if obj.Thickness.Value:
            thickness = obj.Thickness.Value
        else:
            if not obj.Base:
                return
            elif obj.Base.isDerivedFrom("Part::Feature"):
                if not obj.Base.Solids:
                    return

        # creating base shape
        pl = obj.Placement
        base = None
        normal = None
        if obj.Base:
            p = FreeCAD.Placement(obj.Base.Placement)
            normal = p.Rotation.multVec(Vector(0, 0, 1))
            normal = normal.multiply(thickness)
            base = obj.Base.Shape.copy()
            if base.Solids:
                pass
            elif base.Faces:
                self.BaseProfile = base
                self.ExtrusionVector = normal
                base = base.extrude(normal)
            elif base.Wires:
                closed = True
                for w in base.Wires:
                    if not w.isClosed():
                        closed = False
                if closed:
                    base = ArchCommands.makeFace(base.Wires)
                    self.BaseProfile = base
                    self.ExtrusionVector = normal
                    base = base.extrude(normal)
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids:
                            base = sh
        else:
            normal = Vector(0, 0, 1).multiply(thickness)
            self.ExtrusionVector = normal
            l2 = length / 2 or 0.5
            w2 = width / 2 or 0.5
            v1 = Vector(-l2, -w2, 0)
            v2 = Vector(l2, -w2, 0)
            v3 = Vector(l2, w2, 0)
            v4 = Vector(-l2, w2, 0)
            base = Part.makePolygon([v1, v2, v3, v4, v1])
            base = Part.Face(base)
            self.BaseProfile = base
            base = base.extrude(self.ExtrusionVector)

        if base and (obj.Sheets > 1) and normal and thickness:
            bases = [base]
            for i in range(1, obj.Sheets):
                n = FreeCAD.Vector(normal).normalize().multiply(i * thickness)
                b = base.copy()
                b.translate(n)
                bases.append(b)
            base = Part.makeCompound(bases)

        if base and normal and hasattr(obj, "Offset"):
            if obj.Offset.Value:
                v = DraftVecUtils.scaleTo(normal, obj.Offset.Value)
                base.translate(v)

        # process subshapes
        base = self.processSubShapes(obj, base, pl)

        # applying
        if base:
            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(
                            translate("Arch", "Couldn't compute a shape"))
                        return
                    base = base.removeSplitter()
                    obj.Shape = base
                    if not pl.isNull():
                        obj.Placement = pl
Esempio n. 11
0
    def execute(self,obj):
        "creates the panel shape"
        
        if self.clone(obj):
            return

        import Part, DraftGeomUtils

        # base tests
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if not obj.Base.Mesh.isSolid():
                    return
        else:
            if obj.Length.Value:
                length = obj.Length.Value
            else:
                return
            if obj.Width.Value:
                width = obj.Width.Value
            else:
                return
        if obj.Thickness.Value:
            thickness = obj.Thickness.Value
        else:
            if not obj.Base:
                return
            elif obj.Base.isDerivedFrom("Part::Feature"):
                if not obj.Base.Shape.Solids:
                    return

        # creating base shape
        pl = obj.Placement
        base = None
        normal = None
        baseprofile = None
        if obj.Base:
            base = obj.Base.Shape.copy()
            if not base.Solids:
                p = FreeCAD.Placement(obj.Base.Placement)
                if base.Faces:
                    baseprofile = base
                    normal = baseprofile.Faces[0].normalAt(0,0).multiply(thickness)
                    base = base.extrude(normal)
                elif base.Wires:
                    closed = True
                    for w in base.Wires:
                        if not w.isClosed():
                            closed = False
                    if closed:
                        baseprofile = ArchCommands.makeFace(base.Wires)
                        normal = baseprofile.normalAt(0,0).multiply(thickness)
                        base = baseprofile.extrude(normal)
                elif obj.Base.isDerivedFrom("Mesh::Feature"):
                    if obj.Base.Mesh.isSolid():
                        if obj.Base.Mesh.countComponents() == 1:
                            sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                            if sh.isClosed() and sh.isValid() and sh.Solids:
                                base = sh
        else:
            normal = Vector(0,0,1).multiply(thickness)
            l2 = length/2 or 0.5
            w2 = width/2 or 0.5
            v1 = Vector(-l2,-w2,0)
            v2 = Vector(l2,-w2,0)
            v3 = Vector(l2,w2,0)
            v4 = Vector(-l2,w2,0)
            base = Part.makePolygon([v1,v2,v3,v4,v1])
            baseprofile = Part.Face(base)
            base = baseprofile.extrude(normal)
            
        if hasattr(obj,"Area"):
            if baseprofile:
                obj.Area = baseprofile.Area
            
        if hasattr(obj,"WaveLength"):
            if baseprofile and obj.WaveLength.Value and obj.WaveHeight.Value:
                # corrugated element
                bb = baseprofile.BoundBox
                bb.enlarge(bb.DiagonalLength)
                p1 = Vector(bb.getPoint(0).x,bb.getPoint(0).y,bb.Center.z)
                if obj.WaveType == "Curved":
                    p2 = p1.add(Vector(obj.WaveLength.Value/2,0,obj.WaveHeight.Value))
                    p3 = p2.add(Vector(obj.WaveLength.Value/2,0,-obj.WaveHeight.Value))
                    e1 = Part.Arc(p1,p2,p3).toShape()
                    p4 = p3.add(Vector(obj.WaveLength.Value/2,0,-obj.WaveHeight.Value))
                    p5 = p4.add(Vector(obj.WaveLength.Value/2,0,obj.WaveHeight.Value))
                    e2 = Part.Arc(p3,p4,p5).toShape()
                else:
                    if obj.WaveHeight.Value < obj.WaveLength.Value:
                        p2 = p1.add(Vector(obj.WaveHeight.Value,0,obj.WaveHeight.Value))
                        p3 = p2.add(Vector(obj.WaveLength.Value-2*obj.WaveHeight.Value,0,0))
                        p4 = p3.add(Vector(obj.WaveHeight.Value,0,-obj.WaveHeight.Value))
                        e1 = Part.makePolygon([p1,p2,p3,p4])
                        p5 = p4.add(Vector(obj.WaveHeight.Value,0,-obj.WaveHeight.Value))
                        p6 = p5.add(Vector(obj.WaveLength.Value-2*obj.WaveHeight.Value,0,0))
                        p7 = p6.add(Vector(obj.WaveHeight.Value,0,obj.WaveHeight.Value))
                        e2 = Part.makePolygon([p4,p5,p6,p7])
                    else:
                        p2 = p1.add(Vector(obj.WaveLength.Value/2,0,obj.WaveHeight.Value))
                        p3 = p2.add(Vector(obj.WaveLength.Value/2,0,-obj.WaveHeight.Value))
                        e1 = Part.makePolygon([p1,p2,p3])
                        p4 = p3.add(Vector(obj.WaveLength.Value/2,0,-obj.WaveHeight.Value))
                        p5 = p4.add(Vector(obj.WaveLength.Value/2,0,obj.WaveHeight.Value))
                        e2 = Part.makePolygon([p3,p4,p5])
                edges = [e1,e2]
                for i in range(int(bb.XLength/(obj.WaveLength.Value*2))):
                    e1 = e1.copy()
                    e1.translate(Vector(obj.WaveLength.Value*2,0,0))
                    e2 = e2.copy()
                    e2.translate(Vector(obj.WaveLength.Value*2,0,0))
                    edges.extend([e1,e2])
                basewire = Part.Wire(edges)
                baseface = basewire.extrude(Vector(0,bb.YLength,0))
                base = baseface.extrude(Vector(0,0,thickness))
                rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,1),normal)
                base.rotate(bb.Center,rot.Axis,math.degrees(rot.Angle))
                if obj.WaveDirection.Value:
                    base.rotate(bb.Center,normal,obj.WaveDirection.Value)
                n1 = normal.negative().normalize().multiply(obj.WaveHeight.Value*2)
                self.vol = baseprofile.copy()
                self.vol.translate(n1)
                self.vol = self.vol.extrude(n1.negative().multiply(2))
                base = self.vol.common(base)
                base = base.removeSplitter()
                if not base:
                    FreeCAD.Console.PrintError(transpate("Arch","Error computing shape of ")+obj.Label+"\n")
                    return False

        if base and (obj.Sheets > 1) and normal and thickness:
            bases = [base]
            for i in range(1,obj.Sheets):
                n = FreeCAD.Vector(normal).normalize().multiply(i*thickness)
                b = base.copy()
                b.translate(n)
                bases.append(b)
            base = Part.makeCompound(bases)

        if base and normal and hasattr(obj,"Offset"):
            if obj.Offset.Value:
                v = DraftVecUtils.scaleTo(normal,obj.Offset.Value)
                base.translate(v)

        # process subshapes
        base = self.processSubShapes(obj,base,pl)

        # applying
        if base:
            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(translate("Arch","Couldn't compute a shape"))
                        return
                    base = base.removeSplitter()
                    obj.Shape = base
                    if not pl.isNull():
                        obj.Placement = pl
Esempio n. 12
0
    def createGeometry(self,obj):
        "builds the wall shape"

        if not obj.Base:
            return

        import Part, DraftGeomUtils
        
        pl = obj.Placement
        normal,width,height = self.getDefaultValues(obj)

        # computing shape
        base = None
        if obj.Base.isDerivedFrom("Part::Feature"):
            if not obj.Base.Shape.isNull():
                if obj.Base.Shape.isValid():
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif (len(base.Faces) == 1) and (not obj.ForceWire):
                        if height:
                            norm = normal.multiply(height)
                            base = base.extrude(norm)
                    elif len(base.Wires) >= 1:
                        temp = None
                        for wire in obj.Base.Shape.Wires:
                            sh = self.getBase(obj,wire,normal,width,height)
                            if temp:
                                temp = temp.fuse(sh)
                            else:
                                temp = sh
                        base = temp
                    elif base.Edges:
                        wire = Part.Wire(base.Edges)
                        if wire:
                            sh = self.getBase(obj,wire,normal,width,height)
                            if sh:
                                base = sh
                    else:
                        base = None
                        FreeCAD.Console.PrintError(str(translate("Arch","Error: Invalid base object")))
                    
        elif obj.Base.isDerivedFrom("Mesh::Feature"):
            if obj.Base.Mesh.isSolid():
                if obj.Base.Mesh.countComponents() == 1:
                    sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                    if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                        base = sh
                    else:
                        FreeCAD.Console.PrintWarning(str(translate("Arch","This mesh is an invalid solid")))
                        obj.Base.ViewObject.show()
                        
        base = self.processSubShapes(obj,base)
        
        if base:
            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(str(translate("Arch","Couldn't compute the wall shape")))
                        return
                    try:
                        base = base.removeSplitter()
                    except:
                        FreeCAD.Console.PrintError(str(translate("Arch","Error removing splitter from wall shape")))
                    obj.Shape = base
                    if not DraftGeomUtils.isNull(pl):
                        obj.Placement = pl
Esempio n. 13
0
    def createGeometry(self,obj):
        "builds the wall shape"

        if not obj.Base:
            return

        import Part, DraftGeomUtils

        flat = False
        if hasattr(obj.ViewObject,"DisplayMode"):
            flat = (obj.ViewObject.DisplayMode == "Flat 2D")

        width = 1.0
        if hasattr(obj,"Width"):
            if obj.Width:
                width = obj.Width
        
        def getbase(wire):
            "returns a full shape from a base wire"
            dvec = DraftGeomUtils.vec(wire.Edges[0]).cross(normal)
            dvec.normalize()
            if obj.Align == "Left":
                dvec = dvec.multiply(width)
                w2 = DraftGeomUtils.offsetWire(wire,dvec)
                w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
                sh = DraftGeomUtils.bind(w1,w2)
            elif obj.Align == "Right":
                dvec = dvec.multiply(width)
                dvec = DraftVecUtils.neg(dvec)
                w2 = DraftGeomUtils.offsetWire(wire,dvec)
                w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
                sh = DraftGeomUtils.bind(w1,w2)
            elif obj.Align == "Center":
                dvec = dvec.multiply(width/2)
                w1 = DraftGeomUtils.offsetWire(wire,dvec)
                dvec = DraftVecUtils.neg(dvec)
                w2 = DraftGeomUtils.offsetWire(wire,dvec)
                sh = DraftGeomUtils.bind(w1,w2)
            # fixing self-intersections
            sh.fix(0.1,0,1)
            if height and (not flat):
                norm = Vector(normal).multiply(height)
                sh = sh.extrude(norm)
            return sh
        
        pl = obj.Placement

        # getting default values
        height = normal = None
        if obj.Height:
            height = obj.Height
        else:
            for p in obj.InList:
                if Draft.getType(p) == "Floor":
                    height = p.Height
        if not height: height = 1
        if obj.Normal == Vector(0,0,0):
            normal = Vector(0,0,1)
        else:
            normal = Vector(obj.Normal)

        # computing shape
        base = None
        if obj.Base.isDerivedFrom("Part::Feature"):
            if not obj.Base.Shape.isNull():
                if obj.Base.Shape.isValid():
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif base.Faces and (not obj.ForceWire):
                        if height:
                            norm = normal.multiply(height)
                            base = base.extrude(norm)
                    elif base.Wires:
                        temp = None
                        for wire in obj.Base.Shape.Wires:
                            sh = getbase(wire)
                            if temp:
                                temp = temp.fuse(sh)
                            else:
                                temp = sh
                        base = temp
                    elif base.Edges:
                        wire = Part.Wire(base.Edges)
                        sh = getbase(wire)
                        if sh:
                            base = sh
                    else:
                        base = None
                        FreeCAD.Console.PrintError(str(translate("Arch","Error: Invalid base object")))
                    
        elif obj.Base.isDerivedFrom("Mesh::Feature"):
            if obj.Base.Mesh.isSolid():
                if obj.Base.Mesh.countComponents() == 1:
                    sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                    if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                        base = sh
                    else:
                        FreeCAD.Console.PrintWarning(str(translate("Arch","This mesh is an invalid solid")))
                        obj.Base.ViewObject.show()

        if base:

            for app in obj.Additions:
                if Draft.getType(app) == "Window":
                    # window
                    if app.Base and obj.Width:
                        f = self.getSubVolume(app.Base,width)
                        if f:
                            base = base.cut(f)
                elif Draft.isClone(app,"Window"):
                    if app.Objects[0].Base and width:
                        f = self.getSubVolume(app.Objects[0].Base,width,app.Placement)
                        if f:
                            base = base.cut(f)
                elif app.isDerivedFrom("Part::Feature"):
                    if app.Shape:
                        if not app.Shape.isNull():
                            base = base.fuse(app.Shape)
                            app.ViewObject.hide() #to be removed
            for hole in obj.Subtractions:
                if Draft.getType(hole) == "Window":
                    # window
                    if hole.Base and obj.Width:
                        f = self.getSubVolume(hole.Base,width)
                        if f:
                            base = base.cut(f)
                elif Draft.isClone(hole,"Window"):
                    if hole.Objects[0].Base and width:
                        f = self.getSubVolume(hole.Objects[0].Base,width,hole.Placement)
                        if f:
                            base = base.cut(f)                   
                elif hole.isDerivedFrom("Part::Feature"):
                    if hole.Shape:
                        if not hole.Shape.isNull():
                            base = base.cut(hole.Shape)
                            hole.ViewObject.hide() # to be removed

            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(str(translate("Arch","Couldn't compute the wall shape")))
                        return
                    try:
                        base = base.removeSplitter()
                    except:
                        FreeCAD.Console.PrintError(str(translate("Arch","Error removing splitter from wall shape")))
                    obj.Shape = base
                    if not DraftGeomUtils.isNull(pl):
                        obj.Placement = pl
Esempio n. 14
0
    def createGeometry(self, obj):
        "builds the wall shape"

        if not obj.Base:
            return

        import Part, DraftGeomUtils

        pl = obj.Placement
        normal, width, height = self.getDefaultValues(obj)

        # computing shape
        base = None
        if obj.Base.isDerivedFrom("Part::Feature"):
            if not obj.Base.Shape.isNull():
                if obj.Base.Shape.isValid():
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif (len(base.Faces) == 1) and (not obj.ForceWire):
                        if height:
                            norm = normal.multiply(height)
                            base = base.extrude(norm)
                    elif len(base.Wires) >= 1:
                        temp = None
                        for wire in obj.Base.Shape.Wires:
                            sh = self.getBase(obj, wire, normal, width, height)
                            if temp:
                                temp = temp.fuse(sh)
                            else:
                                temp = sh
                        base = temp
                    elif base.Edges:
                        wire = Part.Wire(base.Edges)
                        if wire:
                            sh = self.getBase(obj, wire, normal, width, height)
                            if sh:
                                base = sh
                    else:
                        base = None
                        FreeCAD.Console.PrintError(
                            str(translate("Arch",
                                          "Error: Invalid base object")))

        elif obj.Base.isDerivedFrom("Mesh::Feature"):
            if obj.Base.Mesh.isSolid():
                if obj.Base.Mesh.countComponents() == 1:
                    sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                    if sh.isClosed() and sh.isValid() and sh.Solids and (
                            not sh.isNull()):
                        base = sh
                    else:
                        FreeCAD.Console.PrintWarning(
                            str(
                                translate("Arch",
                                          "This mesh is an invalid solid")))
                        obj.Base.ViewObject.show()

        base = self.processSubShapes(obj, base)

        if base:
            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(
                            str(
                                translate("Arch",
                                          "Couldn't compute the wall shape")))
                        return
                    try:
                        base = base.removeSplitter()
                    except:
                        FreeCAD.Console.PrintError(
                            str(
                                translate(
                                    "Arch",
                                    "Error removing splitter from wall shape"))
                        )
                    obj.Shape = base
                    if not DraftGeomUtils.isNull(pl):
                        obj.Placement = pl
Esempio n. 15
0
    def execute(self, obj):
        "creates the structure shape"

        import Part, DraftGeomUtils

        # getting default values
        length = 1
        width = 1
        height = 1
        if hasattr(obj, "Length"):
            if obj.Length.Value:
                length = obj.Length.Value
        if hasattr(obj, "Width"):
            if obj.Width.Value:
                width = obj.Width.Value
        if hasattr(obj, "Height"):
            if obj.Height.Value:
                height = obj.Height.Value
            else:
                for p in obj.InList:
                    if Draft.getType(p) == "Floor":
                        if p.Height.Value:
                            height = p.Height.Value

        # creating base shape
        pl = obj.Placement
        base = None
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if hasattr(obj, "Tool"):
                    if obj.Tool:
                        try:
                            base = obj.Tool.Shape.copy().makePipe(
                                obj.Base.Shape.copy())
                        except:
                            FreeCAD.Console.PrintError(
                                translate(
                                    "Arch",
                                    "Error: The base shape couldn't be extruded along this tool object"
                                ))
                            return
                if not base:
                    if obj.Normal == Vector(0, 0, 0):
                        p = FreeCAD.Placement(obj.Base.Placement)
                        normal = p.Rotation.multVec(Vector(0, 0, 1))
                    else:
                        normal = Vector(obj.Normal)
                    normal = normal.multiply(height)
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif base.Faces:
                        self.BaseProfile = base
                        self.ExtrusionVector = normal
                        base = base.extrude(normal)
                    elif (len(base.Wires) == 1):
                        if base.Wires[0].isClosed():
                            base = Part.Face(base.Wires[0])
                            self.BaseProfile = base
                            self.ExtrusionVector = normal
                            base = base.extrude(normal)

            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids:
                            base = sh
        else:
            if obj.Normal == Vector(0, 0, 0):
                if length > height:
                    normal = Vector(1, 0, 0).multiply(length)
                else:
                    normal = Vector(0, 0, 1).multiply(height)
            else:
                normal = Vector(obj.Normal).multiply(height)
            self.ExtrusionVector = normal
            if length > height:
                h2 = height / 2 or 0.5
                w2 = width / 2 or 0.5
                v1 = Vector(0, -w2, -h2)
                v2 = Vector(0, -w2, h2)
                v3 = Vector(0, w2, h2)
                v4 = Vector(0, w2, -h2)
            else:
                l2 = length / 2 or 0.5
                w2 = width / 2 or 0.5
                v1 = Vector(-l2, -w2, 0)
                v2 = Vector(l2, -w2, 0)
                v3 = Vector(l2, w2, 0)
                v4 = Vector(-l2, w2, 0)
            base = Part.makePolygon([v1, v2, v3, v4, v1])
            base = Part.Face(base)
            self.BaseProfile = base
            base = base.extrude(self.ExtrusionVector)

        base = self.processSubShapes(obj, base, pl)

        if base:
            # applying axes
            pts = self.getAxisPoints(obj)
            apl = self.getAxisPlacement(obj)
            if pts:
                fsh = []
                for i in range(len(pts)):
                    if hasattr(obj, "Exclude"):
                        if i in obj.Exclude:
                            continue
                    sh = base.copy()
                    if apl:
                        sh.Placement.Rotation = apl.Rotation
                    sh.translate(pts[i])
                    fsh.append(sh)
                    obj.Shape = Part.makeCompound(fsh)

            # finalizing
            else:
                if base:
                    if not base.isNull():
                        if base.isValid() and base.Solids:
                            if base.Volume < 0:
                                base.reverse()
                            if base.Volume < 0:
                                FreeCAD.Console.PrintError(
                                    translate("Arch",
                                              "Couldn't compute a shape"))
                                return
                            base = base.removeSplitter()
                            obj.Shape = base
                if not pl.isNull():
                    obj.Placement = pl
Esempio n. 16
0
    def execute(self,obj):
        "creates the panel shape"

        import Part, DraftGeomUtils

        # base tests
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if not obj.Base.Mesh.isSolid():
                    return
        else:
            if obj.Length.Value:
                length = obj.Length.Value
            else:
                return
            if obj.Width.Value:
                width = obj.Width.Value
            else:
                return
        if obj.Thickness.Value:
            thickness = obj.Thickness.Value
        else:
            if not obj.Base:
                return
            elif obj.Base.isDerivedFrom("Part::Feature"):
                if not obj.Base.Solids:
                    return

        # creating base shape
        pl = obj.Placement
        base = None
        normal = None
        if obj.Base:
            p = FreeCAD.Placement(obj.Base.Placement)
            normal = p.Rotation.multVec(Vector(0,0,1))
            normal = normal.multiply(thickness)
            base = obj.Base.Shape.copy()
            if base.Solids:
                pass
            elif base.Faces:
                self.BaseProfile = base
                self.ExtrusionVector = normal
                base = base.extrude(normal)
            elif base.Wires:
                closed = True
                for w in base.Wires:
                    if not w.isClosed():
                        closed = False
                if closed:
                    base = ArchCommands.makeFace(base.Wires)
                    self.BaseProfile = base
                    self.ExtrusionVector = normal
                    base = base.extrude(normal)
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids:
                            base = sh
        else:
            normal = Vector(0,0,1).multiply(thickness)
            self.ExtrusionVector = normal
            l2 = length/2 or 0.5
            w2 = width/2 or 0.5
            v1 = Vector(-l2,-w2,0)
            v2 = Vector(l2,-w2,0)
            v3 = Vector(l2,w2,0)
            v4 = Vector(-l2,w2,0)
            base = Part.makePolygon([v1,v2,v3,v4,v1])
            base = Part.Face(base)
            self.BaseProfile = base
            base = base.extrude(self.ExtrusionVector)

        if base and (obj.Sheets > 1) and normal and thickness:
            bases = [base]
            for i in range(1,obj.Sheets):
                n = FreeCAD.Vector(normal).normalize().multiply(i*thickness)
                b = base.copy()
                b.translate(n)
                bases.append(b)
            base = Part.makeCompound(bases)

        if base and normal and hasattr(obj,"Offset"):
            if obj.Offset.Value:
                v = DraftVecUtils.scaleTo(normal,obj.Offset.Value)
                base.translate(v)

        # process subshapes
        base = self.processSubShapes(obj,base,pl)

        # applying
        if base:
            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(translate("Arch","Couldn't compute a shape"))
                        return
                    base = base.removeSplitter()
                    obj.Shape = base
                    if not pl.isNull():
                        obj.Placement = pl
Esempio n. 17
0
    def execute(self,obj):
        "creates the structure shape"
        
        import Part, DraftGeomUtils
        
        # getting default values
        length = 1
        width = 1
        height = 1
        if hasattr(obj,"Length"):
            if obj.Length.Value:
                length = obj.Length.Value
        if hasattr(obj,"Width"):
            if obj.Width.Value:
                width = obj.Width.Value
        if hasattr(obj,"Height"):
            if obj.Height.Value:
                height = obj.Height.Value
            else:
                for p in obj.InList:
                    if Draft.getType(p) == "Floor":
                        if p.Height.Value:
                            height = p.Height.Value

        # creating base shape
        pl = obj.Placement
        base = None
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if hasattr(obj,"Tool"):
                    if obj.Tool:
                        try:
                            base = obj.Tool.Shape.copy().makePipe(obj.Base.Shape.copy())
                        except:
                            FreeCAD.Console.PrintError(translate("Arch","Error: The base shape couldn't be extruded along this tool object"))
                            return
                if not base:
                    if obj.Normal == Vector(0,0,0):
                        p = FreeCAD.Placement(obj.Base.Placement)
                        normal = p.Rotation.multVec(Vector(0,0,1))
                    else:
                        normal = Vector(obj.Normal)
                    normal = normal.multiply(height)
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif base.Faces:
                        self.BaseProfile = base
                        self.ExtrusionVector = normal
                        base = base.extrude(normal)
                    elif (len(base.Wires) == 1):
                        if base.Wires[0].isClosed():
                            base = Part.Face(base.Wires[0])
                            self.BaseProfile = base
                            self.ExtrusionVector = normal
                            base = base.extrude(normal)
                            
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids:
                            base = sh
        else:
            if obj.Normal == Vector(0,0,0):
                if length > height:
                    normal = Vector(1,0,0).multiply(length)
                else:
                    normal = Vector(0,0,1).multiply(height)
            else:
                normal = Vector(obj.Normal).multiply(height)
            self.ExtrusionVector = normal
            if length > height:
                h2 = height/2 or 0.5
                w2 = width/2 or 0.5
                v1 = Vector(0,-w2,-h2)
                v2 = Vector(0,-w2,h2)
                v3 = Vector(0,w2,h2)
                v4 = Vector(0,w2,-h2)
            else:
                l2 = length/2 or 0.5
                w2 = width/2 or 0.5
                v1 = Vector(-l2,-w2,0)
                v2 = Vector(l2,-w2,0)
                v3 = Vector(l2,w2,0)
                v4 = Vector(-l2,w2,0)
            base = Part.makePolygon([v1,v2,v3,v4,v1])
            base = Part.Face(base)
            self.BaseProfile = base
            base = base.extrude(self.ExtrusionVector)
            
        base = self.processSubShapes(obj,base,pl)
            
        if base:
            # applying axes
            pts = self.getAxisPoints(obj)
            apl = self.getAxisPlacement(obj)
            if pts:
                fsh = []
                for i in range(len(pts)):
                    if hasattr(obj,"Exclude"):
                        if i in obj.Exclude:
                            continue
                    sh = base.copy()
                    if apl:
                        sh.Placement.Rotation = apl.Rotation
                    sh.translate(pts[i])
                    fsh.append(sh)
                    obj.Shape = Part.makeCompound(fsh)

            # finalizing
            else:
                if base:
                    if not base.isNull():
                        if base.isValid() and base.Solids:
                            if base.Volume < 0:
                                base.reverse()
                            if base.Volume < 0:
                                FreeCAD.Console.PrintError(translate("Arch","Couldn't compute a shape"))
                                return
                            base = base.removeSplitter()
                            obj.Shape = base
                if not pl.isNull():
                    obj.Placement = pl
Esempio n. 18
0
    def execute(self,obj):
        "builds the wall shape"
        
        if self.clone(obj):
            return

        import Part, DraftGeomUtils
        pl = obj.Placement
        normal,length,width,height = self.getDefaultValues(obj)
        base = None
        face = None

        if obj.Base:
            # computing a shape from a base object
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return

                if hasattr(obj,"Face"):
                    if obj.Face > 0:
                        if len(obj.Base.Shape.Faces) >= obj.Face:
                            face = obj.Base.Shape.Faces[obj.Face-1]
                if face:
                    # case 1: this wall is based on a specific face of its base object
                    normal = face.normalAt(0,0)
                    if normal.getAngle(Vector(0,0,1)) > math.pi/4:
                        normal.multiply(width)
                        base = face.extrude(normal)
                        if obj.Align == "Center":
                            base.translate(normal.negative().multiply(0.5))
                        elif obj.Align == "Right":
                            base.translate(normal.negative())
                    else:
                        normal.multiply(height)
                        base = face.extrude(normal)
                elif obj.Base.Shape.Solids:
                    # case 2: the base is already a solid
                    base = obj.Base.Shape.copy()
                elif obj.Base.Shape.Edges:
                    # case 3: the base is flat, we need to extrude it
                    if not obj.Base.Shape.Faces:
                        # set the length property
                        if hasattr(obj.Base.Shape,"Length"):
                            l = obj.Base.Shape.Length
                            if obj.Length != l:
                                obj.Length = l
                    profiles = self.getProfiles(obj)
                    if profiles:
                        normal.multiply(height)
                        base = profiles.pop()
                        base.fix(0.1,0,1)
                        base = base.extrude(normal)
                        for p in profiles:
                            p.fix(0.1,0,1)
                            p = p.extrude(normal)
                            base = base.fuse(p)
                    else:
                        base = None
                else:
                    base = None
                    FreeCAD.Console.PrintError(str(translate("Arch","Error: Invalid base object")))

            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(str(translate("Arch","This mesh is an invalid solid")))
                            obj.Base.ViewObject.show()
        else:
            # computing a shape from scratch
            if length and width and height:
                base = Part.makeBox(length,width,height)

        base = self.processSubShapes(obj,base,pl)
        self.applyShape(obj,base,pl)
Esempio n. 19
0
    def execute(self,obj):

        "builds the wall shape"

        if self.clone(obj):
            return

        import Part, DraftGeomUtils
        base = None
        pl = obj.Placement
        extdata = self.getExtrusionData(obj)
        if extdata:
            bplates = extdata[0]
            extv = extdata[2].Rotation.multVec(extdata[1])
            if isinstance(bplates,list):
                shps = []
                for b in bplates:
                    b.Placement = extdata[2].multiply(b.Placement)
                    b = b.extrude(extv)
                    shps.append(b)
                base = Part.makeCompound(shps)
            else:
                bplates.Placement = extdata[2].multiply(bplates.Placement)
                base = bplates.extrude(extv)
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
                if not obj.Base.Shape.isValid():
                    if not obj.Base.Shape.Solids:
                        # let pass invalid objects if they have solids...
                        return
                elif obj.Base.Shape.Solids:
                    base = obj.Base.Shape.copy()

                # blocks calculation
                elif hasattr(obj,"MakeBlocks") and hasattr(self,"basewires"):
                    if obj.MakeBlocks and self.basewires and extdata and obj.Width and obj.BlockLength.Value and obj.BlockHeight.Value:
                        #print "calculating blocks"
                        if len(self.basewires) == 1:
                            blocks = []
                            n = FreeCAD.Vector(extv)
                            n.normalize()
                            cuts1 = []
                            cuts2 = []
                            for i in range(2):
                                if i == 0:
                                    offset = obj.OffsetFirst.Value
                                else:
                                    offset = obj.OffsetSecond.Value
                                for edge in self.basewires[0].Edges:
                                    while offset < (edge.Length-obj.Joint.Value):
                                        #print i," Edge ",edge," : ",edge.Length," - ",offset
                                        if offset:
                                            t = edge.tangentAt(offset)
                                            p = t.cross(n)
                                            p.multiply(1.1*obj.Width.Value)
                                            p1 = edge.valueAt(offset).add(p)
                                            p2 = edge.valueAt(offset).add(p.negative())
                                            sh = Part.LineSegment(p1,p2).toShape()
                                            if obj.Joint.Value:
                                                sh = sh.extrude(t.multiply(obj.Joint.Value))
                                            sh = sh.extrude(n)
                                            if i == 0:
                                                cuts1.append(sh)
                                            else:
                                                cuts2.append(sh)
                                        offset += (obj.BlockLength.Value+obj.Joint.Value)
                                    else:
                                        offset -= (edge.Length-obj.Joint.Value)
                            if cuts1 and cuts2:
                                if isinstance(bplates,list):
                                    bplates = bplates[0]
                                fsize = obj.BlockHeight.Value+obj.Joint.Value
                                bvec = FreeCAD.Vector(n)
                                bvec.multiply(obj.BlockHeight.Value)
                                svec = FreeCAD.Vector(n)
                                svec.multiply(fsize)
                                plate1 = bplates.cut(cuts1).Faces
                                blocks1 = Part.makeCompound([f.extrude(bvec) for f in plate1])
                                plate2 = bplates.cut(cuts2).Faces
                                blocks2 = Part.makeCompound([f.extrude(bvec) for f in plate2])
                                interval = extv.Length/(fsize)
                                entires = int(interval)
                                rest = (interval - entires)
                                for i in range(entires):
                                    if i % 2: # odd
                                        b = blocks2.copy()
                                    else:
                                        b = blocks1.copy()
                                    if i:
                                        t = FreeCAD.Vector(svec)
                                        t.multiply(i)
                                        b.translate(t)
                                    blocks.append(b)
                                if rest:
                                    rest = extv.Length-(entires*fsize)
                                    rvec = FreeCAD.Vector(n)
                                    rvec.multiply(rest)
                                    if entires % 2:
                                        b = Part.makeCompound([f.extrude(rvec) for f in plate2])
                                    else:
                                        b = Part.makeCompound([f.extrude(rvec) for f in plate1])
                                    t = FreeCAD.Vector(svec)
                                    t.multiply(entires)
                                    b.translate(t)
                                    blocks.append(b)
                                if blocks:
                                    base = Part.makeCompound(blocks)
                            else:
                                FreeCAD.Console.PrintWarning(translate("Arch","Error computing block cuts for wall")+obj.Label+"\n")
                        else:
                            FreeCAD.Console.PrintWarning(translate("Arch","Cannot compute blocks for wall")+obj.Label+"\n")

            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                            base = sh
                        else:
                            FreeCAD.Console.PrintWarning(translate("Arch","This mesh is an invalid solid")+"\n")
                            obj.Base.ViewObject.show()
        if not base:
            FreeCAD.Console.PrintError(translate("Arch","Error: Invalid base object")+"\n")
            return

        base = self.processSubShapes(obj,base,pl)
        self.applyShape(obj,base,pl)

        # count blocks
        if hasattr(obj,"MakeBlocks"):
            if obj.MakeBlocks:
                fvol = obj.BlockLength.Value * obj.BlockHeight.Value * obj.Width.Value
                if fvol:
                    #print("base volume:",fvol)
                    #for s in base.Solids:
                        #print(abs(s.Volume - fvol))
                    ents = [s for s in base.Solids if abs(s.Volume - fvol) < 1]
                    obj.CountEntire = len(ents)
                    obj.CountBroken = len(base.Solids) - len(ents)
                else:
                    obj.CountEntire = 0
                    obj.CountBroken = 0

        # set the length property
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.Edges:
                    if not obj.Base.Shape.Faces:
                        if hasattr(obj.Base.Shape,"Length"):
                            l = obj.Base.Shape.Length
                            if obj.Length.Value != l:
                                obj.Length = l
Esempio n. 20
0
 def execute(self,obj):
     "builds the wall shape"
     
     import Part, DraftGeomUtils
     pl = obj.Placement
     normal,length,width,height = self.getDefaultValues(obj)
     base = None
     
     # computing a shape from scratch
     if not obj.Base:
         if length and width and height:
             base = Part.makeBox(length,width,height)
         else:
             FreeCAD.Console.PrintError(str(translate("Arch","Error: Unable to compute a base shape")))
             return
     else:
         # computing a shape from a base object
         if obj.Base.isDerivedFrom("Part::Feature"):
             if not obj.Base.Shape.isNull():
                 if obj.Base.Shape.isValid():
                     base = obj.Base.Shape.copy()
                     face = None
                     if hasattr(obj,"Face"):
                         if obj.Face:
                             if len(base.Faces) >= obj.Face:
                                 face = base.Faces[obj.Face-1]
                     if face:
                         # wall is based on a face
                         normal = face.normalAt(0,0)
                         if normal.getAngle(Vector(0,0,1)) > math.pi/4:
                             normal.multiply(width)
                             base = face.extrude(normal)
                             if obj.Align == "Center":
                                 base.translate(normal.negative().multiply(0.5))
                             elif obj.Align == "Right":
                                 base.translate(normal.negative())
                         else:
                             normal.multiply(height)
                             base = face.extrude(normal)
                     elif base.Solids:
                         pass
                     elif (len(base.Faces) == 1) and (not obj.ForceWire):
                         if height:
                             normal.multiply(height)
                             base = base.extrude(normal)
                     elif len(base.Wires) >= 1:
                         temp = None
                         for wire in obj.Base.Shape.Wires:
                             sh = self.getBase(obj,wire,normal,width,height)
                             if temp:
                                 temp = temp.fuse(sh)
                             else:
                                 temp = sh
                         base = temp
                     elif base.Edges:
                         wire = Part.Wire(base.Edges)
                         if wire:
                             sh = self.getBase(obj,wire,normal,width,height)
                             if sh:
                                 base = sh
                     else:
                         base = None
                         FreeCAD.Console.PrintError(str(translate("Arch","Error: Invalid base object")))
                     
         elif obj.Base.isDerivedFrom("Mesh::Feature"):
             if obj.Base.Mesh.isSolid():
                 if obj.Base.Mesh.countComponents() == 1:
                     sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                     if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                         base = sh
                     else:
                         FreeCAD.Console.PrintWarning(str(translate("Arch","This mesh is an invalid solid")))
                         obj.Base.ViewObject.show()
                     
     base = self.processSubShapes(obj,base,pl)
     
     if base:
         if not base.isNull():
             if base.isValid() and base.Solids:
                 if base.Volume < 0:
                     base.reverse()
                 if base.Volume < 0:
                     FreeCAD.Console.PrintError(str(translate("Arch","Couldn't compute the wall shape")))
                     return
                 try:
                     base = base.removeSplitter()
                 except:
                     FreeCAD.Console.PrintError(str(translate("Arch","Error removing splitter from wall shape")))
                 obj.Shape = base
                 if not pl.isNull():
                     obj.Placement = pl
Esempio n. 21
0
 def execute(self,obj):
     "builds the wall shape"
     
     import Part, DraftGeomUtils
     pl = obj.Placement
     normal,length,width,height = self.getDefaultValues(obj)
     base = None
     
     # computing a shape from scratch
     if not obj.Base:
         if length and width and height:
             base = Part.makeBox(length,width,height)
         else:
             FreeCAD.Console.PrintError(str(translate("Arch","Error: Unable to compute a base shape")))
             return
     else:
         # computing a shape from a base object
         if obj.Base.isDerivedFrom("Part::Feature"):
             if not obj.Base.Shape.isNull():
                 if obj.Base.Shape.isValid():
                     base = obj.Base.Shape.copy()
                     face = None
                     if hasattr(obj,"Face"):
                         if obj.Face:
                             if len(base.Faces) >= obj.Face:
                                 face = base.Faces[obj.Face-1]
                     if face:
                         # wall is based on a face
                         normal = face.normalAt(0,0)
                         if normal.getAngle(Vector(0,0,1)) > math.pi/4:
                             normal.multiply(width)
                             base = face.extrude(normal)
                             if obj.Align == "Center":
                                 base.translate(normal.negative().multiply(0.5))
                             elif obj.Align == "Right":
                                 base.translate(normal.negative())
                         else:
                             normal.multiply(height)
                             base = face.extrude(normal)
                     elif base.Solids:
                         pass
                     elif (len(base.Faces) == 1) and (not obj.ForceWire):
                         if height:
                             normal.multiply(height)
                             base = base.extrude(normal)
                     elif len(base.Wires) >= 1:
                         temp = None
                         for wire in obj.Base.Shape.Wires:
                             sh = self.getBase(obj,wire,normal,width,height)
                             if temp:
                                 temp = temp.fuse(sh)
                             else:
                                 temp = sh
                         base = temp
                     elif base.Edges:
                         wire = Part.Wire(base.Edges)
                         if wire:
                             sh = self.getBase(obj,wire,normal,width,height)
                             if sh:
                                 base = sh
                     else:
                         base = None
                         FreeCAD.Console.PrintError(str(translate("Arch","Error: Invalid base object")))
                     
         elif obj.Base.isDerivedFrom("Mesh::Feature"):
             if obj.Base.Mesh.isSolid():
                 if obj.Base.Mesh.countComponents() == 1:
                     sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                     if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
                         base = sh
                     else:
                         FreeCAD.Console.PrintWarning(str(translate("Arch","This mesh is an invalid solid")))
                         obj.Base.ViewObject.show()
                     
     base = self.processSubShapes(obj,base,pl)
     
     if base:
         if not base.isNull():
             if base.isValid() and base.Solids:
                 if base.Volume < 0:
                     base.reverse()
                 if base.Volume < 0:
                     FreeCAD.Console.PrintError(str(translate("Arch","Couldn't compute the wall shape")))
                     return
                 try:
                     base = base.removeSplitter()
                 except:
                     FreeCAD.Console.PrintError(str(translate("Arch","Error removing splitter from wall shape")))
                 obj.Shape = base
                 if not pl.isNull():
                     obj.Placement = pl
Esempio n. 22
0
    def execute(self, obj):
        "creates the panel shape"

        if self.clone(obj):
            return

        import Part, DraftGeomUtils

        # base tests
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Base.Shape.isNull():
                    return
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if not obj.Base.Mesh.isSolid():
                    return
        else:
            if obj.Length.Value:
                length = obj.Length.Value
            else:
                return
            if obj.Width.Value:
                width = obj.Width.Value
            else:
                return
        if obj.Thickness.Value:
            thickness = obj.Thickness.Value
        else:
            if not obj.Base:
                return
            elif obj.Base.isDerivedFrom("Part::Feature"):
                if not obj.Base.Shape.Solids:
                    return

        # creating base shape
        pl = obj.Placement
        base = None
        normal = None
        if hasattr(obj, "Normal"):
            if obj.Normal.Length > 0:
                normal = Vector(obj.Normal)
                normal.normalize()
                normal.multiply(thickness)
        baseprofile = None
        if obj.Base:
            base = obj.Base.Shape.copy()
            if not base.Solids:
                p = FreeCAD.Placement(obj.Base.Placement)
                if base.Faces:
                    baseprofile = base
                    if not normal:
                        normal = baseprofile.Faces[0].normalAt(
                            0, 0).multiply(thickness)
                    base = base.extrude(normal)
                elif base.Wires:
                    fm = False
                    if hasattr(obj, "FaceMaker"):
                        if obj.FaceMaker != "None":
                            try:
                                base = Part.makeFace(
                                    base.Wires,
                                    "Part::FaceMaker" + str(obj.FaceMaker))
                                fm = True
                            except:
                                FreeCAD.Console.PrintError(
                                    translate("Arch",
                                              "Facemaker returned an error") +
                                    "\n")
                                return
                    if not fm:
                        closed = True
                        for w in base.Wires:
                            if not w.isClosed():
                                closed = False
                        if closed:
                            baseprofile = ArchCommands.makeFace(base.Wires)
                            if not normal:
                                normal = baseprofile.normalAt(
                                    0, 0).multiply(thickness)
                            base = baseprofile.extrude(normal)
                elif obj.Base.isDerivedFrom("Mesh::Feature"):
                    if obj.Base.Mesh.isSolid():
                        if obj.Base.Mesh.countComponents() == 1:
                            sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                            if sh.isClosed() and sh.isValid() and sh.Solids:
                                base = sh
        else:
            if not normal:
                normal = Vector(0, 0, 1).multiply(thickness)
            l2 = length / 2 or 0.5
            w2 = width / 2 or 0.5
            v1 = Vector(-l2, -w2, 0)
            v2 = Vector(l2, -w2, 0)
            v3 = Vector(l2, w2, 0)
            v4 = Vector(-l2, w2, 0)
            base = Part.makePolygon([v1, v2, v3, v4, v1])
            baseprofile = Part.Face(base)
            base = baseprofile.extrude(normal)

        if hasattr(obj, "Area"):
            if baseprofile:
                obj.Area = baseprofile.Area

        if hasattr(obj, "WaveLength"):
            if baseprofile and obj.WaveLength.Value and obj.WaveHeight.Value:
                # corrugated element
                bb = baseprofile.BoundBox
                bb.enlarge(bb.DiagonalLength)
                p1 = Vector(bb.getPoint(0).x, bb.getPoint(0).y, bb.Center.z)
                if obj.WaveType == "Curved":
                    p2 = p1.add(
                        Vector(obj.WaveLength.Value / 2, 0,
                               obj.WaveHeight.Value))
                    p3 = p2.add(
                        Vector(obj.WaveLength.Value / 2, 0,
                               -obj.WaveHeight.Value))
                    e1 = Part.Arc(p1, p2, p3).toShape()
                    p4 = p3.add(
                        Vector(obj.WaveLength.Value / 2, 0,
                               -obj.WaveHeight.Value))
                    p5 = p4.add(
                        Vector(obj.WaveLength.Value / 2, 0,
                               obj.WaveHeight.Value))
                    e2 = Part.Arc(p3, p4, p5).toShape()
                else:
                    if obj.WaveHeight.Value < obj.WaveLength.Value:
                        p2 = p1.add(
                            Vector(obj.WaveHeight.Value, 0,
                                   obj.WaveHeight.Value))
                        p3 = p2.add(
                            Vector(
                                obj.WaveLength.Value -
                                2 * obj.WaveHeight.Value, 0, 0))
                        p4 = p3.add(
                            Vector(obj.WaveHeight.Value, 0,
                                   -obj.WaveHeight.Value))
                        e1 = Part.makePolygon([p1, p2, p3, p4])
                        p5 = p4.add(
                            Vector(obj.WaveHeight.Value, 0,
                                   -obj.WaveHeight.Value))
                        p6 = p5.add(
                            Vector(
                                obj.WaveLength.Value -
                                2 * obj.WaveHeight.Value, 0, 0))
                        p7 = p6.add(
                            Vector(obj.WaveHeight.Value, 0,
                                   obj.WaveHeight.Value))
                        e2 = Part.makePolygon([p4, p5, p6, p7])
                    else:
                        p2 = p1.add(
                            Vector(obj.WaveLength.Value / 2, 0,
                                   obj.WaveHeight.Value))
                        p3 = p2.add(
                            Vector(obj.WaveLength.Value / 2, 0,
                                   -obj.WaveHeight.Value))
                        e1 = Part.makePolygon([p1, p2, p3])
                        p4 = p3.add(
                            Vector(obj.WaveLength.Value / 2, 0,
                                   -obj.WaveHeight.Value))
                        p5 = p4.add(
                            Vector(obj.WaveLength.Value / 2, 0,
                                   obj.WaveHeight.Value))
                        e2 = Part.makePolygon([p3, p4, p5])
                edges = [e1, e2]
                for i in range(int(bb.XLength / (obj.WaveLength.Value * 2))):
                    e1 = e1.copy()
                    e1.translate(Vector(obj.WaveLength.Value * 2, 0, 0))
                    e2 = e2.copy()
                    e2.translate(Vector(obj.WaveLength.Value * 2, 0, 0))
                    edges.extend([e1, e2])
                basewire = Part.Wire(edges)
                baseface = basewire.extrude(Vector(0, bb.YLength, 0))
                base = baseface.extrude(Vector(0, 0, thickness))
                rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), normal)
                base.rotate(bb.Center, rot.Axis, math.degrees(rot.Angle))
                if obj.WaveDirection.Value:
                    base.rotate(bb.Center, normal, obj.WaveDirection.Value)
                n1 = normal.negative().normalize().multiply(
                    obj.WaveHeight.Value * 2)
                self.vol = baseprofile.copy()
                self.vol.translate(n1)
                self.vol = self.vol.extrude(n1.negative().multiply(2))
                base = self.vol.common(base)
                base = base.removeSplitter()
                if not base:
                    FreeCAD.Console.PrintError(
                        transpate("Arch", "Error computing shape of ") +
                        obj.Label + "\n")
                    return False

        if base and (obj.Sheets > 1) and normal and thickness:
            bases = [base]
            for i in range(1, obj.Sheets):
                n = FreeCAD.Vector(normal).normalize().multiply(i * thickness)
                b = base.copy()
                b.translate(n)
                bases.append(b)
            base = Part.makeCompound(bases)

        if base and normal and hasattr(obj, "Offset"):
            if obj.Offset.Value:
                v = DraftVecUtils.scaleTo(normal, obj.Offset.Value)
                base.translate(v)

        # process subshapes
        base = self.processSubShapes(obj, base, pl)

        # applying
        if base:
            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(
                            translate("Arch", "Couldn't compute a shape"))
                        return
                    base = base.removeSplitter()
                    obj.Shape = base
                    if not pl.isNull():
                        obj.Placement = pl
Esempio n. 23
0
    def createGeometry(self,obj):
        import Part, DraftGeomUtils
        
        # getting default values
        height = width = length = 1
        if hasattr(obj,"Length"):
            if obj.Length:
                length = obj.Length
        if hasattr(obj,"Width"):
            if obj.Width:
                width = obj.Width
        if hasattr(obj,"Height"):
            if obj.Height:
                height = obj.Height

        # creating base shape
        pl = obj.Placement
        base = None
        if obj.Base:
            if obj.Base.isDerivedFrom("Part::Feature"):
                if obj.Normal == Vector(0,0,0):
                    p = FreeCAD.Placement(obj.Base.Placement)
                    normal = p.Rotation.multVec(Vector(0,0,1))
                else:
                    normal = Vector(obj.Normal)
                normal = normal.multiply(height)
                base = obj.Base.Shape.copy()
                if base.Solids:
                    pass
                elif base.Faces:
                    base = base.extrude(normal)
                elif (len(base.Wires) == 1):
                    if base.Wires[0].isClosed():
                        base = Part.Face(base.Wires[0])
                        base = base.extrude(normal)
            elif obj.Base.isDerivedFrom("Mesh::Feature"):
                if obj.Base.Mesh.isSolid():
                    if obj.Base.Mesh.countComponents() == 1:
                        sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                        if sh.isClosed() and sh.isValid() and sh.Solids:
                            base = sh
        else:
            if obj.Normal == Vector(0,0,0):
                normal = Vector(0,0,1)
            else:
                normal = Vector(obj.Normal)
            normal = normal.multiply(height)
            l2 = length/2 or 0.5
            w2 = width/2 or 0.5
            v1 = Vector(-l2,-w2,0)
            v2 = Vector(l2,-w2,0)
            v3 = Vector(l2,w2,0)
            v4 = Vector(-l2,w2,0)
            base = Part.makePolygon([v1,v2,v3,v4,v1])
            base = Part.Face(base)
            base = base.extrude(normal)
            
        base = self.processSubShapes(obj,base)
            
        if base:
            # applying axes
            pts = self.getAxisPoints(obj)
            apl = self.getAxisPlacement(obj)
            if pts:
                fsh = []
                for i in range(len(pts)):
                    if hasattr(obj,"Exclude"):
                        if i in obj.Exclude:
                            continue
                    sh = base.copy()
                    if apl:
                        sh.Placement.Rotation = apl.Rotation
                    sh.translate(pts[i])
                    fsh.append(sh)
                    obj.Shape = Part.makeCompound(fsh)

            # finalizing
            
            else:
                if base:
                    if not base.isNull():
                        if base.isValid() and base.Solids:
                            if base.Volume < 0:
                                base.reverse()
                            if base.Volume < 0:
                                FreeCAD.Console.PrintError(str(translate("Arch","Couldn't compute the wall shape")))
                                return
                            base = base.removeSplitter()
                            obj.Shape = base
                if not DraftGeomUtils.isNull(pl):
                    obj.Placement = pl
Esempio n. 24
0
    def createGeometry(self, obj):
        "builds the wall shape"

        if not obj.Base:
            return

        import Part, DraftGeomUtils

        flat = False
        if hasattr(obj.ViewObject, "DisplayMode"):
            flat = (obj.ViewObject.DisplayMode == "Flat 2D")

        width = 1.0
        if hasattr(obj, "Width"):
            if obj.Width:
                width = obj.Width

        def getbase(wire):
            "returns a full shape from a base wire"
            dvec = DraftGeomUtils.vec(wire.Edges[0]).cross(normal)
            dvec.normalize()
            if obj.Align == "Left":
                dvec = dvec.multiply(width)
                w2 = DraftGeomUtils.offsetWire(wire, dvec)
                w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
                sh = DraftGeomUtils.bind(w1, w2)
            elif obj.Align == "Right":
                dvec = dvec.multiply(width)
                dvec = DraftVecUtils.neg(dvec)
                w2 = DraftGeomUtils.offsetWire(wire, dvec)
                w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
                sh = DraftGeomUtils.bind(w1, w2)
            elif obj.Align == "Center":
                dvec = dvec.multiply(width / 2)
                w1 = DraftGeomUtils.offsetWire(wire, dvec)
                dvec = DraftVecUtils.neg(dvec)
                w2 = DraftGeomUtils.offsetWire(wire, dvec)
                sh = DraftGeomUtils.bind(w1, w2)
            # fixing self-intersections
            sh.fix(0.1, 0, 1)
            if height and (not flat):
                norm = Vector(normal).multiply(height)
                sh = sh.extrude(norm)
            return sh

        pl = obj.Placement

        # getting default values
        height = normal = None
        if obj.Height:
            height = obj.Height
        else:
            for p in obj.InList:
                if Draft.getType(p) == "Floor":
                    height = p.Height
        if not height: height = 1
        if obj.Normal == Vector(0, 0, 0):
            normal = Vector(0, 0, 1)
        else:
            normal = Vector(obj.Normal)

        # computing shape
        base = None
        if obj.Base.isDerivedFrom("Part::Feature"):
            if not obj.Base.Shape.isNull():
                if obj.Base.Shape.isValid():
                    base = obj.Base.Shape.copy()
                    if base.Solids:
                        pass
                    elif base.Faces and (not obj.ForceWire):
                        if height:
                            norm = normal.multiply(height)
                            base = base.extrude(norm)
                    elif base.Wires:
                        temp = None
                        for wire in obj.Base.Shape.Wires:
                            sh = getbase(wire)
                            if temp:
                                temp = temp.fuse(sh)
                            else:
                                temp = sh
                        base = temp
                    elif base.Edges:
                        wire = Part.Wire(base.Edges)
                        sh = getbase(wire)
                        if sh:
                            base = sh
                    else:
                        base = None
                        FreeCAD.Console.PrintError(
                            str(translate("Arch",
                                          "Error: Invalid base object")))

        elif obj.Base.isDerivedFrom("Mesh::Feature"):
            if obj.Base.Mesh.isSolid():
                if obj.Base.Mesh.countComponents() == 1:
                    sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
                    if sh.isClosed() and sh.isValid() and sh.Solids and (
                            not sh.isNull()):
                        base = sh
                    else:
                        FreeCAD.Console.PrintWarning(
                            str(
                                translate("Arch",
                                          "This mesh is an invalid solid")))
                        obj.Base.ViewObject.show()

        if base:

            for app in obj.Additions:
                if Draft.getType(app) == "Window":
                    # window
                    if app.Base and obj.Width:
                        f = self.getSubVolume(app.Base, width)
                        if f:
                            base = base.cut(f)
                elif Draft.isClone(app, "Window"):
                    if app.Objects[0].Base and width:
                        f = self.getSubVolume(app.Objects[0].Base, width,
                                              app.Placement)
                        if f:
                            base = base.cut(f)
                elif app.isDerivedFrom("Part::Feature"):
                    if app.Shape:
                        if not app.Shape.isNull():
                            base = base.fuse(app.Shape)
                            app.ViewObject.hide()  #to be removed
            for hole in obj.Subtractions:
                if Draft.getType(hole) == "Window":
                    # window
                    if hole.Base and obj.Width:
                        f = self.getSubVolume(hole.Base, width)
                        if f:
                            base = base.cut(f)
                elif Draft.isClone(hole, "Window"):
                    if hole.Objects[0].Base and width:
                        f = self.getSubVolume(hole.Objects[0].Base, width,
                                              hole.Placement)
                        if f:
                            base = base.cut(f)
                elif hole.isDerivedFrom("Part::Feature"):
                    if hole.Shape:
                        if not hole.Shape.isNull():
                            base = base.cut(hole.Shape)
                            hole.ViewObject.hide()  # to be removed

            if not base.isNull():
                if base.isValid() and base.Solids:
                    if base.Volume < 0:
                        base.reverse()
                    if base.Volume < 0:
                        FreeCAD.Console.PrintError(
                            str(
                                translate("Arch",
                                          "Couldn't compute the wall shape")))
                        return
                    try:
                        base = base.removeSplitter()
                    except:
                        FreeCAD.Console.PrintError(
                            str(
                                translate(
                                    "Arch",
                                    "Error removing splitter from wall shape"))
                        )
                    obj.Shape = base
                    if not DraftGeomUtils.isNull(pl):
                        obj.Placement = pl