def get_split_edges(self, edge_face_map, face, zmax, product): exp2 = TopExp.TopExp_Explorer(face, TopAbs.TopAbs_EDGE) while exp2.More(): edge = topods.Edge(exp2.Current()) adjface = TopoDS.TopoDS_Face() getadj = TopOpeBRepBuild.TopOpeBRepBuild_Tools.GetAdjacentFace( face, edge, edge_face_map, adjface) if getadj: try: edge_angle = math.degrees( self.get_angle_between_faces(face, adjface)) except: # TODO: Figure out when a math domain error might occur, # because it does, sometimes. edge_angle = 0 if edge_angle > 30 and edge_angle < 160: newedge = self.build_new_edge(edge, zmax + 0.01) if newedge: self.background_elements.append({ 'raw': product, 'geometry': newedge, 'type': 'line', 'z': zmax + 0.01 }) exp2.Next()
def make_frame_from_name(partname, root_transformation): shape_marker = TopoDS.TopoDS_Shape() if (mydoc.GetNamedShape(shape_marker, partname)): frame_marker = chrono.ChFrameD() mydoc.FromCascadeToChrono(shape_marker.Location(), frame_marker) frame_marker.ConcatenatePreTransformation(root_transformation) return frame_marker else: raise ValueError("Warning. Marker part name cannot be found in STEP file.\n")
def make_body_from_name(partname, root_transformation): shape1 = TopoDS.TopoDS_Shape() if (mydoc.GetNamedShape(shape1, partname)): # Make a ChBody representing the TopoDS_Shape part from the CAD: mbody1 = cascade.ChBodyEasyCascade(shape1, # shape 1000, # density (center of mass & inertia automatically computed) True, # mesh for visualization? False) # mesh for collision? mysystem.Add(mbody1) # Move the body as for global displacement/rotation (also mbody1 %= root_frame; ) mbody1.ConcatenatePreTransformation(root_transformation) return mbody1 else: raise ValueError("Warning. Body part name cannot be found in STEP file.\n")
def get_background_elements(self): total_product_shapes = len(self.product_shapes) n = 0 intersections = [] compound = TopoDS.TopoDS_Compound() builder = BRep.BRep_Builder() builder.MakeCompound(compound) for product, shape in self.product_shapes: builder.Add(compound, shape) print('{}/{} background elements processed ...'.format( n, total_product_shapes), end='\r', flush=True) #print('Processing product {} '.format(product.Name)) n += 1 intersection = BRepAlgoAPI.BRepAlgoAPI_Common( self.section_box['shape'], shape).Shape() intersection_edges = self.get_booleaned_edges(intersection) if len(intersection_edges) <= 0: continue intersections.append(intersection) transformed_intersection = BRepBuilderAPI.BRepBuilderAPI_Transform( intersection, self.transformation) intersection = transformed_intersection.Shape() edge_face_map = TopTools.TopTools_IndexedDataMapOfShapeListOfShape( ) TopExp.topexp.MapShapesAndAncestors(intersection, TopAbs.TopAbs_EDGE, TopAbs.TopAbs_FACE, edge_face_map) exp = TopExp.TopExp_Explorer(intersection, TopAbs.TopAbs_FACE) while exp.More(): face = topods.Face(exp.Current()) normal = self.get_normal(face) # Cull back-faces if normal.Z() <= 0: exp.Next() continue zpos, zmax = self.calculate_face_zpos(face) self.build_new_face(face, zpos, product) self.get_split_edges(edge_face_map, face, zmax, product) exp.Next()
def yield_subshapes(shape): it = TopoDS.TopoDS_Iterator(shape) while it.More(): yield it.Value() it.Next()
rotation2.Q_from_AngAxis(chrono.CH_C_PI, chrono.ChVectorD(0, 1, 0)) # 2: rotate 180° on vertical Y axis tot_rotation = chrono.ChQuaternionD() tot_rotation = rotation2 % rotation1 # rotate on 1 then on 2, using quaternion product root_frame = chrono.ChFrameMovingD(chrono.ChVectorD(0, 0, 0), tot_rotation) # Retrieve some sub shapes from the loaded model, using # the GetNamedShape() function, that can use path/subpath/subsubpath/part # syntax and * or ? wildcards, etc. mrigidBody1 = 0 mrigidBody2 = 0 if load_ok: shape1 = TopoDS.TopoDS_Shape() if (mydoc.GetNamedShape(shape1, "Assem1/body1")): mbody1 = mydoc.CreateBodyFromShape(shape1, 1000, False, True) # or: mbody1 = cascade.ChBodyEasyCascade(shape1, 1000, False, True) mysystem.Add(mbody1) mbody1.SetBodyFixed(True) # Move the body as for global displacement/rotation (also mbody1 %= root_frame; ) mbody1.ConcatenatePreTransformation(root_frame) mrigidBody1 = mbody1 else: print("Warning. Desired object not found in document \n")
from OCC.Core import TopoDS, Graphic3d, AIS, Bnd, BRepBndLib from OCC.Core.TopoDS import TopoDS_Wire import ifcopenshell.geom from OCCUtils import Topology import OCC material = Graphic3d.Graphic3d_MaterialAspect(Graphic3d.Graphic3d_NOM_PLASTER) settings = ifcopenshell.geom.settings() settings.set(settings.USE_PYTHON_OPENCASCADE, True) file = ifcopenshell.open("Mur.ifc") walls = file.by_type("IfcWall") bbox = OCC.Core.Bnd.Bnd_Box() for wall in walls: product = ifcopenshell.geom.create_shape(settings, wall) shape = TopoDS.TopoDS_Iterator(product.geometry).Value() occ_display = ifcopenshell.geom.utils.initialize_display() ifcopenshell.geom.utils.display_shape(shape) shape_gpXYZ = shape.Location().Transformation().TranslationPart() print(shape_gpXYZ.X(), shape_gpXYZ.Y(), shape_gpXYZ.Z()) break # wire = TopoDS.topods_Wire(product) # explorer = Topology.WireExplorer(wire) # vertices = explorer.ordered_vertices() # for vertex in vertices: # print vertex raw_input()