Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions DEVSMap_to_Cadmium_Parser/generate_coupled_model_hpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,44 @@ def include_component_models(coupled_model):
components = get_components(coupled_model)
include_statements = ""
for component in components:
include_statements += '#include "' + component["model"].lower() + '.hpp"\n'
model_name = str(component.get("model", "")).strip()
is_library = bool(component.get("is_library")) or model_name.startswith("lib::")
header = component.get("header")

if is_library and header:
include_statements += f'#include <{header}>\n'
elif not is_library and not model_name.startswith("lib::"):
include_statements += '#include "' + model_name.lower() + '.hpp"\n'
include_statements += '\n'
return include_statements


def serialize_constructor_args(component):
'''
Normalizes constructor arguments from the DEVSMap element into a list of C++-ready expressions.
'''
raw_args = component.get("args", [])

if isinstance(raw_args, str):
raw_args = [raw_args]

if not isinstance(raw_args, list):
return []

serialized = []
for arg in raw_args:
if arg is None:
continue
value = str(arg).strip()
if value == "":
continue
if value.startswith(('"', "'", "{", "[", "(", "std::", "true", "false")):
serialized.append(value)
else:
serialized.append('"' + value + '"')
return serialized


def normalize_cpp_type(data_type):
'''
Returns the appropriate C++ datatype for Cadmium port declarations.
Expand Down Expand Up @@ -251,7 +284,12 @@ def generate_coupled_model_struct(model_name, model):
for component in components:
component_model_name = component["model"]
model_id = component["id"]
component_statements += ('\t\tauto ' + model_id +' = addComponent<' + component_model_name +'>("' + model_id + '");\n')
extra_args = serialize_constructor_args(component)
if extra_args:
args_str = ", " + ", ".join(extra_args)
else:
args_str = ""
component_statements += ('\t\tauto ' + model_id +' = addComponent<' + component_model_name +'>("' + model_id + '"' + args_str + ');\n')
constructor += component_statements + '\n'

# addCoupling statements
Expand Down
24 changes: 20 additions & 4 deletions GUI/js/conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,26 @@ export class ConversionManager {

// convert internal component_id -> exported id
if (Array.isArray(modelCopy.components)) {
modelCopy.components = modelCopy.components.map(c => ({
model: c.model,
id: c.component_id ?? c.id
}));
modelCopy.components = modelCopy.components.map(c => {
const component = {
model: c.model,
id: c.component_id ?? c.id
};

if (Array.isArray(c.args) && c.args.length > 0) {
component.args = c.args;
}

if (c.is_library) {
component.is_library = true;
}

if (c.header) {
component.header = c.header;
}

return component;
});
}

return {
Expand Down
Loading