Software management of model files
Working with models
Creating a new model
The public method create is used.
Use the following code to create a model in Engee:
model = "model_name"
engee.create(model)
The code initialises a model variable with the value "model_name", after accessing it via engee.create the Model object is returned and the model is created. You can also create a model in another way:
engee.create("model_name")
Here, the name for the model is immediately passed as a string (data type String) and does not require the variable to be initialised beforehand.
Thus, based on the above code:
-
A model is created with
model_nameand parameters by default. -
The model becomes the current model. Its root system becomes the current system.
The model name ( model_name) must not contain the character /.
Errors.
If a model with this name already exists, throws a ModelAlreadyExistsException exception.
Output
engee.create("model_name")
"Model(model_name)"
Loading a model from a file
The public method load is used
engee.load(file_path; force = false)
-
Loads a model from a file with extension
.engeelocated in thefile_pathpath. -
Returns an object of type
Model. -
The model becomes the current model. Its root system becomes the current system.
Errors.
-
If a model with this name already exists and the parameters
force = true, then reloads it and any changes not previously saved will be lost, ifforce = falsethen throws aModelAlreadyExistsExceptionexception. By default,force = false. -
If the file has an invalid extension, it throws the
InvalidFileExtensionexception. -
If such a file does not exist, throws the
FileNotFoundexception.
Output
engee.load("NewModel.engee"; force = true)
Model(NewModel)
Opening a previously used model
The public method open is used
engee.open(model_name)
engee.open(path)
engee.open(model)
engee.open(system)
-
If
model_nameof a previously opened model is specified in the parameters, it becomes the current model. Its root system becomes the current system. Returns aModelobject. -
Returns the open
System. -
If a path to an existing system
system_pathis specified in the parameters, the model containing it becomes the current model, and the system itself becomes the current system that is displayed in the visual editor. Returns aSystemobject. -
It is also possible to pass directly an instance of
ModelorSysteminstead of the path.
Errors.
-
If the model does not exist, throws a
ModelDoesntExistExceptionexception. -
If the system does not exist, throws a
SystemIsNotExistExceptionexception.
Output
# open model:
m1 = engee.open("NewModel")
Model(NewModel)
engee.gcm(), engee.gcs()
(Model(NewModel), System(root))
# open system:
engee.open("AnotherModel/Subsystem-1")
System(Subsystem-1)
engee.gcm(), engee.gcs()
(Model(AnotherModel), System(Subsystem-1))
Referring to the open current model
The public method gcm is used.
engee.get_current_model()
engee.gcm()
-
Returns the current active model.
Opening the current system (model and subsystem)
Uses the public method gcs.
engee.get_current_system()
engee.gcs()
-
Returns the current active system.
Errors
-
If the current system does not exist, throws a
NoModelOpenedExceptionexception.
Viewing the list of open models
Uses the public method get_all_models.
engee.get_all_models(; sorted=true)
-
Returns a list of models open in the current session as
Vector{Model}. -
If the parameters
sorted=truethen sorts the models by name, ifsorted=falsethe models are output in order of opening. By defaultsorted=true.
Check for unsaved changes
Before editing a model, open it using the open method. After editing, don’t forget to save the results with save.
To check for unsaved changes use the public method is_dirty.
engee.is_dirty(model)
-
Checks if there are any unsaved changes to the model. Returns
trueif there are unsaved changes, otherwise returnsfalse. -
If the model is already closed, returns
false.
Saving the model to a file
The public method save is used.
engee.save(model_name, file_path; force = false)
engee.save(model, file_path; force = false)
-
Saves the model named
model_nameto the pathfile_pathin a file with extension.engee. -
Intermediate directories are created if necessary.
-
Returns
nothing.
Errors.
-
If the file already exists and the parameters
force = true, overwrites it, ifforce = false, it terminates with aFileAlreadyExistserror.
By default, force = false.
Closing the model
The public method close is used.
engee.close(model_name; force = false)
engee.close(model; force = false)
engee.close(; force = false)
-
Closes the model with the name
model_namein the visual editor (deletes it from the session). -
The model opened in the visual editor tab to the left becomes the current model.
-
Returns
Model. -
If no model is specified, closes the current model. If no current model is specified, does nothing.
-
If model is closed, does nothing.
Errors.
-
If there are unsaved changes and the parameters
force=false, it terminates with anUnsavedModelExceptionerror, ifforce=true, the unsaved changes will be lost.
| All public methods of programme management available in Engee are provided in the article Public methods of program management. |
Examples
engee.create("newmodel_1") # creates a model named newmodel_1
engee.load("/user/newmodel_1.engee"; force = true) # forcibly loads a model named newmodel_1 using the specified path.
engee.gcm() # returns the currently active model
engee.gcs() # returns the currently active system
engee.get_all_models(; sorted=true) # retrieves the list of models opened in the current session and sorts them by name
engee.is_dirty("newmodel_1") # checks if there are unsaved changes, if it outputs true after executing the command, then there are unsaved changes.
engee.open("newmodel_1") # returns the open system system and makes the model named newmodel_1 the current model, which can be specified via the model path.
engee.save("newmodel_1", "/user/newmodel_2.engee") # saves the newmodel_1 model as the newmodel_2 model in the specified path
engee.close("newmodel_1") # closes the model named newmodel_1 (deletes it from the session)