Esempio n. 1
0
    def _updateTimeQualitySettings(self):
        if not self._current_settings or not self._enabled:
            return

        if not self._low_quality_settings:
            self._low_quality_settings = MachineSettings()
            self._low_quality_settings.loadSettingsFromFile(Resources.getPath(Resources.SettingsLocation, self._current_settings.getTypeID() + ".json"))
            self._low_quality_settings.loadValuesFromFile(Resources.getPath(Resources.SettingsLocation, "profiles", "low_quality.conf"))

        if not self._high_quality_settings:
            self._high_quality_settings = MachineSettings()
            self._high_quality_settings.loadSettingsFromFile(Resources.getPath(Resources.SettingsLocation, self._current_settings.getTypeID() + ".json"))
            self._high_quality_settings.loadValuesFromFile(Resources.getPath(Resources.SettingsLocation, "profiles", "high_quality.conf"))

        for key, options in self._interpolation_settings.items():
            minimum_value = None
            if options["minimum"] == "low":
                minimum_value = self._low_quality_settings.getSettingValueByKey(key)
            elif options["minimum"] == "high":
                minimum_value = self._high_quality_settings.getSettingValueByKey(key)
            else:
                continue

            maximum_value = None
            if options["maximum"] == "low":
                maximum_value = self._low_quality_settings.getSettingValueByKey(key)
            elif options["maximum"] == "high":
                maximum_value = self._high_quality_settings.getSettingValueByKey(key)
            else:
                continue

            setting_value = round(minimum_value + (maximum_value - minimum_value) * (self._time_quality_value / 100), options["precision"])
            self._current_settings.setSettingValueByKey(key, setting_value)
Esempio n. 2
0
 def loadMachines(self):
     settings_directory = Resources.getStorageLocation(Resources.SettingsLocation)
     for entry in os.listdir(settings_directory):
         settings = MachineSettings()
         settings.loadValuesFromFile(os.path.join(settings_directory, entry))
         self._machines.append(settings)
     self._machines.sort(key = lambda k: k.getName())
Esempio n. 3
0
 def setUp(self):
     # Called before the first testfunction is executed
     self._setting = Setting("TestSetting", 10, "int")
     self._machine_settings = MachineSettings()
     category = SettingsCategory("TestCategory")
     #category.addSetting(self._setting)
     self._machine_settings.addSettingsCategory(category)
     self._machine_settings.loadSettingsFromFile(
         "tests/Settings/SettingData.json")
    def createMachine(self, index, name):
        file = self.getItem(index)["file"]

        machine = MachineSettings()
        machine.loadSettingsFromFile(Resources.getPath(Resources.SettingsLocation, file))
        machine.setName(name)

        app = Application.getInstance()
        index = app.addMachine(machine)
        app.setActiveMachine(app.getMachines()[index])
Esempio n. 5
0
    def _updateTimeQualitySettings(self):
        if not self._current_settings or not self._enabled:
            return

        if not self._low_quality_settings:
            self._low_quality_settings = MachineSettings()
            self._low_quality_settings.loadSettingsFromFile(
                Resources.getPath(Resources.SettingsLocation,
                                  self._current_settings.getTypeID() +
                                  ".json"))
            self._low_quality_settings.loadValuesFromFile(
                Resources.getPath(Resources.SettingsLocation, "profiles",
                                  "low_quality.conf"))

        if not self._high_quality_settings:
            self._high_quality_settings = MachineSettings()
            self._high_quality_settings.loadSettingsFromFile(
                Resources.getPath(Resources.SettingsLocation,
                                  self._current_settings.getTypeID() +
                                  ".json"))
            self._high_quality_settings.loadValuesFromFile(
                Resources.getPath(Resources.SettingsLocation, "profiles",
                                  "high_quality.conf"))

        for key, options in self._interpolation_settings.items():
            minimum_value = None
            if options["minimum"] == "low":
                minimum_value = self._low_quality_settings.getSettingValueByKey(
                    key)
            elif options["minimum"] == "high":
                minimum_value = self._high_quality_settings.getSettingValueByKey(
                    key)
            else:
                continue

            maximum_value = None
            if options["maximum"] == "low":
                maximum_value = self._low_quality_settings.getSettingValueByKey(
                    key)
            elif options["maximum"] == "high":
                maximum_value = self._high_quality_settings.getSettingValueByKey(
                    key)
            else:
                continue

            setting_value = round(
                minimum_value + (maximum_value - minimum_value) *
                (self._time_quality_value / 100), options["precision"])
            self._current_settings.setSettingValueByKey(key, setting_value)
Esempio n. 6
0
 def setUp(self):
     # Called before the first testfunction is executed
     self._setting = Setting("TestSetting",10,"int")
     self._machine_settings = MachineSettings()
     category = SettingsCategory("TestCategory")
     #category.addSetting(self._setting)
     self._machine_settings.addSettingsCategory(category)
     self._machine_settings.loadSettingsFromFile("tests/Settings/SettingData.json")
Esempio n. 7
0
class SettingTest(unittest.TestCase):
    def setUp(self):
        # Called before the first testfunction is executed
        self._setting = Setting("TestSetting", 10, "int")
        self._machine_settings = MachineSettings()
        category = SettingsCategory("TestCategory")
        #category.addSetting(self._setting)
        self._machine_settings.addSettingsCategory(category)
        self._machine_settings.loadSettingsFromFile(
            "tests/Settings/SettingData.json")

    def tearDown(self):
        # Called after the last testfunction was executed
        pass

    def test_getSettingByKey(self):
        self.assertEqual(
            self._machine_settings.getSettingByKey("TestSetting").getType(),
            self._setting.getType())
        self.assertEqual(
            self._machine_settings.getSettingByKey(
                "TestSetting").getDefaultValue(),
            self._setting.getDefaultValue())
        pass

    def test_category(self):
        pass

    def test_validatorTest(self):
        pass
Esempio n. 8
0
    def createMachine(self, index, name):
        file = self.getItem(index)["file"]

        machine = MachineSettings()
        machine.loadSettingsFromFile(
            Resources.getPath(Resources.Settings, file))
        machine.setName(name)

        app = Application.getInstance()
        index = app.addMachine(machine)
        app.setActiveMachine(app.getMachines()[index])
Esempio n. 9
0
class SettingTest(unittest.TestCase):
    def setUp(self):
        # Called before the first testfunction is executed
        self._setting = Setting("TestSetting",10,"int")
        self._machine_settings = MachineSettings()
        category = SettingsCategory("TestCategory")
        #category.addSetting(self._setting)
        self._machine_settings.addSettingsCategory(category)
        self._machine_settings.loadSettingsFromFile("tests/Settings/SettingData.json")

    def tearDown(self):
        # Called after the last testfunction was executed
        pass

    def test_getSettingByKey(self):
        self.assertEqual(self._machine_settings.getSettingByKey("TestSetting").getType(), self._setting.getType())
        self.assertEqual(self._machine_settings.getSettingByKey("TestSetting").getDefaultValue(), self._setting.getDefaultValue())
        pass

    def test_category(self):
        pass

    def test_validatorTest(self):
        pass
Esempio n. 10
0
class PrintInformation(QObject):
    class SlicePass:
        CurrentSettings = 1
        LowQualitySettings = 2
        HighQualitySettings = 3

    class SliceReason:
        SceneChanged = 1
        SettingChanged = 2
        ActiveMachineChanged = 3
        Other = 4

    def __init__(self, parent = None):
        super().__init__(parent)

        self._enabled = False

        self._minimum_print_time = Duration(None, self)
        self._current_print_time = Duration(None, self)
        self._maximum_print_time = Duration(None, self)

        self._material_amount = -1

        self._time_quality_value = 50
        self._time_quality_changed_timer = QTimer()
        self._time_quality_changed_timer.setInterval(500)
        self._time_quality_changed_timer.setSingleShot(True)
        self._time_quality_changed_timer.timeout.connect(self._updateTimeQualitySettings)

        self._interpolation_settings = {
            "layer_height": { "minimum": "low", "maximum": "high", "curve": "linear", "precision": 2 },
            "fill_sparse_density": { "minimum": "low", "maximum": "high", "curve": "linear", "precision": 0 }
        }

        self._low_quality_settings = None
        self._current_settings = None
        self._high_quality_settings = None

        self._slice_pass = None
        self._slice_reason = None

        Application.getInstance().activeMachineChanged.connect(self._onActiveMachineChanged)
        self._onActiveMachineChanged()

        Application.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged)

        self._backend = Application.getInstance().getBackend()
        if self._backend:
            self._backend.printDurationMessage.connect(self._onPrintDurationMessage)
            self._backend.slicingStarted.connect(self._onSlicingStarted)
            self._backend.slicingCancelled.connect(self._onSlicingCancelled)

    minimumPrintTimeChanged = pyqtSignal()
    
    @pyqtProperty(Duration, notify = minimumPrintTimeChanged)
    def minimumPrintTime(self):
        return self._minimum_print_time

    currentPrintTimeChanged = pyqtSignal()
    
    @pyqtProperty(Duration, notify = currentPrintTimeChanged)
    def currentPrintTime(self):
        return self._current_print_time

    maximumPrintTimeChanged = pyqtSignal()
    
    @pyqtProperty(Duration, notify = maximumPrintTimeChanged)
    def maximumPrintTime(self):
        return self._maximum_print_time

    materialAmountChanged = pyqtSignal()
    
    @pyqtProperty(float, notify = materialAmountChanged)
    def materialAmount(self):
        return self._material_amount

    timeQualityValueChanged = pyqtSignal()
    
    @pyqtProperty(int, notify = timeQualityValueChanged)
    def timeQualityValue(self):
        return self._time_quality_value

    def setEnabled(self, enabled):
        if enabled != self._enabled:
            self._enabled = enabled

            if self._enabled:
                self._updateTimeQualitySettings()
                self._onSlicingStarted()

            self.enabledChanged.emit()

    enabledChanged = pyqtSignal()
    @pyqtProperty(bool, fset = setEnabled, notify = enabledChanged)
    def enabled(self):
        return self._enabled

    @pyqtSlot(int)
    def setTimeQualityValue(self, value):
        if value != self._time_quality_value:
            self._time_quality_value = value
            self.timeQualityValueChanged.emit()

            self._time_quality_changed_timer.start()

    def _onSlicingStarted(self):
        if self._slice_pass is None:
            self._slice_pass = self.SlicePass.CurrentSettings

        if self._slice_reason is None:
            self._slice_reason = self.SliceReason.Other

        if self._slice_pass == self.SlicePass.CurrentSettings and self._slice_reason != self.SliceReason.SettingChanged:
            self._minimum_print_time.setDuration(-1)
            self.minimumPrintTimeChanged.emit()
            self._maximum_print_time.setDuration(-1)
            self.maximumPrintTimeChanged.emit()

    def _onPrintDurationMessage(self, time, amount):
        if self._slice_pass == self.SlicePass.CurrentSettings:
            self._current_print_time.setDuration(time)
            self.currentPrintTimeChanged.emit()

            self._material_amount = round(amount / 10) / 100
            self.materialAmountChanged.emit()

            if not self._enabled:
                return

            if self._slice_reason != self.SliceReason.SettingChanged or not self._minimum_print_time.valid or not self._maximum_print_time.valid:
                self._slice_pass = self.SlicePass.LowQualitySettings
                self._backend.slice(settings = self._low_quality_settings, save_gcode = False, save_polygons = False, force_restart = False, report_progress = False)
            else:
                self._slice_pass = None
                self._slice_reason = None
        elif self._slice_pass == self.SlicePass.LowQualitySettings:
            self._minimum_print_time.setDuration(time)
            self.minimumPrintTimeChanged.emit()

            self._slice_pass = self.SlicePass.HighQualitySettings
            self._backend.slice(settings = self._high_quality_settings, save_gcode = False, save_polygons = False, force_restart = False, report_progress = False)
        elif self._slice_pass == self.SlicePass.HighQualitySettings:
            self._maximum_print_time.setDuration(time)
            self.maximumPrintTimeChanged.emit()

            self._slice_pass = None
            self._slice_reason = None

    def _onActiveMachineChanged(self):
        if self._current_settings:
            self._current_settings.settingChanged.disconnect(self._onSettingChanged)

        self._current_settings = Application.getInstance().getActiveMachine()

        if self._current_settings:
            self._current_settings.settingChanged.connect(self._onSettingChanged)
            self._low_quality_settings = None
            self._high_quality_settings = None
            self._updateTimeQualitySettings()

            self._slice_reason = self.SliceReason.ActiveMachineChanged

    def _updateTimeQualitySettings(self):
        if not self._current_settings or not self._enabled:
            return

        if not self._low_quality_settings:
            self._low_quality_settings = MachineSettings()
            self._low_quality_settings.loadSettingsFromFile(Resources.getPath(Resources.SettingsLocation, self._current_settings.getTypeID() + ".json"))
            self._low_quality_settings.loadValuesFromFile(Resources.getPath(Resources.SettingsLocation, "profiles", "low_quality.conf"))

        if not self._high_quality_settings:
            self._high_quality_settings = MachineSettings()
            self._high_quality_settings.loadSettingsFromFile(Resources.getPath(Resources.SettingsLocation, self._current_settings.getTypeID() + ".json"))
            self._high_quality_settings.loadValuesFromFile(Resources.getPath(Resources.SettingsLocation, "profiles", "high_quality.conf"))

        for key, options in self._interpolation_settings.items():
            minimum_value = None
            if options["minimum"] == "low":
                minimum_value = self._low_quality_settings.getSettingValueByKey(key)
            elif options["minimum"] == "high":
                minimum_value = self._high_quality_settings.getSettingValueByKey(key)
            else:
                continue

            maximum_value = None
            if options["maximum"] == "low":
                maximum_value = self._low_quality_settings.getSettingValueByKey(key)
            elif options["maximum"] == "high":
                maximum_value = self._high_quality_settings.getSettingValueByKey(key)
            else:
                continue

            setting_value = round(minimum_value + (maximum_value - minimum_value) * (self._time_quality_value / 100), options["precision"])
            self._current_settings.setSettingValueByKey(key, setting_value)

    def _onSceneChanged(self, source):
        self._slice_reason = self.SliceReason.SceneChanged

    def _onSettingChanged(self, source):
        self._slice_reason = self.SliceReason.SettingChanged

    def _onSlicingCancelled(self):
        self._slice_pass = None
Esempio n. 11
0
class PrintInformation(QObject):
    class SlicePass:
        CurrentSettings = 1
        LowQualitySettings = 2
        HighQualitySettings = 3

    class SliceReason:
        SceneChanged = 1
        SettingChanged = 2
        ActiveMachineChanged = 3
        Other = 4

    def __init__(self, parent=None):
        super().__init__(parent)

        self._enabled = False

        self._minimum_print_time = Duration(None, self)
        self._current_print_time = Duration(None, self)
        self._maximum_print_time = Duration(None, self)

        self._material_amount = -1

        self._time_quality_value = 50
        self._time_quality_changed_timer = QTimer()
        self._time_quality_changed_timer.setInterval(500)
        self._time_quality_changed_timer.setSingleShot(True)
        self._time_quality_changed_timer.timeout.connect(
            self._updateTimeQualitySettings)

        self._interpolation_settings = {
            "layer_height": {
                "minimum": "low",
                "maximum": "high",
                "curve": "linear",
                "precision": 2
            },
            "fill_sparse_density": {
                "minimum": "low",
                "maximum": "high",
                "curve": "linear",
                "precision": 0
            }
        }

        self._low_quality_settings = None
        self._current_settings = None
        self._high_quality_settings = None

        self._slice_pass = None
        self._slice_reason = None

        Application.getInstance().activeMachineChanged.connect(
            self._onActiveMachineChanged)
        self._onActiveMachineChanged()

        Application.getInstance().getController().getScene(
        ).sceneChanged.connect(self._onSceneChanged)

        self._backend = Application.getInstance().getBackend()
        if self._backend:
            self._backend.printDurationMessage.connect(
                self._onPrintDurationMessage)
            self._backend.slicingStarted.connect(self._onSlicingStarted)
            self._backend.slicingCancelled.connect(self._onSlicingCancelled)

    minimumPrintTimeChanged = pyqtSignal()

    @pyqtProperty(Duration, notify=minimumPrintTimeChanged)
    def minimumPrintTime(self):
        return self._minimum_print_time

    currentPrintTimeChanged = pyqtSignal()

    @pyqtProperty(Duration, notify=currentPrintTimeChanged)
    def currentPrintTime(self):
        return self._current_print_time

    maximumPrintTimeChanged = pyqtSignal()

    @pyqtProperty(Duration, notify=maximumPrintTimeChanged)
    def maximumPrintTime(self):
        return self._maximum_print_time

    materialAmountChanged = pyqtSignal()

    @pyqtProperty(float, notify=materialAmountChanged)
    def materialAmount(self):
        return self._material_amount

    timeQualityValueChanged = pyqtSignal()

    @pyqtProperty(int, notify=timeQualityValueChanged)
    def timeQualityValue(self):
        return self._time_quality_value

    def setEnabled(self, enabled):
        if enabled != self._enabled:
            self._enabled = enabled

            if self._enabled:
                self._updateTimeQualitySettings()
                self._onSlicingStarted()

            self.enabledChanged.emit()

    enabledChanged = pyqtSignal()

    @pyqtProperty(bool, fset=setEnabled, notify=enabledChanged)
    def enabled(self):
        return self._enabled

    @pyqtSlot(int)
    def setTimeQualityValue(self, value):
        if value != self._time_quality_value:
            self._time_quality_value = value
            self.timeQualityValueChanged.emit()

            self._time_quality_changed_timer.start()

    def _onSlicingStarted(self):
        if self._slice_pass is None:
            self._slice_pass = self.SlicePass.CurrentSettings

        if self._slice_reason is None:
            self._slice_reason = self.SliceReason.Other

        if self._slice_pass == self.SlicePass.CurrentSettings and self._slice_reason != self.SliceReason.SettingChanged:
            self._minimum_print_time.setDuration(-1)
            self.minimumPrintTimeChanged.emit()
            self._maximum_print_time.setDuration(-1)
            self.maximumPrintTimeChanged.emit()

    def _onPrintDurationMessage(self, time, amount):
        if self._slice_pass == self.SlicePass.CurrentSettings:
            self._current_print_time.setDuration(time)
            self.currentPrintTimeChanged.emit()

            self._material_amount = round(amount / 10) / 100
            self.materialAmountChanged.emit()

            if not self._enabled:
                return

            if self._slice_reason != self.SliceReason.SettingChanged or not self._minimum_print_time.valid or not self._maximum_print_time.valid:
                self._slice_pass = self.SlicePass.LowQualitySettings
                self._backend.slice(settings=self._low_quality_settings,
                                    save_gcode=False,
                                    save_polygons=False,
                                    force_restart=False,
                                    report_progress=False)
            else:
                self._slice_pass = None
                self._slice_reason = None
        elif self._slice_pass == self.SlicePass.LowQualitySettings:
            self._minimum_print_time.setDuration(time)
            self.minimumPrintTimeChanged.emit()

            self._slice_pass = self.SlicePass.HighQualitySettings
            self._backend.slice(settings=self._high_quality_settings,
                                save_gcode=False,
                                save_polygons=False,
                                force_restart=False,
                                report_progress=False)
        elif self._slice_pass == self.SlicePass.HighQualitySettings:
            self._maximum_print_time.setDuration(time)
            self.maximumPrintTimeChanged.emit()

            self._slice_pass = None
            self._slice_reason = None

    def _onActiveMachineChanged(self):
        if self._current_settings:
            self._current_settings.settingChanged.disconnect(
                self._onSettingChanged)

        self._current_settings = Application.getInstance().getActiveMachine()

        if self._current_settings:
            self._current_settings.settingChanged.connect(
                self._onSettingChanged)
            self._low_quality_settings = None
            self._high_quality_settings = None
            self._updateTimeQualitySettings()

            self._slice_reason = self.SliceReason.ActiveMachineChanged

    def _updateTimeQualitySettings(self):
        if not self._current_settings or not self._enabled:
            return

        if not self._low_quality_settings:
            self._low_quality_settings = MachineSettings()
            self._low_quality_settings.loadSettingsFromFile(
                Resources.getPath(Resources.SettingsLocation,
                                  self._current_settings.getTypeID() +
                                  ".json"))
            self._low_quality_settings.loadValuesFromFile(
                Resources.getPath(Resources.SettingsLocation, "profiles",
                                  "low_quality.conf"))

        if not self._high_quality_settings:
            self._high_quality_settings = MachineSettings()
            self._high_quality_settings.loadSettingsFromFile(
                Resources.getPath(Resources.SettingsLocation,
                                  self._current_settings.getTypeID() +
                                  ".json"))
            self._high_quality_settings.loadValuesFromFile(
                Resources.getPath(Resources.SettingsLocation, "profiles",
                                  "high_quality.conf"))

        for key, options in self._interpolation_settings.items():
            minimum_value = None
            if options["minimum"] == "low":
                minimum_value = self._low_quality_settings.getSettingValueByKey(
                    key)
            elif options["minimum"] == "high":
                minimum_value = self._high_quality_settings.getSettingValueByKey(
                    key)
            else:
                continue

            maximum_value = None
            if options["maximum"] == "low":
                maximum_value = self._low_quality_settings.getSettingValueByKey(
                    key)
            elif options["maximum"] == "high":
                maximum_value = self._high_quality_settings.getSettingValueByKey(
                    key)
            else:
                continue

            setting_value = round(
                minimum_value + (maximum_value - minimum_value) *
                (self._time_quality_value / 100), options["precision"])
            self._current_settings.setSettingValueByKey(key, setting_value)

    def _onSceneChanged(self, source):
        self._slice_reason = self.SliceReason.SceneChanged

    def _onSettingChanged(self, source):
        self._slice_reason = self.SliceReason.SettingChanged

    def _onSlicingCancelled(self):
        self._slice_pass = None