Commit 8a996989 authored by Greenwood, Scott's avatar Greenwood, Scott
Browse files

make modifications to remove requirement of project name in input spec file...

make modifications to remove requirement of project name in input spec file (this makes it more general as everything else in the spec is agnostic)
parent 03942566
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ class AutoCSM:
        self._input_specification = None
        self._output_path = None
        self._project_path = None
        self._project_name = None
        
        # Internal variables
        self._model_path = None
@@ -124,11 +125,24 @@ class AutoCSM:

    @project_path.setter
    def project_path(self, path: str) -> None:
        """Sets the project path, ensuring it's not 'package.mo'."""
        """Sets the project path, ensuring it's not 'package.mo'. Updates project_name if name doesn't match path"""
        temp = pathlib.Path(path).resolve()
        if temp.name == "package.mo":
            temp = temp.parent
        self._project_path = temp.as_posix()
        if self._project_name != temp.stem:
            print(f'Updating project name to match project path. Changed {self._project_name} to {temp.stem}')
            self._project_name = temp.stem
             
    @property
    def project_name(self) -> str:
        """Returns the project name."""
        return self._project_name

    @project_name.setter
    def project_name(self, name: str) -> None:
        """Sets the project name."""
        self._project_name = name
                    
    def _execute_with_animation(self, message: str, method, *args, **kwargs):
        """
@@ -149,7 +163,7 @@ class AutoCSM:
        """
        Creates the architecture based on the selected language and architecture.
        
        The output project architecture name is deterined from the JSON input file.
        The output project architecture name is deterined from the project name if provided else the JSON file.

        Args:
            *args: Additional positional arguments passed to the architecture creation method.
@@ -215,16 +229,18 @@ if __name__ == "__main__":
    csm = AutoCSM(language='modelica', architecture='nested')

    # Load the JSON specification
    csm.input_specification = '../examples/data/input_specification_v0.json'
    csm.input_specification = '../examples/json/input_specification_v0.json'

    # Set the path to output created files
    csm.output_path = '../temp'

    csm.project_name = 'GenericDatacenter'
    
    # This line creates a project with a file structure for the specified language and architecture
    csm.create_architecture() # Useful if a project is being created from scratch
    
    # Set the path to the project which uses an AutoCSM language method 
    csm.project_path = '../examples/modelica/GenericCSM'
    csm.project_path = '../examples/modelica/' + csm.project_name

    # Create the model for export to FMU (i.e., Simulator.mo)
    csm.create_model(uniform=[False, False])
+11 −2
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ def create_nested_structure(data, output_path, template_folder, isTopSystem=True
    # Handle the special case of the top level system being the name of the project.
    if isTopSystem:
        new_folder_path = os.path.join(output_path, data['Name'])
            
        if os.path.exists(new_folder_path):
            shutil.rmtree(new_folder_path)
    else:
@@ -334,7 +335,7 @@ def remove_duplicate_systems(input_dict, current_level=0):
        
    return cleaned_dict, report
    
def main(json_file_path, output_path, template_folder, architecture='nested'):
def main(json_file_path, output_path, template_folder, project_name=None, architecture='nested', ):
    """
    Main function to create the folder structure and correct package files.

@@ -342,6 +343,7 @@ def main(json_file_path, output_path, template_folder, architecture='nested'):
    json_file_path (str): The path to the JSON file containing the project structure.
    output_path (str): The base path where the folder structure will be created.
    template_folder (str): The path to the template folder to be copied.
    project_name (str): Name of top level project (e.g., modeling library). Input specification may contain this but if this is not None it will override it.
    architecture (str): The type of project structure to create ('nested' or 'flat').

    Returns:
@@ -349,6 +351,13 @@ def main(json_file_path, output_path, template_folder, architecture='nested'):
    """
    data = helper_functions.read_json(json_file_path)
    
    # Logic to not require project name in input specification
    if project_name is not None:
        data['Name'] = project_name
        
    if 'Name' not in data.keys():
        data['Name'] = 'PROJECTNAME'
        
    # Process the data to remove duplicates at every level
    data, report = remove_duplicate_systems(data)

@@ -368,7 +377,7 @@ if __name__ == "__main__":
    # Change to your JSON file path
    # Change to your template folder path
    # Change to your desired output directory
    json_file_path = '../../../examples/data/input_specification_v0.json'
    json_file_path = '../../../examples/json/input_specification_v0.json'
    template_folder = '../../../methods/modelica/TemplatesCSM/Templates/TemplateSystem'
    output_path = '../../../temp'   
    main(json_file_path, output_path, template_folder, architecture='nested')
 No newline at end of file
+3 −3
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ def main(json_file_path, project_path, base_path, parent_class, output_path, str

if __name__ == "__main__":
    # JSON file path
    json_file_path = '../../../examples/data/input_specification_v0.json'
    json_file_path = '../../../examples/json/input_specification_v0.json'

    # Output Modelica file
    output_path = '../../../temp/Simulator.mo'
@@ -239,7 +239,7 @@ if __name__ == "__main__":
    project_path = '../../../examples/modelica/GenericDatacenter'
    
    # Path to top-level system model folder (dotted path) perhaps not a good one
    base_path = pathlib.Path(project_path).name #'GenericCSM'
    base_path = pathlib.Path(project_path).name #'GenericDatacenter'

    # Model to be extended and modified
    parent_class = 'ExaDigiT_AutoCSM.BaseClasses.Tests.PartialTest'
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ class ModelicaMethods(LanguageMethod):
            create_architecture.main(self.parent.input_specification,
                                              self.parent.output_path,
                                              template_folder,
                                              self.parent.project_name,
                                              self.parent.architecture)
        except FileNotFoundError as e:
            raise RuntimeError(f"Template not found: {e}")
+1 −1
Original line number Diff line number Diff line
@@ -336,7 +336,7 @@ def search_log_file_reverse(file_path, search_text):
if __name__ == "__main__":
    
    file_path = '../../../methods/modelica/TemplatesCSM/Templates/Structure.mo'
    file_path = r'E:\ExaDigiT\AutoCSM\examples\modelica\GenericDatacenter\Systems\Datacenter\Systems\CoolingBlock\Systems\Cabinet\Sources\v0.mo'
    file_path = r'../../../examples/modelica/GenericDatacenter/Systems/Datacenter/Systems/CoolingBlock/Systems/Cabinet/Sources/v0.mo'
    parameters = get_variable_by_type(file_path, 'input')
    print(parameters)