Example #1
0
def figure_simple_display(ai_figure, ai_overlay_figure=[], ai_parameter_info=""):
  """ Display the figure with red lines in the Tkinter Two_Canvas GUI
      If you want a finer control on the way outlines are displayed (color, width, overlay), you need to work at the outline level (not figure level)
  """
  print("Figure simple display with Tkinter")
  # convert all outlines in format-B
  # graphic layer
  graphic_figure = []
  i = 0
  for i_outline in ai_figure:
    if(cnc_outline.check_outline_format(i_outline)==2):
      print("WARN441: Warning, the outline {:d} must be converted in format-B with ideal_outline()!".format(i))
      graphic_figure.append(cnc_outline.ideal_outline(i_outline, "figure_simple_display"))
    else:
      graphic_figure.append(i_outline)
    i += 1
  # overlay layer
  overlay_figure = []
  i = 0
  for i_outline in ai_overlay_figure:
    if(cnc_outline.check_outline_format(i_outline)==2):
      print("WARN442: Warning, the overlay outline {:d} must be converted in format-B with ideal_outline()!".format(i))
      overlay_figure.append(cnc_outline.ideal_outline(i_outline, "figure_simple_display_overlay"))
    else:
      overlay_figure.append(i_outline)
    i += 1
  # start GUI
  tk_root = Tkinter.Tk()
  fsd_canvas = Two_Canvas(tk_root)
  # callback function for display_backend
  def sub_fsd_canvas_graphics(ai_rotation_direction, ai_angle_position):
    # angle position
    l_angle_position = float(ai_angle_position)/100
    #
    r_canvas_graphics = []
    for ol in overlay_figure:
      rotated_ol = cnc_outline.outline_rotate(ol, 0, 0, l_angle_position) # rotation of center (0,0) and angle l_angle_position
      r_canvas_graphics.append(('overlay_lines', outline_arc_line(rotated_ol, 'tkinter'), 'orange', 2))
    for ol in graphic_figure:
      rotated_ol = cnc_outline.outline_rotate(ol, 0, 0, l_angle_position) # rotation of center (0,0) and angle l_angle_position
      r_canvas_graphics.append(('graphic_lines', outline_arc_line(rotated_ol, 'tkinter'), 'red', 1))
    return(r_canvas_graphics)
  # end of callback function
  fsd_canvas.add_canvas_graphic_function(sub_fsd_canvas_graphics)
  fsd_canvas.add_parameter_info(ai_parameter_info)
  tk_root.mainloop()
  del (tk_root, fsd_canvas)
  time.sleep(1.0)
  return(0)
def ideal_figure(ai_figure, ai_error_msg_id):
    """ apply the ideal_outline function to all outlines of the input figure
  """
    r_figure = []
    for i in range(len(ai_figure)):
        # print("dbg145:", ai_figure[i])
        if cnc_outline.check_outline_format(ai_figure[i]) == 2:
            r_figure.append(cnc_outline.ideal_outline(ai_figure[i], "{:s}.ol{:d}".format(ai_error_msg_id, i)))
        else:  # circle of format-B
            r_figure.append(ai_figure[i])
    return r_figure
Example #3
0
def ideal_figure(ai_figure, ai_error_msg_id):
    """ apply the ideal_outline function to all outlines of the input figure
  """
    r_figure = []
    for i in range(len(ai_figure)):
        #print("dbg145:", ai_figure[i])
        if (cnc_outline.check_outline_format(ai_figure[i]) == 2):
            r_figure.append(
                cnc_outline.ideal_outline(
                    ai_figure[i], "{:s}.ol{:d}".format(ai_error_msg_id, i)))
        else:  # circle of format-B
            r_figure.append(ai_figure[i])
    return (r_figure)
Example #4
0
def figure_simple_display(ai_figure,
                          ai_overlay_figure=[],
                          ai_parameter_info=""):
    """ Display the figure with red lines in the Tkinter Two_Canvas GUI
      If you want a finer control on the way outlines are displayed (color, width, overlay), you need to work at the outline level (not figure level)
  """
    print("Figure simple display with Tkinter")
    # convert all outlines in format-B
    # graphic layer
    graphic_figure = []
    i = 0
    for i_outline in ai_figure:
        if (cnc_outline.check_outline_format(i_outline) == 2):
            print(
                "WARN441: Warning, the outline {:d} must be converted in format-B with ideal_outline()!"
                .format(i))
            graphic_figure.append(
                cnc_outline.ideal_outline(i_outline, "figure_simple_display"))
        else:
            graphic_figure.append(i_outline)
        i += 1
    # overlay layer
    overlay_figure = []
    i = 0
    for i_outline in ai_overlay_figure:
        if (cnc_outline.check_outline_format(i_outline) == 2):
            print(
                "WARN442: Warning, the overlay outline {:d} must be converted in format-B with ideal_outline()!"
                .format(i))
            overlay_figure.append(
                cnc_outline.ideal_outline(i_outline,
                                          "figure_simple_display_overlay"))
        else:
            overlay_figure.append(i_outline)
        i += 1
    # start GUI
    tk_root = Tkinter.Tk()
    fsd_canvas = Two_Canvas(tk_root)

    # callback function for display_backend
    def sub_fsd_canvas_graphics(ai_rotation_direction, ai_angle_position):
        # angle position
        l_angle_position = float(ai_angle_position) / 100
        #
        r_canvas_graphics = []
        for ol in overlay_figure:
            rotated_ol = cnc_outline.outline_rotate(
                ol, 0, 0, l_angle_position
            )  # rotation of center (0,0) and angle l_angle_position
            r_canvas_graphics.append(
                ('overlay_lines', outline_arc_line(rotated_ol,
                                                   'tkinter'), 'orange', 2))
        for ol in graphic_figure:
            rotated_ol = cnc_outline.outline_rotate(
                ol, 0, 0, l_angle_position
            )  # rotation of center (0,0) and angle l_angle_position
            r_canvas_graphics.append(
                ('graphic_lines', outline_arc_line(rotated_ol,
                                                   'tkinter'), 'red', 1))
        return (r_canvas_graphics)

    # end of callback function
    fsd_canvas.add_canvas_graphic_function(sub_fsd_canvas_graphics)
    fsd_canvas.add_parameter_info(ai_parameter_info)
    tk_root.mainloop()
    del (tk_root, fsd_canvas)
    time.sleep(1.0)
    return (0)
Example #5
0
def outline_arc_line(ai_segments, ai_backend):
    """ Generates the arcs and lines outline according to the selected backend
      Possible backend: freecad, mozman dxfwrite, mozman svgwrite, Tkinter.
      ai_segments is a list of segments (ie line or arc)
      If ai_segments is a list/tuple of list/tuple, it's a list of segments (ie line or arc)
      a segment starts from the last point of the previous segment.
      a line is defined by a list of two floats [x-end, y-end]
      an arc is defined by a list of four floats [x-mid, y-mid, x-end, y-end]
      The first element of ai_segments is the starting point, i.e. a list of two floats [x-start, y-start]
      If the last point [x-end, y-end] of the last segment is equal to [x-start, y-start] the outline is closed.
      ai_segments can be made with lists or tuples or a mix of both.
      From a programming point of view, ai_segments is a tuple of 2-tulpes and/or 4-tuples.
      eg: ai_segments = [ [x1,y1], .. [x2,y2], .. [x3,y3,x4,y4], .. ]
      If ai_segments is a list/tuple of three int/float, it's a circle
  """
    r_outline = ''
    #print("dbg204: len(ai_segments):", len(ai_segments))
    #print("dbg205: ai_backend:", ai_backend)
    # check is ai_segments is a list or a tuple
    if (not isinstance(ai_segments, (tuple, list))):
        print("ERR337: Error, ai_segments must be a list or a tuple")
        sys.exit(2)
    # check if the outline is a circle or a general outline
    if (isinstance(ai_segments[0], (tuple, list))):  # general outline
        # checks on ai_segments for general outline
        if (len(ai_segments) < 2):
            print(
                "ERR509: Error, the segment list must contain at least 2 elements. Currently, len(ai_segments) = {:d}"
                .format(len(ai_segments)))
            sys.exit(2)
        # convert any format into format-B
        if (len(ai_segments[0]) == 3):  # format-A or format-C
            print(
                "WARN231: warning, format-A or format-C used in outline_arc_line() and must be converted in format-B with ideal_outline()"
            )
            outline_B = cnc_outline.ideal_outline(ai_segments,
                                                  "outline_arc_line")
        else:
            outline_B = ai_segments
        if (len(outline_B[0]) != 2):
            print(
                "ERR403: Error, the first element of the segment list must have 2 elements. Currently, len(outline_B[0]) = {:d}"
                .format(len(outline_B[0])))
            sys.exit(2)
        for i in range(len(outline_B)):
            if ((len(outline_B[i]) != 2) and (len(outline_B[i]) != 4)):
                print(
                    "ERR405: Error, the length of the segment {:d} must be 2 or 4. Currently len(outline_B[i]) = {:d}"
                    .format(i, len(outline_B[i])))
                sys.exit(2)
        # check if the outline is closed
        outline_closed = False
        if ((outline_B[0][0] == outline_B[-1][-2])
                and (outline_B[0][1] == outline_B[-1][-1])):
            #print("dbg207: the outline is closed.")
            outline_closed = True
        # select backend
        if (ai_backend == 'freecad'):
            r_outline = outline_arc_line_with_freecad(outline_B,
                                                      outline_closed)
        elif (ai_backend == 'svgwrite'):
            r_outline = outline_arc_line_with_svgwrite(outline_B,
                                                       outline_closed)
        elif (ai_backend == 'dxfwrite'):
            r_outline = outline_arc_line_with_dxfwrite(outline_B,
                                                       outline_closed)
        elif (ai_backend == 'tkinter'):
            r_outline = outline_arc_line_with_tkinter(outline_B,
                                                      outline_closed)
    else:  # circle outline
        if (len(ai_segments) != 3):
            print(
                "ERR658: Error, circle outline must be a list of 3 floats (or int)! Current len: {:d}"
                .format(len(ai_segments)))
            print("dbg368: ai_segments:", ai_segments)
            sys.exit(2)
        r_outline = outline_circle((ai_segments[0], ai_segments[1]),
                                   ai_segments[2], ai_backend)
    return (r_outline)
Example #6
0
def outline_arc_line(ai_segments, ai_backend):
  """ Generates the arcs and lines outline according to the selected backend
      Possible backend: freecad, mozman dxfwrite, mozman svgwrite, Tkinter.
      ai_segments is a list of segments (ie line or arc)
      If ai_segments is a list/tuple of list/tuple, it's a list of segments (ie line or arc)
      a segment starts from the last point of the previous segment.
      a line is defined by a list of two floats [x-end, y-end]
      an arc is defined by a list of four floats [x-mid, y-mid, x-end, y-end]
      The first element of ai_segments is the starting point, i.e. a list of two floats [x-start, y-start]
      If the last point [x-end, y-end] of the last segment is equal to [x-start, y-start] the outline is closed.
      ai_segments can be made with lists or tuples or a mix of both.
      From a programming point of view, ai_segments is a tuple of 2-tulpes and/or 4-tuples.
      eg: ai_segments = [ [x1,y1], .. [x2,y2], .. [x3,y3,x4,y4], .. ]
      If ai_segments is a list/tuple of three int/float, it's a circle
  """
  r_outline = ''
  #print("dbg204: len(ai_segments):", len(ai_segments))
  #print("dbg205: ai_backend:", ai_backend)
  # check is ai_segments is a list or a tuple
  if(not isinstance(ai_segments, (tuple, list))):
    print("ERR337: Error, ai_segments must be a list or a tuple")
    sys.exit(2)
  # check if the outline is a circle or a general outline
  if(isinstance(ai_segments[0], (tuple, list))): # general outline
    # checks on ai_segments for general outline
    if(len(ai_segments)<2):
      print("ERR509: Error, the segment list must contain at least 2 elements. Currently, len(ai_segments) = {:d}".format(len(ai_segments)))
      sys.exit(2)
    # convert any format into format-B
    if(len(ai_segments[0])==3): # format-A or format-C
      print("WARN231: warning, format-A or format-C used in outline_arc_line() and must be converted in format-B with ideal_outline()")
      outline_B = cnc_outline.ideal_outline(ai_segments, "outline_arc_line")
    else:
      outline_B = ai_segments
    if(len(outline_B[0])!=2):
      print("ERR403: Error, the first element of the segment list must have 2 elements. Currently, len(outline_B[0]) = {:d}".format(len(outline_B[0])))
      sys.exit(2)
    for i in range(len(outline_B)):
      if((len(outline_B[i])!=2)and(len(outline_B[i])!=4)):
        print("ERR405: Error, the length of the segment {:d} must be 2 or 4. Currently len(outline_B[i]) = {:d}".format(i, len(outline_B[i])))
        sys.exit(2)
    # check if the outline is closed
    outline_closed = False
    if((outline_B[0][0]==outline_B[-1][-2])and(outline_B[0][1]==outline_B[-1][-1])):
      #print("dbg207: the outline is closed.")
      outline_closed = True
    # select backend
    if(ai_backend=='freecad'):
      r_outline = outline_arc_line_with_freecad(outline_B, outline_closed)
    elif(ai_backend=='svgwrite'):
      r_outline = outline_arc_line_with_svgwrite(outline_B, outline_closed)
    elif(ai_backend=='dxfwrite'):
      r_outline = outline_arc_line_with_dxfwrite(outline_B, outline_closed)
    elif(ai_backend=='tkinter'):
      r_outline = outline_arc_line_with_tkinter(outline_B, outline_closed)
  else: # circle outline
    if(len(ai_segments)!=3):
      print("ERR658: Error, circle outline must be a list of 3 floats (or int)! Current len: {:d}".format(len(ai_segments)))
      print("dbg368: ai_segments:", ai_segments)
      sys.exit(2)
    r_outline = outline_circle((ai_segments[0], ai_segments[1]), ai_segments[2], ai_backend)
  return(r_outline)
Example #7
0
 def ideal(self):
   """ untouched corner and return a B-format outline list
   """
   r_B_format = cnc_outline.ideal_outline(self.ol, self.outline_id)
   return(r_B_format)