def init_modules(sim, _cc3dXML2ObjConverter): """ :param sim: :param _cc3dXML2ObjConverter: :return: """ plugin_data_list = XMLUtils.CC3DXMLListPy(_cc3dXML2ObjConverter.root.getElements("Plugin")) for pluginData in plugin_data_list: sim.ps.addPluginDataCC3D(pluginData) steppable_data_list = XMLUtils.CC3DXMLListPy(_cc3dXML2ObjConverter.root.getElements("Steppable")) for steppableData in steppable_data_list: sim.ps.addSteppableDataCC3D(steppableData) potts_data_list = XMLUtils.CC3DXMLListPy(_cc3dXML2ObjConverter.root.getElements("Potts")) assert potts_data_list.getBaseClass().size() <= 1, 'You have more than 1 definition of the Potts section' if potts_data_list.getBaseClass().size() == 1: for pottsData in potts_data_list: sim.ps.addPottsDataCC3D(pottsData) metadata_data_list = XMLUtils.CC3DXMLListPy(_cc3dXML2ObjConverter.root.getElements("Metadata")) assert metadata_data_list.getBaseClass().size() <= 1, 'You have more than 1 definition of the Metadata section' if metadata_data_list.getBaseClass().size() == 1: for metadataData in metadata_data_list: sim.ps.addMetadataDataCC3D(metadataData)
def extract_fields_used_from_file_name(_lds_file: str) -> dict: lds_xml = _LatticeDataXMLReader(_lds_file) fields_used = dict() if lds_xml.fields_element: field_list = XMLUtils.CC3DXMLListPy(lds_xml.fields_element.getElements("Field")) fields_used.update({el.getAttribute("Name"): el.getAttribute("Type") for el in field_list}) return fields_used
def extract_custom_vis_scripts_from_file_name(_lds_file: str) -> dict: lds_xml = _LatticeDataXMLReader(_lds_file) o = dict() # ToDo: if a "CustomVis" Type was provided, # require that a "Script" was also provided; else warn user if lds_xml.fields_element: fl = XMLUtils.CC3DXMLListPy(lds_xml.fields_element.getElements("Field")) o.update({el.getAttribute("Name"): el.getAttribute("Script") for el in fl if el.findAttribute("Script")}) return o
def extract_lattice_description_info(self, file_name: str) -> None: """ Reads the xml that summarizes serialized simulation files :param file_name:{str} xml metadata file name :return: None """ # lattice data simulation file lds_file = os.path.abspath(file_name) self.ldsDir = os.path.dirname(lds_file) xml2_obj_converter = XMLUtils.Xml2Obj() root_element = xml2_obj_converter.Parse(lds_file) dim_element = root_element.getFirstElement("Dimensions") self.fieldDim = CompuCell.Dim3D() self.fieldDim.x = int(dim_element.getAttribute("x")) self.fieldDim.y = int(dim_element.getAttribute("y")) self.fieldDim.z = int(dim_element.getAttribute("z")) output_element = root_element.getFirstElement("Output") self.ldsCoreFileName = output_element.getAttribute("CoreFileName") self.frequency = int(output_element.getAttribute("Frequency")) self.numberOfSteps = int(output_element.getAttribute("NumberOfSteps")) # obtaining list of files in the ldsDir lattice_element = root_element.getFirstElement("Lattice") self.latticeType = lattice_element.getAttribute("Type") # getting information about cell type names and cell ids. # It is necessary during generation of the PIF files from VTK output cell_types_elements = root_element.getElements("CellType") list_cell_type_elements = CC3DXMLListPy(cell_types_elements) for cell_type_element in list_cell_type_elements: type_name = cell_type_element.getAttribute("TypeName") type_id = cell_type_element.getAttributeAsInt("TypeId") self.typeIdTypeNameDict[type_id] = type_name # now will convert python dictionary into C++ map<int, string> self.typeIdTypeNameCppMap = CC3DXML.MapIntStr() for type_id in list(self.typeIdTypeNameDict.keys()): self.typeIdTypeNameCppMap[int( type_id)] = self.typeIdTypeNameDict[type_id] lds_file_list = os.listdir(self.ldsDir) for fName in lds_file_list: if re.match(".*\.vtk$", fName): self.ldsFileList.append(fName) self.ldsFileList.sort() # extracting information about fields in the lds file fields_element = root_element.getFirstElement("Fields") if fields_element: field_list = XMLUtils.CC3DXMLListPy( fields_element.getElements("Field")) for field_elem in field_list: field_name = field_elem.getAttribute("Name") self.fieldsUsed[field_elem.getAttribute( "Name")] = field_elem.getAttribute("Type") if field_elem.findAttribute( "Script"): # True or False if present # ToDo: if a "CustomVis" Type was provided, # require that a "Script" was also provided; else warn user custom_vis_script = field_elem.getAttribute("Script") self.customVis = CompuCellSetup.createCustomVisPy( field_name) self.customVis.registerVisCallbackFunction( CompuCellSetup.vtkScriptCallback) self.customVis.addActor(field_name, "vtkActor") # we'll piggyback off the actorsDict self.customVis.addActor("customVTKScript", custom_vis_script)
def treeNode(itemNode, _superParent=None): # itemNode can only be Element! # itemNode is of type CC3DXMLElement if not itemNode: return None try: itemNode.name node = itemNode except AttributeError: node = itemNode.root # node = itemNode t_node = TreeItem(node.name, node.cdata) # Setting item values for Potts, Metadata, Plugins and Steppables. # Those settings are for display purposes only and do not affect CC3DXML element that # Compucell3d uses to configure the data # all we do is to label Potts tree element as Posst and Plugin and Steppables are named # using their names extracted from xml file. # we are using _itemValue to label label those elements and do not change cdata of the CC3DXMLelement if node.name == "Potts": t_node.setItemValueOnly("Potts") if node.name == "Metadata": t_node.setItemValueOnly("Metadata") # handling opening elements for Plugin and Steppables if node.name == "Plugin": t_node.setItemValueOnly(node.getAttribute("Name")) if node.name == "Steppable": t_node.setItemValueOnly(node.getAttribute("Type")) t_node.setCC3DXMLElement( node) # domNode holds reference to current CC3DXMLElement # setting superParents -they are either Potts, Plugin or Steppable. SuperParents are used in steering. # Essentially when we change any TreeItem in the TreeView # we can quickly extract name of the superParent and tell CC3D to reinitialize module that superParent describes. # Otherwise if we dont keep track of super parents we would either have to do: # 1. time consuming and messy tracking back of which module needs to be changed in response # to change in one of the parameter # or # 2. reinitialize all modules each time a single parameter is changed superParent = _superParent if not _superParent: if node.name in ("Plugin", "Steppable", "Potts", "Metadata"): superParent = t_node t_node.setSuperParent(superParent) # FOR AN UNKNOWN REASON "regular" map iteration does not work so i had to implement by hand iterators # in C++ and Python to walk through all the elements in the map<string,string> in python if node.attributes.size(): for attr_combo in node.attributes.items(): attribute_name = attr_combo[0] attribute_value = attr_combo[1] if node.name == "Plugin" and attribute_name == "Name": continue if node.name == "Steppable" and attribute_name == "Type": continue tree_child = TreeItem( attribute_name, attribute_value) # attribute name, attribute value pair tree_child.setCC3DXMLElement(node) tree_child.setSuperParent(superParent) tree_child.setElementType("attribute") t_node.addChild(tree_child) children = XMLUtils.CC3DXMLListPy(node.children) for child in children: t_child = treeNode(child, superParent) t_node.addChild(t_child) return t_node