Przeglądaj źródła

- made the Custom ToolChange Text area in CNCJob Selected Tab depend on the status of the ToolChange Enable Checkbox even in the init stage.
- added some parameters throughout camlib gcode generation functions; handled some possible errors (e.g like when attempting to use an empty Custom GCode Toolchange)

Marius Stanciu 7 lat temu
rodzic
commit
fb6edfc394
4 zmienionych plików z 59 dodań i 8 usunięć
  1. 33 1
      FlatCAMObj.py
  2. 12 6
      ObjectUI.py
  3. 7 0
      README.md
  4. 7 1
      camlib.py

+ 33 - 1
FlatCAMObj.py

@@ -5108,6 +5108,10 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         assert isinstance(self.ui, CNCObjectUI), \
         assert isinstance(self.ui, CNCObjectUI), \
             "Expected a CNCObjectUI, got %s" % type(self.ui)
             "Expected a CNCObjectUI, got %s" % type(self.ui)
 
 
+        # this signal has to be connected to it's slot before the defaults are populated
+        # the decision done in the slot has to override the default value set bellow
+        self.ui.toolchange_cb.toggled.connect(self.on_toolchange_custom_clicked)
+
         self.form_fields.update({
         self.form_fields.update({
             "plot": self.ui.plot_cb,
             "plot": self.ui.plot_cb,
             # "tooldia": self.ui.tooldia_entry,
             # "tooldia": self.ui.tooldia_entry,
@@ -5155,7 +5159,6 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
             self.ui.cnc_tools_table.cellWidget(row, 6).clicked.connect(self.on_plot_cb_click_table)
             self.ui.cnc_tools_table.cellWidget(row, 6).clicked.connect(self.on_plot_cb_click_table)
         self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
         self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
 
 
-
     def ui_disconnect(self):
     def ui_disconnect(self):
         for row in range(self.ui.cnc_tools_table.rowCount()):
         for row in range(self.ui.cnc_tools_table.rowCount()):
             self.ui.cnc_tools_table.cellWidget(row, 6).clicked.disconnect(self.on_plot_cb_click_table)
             self.ui.cnc_tools_table.cellWidget(row, 6).clicked.disconnect(self.on_plot_cb_click_table)
@@ -5415,7 +5418,13 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
             # match = self.re_toolchange.search(g)
             # match = self.re_toolchange.search(g)
             if 'M6' in g:
             if 'M6' in g:
                 m6_code = self.parse_custom_toolchange_code(self.ui.toolchange_text.get_value())
                 m6_code = self.parse_custom_toolchange_code(self.ui.toolchange_text.get_value())
+                if m6_code is None or m6_code == '':
+                    self.app.inform.emit("[ERROR_NOTCL] Cancelled. The Toolchange Custom code is enabled "
+                                         "but it's empty.")
+                    return 'fail'
+
                 g = g.replace('M6', m6_code)
                 g = g.replace('M6', m6_code)
+                self.app.inform.emit("[success] Toolchange G-code was replaced by a custom code.")
 
 
         # lines = StringIO(self.gcode)
         # lines = StringIO(self.gcode)
         lines = StringIO(g)
         lines = StringIO(g)
@@ -5439,6 +5448,29 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         else:
         else:
             return lines
             return lines
 
 
+    def on_toolchange_custom_clicked(self, signal):
+        try:
+            if 'toolchange_custom' not in str(self.options['ppname_e']).lower():
+                print(self.options['ppname_e'])
+                if self.ui.toolchange_cb.get_value():
+                    self.ui.toolchange_cb.set_value(False)
+                    self.app.inform.emit(
+                        "[WARNING_NOTCL] The used postprocessor file has to have in it's name: 'toolchange_custom'")
+        except KeyError:
+            try:
+                for key in self.cnc_tools:
+                    ppg = self.cnc_tools[key]['data']['ppname_g']
+                    if 'toolchange_custom' not in str(ppg).lower():
+                        print(ppg)
+                        if self.ui.toolchange_cb.get_value():
+                            self.ui.toolchange_cb.set_value(False)
+                            self.app.inform.emit(
+                                "[WARNING_NOTCL] The used postprocessor file has to have in it's name: "
+                                "'toolchange_custom'")
+            except KeyError:
+                self.app.inform.emit(
+                    "[ERROR] There is no postprocessor file.")
+
     def get_gcode(self, preamble='', postamble=''):
     def get_gcode(self, preamble='', postamble=''):
         #we need this to be able get_gcode separatelly for shell command export_gcode
         #we need this to be able get_gcode separatelly for shell command export_gcode
         return preamble + '\n' + self.gcode + "\n" + postamble
         return preamble + '\n' + self.gcode + "\n" + postamble

+ 12 - 6
ObjectUI.py

@@ -1453,15 +1453,19 @@ class CNCObjectUI(ObjectUI):
         self.cnc_box.setContentsMargins(0, 0, 0, 0)
         self.cnc_box.setContentsMargins(0, 0, 0, 0)
         self.cnc_frame.setLayout(self.cnc_box)
         self.cnc_frame.setLayout(self.cnc_box)
 
 
-        # Prepend to G-Code
-        toolchangelabel = QtWidgets.QLabel('Toolchange G-Code:')
-        toolchangelabel.setToolTip(
+        # Toolchange Custom G-Code
+        self.toolchangelabel = QtWidgets.QLabel('Toolchange G-Code:')
+        self.toolchangelabel.setToolTip(
             "Type here any G-Code commands you would\n"
             "Type here any G-Code commands you would\n"
             "like to be executed when Toolchange event is encountered.\n"
             "like to be executed when Toolchange event is encountered.\n"
             "This will constitute a Custom Toolchange GCode,\n"
             "This will constitute a Custom Toolchange GCode,\n"
-            "or a Toolchange Macro."
+            "or a Toolchange Macro.\n"
+            "The FlatCAM variables are surrounded by '%' symbol.\n\n"
+            "WARNING: it can be used only with a postprocessor file\n"
+            "that has 'toolchange_custom' in it's name and this is built\n"
+            "having as template the 'Toolchange Custom' posprocessor file."
         )
         )
-        self.cnc_box.addWidget(toolchangelabel)
+        self.cnc_box.addWidget(self.toolchangelabel)
 
 
         self.toolchange_text = FCTextArea()
         self.toolchange_text = FCTextArea()
         self.cnc_box.addWidget(self.toolchange_text)
         self.cnc_box.addWidget(self.toolchange_text)
@@ -1469,13 +1473,15 @@ class CNCObjectUI(ObjectUI):
         cnclay = QtWidgets.QHBoxLayout()
         cnclay = QtWidgets.QHBoxLayout()
         self.cnc_box.addLayout(cnclay)
         self.cnc_box.addLayout(cnclay)
 
 
-        # Toolchange Replacement GCode
+        # Toolchange Replacement Enable
         self.toolchange_cb = FCCheckBox(label='Use Toolchange Macro')
         self.toolchange_cb = FCCheckBox(label='Use Toolchange Macro')
         self.toolchange_cb.setToolTip(
         self.toolchange_cb.setToolTip(
             "Check this box if you want to use\n"
             "Check this box if you want to use\n"
             "a Custom Toolchange GCode (macro)."
             "a Custom Toolchange GCode (macro)."
         )
         )
         cnclay.addWidget(self.toolchange_cb)
         cnclay.addWidget(self.toolchange_cb)
+
+        self.toolch_ois = OptionalInputSection(self.toolchange_cb, [self.toolchangelabel, self.toolchange_text])
         cnclay.addStretch()
         cnclay.addStretch()
 
 
         cnclay1 = QtWidgets.QHBoxLayout()
         cnclay1 = QtWidgets.QHBoxLayout()

+ 7 - 0
README.md

@@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing.
 
 
 =================================================
 =================================================
 
 
+27.02.2019
+
+- made the Custom ToolChange Text area in CNCJob Selected Tab depend on the status of the ToolChange Enable Checkbox even in the init stage.
+- added some parameters throughout camlib gcode generation functions; handled some possible errors (e.g like when attempting to use an empty Custom GCode Toolchange)
+
 26.02.2019
 26.02.2019
 
 
 - added a function to read the parameters from ToolChange macro Text Box (I need to move it from CNCJob to Excellon and Geometry)
 - added a function to read the parameters from ToolChange macro Text Box (I need to move it from CNCJob to Excellon and Geometry)
@@ -20,6 +25,8 @@ CAD program, and create G-Code for Isolation routing.
 - because adding shapes to the shapes collection (when doing Mark or Mark All) is time consuming I made the plot_apertures() threaded.
 - because adding shapes to the shapes collection (when doing Mark or Mark All) is time consuming I made the plot_apertures() threaded.
 - made the polygon fusing in modified Gerber creation, a list comprehension in an attempt for optimization
 - made the polygon fusing in modified Gerber creation, a list comprehension in an attempt for optimization
 - when right clicking the files in Project tab, the Save option for Excellon no longer export it but really save the original. 
 - when right clicking the files in Project tab, the Save option for Excellon no longer export it but really save the original. 
+- in ToolChange Custom Code replacement, the Text Box in the CNCJob Selected tab will be active only if there is a 'toolchange_custom' in the name of the postprocessor file. This assume that it is, or was created having as template the Toolchange Custom postprocessor file.
+
 
 
 25.02.2019
 25.02.2019
 
 

+ 7 - 1
camlib.py

@@ -4906,7 +4906,8 @@ class CNCjob(Geometry):
                 if exobj.drills:
                 if exobj.drills:
                     for tool in tools:
                     for tool in tools:
                         self.tool=tool
                         self.tool=tool
-                        self.postdata['toolC']=exobj.tools[tool]["C"]
+                        self.postdata['toolC'] = exobj.tools[tool]["C"]
+                        self.tooldia = exobj.tools[tool]["C"]
 
 
                         ################################################
                         ################################################
                         # Create the data.
                         # Create the data.
@@ -5004,6 +5005,7 @@ class CNCjob(Geometry):
                     for tool in tools:
                     for tool in tools:
                         self.tool=tool
                         self.tool=tool
                         self.postdata['toolC']=exobj.tools[tool]["C"]
                         self.postdata['toolC']=exobj.tools[tool]["C"]
+                        self.tooldia = exobj.tools[tool]["C"]
 
 
                         ################################################
                         ################################################
                         node_list = []
                         node_list = []
@@ -5096,6 +5098,7 @@ class CNCjob(Geometry):
                 if exobj.drills:
                 if exobj.drills:
                     self.tool = tool
                     self.tool = tool
                     self.postdata['toolC'] = exobj.tools[tool]["C"]
                     self.postdata['toolC'] = exobj.tools[tool]["C"]
+                    self.tooldia = exobj.tools[tool]["C"]
 
 
                     # Only if tool has points.
                     # Only if tool has points.
                     if tool in points:
                     if tool in points:
@@ -5212,6 +5215,9 @@ class CNCjob(Geometry):
 
 
         self.toolchangez = float(toolchangez) if toolchangez else None
         self.toolchangez = float(toolchangez) if toolchangez else None
 
 
+        # it servers in the postprocessor file
+        self.tool = tool_no
+
         try:
         try:
             if toolchangexy == '':
             if toolchangexy == '':
                 self.toolchange_xy = None
                 self.toolchange_xy = None