MantisBT - Community
View Issue Details
0024925Community[OCCT] OCCT:Application Frameworkpublic2014-05-14 20:052016-06-23 09:30
Roman Lygin 
normalintegration request 
[OCCT] 6.7.1 
[OCCT] 6.8.0[OCCT] 6.8.0 
bugs caf(015) bug24925
0024925: Enabling OCAF persistence without setting environment variables
Currently in order to enable OCAF persistence there must be a few variables defined and resource files supplied. These includes:
- the Plugin file and the CSF_PluginDefaults variable.
- the <AppFormat> file and the CSF_<AppFormat>Defaults variable, where <AppFormat> is the value returned by Resources() method (re-)defined in the subclass of TDocStd_Application.
This creates inconvenience and fragility when redistributing the
OCC-based solutions: end-user applications and especially libraries.

The modifications below allow to remove this need by providing respective API. Current behavior is preserved. Moreover environment variables and external files will override API-based values.

Details are below:
1. Eliminated need in FWOSPlugin library and respective entrance in the Plugin file.
   If the entry for plugin a148e300-5740-11d1-a904-080036aaa103 is not provided the driver will be defaulted to CDF_FWOSDriver (which has been moved from FWOSDriver package). FWOSPlugin is retained but is reduced in size (moving FWOSDriver_Driver into CDF). Possible next step is to remove FWOSPlugin altogether.
2. TDocStd_Application subclasses may define Resources() method to return an empty string, and instead directly set up the myResources resource manager which is now made protected in TDocStd_Application.
3. The Plugin::Load() method can now consult Plugin::AdditionalPluginMap() if it cannot find the plugin using the Plugin file. This global map can be populated from inside user's code.
   Plugin::Load() now accepts an additional boolean parameter theVerbose to suppress errors sent to std::cout. The default value is true to preserve current behavior.
   CDF_Session::LoadDriver() specifies false when trying to load the metadata driver.
The test sample demonstrates how to enable XML persistence using the API-only approach.
No tags attached.
related to 0009457closed ski Community Avoid usage of environment variables 
parent of 0025173closed bugmaster Community VS 2012: linker errors 
related to 0024895closed bugmaster Community 'PLUGINFACTORY' has C-linkage specified, but returns user-defined type 'Handle_Standard_Transient' which is incompatible with C 
related to 0025812closed abv Open CASCADE Replace dynamic loading mechanism of OCAF persistence with dynamic-link one 
cxx OCCXDETestLib_OCC_excerpt.cxx (3,965) 2014-05-14 20:09
Issue History
2014-05-14 20:05Roman LyginNew Issue
2014-05-14 20:05Roman LyginAssigned To => szy
2014-05-14 20:09Roman LyginFile Added: OCCXDETestLib_OCC_excerpt.cxx
2014-05-14 20:19Roman LyginNote Added: 0029338
2014-05-14 20:19Roman LyginStatusnew => resolved
2014-05-14 23:49Roman LyginRelationship addedrelated to 0009457
2014-06-09 17:55szyNote Added: 0029753
2014-06-09 17:55szyAssigned Toszy => mkv
2014-06-09 17:55szyStatusresolved => reviewed
2014-06-09 18:38apnNote Added: 0029755
2014-06-09 18:39apnAssigned Tomkv => Roman Lygin
2014-06-09 18:39apnStatusreviewed => assigned
2014-06-18 12:27Roman LyginNote Added: 0029810
2014-06-18 12:27Roman LyginAssigned ToRoman Lygin => apn
2014-06-18 12:27Roman LyginStatusassigned => resolved
2014-06-18 12:31apnStatusresolved => reviewed
2014-06-18 14:00mkvAssigned Toapn => mkv
2014-06-23 11:14mkvAssigned Tomkv => apv
2014-06-25 12:36kgvNote Added: 0029878
2014-06-25 19:53mkvNote Added: 0029884
2014-06-25 19:54mkvNote Added: 0029885
2014-06-25 19:55mkvTest case number => bugs caf(015) bug24925
2014-06-25 19:55mkvAssigned Toapv => abv
2014-06-25 19:55mkvStatusreviewed => feedback
2014-07-07 09:49abvNote Added: 0029975
2014-07-07 09:49abvAssigned Toabv => mkv
2014-07-08 08:53mkvNote Added: 0029992
2014-07-08 08:53mkvAssigned Tomkv => bugmaster
2014-07-08 08:53mkvStatusfeedback => tested
2014-07-08 10:08Roman LyginNote Added: 0029994
2014-07-11 14:22apnChangeset attached => occt master b6c0b841
2014-07-11 14:22apnAssigned Tobugmaster => apn
2014-07-11 14:22apnStatustested => verified
2014-07-11 14:22apnResolutionopen => fixed
2014-07-12 12:17kgvRelationship addedrelated to 0024895
2014-07-22 16:18gitNote Added: 0030338
2014-07-22 16:18gitNote Added: 0030339
2014-08-20 17:25PawelRelationship addedparent of 0025173
2014-10-15 15:39Roman LyginNote Added: 0033142
2014-11-11 12:44aivFixed in Version => 6.8.0
2014-11-11 12:59aivStatusverified => closed
2016-04-25 21:59abvRelationship addedrelated to 0027401
2016-06-23 09:30abvRelationship addedrelated to 0025812

Roman Lygin   
2014-05-14 20:19   
The fix has been pushed to git.
Integration requested for 6.8.0. The target version is set respectively.
2014-06-09 17:55   
To be tested.
2014-06-09 18:38   
Could you please rebase CR24925 to current state of master.
Roman Lygin   
2014-06-18 12:27   
Rebased to the master of 06/17/14.
The remote branch renamed with CR24925_1.
2014-06-25 12:36   
Dear apv,

test case bugs/caf/bug24925 using new command OCC24925 has been pushed to branch CR24925_1.
The test is based on attached file OCCXDETestLib_OCC_excerpt.cxx with following changes:
- Standard TKXml plugin is used instead of custom plugin.
- Test case corrupt CSF_PluginDefaults environment variable to prevent default Plugin file loading (containing TKXml definition).
2014-06-25 19:53   
Dear BugMaster,

Branch CR24925_1 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
SHA-1: 1581699154adcd080d39d451c41a093b022ab66d

Number of compiler warnings:

occt component :
Linux: 16 (16 on master)
Windows: 0 (0 on master)
MacOS: 200 (203 on master)

products component :
Linux: 11 (11 on master)
Windows: 2 (2 on master)

No regressions/differences

Testing cases:
http://occt-tests/CR24925-1-master-occt/Debian60-64/bugs/caf/bug24925.html [^]
http://occt-tests/CR24925-1-master-occt/Windows-32-VC9/bugs/caf/bug24925.html [^]
bugs caf(015) bug24925: OK

Testing on Linux:
Total MEMORY difference: 348470736 / 348657500
Total CPU difference: 50404.65000000001 / 51365.58000000003

Testing on Windows:
Total MEMORY difference: 376318216 / 376769996
Total CPU difference: 43594.78125 / 38728.28125

There are no differences in images found by testdiff.
2014-06-25 19:54   
Dear abv,
could you please review new OCC24925 draw command.
2014-07-07 09:49   
The DRAW command looks OK to me.

@Roman: I have a few general comments / questions to the issue (sorry for being late):

a) The whole approach with plugins loaded via resource files is redundant: it should be easier to link directly to required libs. The overall refactoring is planned.

b) Instead of playing with your own resource managers, why not just set environment variables expected by OCAF programmatically?
2014-07-08 08:53   
Dear BugMaster,

Branch CR24925_1 from occt git-repository (and master from products git-repository) was rebased on current master, recompiled and retested.
SHA-1: 71108305a89b314feb6575c574d9aa1178ede439
Roman Lygin   
2014-07-08 10:08   
Hi Andrey,

Thanks for your comments.

a). Certainly, feel free to refactor the overall mechanism per your plan. The current modification is just a minor relief within the current paradigm. The plugin-based approach is flexible and has multiple advantages over direct linking, e.g. reduced list of required libraries, smaller memory footprint, etc.
For instance, for persistence-less OCAF-based applications direct linking with all persistence flavors would just be an overkill. Also without plugin-based approach enabling user-defined persistence becomes awkward to implement.
So unless I am missing something, the plugin-based architecture is rather to stay. I am open to discussion, of course.

b). The whole idea of this modification is to enable fully API based approach to overcome the need of having environment variable and resource files (although compatibility and prevailing of the current mechanism is preserved). For the library vendors (like CAD Exchanger) it is virtually impossible to reliably set environment variables - there is no control over the application vendor or end-user environment, it is impossible to even compute relative path of the resource file (e.g. Plugin) from the library the call is made from, using some temporary directory to generate temporary Plugin file is fragile, etc.

IMHO the long-term objective should be to enable all settings via API and optionally have environment variables as an extra option to redefine API-set values. For instance, the OpenMP library is a good example of this two-fold approach - the number of threads will be automatically computed upon library initialization, optionally using omp_set_num_threads() you can explicitly specify that value, the optional OMP_NUM_THREADS environment variable will redefine that.

Thus, it would be very convenient to have OCC-based libraries/applications running out of the box without a need to have any single env var set. Whatever is required must be precomputed on the fly, or set via optional API, or redefined via optional env vars.

2014-07-22 16:18   
Branch CR24925 has been deleted by inv.

SHA-1: fb9510735031a1ea8ac41409e700762951126335
2014-07-22 16:18   
Branch CR24925_1 has been deleted by inv.

SHA-1: 71108305a89b314feb6575c574d9aa1178ede439
Roman Lygin   
2014-10-15 15:39   
Verified in 6.8.0 beta.