mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Added Wavefront export command line option.
This commit is contained in:
parent
257672a64f
commit
f0209fa021
6 changed files with 106 additions and 76 deletions
|
@ -174,15 +174,15 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
||||||
|
|
||||||
// Image output options.
|
// Image output options.
|
||||||
bool SaveImage = false;
|
bool SaveImage = false;
|
||||||
|
bool SaveWavefront = false;
|
||||||
// bool ImageHighlight = false;
|
// bool ImageHighlight = false;
|
||||||
int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
|
int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
|
||||||
int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
|
int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
|
||||||
lcStep ImageStart = 0;
|
lcStep ImageStart = 0;
|
||||||
lcStep ImageEnd = 0;
|
lcStep ImageEnd = 0;
|
||||||
char* ImageName = NULL;
|
char* ImageName = NULL;
|
||||||
|
|
||||||
// File to open.
|
|
||||||
char* ProjectName = NULL;
|
char* ProjectName = NULL;
|
||||||
|
char* WavefrontName = NULL;
|
||||||
|
|
||||||
// Parse the command line arguments.
|
// Parse the command line arguments.
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
|
@ -227,6 +227,17 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
||||||
}
|
}
|
||||||
// else if (strcmp(Param, "--highlight") == 0)
|
// else if (strcmp(Param, "--highlight") == 0)
|
||||||
// ImageHighlight = true;
|
// ImageHighlight = true;
|
||||||
|
else if ((strcmp(Param, "-wf") == 0) || (strcmp(Param, "--wavefront") == 0))
|
||||||
|
{
|
||||||
|
SaveWavefront = true;
|
||||||
|
|
||||||
|
if ((argc > (i+1)) && (argv[i+1][0] != '-'))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
WavefrontName = argv[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if ((strcmp(Param, "-v") == 0) || (strcmp(Param, "--version") == 0))
|
else if ((strcmp(Param, "-v") == 0) || (strcmp(Param, "--version") == 0))
|
||||||
{
|
{
|
||||||
printf("LeoCAD Version " LC_VERSION_TEXT "\n");
|
printf("LeoCAD Version " LC_VERSION_TEXT "\n");
|
||||||
|
@ -244,7 +255,8 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
||||||
printf(" -h, --height <height>: Sets the picture height.\n");
|
printf(" -h, --height <height>: Sets the picture height.\n");
|
||||||
printf(" -f, --from <time>: Sets the first frame or step to save pictures.\n");
|
printf(" -f, --from <time>: Sets the first frame or step to save pictures.\n");
|
||||||
printf(" -t, --to <time>: Sets the last frame or step to save pictures.\n");
|
printf(" -t, --to <time>: Sets the last frame or step to save pictures.\n");
|
||||||
printf(" --highlight: Highlight pieces in the steps they appear.\n");
|
// printf(" --highlight: Highlight pieces in the steps they appear.\n");
|
||||||
|
printf(" -wf, --wavefront <outfile.obj>: Exports the model to Wavefront format.\n");
|
||||||
printf(" \n");
|
printf(" \n");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -260,7 +272,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
||||||
|
|
||||||
if (!LoadPiecesLibrary(LibPath, LibraryInstallPath, LDrawPath, LibraryCachePath))
|
if (!LoadPiecesLibrary(LibPath, LibraryInstallPath, LDrawPath, LibraryCachePath))
|
||||||
{
|
{
|
||||||
if (SaveImage)
|
if (SaveImage || SaveWavefront)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: Cannot load pieces library.");
|
fprintf(stderr, "ERROR: Cannot load pieces library.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -280,70 +292,91 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
||||||
// Load project.
|
// Load project.
|
||||||
if (ProjectName && gMainWindow->OpenProject(ProjectName))
|
if (ProjectName && gMainWindow->OpenProject(ProjectName))
|
||||||
{
|
{
|
||||||
if (!SaveImage)
|
if (SaveImage)
|
||||||
return true;
|
|
||||||
|
|
||||||
QString FileName;
|
|
||||||
|
|
||||||
if (ImageName)
|
|
||||||
FileName = ImageName;
|
|
||||||
else
|
|
||||||
FileName = ProjectName;
|
|
||||||
|
|
||||||
QString Extension = QFileInfo(FileName).suffix().toLower();
|
|
||||||
|
|
||||||
if (Extension.isEmpty())
|
|
||||||
{
|
{
|
||||||
FileName += lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
|
QString FileName;
|
||||||
}
|
|
||||||
else if (Extension != "bmp" && Extension != "jpg" && Extension != "jpeg" && Extension != "png")
|
if (ImageName)
|
||||||
{
|
FileName = ImageName;
|
||||||
FileName = FileName.left(FileName.length() - Extension.length() - 1);
|
else
|
||||||
FileName += lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
|
FileName = ProjectName;
|
||||||
|
|
||||||
|
QString Extension = QFileInfo(FileName).suffix().toLower();
|
||||||
|
|
||||||
|
if (Extension.isEmpty())
|
||||||
|
{
|
||||||
|
FileName += lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
|
||||||
|
}
|
||||||
|
else if (Extension != "bmp" && Extension != "jpg" && Extension != "jpeg" && Extension != "png")
|
||||||
|
{
|
||||||
|
FileName = FileName.left(FileName.length() - Extension.length() - 1);
|
||||||
|
FileName += lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImageEnd < ImageStart)
|
||||||
|
ImageEnd = ImageStart;
|
||||||
|
else if (ImageStart > ImageEnd)
|
||||||
|
ImageStart = ImageEnd;
|
||||||
|
|
||||||
|
if ((ImageStart == 0) && (ImageEnd == 0))
|
||||||
|
{
|
||||||
|
ImageStart = ImageEnd = mProject->GetActiveModel()->GetCurrentStep();
|
||||||
|
}
|
||||||
|
else if ((ImageStart == 0) && (ImageEnd != 0))
|
||||||
|
{
|
||||||
|
ImageStart = ImageEnd;
|
||||||
|
}
|
||||||
|
else if ((ImageStart != 0) && (ImageEnd == 0))
|
||||||
|
{
|
||||||
|
ImageEnd = ImageStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImageStart > 255)
|
||||||
|
ImageStart = 255;
|
||||||
|
|
||||||
|
if (ImageEnd > 255)
|
||||||
|
ImageEnd = 255;
|
||||||
|
|
||||||
|
QString Frame;
|
||||||
|
|
||||||
|
if (ImageStart != ImageEnd)
|
||||||
|
{
|
||||||
|
QString Extension = QFileInfo(FileName).suffix();
|
||||||
|
Frame = FileName.left(FileName.length() - Extension.length() - 1) + QLatin1String("%1.") + Extension;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Frame = FileName;
|
||||||
|
|
||||||
|
lcGetActiveModel()->SaveStepImages(Frame, ImageWidth, ImageHeight, ImageStart, ImageEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImageEnd < ImageStart)
|
if (SaveWavefront)
|
||||||
ImageEnd = ImageStart;
|
|
||||||
else if (ImageStart > ImageEnd)
|
|
||||||
ImageStart = ImageEnd;
|
|
||||||
|
|
||||||
if ((ImageStart == 0) && (ImageEnd == 0))
|
|
||||||
{
|
{
|
||||||
ImageStart = ImageEnd = mProject->GetActiveModel()->GetCurrentStep();
|
QString FileName;
|
||||||
|
|
||||||
|
if (WavefrontName)
|
||||||
|
FileName = WavefrontName;
|
||||||
|
else
|
||||||
|
FileName = ProjectName;
|
||||||
|
|
||||||
|
QString Extension = QFileInfo(FileName).suffix().toLower();
|
||||||
|
|
||||||
|
if (Extension.isEmpty())
|
||||||
|
{
|
||||||
|
FileName += ".obj";
|
||||||
|
}
|
||||||
|
else if (Extension != "obj")
|
||||||
|
{
|
||||||
|
FileName = FileName.left(FileName.length() - Extension.length() - 1);
|
||||||
|
FileName += ".obj";
|
||||||
|
}
|
||||||
|
|
||||||
|
mProject->ExportWavefront(FileName);
|
||||||
}
|
}
|
||||||
else if ((ImageStart == 0) && (ImageEnd != 0))
|
|
||||||
{
|
|
||||||
ImageStart = ImageEnd;
|
|
||||||
}
|
|
||||||
else if ((ImageStart != 0) && (ImageEnd == 0))
|
|
||||||
{
|
|
||||||
ImageEnd = ImageStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImageStart > 255)
|
|
||||||
ImageStart = 255;
|
|
||||||
|
|
||||||
if (ImageEnd > 255)
|
|
||||||
ImageEnd = 255;
|
|
||||||
|
|
||||||
QString Frame;
|
|
||||||
|
|
||||||
if (ImageStart != ImageEnd)
|
|
||||||
{
|
|
||||||
QString Extension = QFileInfo(FileName).suffix();
|
|
||||||
Frame = FileName.left(FileName.length() - Extension.length() - 1) + QLatin1String("%1.") + Extension;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Frame = FileName;
|
|
||||||
|
|
||||||
lcGetActiveModel()->SaveStepImages(Frame, ImageWidth, ImageHeight, ImageStart, ImageEnd);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else if (SaveImage)
|
|
||||||
{
|
if (SaveImage || SaveWavefront)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
lcLoadDefaultKeyboardShortcuts();
|
lcLoadDefaultKeyboardShortcuts();
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ enum LC_DIALOG_TYPE
|
||||||
LC_DIALOG_EXPORT_CSV,
|
LC_DIALOG_EXPORT_CSV,
|
||||||
LC_DIALOG_EXPORT_HTML,
|
LC_DIALOG_EXPORT_HTML,
|
||||||
LC_DIALOG_EXPORT_POVRAY,
|
LC_DIALOG_EXPORT_POVRAY,
|
||||||
LC_DIALOG_EXPORT_WAVEFRONT,
|
|
||||||
LC_DIALOG_PROPERTIES,
|
LC_DIALOG_PROPERTIES,
|
||||||
LC_DIALOG_PRINT,
|
LC_DIALOG_PRINT,
|
||||||
LC_DIALOG_FIND,
|
LC_DIALOG_FIND,
|
||||||
|
|
|
@ -379,7 +379,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_FILE_EXPORT_WAVEFRONT:
|
case LC_FILE_EXPORT_WAVEFRONT:
|
||||||
lcGetActiveProject()->ExportWavefront();
|
lcGetActiveProject()->ExportWavefront(QString());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_FILE_PRINT_PREVIEW:
|
case LC_FILE_PRINT_PREVIEW:
|
||||||
|
|
|
@ -1555,7 +1555,7 @@ void Project::ExportPOVRay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::ExportWavefront()
|
void Project::ExportWavefront(const QString& FileName)
|
||||||
{
|
{
|
||||||
lcArray<lcModelPartsEntry> ModelParts;
|
lcArray<lcModelPartsEntry> ModelParts;
|
||||||
|
|
||||||
|
@ -1567,16 +1567,19 @@ void Project::ExportWavefront()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char FileName[LC_MAXPATH];
|
QString SaveFileName = FileName;
|
||||||
memset(FileName, 0, sizeof(FileName));
|
if (SaveFileName.isEmpty())
|
||||||
|
{
|
||||||
|
SaveFileName = QFileDialog::getSaveFileName(gMainWindow->mHandle, tr("Export Wavefront"), SaveFileName, tr("Wavefront Files (*.obj);;All Files (*.*)"));
|
||||||
|
|
||||||
if (!gMainWindow->DoDialog(LC_DIALOG_EXPORT_WAVEFRONT, FileName))
|
if (SaveFileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lcDiskFile OBJFile;
|
lcDiskFile OBJFile;
|
||||||
char Line[1024];
|
char Line[1024];
|
||||||
|
|
||||||
if (!OBJFile.Open(FileName, "wt"))
|
if (!OBJFile.Open(SaveFileName.toLatin1().constData(), "wt")) // todo: qstring
|
||||||
{
|
{
|
||||||
gMainWindow->DoMessageBox("Could not open file for writing.", LC_MB_OK|LC_MB_ICONERROR);
|
gMainWindow->DoMessageBox("Could not open file for writing.", LC_MB_OK|LC_MB_ICONERROR);
|
||||||
return;
|
return;
|
||||||
|
@ -1589,7 +1592,7 @@ void Project::ExportWavefront()
|
||||||
|
|
||||||
OBJFile.WriteLine("# Model exported from LeoCAD\n");
|
OBJFile.WriteLine("# Model exported from LeoCAD\n");
|
||||||
|
|
||||||
strcpy(buf, FileName);
|
strcpy(buf, SaveFileName.toLatin1().constData());
|
||||||
ptr = strrchr(buf, '.');
|
ptr = strrchr(buf, '.');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
void ExportCSV();
|
void ExportCSV();
|
||||||
void ExportHTML();
|
void ExportHTML();
|
||||||
void ExportPOVRay();
|
void ExportPOVRay();
|
||||||
void ExportWavefront();
|
void ExportWavefront(const QString& FileName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetModelParts(lcArray<lcModelPartsEntry>& ModelParts);
|
void GetModelParts(lcArray<lcModelPartsEntry>& ModelParts);
|
||||||
|
|
|
@ -291,7 +291,6 @@ bool lcBaseWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data)
|
||||||
case LC_DIALOG_EXPORT_3DSTUDIO:
|
case LC_DIALOG_EXPORT_3DSTUDIO:
|
||||||
case LC_DIALOG_EXPORT_BRICKLINK:
|
case LC_DIALOG_EXPORT_BRICKLINK:
|
||||||
case LC_DIALOG_EXPORT_CSV:
|
case LC_DIALOG_EXPORT_CSV:
|
||||||
case LC_DIALOG_EXPORT_WAVEFRONT:
|
|
||||||
{
|
{
|
||||||
char* FileName = (char*)Data;
|
char* FileName = (char*)Data;
|
||||||
QString result;
|
QString result;
|
||||||
|
@ -310,10 +309,6 @@ bool lcBaseWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data)
|
||||||
result = QFileDialog::getSaveFileName(parent, tr("Export CSV"), FileName, tr("CSV Files (*.csv);;All Files (*.*)"));
|
result = QFileDialog::getSaveFileName(parent, tr("Export CSV"), FileName, tr("CSV Files (*.csv);;All Files (*.*)"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_DIALOG_EXPORT_WAVEFRONT:
|
|
||||||
result = QFileDialog::getSaveFileName(parent, tr("Export Wavefront"), FileName, tr("Wavefront Files (*.obj);;All Files (*.*)"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue