Test Create ArchRebar2 Object

A forum dedicated to the Arch module development
User avatar
bernd
Posts: 3869
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Test Create ArchRebar2 Object

Postby bernd » Tue Aug 30, 2016 3:13 pm

@Yorik:
Do you know if there has ever been some afford to make an editor for the Property::Map?
User avatar
yorik
Site Admin
Posts: 8553
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Test Create ArchRebar2 Object

Postby yorik » Wed Aug 31, 2016 12:10 am

bernd wrote:Do you know if there has ever been some afford to make an editor for the Property::Map?

No I don't think so...
chakkree
Posts: 134
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Test Create ArchRebar2 Object

Postby chakkree » Mon Feb 20, 2017 9:29 am

ArchRebar2 --
New Concept -- Modified from ArchPipe
but Dwire can not dynamic change position(x,y,z) of points.
I make a new class that inherits from Draft._Wire. In DataView tab, you can change the value of A, B, and C.(distance of U-shape rebar)

Code: Select all

# -*- coding: utf8 -*-

#
#  Modified from ArchPipe
#*   Copyright (c) 2017                *
#*   chakkree tiyawongsuwan                              *

import FreeCAD, ArchComponent
import Draft



def makeRebar2(baseobj=None,diameter=0,length=0,placement=None,name="Rebar"):
   
    "makeRebar2([baseobj,diamerter,length,placement,name]): creates an Rebar object from the given base object"
   
    obj= FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
    obj.Label = name
    _Rebar2(obj)
    if FreeCAD.GuiUp:
        _ViewProviderRebar2(obj.ViewObject)
        if baseobj:
            baseobj.ViewObject.hide()
    if baseobj:
        obj.Base = baseobj
    else:
        if length:
            obj.Length = length
        else:
            obj.Length = 1000
    if diameter:
        obj.Diameter = diameter
    else:
        p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
        obj.Diameter = p.GetFloat("RebarDiameter",50)
    if placement:
        obj.Placement = placement
    return obj

class _Rebar2(ArchComponent.Component):
   
   
    def __init__(self,obj):

        ArchComponent.Component.__init__(self,obj)
        self.Type = "Rebar"
        obj.Role = ["ReinforcingBar"]
        obj.addProperty("App::PropertyLength", "Diameter",    "Arch", "The diameter of this pipe, if not based on a profile")
        obj.addProperty("App::PropertyLength", "Length",      "Arch", "The length of this pipe, if not based on an edge")
        obj.addProperty("App::PropertyLink",   "Profile",     "Arch", "An optional closed profile to base this pipe on")
        #obj.addProperty("App::PropertyLength", "OffsetStart", "Arch", QT_TRANSLATE_NOOP("App::Property","Offset from the start point"))
        #obj.addProperty("App::PropertyLength", "OffsetEnd",   "Arch", QT_TRANSLATE_NOOP("App::Property","Offset from the end point"))

    def execute(self,obj):
       
        import Part,DraftGeomUtils,math
        pl = obj.Placement
        w = self.getWire(obj)
        if not w:
            FreeCAD.Console.PrintError("Unable to build the base path\n")
            return
        """
        if obj.OffsetStart.Value:
            e = w.Edges[0]
            v = e.Vertexes[-1].Point.sub(e.Vertexes[0].Point).normalize()
            v.multiply(obj.OffsetStart.Value)
            e = Part.LineSegment(e.Vertexes[0].Point.add(v),e.Vertexes[-1].Point).toShape()
            w = Part.Wire([e]+w.Edges[1:])
        if obj.OffsetEnd.Value:
            e = w.Edges[-1]
            v = e.Vertexes[0].Point.sub(e.Vertexes[-1].Point).normalize()
            v.multiply(obj.OffsetEnd.Value)
            e = Part.LineSegment(e.Vertexes[-1].Point.add(v),e.Vertexes[0].Point).toShape()
            w = Part.Wire(w.Edges[:-1]+[e])
        """
        p = self.getProfile(obj)
        if not p:
            FreeCAD.Console.PrintError(translate("Arch","Unable to build the profile\n"))
            return
        # move and rotate the profile to the first point
        delta = w.Vertexes[0].Point-p.CenterOfMass
        p.translate(delta)
        v1 = w.Vertexes[1].Point-w.Vertexes[0].Point
        v2 = DraftGeomUtils.getNormal(p)
        rot = FreeCAD.Rotation(v2,v1)
        p.rotate(p.CenterOfMass,rot.Axis,math.degrees(rot.Angle))
        try:
            sh = w.makePipeShell([p],True,False,2)
        except:
            FreeCAD.Console.PrintError(translate("Arch","Unable to build the Rebar\n"))
        else:
            obj.Shape = sh
            if obj.Base:
                obj.Length = w.Length
            else:
                obj.Placement = pl
   
    def getWire(self,obj):
       
        import Part
        if obj.Base:
            if not obj.Base.isDerivedFrom("Part::Feature"):
                FreeCAD.Console.PrintError("The base object is not a Part\n")
                return
            if len(obj.Base.Shape.Wires) != 1:
                FreeCAD.Console.PrintError("Too many wires in the base shape\n")
                return
            if obj.Base.Shape.Wires[0].isClosed():
                FreeCAD.Console.PrintError("The base wire is closed\n")
                return
            w = obj.Base.Shape.Wires[0]
        else:
            if obj.Length.Value == 0:
                return
            w = Part.Wire([Part.LineSegment(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,obj.Length.Value)).toShape()])
        return w
   
    def getProfile(self,obj):
       
        import Part
        if obj.Profile:
            if not obj.Profile.isDerivedFrom("Part::Part2DObject"):
                FreeCAD.Console.PrintError(translate("Arch","The profile is not a 2D Part\n"))
                return
            if len(obj.Profile.Shape.Wires) != 1:
                FreeCAD.Console.PrintError(translate("Arch","Too many wires in the profile\n"))
                return
            if not obj.Base.Profile.Wires[0].isClosed():
                FreeCAD.Console.PrintError(translate("Arch","The profile is not closed\n"))
                return
            p = obj.Base.Profile.Wires[0]
        else:
            if obj.Diameter.Value == 0:
                return
            p = Part.Wire([Part.Circle(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),obj.Diameter.Value/2).toShape()])
        return p


class _ViewProviderRebar2(ArchComponent.ViewProviderComponent):
    "A View Provider for the Pipe object"

    def __init__(self,vobj):

        ArchComponent.ViewProviderComponent.__init__(self,vobj)
        vobj.ShapeColor = (0.667,0.000,0.000)

    def getIcon(self):

        import Arch_rc
        return ":/icons/Arch_Rebar_Tree.svg"

class ShapeU(Draft._Wire):
    def __init__(self,obj):
        Draft._Wire.__init__(self,obj)
        obj.addProperty("App::PropertyLength", "A",    "Rebar", "The Length A of U-shape rebar")
        obj.addProperty("App::PropertyLength", "B",    "Rebar", "The Length B of U-shape rebar")
        obj.addProperty("App::PropertyLength", "C",    "Rebar", "The Length C of U-shape rebar")

    def execute(self,obj):
        pointslist=[
         FreeCAD.Vector(0,0,obj.A),
         FreeCAD.Vector(0,0,0),
         FreeCAD.Vector(obj.B,0,0),
         FreeCAD.Vector(obj.B,0,obj.C),
        ]
        obj.Points = pointslist
        obj.Closed = False
        obj.MakeFace = False
        obj.Support = None
       
        Draft._Wire.execute(self,obj)


class ShapeStirrup(Draft._Wire):
    def __init__(self,obj):
        Draft._Wire.__init__(self,obj)
        obj.addProperty("App::PropertyLength", "A",    "Rebar", "The Length A of U-shape rebar")
        obj.addProperty("App::PropertyLength", "B",    "Rebar", "The Length B of U-shape rebar")

    def execute(self,obj):
        pointslist=[
         FreeCAD.Vector(0,0,obj.A),
         FreeCAD.Vector(0,0,0),
         FreeCAD.Vector(obj.B,0,0),
         FreeCAD.Vector(obj.B,0,obj.C),
        ]
        obj.Points = pointslist
        obj.Closed = False
        obj.MakeFace = False
        obj.Support = None
       
        Draft._Wire.execute(self,obj)

       
if __name__=='__main__':
    """
    rebar1 = makeRebar2()

    points=[
     FreeCAD.Vector(150,0,191),
     FreeCAD.Vector(0,0,191),
     FreeCAD.Vector(0,0,0),
     FreeCAD.Vector(891,0,0),
     FreeCAD.Vector(891,0,191),
     FreeCAD.Vector(741,0,191),
    ]

    line = Draft.makeWire(points,closed=False,face=False,support=None)
    dia2 = 12
    line.FilletRadius = 2*dia2 + 0.5*dia2
    rebar2 = makeRebar2(line)
    """


    dia3 = 12
    name ='shapeU'
    line3= FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",name)
    ShapeU(line3)
    Draft._ViewProviderWire(line3.ViewObject)
    line3.A = 300
    line3.B = 1000
    line3.C = 500

    line3.MakeFace = False
    line3.FilletRadius = 2*dia3 +0.5*dia3

    rebar3 = makeRebar2(line3)
    rebar3.Diameter = dia3
    rebar3.Placement.Base = FreeCAD.Vector(0 , 1000 , 0)

    FreeCAD.ActiveDocument.recompute()


Result form macro:
NewArchRebar2.png
NewArchRebar2.png (231.12 KiB) Viewed 71 times