Subject:
|
Re: LDrawIni API (was: LDRAWPREDIRS LDRAWPOSTDIRS - additional search paths)
|
Newsgroups:
|
lugnet.cad.dev
|
Date:
|
Thu, 18 Mar 2004 19:57:49 GMT
|
Viewed:
|
4033 times
|
| |
| |
"Lars C. Hassing" <sp.lars@am.hassings.dk> schrieb im Newsbeitrag
news:Hun57C.1xM8@lugnet.com...
> Here are my ideas of an API for accessing the LDrawIni settings.
>
> The basic idea is that it should be very simple to use, there are only four functions
> and a data structure declaration.
>
> First you call LDrawIniGet to read and initialize all relevant ldraw.ini data,
> the LDrawDir, the search directories, the LGEO directory.
> The data is initialized from environment variables and/or ini files
> suitable for the platform you are running and in the agreed order.
>
> L3P, as an example, will now look for the model in each of the search dirs.
> When found L3P calls LDrawIniComputeRealDirs with the directory of the model.
> This will recalculate the search dirs in the data structure to include those with <MODELDIR>.
> L3P will now (probably) have an extra search dir to look in for the remaining loading of parts.
> (directories marked with <SKIP> will of course be excluded from the search
dirs)
Don mentioned that already, it would be good to enable <SKIP> from the
programm. Imagine an
alternate set of files with <SKIP> flag before official ones. When the user
can enable/disable the SKIP
detection, the user can see the different view without to modify any ini
file - on some systems users
might not be able to modify these files (e.g. when running with a guest
account).
>
> For each search dir there may be a number of flags. The known ones are parsed into bit-flags
> to speed up testing (e.g. LDSDF_HIDE|LDSDF_DEFPRIM), the remaining are available
> as a string, e.g "<MyFlag><UnknownFlag>".
> (or would you like a NULL terminated array of strings?)
I would prefere the current variant, as this allows quick searching for
flags using just one standard function call.
>
> When finding a file in one of the search dirs and the file has no official header
> L3P can quickly determine whether the default filetype is e.g. Primitive.
>
> When done L3P calls LDrawIniFree to release the data structure.
>
> L3Lab works the same way, only it calls LDrawIniComputeRealDirs
> whenever a new model is loaded.
>
> The last function is LDrawIniResetSearchDirs, only to be called from the
> LDrawSetup program - or if you wish to override the search to be the
> standard one.
Do we have to call LDrawIniResetSearchDirs before each call to
LDrawIniComputeRealDirs?
<SNIP>
>
> static int FileIsFromP;
> static int FileIsFromPARTS;
> static FILE *OpenDatFile2(char *DatName, char *Extension)
> {
> FILE *fp;
> register int i;
>
> for (i = 0; i < LDrawIni->nSearchDirs; i++)
> {
> strcpy(DatPath, LDrawIni->SearchDirs[i].Dir); /* Has trailing \ */
> strcat(DatPath, DatName);
> strcat(DatPath, Extension);
> FileIsFromP = (LDrawIni->SearchDirs[i].Flags & LDSDF_DEFPRIM) ? 1 : 0;
> FileIsFromPARTS = (LDrawIni->SearchDirs[i].Flags & LDSDF_DEFPART) ? 1 : 0;
> fp = fopeni(DatPath, "rb");
> if (fp)
> return fp;
> }
> return NULL;
> }
> FILE *OpenDatFile(char *DatName, int IsModel)
> {
> static char *Extensions[] = { "", ".ldr", ".dat", ".mpd" };
> int i;
> FILE *fp;
>
> if (IsModel)
> {
> /* Be sure to load model; can't be sure <MODELDIR> is in search dirs */
> strcpy(DatPath, ModelDir); /* ModelDir may be "" */
> if (DatPath[0])
> strcat(DatPath, BACKSLASH_STRING);
> strcat(DatPath, DatName);
> FileIsFromP = 0;
> FileIsFromPARTS = 0;
> fp = fopeni(DatPath, "rb");
> if (fp)
> return fp;
> }
> for (i = 0; i < sizeof(Extensions)/sizeof(char *); i++)
> {
> fp = OpenDatFile2(DatName, Extensions[i]);
> if (fp)
> return fp;
> }
> return NULL;
> }
Don't you ever need FileIsFrom* flags when processing the files themself? If
you use global variables you cannot tell, which flag belongs to which file?!
These library is ideal for me at least, and I like this suggestion. Well
done Lars!
Is there any interest out there on a c++ class? If yes, I'll write a well
documented one otherwice I do the quick and dirty way without comments and
documentation :-)
Michael
|
|
Message has 1 Reply:
Message is in Reply To:
132 Messages in This Thread: (Inline display suppressed due to large size. Click Dots below to view.)
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|