What does canon do?

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
05 Jun 2024 11:33 #302375 by JT
What does canon do? was created by JT
I see canon passed in several places in code like
lib/python/qt5_graphics.py:392:            result, seq = self.load_preview(filename, canon, unitcode, initcode)

The whole function
    def load(self,filename = None):
        s = self.stat
        s.poll()
        if not filename and s.file:
            filename = s.file
        elif not filename and not s.file:
            return


        lines = open(filename).readlines()
        progress = Progress(2, len(lines))
        # monkey patch function to call ours
        progress.emit_percent = self.emit_percent

        code = []
        i = 0
        for i, l in enumerate(lines):
            l = l.expandtabs().replace("\r", "")
            code.extend(["%6d: " % (i+1), "lineno", l, ""])
            if i % 1000 == 0:
                del code[:]
                progress.update(i)
        if code:
            pass
        progress.nextphase(len(lines))


        td = tempfile.mkdtemp()
        self._current_file = filename
        try:
            random = int(self.inifile.find("EMCIO", "RANDOM_TOOLCHANGER") or 0)
            arcdivision = int(self.inifile.find("DISPLAY", "ARCDIVISION") or 64)
            text = ''
            canon = StatCanon(self.colors,
                                self.get_geometry(),
                                self.foam_option,
                                self.lathe_option,
                                s, text, random, i,
                                progress, arcdivision)
            # monkey patched function to call ours
            canon.output_notify_message = self.output_notify_message
            parameter = self.inifile.find("RS274NGC", "PARAMETER_FILE")
            temp_parameter = os.path.join(td, os.path.basename(parameter or "linuxcnc.var"))
            if parameter:
                shutil.copy(parameter, temp_parameter)
            canon.parameter_file = temp_parameter
            unitcode = "G%d" % (20 + (s.linear_units == 1))
            initcode = self.inifile.find("RS274NGC", "RS274NGC_STARTUP_CODE") or ""
            result, seq = self.load_preview(filename, canon, unitcode, initcode)
            if result > gcode.MIN_ERROR:
                self.report_gcode_error(result, seq, filename)
            self.logger.set_depth(self.from_internal_linear_unit(self.get_foam_z()),
                       self.from_internal_linear_unit(self.get_foam_w()))
            self.calculate_gcode_properties(canon)
        except Exception as e:
            print (e)
            self.gcode_properties = None
        finally:
            shutil.rmtree(td)
            if canon:
                canon.progress = DummyProgress()
            try:
                progress.done()
            except UnboundLocalError:
                pass
        self._redraw()
class StatCanon(glcanon.GLCanon, interpret.StatMixin):
    def __init__(self, colors, geometry, is_foam, lathe_view_option, stat, random, text, linecount, progress, arcdivision):
        glcanon.GLCanon.__init__(self, colors, geometry, is_foam)
        interpret.StatMixin.__init__(self, stat, random)
        self.lathe_view_option = lathe_view_option
        self.text = text
        self.linecount = linecount
        self.progress = progress
        self.aborted = False
        self.arcdivision = arcdivision

    def is_lathe(self): return self.lathe_view_option

    def change_tool(self, pocket):
        glcanon.GLCanon.change_tool(self,pocket)
        interpret.StatMixin.change_tool(self,pocket)

    # not sure if this is used - copied from AXIS code
    def do_cancel(self, event):
        self.aborted = True

    # not sure if this is used - copied from AXIS code
    def check_abort(self):
        #root_window.update()
        if self.aborted: raise KeyboardInterrupt

    def next_line(self, st):
        glcanon.GLCanon.next_line(self, st)
        self.progress.update(self.lineno)
        if self.notify:
            self.output_notify_message(self.notify_message)
            self.notify = 0

    # this is class patched
    # output the text from the magic comment eg: (PREVIEW,notify,The text)
    def output_notify_message(self, message):
        pass

Just trying to understand what's doing what and why.

JT
 

Please Log in or Create an account to join the conversation.

More
06 Jun 2024 12:33 #302464 by Aciera
Replied by Aciera on topic What does canon do?
I think 'canon' here points to the current instance of StatCanon (not sure if that is the correct terminology though).
This is line 322 'lib/python/gremlin.py':
canon = StatCanon(self.colors, self.get_geometry(),self.lathe_option, s, random)

and this is line 80:
class StatCanon(rs274.glcanon.GLCanon, rs274.interpret.StatMixin):
    def __init__(self, colors, geometry, lathe_view_option, stat, random):
        rs274.glcanon.GLCanon.__init__(self, colors, geometry)
        rs274.interpret.StatMixin.__init__(self, stat, random)
        self.progress = DummyProgress()
        self.lathe_view_option = lathe_view_option

    def is_lathe(self): return self.lathe_view_option

    def change_tool(self, pocket):
        rs274.glcanon.GLCanon.change_tool(self,pocket)
        rs274.interpret.StatMixin.change_tool(self,pocket)

 

Please Log in or Create an account to join the conversation.

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
06 Jun 2024 15:40 #302480 by JT
Replied by JT on topic What does canon do?
Yes, I know canon = StatCanon(...) but what does StatCanon do?

JT

Please Log in or Create an account to join the conversation.

More
06 Jun 2024 23:37 #302498 by MennilTossFlykune
canon is used to call Python functions from C++

Please Log in or Create an account to join the conversation.

More
07 Jun 2024 01:31 #302500 by tommylight
Replied by tommylight on topic What does canon do?
I might be off, but GLcanon is part of LinuxCNC, the python part that probably deals with OpenGL, and it is mentioned several times on your code above, and i am sure there is a file named glcanon.py included with LinuxCNC, so maybe having a look there sheds some light ... or turns out to be a deep rabbit hole ! :)

Please Log in or Create an account to join the conversation.

More
07 Jun 2024 11:12 - 07 Jun 2024 11:13 #302528 by Aciera
Replied by Aciera on topic What does canon do?

Yes, I know canon = StatCanon(...) but what does StatCanon do?


Well, I'm certainly not the python expert but if we follow the trail then it seems to initialize these two classes which can be found in /lib/python/rs274/glcanon.py and /lib/python/rs274/interpret.py
rs274.glcanon.GLCanon.__init__(self, colors, geometry)
rs274.interpret.StatMixin.__init__(self, stat, random)
Which are used to set up the preview window depending on the geometry of the config and also (I guess) the tool preview. As for the more intricate details of the code, I'm probably not the right person to answer. 
Last edit: 07 Jun 2024 11:13 by Aciera.

Please Log in or Create an account to join the conversation.

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
07 Jun 2024 11:30 #302529 by JT
Replied by JT on topic What does canon do?
It's a very deep and cornfusing rabbit hole for sure.

It looks to me that all the graphics previews are a copy of what Axis has with some variations.

JT

Please Log in or Create an account to join the conversation.

More
07 Jun 2024 11:43 #302530 by Aciera
Replied by Aciera on topic What does canon do?

It looks to me that all the graphics previews are a copy of what Axis has with some variations.

Yes, with the exeption of 'Probe Basic'.
forum.linuxcnc.org/qtpyvcp/52562-preview...-program-path#300022

Please Log in or Create an account to join the conversation.

More
08 Jun 2024 05:48 #302605 by tommylight
Replied by tommylight on topic What does canon do?
I think Probe Basic uses VTK for preview, from reading here as it was mentioned in regards to RPI not having VTK support, and i recall something was done to make it work.
Me not helping ... :)

Please Log in or Create an account to join the conversation.

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
08 Jun 2024 10:50 #302619 by JT
Replied by JT on topic What does canon do?
I worked for a while on QtPyVCP and the VTK plotter.

JT
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

Time to create page: 0.097 seconds
Powered by Kunena Forum