diff --git a/resources/soil.jar b/resources/soil.jar index 3b253c9d8a23a9768c725ba13067d4002ce49f2b..7e57a146617506dbedcad87a6f6d21894c8d592d 100644 Binary files a/resources/soil.jar and b/resources/soil.jar differ diff --git a/src/main.py b/src/main.py index 0daf068b66f237e95d09368920ffd8234681fefc..f3ef87cc7114dd1a1ba72ecc7a7a02ba90b0578e 100644 --- a/src/main.py +++ b/src/main.py @@ -268,24 +268,31 @@ async def translate_to_visual(text_models: Dict, background_tasks: BackgroundTas with open(f'{file_path}.soil', 'w') as file: file.write(file_content["textModel"]) - print(in_path) - print(out_path) - # create a background task to delete all files AFTER the response have been returned background_tasks.add_task(clean_up_generation, identifier) # Execute monticore - for file in files: - command = f'java -jar ../resources/soil.jar soil.MainSoilTool -t visual -i {file}.soil -d {out_path}' - result = subprocess.run(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd='.') + command = f'java -jar ../resources/soil.jar soil.MainSoilTool -t visual -i {os.path.join(in_path, main_file)}.soil -d {out_path}' + result = subprocess.run(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd='.') + print('Stdout of generation process:') + print(result.stdout.decode('utf-8')) + print('Stderr of generation process:') + print(result.stderr.decode('utf-8')) + # Read the generated visual representation from the generated file results_dict = {} - for folder in os.listdir(out_path): - file_path = os.path.join(out_path, folder, f'{folder}.json') + # for folder in os.listdir(os.path.join(out_path, main_file)): + # file_path = os.path.join(out_path, folder, f'{folder}.json') + # with open(file_path, 'r') as f: + # file_contents = json.load(f) + # results_dict[folder] = file_contents + + for model in text_models.keys(): + file_path = os.path.join(out_path, main_file, f'{model}.json') with open(file_path, 'r') as f: file_contents = json.load(f) - results_dict[folder] = file_contents + results_dict[model] = file_contents # Return the Results print(results_dict) diff --git a/src/translate.py b/src/translate.py index f6b05456d977d1fc68be3423bad3929eb5f7a018..4c3d39b345a17e25522287ead90071aaf670f839 100644 --- a/src/translate.py +++ b/src/translate.py @@ -37,17 +37,33 @@ def events_to_text(events: List[Dict]) -> str: return output -def child_components_to_text(child_components: List[Dict[str, str]], filename: str, files: dict[str, any]) -> str: +def child_components_to_text(child_components: List[Dict[str, str]], filename: str, files: dict[str, any]) -> (str, dict[str, str], dict[str, str]): temp_text = "" + custom_descriptions = {} + custom_names = {} for child_component in child_components: if "constant" in child_component and child_component["constant"]: temp_text += " constant " + elif "internal" in child_component and child_component["internal"]: + temp_text += " internal " elif "dynamic" in child_component and child_component["dynamic"]: temp_text += " dynamic " else: temp_text += " " element_name = get_element_type_name(child_component["value"], filename, files) - temp_text += f'{element_name} {child_component["name"]}\n' + temp_text += f'{element_name} {child_component["name"]}' + + if "initialValue" in child_component: + if child_component["initialValue"] != "": + temp_text += f' = {child_component["initialValue"]}' + + if "description" in child_component: + custom_descriptions[child_component["name"]] = child_component["description"] + + if "customName" in child_component: + custom_names[child_component["name"]] = child_component["customName"] + + temp_text += '\n' # if "isImport" in get_element_in_visual_model_by_uuid(child_component["value"], visual_model): # temp_text += get_element_in_visual_model_by_uuid(child_component["value"], visual_model)[ # "isImport"] + "." @@ -55,11 +71,13 @@ def child_components_to_text(child_components: List[Dict[str, str]], filename: s # " ", "") + " " + child_component["name"] + "\n" # else: # temp_text += "Undefined " + child_component["name"] + "\n" - return temp_text + return temp_text, custom_names, custom_descriptions # Converts an element to text def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any]) -> str: + custom_names = {} + custom_descriptions = {} temp_output = element["elementType"] + " " + element["name"].replace(" ", "") + " " if element['elementType'] == 'component' and 'baseComponent' in element: temp_output += "extends " + get_element_type_name(element["baseComponent"], filename, files) + " " @@ -80,7 +98,10 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any continue elif key in ["arguments", "returns", "components", "parameters", "functions", "measurements"]: if len(element[key]): - temp_output += " " + key + ":\n" + child_components_to_text(element[key], filename, files) + child_components_text, custom_names_p, custom_descriptions_p = child_components_to_text(element[key], filename, files) + temp_output += " " + key + ":\n" + child_components_text + custom_names.update(custom_names_p) + custom_descriptions.update(custom_descriptions_p) elif key in ["name", "description"]: temp_output += " " + key + ": \"" + str(element[key]) + "\"\n" elif key == "events": @@ -101,6 +122,11 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any temp_output += " " + key + ": " + str(element[key]).lower() + "\n" else: temp_output += " " + key + ": " + str(element[key]) + "\n" + for variable, custom_name in custom_names.items(): + temp_output += " " + variable + '.name = "' + custom_name + '"\n' + + for variable, custom_description in custom_descriptions.items(): + temp_output += " " + variable + '.description = "' + custom_description + '"\n' return temp_output + "}\n\n"