Differences between revisions 1 and 2
Revision 1 as of 2008-09-09 22:11:08
Size: 3690
Revision 2 as of 2008-09-09 22:14:13
Size: 3830
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:

Line 82: Line 85:
For the complete code see file canglob.cpp and in there: wxCursor& a2dArtProvider::GetCursor( a2dCursorId id ).
Line 88: Line 92:

Dynamic Variables

In the GeneralModule, the class <<DOX(a2dVariablesHash)>>, and a global instance of it can be reached via: a2dDocviewGlobals->GetVariablesHash().

You can set variable in it like this:

   1     a2dDocviewGlobals->GetVariablesHash().SetVariableString( "wxart2dlayers", "maskproclayers.cvg" );

This will create or set a variable called wxart2dlayers with the string value askproclayers.cvg. But variables of various types like double, int can be set, since they are stored as a2dNamedProperty. So a double is stored as a2dDoubleProperty. But any derived a2dNamedProperty can be stored as a variable.

You can get the value of a variable back as a string like this:

   1 wxString* layerfile = a2dGeneralGlobals->GetVariablesHash().GetVariableString( "wxart2dlayers" );

If you want to have the original type again, you get it as a a2dNamedProperty first. For the simple types, there are methods to get the value straight away. Complex types, you can cast back to the orginal a2dNamedProperty class, and get the value from that.

   1 a2dNamedProperty* myprop = a2dVariablesHash::GetVariable( "variableName" )
   2 double value = myprop->GetDouble();

When setting a double variable makes the id of the created <<DOX(a2dDoubleProperty)>> the following a2dPropertyIdDouble::GetDummy(). This can be used to test the type.

   1     a2dDocviewGlobals->GetVariablesHash().SetVariableDouble( "myDoubleVar", 123.456 );
   2     a2dNamedProperty* myprop = a2dVariablesHash::GetVariable( "myDoubleVar" )
   3     a2dPropertyId id = myprop->GetId()    

What is its use

The variables system is used internal in the library for getting to files and paths, which can be defined by the application. Internal a reserved variable name is used to get to it. At the start if the application the variables is set by the application, and wxArt2D will use that path from then on. For instance "wxart2dlayers" and "layerFileSavePath" are used to find a default layer file where it is needed.

Variables as part of paths

A path to a file can be defined as "%{layerFileSavePath}/someSubDir", and this can be evaluated by <<DOX(a2dPathList)>>. That will find the internal variable "layerFileSavePath" and substitute its value in it. But you can even add paths to the pathlist containing variables, like:

   1    a2dPathList mySearchPaths;
   2    mySearchPaths.Add( "%{mySpecialSearchDir}/${MyEnvironmentVar}/someSubDir" );
   3    mySearchPaths.FindValidPath( "SomeFile" );

The above will evaluate on the fly %{mySpecialSearchDir} in the a2dPathList, and use that path to find SomeFile. The ${MyEnvironmentVar} will be taken from the Environment variable, and gives even more flexibility. This makes it all very flexible. And combined with wxLua, you can configure your application paths without limitation. Just an example:

   1 cmdh = wx.a2dLuaWP;
   2 res, myproc = wx.wxGetEnv( "MYAPP_ROOT"  )
   3 --cmdh:Message( myproc )
   4 home = wx.wxGetHomeDir()
   6 cmdh:AddLayersPath( home .. "/config" )
   7 cmdh:AddConfigPath( home .. "/config" )
   8 cmdh:AddImagePath( home .. "/config" )
   9 cmdh:AddLayersPath( myproc .. "/config" )
  10 cmdh:AddFontPath( myproc .. "/config" )
  11 cmdh:AddImagePath( myproc .. "/config" )


The following is used to get to cursors used in wxArt2D:

   1         wxString* artdir = a2dGeneralGlobals->GetVariablesHash().GetVariableString(  wxT( "WXART2D_ART" ) );
   2         wxString artroot;
   3         if ( artdir && !artdir->IsEmpty() )
   4         {
   5                 artroot = *artdir;
   6                 artroot += wxT("/cursors/");
   7         }

For the complete code see file canglob.cpp and in there: wxCursor& a2dArtProvider::GetCursor( a2dCursorId id ).

wxArt2D: InternalVariables (last edited 2011-07-04 14:55:33 by KlaasHolwerda)