xxsimInsertSubmodel

PURPOSE ^

xxsimInsertSubmodel - Insert a new submodel from file

SYNOPSIS ^

function [result] = xxsimInsertSubmodel(submodelName, fileName, position_x, position_y, varargin)

DESCRIPTION ^

 xxsimInsertSubmodel - Insert a new submodel from file

 Syntax:
   result = xxsimInsertSubmodel(submodelName, fileName, position_x, position_y, implementation)

 Inputs:
   submodelName =   the hierachical submodel name
   fileName =       path to the model with which the submodel should be replaced
   position_x =     x-position of the new submodel
   position_y =     y-position of the new submodel
   implementation = the implementation that should be made active when
                    the stored submodel has multiple implementations
                    (optional)

 Outputs:
   result = boolean indicating the success.

 Examples:
   result = xxsimInsertSubmodel('mysubmodel', 'C:\temp\mysubmodel.emx', 200, 200);
   result = xxsimInsertSubmodel('mysubmodel', 'C:\temp\mysubmodel.emx', 200, 200, 'mysubmodel implementation');

 Author: Controllab Products B.V.
 e-mail: info@controllab.nl
 Website: https://www.controllab.nl
 December 2021

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [result] = xxsimInsertSubmodel(submodelName, fileName, position_x, position_y, varargin)
0002 % xxsimInsertSubmodel - Insert a new submodel from file
0003 %
0004 % Syntax:
0005 %   result = xxsimInsertSubmodel(submodelName, fileName, position_x, position_y, implementation)
0006 %
0007 % Inputs:
0008 %   submodelName =   the hierachical submodel name
0009 %   fileName =       path to the model with which the submodel should be replaced
0010 %   position_x =     x-position of the new submodel
0011 %   position_y =     y-position of the new submodel
0012 %   implementation = the implementation that should be made active when
0013 %                    the stored submodel has multiple implementations
0014 %                    (optional)
0015 %
0016 % Outputs:
0017 %   result = boolean indicating the success.
0018 %
0019 % Examples:
0020 %   result = xxsimInsertSubmodel('mysubmodel', 'C:\temp\mysubmodel.emx', 200, 200);
0021 %   result = xxsimInsertSubmodel('mysubmodel', 'C:\temp\mysubmodel.emx', 200, 200, 'mysubmodel implementation');
0022 %
0023 % Author: Controllab Products B.V.
0024 % e-mail: info@controllab.nl
0025 % Website: https://www.controllab.nl
0026 % December 2021
0027 
0028 %------------- BEGIN CODE --------------
0029     %check input arguments
0030     if (nargin < 4)
0031         error('This function expects 4 or 5 input arguments: submodelName, fileName, position_x, position_y and implementation and implementation (optional).');    
0032     end
0033 
0034     implementation = '';
0035     
0036     if (length(varargin) > 1)
0037         error('This function expects 4 or 5 input arguments: submodelName, fileName, position_x, position_y and implementation and implementation (optional).');
0038     else
0039         if length(varargin)>=1
0040             if ~ischar(varargin{1})
0041                 error('Input argument 5 (implementation) should be the name of the implementation (string).');
0042             else
0043                 implementation = varargin{1};
0044             end
0045         end
0046     end
0047 
0048     if ~ischar(submodelName)
0049         error('Input argument submodelName should be the submodel name (string).');
0050     end
0051     if ~ischar(fileName)
0052         error('Input argument fileName should contain a valid filename (string).');
0053     end
0054 
0055     position = struct('x', int32(position_x), 'y', int32(position_y));
0056     inputs = struct('submodelName', submodelName, 'fileName', fileName, 'implementation', implementation, 'position', position);
0057     reply = xrlinvoke('xxsim.model.insertSubmodel', inputs);
0058     if (isempty(reply) )
0059         result = false;
0060         error('could not insert the submodel');
0061     end
0062 
0063     % return the success
0064     result = true;
0065 end
0066 %------------- END OF CODE --------------

Generated on Thu 25-Apr-2024 10:30:24