def draw_polyline(self, element, position): classes = self.get_classes(element["raw"], position) exp = BRepTools.BRepTools_WireExplorer(element["geometry"]) points = [] while exp.More(): point = BRep.BRep_Tool.Pnt(exp.CurrentVertex()) points.append((point.X() * self.scale, -point.Y() * self.scale)) exp.Next() self.svg.add(self.svg.polyline(points=points, class_=" ".join(classes)))
def build_new_face(self, face, zpos, product): exp = TopExp.TopExp_Explorer(face, TopAbs.TopAbs_WIRE) while exp.More(): wireexp = BRepTools.BRepTools_WireExplorer( topods.Wire(exp.Current())) new_wire_builder = BRepBuilderAPI.BRepBuilderAPI_MakeWire() first_vertex = None previous_vertex = None while wireexp.More(): current_vertex = wireexp.CurrentVertex() current_point = BRep.BRep_Tool.Pnt(current_vertex) # Dodgy technique to squash in Z axis current_point.SetZ(zpos) current_vertex = BRepBuilderAPI.BRepBuilderAPI_MakeVertex( current_point).Vertex() if not first_vertex: first_vertex = current_vertex if not previous_vertex: previous_vertex = current_vertex else: try: new_wire_builder.Add( topods.Edge( BRepBuilderAPI.BRepBuilderAPI_MakeEdge( previous_vertex, current_vertex).Edge())) previous_vertex = current_vertex except: pass wireexp.Next() # make last edge if not wireexp.More(): try: new_wire_builder.Add( topods.Edge( BRepBuilderAPI.BRepBuilderAPI_MakeEdge( current_vertex, first_vertex).Edge())) except: pass try: new_wire = new_wire_builder.Wire() new_face = BRepBuilderAPI.BRepBuilderAPI_MakeFace( new_wire).Face() self.background_elements.append({ 'raw': product, 'geometry': new_wire, 'geometry_face': new_face, 'type': 'polygon', 'z': zpos }) except: #print('Could not build face') pass exp.Next()
def do_cut(process_data): global_id, shape, section, trsf_data = process_data axis = gp.gp_Ax2( gp.gp_Pnt(trsf_data['top_left_corner'][0], trsf_data['top_left_corner'][1], trsf_data['top_left_corner'][2]), gp.gp_Dir(trsf_data['projection'][0], trsf_data['projection'][1], trsf_data['projection'][2]), gp.gp_Dir(trsf_data['x_axis'][0], trsf_data['x_axis'][1], trsf_data['x_axis'][2])) source = gp.gp_Ax3(axis) destination = gp.gp_Ax3(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(0, 0, -1), gp.gp_Dir(1, 0, 0)) transformation = gp.gp_Trsf() transformation.SetDisplacement(source, destination) cut_polygons = [] section = BRepAlgoAPI.BRepAlgoAPI_Section(section, shape).Shape() section_edges = get_booleaned_edges(section) if len(section_edges) <= 0: return cut_polygons wires = connect_edges_into_wires(section_edges) for i in range(wires.Length()): wire_shape = wires.Value(i + 1) transformed_wire = BRepBuilderAPI.BRepBuilderAPI_Transform( wire_shape, transformation) wire_shape = transformed_wire.Shape() wire = topods.Wire(wire_shape) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire).Face() points = [] exp = BRepTools.BRepTools_WireExplorer(wire) while exp.More(): point = BRep.BRep_Tool.Pnt(exp.CurrentVertex()) points.append((point.X(), -point.Y())) exp.Next() cut_polygons.append({ 'global_id': global_id, 'metadata': {}, 'points': points }) return cut_polygons