def _getPropertyValue(self, property_name):
        # Use the evaluation context to skip certain containers
        context = PropertyEvaluationContext(self._stack)
        context.context["evaluate_from_container_index"] = self._store_index

        property_value = self._stack.getProperty(self._key,
                                                 property_name,
                                                 context=context)
        if isinstance(property_value, SettingFunction):
            property_value = property_value(self._stack)

        if property_name == "value":
            setting_type = self._stack.getProperty(self._key, "type")
            if setting_type is not None:
                property_value = SettingDefinition.settingValueToString(
                    setting_type, property_value)
            else:
                property_value = ""
        elif property_name == "validationState":
            # Setting is not validated. This can happen if there is only a setting definition.
            # We do need to validate it, because a setting defintions value can be set by a function, which could
            # be an invalid setting.
            if property_value is None:
                if not self._validator:
                    definition = self._stack.getSettingDefinition(self._key)
                    if definition:
                        validator_type = SettingDefinition.getValidatorForType(
                            definition.type)
                        if validator_type:
                            self._validator = validator_type(self._key)
                if self._validator:
                    property_value = self._validator(self._stack)
        return str(property_value)
Example #2
0
    def hasErrors(self) -> bool:
        """Check if the container stack has errors"""

        for key in self.getAllKeys():
            enabled = self.getProperty(key, "enabled")
            if not enabled:
                continue
            validation_state = self.getProperty(key, "validationState")
            if validation_state is None:
                # Setting is not validated. This can happen if there is only a setting definition.
                # We do need to validate it, because a setting defintions value can be set by a function, which could
                # be an invalid setting.
                definition = cast(SettingDefinition,
                                  self.getSettingDefinition(key))
                validator_type = SettingDefinition.getValidatorForType(
                    definition.type)
                if validator_type:
                    validator = validator_type(key)
                    validation_state = validator(self)
            if validation_state in (ValidatorState.Exception,
                                    ValidatorState.MaximumError,
                                    ValidatorState.MinimumError,
                                    ValidatorState.Invalid):
                return True
        return False
Example #3
0
    def _checkStackForErrors(self, stack: ContainerStack) -> bool:

        top_of_stack = cast(InstanceContainer, stack.getTop())  # Cache for efficiency.
        changed_setting_keys = top_of_stack.getAllKeys()

        # Add all relations to changed settings as well.
        for key in top_of_stack.getAllKeys():
            instance = top_of_stack.getInstance(key)
            if instance is None:
                continue
            self._addRelations(changed_setting_keys, instance.definition.relations)
            Job.yieldThread()

        for changed_setting_key in changed_setting_keys:
            validation_state = stack.getProperty(changed_setting_key, "validationState")

            if validation_state is None:
                definition = cast(SettingDefinition, stack.getSettingDefinition(changed_setting_key))
                validator_type = SettingDefinition.getValidatorForType(definition.type)
                if validator_type:
                    validator = validator_type(changed_setting_key)
                    validation_state = validator(stack)
            if validation_state in (
            ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError, ValidatorState.Invalid):
                Logger.log("w", "Setting %s is not valid, but %s. Aborting slicing.", changed_setting_key, validation_state)
                return True
            Job.yieldThread()

        return False
    def _getPropertyValue(self, property_name):
        # Use the evaluation context to skip certain containers
        context = PropertyEvaluationContext(self._stack)
        context.context["evaluate_from_container_index"] = self._store_index

        property_value = self._stack.getProperty(self._key, property_name, context = context)
        if isinstance(property_value, SettingFunction):
            property_value = property_value(self._stack)

        if property_name == "value":
            setting_type = self._stack.getProperty(self._key, "type")
            if setting_type is not None:
                property_value = SettingDefinition.settingValueToString(setting_type, property_value)
            else:
                property_value = ""
        elif property_name == "validationState":
            # Setting is not validated. This can happen if there is only a setting definition.
            # We do need to validate it, because a setting defintions value can be set by a function, which could
            # be an invalid setting.
            if property_value is None:
                if not self._validator:
                    definition = self._stack.getSettingDefinition(self._key)
                    if definition:
                        validator_type = SettingDefinition.getValidatorForType(definition.type)
                        if validator_type:
                            self._validator = validator_type(self._key)
                if self._validator:
                    property_value = self._validator(self._stack)
        return str(property_value)
    def _getPropertyValue(self, property_name):
        property_value = self._stack.getProperty(self._key, property_name)
        if isinstance(property_value, SettingFunction):
            property_value = property_value(self._stack)

        if property_name == "value":
            setting_type = self._stack.getProperty(self._key, "type")
            if setting_type is not None:
                property_value = SettingDefinition.settingValueToString(
                    setting_type, property_value)
            else:
                property_value = ""
        elif property_name == "validationState":
            # Setting is not validated. This can happen if there is only a setting definition.
            # We do need to validate it, because a setting defintions value can be set by a function, which could
            # be an invalid setting.
            if property_value is None:
                if not self._validator:
                    definition = self._stack.getSettingDefinition(self._key)
                    validator_type = SettingDefinition.getValidatorForType(
                        definition.type)
                    if validator_type:
                        self._validator = validator_type(self._key)
                if self._validator:
                    property_value = self._validator(self._stack)
        return str(property_value)
Example #6
0
    def _checkStack(self) -> None:
        if self._need_to_check:
            Logger.log(
                "d",
                "Need to check for errors again. Discard the current progress and reschedule a check."
            )
            self._check_in_progress = False
            self._application.callLater(self.startErrorCheck)
            return

        self._check_in_progress = True

        # If there is nothing to check any more, it means there is no error.
        if not self._stacks_and_keys_to_check:
            # Finish
            self._setResult(False)
            return

        # Get the next stack and key to check
        stack, key = self._stacks_and_keys_to_check.popleft()

        enabled = stack.getProperty(key, "enabled")
        if not enabled:
            self._application.callLater(self._checkStack)
            return

        validation_state = stack.getProperty(key, "validationState")
        if validation_state is None:
            # Setting is not validated. This can happen if there is only a setting definition.
            # We do need to validate it, because a setting definitions value can be set by a function, which could
            # be an invalid setting.
            definition = stack.getSettingDefinition(key)
            validator_type = SettingDefinition.getValidatorForType(
                definition.type)
            if validator_type:
                validator = validator_type(key)
                validation_state = validator(stack)
        if validation_state in (ValidatorState.Exception,
                                ValidatorState.MaximumError,
                                ValidatorState.MinimumError,
                                ValidatorState.Invalid):
            # Since we don't know if any of the settings we didn't check is has an error value, store the list for the
            # next check.
            keys_to_recheck = {
                setting_key
                for stack, setting_key in self._stacks_and_keys_to_check
            }
            keys_to_recheck.add(key)
            self._setResult(True, keys_to_recheck=keys_to_recheck)
            return

        # Schedule the check for the next key
        self._application.callLater(self._checkStack)
Example #7
0
    def _checkStack(self) -> None:
        if self._need_to_check:
            Logger.log(
                "d",
                "Need to check for errors again. Discard the current progress and reschedule a check."
            )
            self._check_in_progress = False
            self._application.callLater(self.startErrorCheck)
            return

        self._check_in_progress = True

        # If there is nothing to check any more, it means there is no error.
        if not self._stacks_and_keys_to_check:
            Logger.log("d", "THAT IS CALLED2!!!!!!!!!!!!!!!!!!!")
            # Finish
            self._setResult(False)
            return

        # Get the next stack and key to check
        stack, key = self._stacks_and_keys_to_check.popleft()

        enabled = stack.getProperty(key, "enabled")
        if not enabled:
            self._application.callLater(self._checkStack)
            return
        #Logger.log("d","KEYTO VALIDATE:"+key)
        validation_state = stack.getProperty(key, "validationState")

        if validation_state is None:
            # Setting is not validated. This can happen if there is only a setting definition.
            # We do need to validate it, because a setting definitions value can be set by a function, which could
            # be an invalid setting.
            definition = stack.getSettingDefinition(key)
            validator_type = SettingDefinition.getValidatorForType(
                definition.type)
            if validator_type:
                validator = validator_type(key)
                validation_state = validator(stack)
        #Logger.log("d","VALIDATION:"+str(validation_state))
        if validation_state in (ValidatorState.Exception,
                                ValidatorState.MaximumError,
                                ValidatorState.MinimumError
                                ) and key != "max_feedrate_z_override":
            #Logger.log("d","THAT IS CALLED!!!!!!!!!!!!!!!!!!!")
            # Finish
            self._setResult(True)
            return
        # Schedule the check for the next key
        self._application.callLater(self._checkStack)
Example #8
0
 def getErrorKeys(self) -> List[str]:
     error_keys = []
     for key in self.getAllKeys():
         validation_state = self.getProperty(key, "validationState")
         if validation_state is None:
             # Setting is not validated. This can happen if there is only a setting definition.
             # We do need to validate it, because a setting defintions value can be set by a function, which could
             # be an invalid setting.
             definition = cast(SettingDefinition, self.getSettingDefinition(key))
             validator_type = SettingDefinition.getValidatorForType(definition.type)
             if validator_type:
                 validator = validator_type(key)
                 validation_state = validator(self)
         if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
             error_keys.append(key)
     return error_keys
Example #9
0
 def getErrorKeys(self) -> List[str]:
     error_keys = []
     for key in self.getAllKeys():
         validation_state = self.getProperty(key, "validationState")
         if validation_state is None:
             # Setting is not validated. This can happen if there is only a setting definition.
             # We do need to validate it, because a setting defintions value can be set by a function, which could
             # be an invalid setting.
             definition = cast(SettingDefinition, self.getSettingDefinition(key))
             validator_type = SettingDefinition.getValidatorForType(definition.type)
             if validator_type:
                 validator = validator_type(key)
                 validation_state = validator(self)
         if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
             error_keys.append(key)
     return error_keys
Example #10
0
 def hasErrors(self) -> bool:
     for key in self.getAllKeys():
         enabled = self.getProperty(key, "enabled")
         if not enabled:
             continue
         validation_state = self.getProperty(key, "validationState")
         if validation_state is None:
             # Setting is not validated. This can happen if there is only a setting definition.
             # We do need to validate it, because a setting defintions value can be set by a function, which could
             # be an invalid setting.
             definition = cast(SettingDefinition, self.getSettingDefinition(key))
             validator_type = SettingDefinition.getValidatorForType(definition.type)
             if validator_type:
                 validator = validator_type(key)
                 validation_state = validator(self)
         if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
             return True
     return False
Example #11
0
    def _checkStack(self):
        if self._need_to_check:
            Logger.log("d", "Need to check for errors again. Discard the current progress and reschedule a check.")
            self._check_in_progress = False
            self._application.callLater(self.startErrorCheck)
            return

        self._check_in_progress = True

        # If there is nothing to check any more, it means there is no error.
        if not self._stacks_and_keys_to_check:
            # Finish
            self._setResult(False)
            return

        # Get the next stack and key to check
        stack, key = self._stacks_and_keys_to_check.popleft()

        enabled = stack.getProperty(key, "enabled")
        if not enabled:
            self._application.callLater(self._checkStack)
            return

        validation_state = stack.getProperty(key, "validationState")
        if validation_state is None:
            # Setting is not validated. This can happen if there is only a setting definition.
            # We do need to validate it, because a setting definitions value can be set by a function, which could
            # be an invalid setting.
            definition = stack.getSettingDefinition(key)
            validator_type = SettingDefinition.getValidatorForType(definition.type)
            if validator_type:
                validator = validator_type(key)
                validation_state = validator(stack)
        if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
            # Finish
            self._setResult(True)
            return

        # Schedule the check for the next key
        self._application.callLater(self._checkStack)