summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2009-02-21 08:33:06 +0000
committerleo2009-02-21 08:33:06 +0000
commit83f1097598a63b64d2fec04f92f6f9c9e511b5af (patch)
tree83518aaf6991c8227ed939ad9be7351a6d08b14c
parent98288502360f565f018b15e3437f8bc5a88c614e (diff)
Added support for importing pieces from the command line.
git-svn-id: http://svn.leocad.org/tags/leocad-0.75@738 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--common/lc_application.cpp24
-rwxr-xr-xcommon/library.cpp24
2 files changed, 48 insertions, 0 deletions
diff --git a/common/lc_application.cpp b/common/lc_application.cpp
index ef57f5d..7743737 100644
--- a/common/lc_application.cpp
+++ b/common/lc_application.cpp
@@ -133,6 +133,9 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* SysLibPath)
// File to open.
char* ProjectName = NULL;
+ // First piece to import.
+ int ImportPieceArg = 0;
+
// Parse the command line arguments.
for (int i = 1; i < argc; i++)
{
@@ -180,6 +183,17 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* SysLibPath)
ImageInstructions = true;
else if (strcmp(Param, "--highlight") == 0)
ImageHighlight = true;
+ else if (strcmp(Param, "--importpieces") == 0)
+ {
+ if ((i == argc) || (argv[i+1][0] == '-'))
+ {
+ printf("Expected file name after --importpiece.");
+ return false;
+ }
+
+ ImportPieceArg = i+1;
+ break;
+ }
else if ((strcmp(Param, "-v") == 0) || (strcmp(Param, "--version") == 0))
{
printf("LeoCAD version " LC_VERSION_TEXT LC_VERSION_TAG " for "LC_VERSION_OSNAME"\n");
@@ -214,6 +228,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* SysLibPath)
printf(" --animation: Saves animations frames.\n");
printf(" --instructions: Saves instructions steps.\n");
printf(" --highlight: Highlight pieces in the steps they appear.\n");
+ printf(" --importpiece [file]: Import pieces into the library.\n");
printf(" \n");
}
else
@@ -387,6 +402,15 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* SysLibPath)
project->OnNewDocument();
}
+ if (ImportPieceArg)
+ {
+ for (int i = ImportPieceArg; i < argc; i++)
+ if (!ImportLDrawPiece(argv[i]))
+ break;
+
+ return false;
+ }
+
return true;
}
diff --git a/common/library.cpp b/common/library.cpp
index 0df8c51..9b49d62 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -1205,7 +1205,11 @@ bool PiecesLibrary::ImportTexture (const char* Name)
p = strrchr(file1, '/');
if (!p)
p = file1;
+#ifdef LC_WINDOWS
strupr(p);
+#else
+ strlwr(p);
+#endif
p++;
memset(NewTexName, 0, 9);
@@ -1361,10 +1365,16 @@ bool PiecesLibrary::ImportLDrawPiece (const char* Filename)
if (SaveLDrawPiece (&piece))
Sys_MessageBox ("Piece successfully imported.");
else
+ {
+ fprintf(stderr, "Error saving library after importing %s.\n", Filename);
Sys_MessageBox ("Error saving library.");
+ }
}
else
+ {
+ fprintf(stderr, "Error reading file %s\n", Filename);
Sys_MessageBox ("Error reading file.");
+ }
FreeLDrawPiece(&piece);
@@ -1844,7 +1854,14 @@ static void decodefile(FILE *F, Matrix *mat, unsigned char defcolor, lineinfo_t*
strcat (fn, "p/");
strcat (fn, filename);
+#ifdef LC_WINDOWS
strupr(filename);
+#else
+ strlwr(filename);
+ for (unsigned int i = 0; i < strlen(filename); i++)
+ if (filename[i] == '\\')
+ filename[i] = '/';
+#endif
for (val = 0; val < numvalid; val++)
if (strcmp(filename, valid[val]) == 0)
break;
@@ -1882,6 +1899,8 @@ static void decodefile(FILE *F, Matrix *mat, unsigned char defcolor, lineinfo_t*
info = info->next;
fclose(tf);
}
+ else
+ fprintf(stderr, "failed to load file %s (last attempt %s)\n", filename, fn);
} break;
case 2:
@@ -1980,6 +1999,11 @@ static void decodeconnections(FILE *F, Matrix *mat, unsigned char defcolor, char
strcat (fn, "P/");
strcat (fn, filename);
+#ifdef LC_WINDOWS
+ strupr(filename);
+#else
+ strlwr(filename);
+#endif
if (color == 16) color = defcolor;
strupr(filename);