How can I remove the MDLREF_HIDE_CHILD define?

11 views (last 30 days)
I want to generate code from a model that includes a referenced model. In the "topmodel.h" file the following code appears:
#define refmodel_MDLREF_HIDE_CHILD_
#include "refmodel.h"
In the "refmodel.h" file the following code is generated (this is only a partial excerpt as needed for the question):
#ifndef refmodel_MDLREF_HIDE_CHILD_
typedef struct {
...
} DW_refmodel_fwu4_T;
extern DW_refmodel_fwu4_T refmodel_DW;
#endif
I have custom code that wraps the generated code and that needs to access "refmodel_DW". Therefore, I need to remove "#define refmodel_MDLREF_HIDE_CHILD_" from the "topmodel.h" file. Ovviously I can manually (or with a script) remove the line after the code has been generated, but is there a setting in the model configuration to prevent this line being generated in the first place?
  2 Comments
Bence Béres
Bence Béres on 31 Jan 2019
Hello Marc, I experienced the same issue, and I would like to ask if you've found a solution yet.
Thank you for your reply in advance!
Marc Welsch
Marc Welsch on 31 Jan 2019
Hello Bence,
according to Mathworks this directive is inevitably linked to the 'Total Number of Instances Allowed per Top Model' setting (see quote below). As I could not change the setting to either 'Zero' or 'Multiple' for other reasons, I ended up "manually" deleting the directive via my code generation script after the header file was created. So far it seems to have no other side effects.
Best regards,
Marc
The #define <modelName>MDLREF_HIDE_CHILD_ directive is appended to the model reference name when the 'Total Number of Instances Allowed per Top Model' option is set to 'One'. This option can be changed to 'Zero' or 'Multiple' and that directive will disappear. The option can be found in configuration parameters >> Model Referencing >> Options for Referencing this model.
Note that changing a model to have the 'Total Number of Instances Allowed per Top Model' to 'Multiple' eliminates the flag, but it may cause other errors if global storage classes are used. More specifically, it would be a conflict with global storage classes and allowing multiple instances of the reference model.

Sign in to comment.

Answers (2)

Halil Aydogus
Halil Aydogus on 26 May 2019
Edited: Halil Aydogus on 27 May 2019
I had the same issue and found a solution by which I can change the macro defined in the file "topmodel.h". Removing its definition from this file does not seem to be possible but changing the name of it would give the same effect.
In your system target file (*.tlc file), you can change HideChildDefineSymbol if the model being processed is a referenced model using the following function which utilizes some undocumented functions of the RTW. It gets the model reference interface which is stored in a MAT file, adds a postfix string "_MY_CUSTOM_POSTFIX_" to the define symbol used for this referenced model and then caches back the manipulated interface information to the MAT file again. The information stored in this MAT file will later be used in the code generation process of the parent model.
%function FcnModifyHideChildDefineSymbol() void
%assign buildStartDir = FEVAL("rtwprivate","rtwattic","getStartDir")
%assign blkInterface = LoadModelrefInterfaceInMatInfoFile(Name, buildStartDir)
%if ISFIELD(blkInterface, "HideChildDefineSymbol")
%if !ISEMPTY(blkInterface.HideChildDefineSymbol)
%copyrecord deepCopiedModelInterface blkInterface
%assign deepCopiedModelInterface.HideChildDefineSymbol = "%<deepCopiedModelInterface.HideChildDefineSymbol>_MY_CUSTOM_POSTFIX_"
%<CacheModelrefInterfaceInMatInfoFile(Name, "addInterface", deepCopiedModelInterface)>
%endif
%endif
%endfunction
The define used in the file "refmodel.h" won't change:
#ifndef refmodel_MDLREF_HIDE_CHILD_
typedef struct {
...
} DW_refmodel_fwu4_T;
extern DW_refmodel_fwu4_T refmodel_DW;
#endif
but the directive which is defined in the file "topmodel.h" will look like:
#define refmodel_MDLREF_HIDE_CHILD__MY_CUSTOM_POSTFIX_
#include "refmodel.h"
Since refmodel_MDLREF_HIDE_CHILD_ is not defined, you will be able to get the objects that you want to access.
In case you don't know how to check if the model being processed in the system target file is a referenced model, use the following condition:
%% Modify the HideChildDefineSymbol for referenced models
%if IsModelReferenceTarget()
%<FcnModifyHideChildDefineSymbol()>
%endif

Wei Jiang
Wei Jiang on 18 Oct 2023
Hi Marc,
All _MDLREF_HIDE_CHILD_ macros are removed since MATLAB R2023b.
Generally, the guarded content in generated code will now be in modelName_private.h file if it exists, or be in modelName.g file if private file does not exist.
Hope this answer helps.
Regards,
Wei Jiang

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!