コード例 #1
0
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)
コード例 #2
0
ファイル: docmodel.py プロジェクト: paddy-r/kodacad
    def saveDoc(self, filename="foo.caf"):
        """Save doc to file (for educational purposes) (not working yet)

        https://www.opencascade.com/doc/occt-7.4.0/overview/html/occt_user_guides__ocaf.html#occt_ocaf_11
        """
        frmte = TCollection_ExtendedString("Xml-XCAF")
        #frmta = TCollection_AsciiString("MDTV-CAF")
        self.app.DefineFormat(TCollection_AsciiString("DocumentFormat"),
                              TCollection_AsciiString("MDTV-CAF"),
                              TCollection_AsciiString("caf"),
                              XmlXCAFDrivers_DocumentRetrievalDriver(),
                              XmlXCAFDrivers_DocumentStorageDriver(frmte))
        logger.debug("Saving doc to file")
        savefilename = TCollection_ExtendedString(filename)
        self.app.SaveAs(self.doc, savefilename)
コード例 #3
0
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)
コード例 #4
0
def relative_position(event=None):
    # create a texture
    aTextureItem = TextureItem(
        TCollection_AsciiString("../assets/images/carre-200.png"),
        display.GetView().GetObject(), display.GetOverLayer())
    aTextureItem.SetRelativePosition(30, 60)  # 30% width, 60% width
    display.register_overlay_item(aTextureItem)
コード例 #5
0
def absolute_position(event=None):
    # create a texture
    aTextureItem = TextureItem(
        TCollection_AsciiString("../assets/images/carre-200.png"),
        display.GetView().GetObject(), display.GetOverLayer())
    aTextureItem.SetAbsolutePosition(50, 50)
    display.register_overlay_item(aTextureItem)
コード例 #6
0
 def _get_label_name(lab):
     entry = TCollection_AsciiString()
     TDF_Tool.Entry(lab, entry)
     n = TDataStd_Name()
     lab.FindAttribute(TDataStd_Name_GetID(), n)
     if n:
         return n.Get().PrintToString()
     return "No Name"
コード例 #7
0
def get_label_name(lab):
    entry = TCollection_AsciiString()
    TDF_Tool.Entry(lab, entry)
    N = Handle_TDataStd_Name()
    lab.FindAttribute(TDataStd_Name_GetID(), N)
    n = N.GetObject()
    if n:
        return n.Get().PrintToString()
    return "No Name"
コード例 #8
0
ファイル: xde.py プロジェクト: tnakaicode/AFEM-OCC
    def set_string(self, string):
        """
        Set label name.

        :param str string: The string.

        :return: None.
        """
        txt = TCollection_AsciiString(string)
        TDataStd_AsciiString.Set_(self._label, txt)
コード例 #9
0
ファイル: OCCViewer.py プロジェクト: nyao9494/win_env_conda38
    def DisplayShape(self,
                     shapes,
                     material=None,
                     texture=None,
                     color=None,
                     transparency=None,
                     update=False):
        """ display one or a set of displayable objects
        """
        ais_shapes = []  # the list of all displayed shapes

        if issubclass(shapes.__class__, gp_Pnt):
            # if a gp_Pnt is passed, first convert to vertex
            vertex = BRepBuilderAPI_MakeVertex(shapes)
            shapes = [vertex.Shape()]
        elif isinstance(shapes, gp_Pnt2d):
            vertex = BRepBuilderAPI_MakeVertex(
                gp_Pnt(shapes.X(), shapes.Y(), 0))
            shapes = [vertex.Shape()]
        elif isinstance(shapes, Geom_Surface):
            bounds = True
            toldegen = 1e-6
            face = BRepBuilderAPI_MakeFace()
            face.Init(shapes, bounds, toldegen)
            face.Build()
            shapes = [face.Shape()]
        elif isinstance(shapes, Geom_Curve):
            edge = BRepBuilderAPI_MakeEdge(shapes)
            shapes = [edge.Shape()]
        elif isinstance(shapes, Geom2d_Curve):
            edge2d = BRepBuilderAPI_MakeEdge2d(shapes)
            shapes = [edge2d.Shape()]
        # if only one shapes, create a list with a single shape
        if not isinstance(shapes, list):
            shapes = [shapes]
        # build AIS_Shapes list
        for shape in shapes:
            if material or texture:
                if texture:
                    shape_to_display = AIS_TexturedShape(shape)
                    filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties(
                    )
                    shape_to_display.SetTextureFileName(
                        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 = AIS_Shape(shape)
                    shape_to_display.SetMaterial(
                        Graphic3d_MaterialAspect(material))
            else:
                # TODO: can we use .Set to attach all TopoDS_Shapes
                # to this AIS_Shape instance?
                shape_to_display = AIS_Shape(shape)

            ais_shapes.append(shape_to_display)

        # 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 = AIS_MultipleConnectedInteractive()
        #     for ais_shp in ais_shapes:
        #         # TODO : following line crashes with oce-0.18
        #         # why ? fix ?
        #         #shape_to_display.Connect(i)
        #         self.Context.Display(ais_shp, False)
        # 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
            for shape_to_display in ais_shapes:
                shape_to_display.SetMaterial(
                    Graphic3d_MaterialAspect(Graphic3d_NOM_NEON_GNC))
        if color:
            if isinstance(color, str):
                color = get_color_from_name(color)
            elif isinstance(color, int):
                color = Quantity_Color(color)
            for shp in ais_shapes:
                self.Context.SetColor(shp, color, False)
        if transparency:
            for shape_to_display in ais_shapes:
                shape_to_display.SetTransparency(transparency)
        # display the shapes
        for shape_to_display in ais_shapes:
            self.Context.Display(shape_to_display, False)
        if update:
            # especially this call takes up a lot of time...
            self.FitAll()
            self.Repaint()

        return ais_shapes
コード例 #10
0
{
    gl_FragColor=vec4(0.0, 1.0, 0, 1.0);
}
"""

# vertex shader
vs = """
void main()
{
    gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}
"""

# construct the shader, load, compile and attach the GLSL programs
vs_shader = Graphic3d_ShaderObject.CreateFromSource(
    Graphic3d_TOS_VERTEX, TCollection_AsciiString(vs))
fs_shader = Graphic3d_ShaderObject.CreateFromSource(
    Graphic3d_TOS_FRAGMENT, TCollection_AsciiString(fs))
aProgram = Graphic3d_ShaderProgram()
aProgram.AttachShader(fs_shader)
aProgram.AttachShader(vs_shader)

# attach the shader to the AIS_Shape representation that renders the sphere
aspect = anIO.Attributes().ShadingAspect().Aspect()

if aProgram.IsDone():
    aspect.SetShaderProgram(aProgram)
else:
    raise AssertionError("no valid shader program found")

# when a shader fails to compile, raise an AssertionError
コード例 #11
0
ファイル: OCCViewer.py プロジェクト: vinoth136/pythonocc-core
    def DisplayShape(self,
                     shapes,
                     material=None,
                     texture=None,
                     color=None,
                     transparency=None,
                     update=False):
        """ display one or a set of displayable objects
        """
        SOLO = False  # assume multiple instances by default
        # if a gp_Pnt is passed, first convert to vertex
        if issubclass(shapes.__class__, gp_Pnt):
            vertex = BRepBuilderAPI_MakeVertex(shapes)
            shapes = [vertex.Shape()]
            SOLO = True
        elif isinstance(shapes, gp_Pnt2d):
            vertex = BRepBuilderAPI_MakeVertex(
                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__, Handle_Geom_Curve):
                edge = BRepBuilderAPI_MakeEdge(handle)
                shapes = [edge.Shape()]
                SOLO = True
            elif issubclass(handle.__class__, Handle_Geom2d_Curve):
                edge2d = BRepBuilderAPI_MakeEdge2d(handle)
                shapes = [edge2d.Shape()]
                SOLO = True
            elif issubclass(handle.__class__, Handle_Geom_Surface):
                bounds = True
                toldegen = 1e-6
                face = BRepBuilderAPI_MakeFace()
                face.Init(handle, bounds, toldegen)
                face.Build()
                shapes = [face.Shape()]
                SOLO = True
        elif isinstance(shapes, Handle_Geom_Surface):
            bounds = True
            toldegen = 1e-6
            face = BRepBuilderAPI_MakeFace()
            face.Init(shapes, bounds, toldegen)
            face.Build()
            shapes = [face.Shape()]
            SOLO = True
        elif isinstance(shapes, Handle_Geom_Curve):
            edge = BRepBuilderAPI_MakeEdge(shapes)
            shapes = [edge.Shape()]
            SOLO = True
        elif isinstance(shapes, Handle_Geom2d_Curve):
            edge2d = BRepBuilderAPI_MakeEdge2d(shapes)
            shapes = [edge2d.Shape()]
            SOLO = True
        elif issubclass(shapes.__class__, TopoDS_Shape):
            shapes = [shapes]
            SOLO = True

        ais_shapes = []

        for shape in shapes:
            if material or texture:
                if texture:
                    self.View.SetSurfaceDetail(V3d_TEX_ALL)
                    shape_to_display = AIS_TexturedShape(shape)
                    filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties(
                    )
                    shape_to_display.SetTextureFileName(
                        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 = 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 = 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 = AIS_MultipleConnectedInteractive()
            for ais_shp in ais_shapes:
                # TODO : following line crashes with oce-0.18
                # why ? fix ?
                #shape_to_display.Connect(i)
                self.Context.Display(ais_shp, False)
            shape_to_display = ais_shapes
            return shape_to_display
        # 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(Graphic3d_NOM_NEON_GNC)
        if color:
            if isinstance(color, str):
                color = get_color_from_name(color)
            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...
            self.FitAll()
            self.Repaint()
        else:
            self.Context.Display(shape_to_display.GetHandle(), False)

        if SOLO:
            return ais_shapes[0]
        else:
            return shape_to_display
コード例 #12
0
ファイル: __init__.py プロジェクト: ocastrup/OCX
 def externalGeometryAssembly(self):
     # Create a TDoc holding the assembly of structure parts with external geometry. When assembled, write the STEP file
     # Initialize the  writer
     shapes = []
     step_writer = STEPCAFControl_Writer()
     step_writer.SetNameMode(True)
     step_writer.SetPropsMode(True)
     # create the handle to a document
     doc = TDocStd_Document(TCollection_ExtendedString("ocx-doc"))
     # Get root assembly
     shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
     shape_tool.SetAutoNaming(False)
     l_colors = XCAFDoc_DocumentTool_ColorTool(doc.Main())
     l_layers = XCAFDoc_DocumentTool_LayerTool(doc.Main())
     l_materials = XCAFDoc_DocumentTool_MaterialTool(doc.Main())
     aBuilder = BRep_Builder()
     # Loop over all Panels
     panelchildren = []
     for panel in self.model.panels:
         OCXCommon.LogMessage(panel, self.logging)
         guid = self.model.getGUID(panel)
         children = self.model.getPanelChildren(guid)
         panelchildren = panelchildren + children
         # Build the Panel compound
         compound = TopoDS_Compound()
         aBuilder.MakeCompound(compound)
         label = shape_tool.AddShape(compound)
         pname = panel.get('name')
         tname = TDataStd_Name()
         tname.Set(TCollection_ExtendedString(pname))
         label.AddAttribute(tname)
         for child in children:
             object = self.model.getObject(child)
             name = object.get('name')
             extg = ExternalGeometry(self.model, object, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     # Root brackets
     compound = TopoDS_Compound()
     aBuilder.MakeCompound(compound)
     label = shape_tool.AddShape(compound)
     tname = TDataStd_Name()
     tname.Set(TCollection_ExtendedString('Brackets'))
     label.AddAttribute(tname)
     for br in self.model.brackets:
         guid = self.model.getGUID(br)
         name = br.get('name')
         if guid not in panelchildren:
             extg = ExternalGeometry(self.model, br, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     # Root plates
     compound = TopoDS_Compound()
     aBuilder.MakeCompound(compound)
     label = shape_tool.AddShape(compound)
     tname = TDataStd_Name()
     tname.Set(TCollection_ExtendedString('Plates'))
     label.AddAttribute(tname)
     for pl in self.model.plates:
         guid = self.model.getGUID(pl)
         name = pl.get('name')
         if guid not in panelchildren:
             extg = ExternalGeometry(self.model, pl, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     # Root pillars
     compound = TopoDS_Compound()
     aBuilder.MakeCompound(compound)
     label = shape_tool.AddShape(compound)
     tname = TDataStd_Name()
     tname.Set(TCollection_ExtendedString('Pillars'))
     label.AddAttribute(tname)
     for pil in self.model.pillars:
         guid = self.model.getGUID(pil)
         name = pil.get('name')
         if guid not in panelchildren:
             extg = ExternalGeometry(self.model, pil, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     step_writer.Perform(
         doc, TCollection_AsciiString(self.model.ocxfile.stem + '.stp'))
     return