Exemplo n.º 1
0
    def axis(self):
        center = gp_Pnt(0, 0, 0)
        zd = gp_Dir(0, 0, 10000)
        self.display.Context.Display(
            self.mk_colored_line(center, zd, rgb_color(0, 0, 1), 0, 1.0),
            False)

        xd = gp_Dir(1, 0, 0)
        self.display.Context.Display(
            self.mk_colored_line(center, xd, rgb_color(1, 0, 0), 0, 1.0),
            False)

        yd = gp_Dir(0, 1, 0)
        self.display.Context.Display(
            self.mk_colored_line(center, yd, rgb_color(0, 1, 0), 0, 1.0),
            False)
Exemplo n.º 2
0
    def Bulk_stptoimag(self):
        pass
        self.file_list = os.listdir(self.chose_document)
        print(self.file_list)
        for file in self.file_list:
            self.canva._display.EraseAll()
            self.canva._display.hide_triedron()
            self.canva._display.display_triedron()
            if "stp" in file or "step" in file or "iges" in file:
                try:
                    if file == "iseg":
                        continue
                    else:
                        read_path = os.path.join(self.chose_document, file)
                        the_shape = read_step_file(read_path)
                        name = file.split(".")
                        ais_shape = AIS_ColoredShape(the_shape)
                        for e in TopologyExplorer(the_shape).solids():
                            rnd_color = (random(), random(), random())
                            ais_shape.SetCustomColor(e,
                                                     rgb_color(0.5, 0.5, 0.5))

                        self.canva._display.Context.Display(ais_shape, True)
                        self.canva._display.FitAll()
                        path = self.chose_document + "\\" + name[0] + ".bmp"
                        self.canva._display.ExportToImage(path)

                except:
                    pass

            self.statusbar.showMessage("状态:表格生成成功")
Exemplo n.º 3
0
 def display(self, writer=None):
     debug("shape Display")
     if self.shape != None:
         if (writer != None):
             writer.Transfer(self.shape)
         else:
             debug("Line style is %s" % (self.style, ))
             ais_context = Singleton.sd.display.GetContext()
             if (self.style == 'hidden'):
                 ais_shp = AIS_Shape(self.shape)
                 ais_shp.SetWidth(0.1)
                 ais_shp.SetTransparency(0.10)
                 ais_shp.SetColor(rgb_color(0, 0, 0))
                 aspect = ais_shp.Attributes().WireAspect()
                 aspect.SetColor(rgb_color(0, 0, 0))
                 aspect.SetTypeOfLine(1)
                 ais_context.Display(ais_shp, True)
             elif (self.style == 'main_projection'):
                 ais_shp = AIS_Shape(self.shape)
                 ais_shp.SetWidth(5)
                 #ais_shp.SetTransparency(0)
                 #ais_shp.SetColor(rgb_color(0,0,0))
                 aspect = ais_shp.Attributes().WireAspect()
                 aspect.SetColor(rgb_color(0, 0, 0))
                 aspect.SetTypeOfLine(0)
                 ais_context.Display(ais_shp, True)
             else:
                 ais_context = Singleton.sd.display.GetContext()
                 ais_shp = AIS_Shape(self.shape)
                 ais_shp.SetWidth(2.0)
                 ais_shp.SetTypeOfHLR(2)
                 if (is_var_set(self.shape_color)):
                     ais_shp.SetColor(self.shape_color)
                 else:
                     ais_shp.SetColor(Quantity_Color(Quantity_NOC_PERU))
                 if (self.display_mode == DISP_MODE_WIREFRAME):
                     ais_context.SetDisplayMode(ais_shp, AIS_WireFrame,
                                                True)
                 else:
                     ais_context.SetDisplayMode(ais_shp, AIS_Shaded, True)
                 ais_context.Display(ais_shp, True)
     else:
         warning("Empty shape")
Exemplo n.º 4
0
def plot_splinegons(splinegons, transparency=0.5, color='random'):
    """Plots splinegons.

    Parameters
    ----------
    splinegons : list
        Each member of the list is a `TopoDS_Face` object, the surface of a splinegon.
    transparency : float, optional
        The transparency value should be between 0 and 1. At 0, an object will be totally opaque,
        and at 1, fully transparent.
    color : tuple or str, optional
        Color of the splinegons. Either 'random' to associate a random color for each splinegon
        in the list `splinegons` or a 3-tuple with entries between 0 and 1 to give the same RGB
        values to all the splinegons.

    Returns
    -------
    None

    See Also
    --------
    splinegonize

    """
    display, start_display, add_menu, add_function_to_menu = init_display()
    # display.default_drawer.SetFaceBoundaryDraw(False)
    # Check the format of the optional arguments
    if not (0 <= transparency <= 1):
        raise ValueError('Transparency must be in the interval [0, 1].')
    if color != 'random':
        # TODO: Check for format
        col = rgb_color(*color)
    for i, splinegon in enumerate(splinegons):
        # Plot the faces
        if color == 'random':
            col = rgb_color(np.random.random(), np.random.random(),
                            np.random.random())
        display.DisplayShape(splinegon,
                             update=True,
                             transparency=transparency,
                             color=col)
    start_display()
Exemplo n.º 5
0
 def color(self, color):
     debug("Trying to set color: %s" % (color, ))
     new_color = Noval
     if (type(color) == list):
         c = color[:]
         if (len(c) < 4):
             c.append(1.0)
         new_color = rgb_color(c[0], c[1], c[2])
     else:
         if (unstringify(color) not in colorname_map):
             warning("Unknown color: %s" % (color, ))
         else:
             new_color = Quantity_Color(colorname_map[unstringify(color)])
     if not is_var_set(self.shape_color):
         self.shape_color = new_color
Exemplo n.º 6
0
    def __init__(self, shape_path, occ_display):
        self.colors = []
        rgb_list = np.array(
            np.meshgrid([0.9, 0.6, 0.3], [0.9, 0.6, 0.3],
                        [0.9, 0.6, 0.3])).T.reshape(-1, 3)
        for rgb in rgb_list:
            self.colors.append(rgb_color(rgb[0], rgb[1], rgb[2]))

        self.shape_path = shape_path
        self.names = [
            name.split(os.sep)[-1].split('.')[0]
            for name in glob.glob(shape_path + '*.step')
        ]
        self.shape_cnt = -1  #random.randint(0, len(self.names))
        self.occ_display = occ_display
Exemplo n.º 7
0
def random_color():
    return rgb_color(random.random(), random.random(), random.random())
Exemplo n.º 8
0
from OCC.Core.BRep import BRep_Builder

import occ_utils

import pickle
import os
import numpy as np

display, start_display, add_menu, add_function_to_menu = init_display()

colors = []
rgb_list = np.array(
    np.meshgrid([0.9, 0.6, 0.3], [0.9, 0.6, 0.3],
                [0.9, 0.6, 0.3])).T.reshape(-1, 3)
for rgb in rgb_list:
    colors.append(rgb_color(rgb[0], rgb[1], rgb[2]))

FEAT_NAMES = [
    'through_hole',
    'triangular_passage',
    'rectangular_passage',
    '6sides_passage',
    'triangular_through_slot',
    'rectangular_through_slot',
    'circular_through_slot',
    'rectangular_through_step',
    '2sides_through_step',
    'slanted_through_step',  # 10 through features
    'Oring',
    'blind_hole',
    'triangular_pocket',
Exemplo n.º 9
0
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib_Add
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.Quantity import Quantity_Color
from OCC.Core.Quantity import Quantity_Color, Quantity_TOC_RGB
from OCC.Display.SimpleGui import init_display
from OCC.Display.OCCViewer import Viewer3d
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox

the_shape = read_step_file('SFU01610-4.step')
print(type(the_shape))
# loads brep shape
#cylinder_head = TopoDS_Shape()
#builder = BRep_Builder()
#breptools_Read(cylinder_head, './models/cylinder_head.brep', builder)
# render cylinder head in x3dom
my_renderer = x3dom_renderer.X3DomRenderer(path="d:\\123")
ais_shape = AIS_ColoredShape(the_shape)

#display.DisplayShape(my_box,update=True)
#display.Context.Display(cube,True)
for e in TopologyExplorer(the_shape).shells():
    rnd_color = (random(), random(), random())
    ais_shape.SetCustomColor(e, rgb_color(random(), random(), random()))
    my_renderer.DisplayShape(e,
                             export_edges=True,
                             color=(random(), random(), random()))

my_renderer.render()
imagine importing a CAD file and wanting to set color to a subshape of the imported CAD data
with OCE 0.17 / OCC 6.8.0, this became easy, since colors can be set for subshapes

"""

from __future__ import print_function

from random import random

from OCC.AIS import AIS_ColoredShape
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.OCCViewer import rgb_color
from OCC.Display.SimpleGui import init_display

from core_topology_traverse import Topo

display, start_display, add_menu, add_function_to_menu = init_display()

my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()

ais = AIS_ColoredShape(my_box)

for fc in Topo(my_box).faces():
    # set a custom color per-face
    ais.SetCustomColor(fc, rgb_color(random(), random(), random()))

display.Context.Display(ais.GetHandle())
display.FitAll()

start_display()
Exemplo n.º 11
0
imagine importing a CAD file and wanting to set color to a subshape of the imported CAD data
with OCE 0.17 / OCC 6.8.0, this became easy, since colors can be set for subshapes

"""

from __future__ import print_function

from random import random

from OCC.AIS import AIS_ColoredShape
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.OCCViewer import rgb_color
from OCC.Display.SimpleGui import init_display

from core_topology_traverse import Topo

display, start_display, add_menu, add_function_to_menu = init_display()

my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()

ais = AIS_ColoredShape(my_box)

for fc in Topo(my_box).faces():
    # set a custom color per-face
    ais.SetCustomColor(fc, rgb_color(random(), random(), random()))

display.Context.Display(ais.GetHandle())
display.FitAll()

start_display()
Exemplo n.º 12
0
    for shape_face in fset:
        id_map[shape_face] = fid
        fid += 1

    return shape, name_map, id_map, shape_name


if __name__ == '__main__':
    print('model_factory.py')

    OCC_DISPLAY, START_OCC_DISPLAY, ADD_MENU, ADD_FUNCTION_TO_MENU = init_display(
    )
    OCC_DISPLAY.EraseAll()

    COLORS = [
        rgb_color(0, 0, 0),
        rgb_color(0.75, 0.75, 0.75),
        rgb_color(1, 0, 0),
        rgb_color(1, 0.5, 0),
        rgb_color(0, 1, 1),
        rgb_color(1, 0, 1),
        rgb_color(1, 0.8, 0.8),
        rgb_color(1, 1, 0.8),
        rgb_color(0.8, 1, 1),
        rgb_color(1, 0.8, 1),
        rgb_color(0.4, 0, 0),
        rgb_color(0.4, 0.4, 0),
        rgb_color(0, 0.4, 0.4),
        rgb_color(0.4, 0, 0.4)
    ]