Exemple #1
0
    def display_shape(self):
        self.occ_display.EraseAll()
        AIS = AIS_ColoredShape(self.shape)
        for a_face in self.label_map:
            AIS.SetCustomColor(a_face, self.colors[self.label_map[a_face]])

        self.occ_display.Context.Display(AIS)
        self.occ_display.View_Iso()
        self.occ_display.FitAll()
Exemple #2
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()
Exemple #3
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()
Exemple #4
0
    def _get_viewer(self):

        return self.canvas._display.GetViewer().GetObject()

    def _get_context(self):

        return self.canvas._display.GetContext().GetObject()


if __name__ == "__main__":

    import sys
    from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox

    app = QApplication(sys.argv)
    viewer = OCCViewer()
    viewer.show_line()

    dlg = QDialog()
    dlg.setFixedHeight(400)
    dlg.setFixedWidth(600)

    layout(dlg, (viewer, ), dlg)
    dlg.show()

    box = BRepPrimAPI_MakeBox(20, 20, 30)
    box_ais = AIS_ColoredShape(box.Shape())
    viewer.display(box_ais)

    sys.exit(app.exec_())
Exemple #5
0
def make_AIS(obj: cq.Workplane):

    shape = to_compound(obj)
    ais = AIS_ColoredShape(shape.wrapped)

    return ais, shape
Exemple #6
0
def make_AIS(obj : cq.Workplane):
    
    ais = AIS_ColoredShape(to_compound(obj).wrapped)
    
    return ais
Exemple #7
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()
    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