def shape_to_wire(self, shape): if hasattr(shape, 'Wire'): return shape.Wire() elif hasattr(shape, 'Edge'): return shape.Edge() elif hasattr(shape, 'Shape'): # Transforms return topods.Wire(shape.Shape()) elif hasattr(shape, 'GetHandle'): # Curves return BRepBuilderAPI_MakeEdge(shape.GetHandle()).Edge() raise ValueError("Cannot build Wire from shape: {}".format(shape))
def get_chord_scale(wing, wing_connection): """ Returns the chord scale of the given wing connection :param wing: :param wing_connection: :return: """ wing_transform = wing.get_transformation_matrix() inner_profile_wire = wing_connection.get_profile().get_chord_line_wire() inner_chord_line_wire = transform_wing_profile_geometry(wing_transform, wing_connection, inner_profile_wire) return get_length(topods.Wire(inner_chord_line_wire))
def shape_base_drain(): ''' output s: TopoDS_Shape ''' wire = wire_circle() trsf = gp_Trsf() trsf.SetScale(DRAIN_RCS.Location(), DRAIN_R) bresp_trsf = BRepBuilderAPI_Transform(wire, trsf) wire = topods.Wire(bresp_trsf.Shape()) base_face = BRepBuilderAPI_MakeFace(wire).Face() shape = BRepPrimAPI_MakePrism(base_face, gp_Vec(0, 0, DRAIN_T)).Shape() return shape
def list_wire_random(): ''' output wires: {TopoDS_Wire:string} wire_name: '' ''' wire_name = '' # number of rings numr = int((DRAIN_R / 4 / DRAIN_S - 0.5)) wires = {} for i in range(numr): # radius of ith ring radius = 3 * DRAIN_S + i * 4 * DRAIN_S # number of cells per ring nump = int(1.5 * pi + 2 * pi * i) # print('np:',np) # randomly choose the number of cells to combine combo_list = range(1, nump // 3 + 1) combo = random.choice(combo_list) # angle between two adjacent cells ang = 2 * pi / nump # randomly offset the start cell offset = random.gauss(ang / 2, ang / 2) if offset < 0.: offset = 0. if offset > ang: offset = ang wlist, combo_name = list_wire_combo(combo, ang, offset, radius) wires.update(wlist) wire_name += str(combo) + '(' + combo_name + ')' nump = nump // combo # print('combo',combo,'repeat',np) ang = 2 * pi / nump for j in range(1, nump): trsf = gp_Trsf() trsf.SetRotation( gp_Ax1(DRAIN_RCS.Location(), DRAIN_RCS.Direction()), ang * j) for wire in wlist: wname = wlist[wire] bresp_trsf = BRepBuilderAPI_Transform(wire, trsf) wire = topods.Wire(bresp_trsf.Shape()) wires[wire] = wname return wires, wire_name
def update_shape(self, change): d = self.declaration shape = BRepBuilderAPI_MakeWire() for c in self.children(): if hasattr(c.shape, 'Wire'): #: No conversion needed shape.Add(c.shape.Wire()) elif hasattr(c.shape, 'Edge'): #: No conversion needed shape.Add(c.shape.Edge()) elif isinstance(c.shape, (list, tuple)): #: Assume it's a list of drawn objects... for e in c.shape: shape.Add(e.Edge()) else: #: Attempt to convert the shape into a wire shape.Add(topods.Wire(c.shape.Shape())) assert shape.IsDone(), 'Edges must be connected' self.shape = shape
# Quick way to specify the X axis xAxis = gp_OX() # Set up the mirror aTrsf = gp_Trsf() aTrsf.SetMirror(xAxis) # Apply the mirror transformation aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf) # Get the mirrored shape back out of the transformation and convert # back to a wire aMirroredShape = aBRespTrsf.Shape() # A wire instead of a generic shape now aMirroredWire = topods.Wire(aMirroredShape) # Combine the two constituent wires mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(aWire.Wire()) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() # The face that we'll sweep to make the prism myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) # We want to sweep the face along the Z axis to the height aPrismVec = gp_Vec(0, 0, height) myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec) # Add fillets to all edges through the explorer
# Open Cascade has a function to turn loose unconnected edges into a list of # connected wires. This function takes handles (pointers) to Open Cascade's native # sequence type. Hence, two sequences and handles, one for the input, one for the # output, are created. edges = OCC.TopTools.TopTools_HSequenceOfShape() edges_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(edges) wires = OCC.TopTools.TopTools_HSequenceOfShape() wires_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(wires) # The edges are copied to the sequence for edge in section_edges: edges.Append(edge) # A wire is formed by connecting the edges OCC.ShapeAnalysis.ShapeAnalysis_FreeBounds.ConnectEdgesToWires( edges_handle, 1e-5, True, wires_handle) wires = wires_handle.GetObject() for i in range(wires.Length()): wire_shape = wires.Value(i + 1) wire = topods.Wire(wire_shape) face = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire).Face() # The wires and the faces are displayed ifcopenshell.geom.utils.display_shape(wire, clr=RED) face_display = ifcopenshell.geom.utils.display_shape(face, clr=RED) ifcopenshell.geom.utils.set_shape_transparency( face_display, 0.5) exp.Next()
def list_wire_combo(num_cell, ang, offset, radius): ''' input nc: int, number of cells to be combined ang: float, angle between adjaent cells offset: float, offset angle of start position ri: float, radius of this ring output wlist: {TopoDS_Wire: string} combo_name: '' ''' combo_name = '' pos_list = list(range(num_cell)) wlist = {} pos_len_name = {} while len(pos_list) > 0: # 1 choose a random location pos = random.choice(pos_list) # 2 choose a random length len_seq = len_seq_natural(pos, pos_list) len_seq = random.randrange(1, len_seq + 1) # 3 choose a random shape func = random.choice(FLIST) # print(pos_list, pos, l, fname[FLIST.index(func)]) trsf_scale = gp_Trsf() trsf_scale.SetScale(DRAIN_RCS.Location(), DRAIN_S) trsf_trans = gp_Trsf() trans_vec = gp_Vec(DRAIN_RCS.XDirection()) * radius trsf_trans.SetTranslation(trans_vec) trsf_rotate = gp_Trsf() trsf_rotate.SetRotation( gp_Ax1(DRAIN_RCS.Location(), DRAIN_RCS.Direction()), offset + pos * ang) if func == wire_sweep_circle and len_seq > 1: cir1 = DRAIN_RCS.Location() cir2 = DRAIN_RCS.Location() cir1.Translate(trans_vec) cir1.Rotate(gp_Ax1(DRAIN_RCS.Location(), DRAIN_RCS.Direction()), offset + pos * ang) cir2.Translate(trans_vec) cir2.Rotate(gp_Ax1(DRAIN_RCS.Location(), DRAIN_RCS.Direction()), offset + (pos + len_seq - 1) * ang) wire = wire_sweep_circle(cir1, cir2) elif func != wire_sweep_circle and len_seq == 1: wire = func() bresp_trsf = BRepBuilderAPI_Transform(wire, trsf_scale) wire = topods.Wire(bresp_trsf.Shape()) bresp_trsf = BRepBuilderAPI_Transform(wire, trsf_trans) wire = topods.Wire(bresp_trsf.Shape()) bresp_trsf = BRepBuilderAPI_Transform(wire, trsf_rotate) wire = topods.Wire(bresp_trsf.Shape()) else: continue wname = SKETCH_TYPE[FLIST.index(func)] pos_len_name[pos] = (len_seq, wname) wlist[wire] = wname for pos in range(pos, pos + len_seq): pos_list.remove(pos) pos_len_name = sorted(pos_len_name.items(), key=lambda t: t[0]) for pos in pos_len_name: combo_name += str(pos[1][0]) + '[' + pos[1][1] + ']' return wlist, combo_name
case_upper = case_upper.Wire() case_top = BRepBuilderAPI_MakePolygon() # create case outboard for dy, dz in zip([1, 1, -1, -1], [1, 0, 0, 1]): case_top.Add( gp_Pnt(rtop, dy * (depth / 2 + side), ztop + dz * (width + outboard + external))) case_top.Close() case_top = case_top.Wire() # transform inner sections trans = gp_Trsf() trans.SetTranslation(gp_Pnt(loop[0]['p0']['r'], 0, loop[0]['p0']['z']), gp_Pnt(loop[3]['p3']['r'], 0, loop[3]['p3']['z'])) case_lower = BRepBuilderAPI_Transform(case_upper, trans).Shape() case_lower = topods.Wire(case_lower) # wire wp_lower = BRepBuilderAPI_Transform(wp_upper, trans).Shape() wp_lower = topods.Wire(wp_lower) # wire # transform mid sections trans = gp_Trsf() r1, z1 = loop[0]['p0']['r'], loop[0]['p0']['z'] r2, z2 = loop[3]['p3']['r'], loop[3]['p3']['z'] rm, zm = r1 + (r2 - r1) / 2, z1 + (z2 - z1) / 2 trans.SetTranslation(gp_Pnt(r1, 0, z1), gp_Pnt(rm, 0, zm)) case_mid = BRepBuilderAPI_Transform(case_upper, trans).Shape() case_mid = topods.Wire(case_mid) # wire wp_mid = BRepBuilderAPI_Transform(wp_upper, trans).Shape() wp_mid = topods.Wire(wp_mid) # wire # mirror outer sections