Пример #1
0
def display_shape(shape, fmap):
    occ_display.EraseAll()
    ais = AIS_ColoredShape(shape)
    for f in fmap:
        ais.SetCustomColor(f, colors[fmap[f]])

    occ_display.Context.Display(ais.GetHandle())
    #    occ_display.View_Iso()
    occ_display.FitAll()
Пример #2
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 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, color(random(), random(), random()))

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

start_display()
Пример #3
0
    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)
    ]

    SHAPE, FMAP, ID_MAP, SHAPE_NAME = shape_drain()
    print(SHAPE_NAME)

    AIS = AIS_ColoredShape(SHAPE)
    for a_face in FMAP:
        AIS.SetCustomColor(a_face, COLORS[FMAP[a_face]])

    OCC_DISPLAY.Context.Display(AIS.GetHandle())
    OCC_DISPLAY.View_Iso()
    OCC_DISPLAY.FitAll()

    START_OCC_DISPLAY()
Пример #4
0
    def loadShape(self, shape_list):
        """
        Method for loading one or more shapes and displaying to Output Viewer.

        This method uses libraries of iges caf control for fetching sub-shape names within .igs files. This method
        is used when adding a case in the main routine.

        @param shape_list [list] First index contains the path of shape, second index contains a list of display
        exceptions, e.g: [[igs_2d_shape_path, ["HUB", "SHROUD"], [igs_3d_shape_path, ["STREAM"]]
        @return First return contains list of ais_shapes handles and second return contains a list of sub-shape names
        in strings
        """
        loaded_ais_shape = []
        loaded_h_ais_shape = []
        loaded_subshape_names = []
        default_displaying_h_ais_shape = []

        for shape_case in shape_list:

            loaded_shape_filename = os.path.basename(shape_case[0])
            exception_list = shape_case[1]
            exception_list = list(
                filter(None, exception_list)
            )  # Mistake-prevention of user filling of exception list

            # creates a handle for TdocStd documents
            h_doc = Handle_TDocStd_Document()

            # create the application
            app = _XCAFApp.XCAFApp_Application_GetApplication().GetObject()
            app.NewDocument(TCollection_ExtendedString(""), h_doc)

            # get root assembly
            doc = h_doc.GetObject()
            h_shape_tool = XCAFDoc_DocumentTool().ShapeTool(doc.Main())

            # creates a reader responsible for reading an IGS file
            reader = IGESCAFControl_Reader()
            reader.ReadFile(shape_case[0])

            #  Translates currently loaded IGES file into the document
            reader.Transfer(doc.GetHandle())

            # labels for the shapes. Every IGS file contains a name for each individual shape
            labels = TDF_LabelSequence()

            shape_tool = h_shape_tool.GetObject()
            shape_tool.GetShapes(labels)

            # gets the number of individual shapes contained in the igs file
            nb = reader.NbShapes()

            # for each individual shape gets the label nad creates a AIS_Shape for data contained in reader.Shape()
            for i in range(1, nb + 1):
                label = labels.Value(i)

                h_name = Handle_TDataStd_Name()
                label.FindAttribute(TDataStd_Name_GetID(), h_name)
                str_dump = h_name.GetObject().DumpToString()
                name_subshape = str_dump.split('|')[-2]
                name = "%s - %s" % (loaded_shape_filename, name_subshape)

                loaded_subshape_names.append(name)

                shape = AIS_ColoredShape(reader.Shape(i))
                loaded_ais_shape.append(shape)
                loaded_h_ais_shape.append(shape.GetHandle())

                if not any(iterator in name_subshape
                           for iterator in exception_list):
                    default_displaying_h_ais_shape.append(shape.GetHandle())

                self.op_viewer.master_shape_list.append(shape.GetHandle())

            # number of cases is a variable used to make the loaded shape color different from the previous one
            number_of_cases = self.op_viewer.model.rowCount(
                self.op_viewer.ui_case_treeview.rootIndex())

            # sets the default attributes for ais shapes handles
            for h_ais_shape in loaded_h_ais_shape:
                self.op_viewer.display.Context.SetDeviationCoefficient(
                    h_ais_shape,
                    self.op_viewer.DC / self.op_viewer.default_shape_factor)
                self.op_viewer.display.Context.SetHLRDeviationCoefficient(
                    h_ais_shape, self.op_viewer.DC_HLR /
                    self.op_viewer.default_shape_factor)
                self.op_viewer.display.Context.SetColor(
                    h_ais_shape, shape_colordictionary[shape_colorlist[
                        (self.op_viewer.default_shape_color + number_of_cases)
                        % len(shape_colorlist)]])

                self.op_viewer.display.Context.SetTransparency(
                    h_ais_shape, self.op_viewer.default_shape_transparency)

        # displays the handles of the ais_shapes in the viewer3d context.
        for h_ais_shape in default_displaying_h_ais_shape:
            self.op_viewer.display.Context.Display(h_ais_shape)

        return loaded_h_ais_shape, loaded_subshape_names