def _read_settings(self, module_name, sub_module_name):
     """
     reads the public settings from a simulation module
     """
     module_cls = getattr(simulation_modules, module_name)
     sub_module_cls = get_simulation_module_class_by_name(module_cls, sub_module_name)
     return sub_module_cls.public_settings
    def _apply_regime(self, reg):
        """
        sets all module settings to those provided in the regime
        """
        if reg["clear previous"]:
            # delete all items
            self.target_model.removeRows(0, self.target_model.rowCount())

            # load module defaults
            self._setup_model_items()

        # overwrite all settings with the provided ones
        for module_name, value in reg.iteritems():
            if module_name == "Name" or module_name == "clear previous":
                continue

            # sanity check
            module_cls = getattr(simulation_modules, module_name)
            if not module_cls:
                raise AttributeError("_apply_regime(): No module called {0}".format(module_name))

            items = self.target_model.findItems(module_name)
            # items = self.target_model.findItems(string.capwords(module_name))
            if not len(items):
                raise ValueError("_apply_regime(): No item in List called {0}".format(module_name))
            module_item = items.pop(0)
            module_type = value["type"]

            # sanity check
            sub_module_cls = get_simulation_module_class_by_name(module_cls, module_type)

            if not sub_module_cls:
                raise AttributeError("_apply_regime(): No sub-module called {0}".format(module_type))

            module_index = module_item.index()
            module_type_index = module_index.model().index(module_index.row(), 1)
            module_index.model().setData(module_type_index, module_type)
            # due to signal connections, default settings are loaded automatically in the back

            # overwrite specific settings
            for key, val in value.iteritems():
                if key == "type":
                    continue

                found = False
                for row in range(module_item.rowCount()):
                    if str(module_item.child(row, 0).text()) == key:
                        value_idx = self.target_model.index(row, 1, module_index)
                        self.target_model.setData(value_idx, str(val))
                        found = True
                        break

                if not found:
                    self._logger.error("_applyRegime(): setting {0} not available for {1}".format(key, module_type))
                    continue
    def _setup_sim_modules(self, model):
        """
        setup simulation Modules
        :param model: model holding the public settings of each module
        """

        for row in range(model.rowCount()):
            # build correct object and add it to the simulator
            module_item = model.item(row, 0)
            module_name = str(module_item.text())
            sub_module_item = model.item(row, 1)
            sub_module_name = str(sub_module_item.text())

            if sub_module_name == 'None':
                continue

            # get class
            module_cls = getattr(simulation_modules, module_name)
            sub_module_cls = get_simulation_module_class_by_name(module_cls, sub_module_name)

            # get public settings for module
            settings = self._get_settings(self.target_model, module_item.text())
            settings.update({"type": sub_module_name})
            settings.update({"modules": self._sim_modules})

            # append special settings
            if module_name == "Solver":
                self._sim_settings = SimulationSettings(settings["start time"],
                                                        settings["end time"],
                                                        settings["measure rate"])

            # build object
            slot = sub_module_cls(settings)

            # add to simulation modules
            self._sim_modules.update({module_name: slot})

            # store settings
            self._sim_data['modules'].update({module_name: settings})