Пример #1
0
 def cmdOK_Clicked(self):
     section = self._main_form.project.landuses
     land_uses_list = section.value[0:]
     for land_use in land_uses_list:
         if land_use.land_use_name == self.land_use_id:
             # put this back in place
             land_use.land_use_name = self.tblGeneral.item(0, 0).text()
             land_use.comment = self.tblGeneral.item(1, 0).text()
             land_use.last_swept = self.tblGeneral.item(3, 0).text()
             land_use.street_sweeping_availability = self.tblGeneral.item(
                 4, 0).text()
             land_use.street_sweeping_interval = self.tblGeneral.item(
                 5, 0).text()
     section = self._main_form.project.buildup
     buildup_list = section.value[0:]
     pollutant_count = -1
     for pollutant in self.local_pollutant_list:
         pollutant_count += 1
         buildup_found = False
         for buildup in buildup_list:
             if buildup.land_use_name == self.land_use_id and pollutant == buildup.pollutant:
                 # put this back in place
                 buildup_found = True
                 combobox = self.tblBuildup.cellWidget(0, pollutant_count)
                 buildup.function = BuildupFunction[combobox.currentText()]
                 buildup.max_buildup = self.tblBuildup.item(
                     1, pollutant_count).text()
                 buildup.rate_constant = self.tblBuildup.item(
                     2, pollutant_count).text()
                 buildup.power_sat_constant = self.tblBuildup.item(
                     3, pollutant_count).text()
                 combobox = self.tblBuildup.cellWidget(4, pollutant_count)
                 buildup.normalizer = Normalizer[combobox.currentText()]
                 buildup.scaling_factor = self.tblBuildup.item(
                     5, pollutant_count).text()
                 combobox = self.tblBuildup.cellWidget(6, pollutant_count)
                 buildup.timeseries = combobox.currentText()
         if not buildup_found:
             # add new record
             new_buildup = Buildup()
             new_buildup.land_use_name = self.land_use_id
             new_buildup.pollutant = pollutant
             combobox = self.tblBuildup.cellWidget(0, pollutant_count)
             new_buildup.function = BuildupFunction[combobox.currentText()]
             new_buildup.max_buildup = self.tblBuildup.item(
                 1, pollutant_count).text()
             new_buildup.rate_constant = self.tblBuildup.item(
                 2, pollutant_count).text()
             new_buildup.power_sat_constant = self.tblBuildup.item(
                 3, pollutant_count).text()
             combobox = self.tblBuildup.cellWidget(4, pollutant_count)
             new_buildup.normalizer = Normalizer[combobox.currentText()]
             new_buildup.scaling_factor = self.tblBuildup.item(
                 5, pollutant_count).text()
             combobox = self.tblBuildup.cellWidget(6, pollutant_count)
             new_buildup.timeseries = combobox.currentText()
             if section.value == '':
                 section.value = []
             section.value.append(new_buildup)
     section = self._main_form.project.find_section("WASHOFF")
     washoff_list = section.value[0:]
     pollutant_count = -1
     for pollutant in self.local_pollutant_list:
         pollutant_count += 1
         washoff_found = False
         for washoff in washoff_list:
             if washoff.land_use_name == self.land_use_id and pollutant == washoff.pollutant:
                 # put this back in place
                 washoff_found = True
                 combobox = self.tblWashoff.cellWidget(0, pollutant_count)
                 washoff.function = WashoffFunction[combobox.currentText()]
                 washoff.coefficient = self.tblWashoff.item(
                     1, pollutant_count).text()
                 washoff.exponent = self.tblWashoff.item(
                     2, pollutant_count).text()
                 washoff.cleaning_efficiency = self.tblWashoff.item(
                     3, pollutant_count).text()
                 washoff.bmp_efficiency = self.tblWashoff.item(
                     4, pollutant_count).text()
         if not washoff_found:
             # add new record
             new_washoff = Washoff()
             new_washoff.land_use_name = self.land_use_id
             new_washoff.pollutant = pollutant
             combobox = self.tblWashoff.cellWidget(0, pollutant_count)
             new_washoff.function = WashoffFunction[combobox.currentText()]
             new_washoff.coefficient = self.tblWashoff.item(
                 1, pollutant_count).text()
             new_washoff.exponent = self.tblWashoff.item(
                 2, pollutant_count).text()
             new_washoff.cleaning_efficiency = self.tblWashoff.item(
                 3, pollutant_count).text()
             new_washoff.bmp_efficiency = self.tblWashoff.item(
                 4, pollutant_count).text()
             if section.value == '':
                 section.value = []
             section.value.append(new_washoff)
     self.close()
    def cmdOK_Clicked(self):
        new_name = self.tblGeneral.item(0,0).text()
        pollutant_count = -1
        for pollutant in self.local_pollutant_list:
            pollutant_count += 1
            buildup_found = False
            for buildup in self.project.buildup.value:
                if buildup.land_use_name == self.editing_item.name and pollutant == buildup.pollutant:
                    # put this back in place
                    buildup_found = True

                    orig_land_use_name = buildup.land_use_name
                    orig_function = buildup.function
                    orig_max_buildup = buildup.max_buildup
                    orig_rate_constant = buildup.rate_constant
                    orig_power_sat_constant = buildup.power_sat_constant
                    orig_normalizer = buildup.normalizer
                    orig_scaling_factor = buildup.scaling_factor
                    orig_timeseries = buildup.timeseries

                    combobox = self.tblBuildup.cellWidget(0,pollutant_count)
                    buildup.land_use_name = new_name
                    buildup.function = BuildupFunction[combobox.currentText()]
                    buildup.max_buildup = self.tblBuildup.item(1,pollutant_count).text()
                    buildup.rate_constant = self.tblBuildup.item(2,pollutant_count).text()
                    buildup.power_sat_constant = self.tblBuildup.item(3,pollutant_count).text()
                    combobox = self.tblBuildup.cellWidget(4,pollutant_count)
                    buildup.normalizer = Normalizer[combobox.currentText()]
                    buildup.scaling_factor = self.tblBuildup.item(5,pollutant_count).text()
                    combobox = self.tblBuildup.cellWidget(6,pollutant_count)
                    buildup.timeseries = combobox.currentText()

                    if orig_land_use_name != buildup.land_use_name or \
                        orig_function != buildup.function or \
                        orig_max_buildup != buildup.max_buildup or \
                        orig_rate_constant != buildup.rate_constant or \
                        orig_power_sat_constant != buildup.power_sat_constant or \
                        orig_normalizer != buildup.normalizer or \
                        orig_scaling_factor != buildup.scaling_factor or \
                        orig_timeseries != buildup.timeseries and buildup.function == BuildupFunction.EXP:
                        self._main_form.mark_project_as_unsaved()

            if not buildup_found:
                # add new record
                new_buildup = Buildup()
                new_buildup.land_use_name = new_name
                new_buildup.pollutant = pollutant
                combobox = self.tblBuildup.cellWidget(0,pollutant_count)
                new_buildup.function = BuildupFunction[combobox.currentText()]
                new_buildup.max_buildup = self.tblBuildup.item(1,pollutant_count).text()
                new_buildup.rate_constant = self.tblBuildup.item(2,pollutant_count).text()
                new_buildup.power_sat_constant = self.tblBuildup.item(3,pollutant_count).text()
                combobox = self.tblBuildup.cellWidget(4,pollutant_count)
                new_buildup.normalizer = Normalizer[combobox.currentText()]
                new_buildup.scaling_factor = self.tblBuildup.item(5,pollutant_count).text()
                combobox = self.tblBuildup.cellWidget(6,pollutant_count)
                new_buildup.timeseries = combobox.currentText()
                if self.project.buildup.value == '':
                    self.project.buildup.value = []
                self.project.buildup.value.append(new_buildup)
                self._main_form.mark_project_as_unsaved()

        pollutant_count = -1
        for pollutant in self.local_pollutant_list:
            pollutant_count += 1
            washoff_found = False
            for washoff in self.project.washoff.value:
                if washoff.land_use_name == self.editing_item.name and pollutant == washoff.pollutant:
                    # put this back in place
                    washoff_found = True

                    orig_land_use_name = washoff.land_use_name
                    orig_function = washoff.function
                    orig_coefficient = washoff.coefficient
                    orig_exponent = washoff.exponent
                    orig_cleaning_efficiency = washoff.cleaning_efficiency
                    orig_bmp_efficiency = washoff.bmp_efficiency

                    combobox = self.tblWashoff.cellWidget(0,pollutant_count)
                    washoff.land_use_name = new_name
                    washoff.function = WashoffFunction[combobox.currentText()]
                    washoff.coefficient = self.tblWashoff.item(1,pollutant_count).text()
                    washoff.exponent = self.tblWashoff.item(2,pollutant_count).text()
                    washoff.cleaning_efficiency = self.tblWashoff.item(3,pollutant_count).text()
                    washoff.bmp_efficiency = self.tblWashoff.item(4,pollutant_count).text()

                    if orig_land_use_name != washoff.land_use_name or \
                        orig_function != washoff.function or \
                        orig_coefficient != washoff.coefficient or \
                        orig_exponent != washoff.exponent or \
                        orig_cleaning_efficiency != washoff.cleaning_efficiency or \
                        orig_bmp_efficiency != washoff.bmp_efficiency:
                        self._main_form.mark_project_as_unsaved()

            if not washoff_found:
                # add new record
                new_washoff = Washoff()
                new_washoff.land_use_name = new_name
                new_washoff.pollutant = pollutant
                combobox = self.tblWashoff.cellWidget(0,pollutant_count)
                new_washoff.function = WashoffFunction[combobox.currentText()]
                new_washoff.coefficient = self.tblWashoff.item(1,pollutant_count).text()
                new_washoff.exponent = self.tblWashoff.item(2,pollutant_count).text()
                new_washoff.cleaning_efficiency = self.tblWashoff.item(3,pollutant_count).text()
                new_washoff.bmp_efficiency = self.tblWashoff.item(4,pollutant_count).text()
                if self.project.washoff.value == '':
                    self.project.washoff.value = []
                self.project.washoff.value.append(new_washoff)
                self._main_form.mark_project_as_unsaved()

        # put this back in place
        orig_name = self.editing_item.name
        orig_comment = self.editing_item.comment
        orig_last_swept = self.editing_item.last_swept
        orig_street_sweeping_availability = self.editing_item.street_sweeping_availability
        orig_street_sweeping_interval = self.editing_item.street_sweeping_interval

        self.editing_item.name = new_name
        self.editing_item.comment = self.tblGeneral.item(1,0).text()
        self.editing_item.last_swept = self.tblGeneral.item(3,0).text()
        self.editing_item.street_sweeping_availability = self.tblGeneral.item(4,0).text()
        self.editing_item.street_sweeping_interval = self.tblGeneral.item(5,0).text()

        if orig_name != self.editing_item.name or \
            orig_comment != self.editing_item.comment or \
            orig_last_swept != self.editing_item.last_swept or \
            orig_street_sweeping_availability != self.editing_item.street_sweeping_availability or \
            orig_street_sweeping_interval != self.editing_item.street_sweeping_interval:
            self._main_form.mark_project_as_unsaved()

        if self.new_item:  # We are editing a newly created item and it needs to be added to the project
            self._main_form.add_item(self.new_item)
            self._main_form.mark_project_as_unsaved()
        else:
            pass
            # TODO: self._main_form.edited_?

        self.close()