Skip to content
Snippets Groups Projects
Commit 7cf0d1e1 authored by André Fugmann's avatar André Fugmann
Browse files

Update visual to text and text to visual generation

Updated the methods for visual->text and text->visual generations to now
include the latest SOIL features (except semantics). Also updated the soil.jar
to a newer version.
parent 0591f6f3
Branches
No related tags found
No related merge requests found
No preview for this file type
...@@ -268,24 +268,31 @@ async def translate_to_visual(text_models: Dict, background_tasks: BackgroundTas ...@@ -268,24 +268,31 @@ async def translate_to_visual(text_models: Dict, background_tasks: BackgroundTas
with open(f'{file_path}.soil', 'w') as file: with open(f'{file_path}.soil', 'w') as file:
file.write(file_content["textModel"]) 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 # create a background task to delete all files AFTER the response have been returned
background_tasks.add_task(clean_up_generation, identifier) background_tasks.add_task(clean_up_generation, identifier)
# Execute monticore # Execute monticore
for file in files: command = f'java -jar ../resources/soil.jar soil.MainSoilTool -t visual -i {os.path.join(in_path, main_file)}.soil -d {out_path}'
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='.') 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 # Read the generated visual representation from the generated file
results_dict = {} results_dict = {}
for folder in os.listdir(out_path): # for folder in os.listdir(os.path.join(out_path, main_file)):
file_path = os.path.join(out_path, folder, f'{folder}.json') # 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: with open(file_path, 'r') as f:
file_contents = json.load(f) file_contents = json.load(f)
results_dict[folder] = file_contents results_dict[model] = file_contents
# Return the Results # Return the Results
print(results_dict) print(results_dict)
......
...@@ -37,17 +37,33 @@ def events_to_text(events: List[Dict]) -> str: ...@@ -37,17 +37,33 @@ def events_to_text(events: List[Dict]) -> str:
return output 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 = "" temp_text = ""
custom_descriptions = {}
custom_names = {}
for child_component in child_components: for child_component in child_components:
if "constant" in child_component and child_component["constant"]: if "constant" in child_component and child_component["constant"]:
temp_text += " 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"]: elif "dynamic" in child_component and child_component["dynamic"]:
temp_text += " dynamic " temp_text += " dynamic "
else: else:
temp_text += " " temp_text += " "
element_name = get_element_type_name(child_component["value"], filename, files) 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): # 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)[ # temp_text += get_element_in_visual_model_by_uuid(child_component["value"], visual_model)[
# "isImport"] + "." # "isImport"] + "."
...@@ -55,11 +71,13 @@ def child_components_to_text(child_components: List[Dict[str, str]], filename: s ...@@ -55,11 +71,13 @@ def child_components_to_text(child_components: List[Dict[str, str]], filename: s
# " ", "") + " " + child_component["name"] + "\n" # " ", "") + " " + child_component["name"] + "\n"
# else: # else:
# temp_text += "Undefined " + child_component["name"] + "\n" # temp_text += "Undefined " + child_component["name"] + "\n"
return temp_text return temp_text, custom_names, custom_descriptions
# Converts an element to text # Converts an element to text
def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any]) -> str: 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(" ", "") + " " temp_output = element["elementType"] + " " + element["name"].replace(" ", "") + " "
if element['elementType'] == 'component' and 'baseComponent' in element: if element['elementType'] == 'component' and 'baseComponent' in element:
temp_output += "extends " + get_element_type_name(element["baseComponent"], filename, files) + " " 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 ...@@ -80,7 +98,10 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any
continue continue
elif key in ["arguments", "returns", "components", "parameters", "functions", "measurements"]: elif key in ["arguments", "returns", "components", "parameters", "functions", "measurements"]:
if len(element[key]): 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"]: elif key in ["name", "description"]:
temp_output += " " + key + ": \"" + str(element[key]) + "\"\n" temp_output += " " + key + ": \"" + str(element[key]) + "\"\n"
elif key == "events": elif key == "events":
...@@ -101,6 +122,11 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any ...@@ -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" temp_output += " " + key + ": " + str(element[key]).lower() + "\n"
else: else:
temp_output += " " + key + ": " + str(element[key]) + "\n" 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" return temp_output + "}\n\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment