def runTests(self): # self.canva._display.Test() '''HR exercise 9/7/20 Want to convert line above with new code that is self-contained here C++ code to replicate (from 'Display3d.cpp') is below: BRepPrimAPI_MakeBox S(100,50,40); Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape()); myAISContext->Display(anAISShape, Standard_False); myV3dView->ZFitAll(); myV3dView->FitAll(); ''' # S = BRepPrimAPI_MakeBox(100,100,100) # S_shape = AIS_Shape(S.Shape()) # self.canva._display.DisplayShape(S_shape, update=True) display = self.canva._display filename = 'Torch Assembly.STEP' # ## # ## # # From "core_load_step_ap203" # color = Quantity_Color(random.random(), # random.random(), # random.random(), # Quantity_TOC_RGB) # # compound = read_step_file(os.path.join('..', 'assets', 'models', 'as1_pe_203.stp')) # compound = read_step_file(filename) # t = TopologyExplorer(compound) # display.EraseAll() # for solid in t.solids(): # color = Quantity_Color(random.random(), # random.random(), # random.random(), # Quantity_TOC_RGB) # display.DisplayColoredShape(solid, color) ## ## # From "core_load_step_with_names_colors" shapes_labels_colors = read_step_file_with_names_colors(filename) for shpt_lbl_color in shapes_labels_colors: label, c = shapes_labels_colors[shpt_lbl_color] display.DisplayColoredShape(shpt_lbl_color, color=Quantity_Color( c.Red(), c.Green(), c.Blue(), Quantity_TOC_RGB)) display.View.FitAll() display.View.ZFitAll()
def import_step(self, filename): shapes_labels_colors = read_step_file_with_names_colors(filename) for shpt_lbl_color in shapes_labels_colors: label, c = shapes_labels_colors[shpt_lbl_color] debug("shpt_lbl_color: %s" % (str(shpt_lbl_color), )) if (type(shpt_lbl_color) != TopoDS_Solid): debug("skip") continue scls = SCLShape(shpt_lbl_color) scls.color([c.Red(), c.Green(), c.Blue()]) sclp = SCLPart3(self) sclp.set_shape(scls) name = get_inc_name("step") sclp.set_name(name) debug("Creating step %s" % (name, )) self.add_child_context(sclp)
##(at your option) any later version. ## ##pythonOCC is distributed in the hope that it will be useful, ##but WITHOUT ANY WARRANTY; without even the implied warranty of ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##GNU Lesser General Public License for more details. ## ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. from OCC.Extend.DataExchange import read_step_file_with_names_colors from OCC.Extend.TopologyUtils import TopologyExplorer from OCC.Display.WebGl import x3dom_renderer filename = '../assets/models/as1-oc-214.stp' shapes_labels_colors = read_step_file_with_names_colors(filename) # create the x3dom renderer my_renderer = x3dom_renderer.X3DomRenderer() # traverse shapes, render in "face" mode for shpt_lbl_color in shapes_labels_colors: shape, label, c = shpt_lbl_color all_faces = TopologyExplorer(shape).faces() for face in all_faces: my_renderer.DisplayShape(face, color=(c.Red(), c.Green(), c.Blue()), export_edges=True) my_renderer.render()
def test_read_step_file_names_colors(self): read_step_file_with_names_colors(STEP_AP203_SAMPLE_FILE) read_step_file_with_names_colors(STEP_AP214_SAMPLE_FILE)
writer = STEPControl_Writer() fp = writer.WS().TransferWriter().FinderProcess() Interface_Static_SetCVal('write.step.schema', schema) Interface_Static_SetCVal('write.step.unit', 'M') Interface_Static_SetCVal('write.step.assembly', str(assembly_mode)) my_box1 = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() my_box2 = BRepPrimAPI_MakeBox(20., 1., 30.).Shape() components = [my_box1, my_box2] comp_names = ['PartA', 'PartB'] for i, comp in enumerate(components): Interface_Static_SetCVal('write.step.product.name', comp_names[i]) status = writer.Transfer(comp, STEPControl_AsIs) if int(status) > int(IFSelect_RetError): raise Exception('Some Error occurred') # This portion is not working as I hoped item = stepconstruct_FindEntity(fp, comp) if not item: raise Exception('Item not found') item.SetName(TCollection_HAsciiString(comp_names[i])) status = writer.Write('step_export_with_name.stp') if int(status) > int(IFSelect_RetError): raise Exception('Something bad happened') read_step_file_with_names_colors('step_export_with_name.stp')
def test_discretize_wire(self): read_step_file_with_names_colors(STEP_AP203_SAMPLE_FILE) read_step_file_with_names_colors(STEP_AP214_SAMPLE_FILE)