def do_paint(self, gc: wx.GraphicsContext, fill: wx.Colour, selected: bool): self._recompute(for_collision=False) rxn_color: wx.Colour # Draw bezier curve if selected: rxn_color = get_theme('selected_reaction_fill') else: rxn_color = fill pen = gc.CreatePen(wx.GraphicsPenInfo(rxn_color).Width(self.thickness)) gc.SetPen(pen) # gc.StrokeLines([wx.Point2D(*(p * cstate.scale)) for p in self.bezier_points]) path = gc.CreatePath() points = [p for p in (self.node_intersection, self.handle.tip, self.centroid_handle.tip, self.real_center)] path.MoveToPoint(*points[0]) if self.bezierCurves: path.AddCurveToPoint(*points[1], *points[2], *points[3]) else: path.AddLineToPoint(*points[3]) gc.StrokePath(path) if selected: assert self.node_intersection is not None self.handle.base = self.node_intersection # Draw arrow tip if not self.is_source: color = get_theme('handle_color') if selected else fill self.paint_arrow_tip(gc, color)
def render_cutcode(self, cutcode: CutCode, gc: wx.GraphicsContext, x: int = 0, y: int = 0): last_point = None p = gc.CreatePath() for cut in cutcode: start = cut.start() end = cut.end() if last_point != start: p.MoveToPoint(start[0] + x, start[1] + y) if isinstance(cut, LineCut): p.AddLineToPoint(end[0] + x, end[1] + y) elif isinstance(cut, QuadCut): p.AddQuadCurveToPoint(cut.control[0] + x, cut.control[1] + y, end[0] + x, end[1] + y) elif isinstance(cut, CubicCut): p.AddCurveToPoint( cut.control1[0] + x, cut.control1[1] + y, cut.control2[0] + x, cut.control2[1] + y, end[0] + x, end[1] + y, ) elif isinstance(cut, RasterCut): image = cut.image try: matrix = Matrix(image.transform) except AttributeError: matrix = Matrix() step = cut.settings.raster_step matrix.post_scale(step, step) matrix.post_translate(x, y) gc.PushState() gc.ConcatTransform( wx.GraphicsContext.CreateMatrix(gc, ZMatrix(matrix))) cache = None cache_id = -1 try: cache = cut.cache cache_id = cut.cache_id except AttributeError: pass if cache_id != id(image.image): cache = None if cache is None: # max_allowed = 2048 cut.c_width, cut.c_height = image.image.size cut.cache = self.make_thumbnail(image.image) cut.cache_id = id(image.image) gc.DrawBitmap(cut.cache, 0, 0, cut.c_width, cut.c_height) gc.PopState() last_point = end gc.StrokePath(p) del p
def draw_cutcode(self, cutcode: CutCode, gc: wx.GraphicsContext, x: int = 0, y: int = 0): """ Draw cutcode object into wxPython graphics code. This code accepts x,y offset values. The cutcode laser offset can be set with a command with the rest of the cutcode remaining the same. So drawing the cutcode requires knowing what, if any offset is currently being applied. @param cutcode: flat cutcode object to draw. @param gc: wx.graphics context @param x: offset in x direction @param y: offset in y direction @return: """ p = None last_point = None color = None for cut in cutcode: c = cut.line_color if c is not color: color = c last_point = None if p is not None: gc.StrokePath(p) del p p = gc.CreatePath() self.set_pen(gc, c, width=7.0, alpha=127) start = cut.start end = cut.end if p is None: p = gc.CreatePath() if last_point != start: p.MoveToPoint(start[0] + x, start[1] + y) if isinstance(cut, LineCut): # Standard line cut. Applies to path object. p.AddLineToPoint(end[0] + x, end[1] + y) elif isinstance(cut, QuadCut): # Standard quadratic bezier cut p.AddQuadCurveToPoint(cut.c()[0] + x, cut.c()[1] + y, end[0] + x, end[1] + y) elif isinstance(cut, CubicCut): # Standard cubic bezier cut p.AddCurveToPoint( cut.c1()[0] + x, cut.c1()[1] + y, cut.c2()[0] + x, cut.c2()[1] + y, end[0] + x, end[1] + y, ) elif isinstance(cut, RasterCut): # Rastercut object. image = cut.image gc.PushState() matrix = Matrix.scale(cut.step_x, cut.step_y) matrix.post_translate(cut.offset_x + x, cut.offset_y + y) # Adjust image xy gc.ConcatTransform( wx.GraphicsContext.CreateMatrix(gc, ZMatrix(matrix))) try: cache = cut.cache cache_id = cut.cache_id except AttributeError: cache = None cache_id = -1 if cache_id != id(image): # Cached image is invalid. cache = None if cache is None: # No valid cache. Generate. cut.c_width, cut.c_height = image.size try: cut.cache = self.make_thumbnail(image, maximum=5000) except (MemoryError, RuntimeError): cut.cache = None cut.cache_id = id(image) if cut.cache is not None: # Cache exists and is valid. gc.DrawBitmap(cut.cache, 0, 0, cut.c_width, cut.c_height) else: # Image was too large to cache, draw a red rectangle instead. gc.SetBrush(wx.RED_BRUSH) gc.DrawRectangle(0, 0, cut.c_width, cut.c_height) gc.DrawBitmap(icons8_image_50.GetBitmap(), 0, 0, cut.c_width, cut.c_height) gc.PopState() elif isinstance(cut, RawCut): pass elif isinstance(cut, PlotCut): p.MoveToPoint(start[0] + x, start[1] + y) for px, py, pon in cut.plot: if pon == 0: p.MoveToPoint(px + x, py + y) else: p.AddLineToPoint(px + x, py + y) elif isinstance(cut, DwellCut): pass elif isinstance(cut, WaitCut): pass elif isinstance(cut, InputCut): pass elif isinstance(cut, OutputCut): pass last_point = end if p is not None: gc.StrokePath(p) del p