Exemplo n.º 1
0
    def updateGraphicObjects(self, points, display):

        self.GHPolygon = []

        for i in self.PolygonPoints:
            if i in range(len(points)):
                self.GHPolygon.Add(points[i].Point)
            else:
                print('polygon point %d does not exist' % i)

        self.GHPolygon.Close()
        self.GHFace = BRepBuilderAPI_MakeFace(self.GHPolygon.Wire())
        self.GHShape = BRepBuilderAPI_MakeShape.Shape(self.GHFace)

        #display.DisplayShape(self.GHShape)

        if len(self.Opening) > 0:
            print('processing openings')
            for i in range(len(self.Opening)):
                openingpolygon = BRepBuilderAPI_MakePolygon()
                for j in self.Opening[i]:
                    openingpolygon.Add(points[j].Point)
                openingpolygon.Close()
                openingface = BRepBuilderAPI_MakeFace(openingpolygon.Wire())
                openingshape = BRepBuilderAPI_MakeShape.Shape(openingface)
                cut = BRepAlgoAPI_Cut(self.GHShape, openingshape)
                self.GHShape = cut.Shape()

        #display.DisplayShape(self.GHShape)

        # calculate Area
        Props = GProp_GProps()
        brepgprop.SurfaceProperties(self.GHShape, Props)
        self.Area = Props.Mass()
Exemplo n.º 2
0
 def update_shape(self, change):
     d = self.declaration
     shape = BRepBuilderAPI_MakePolygon()
     for child in self.children():
         if isinstance(child, (OccPoint, OccVertex)):
             shape.Add(child.shape)
     self.shape = shape
Exemplo n.º 3
0
 def create_shape(self):
     shape = BRepBuilderAPI_MakePolygon()
     for m in re.finditer(r'(\-?\d+\.?\d*),(\-?\d+\.?\d*)\s+',
                          self.element.attrib.get('points', '')):
         x, y = map(float, m.groups())
         shape.Add(gp_Pnt(x, y, 0))
     return shape.Wire()
Exemplo n.º 4
0
 def create_shape(self):
     d = self.declaration
     shape = BRepBuilderAPI_MakePolygon()
     for p in d.points:
         shape.Add(gp_Pnt(*p))
     if d.closed:
         shape.Close()
     self.shape = shape
Exemplo n.º 5
0
    def test_approximate(self):
        #my_surface = approximate_surface(pts)
        p1, p2, p3, p4, p5 = Point(0, 0, 0), Point(0, 10, 0), Point(
            0, 10, 10), Point(0, 0, 10), Point(5, 5, 5)
        poly = BRepBuilderAPI_MakePolygon()
        map(poly.Add, [p1, p2, p3, p4, p1])
        poly.Build()

        my_surf = build_plate([poly], [Point(-1, -1, -1)])
        sh = my_surf.Shape()
        display.DisplayShape(sh)
Exemplo n.º 6
0
    def makePolygon(cls, listOfVertices, forConstruction=False):
        # convert list of tuples into Vectors.
        wire_builder = BRepBuilderAPI_MakePolygon()

        for v in listOfVertices:
            wire_builder.Add(v.toPnt())

        w = cls(wire_builder.Wire())
        w.forConstruction = forConstruction

        return w
Exemplo n.º 7
0
 def approximate(self):
     '''make a boundary representation of a surface that approximates the points'''
     self.make_bounding_box()
     #make the bounding box into a polygon
     poly = BRepBuilderAPI_MakePolygon()
     map(poly.Add, [
         self.bottom_left, self.bottom_right, self.top_left, self.top_right
     ])
     poly.Build()
     self.polygons = [poly]
     my_surf = build_plate(self.polygons, self.points)
     self.shape = my_surf.Shape()
     display.DisplayShape(self.shape)
Exemplo n.º 8
0
def make_polygon(pyptlist):
    array = []
    for pt in pyptlist:
        array.append(gp_Pnt(pt[0], pt[1], pt[2]))

    poly = BRepBuilderAPI_MakePolygon()
    map(poly.Add, array)
    poly.Build()
    poly.Close()

    wire = poly.Wire()
    occface = BRepBuilderAPI_MakeFace(wire)
    return occface.Face()
Exemplo n.º 9
0
def make_wire(pyptlist):
    '''
    if you want a close wire, make sure the pts the first pts too
    '''
    array = []
    for pt in pyptlist:
        array.append(gp_Pnt(pt[0], pt[1], pt[2]))

    poly = BRepBuilderAPI_MakePolygon()
    map(poly.Add, array)
    poly.Build()
    wire = poly.Wire()
    return wire
Exemplo n.º 10
0
    def polygon(self):  # creates openCad polygon
        l = self.lines
        l0 = l[0]
        if isinstance(l0, Line):
            print(l0.dr().mag())
            Pstart = l0.start.gpP()
            Pend = l0.end.gpP()
            pol = BRepBuilderAPI_MakePolygon(Pstart, Pend)

            for i in range(1, len(l)):
                if isinstance(l[i], Line):
                    Pstarti = l[i].start.gpP()
                    Pendi = l[i].end.gpP()
                    pol.Add(Pstarti)
                    pol.Add(Pendi)
            #pol.Add(Pstart)
            return pol
def make_closed_polygon(*args):
    poly = BRepBuilderAPI_MakePolygon()
    for pt in args:
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    poly.Build()
    poly.Close()
    result = poly.Wire()
    return result
Exemplo n.º 12
0
def make_closed_polygon(*args):
    poly = BRepBuilderAPI_MakePolygon()
    for pt in args:
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    poly.Build()
    poly.Close()
    with assert_isdone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result
Exemplo n.º 13
0
def make_polygon(args, closed=False):
    poly = BRepBuilderAPI_MakePolygon()
    for pt in args:
        # support nested lists
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    if closed:
        poly.Close()
    poly.Build()

    with assert_isdone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result
Exemplo n.º 14
0
class Surf:
    """

    Class holding surface properties;

    ID: ID of the surface [-]:
        int 1x1
    PolygonPoints
        array [nx1]
    Geometry: surface object
        tbd
    Normal: surface normal
        array [3x1]
    Area: surface area [m²]
        double 1x1
    Opening: opening polygons
        array [n x n]
    PartID: ID of the part to assign
        int 1x1

    Surface Definition:

                |      |
                |      |
    Side 1      |      |    Side 2
                |      |
            ------------------>   Surface normal
                |      |
                |      |
                |      |

     ------------------------------
     Side 1
     ------------------------------

    Side1_Zone: adjacent Zone ID of side 1 (surface normal origin)
        int 1x1

    Side1_Adj: adjacent area
        0: Auto (automatic allocation)
        1: Zone
        2: Outside Air
        3: Soil
        4: User specified

    Side1_HeatFlow: heat flow over side 1 surface; only applied if Side1Adj == 3
        int 1x1 or array [Time,Side1HeatFlow]
        Unit: [W]

    Side1_T: surface temperature
        int 1x1 or array [Time,Side1_T]
        Unit: [K]

    Side1_RelHum: adjacent relative humidity to side 1
        int 1x1 or array [Time,Side1_RelHum]
        Unit: [-]

    Side1_TAir: adjacent air temperature
        int 1x1 or array [Time,Side1_TAir]
        Unit: [K]

    Side1_TAir: adjacent air temperature
        int 1x1 or array [Time,Side1_TAir]
        Unit: [K]



     ------------------------------
     Side 2
     ------------------------------


    Side2_Zone: adjacent Zone ID of side 2 (surface normal origin)
        int 1x1

    Side2_Adj: adjacent area
        0: Auto (automatic allocation)
        1: Zone
        2: Outside Air
        3: Soil
        4: User specified

    Side2_HeatFlow: heat flow over side 2 surface; only applied if Side1Adj == 3
        int 1x1 or array [Time,Side1HeatFlow]
        Unit: [W]

    Side2_T: surface temperature
        int 1x1 or array [Time,Side1_T]
        Unit: [K]

    Side2_RelHum: adjacent relative humidity to side 2
        int 1x1 or array [Time,Side1_RelHum]
        Unit: [-]

    Side2_TAir: adjacent air temperature
        int 1x1 or array [Time,Side1_TAir]
        Unit: [K]

    Side2_TAir: adjacent air temperature
        int 1x1 or array [Time,Side1_TAir]
        Unit: [K]


    """
    def __init__(self, dict):
        # init with default values

        self.ID = []
        self.PolygonPoints = np.array([])
        self.Geometry = []
        self.Normal = []
        self.Area = []
        self.Opening = []
        self.PartID = []

        # ------------------------------
        # Side 1
        # ------------------------------

        self.Side1_Zone = []
        self.Side1_Adj = []
        self.Side1_HeatFlow = []
        self.Side1_T = []
        self.Side1_RelHum = []
        self.Side1_TAir = []

        # -----------------------------
        # Side 2
        # ------------------------------

        self.Side2_Zone = []
        self.Side2_Adj = []
        self.Side2_HeatFlow = []
        self.Side2_T = []
        self.Side2_RelHum = []
        self.Side2_TAir = []

        # ------------------------------
        # Graphic objects
        # ------------------------------

        self.GHPolygon = []
        self.GHFace = []
        self.GHShape = []

        # Overwrite default values with received entries
        for key in dict:
            setattr(self, key, dict[key])

    def createGraphicObjects(self, points, display):

        self.GHPolygon = BRepBuilderAPI_MakePolygon()

        for i in self.PolygonPoints:
            if i in range(len(points)):
                self.GHPolygon.Add(points[i].Point)
            else:
                print('polygon point %d does not exist' % i)

        self.GHPolygon.Close()
        self.GHFace = BRepBuilderAPI_MakeFace(self.GHPolygon.Wire())
        self.GHShape = BRepBuilderAPI_MakeShape.Shape(self.GHFace)

        #display.DisplayShape(self.GHShape)

        if len(self.Opening) > 0:
            print('processing openings')
            for i in range(len(self.Opening)):
                openingpolygon = BRepBuilderAPI_MakePolygon()
                for j in self.Opening[i]:
                    openingpolygon.Add(points[j].Point)
                openingpolygon.Close()
                openingface = BRepBuilderAPI_MakeFace(openingpolygon.Wire())
                openingshape = BRepBuilderAPI_MakeShape.Shape(openingface)
                Cut = BRepAlgoAPI_Cut(self.GHShape, openingshape)
                self.GHShape = Cut.Shape()

        #display.DisplayShape(self.GHShape)

        # calculate Area
        Props = GProp_GProps()
        brepgprop.SurfaceProperties(self.GHShape, Props)
        self.Area = Props.Mass()

        return display

    def update(self, dict):
        for key in dict:
            setattr(self, key, dict[key])

    def updateGraphicObjects(self, points, display):

        self.GHPolygon = []

        for i in self.PolygonPoints:
            if i in range(len(points)):
                self.GHPolygon.Add(points[i].Point)
            else:
                print('polygon point %d does not exist' % i)

        self.GHPolygon.Close()
        self.GHFace = BRepBuilderAPI_MakeFace(self.GHPolygon.Wire())
        self.GHShape = BRepBuilderAPI_MakeShape.Shape(self.GHFace)

        #display.DisplayShape(self.GHShape)

        if len(self.Opening) > 0:
            print('processing openings')
            for i in range(len(self.Opening)):
                openingpolygon = BRepBuilderAPI_MakePolygon()
                for j in self.Opening[i]:
                    openingpolygon.Add(points[j].Point)
                openingpolygon.Close()
                openingface = BRepBuilderAPI_MakeFace(openingpolygon.Wire())
                openingshape = BRepBuilderAPI_MakeShape.Shape(openingface)
                cut = BRepAlgoAPI_Cut(self.GHShape, openingshape)
                self.GHShape = cut.Shape()

        #display.DisplayShape(self.GHShape)

        # calculate Area
        Props = GProp_GProps()
        brepgprop.SurfaceProperties(self.GHShape, Props)
        self.Area = Props.Mass()
def evolved_shape():
    make_polygon = BRepBuilderAPI_MakePolygon()
    make_polygon.Add(gp_Pnt(0., 0., 0.))
    make_polygon.Add(gp_Pnt(200., 0., 0.))
    make_polygon.Add(gp_Pnt(200., 200., 0.))
    make_polygon.Add(gp_Pnt(0., 200., 0.))
    make_polygon.Add(gp_Pnt(0., 0., 0.))
    wprof = BRepBuilderAPI_MakePolygon(gp_Pnt(0., 0., 0.), gp_Pnt(-60., -60., -200.))
    make_evolved = BRepOffsetAPI_MakeEvolved(make_polygon.Wire(),  # spine
                                             wprof.Wire(),  # profile
                                             GeomAbs_Arc,  # join
                                             True,  # AxeProf
                                             False,  # Solid
                                             True,  # ProfOnSpine
                                             0.0001)
    make_evolved.Build()
    display.DisplayShape(wprof.Shape(), color='WHITE')
    display.DisplayShape(make_polygon.Shape(), color='BLUE')
    display.DisplayShape(make_evolved.Shape(), update=True)
Exemplo n.º 16
0
 def __init__(self):
     self.bottom_left, self.bottom_right, self.top_left, self.top_right = Point(
         0, 0, 0), Point(0, 0, 0), Point(0, 0, 0), Point(0, 0, 0)
     self.points = []  #points that we want to approximate
     self.shape = Shape()
     self.polygons = [BRepBuilderAPI_MakePolygon()]
Exemplo n.º 17
0
    full_curve = BRepBuilderAPI_MakeWire(full_curve.Wire(), inner_edge)
else:
    outer_curve = BRepBuilderAPI_MakeWire(*[w[1], w[2]])
    full_curve = BRepBuilderAPI_MakeWire(*[w[0], w[1], w[2], w[3]])
    full_curve = BRepBuilderAPI_MakeWire(full_curve.Wire(), inner_edge)

# extract winding pack dimesions
ro, zo = loop[0]['p0']['r'], loop[0]['p0']['z']
rtop, ztop = loop[0]['p3']['r'], loop[0]['p3']['z']
width, depth = cs['winding_pack']['width'], cs['winding_pack']['depth']
inboard, outboard = cs['case']['inboard'], cs['case']['outboard']
external = cs['case']['external']
side, nose = cs['case']['side'], cs['case']['nose']

# create winding pack upper
wp_upper = BRepBuilderAPI_MakePolygon()
for dr, dy in zip([0, 0, -1, -1], [-1, 1, 1, -1]):
    wp_upper.Add(gp_Pnt(ro + dr * width - inboard, dy * depth / 2, zo))
wp_upper.Close()
wp_upper = wp_upper.Wire()

# create winding pack top
wp_top = BRepBuilderAPI_MakePolygon()
for dy, dz in zip([1, 1, -1, -1], [1, 0, 0, 1]):
    wp_top.Add(gp_Pnt(rtop, dy * depth / 2, ztop + outboard + dz * width))
wp_top.Close()
wp_top = wp_top.Wire()

# create case inboard
case_upper = BRepBuilderAPI_MakePolygon()
theta = math.pi / nTF
Exemplo n.º 18
0
 def create_shape(self):
     attrs = self.element.attrib
     x = parse_unit(attrs.get('x', 0))
     y = parse_unit(attrs.get('y', 0))
     w = parse_unit(attrs.get('width', 0))
     h = parse_unit(attrs.get('height', 0))
     rx = parse_unit(attrs.get('rx', 0))
     ry = parse_unit(attrs.get('ry', 0))
     if rx == ry == 0:
         shape = BRepBuilderAPI_MakePolygon(
             gp_Pnt(x, y, 0), gp_Pnt(x+w, y, 0),
             gp_Pnt(x+w, y+h, 0), gp_Pnt(x, y+h, 0),
             True
         )
         shape.Close()
         return shape.Wire()
     elif rx == 0:
         rx = ry
     elif ry == 0:
         ry = rx
     
     # Build the rect
     shape = BRepBuilderAPI_MakeWire()
     
     # Bottom
     p1 = gp_Pnt(x+rx, y, 0)
     p2 = gp_Pnt(x+w-rx, y, 0)
     
     # Right
     p3 = gp_Pnt(x+w, y+ry, 0)
     p4 = gp_Pnt(x+w, y+h-ry, 0)
     
     # Top
     p5 = gp_Pnt(x+w-rx, y+h, 0)
     p6 = gp_Pnt(x+rx, y+h, 0)
     
     # Left
     p7 = gp_Pnt(x, y+h-ry, 0)
     p8 = gp_Pnt(x, y+ry, 0)
     
     # Bottom
     shape.Add(BRepBuilderAPI_MakeEdge(p1, p2).Edge())
     
     # Arc bottom right
     c = make_ellipse((x+w-rx, y+ry, 0), rx, ry)
     shape.Add(BRepBuilderAPI_MakeEdge(
         GC_MakeArcOfEllipse(c, p2, p3, False).Value()).Edge())
     
     # Right
     shape.Add(BRepBuilderAPI_MakeEdge(p3, p4).Edge())
     
     # Arc top right
     c.SetLocation(gp_Pnt(x+w-rx, y+h-ry, 0))
     shape.Add(BRepBuilderAPI_MakeEdge(
         GC_MakeArcOfEllipse(c, p4, p5, False).Value()).Edge())
     
     # Top
     shape.Add(BRepBuilderAPI_MakeEdge(p5, p6).Edge())
     
     # Arc top left
     c.SetLocation(gp_Pnt(x+rx, y+h-ry, 0))
     shape.Add(BRepBuilderAPI_MakeEdge(
         GC_MakeArcOfEllipse(c, p6, p7, False).Value()).Edge())
     
     # Left
     shape.Add(BRepBuilderAPI_MakeEdge(p7, p8).Edge())
     
     # Arc bottom left
     c.SetLocation(gp_Pnt(x+rx, y+ry, 0))
     shape.Add(BRepBuilderAPI_MakeEdge(
         GC_MakeArcOfEllipse(c, p8, p1, False).Value()).Edge())
     
     wire = shape.Wire()
     wire.Closed(True)
     return wire
def evolved_shape():
    P = BRepBuilderAPI_MakePolygon()
    P.Add(gp_Pnt(0., 0., 0.))
    P.Add(gp_Pnt(200., 0., 0.))
    P.Add(gp_Pnt(200., 200., 0.))
    P.Add(gp_Pnt(0., 200., 0.))
    P.Add(gp_Pnt(0., 0., 0.))
    wprof = BRepBuilderAPI_MakePolygon(gp_Pnt(0., 0., 0.),
                                       gp_Pnt(-60., -60., -200.))
    S = BRepOffsetAPI_MakeEvolved(P.Wire(), wprof.Wire(), GeomAbs_Arc, True,
                                  False, True, 0.0001)
    S.Build()
    display.DisplayShape(S.Shape(), update=True)