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     % set the result varaible
0056     result = true;
0057 
0058     position = struct(
0059             'x', int32(position_x),
0060             'y', int32(position_y)
0061     );
0062     inputs = struct(
0063         'submodelName', submodelName,
0064         'fileName', fileName,
0065         'implementation', implementation,
0066         'position', position
0067     );
0068     reply = xrlinvoke('xxsim.model.insertSubmodel', inputs);
0069     if (length(reply) == 0 )
0070         error('could not insert the submodel');
0071         result = false;
0072     end
0073 
0074     % return the success
0075     result = true;
0076 end
0077 %------------- END OF CODE --------------

Generated on Thu 06-Jan-2022 15:23:22