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 [], []
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 [], []
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 [], []
def __init__(self, main_file): """ Initializes the data class. Args: main_file: The main file associated with this component. """ super().__init__(main_file) self.data = BoundaryCoverageData(main_file) self.class_name = 'BoundaryCoverageComponent' self.module_name = 'standard_interface_template.components.boundary_coverage_component' # [(menu_text, menu_method)...] self.tree_commands = [ ('Display Options...', 'open_display_options'), ] self.arc_commands = [ ('Assign Arc', 'open_assign_arc'), ] self.point_commands = [ ('Assign Point', 'open_assign_point'), ] self.disp_opts_file = os.path.join( os.path.dirname(self.main_file), 'boundary_coverage_display_options.json') if not os.path.isfile(self.main_file): # Read the default display options, and save ourselves a copy with a randomized UUID. categories = CategoryDisplayOptionList( ) # Generates a random UUID key for the display list default_file = os.path.join( os.path.dirname(os.path.dirname(__file__)), 'gui', 'resources', 'default_data', 'default_boundary_coverage_display_options.json') json_dict = read_display_options_from_json(default_file) json_dict['comp_uuid'] = os.path.basename( os.path.dirname(self.main_file)) categories.from_dict(json_dict) write_display_options_to_json(self.disp_opts_file, categories) # Save our display list UUID to the main file self.data.info.attrs['display_uuid'] = categories.uuid self.data.commit() else: self.cov_uuid = self.data.info.attrs['cov_uuid']
def duplicate_display_opts(new_path, disp_opts_fname): """ Duplicates display options. Args: new_path (str): Path to the new save location. disp_opts_fname (str): The filename (no path) of the display options JSON file. Returns: (json_dict): dict containing the display options. """ fname = os.path.join(new_path, disp_opts_fname) json_dict = read_display_options_from_json(fname) if 'uuid' in json_dict: json_dict['uuid'] = str(uuid.uuid4()) json_dict['comp_uuid'] = os.path.basename(new_path) categories = CategoryDisplayOptionList( ) # Generates a random UUID key for the display list categories.from_dict(json_dict) write_display_options_to_json(fname, categories) return json_dict
def _create_component_folder_and_copy_display_options(self): """Creates the folder for the mapped bc component and copies the display options from the bc coverage.""" if self.bc_mapped_comp_uuid is None: comp_uuid = str(uuid.uuid4()) # pragma: no cover else: comp_uuid = self.bc_mapped_comp_uuid self._logger.info('Creating component folder') bc_comp_path = os.path.dirname(self._bc_component_file) self._comp_path = os.path.join(os.path.dirname(bc_comp_path), comp_uuid) if os.path.exists(self._comp_path): shutil.rmtree(self._comp_path) # pragma: no cover os.mkdir(self._comp_path) os.mkdir(os.path.join(self._comp_path, 'display_ids')) bc_comp_display_file = os.path.join(bc_comp_path, 'boundary_coverage_display_options.json') comp_display_file = os.path.join(self._comp_path, 'boundary_coverage_display_options.json') if os.path.isfile(bc_comp_display_file): shutil.copyfile(bc_comp_display_file, comp_display_file) categories = CategoryDisplayOptionList() # Generates a random UUID key for the display list json_dict = read_display_options_from_json(comp_display_file) if self.bc_mapped_comp_display_uuid is None: json_dict['uuid'] = str(uuid.uuid4()) # pragma: no cover else: json_dict['uuid'] = self.bc_mapped_comp_display_uuid json_dict['comp_uuid'] = comp_uuid json_dict['is_ids'] = 0 categories.from_dict(json_dict) categories.projection = {'wkt': self._grid_wkt} # Set all snapped arcs to be dashed and thick by default. Keep current color. for category in categories.categories: category.options.style = LineStyle.DASHEDLINE category.options.width = 4 category.label_on = False write_display_options_to_json(comp_display_file, categories) self._comp_main_file = comp_display_file else: self._logger.info('Could not find boundary_coverage_display_options.json file') # pragma: no cover
def _create_component_folder_and_copy_display_options(self): """Creates a folder for the mapped material component and copies display options from the material coverage.""" if self.mapped_comp_uuid is None: comp_uuid = str(uuid.uuid4()) # pragma: no cover else: comp_uuid = self.mapped_comp_uuid self._logger.info('Creating component folder') mat_comp_path = os.path.dirname(self._material_component_file) self._comp_path = os.path.join(os.path.dirname(mat_comp_path), comp_uuid) if os.path.exists(self._comp_path): shutil.rmtree(self._comp_path) # pragma: no cover os.mkdir(self._comp_path) os.mkdir(os.path.join(self._comp_path, 'display_ids')) mat_comp_display_file = os.path.join( mat_comp_path, 'materials_coverage_display_options.json') comp_display_file = os.path.join( self._comp_path, 'materials_coverage_display_options.json') if os.path.isfile(mat_comp_display_file): shutil.copyfile(mat_comp_display_file, comp_display_file) categories = CategoryDisplayOptionList( ) # Generates a random UUID key for the display list json_dict = read_display_options_from_json(comp_display_file) if self.mapped_material_display_uuid is None: json_dict['uuid'] = str(uuid.uuid4()) # pragma: no cover else: json_dict['uuid'] = self.mapped_material_display_uuid json_dict['comp_uuid'] = comp_uuid json_dict['is_ids'] = 0 # Set projection of free locations to be that of the mesh/current display categories.projection = {'wkt': self.grid_wkt} categories.from_dict(json_dict) write_display_options_to_json(comp_display_file, categories) self._comp_main_file = comp_display_file else: self._logger.info( 'Could not find materials_coverage_display_options.json file' ) # pragma: no cover