Exemplo n.º 1
0
def line():
    # create a line
    p1 = gp_Pnt(2., 3., 4.)
    d1 = gp_Dir(4., 5., 6.)
    line1 = Geom_Line(p1, d1)

    ais_line1 = AIS_Line(line1)

    # if we need to edit color, we can simply use SetColor
    # ais_line1.SetColor(Quantity_NOC_RED)

    # but actually we need to edit more, not just color. Line width and style as well
    # To do that, we need to do use AIS_Drawer and apply it to ais_line1
    drawer = Prs3d_Drawer()
    ais_line1.SetAttributes(drawer)

    display.Context.Display(ais_line1, False)
    # we can apply the same rule for other lines by just doing a for loop
    for i in range(1, 5):
        p2 = gp_Pnt(i, 2., 5.)
        d2 = gp_Dir(4 * i, 6., 9.)
        line2 = Geom_Line(p2, d2)

        ais_line2 = AIS_Line(line2)

        width = float(i)
        drawer = ais_line2.Attributes()
        # asp : first parameter color, second type, last width
        asp = Prs3d_LineAspect(9 * i, i, width)
        drawer.SetLineAspect(asp)
        ais_line2.SetAttributes(drawer)

        display.Context.Display(ais_line2, False)
    start_display()
Exemplo n.º 2
0
    def __init__(self, name):
        self.data = []
        self.rootNode: Node = None
        self.objectName = name
        self.objectCounter = 0
        self.curCoordinateSystem = gp_Ax3(gp.XOY())

        self.myType = Sketch_ObjectType.MainSketchType
        self.myColor = Quantity_Color(Quantity_NOC_YELLOW)
        self.myStyle = Aspect_TOL_SOLID
        self.myWidth = 1.0
        self.myPrs3dAspect = Prs3d_LineAspect(self.myColor, self.myStyle,
                                              self.myWidth)

        self.myPolylineMode = False
        self.curPnt2d = gp.Origin2d()
        self.myFirstgp_Pnt2d = gp.Origin2d()
        self.mySecondgp_Pn2d = gp.Origin2d()

        self.myFirstPoint: Geom_CartesianPoint = Geom_CartesianPoint(
            gp.Origin())
        self.mySecondPoint: Geom_CartesianPoint = Geom_CartesianPoint(
            gp.Origin())
        self.myRubberLine = AIS_Line(self.myFirstPoint, self.mySecondPoint)
        self.myRubberLine.SetColor(Quantity_Color(Quantity_NOC_LIGHTPINK1))
Exemplo n.º 3
0
    def set_line_aspect(self, width, aspect_type=Aspect_TOL_SOLID):
        self.width = width

        lineAspect = Prs3d_LineAspect(self._color.to_Quantity_Color(),
                                      aspect_type, self.width)

        self.ais_object.Attributes().SetLineAspect(lineAspect)
Exemplo n.º 4
0
    def mk_colored_line(self, start, direction, color, linestyle, width):
        line = Geom_Line(start, direction)
        ais_line = AIS_Line(line)

        drawer = ais_line.Attributes()
        aspect = Prs3d_LineAspect(color, linestyle, width)
        drawer.SetLineAspect(aspect)
        ais_line.SetAttributes(drawer)
        return ais_line
Exemplo n.º 5
0
 def draw_wp(self, uid):
     """Draw the workplane with uid."""
     context = self.canvas._display.Context
     if uid:
         wp = self.wp_dict[uid]
         border = wp.border
         if uid == self.activeWpUID:
             borderColor = Quantity_Color(Quantity_NOC_DARKGREEN)
         else:
             borderColor = Quantity_Color(Quantity_NOC_GRAY)
         aisBorder = AIS_Shape(border)
         context.Display(aisBorder, True)
         context.SetColor(aisBorder, borderColor, True)
         transp = 0.8  # 0.0 <= transparency <= 1.0
         context.SetTransparency(aisBorder, transp, True)
         drawer = aisBorder.DynamicHilightAttributes()
         context.HilightWithColor(aisBorder, drawer, True)
         clClr = Quantity_Color(Quantity_NOC_MAGENTA1)
         for cline in wp.clines:
             geomline = wp.geomLineBldr(cline)
             aisline = AIS_Line(geomline)
             aisline.SetOwner(geomline)
             drawer = aisline.Attributes()
             # asp parameters: (color, type, width)
             asp = Prs3d_LineAspect(clClr, 2, 1.0)
             drawer.SetLineAspect(asp)
             aisline.SetAttributes(drawer)
             context.Display(aisline, False)  # (see comment below)
             # 'False' above enables 'context' mode display & selection
         pntlist = wp.intersectPts()  # type <gp_Pnt>
         for point in pntlist:
             self.canvas._display.DisplayShape(point)
         for ccirc in wp.ccircs:
             aiscirc = AIS_Circle(wp.convert_circ_to_geomCirc(ccirc))
             drawer = aisline.Attributes()
             # asp parameters: (color, type, width)
             asp = Prs3d_LineAspect(clClr, 2, 1.0)
             drawer.SetLineAspect(asp)
             aiscirc.SetAttributes(drawer)
             context.Display(aiscirc, False)  # (see comment below)
             # 'False' above enables 'context' mode display & selection
         for edge in wp.edgeList:
             self.canvas._display.DisplayShape(edge, color="WHITE")
         self.canvas._display.Repaint()
Exemplo n.º 6
0
 def redraw(self):
     context = self.canva._display.Context
     if not self.registeredCallback:
         self.canva._display.SetSelectionModeNeutral()
         context.SetAutoActivateSelection(True)
     context.RemoveAll(True)
     for uid in self.drawList:
         if uid in self._partDict.keys():
             if uid in self._transparencyDict.keys():
                 transp = self._transparencyDict[uid]
             else:
                 transp = 0.0
             color = self._colorDict[uid]
             aisShape = AIS_Shape(self._partDict[uid])
             context.Display(aisShape, True)
             context.SetColor(aisShape, color, True)
             # Set shape transparency, a float from 0.0 to 1.0
             context.SetTransparency(aisShape, transp, True)
             drawer = aisShape.DynamicHilightAttributes()
             context.HilightWithColor(aisShape, drawer, True)
         elif uid in self._wpDict.keys():
             wp = self._wpDict[uid]
             border = wp.border
             if uid == self.activeWpUID:
                 borderColor = Quantity_Color(Quantity_NOC_DARKGREEN)
             else:
                 borderColor = Quantity_Color(Quantity_NOC_GRAY)
             aisBorder = AIS_Shape(border)
             context.Display(aisBorder, True)
             context.SetColor(aisBorder, borderColor, True)
             transp = 0.8  # 0.0 <= transparency <= 1.0
             context.SetTransparency(aisBorder, transp, True)
             drawer = aisBorder.DynamicHilightAttributes()
             context.HilightWithColor(aisBorder, drawer, True)
             clClr = Quantity_Color(Quantity_NOC_MAGENTA1)
             for cline in wp.clines:
                 geomline = wp.geomLineBldr(cline)
                 aisline = AIS_Line(geomline)
                 aisline.SetOwner(geomline)
                 drawer = aisline.Attributes()
                 # asp parameters: (color, type, width)
                 asp = Prs3d_LineAspect(clClr, 2, 1.0)
                 drawer.SetLineAspect(asp)
                 aisline.SetAttributes(drawer)
                 context.Display(aisline, False)  # (see comment below)
                 # 'False' above enables 'context' mode display & selection
             pntlist = wp.intersectPts()  # type <gp_Pnt>
             for point in pntlist:
                 self.canva._display.DisplayShape(point)
             for ccirc in wp.ccircs:
                 aiscirc = AIS_Circle(wp.convert_circ_to_geomCirc(ccirc))
                 drawer = aisline.Attributes()
                 # asp parameters: (color, type, width)
                 asp = Prs3d_LineAspect(clClr, 2, 1.0)
                 drawer.SetLineAspect(asp)
                 aiscirc.SetAttributes(drawer)
                 context.Display(aiscirc, False)  # (see comment below)
                 # 'False' above enables 'context' mode display & selection
             for edge in wp.edgeList:
                 self.canva._display.DisplayShape(edge, color="WHITE")
             self.canva._display.Repaint()