How can I remove the MDLREF_HIDE_CHILD define?
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
Bence Béres
2019-1-31
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!
回答(2 个)
Halil Aydogus
2019-5-26
编辑:Halil Aydogus
2019-5-27
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
0 个评论
Wei Jiang
2023-10-18
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!