mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 06:55:54 +08:00
commit
fd5a7bb416
@ -6,7 +6,7 @@ import numpy
|
||||
from string import Formatter
|
||||
from enum import IntEnum
|
||||
import time
|
||||
from typing import Any, cast, Dict, List, Optional, Set
|
||||
from typing import Any, cast, Dict, List, Optional, Set, Tuple
|
||||
import re
|
||||
import pyArcus as Arcus # For typing.
|
||||
from PyQt6.QtCore import QCoreApplication
|
||||
@ -68,7 +68,23 @@ class GcodeStartEndFormatter(Formatter):
|
||||
self._default_extruder_nr: int = default_extruder_nr
|
||||
self._additional_per_extruder_settings: Optional[Dict[str, Dict[str, any]]] = additional_per_extruder_settings
|
||||
|
||||
def get_field(self, field_name, args: [str], kwargs: dict) -> Tuple[str, str]:
|
||||
# get_field method parses all fields in the format-string and parses them individually to the get_value method.
|
||||
# e.g. for a string "Hello {foo.bar}" would the complete field "foo.bar" would be passed to get_field, and then
|
||||
# the individual parts "foo" and "bar" would be passed to get_value. This poses a problem for us, because want
|
||||
# to parse the entire field as a single expression. To solve this, we override the get_field method and return
|
||||
# the entire field as the expression.
|
||||
return self.get_value(field_name, args, kwargs), field_name
|
||||
|
||||
def get_value(self, expression: str, args: [str], kwargs: dict) -> str:
|
||||
|
||||
# The following variables are not settings, but only become available after slicing.
|
||||
# when these variables are encountered, we return them as-is. They are replaced later
|
||||
# when the actual values are known.
|
||||
post_slice_data_variables = ["filament_cost", "print_time", "filament_amount", "filament_weight", "jobname"]
|
||||
if expression in post_slice_data_variables:
|
||||
return f"{{{expression}}}"
|
||||
|
||||
extruder_nr = self._default_extruder_nr
|
||||
|
||||
# The settings may specify a specific extruder to use. This is done by
|
||||
@ -102,6 +118,7 @@ class GcodeStartEndFormatter(Formatter):
|
||||
setting_function = SettingFunction(expression)
|
||||
value = setting_function(container_stack, additional_variables=additional_variables)
|
||||
|
||||
|
||||
return value
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user