WRAPPER_API bool LoadFile(const BmgChar *fileName, bool readOnly = false,
const BmgChar* customFileName = 0, const BmgChar* changeLog = 0, const BmgChar* customChangeLog = 0);
WRAPPER_API bool LoadFile(const BmgChar *fileName, const BmgChar* viewFileName, bool readOnly,
const BmgChar* customFileName, const BmgChar* changeLog, const BmgChar* customChangeLog, const BmgChar* defaultViewFile);
WRAPPER_API bool LoadFile(const BmgChar *fileName, const DataView& dataView, bool readOnly,
const BmgChar* customFileName, const BmgChar* changeLog, const BmgChar* customChangeLog);
The LoadFile methods load a base data source file into the DataSource. If the specified file cannot be found, a GeoCalcException will be thrown with an ErrorCode specifying XercesParseError.
The first version of this method preserves the behavior in past releases by defaulting the newer parameters. If you call LoadFile and provide only the datasource xml file, you will get behavior matching that in past releases. Users will be able to add, remove, move, rename, or edit objects in the base datasource, as they have been able to do in the past. Any brand new objects will be added to the base datasource file.
The readOnly parameter indicates whether the base datasource can be edited. In the case of the backwards-compatible version of LoadFile this parameter defaults to false. It is recommended, however, that the readOnly parameter be set to true to indicate that the user may not add, remove, move, rename or edit objects in the base datasource. This will ensure that standard object definitions will not be altered.
The GeoCalc library has been enhanced to support the use of a new "custom" datasource which is loaded on top of the base datasource, in order to provide more flexibility to users, and to ensure that standard data objects can be protected against inadvertent changes. In order to make use of this functionality, the customFileName should be set to refer to the desired xml filename. If this custom file does not already exist, it will be created when and if the data source is later saved via CommitToFile. Note that the custom data source file does not need to contain fully defined objects. For example, if a user has created a custom point style based on radians, the custom file will contain the new custom point style, but does not need to contain another definition of radians. It will rely on the base datasource to define radians. During the load, any objects in the custom file that were already loaded from the base file will be ignored.
In the case of the backwards-compatible version of LoadFile the customFileName parameter defaults to an empty string, to preserve the behavior in past releases, in which all data is loaded from and stored in a single xml file. It is recommended, however, that a datasource be used, and that the base datasource be locked as described above. If this protocol is employed, then during future upgrades users may simply replace the base geodata.xml data source file with the newest version, without fear of losing custom data.
The GeoCalc library has additionally been enhanced to support the use of a new "view" file which contains the presentation information for the display of objects in dialogs. This provides users the ability to hide and reorganize objects, and to specify display names, without altering the actual datasource file. This also means there could be several different views employed that could then be used as filters so that different users are restricted to different sets of objects. A view file is distinguished by the ".xvw" extension. Users may either specify the view file itself during the LoadFile, or they may load (or create) the view independently and then pass it into the LoadFile call. If the specified view does not exist yet, a default will be created and saved during the CommitToFile. If no view is specified, we will first attempt to find an ".xvw" file with the same name as our current base datasource, and if that exists, it will be used. Otherwise, we will default to a basic view in which objects are grouped by object type.
A defaultDataView parameter is provided in the second version of LoadFile above to allow for the following: a user may wish to set things up such that the base view shipped with GeoCalc is stored in a central location, and individual users have their own local views that begin as copies of that base view. If this is the desired behavior, then a defaultDataView may be specified. In that case, if the viewFile does not yet exist it will be created as a copy of defaultDataView.
If the xml files being loaded date from prior to the 6.4 release, they may contain the grouping information now split out into the view file. In this case, if you want to use the old grouping information, simply specify a new (non-existant) viewFileName and do not specify a default. The Load process will extract the grouping information from the datasource xml file. When CommitToFile is called, the folder structure will be stored in the specified new xvw file, and will be removed from the datasource xml file.
A single instance of the DataSource class can only be connected to a single base data source file and a single custom data source file. If the IsLoaded property is true when this method is called, the current base data source file (and custom data source file, if it exists) will be unloaded and the specified file(s) will be loaded.
When loading data from the base datasource file and the custom datasource file, if objects are encountered that are not in the specified view, they will be added under the top-level folder for their type. By default, base objects thus added will be hidden in the view, but custom objects will be visible. If it is desired that base objects be added to the view as visible, use set_RefreshViewHidden(false).
An additional new piece of DataSource functionality is the ability to log changes to the base and custom datasources. In order to activate logging, the changeLog and/or customChangeLog parameters must be set to the desired log files. If the change logs already exist, they will be loaded first so users may access prior changes if desired. If the change logs do not already exist, they will be created when the datasource(s) are saved. If no change logs are specified, changes will not be logged.
void DataSource_LoadFile()
{
GEOCALCPBW_NAMESPACE::DataSource data;
_towchar filename("c:\\bmg\\geocalcpbw\\data\\geocalc.xml");
_towchar customfilename("c:\\bmg\\geocalcpbw\\data\\custom.xml");
if(! data.LoadFile(filename.c_str(), true, customfilename.c_str()))
{
AfxMessageBox("DataSource::LoadFile failed");
}
}