Changed startup order to fix saving images from the command line.

This commit is contained in:
leo 2015-01-21 22:41:53 +00:00
parent 817ffce7ef
commit 257672a64f
5 changed files with 49 additions and 71 deletions

View file

@ -277,49 +277,30 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
// Create a new project.
mProject = new Project();
GL_DisableVertexBufferObject();
// Load project.
if (ProjectName && gMainWindow->OpenProject(ProjectName))
{
if (!SaveImage)
return true;
// Check if there's a file name and it has an extension.
bool NeedExt = true;
String FileName;
QString FileName;
if (!ImageName)
{
if (ImageName)
FileName = ImageName;
else
FileName = ProjectName;
int i = FileName.ReverseFind('.');
if (i != -1)
FileName[i] = 0;
}
else
QString Extension = QFileInfo(FileName).suffix().toLower();
if (Extension.isEmpty())
{
FileName = ImageName;
int i = FileName.ReverseFind('.');
String Ext;
if (i != -1)
{
Ext = FileName.Right(FileName.GetLength() - i);
Ext.MakeLower();
}
if (Ext == "bmp")
NeedExt = false;
else if ((Ext == "jpg") || (Ext == "jpeg"))
NeedExt = false;
else if (Ext == "png")
NeedExt = false;
}
if (NeedExt)
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;
@ -345,18 +326,17 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
if (ImageEnd > 255)
ImageEnd = 255;
String Frame;
QString Frame;
if (ImageStart != ImageEnd)
{
int Ext = FileName.ReverseFind('.');
Frame = FileName.Left(Ext) + "%1" + FileName.Right(FileName.GetLength() - Ext);
QString Extension = QFileInfo(FileName).suffix();
Frame = FileName.left(FileName.length() - Extension.length() - 1) + QLatin1String("%1.") + Extension;
}
else
Frame = FileName;
lcGetActiveModel()->SaveStepImages(Frame.Buffer(), ImageWidth, ImageHeight, ImageStart, ImageEnd);
lcGetActiveModel()->SaveStepImages(Frame, ImageWidth, ImageHeight, ImageStart, ImageEnd);
return false;
}

View file

@ -1072,7 +1072,13 @@ void lcModel::SaveStepImages(const QString& BaseName, int Width, int Height, lcS
SetCurrentStep(Step);
View.OnDraw();
QString FileName = BaseName.arg(Step, 2, 10, QLatin1Char('0'));
QString FileName;
if (Start == End)
FileName = BaseName;
else
FileName = BaseName.arg(Step, 2, 10, QLatin1Char('0'));
if (!Context->SaveRenderToTextureImage(FileName, Width, Height))
break;
}

View file

@ -43,37 +43,14 @@ lcQMainWindow::lcQMainWindow(QWidget *parent)
QGridLayout *previewLayout = new QGridLayout(previewFrame);
previewLayout->setContentsMargins(0, 0, 0, 0);
QWidget *viewWidget = new lcQGLWidget(previewFrame, piecePreview, new View(lcGetActiveModel()), true);
QWidget *viewWidget = new lcQGLWidget(previewFrame, piecePreview, new View(NULL), true);
previewLayout->addWidget(viewWidget, 0, 0, 1, 1);
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardChanged()));
clipboardChanged();
lcPiecesLibrary* Library = lcGetPiecesLibrary();
PieceInfo* Info = Library->FindPiece("3005", false);
GL_EnableVertexBufferObject();
if (!lcGetActiveModel()->GetPieces().IsEmpty())
{
for (int PieceIdx = 0; PieceIdx < Library->mPieces.GetSize(); PieceIdx++)
{
lcMesh* Mesh = Library->mPieces[PieceIdx]->GetMesh();
if (Mesh)
Mesh->UpdateBuffers();
}
}
if (!Info)
Info = Library->mPieces[0];
if (Info)
{
PiecePreview* Preview = (PiecePreview*)piecePreview->widget;
gMainWindow->mPreviewWidget = Preview;
Preview->SetCurrentPiece(Info);
}
QSettings settings;
settings.beginGroup("MainWindow");
@ -88,6 +65,23 @@ lcQMainWindow::~lcQMainWindow()
{
}
void lcQMainWindow::LibraryLoaded()
{
lcPiecesLibrary* Library = lcGetPiecesLibrary();
PieceInfo* Info = Library->FindPiece("3005", false);
if (!Info)
Info = Library->mPieces[0];
if (Info)
gMainWindow->mPreviewWidget->SetCurrentPiece(Info);
QCompleter *completer = new QCompleter(this);
completer->setModel(new lcQPartsListModel(completer));
completer->setCaseSensitivity(Qt::CaseInsensitive);
partSearch->setCompleter(completer);
}
void lcQMainWindow::createActions()
{
for (int Command = 0; Command < LC_NUM_COMMANDS; Command++)
@ -502,11 +496,6 @@ void lcQMainWindow::createToolBars()
connect(partSearch, SIGNAL(returnPressed()), this, SLOT(partSearchReturn()));
connect(partSearch, SIGNAL(textChanged(QString)), this, SLOT(partSearchChanged(QString)));
QCompleter *completer = new QCompleter(this);
completer->setModel(new lcQPartsListModel(completer));
completer->setCaseSensitivity(Qt::CaseInsensitive);
partSearch->setCompleter(completer);
QFrame *colorFrame = new QFrame(partsSplitter);
colorFrame->setFrameShape(QFrame::StyledPanel);
colorFrame->setFrameShadow(QFrame::Sunken);

View file

@ -21,6 +21,8 @@ public:
explicit lcQMainWindow(QWidget *parent = 0);
~lcQMainWindow();
void LibraryLoaded();
void showPrintDialog();
void splitHorizontal();

View file

@ -176,12 +176,13 @@ int main(int argc, char *argv[])
QDir dir;
dir.mkpath(cachePath);
gMainWindow = new lcMainWindow();
lcQMainWindow w;
gMainWindow->mHandle = &w;
if (!g_App->Initialize(argc, argv, libPath, LDrawPath, cachePath.toLocal8Bit().data()))
return 1;
lcQMainWindow w;
gMainWindow->mHandle = &w;
w.LibraryLoaded();
lcGetActiveModel()->UpdateInterface();
gMainWindow->SetColorIndex(lcGetColorIndex(4));
gMainWindow->UpdateRecentFiles();