def draw_simple_text(x, y, text_str): str_to_display = TCollection_AsciiString(text_str) height = 30 font_name = TCollection_AsciiString("Courier") display_type = Aspect_TODT_NORMAL text_color = Quantity_Color(Quantity_NOC_BLACK) subtitle_color = Quantity_Color(Quantity_NOC_BLACK) aTextItem = TextItem(str_to_display, x, y, height, font_name, text_color, subtitle_color, display_type, display.GetOverLayer()) display.register_overlay_item(aTextItem)
def set_bg_gradient_color(self, R1, G1, B1, R2, G2, B2): """ set a bg vertical gradient color. R, G and B are floats. """ aColor1 = Quantity_Color(float(R1)/255., float(G1)/255., float(B1)/255., Quantity_TOC_RGB) aColor2 = Quantity_Color(float(R2)/255., float(G2)/255., float(B2)/255., Quantity_TOC_RGB) self.View.SetBgGradientColors(aColor1, aColor2, 2, True)
def show_grid(self, step=1., size=10. + 1e-6, color1=(.7, .7, .7), color2=(0, 0, 0)): viewer = self._get_viewer() viewer.ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines) viewer.SetRectangularGridGraphicValues(size, size, 0) viewer.SetRectangularGridValues(0, 0, step, step, 0) grid = viewer.Grid().GetObject() grid.SetColors(Quantity_Color(*color1, TOC_RGB), Quantity_Color(*color2, TOC_RGB))
def find_color(label, color_tool, shape_tool): """ Gets the color of a :class:`.OCC.TDF.TDF_Label` (**label**) :param label: :class:`.OCC.TDF.TDF_Label` :param shape_tool: :class:`.OCC.XCAFDoc.XCAFDoc_ShapeTool` :param color_tool: :class:`.OCC.XCAFDoc.XCAFDoc_ColorTool` """ c = Quantity_Color() if (color_tool.GetInstanceColor(shape_tool.GetShape(label), 0, c) or color_tool.GetInstanceColor(shape_tool.GetShape(label), 1, c) or color_tool.GetInstanceColor(shape_tool.GetShape(label), 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(label, i, c) return c if (color_tool.GetColor(label, 0, c) or color_tool.GetColor(label, 1, c) or color_tool.GetColor(label, 2, c)): shape = shape_tool.GetShape(label) for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) return c return False
def import_as_compound(event=None): compound = read_step_file(os.path.join('.', 'models', 'as1_pe_203.stp')) t = Topo(compound) display.EraseAll() for solid in t.solids(): color = Quantity_Color(random.random(), random.random(), random.random(), Quantity_TOC_RGB)
def get_color_from_name(color_name): ''' from the string 'WHITE', returns Quantity_Color WHITE. color_name is the color name, case insensitive. ''' enum_name = 'Quantity_NOC_%s' % color_name.upper() if enum_name in globals(): color_num = globals()[enum_name] return Quantity_Color(color_num) elif enum_name + '1' in globals(): color_num = globals()[enum_name + '1'] print('Many colors for color name %s, using first.' % color_name) else: color_num = Quantity_NOC_WHITE print('Color name not defined. Use White by default') return Quantity_Color(color_num)
def test_write_step_file(self): ''' Exports a colored box into a STEP file ''' ### initialisation h_doc = Handle_TDocStd_Document() assert (h_doc.IsNull()) # Create the application app = XCAFApp_Application.GetApplication().GetObject() app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), h_doc) # Get root assembly doc = h_doc.GetObject() h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main()) l_Colors = XCAFDoc_DocumentTool_ColorTool(doc.Main()) shape_tool = h_shape_tool.GetObject() colors = l_Colors.GetObject() ### create the shape to export test_shape = BRepPrimAPI_MakeBox(100., 100., 100.).Shape() ### add shape shp_label = shape_tool.AddShape(test_shape) ### set a color for this shape r = 1 g = b = 0.5 red_color = Quantity_Color(r, g, b, 0) colors.SetColor(shp_label, red_color, XCAFDoc_ColorGen) # write file WS = XSControl_WorkSession() writer = STEPCAFControl_Writer(WS.GetHandle(), False) writer.Transfer(h_doc, STEPControl_AsIs) status = writer.Write("./test_io/test_ocaf_generated.stp") assert status assert os.path.isfile("./test_io/test_ocaf_generated.stp")
def DisplayColoredShape( self, shapes, color='YELLOW', update=False, ): if isinstance(color, str): dict_color = { 'WHITE': Quantity_NOC_WHITE, 'BLUE': Quantity_NOC_BLUE1, 'RED': Quantity_NOC_RED, 'GREEN': Quantity_NOC_GREEN, 'YELLOW': Quantity_NOC_YELLOW, 'CYAN': Quantity_NOC_CYAN1, 'BLACK': Quantity_NOC_BLACK, 'ORANGE': Quantity_NOC_ORANGE } clr = Quantity_Color(dict_color[color]) elif isinstance(color, Quantity_Color): clr = color else: raise ValueError( 'color should either be a string ( "BLUE" ) or a Quantity_Color(0.1, 0.8, 0.1) got %s' % color) return self.DisplayShape(shapes, color=clr, update=update)
def set_capping_color(self, color): display = self.display clip_plane = self.graphic if color: c = Quantity_Color(color.red / 255., color.green / 255., color.blue / 255., Quantity_TOC_RGB) mat = clip_plane.CappingMaterial() mat.SetAmbientColor(c) mat.SetDiffuseColor(c) clip_plane.SetCappingMaterial(mat)
def import_as_multiple_shapes(event=None): compound = read_step_file( os.path.join('..', 'assets', 'models', 'as1_pe_203.stp')) 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) display.FitAll()
def draw_lines(pnt_list, nr_of_points, display): """ rendering a large number of points through the usual way of: display.DisplayShape( make_vertex( gp_Pnt() ) ) is fine for TopoDS_Shapes but certainly not for large number of points. in comparison, drawing all the voxel samples takes 18sec using the approach above, but negigable when using this function its about 2 orders of Magnitude faster, so worth the extra hassle here we use a more close-to-the-metal approach of drawing directly in OpenGL see [1] for a more detailed / elegant way to perform this task [1] http://www.opencascade.org/org/forum/thread_21732/?forum=3 Parameters ---------- pnt_list: list of (x,y,z) tuples vertex list display: qtViewer3d """ a_presentation, group = create_ogl_group(display) black = Quantity_Color(Quantity_NOC_BLACK) asp = Graphic3d_AspectLine3d(black, Aspect_TOL_SOLID, 1) gg = Graphic3d_ArrayOfPolylines( nr_of_points * 2, nr_of_points * 2, 0, # maxEdges False, # hasVColors True, # hasBColors False, # hasEdgeInfos ) try: while 1: pnt = gp_Pnt(*next(pnt_list)) gg.AddVertex(pnt) pnt = gp_Pnt(*next(pnt_list)) gg.AddVertex(pnt) # create the line, with a random color gg.AddBound(2, random.random(), random.random(), random.random()) except StopIteration: pass group.SetPrimitivesAspect(asp.GetHandle()) group.AddPrimitiveArray(gg.GetHandle()) a_presentation.Display()
def add_scrolled_text(event=None): str_to_display = TCollection_AsciiString("Pythonocc Rocks!!") x1 = 1024 / 2 y1 = 768 / 2 height = 30 font_name = TCollection_AsciiString("Arial") display_type = Aspect_TODT_DEKALE text_color = Quantity_Color(Quantity_NOC_ORANGE) subtitle_color = Quantity_Color(Quantity_NOC_BLACK) aTextItem = TextItem(str_to_display, x1, y1, height, font_name, text_color, subtitle_color, display_type, display.GetOverLayer(), ScrollX=random.random() - 0.5, ScrollY=random.random() - 0.5) display.register_overlay_item(aTextItem) rotate_shp(ais_bottle)
def draw_random_overlayered_lines(event=None): # random line parameters window_width = 1024 window_height = 768 for i in range(number_of_lines): x1 = random.randint(1, window_width) x2 = random.randint(1, window_width) y1 = random.randint(1, window_height) y2 = random.randint(1, window_height) line_width = random.uniform(0., 10) line_transp = random.random() line_type = random.randint(0, 10) line_color = Quantity_Color(random.random(), random.random(), random.random(), 1) # register line a_line = LineItem(x1, y1, x2, y2, display.GetOverLayer(), line_type, line_width, line_transp, line_color) display.register_overlay_item(a_line)
def tabletop(event=None): pcd_file = open(os.path.join('assets', 'models', 'tabletop.pcd'), 'r').readlines()[11:] #create the point_cloud pc = Graphic3d_ArrayOfPoints(len(pcd_file), True) for idx, line in enumerate(pcd_file): x, y, z, rgb = map(float, line.split()) rgb = float2int(rgb) r = (rgb >> 16 & 0x0000ff) / float(255) g = (rgb >> 8 & 0x0000ff) / float(255) b = (rgb & 0x0000ff) / float(255) color = Quantity_Color(r, g, b, Quantity_TOC_RGB) pc.AddVertex(gp_Pnt(x, y, z), color) point_cloud = AIS_PointCloud() point_cloud.SetPoints(pc.GetHandle()) ais_context = display.GetContext().GetObject() ais_context.Display(point_cloud.GetHandle()) display.DisableAntiAliasing() display.View_Iso() display.FitAll()
def color(r, g, b): return Quantity_Color(r, g, b, Quantity_TOC_RGB)
#while aFaceExplorer.More(): for i in range(31): i += 1 aFace = OCC.TopoDS.topods_Face(aFaceExplorer.Current()) aSurface = BRep_Tool.Surface(aFace) #print(aSurface.GetObject().DynamicType(),OCC.Geom.Geom_Plane) print(aFace) aFaceExplorer.Next() #facesToRemove.Append(aFace) myBody = MakeThickSolid(myBody, facesToRemove, -myThickness / 50, 1e-3).Shape() #display.DisplayColoredShape(myWireProfile,'BLUE') rgba = list(colors[0]) rgba.append(0) # add alpha display.DisplayColoredShape(myBody, Quantity_Color(*rgba)) start_display() ''' # Threading : Create Surfaces neckAx2_bis = gp_Ax3(neckLocation , neckNormal) aCyl1 = Geom_CylindricalSurface(neckAx2_bis , myNeckRadius * 0.99) aCyl2 = Geom_CylindricalSurface(neckAx2_bis , myNeckRadius * 1.05) aCyl1_handle = aCyl1.GetHandle() aCyl2_handle = aCyl2.GetHandle() # Threading : Define 2D Curves aPnt = gp_Pnt2d(2. * math.pi , myNeckHeight / 2.) aDir = gp_Dir2d(2. * math.pi , myNeckHeight / 4.) aAx2d = gp_Ax2d(aPnt , aDir) aMajor = 2. * math.pi aMinor = myNeckHeight / 10.
import sys import json import math import numpy as np from OCC.Quantity import Quantity_Color, Quantity_TOC_RGB import seaborn as sns colors = sns.color_palette('Paired', 12) QC = [[] for i in range(len(colors))] for i, c in enumerate(colors): QC[i] = Quantity_Color(*c, Quantity_TOC_RGB) QC[i].ChangeIntensity(-50) from collections import OrderedDict from OCC.Display.WebGl import x3dom_renderer from OCC.gp import gp_Pnt, gp_Trsf, gp_Ax1, gp_Ax2 from OCC.gp import gp_Dir from OCC.GC import GC_MakeArcOfCircle from OCC.Geom import Geom_BezierCurve from OCC.BRepFill import BRepFill_PipeShell from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeEdge from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeWire from OCC.BRepBuilderAPI import BRepBuilderAPI_Transform from OCC.BRepBuilderAPI import BRepBuilderAPI_MakePolygon from OCC.BRepPrimAPI import BRepPrimAPI_MakeRevol from OCC.TopoDS import topods from OCC.GProp import GProp_GProps from OCC.BRepGProp import brepgprop_VolumeProperties from OCC.Display.SimpleGui import init_display from OCC.TColgp import TColgp_Array1OfPnt from OCCUtils.Common import GpropsFromShape from OCCUtils import Construct
def to_occ_color(color): return Quantity_Color(color.redF(), color.greenF(), color.blueF(), TOC_RGB)
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False, fit=False): # if a gp_Pnt is passed, first convert to vertex if issubclass(shapes.__class__, OCCViewer.gp_Pnt): vertex = OCCViewer.BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.gp_Pnt2d): vertex = OCCViewer.BRepBuilderAPI_MakeVertex( OCCViewer.gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] SOLO = True # if a Geom_Curve is passed elif callable(getattr(shapes, "GetHandle", None)): handle = shapes.GetHandle() if issubclass(handle.__class__, OCCViewer.Handle_Geom_Curve): edge = OCCViewer.BRepBuilderAPI_MakeEdge(handle) shapes = [edge.Shape()] SOLO = True elif issubclass(handle.__class__, OCCViewer.Handle_Geom2d_Curve): edge2d = OCCViewer.BRepBuilderAPI_MakeEdge2d(handle) shapes = [edge2d.Shape()] SOLO = True elif issubclass(handle.__class__, OCCViewer.Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = OCCViewer.BRepBuilderAPI_MakeFace() face.Init(handle, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = OCCViewer.BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom_Curve): edge = OCCViewer.BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom2d_Curve): edge2d = OCCViewer.BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] SOLO = True elif issubclass(shapes.__class__, OCCViewer.TopoDS_Shape): shapes = [shapes] SOLO = True else: SOLO = False ais_shapes = [] for shape in shapes: if material or texture: if texture: self.View.SetSurfaceDetail(OCCViewer.OCC.V3d.V3d_TEX_ALL) shape_to_display = OCCViewer.OCC.AIS.AIS_TexturedShape( shape) (filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV) = texture.GetProperties() shape_to_display.SetTextureFileName( OCCViewer.TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = OCCViewer.AIS_Shape(shape) shape_to_display.SetMaterial(material) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = OCCViewer.AIS_Shape(shape) ais_shapes.append(shape_to_display.GetHandle()) if not SOLO: # computing graphic properties is expensive # if an iterable is found, so cluster all TopoDS_Shape under # an AIS_MultipleConnectedInteractive shape_to_display = OCCViewer.AIS_MultipleConnectedInteractive() for i in ais_shapes: shape_to_display.Connect(i) #set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective shape_to_display.SetMaterial(OCCViewer.Graphic3d_NOM_NEON_GNC) if color: # Convert enaml color to OCC color if color.alpha != 255: transparency = 1 - color.alpha / 255.0 color = Quantity_Color(color.red / 255., color.green / 255., color.blue / 255., Quantity_TOC_RGB) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: shape_to_display.SetTransparency(transparency) if update: # only update when explicitely told to do so self.Context.Display(shape_to_display.GetHandle(), False) # especially this call takes up a lot of time... if fit: self.FitAll() self.Repaint() else: self.Context.Display(shape_to_display.GetHandle(), False) if SOLO: return ais_shapes[0] else: return shape_to_display
def init2(self): Viewer.init2(self) self.eye = [0.82, 0.45, 0.36] self._update_grid_size() self.viewer.Grid().GetObject().SetColors(Quantity_Color(.9, .9, .9, 0), Quantity_Color(.8, .8, .8, 0))
def visualise_falsecolour_topo(occtopo_list, results, other_occtopo_2dlist=None, other_colour_list=None, minval=None, maxval=None, backend="qt-pyqt5", inverse=False): """ This function visualise a falsecolour 3D model using the PythonOCC viewer. Parameters ---------- occtopo_list : list of OCCtopologies The geometries to be visualised with the results. The list of geometries must correspond to the list of results. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex results : list of floats The results to be visualised. The list of results must correspond to the occtopo_list. other_occtopo_2dlist : 2d list of OCCtopologies, optional Other geometries to be visualised together with the results, Default = None. other_colour_list : list of str, optional The colours of the other_topo2dlist, Default = None. The colour strings include: "WHITE", "BLUE", "RED", "GREEN", "YELLOW", "CYAN", "BLACK", "ORANGE". The number of colours must correspond to the number of list in the other_topo2dlist. minval : float, optional The minimum value of the falsecolour rgb, Default = None. If None the maximum value is equal to the maximum value from the results. maxval : float, optional The maximum value of the falsecolour rgb, Default = None. If None the maximum value is equal to the minimum value from the results. backend : str, optional The graphic interface to use for visualisation, Default = qt-pyqt5. Other options include:"qt-pyqt4", "qt-pyside", "wx" inverse : bool False for red being max, True for blue being maximum. Returns ------- None : None A qt window pops up displaying the geometries. """ display, start_display, add_menu, add_function_to_menu = init_display( backend_str=backend) if minval == None: minval1 = min(results) elif minval != None: minval1 = minval if maxval == None: maxval1 = max(results) elif maxval != None: maxval1 = maxval res_colours = falsecolour(results, minval1, maxval1, inverse=inverse) colour_list = [] c_srf_list = [] for r_cnt in range(len(res_colours)): fcolour = res_colours[r_cnt] rf = occtopo_list[r_cnt] if fcolour not in colour_list: colour_list.append(fcolour) c_srf_list.append([rf]) elif fcolour in colour_list: c_index = colour_list.index(fcolour) c_srf_list[c_index].append(rf) for c_cnt in range(len(c_srf_list)): c_srfs = c_srf_list[c_cnt] colour = colour_list[c_cnt] from OCC.Quantity import Quantity_TOC_RGB, Quantity_Color compound = construct.make_compound(c_srfs) display.DisplayColoredShape(compound, color=Quantity_Color( colour[0], colour[1], colour[2], Quantity_TOC_RGB), update=True) #display the edges of the grid tedges = [] for t in occtopo_list: edge = list(Topology.Topo(t).edges()) tedges.extend(edge) edgecompound = construct.make_compound(tedges) display.DisplayColoredShape(edgecompound, color="BLACK", update=True) if other_occtopo_2dlist != None: tc_cnt = 0 for other_topolist in other_occtopo_2dlist: other_compound = construct.make_compound(other_topolist) other_colour = other_colour_list[tc_cnt] display.DisplayColoredShape(other_compound, color=other_colour, update=True) tc_cnt += 1 display.set_bg_gradient_color(0, 0, 0, 0, 0, 0) display.View_Iso() display.FitAll() start_display()
ais_shp = display.DisplayShape(cylinder_head).GetObject() # clip plane number one, by default xOy clip_plane_1 = Graphic3d_ClipPlane() # set hatch on clip_plane_1.SetCapping(True) clip_plane_1.SetCappingHatch(True) # off by default, user will have to enable it clip_plane_1.SetOn(False) # set clip plane color aMat = clip_plane_1.CappingMaterial() aColor = Quantity_Color(0.5, 0.6, 0.7, Quantity_TOC_RGB) aMat.SetAmbientColor(aColor) aMat.SetDiffuseColor(aColor) clip_plane_1.SetCappingMaterial(aMat) ais_shp.AddClipPlane(clip_plane_1.GetHandle()) def enable_clip_plane(event=None): clip_plane_1.SetOn(True) display.Context.UpdateCurrentViewer() def disable_clip_plane(event=None): clip_plane_1.SetOn(False) display.Context.UpdateCurrentViewer()
"Olá mundo": "Arial", # Portuguese "Здравствулте мир": "Microsoft Yahei", # Russian "Hola mundo": "Arial" # Spanish } arialbold_brep_string = text_to_brep("hello from pythonocc !", "Arial", Font_FA_Regular, 12., True) ## Then display the string display.DisplayShape(arialbold_brep_string) for hello_str in hello: rndm_size = random.uniform(10., 16.) font = hello[hello_str] brep_string = text_to_brep(hello_str, font, Font_FA_Regular, rndm_size, True) rndm_extrusion_depth = random.uniform(8., 16.) rndm_extrusion_direction = gp_Vec(random.random(), random.random(), random.random()) extruded_string = make_extrusion(brep_string, rndm_extrusion_depth, rndm_extrusion_direction) rndm_pos = gp_Vec(random.random() * 100 - 50, random.random() * 100 - 50, random.random() * 100 - 50) rndm_color = Quantity_Color(random.random(), random.random(), random.random(), Quantity_TOC_RGB) trs_shp = translate_shp(extruded_string, rndm_pos) display.DisplayColoredShape(trs_shp, rndm_color) display.FitAll() start_display()
def getSubShapes(lab, loc): global cnt, lvl cnt += 1 print("\n[%d] level %d, handling LABEL %s\n" % (cnt, lvl, get_label_name(lab))) print() print(lab.DumpToString()) print() print("Is Assembly :", shape_tool.IsAssembly(lab)) print("Is Free :", shape_tool.IsFree(lab)) print("Is Shape :", shape_tool.IsShape(lab)) print("Is Compound :", shape_tool.IsCompound(lab)) print("Is Component :", shape_tool.IsComponent(lab)) print("Is SimpleShape :", shape_tool.IsSimpleShape(lab)) print("Is Reference :", shape_tool.IsReference(lab)) users = TDF_LabelSequence() users_cnt = shape_tool.GetUsers(lab, users) print("Nr Users :", users_cnt) l_subss = TDF_LabelSequence() shape_tool.GetSubShapes(lab, l_subss) print("Nb subshapes :", l_subss.Length()) l_comps = TDF_LabelSequence() shape_tool.GetComponents(lab, l_comps) print("Nb components :", l_comps.Length()) print() if shape_tool.IsAssembly(lab): l_c = TDF_LabelSequence() shape_tool.GetComponents(lab, l_c) for i in range(l_c.Length()): label = l_c.Value(i + 1) if shape_tool.IsReference(label): print("\n######## reference label :", label) label_reference = TDF_Label() shape_tool.GetReferredShape(label, label_reference) loc = shape_tool.GetLocation(label) print(" loc :", loc) trans = loc.Transformation() print(" tran form :", trans.Form()) rot = trans.GetRotation() print(" rotation :", rot) print(" X :", rot.X()) print(" Y :", rot.Y()) print(" Z :", rot.Z()) print(" W :", rot.W()) tran = trans.TranslationPart() print(" translation :", tran) print(" X :", tran.X()) print(" Y :", tran.Y()) print(" Z :", tran.Z()) locs.append(loc) print(">>>>") lvl += 1 getSubShapes(label_reference, loc) lvl -= 1 print("<<<<") locs.pop() elif shape_tool.IsSimpleShape(lab): print("\n######## simpleshape label :", lab) shape = shape_tool.GetShape(lab) print(" all ass locs :", locs) loc = TopLoc_Location() for i in range(len(locs)): print(" take loc :", locs[i]) loc = loc.Multiplied(locs[i]) trans = loc.Transformation() print(" FINAL loc :") print(" tran form :", trans.Form()) rot = trans.GetRotation() print(" rotation :", rot) print(" X :", rot.X()) print(" Y :", rot.Y()) print(" Z :", rot.Z()) print(" W :", rot.W()) tran = trans.TranslationPart() print(" translation :", tran) print(" X :", tran.X()) print(" Y :", tran.Y()) print(" Z :", tran.Z()) shape = BRepBuilderAPI_Transform(shape, loc.Transformation()).Shape() c = Quantity_Color() colorSet = False if (color_tool.GetInstanceColor(shape, 0, c) or color_tool.GetInstanceColor(shape, 1, c) or color_tool.GetInstanceColor(shape, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab, 0, c) or color_tool.GetColor(lab, 1, c) or color_tool.GetColor(lab, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # n = c.Name(c.Red(), c.Green(), c.Blue()) # print(' color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # Display shape display.DisplayColoredShape(shape, c) for i in range(l_subss.Length()): lab = l_subss.Value(i + 1) print("\n######## simpleshape subshape label :", lab) shape = shape_tool.GetShape(lab) c = Quantity_Color() colorSet = False if (color_tool.GetInstanceColor(shape, 0, c) or color_tool.GetInstanceColor(shape, 1, c) or color_tool.GetInstanceColor(shape, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab, 0, c) or color_tool.GetColor(lab, 1, c) or color_tool.GetColor(lab, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # n = c.Name(c.Red(), c.Green(), c.Blue()) # print(' color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # Display shape display.DisplayColoredShape(shape, c)
def face(): p1 = gp_Pnt() p2 = gp_Pnt() p3 = gp_Pnt() p4 = gp_Pnt() p5 = gp_Pnt() p6 = gp_Pnt() # The white Face sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150) green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9) # The red face p1.SetCoord(-15, 200, 10) p2.SetCoord(5, 204, 0) p3.SetCoord(15, 200, 0) p4.SetCoord(-15, 20, 15) p5.SetCoord(-5, 20, 0) p6.SetCoord(15, 20, 35) array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() red_face = BRepBuilderAPI_MakeFace(curve, 1e-6) #The brown face circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80) Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi) Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40)) Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80)) ##TopoDS_Wire YellowWire MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge()) if MW1.IsDone(): yellow_wire = MW1.Wire() brown_face = BRepBuilderAPI_MakeFace(yellow_wire) #The pink face p1.SetCoord(35, -200, 40) p2.SetCoord(50, -204, 30) p3.SetCoord(65, -200, 30) p4.SetCoord(35, -20, 45) p5.SetCoord(45, -20, 30) p6.SetCoord(65, -20, 65) array2 = TColgp_Array2OfPnt(1, 3, 1, 2) array2.SetValue(1, 1, p1) array2.SetValue(2, 1, p2) array2.SetValue(3, 1, p3) array2.SetValue(1, 2, p4) array2.SetValue(2, 2, p5) array2.SetValue(3, 2, p6) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2, 0.001) aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face() ## ##//2d lines P12d = gp_Pnt2d(0.9, 0.1) P22d = gp_Pnt2d(0.2, 0.7) P32d = gp_Pnt2d(0.02, 0.1) ## line1 = Geom2d_Line(P12d, gp_Dir2d((0.2-0.9), (0.7-0.1))) line2 = Geom2d_Line(P22d, gp_Dir2d((0.02-0.2), (0.1-0.7))) line3 = Geom2d_Line(P32d, gp_Dir2d((0.9-0.02), (0.1-0.1))) ## ##//Edges are on the BSpline surface Edge1 = BRepBuilderAPI_MakeEdge(line1.GetHandle(), BSplineSurf.Surface(), 0, P12d.Distance(P22d)).Edge() Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(), 0, P22d.Distance(P32d)).Edge() Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(), 0, P32d.Distance(P12d)).Edge() ## Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire() Wire1.Reverse() pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face() breplib_BuildCurves3d(pink_face) display.DisplayColoredShape(green_face.Face(), 'GREEN') display.DisplayColoredShape(red_face.Face(), 'RED') display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK)) display.DisplayColoredShape(brown_face.Face(), 'BLUE') display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
# coding: utf-8 r""" for this example to work, pythonocc / OCE needs to be built with the gl2ps lib """ from OCC.Quantity import Quantity_Color, Quantity_TOC_RGB from OCC.Display.SimpleGui import init_display from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus, BRepPrimAPI_MakeCylinder from OCC.Graphic3d import (Graphic3d_EF_PDF, Graphic3d_EF_SVG, Graphic3d_EF_TEX, Graphic3d_EF_PostScript, Graphic3d_EF_EnhPostScript) display, start_display, add_menu, add_function_to_menu = init_display('wx') display.View.SetBackgroundColor(Quantity_Color(1., 1., 1., Quantity_TOC_RGB)) display.SetModeHLR() # my_torus = BRepPrimAPI_MakeTorus(40., 20.).Shape() my_cylinder = BRepPrimAPI_MakeCylinder(10., 30.).Shape() display.DisplayShape(my_cylinder, update=True) display.View_Iso() display.FitAll() f = display.View.View().GetObject() # Get Context ais_context = display.GetContext().GetObject() # Get Prs3d_drawer from previous context drawer_handle = ais_context.DefaultDrawer()