Beispiel #1
0
    def open_display_options(self, query, params, win_cont, icon):
        """
        Shows the display options dialog.

        Args:
            query (:obj:`xmsapi.dmi.Query`): An object for communicating with XMS. Unused by this method.
            params (:obj:`list` of :obj:`str`): A list of parameters add to the ActionRequest. Unused by this method.
            win_cont (:obj:`PySide2.QtWidgets.QWidget`): The window container.
            icon (:obj:`PySide2.QtGui.QIcon`): Icon to show in the dialog title.

        Returns:
            (:obj:`tuple`): tuple containing:
                - messages (:obj:`list` of :obj:`tuple` of :obj:`str`): List of tuples with the first element of the
                  tuple being the message level (DEBUG, ERROR, WARNING, INFO) and the second element being the message
                  text.
                - action_requests (:obj:`list` of :obj:`xmsapi.dmi.ActionRequest`): List of actions for XMS to perform.
        """
        categories = CategoryDisplayOptionList()
        json_dict = read_display_options_from_json(self.disp_opts_file)
        categories.from_dict(json_dict)
        categories_list = [categories]

        dlg = CategoryDisplayOptionsDialog(categories_list, win_cont)
        dlg.setWindowIcon(icon)
        dlg.setModal(True)
        if dlg.exec():
            # write files
            category_lists = dlg.get_category_lists()
            for category_list in category_lists:
                write_display_options_to_json(self.disp_opts_file, category_list)
                self.display_option_list.append(
                    XmsDisplayMessage(file=self.disp_opts_file, draw_type=DrawType.draw_at_locations)
                )
                break  # only one list
        return [], []
Beispiel #2
0
    def open_materials(self, query, params, win_cont, icon):
        """
        Shows the materials dialog.

        Args:
            query (:obj:`xmsapi.dmi.Query`): Object for communicating with XMS.
            params (:obj:`list` of :obj:`str`): List of parameters.  Unused in this case.
            win_cont (:obj:`PySide2.QtWidgets.QWidget`): The window container.
            icon (:obj:`PySide2.QtGui.QIcon`): Icon to show in the dialog title.

        Returns:
            (:obj:`tuple`): tuple containing:
                - messages (:obj:`list` of :obj:`tuple` of :obj:`str`): List of tuples with the first element of the
                  tuple being the message level (DEBUG, ERROR, WARNING, INFO) and the second element being the message
                  text.
                - action_requests (:obj:`list` of :obj:`xmsapi.dmi.ActionRequest`): List of actions for XMS to perform.
        """
        ids = list(self.data.coverage_data.material_id.values)
        dlg = MaterialsDialog('Materials', win_cont, icon, self.data)
        if dlg.exec_():
            new_ids = list(self.data.coverage_data.material_id.values)
            deleted_ids = [
                int(x) for x in self.update_display_id_files(ids, new_ids)
            ]
            self.unassign_materials(query, deleted_ids)
            # write files
            category_list = self._get_category_list()
            write_display_options_to_json(self.disp_opts_file, category_list)
            self.display_option_list.append(
                XmsDisplayMessage(
                    file=self.disp_opts_file,
                    edit_uuid=self.cov_uuid,
                ))
        return [], []
Beispiel #3
0
    def project_open_event(self, new_path):
        """
        Called when an XMS project is opened.

        Components with display lists should add XmsDisplayMessage(s) to self.display_option_list.

        Args:
            new_path (str): Path to the new save location.
        """
        if self.disp_opts_file:  # Component has a display list
            new_disp_opts = os.path.join(new_path,
                                         os.path.basename(self.disp_opts_file))
            if self.cov_uuid:  # drawing on a coverage by id
                self.display_option_list.append(
                    XmsDisplayMessage(file=new_disp_opts,
                                      edit_uuid=self.cov_uuid))
            else:  # Free location draw of a mapped component
                self.display_option_list.append(
                    XmsDisplayMessage(file=new_disp_opts,
                                      draw_type=DrawType.draw_at_locations))
Beispiel #4
0
    def get_initial_display_options(self, query, params):
        """
        Get the coverage UUID from XMS and send back the display options list.

        Args:
            query (:obj:`xmsapi.dmi.Query`): Object for communicating with XMS.
            params (:obj:`dict`): Generic map of parameters. Unused in this case.

        Returns:
            (:obj:`tuple`): tuple containing:
                - messages (:obj:`list` of :obj:`tuple` of :obj:`str`): List of tuples with the first element of the
                  tuple being the message level (DEBUG, ERROR, WARNING, INFO) and the second element being the message
                  text. For this method this will always be empty.
                - action_requests (:obj:`list` of :obj:`xmsapi.dmi.ActionRequest`): List of actions for XMS to perform.
                  For this method this will always be empty.
        """
        query.select('Parent')  # Go up to the parent coverage.
        uuid_result = query.get('geom_guid')['geom_guid']
        if not uuid_result or not uuid_result[0]:
            return [('ERROR',
                     'Could not get Standard Interface coverage UUID.')], []
        self.cov_uuid = uuid_result[0].get_as_string()

        initial_att_file = os.path.join(os.path.dirname(self.main_file),
                                        BC_COVERAGE_INITIAL_ATT_ID_FILE)
        if os.path.isfile(
                initial_att_file
        ):  # Came from a model native read, initialize the component ids.
            att_ids = read_display_option_ids(initial_att_file)
            initial_comp_file = os.path.join(os.path.dirname(self.main_file),
                                             BC_COVERAGE_INITIAL_COMP_ID_FILE)
            comp_ids = read_display_option_ids(initial_comp_file)
            os.remove(initial_att_file)
            os.remove(initial_comp_file)
            for att_id, comp_id in zip(att_ids, comp_ids):
                self.update_component_id(TargetType.arc, att_id, comp_id)
            id_dir = os.path.join(os.path.dirname(self.main_file),
                                  'display_ids')
            os.mkdir(id_dir)
            self.update_id_files()

        self.data.info.attrs['cov_uuid'] = self.cov_uuid
        self.data.commit()
        # Send the display message to XMS.
        self.display_option_list.append(
            XmsDisplayMessage(file=self.disp_opts_file,
                              edit_uuid=self.cov_uuid))
        return [], []
Beispiel #5
0
    def get_initial_display_options(self, query, params):
        """
        Get the coverage UUID from XMS and send back the display options list.

        Args:
            query (:obj:`xmsapi.dmi.Query`): Object for communicating with XMS.
            params (:obj:`dict`): Generic map of parameters. Unused in this case.

        Returns:
            Empty message and ActionRequest lists.
        """
        # Send the default display options list to XMS.
        self.display_option_list.append(
            XmsDisplayMessage(file=self.main_file,
                              draw_type=DrawType.draw_at_locations))
        return [], []
Beispiel #6
0
    def get_initial_display_options(self, query, params):
        """
        Get the coverage UUID from XMS and send back the display options list.

        Args:
            query (:obj:`xmsapi.dmi.Query`): Object for communicating with XMS.
            params (:obj:`dict`): Generic map of parameters. Unused in this case.

        Returns:
            Empty message and ActionRequest lists.
        """
        query.select('Parent')  # Go up to the parent coverage.
        uuid_result = query.get('geom_guid')['geom_guid']
        if not uuid_result or not uuid_result[0]:
            return [('ERROR',
                     'Could not get Standard Interface coverage UUID.')], []
        self.cov_uuid = uuid_result[0].get_as_string()

        initial_att_file = os.path.join(os.path.dirname(self.main_file),
                                        MAT_COVERAGE_INITIAL_ATT_ID_FILE)
        if os.path.isfile(
                initial_att_file
        ):  # Came from a model native read, initialize the component ids.
            att_ids = read_display_option_ids(initial_att_file)
            initial_comp_file = os.path.join(
                os.path.dirname(self.main_file),
                MAT_COVERAGE_INITIAL_COMP_ID_FILE)
            comp_ids = read_display_option_ids(initial_comp_file)
            os.remove(initial_att_file)
            os.remove(initial_comp_file)
            for att_id, comp_id in zip(att_ids, comp_ids):
                self.update_component_id(TargetType.polygon, att_id, comp_id)
            id_dir = os.path.join(os.path.dirname(self.main_file),
                                  'display_ids')
            os.mkdir(id_dir)
            categories = self._get_category_list()
            write_display_options_to_json(self.disp_opts_file, categories)
            self.update_display_id_files(
                [], list(self.data.coverage_data.material_id.values))

        self.data.info.attrs['cov_uuid'] = self.cov_uuid
        self.data.commit()
        # Send the display message to XMS.
        self.display_option_list.append(
            XmsDisplayMessage(file=self.disp_opts_file,
                              edit_uuid=self.cov_uuid))
        return [], []
Beispiel #7
0
    def open_assign_polygon(self, query, params, win_cont, icon):
        """
        Opens the Assign Polygon dialog and saves component data state on OK.

        Args:
            query (:obj:`xmsapi.dmi.Query`): Object for communicating with XMS.  Unused in this case.
            params (:obj:`dict`): Generic map of parameters. Contains selection map and component id files.
            win_cont (:obj:`PySide2.QtWidgets.QWidget`): The window container.
            icon (:obj:`PySide2.QtGui.QIcon`): Icon to show in the dialog title.

        Returns:
            (:obj:`tuple`): tuple containing:
                - messages (:obj:`list` of :obj:`tuple` of :obj:`str`): List of tuples with the first element of the
                  tuple being the message level (DEBUG, ERROR, WARNING, INFO) and the second element being the message
                  text.
                - action_requests (:obj:`list` of :obj:`xmsapi.dmi.ActionRequest`): List of actions for XMS to perform.
        """
        polygon_ids = []
        params = {
            key.get_as_string(): value
            for key, value in params[0].items()
        }
        if 'selection' in params:
            polygon_ids = [
                polygon_id.get_as_int() for polygon_id in params['selection']
            ]
        num_arcs = len(polygon_ids)
        if num_arcs == 0:
            return [(
                'INFO',
                'No polygons selected. Select one or more polygons to assign properties.'
            )], []

        # Get the component id map of the selected (if any).
        comp_id = -1
        multi_label = ''
        if 'id_files' in params:
            if params['id_files'] and params['id_files'][0]:
                files_dict = {
                    'POLYGON': (params['id_files'][0].get_as_string(),
                                params['id_files'][1].get_as_string())
                }
                self.load_coverage_component_id_map(files_dict)
                target_type = TargetType.polygon
                try:
                    selected_comp_ids = list(
                        self.comp_to_xms[self.cov_uuid][target_type].keys())
                    comp_id = selected_comp_ids[0] if selected_comp_ids else -1
                    if len(selected_comp_ids) > 1:
                        multi_label = 'Multiple polygons will be assigned the same material.'
                except KeyError:
                    comp_id = -1  # No component ids assigned for any of the selected polygons
        single_polygon = self.data.coverage_data.where(
            self.data.coverage_data.material_id == comp_id, drop=True)
        material_names = list(self.data.coverage_data.name.values)
        material_ids = list(self.data.coverage_data.material_id.values)
        if single_polygon.user_option.size == 0:
            # Here we are using component id 0 for default values.
            single_polygon = self.data.coverage_data.where(
                self.data.coverage_data.material_id == 0, drop=True)
        material_index = material_names.index(single_polygon.name[0])
        dialog = AssignPolyMaterialDialog(win_cont, icon, 'Assign Material',
                                          multi_label, material_names,
                                          material_index)
        if dialog.exec_():
            new_material_index = dialog.get_selected_material()
            new_material_id = int(material_ids[new_material_index])
            for polygon_id in polygon_ids:
                self.update_component_id(TargetType.polygon, polygon_id,
                                         new_material_id)
            self.display_option_list.append(
                XmsDisplayMessage(file=self.disp_opts_file,
                                  edit_uuid=self.cov_uuid))
            self.data.commit()

        # Delete the id dumped by xms files.
        shutil.rmtree(os.path.join(os.path.dirname(self.main_file), 'temp'),
                      ignore_errors=True)

        return [], []
Beispiel #8
0
    def open_assign_point(self, query, params, win_cont, icon):
        """
        Opens the Assign Point dialog and saves component data state on OK.

        Args:
            query (:obj:`xmsapi.dmi.Query`): Object for communicating with XMS.
            params (:obj:`dict`): Generic map of parameters. Contains selection map and component id files.
            win_cont (:obj:`PySide2.QtWidgets.QWidget`): The window container.
            icon (:obj:`PySide2.QtGui.QIcon`): Icon to show in the dialog title.

        Returns:
            (:obj:`tuple`): tuple containing:
                - messages (:obj:`list` of :obj:`tuple` of :obj:`str`): List of tuples with the first element of the
                  tuple being the message level (DEBUG, ERROR, WARNING, INFO) and the second element being the message
                  text.
                - action_requests (:obj:`list` of :obj:`xmsapi.dmi.ActionRequest`): List of actions for XMS to perform.
        """
        point_ids = []
        params = {
            key.get_as_string(): value
            for key, value in params[0].items()
        }
        if 'selection' in params:
            point_ids = [
                point_id.get_as_int() for point_id in params['selection']
            ]
        num_points = len(point_ids)
        if num_points == 0:
            return [(
                'INFO',
                'No points selected. Select one or more points to assign properties.'
            )], []

        # Get the component id map of the selected (if any).
        comp_id = -1
        if 'id_files' in params:
            if params['id_files'] and params['id_files'][0]:
                files_dict = {
                    'POINT': (params['id_files'][0].get_as_string(),
                              params['id_files'][1].get_as_string())
                }
                self.load_coverage_component_id_map(files_dict)
                target_type = TargetType.point
                try:
                    selected_comp_ids = list(
                        self.comp_to_xms[self.cov_uuid][target_type].keys())
                    comp_id = selected_comp_ids[0] if selected_comp_ids else -1
                except KeyError:
                    comp_id = -1  # No component ids assigned for any of the selected points
        single_point = self.data.coverage_data.where(
            self.data.coverage_data.comp_id == comp_id, drop=True)
        if single_point.user_option.size == 0:
            # Here we are using component id 0 for default values.
            single_point = self.data.coverage_data.where(
                self.data.coverage_data.comp_id == 0, drop=True)
        dialog = BoundaryDialog(win_cont, icon, 'Point Dialog',
                                single_point.user_text.item(0),
                                single_point.user_option.item(0))
        if dialog.exec():
            dlg_data = dialog.get_dialog_data_dict()
            edit = dlg_data['user_edit']
            option = dlg_data['user_display']
            new_comp_id = int(self.data.coverage_data.comp_id.max() + 1)
            new_values = []
            for point_id in point_ids:
                self.update_component_id(TargetType.point, point_id,
                                         new_comp_id)
                new_values.append([new_comp_id, option, edit])
                new_comp_id += 1
            values_dataset = pd.DataFrame(
                new_values, columns=['comp_id', 'user_option',
                                     'user_text']).to_xarray()
            self.data.coverage_data = xr.concat(
                [self.data.coverage_data, values_dataset], 'index')
            self.update_id_files()
            self.display_option_list.append(
                XmsDisplayMessage(file=self.disp_opts_file,
                                  edit_uuid=self.cov_uuid))
            self.data.commit()

        # Delete the id dumped by xms files.
        shutil.rmtree(os.path.join(os.path.dirname(self.main_file), 'temp'),
                      ignore_errors=True)

        return [], []