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 relative_position(event=None):
    # create a texture
    aTextureItem = TextureItem(
        TCollection_AsciiString("./images/carre-200.png"),
        display.GetView().GetObject(), display.GetOverLayer())
    aTextureItem.SetRelativePosition(30, 60)  # 30% width, 60% width
    display.register_overlay_item(aTextureItem)
def absolute_position(event=None):
    # create a texture
    aTextureItem = TextureItem(
        TCollection_AsciiString("./images/carre-200.png"),
        display.GetView().GetObject(), display.GetOverLayer())
    aTextureItem.SetAbsolutePosition(50, 50)
    display.register_overlay_item(aTextureItem)
Пример #4
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"
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)
Пример #6
0
def set_label_name(label, name):
    """

    Sets the name of a :class:`.OCC.TDF.TDF_Label` (**label**)

    :param label: :class:`.OCC.TDF.TDF_Label`
    :param name: new name for a :class:`.OCC.TDF.TDF_Label`

    """
    entry = TCollection_AsciiString()
    TDF_Tool.Entry(label, entry)
    N = Handle_TDataStd_Name()
    label.FindAttribute(TDataStd_Name_GetID(), N)
    n = N.GetObject()
    n.Set(TCollection_ExtendedString(name.encode("latin-1")))
Пример #7
0
def get_label_name(lab):
    """

    Returns the name of a :class:`.OCC.TDF.TDF_Label` (**lab**)

    :param lab: :class:`.OCC.TDF.TDF_Label`

    """
    entry = TCollection_AsciiString()
    TDF_Tool.Entry(lab, entry)
    N = Handle_TDataStd_Name()
    lab.FindAttribute(TDataStd_Name_GetID(), N)
    n = N.GetObject()
    return unicode(n.Get().PrintToString(),
                   errors='ignore')  #.decode("latin-1")
Пример #8
0
    def set_parameter(self, name, value, does_commit):
        # call registered callbacks. Rules/Relations have to be updated before the geometry is modified. 
        # Be careful: just rules and Callbacks have to be called before the geometry is modified
        for pre_solver_callback in self.pre_solver_callbacks:
            pre_solver_callback()

        if does_commit:
            self.doc.NewCommand()
        # "" and True, here after are maybe to change
        self.myEngine.SetInterpreterConstant(self.docId, TCollection_AsciiString(name), value,TCollection_AsciiString(""),True)

        #update registered solvers
        if self.AUTOMATIC_UPDATE:
            self.solve()       
            
            if does_commit:
                self.doc.CommitCommand()            
            
            self.update_display()
        
        #Call post_solver callbacks
        for post_solver_callback in self.post_solver_callbacks:
            post_solver_callback()
{
    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().GetObject().ShadingAspect().GetObject().aspect(
).GetObject()

if aProgram.IsDone():
    aspect.SetShaderProgram(aProgram.GetHandle())
else:
    raise AssertionError("no valid shader program found")
Пример #10
0
    def DisplayShape(self,
                     shapes,
                     material=None,
                     texture=None,
                     color=None,
                     transparency=None,
                     update=False):
        '''
        '''
        # 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
        else:
            SOLO = False

        ais_shapes = []

        for shape in shapes:
            if material or texture:
                if texture:
                    self.View.SetSurfaceDetail(OCC.V3d.V3d_TEX_ALL)
                    shape_to_display = OCC.AIS.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 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(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