mirror of
https://github.com/leozide/leocad
synced 2025-01-29 20:34:50 +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.
|
||||
bool SaveImage = false;
|
||||
bool SaveWavefront = false;
|
||||
// bool ImageHighlight = false;
|
||||
int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
|
||||
int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
|
||||
lcStep ImageStart = 0;
|
||||
lcStep ImageEnd = 0;
|
||||
char* ImageName = NULL;
|
||||
|
||||
// File to open.
|
||||
char* ProjectName = NULL;
|
||||
char* WavefrontName = NULL;
|
||||
|
||||
// Parse the command line arguments.
|
||||
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)
|
||||
// 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))
|
||||
{
|
||||
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(" -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(" --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");
|
||||
|
||||
return false;
|
||||
|
@ -260,7 +272,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
|||
|
||||
if (!LoadPiecesLibrary(LibPath, LibraryInstallPath, LDrawPath, LibraryCachePath))
|
||||
{
|
||||
if (SaveImage)
|
||||
if (SaveImage || SaveWavefront)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Cannot load pieces library.");
|
||||
return false;
|
||||
|
@ -280,70 +292,91 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
|||
// Load project.
|
||||
if (ProjectName && gMainWindow->OpenProject(ProjectName))
|
||||
{
|
||||
if (!SaveImage)
|
||||
return true;
|
||||
|
||||
QString FileName;
|
||||
|
||||
if (ImageName)
|
||||
FileName = ImageName;
|
||||
else
|
||||
FileName = ProjectName;
|
||||
|
||||
QString Extension = QFileInfo(FileName).suffix().toLower();
|
||||
|
||||
if (Extension.isEmpty())
|
||||
if (SaveImage)
|
||||
{
|
||||
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);
|
||||
QString FileName;
|
||||
|
||||
if (ImageName)
|
||||
FileName = ImageName;
|
||||
else
|
||||
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)
|
||||
ImageEnd = ImageStart;
|
||||
else if (ImageStart > ImageEnd)
|
||||
ImageStart = ImageEnd;
|
||||
|
||||
if ((ImageStart == 0) && (ImageEnd == 0))
|
||||
if (SaveWavefront)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
lcLoadDefaultKeyboardShortcuts();
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ enum LC_DIALOG_TYPE
|
|||
LC_DIALOG_EXPORT_CSV,
|
||||
LC_DIALOG_EXPORT_HTML,
|
||||
LC_DIALOG_EXPORT_POVRAY,
|
||||
LC_DIALOG_EXPORT_WAVEFRONT,
|
||||
LC_DIALOG_PROPERTIES,
|
||||
LC_DIALOG_PRINT,
|
||||
LC_DIALOG_FIND,
|
||||
|
|
|
@ -379,7 +379,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
|
|||
break;
|
||||
|
||||
case LC_FILE_EXPORT_WAVEFRONT:
|
||||
lcGetActiveProject()->ExportWavefront();
|
||||
lcGetActiveProject()->ExportWavefront(QString());
|
||||
break;
|
||||
|
||||
case LC_FILE_PRINT_PREVIEW:
|
||||
|
|
|
@ -1555,7 +1555,7 @@ void Project::ExportPOVRay()
|
|||
}
|
||||
}
|
||||
|
||||
void Project::ExportWavefront()
|
||||
void Project::ExportWavefront(const QString& FileName)
|
||||
{
|
||||
lcArray<lcModelPartsEntry> ModelParts;
|
||||
|
||||
|
@ -1567,16 +1567,19 @@ void Project::ExportWavefront()
|
|||
return;
|
||||
}
|
||||
|
||||
char FileName[LC_MAXPATH];
|
||||
memset(FileName, 0, sizeof(FileName));
|
||||
QString SaveFileName = 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))
|
||||
return;
|
||||
if (SaveFileName.isEmpty())
|
||||
return;
|
||||
}
|
||||
|
||||
lcDiskFile OBJFile;
|
||||
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);
|
||||
return;
|
||||
|
@ -1589,7 +1592,7 @@ void Project::ExportWavefront()
|
|||
|
||||
OBJFile.WriteLine("# Model exported from LeoCAD\n");
|
||||
|
||||
strcpy(buf, FileName);
|
||||
strcpy(buf, SaveFileName.toLatin1().constData());
|
||||
ptr = strrchr(buf, '.');
|
||||
if (ptr)
|
||||
*ptr = 0;
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
void ExportCSV();
|
||||
void ExportHTML();
|
||||
void ExportPOVRay();
|
||||
void ExportWavefront();
|
||||
void ExportWavefront(const QString& FileName);
|
||||
|
||||
protected:
|
||||
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_BRICKLINK:
|
||||
case LC_DIALOG_EXPORT_CSV:
|
||||
case LC_DIALOG_EXPORT_WAVEFRONT:
|
||||
{
|
||||
char* FileName = (char*)Data;
|
||||
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 (*.*)"));
|
||||
break;
|
||||
|
||||
case LC_DIALOG_EXPORT_WAVEFRONT:
|
||||
result = QFileDialog::getSaveFileName(parent, tr("Export Wavefront"), FileName, tr("Wavefront Files (*.obj);;All Files (*.*)"));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue