def handleSelection(self):

        inspected_items = self.inspected_items
        self.sigRemoveObjects.emit(inspected_items)
        inspected_items.clear()

        items = self.selectedItems()
        if len(items) == 0:
            return

        item = items[-1]
        if type(item) is CQStackItem:
            cq_plane = item.workplane.plane
            dim = item.workplane.largestDimension()
            plane = gp_Ax3(cq_plane.origin.toPnt(), cq_plane.zDir.toDir(),
                           cq_plane.xDir.toDir())
            self.sigChangePlane.emit(plane)
            self.sigShowPlane[bool, float].emit(True, dim)

            for child in (item.child(i) for i in range(item.childCount())):
                obj = child.cq_item
                if hasattr(obj, 'wrapped') and type(obj) != Vector:
                    ais = AIS_ColoredShape(obj.wrapped)
                    inspected_items.append(ais)

        else:
            self.sigShowPlane.emit(False)
            obj = item.cq_item
            if hasattr(obj, 'wrapped') and type(obj) != Vector:
                ais = AIS_ColoredShape(obj.wrapped)
                inspected_items.append(ais)

        self.sigDisplayObjects.emit(inspected_items, False)
Beispiel #2
0
def make_AIS(obj: Union[cq.Workplane, List[cq.Workplane], cq.Shape,
                        List[cq.Shape], cq.Assembly, AIS_Shape],
             options={}):

    shape = None

    if isinstance(obj, cq.Assembly):
        label, shape = toCAF(obj)
        ais = XCAFPrs_AISObject(label)
    elif isinstance(obj, AIS_Shape):
        ais = obj
    else:
        shape = to_compound(obj)
        ais = AIS_ColoredShape(shape.wrapped)

    if 'alpha' in options:
        ais.SetTransparency(options['alpha'])
    if 'color' in options:
        ais.SetColor(to_occ_color(options['color']))
    if 'rgba' in options:
        r, g, b, a = options['rgba']
        ais.SetColor(to_occ_color((r, g, b)))
        ais.SetTransparency(a)

    return ais, shape
Beispiel #3
0
def make_AIS(obj : Union[cq.Workplane, cq.Shape], options={}):

    shape = to_compound(obj)
    ais = AIS_ColoredShape(shape.wrapped)
    
    if 'alpha' in options:
        ais.SetTransparency(options['alpha'])
    if 'color' in options:
        ais.SetColor(to_occ_color(options['color']))
    if 'rgba' in options:
        r,g,b,a = options['rgba']
        ais.SetColor(to_occ_color((r,g,b)))
        ais.SetTransparency(a)

    return ais,shape
Beispiel #4
0
def make_AIS(obj : Union[cq.Workplane, cq.Shape], options={}):
    
    if isinstance(obj, cq.Shape):
        obj = to_workplane(obj)
    elif isinstance(obj, TopoDS_Shape):
        obj = to_workplane(cq.Shape.cast(obj))

    shape = to_compound(obj)
    ais = AIS_ColoredShape(shape.wrapped)
    
    if 'alpha' in options:
        ais.SetTransparency(options['alpha'])
    if 'color' in options:
        ais.SetColor(to_occ_color(options['color']))
    if 'rgba' in options:
        r,g,b,a = options['rgba']
        ais.SetColor(to_occ_color((r,g,b)))
        ais.SetTransparency(a)

    return ais,shape
Beispiel #5
0
def get_occ_color(ais : AIS_ColoredShape) -> QColor:
    
    color = Quantity_Color()
    ais.Color(color)
    
    return QColor.fromRgbF(color.Red(), color.Green(), color.Blue())
Beispiel #6
0
        ctx = self._get_context()
        ctx.ClearSelected(False)

        for obj in ais:
            ctx.AddOrRemoveSelected(obj,False)

        self.redraw()


if __name__ == "__main__":

    import sys
    from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox

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

    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_())