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