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 draw_shape(self, uid): """Draw the part (shape) with uid.""" context = self.canvas._display.Context if uid: if uid in self.transparency_dict: transp = self.transparency_dict[uid] else: transp = 0.0 part_data = doc.part_dict[uid] shape = part_data["shape"] color = part_data["color"] try: aisShape = AIS_Shape(shape) self.ais_shape_dict[uid] = aisShape 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) except AttributeError as e: print(e)
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()
##but WITHOUT ANY WARRANTY; without even the implied warranty of ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##GNU Lesser General Public License for more details. ## ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Core.AIS import AIS_Shape from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() myBox = BRepPrimAPI_MakeBox(60, 60, 50).Shape() context = display.Context context.SetAutoActivateSelection(False) aisShape = AIS_Shape(myBox) context.Display(aisShape, True) # Set shape transparency, a float number from 0.0 to 1.0 context.SetTransparency(aisShape, 0.6, True) owner = aisShape.GetOwner() drawer = aisShape.DynamicHilightAttributes() # TODO: how do we set the color ? Quantity_NOC_RED context.HilightWithColor(aisShape, drawer, True) display.View_Iso() display.FitAll() start_display()