Browse Source

Add a print job name setting to general preferences

CURA-5479
Nino van Hooff 4 years ago
parent
commit
c50f7aa455

+ 1 - 1
cura/CuraApplication.py

@@ -533,7 +533,7 @@ class CuraApplication(QtApplication):
         preferences.addPreference("cura/active_mode", "simple")
 
         preferences.addPreference("cura/categories_expanded", "")
-        preferences.addPreference("cura/jobname_prefix", True)
+        preferences.addPreference("cura/job_name_template", "{machine_name_short}_{project_name}")
         preferences.addPreference("cura/select_models_on_load", False)
         preferences.addPreference("view/center_on_select", False)
         preferences.addPreference("mesh/scale_to_fit", False)

+ 32 - 10
cura/UI/PrintInformation.py

@@ -252,11 +252,12 @@ class PrintInformation(QObject):
         self.materialNamesChanged.emit()
 
     def _onPreferencesChanged(self, preference: str) -> None:
-        if preference != "cura/material_settings":
-            return
+        if preference == "cura/job_name_template":
+            self._updateJobName()
 
-        for build_plate_number in range(self._multi_build_plate_model.maxBuildPlate + 1):
-            self._calculateInformation(build_plate_number)
+        if preference == "cura/material_settings":
+            for build_plate_number in range(self._multi_build_plate_model.maxBuildPlate + 1):
+                self._calculateInformation(build_plate_number)
 
     def _onActiveBuildPlateChanged(self) -> None:
         new_active_build_plate = self._multi_build_plate_model.activeBuildPlate
@@ -305,12 +306,8 @@ class PrintInformation(QObject):
 
         # Only update the job name when it's not user-specified.
         if not self._is_user_specified_job_name:
-            if self._application.getInstance().getPreferences().getValue("cura/jobname_prefix") and not self._pre_sliced:
-                # Don't add abbreviation if it already has the exact same abbreviation.
-                if base_name.startswith(self._abbr_machine + "_"):
-                    self._job_name = base_name
-                else:
-                    self._job_name = self._abbr_machine + "_" + base_name
+            if not self._pre_sliced:
+                self._job_name = self.parseTemplate()
             else:
                 self._job_name = base_name
 
@@ -440,3 +437,28 @@ class PrintInformation(QObject):
         """Listen to scene changes to check if we need to reset the print information"""
 
         self.setToZeroPrintInformation(self._active_build_plate)
+
+    def parseTemplate(self) -> str:
+        """Generate a print job name from the job name template
+
+        The template is a user preference: "cura/job_name_template"
+        """
+        template = self._application.getInstance().getPreferences().getValue("cura/job_name_template")
+        output = template
+
+        output = output.replace("{machine_name_short}", self._abbr_machine)
+
+        if "{machine_name}" in template:
+            global_container_stack = self._application.getGlobalContainerStack()
+            if not global_container_stack:
+                self._abbr_machine = ""
+                return
+            active_machine_type_name = global_container_stack.definition.getName()
+            active_machine_type_name = active_machine_type_name.replace(" ", "_")
+            output = output.replace("{machine_name}", active_machine_type_name)
+
+        if "{project_name}" in template:
+            base_name = self._stripAccents(self._base_name)
+            output = output.replace("{project_name}", base_name)
+
+        return output

+ 19 - 8
resources/qml/Preferences/GeneralPage.qml

@@ -85,8 +85,8 @@ UM.PreferencesPage
         scaleTinyCheckbox.checked = boolCheck(UM.Preferences.getValue("mesh/scale_tiny_meshes"))
         UM.Preferences.resetPreference("cura/select_models_on_load")
         selectModelsOnLoadCheckbox.checked = boolCheck(UM.Preferences.getValue("cura/select_models_on_load"))
-        UM.Preferences.resetPreference("cura/jobname_prefix")
-        prefixJobNameCheckbox.checked = boolCheck(UM.Preferences.getValue("cura/jobname_prefix"))
+        UM.Preferences.resetPreference("cura/job_name_template")
+        jobnameTemplateTextField.text = UM.Preferences.getValue("cura/job_name_template")
         UM.Preferences.resetPreference("view/show_overhang");
         showOverhangCheckbox.checked = boolCheck(UM.Preferences.getValue("view/show_overhang"))
         UM.Preferences.resetPreference("view/show_xray_warning");
@@ -627,14 +627,25 @@ UM.PreferencesPage
             {
                 width: childrenRect.width
                 height: childrenRect.height
-                text: catalog.i18nc("@info:tooltip", "Should a prefix based on the printer name be added to the print job name automatically?")
+                text: catalog.i18nc("@info:tooltip. Note variable names themselves (ie. machine_name_short, project_name) should not be translated", "Variables: machine_name_short, machine_name, project_name")
 
-                CheckBox
+                Column
                 {
-                    id: prefixJobNameCheckbox
-                    text: catalog.i18nc("@option:check", "Add machine prefix to job name")
-                    checked: boolCheck(UM.Preferences.getValue("cura/jobname_prefix"))
-                    onCheckedChanged: UM.Preferences.setValue("cura/jobname_prefix", checked)
+                    spacing: 4 * screenScaleFactor
+
+                    Label
+                    {
+                        id: jobNameTemplateLabel
+                        text: catalog.i18nc("@label","Print job template:")
+                    }
+
+                    TextField
+                    {
+                        id: jobNameTemplateTextField
+                        width: 200 * screenScaleFactor
+                        text: UM.Preferences.getValue("cura/job_name_template")
+                        onTextChanged: UM.Preferences.setValue("cura/job_name_template", text)
+                    }
                 }
             }
 

+ 1 - 1
resources/texts/change_log.txt

@@ -140,7 +140,7 @@ A new performance enhancement that limits re-rendering of the application interf
 Previous versions used different ways of handling HTTP requests. This version uses a unified method, for better performance.
 
 * Job names less sensitive to being touched.
-A contribution from fieldOfview has fixed an issue where the jobname in the bottom-left of the scene is no longer made static by clicking on it. If you load a model and change to another printer, the prefix is now correctly updated.
+A contribution from fieldOfview has fixed an issue where the job name in the bottom-left of the scene is no longer made static by clicking on it. If you load a model and change to another printer, the prefix is now correctly updated.
 
 * Property checks on instance containers.
 A new speed optimization for reading setting values from profiles.