leocad/common/project.cpp

756 lines
20 KiB
C++
Raw Normal View History

#include "lc_global.h"
2012-03-29 03:10:55 +02:00
#include "lc_math.h"
#include "lc_mesh.h"
2011-09-07 23:06:51 +02:00
#include <locale.h>
#include "opengl.h"
#include "pieceinf.h"
2012-10-12 01:55:55 +02:00
#include "lc_texture.h"
2011-09-07 23:06:51 +02:00
#include "piece.h"
#include "camera.h"
#include "light.h"
#include "group.h"
#include "project.h"
#include "image.h"
2013-08-16 03:25:51 +02:00
#include "lc_mainwindow.h"
2011-09-07 23:06:51 +02:00
#include "view.h"
2012-10-02 03:23:44 +02:00
#include "lc_library.h"
2011-09-07 23:06:51 +02:00
#include "lc_application.h"
2013-08-09 06:57:18 +02:00
#include "lc_profile.h"
2014-04-14 05:20:16 +02:00
#include "preview.h"
2014-12-13 00:42:09 +01:00
#include "lc_qmodellistdialog.h"
2011-09-07 23:06:51 +02:00
Project::Project()
{
mModified = false;
2014-12-13 00:42:09 +01:00
mActiveModel = new lcModel(tr("Model #1"));
2014-12-16 00:55:17 +01:00
mActiveModel->SetSaved();
2014-12-13 00:42:09 +01:00
mModels.Add(mActiveModel);
2011-09-07 23:06:51 +02:00
}
Project::~Project()
{
mModels.DeleteAll();
2011-09-07 23:06:51 +02:00
}
2014-12-13 00:42:09 +01:00
bool Project::IsModified() const
2011-09-07 23:06:51 +02:00
{
2014-12-13 00:42:09 +01:00
if (mModified)
return true;
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
if (mModels[ModelIdx]->IsModified())
return true;
return false;
}
QString Project::GetTitle() const
{
return mFileName.isEmpty() ? tr("New Project.ldr") : QFileInfo(mFileName).fileName();
}
void Project::SetActiveModel(int ModelIndex)
{
if (ModelIndex < 0 || ModelIndex >= mModels.GetSize())
return;
mActiveModel = mModels[ModelIndex];
mActiveModel->UpdateInterface();
gMainWindow->UpdateModels();
const lcArray<View*>& Views = gMainWindow->GetViews();
for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++)
Views[ViewIdx]->SetModel(lcGetActiveModel());
}
bool Project::IsModelNameValid(const QString& Name) const
{
if (Name.isEmpty())
return false;
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
if (mModels[ModelIdx]->GetProperties().mName == Name)
return false;
return true;
}
void Project::CreateNewModel()
{
const QString Prefix = tr("Model #");
int Max = 0;
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
{
QString Name = mModels[ModelIdx]->GetProperties().mName;
if (Name.startsWith(Prefix))
{
QString NumberString = Name.mid(Prefix.length());
QTextStream Stream(&NumberString);
int Number;
Stream >> Number;
Max = qMax(Max, Number);
}
}
QString Name = Prefix + QString::number(Max + 1);
for (;;)
{
bool Ok = false;
Name = QInputDialog::getText(gMainWindow->mHandle, tr("New Model"), tr("Name:"), QLineEdit::Normal, Name, &Ok);
if (!Ok)
return;
if (IsModelNameValid(Name))
break;
if (Name.isEmpty())
QMessageBox::information(gMainWindow->mHandle, tr("Empty Name"), tr("The model name cannot be empty."));
else
QMessageBox::information(gMainWindow->mHandle, tr("Duplicate Model"), tr("A model named '%1' already exists in this project, please enter an unique name.").arg(Name));
}
if (!Name.isEmpty())
{
mModified = true;
2014-12-16 00:55:17 +01:00
lcModel* Model = new lcModel(Name);
Model->SetSaved();
mModels.Add(Model);
2014-12-13 00:42:09 +01:00
SetActiveModel(mModels.GetSize() - 1);
gMainWindow->UpdateTitle();
}
}
void Project::ShowModelListDialog()
{
QList<QPair<QString, lcModel*>> Models;
Models.reserve(mModels.GetSize());
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
{
lcModel* Model = mModels[ModelIdx];
Models.append(QPair<QString, lcModel*>(Model->GetProperties().mName, Model));
}
lcQModelListDialog Dialog(gMainWindow->mHandle, Models);
if (Dialog.exec() != QDialog::Accepted || Models.isEmpty())
return;
lcArray<lcModel*> NewModels;
for (QList<QPair<QString, lcModel*>>::iterator it = Models.begin(); it != Models.end(); it++)
{
lcModel* Model = it->second;
if (!Model)
{
Model = new lcModel(it->first);
2014-12-16 00:55:17 +01:00
Model->SetSaved();
2014-12-13 00:42:09 +01:00
mModified = true;
}
else if (Model->GetProperties().mName != it->first)
{
Model->SetName(it->first);
mModified = true;
}
NewModels.Add(Model);
}
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
{
lcModel* Model = mModels[ModelIdx];
if (NewModels.FindIndex(Model) == -1)
{
delete Model;
mModified = true;
}
}
mModels = NewModels;
SetActiveModel(Dialog.mActiveModel);
gMainWindow->UpdateTitle();
2011-09-07 23:06:51 +02:00
}
bool Project::Load(const QString& FileName)
2011-09-07 23:06:51 +02:00
{
QFile File(FileName);
2011-09-07 23:06:51 +02:00
if (!File.open(QIODevice::ReadOnly))
2011-09-07 23:06:51 +02:00
{
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error reading file '%1':\n%2").arg(FileName, File.errorString()));
return false;
2011-09-07 23:06:51 +02:00
}
2014-12-13 00:42:09 +01:00
mModels.DeleteAll();
QString Extension = QFileInfo(FileName).suffix().toLower();
2013-12-19 14:41:49 +01:00
if (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr") || Extension == QLatin1String("mpd"))
2013-01-06 20:24:25 +01:00
{
QTextStream Stream(&File);
2011-09-07 23:06:51 +02:00
while (!Stream.atEnd())
2011-09-07 23:06:51 +02:00
{
2014-12-10 00:56:29 +01:00
QString Name = tr("Model%1").arg(QString::number(mModels.GetSize() + 1));
lcModel* Model = new lcModel(Name);
mModels.Add(Model);
Model->LoadLDraw(Stream);
2014-12-16 00:55:17 +01:00
Model->SetSaved();
2011-09-07 23:06:51 +02:00
}
}
else
{
lcMemFile MemFile;
QByteArray FileData = File.readAll();
MemFile.WriteBuffer(FileData.constData(), FileData.size());
MemFile.Seek(0, SEEK_SET);
2011-09-07 23:06:51 +02:00
2014-12-10 00:56:29 +01:00
lcModel* Model = new lcModel(tr("Model1"));
2011-09-07 23:06:51 +02:00
if (Model->LoadBinary(&MemFile))
2014-12-16 00:55:17 +01:00
{
mModels.Add(Model);
2014-12-16 00:55:17 +01:00
Model->SetSaved();
}
else
delete Model;
2011-09-07 23:06:51 +02:00
}
2014-12-13 00:42:09 +01:00
// todo: validate model names
if (mModels.IsEmpty())
return false;
2011-09-07 23:06:51 +02:00
mActiveModel = mModels[0];
2011-09-07 23:06:51 +02:00
/*
if (datfile || mpdfile)
2011-09-07 23:06:51 +02:00
{
gMainWindow->UpdateCurrentStep();
gMainWindow->UpdateFocusObject(GetFocusObject());
UpdateSelection();
2011-09-07 23:06:51 +02:00
const lcArray<View*>& Views = gMainWindow->GetViews();
for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++)
Views[ViewIdx]->ZoomExtents();
2011-09-07 23:06:51 +02:00
Success = true;
2011-09-07 23:06:51 +02:00
}
else
2011-09-07 23:06:51 +02:00
{
Success = FileLoad(&file, false, false);
2011-09-07 23:06:51 +02:00
2014-10-05 07:21:51 +02:00
UpdateBackgroundTexture();
2011-09-07 23:06:51 +02:00
CalculateStep();
2012-12-13 01:20:40 +01:00
2011-09-07 23:06:51 +02:00
if (!bUndo)
2014-08-17 22:44:12 +02:00
ClearSelection(false);
2012-12-13 01:20:40 +01:00
2011-09-07 23:06:51 +02:00
if (!bMerge)
2013-08-09 06:57:18 +02:00
gMainWindow->UpdateFocusObject(GetFocusObject());
2012-12-13 01:20:40 +01:00
if (!bMerge)
{
2014-10-05 07:21:51 +02:00
const lcArray<View*>& Views = gMainWindow->GetViews();
2014-05-03 23:16:48 +02:00
for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++)
2012-12-13 01:20:40 +01:00
{
2014-05-03 23:16:48 +02:00
View* view = Views[ViewIdx];
2012-12-13 01:20:40 +01:00
if (!view->mCamera->IsSimple())
view->SetDefaultCamera();
2014-11-10 01:06:11 +01:00
if (!bUndo)
view->ZoomExtents();
}
2012-12-13 01:20:40 +01:00
}
2014-10-05 07:21:51 +02:00
gMainWindow->UpdateLockSnap();
2013-08-09 06:57:18 +02:00
gMainWindow->UpdateSnap();
2014-05-03 23:16:48 +02:00
gMainWindow->UpdateCameraMenu();
2011-09-07 23:06:51 +02:00
UpdateSelection();
2014-07-06 08:04:09 +02:00
gMainWindow->UpdateCurrentStep();
2014-05-03 23:16:48 +02:00
gMainWindow->UpdateAllViews();
}
*/
mFileName = FileName;
2014-12-13 00:42:09 +01:00
mModified = false;
2011-09-07 23:06:51 +02:00
return true;
}
bool Project::Save(const QString& FileName)
2011-09-07 23:06:51 +02:00
{
QFile File(FileName);
2011-09-07 23:06:51 +02:00
if (!File.open(QIODevice::WriteOnly))
2012-03-23 00:44:56 +01:00
{
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
return false;
2012-03-23 00:44:56 +01:00
}
2011-09-07 23:06:51 +02:00
QTextStream Stream(&File);
bool MPD = mModels.GetSize() > 1;
2011-09-07 23:06:51 +02:00
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
2011-09-07 23:06:51 +02:00
{
lcModel* Model = mModels[ModelIdx];
if (MPD)
Stream << QLatin1String("0 FILE ") << Model->GetProperties().mName << QLatin1String("\r\n");
2014-12-16 00:55:17 +01:00
Model->SaveLDraw(Stream, false);
Model->SetSaved();
if (MPD)
Stream << QLatin1String("0 ENDFILE\r\n");
}
mFileName = FileName;
mModified = false;
return true;
}
/*
void Project::LoadDefaults() // todo: Change the interface in SetProject() instead
{
mProperties.LoadDefaults();
gMainWindow->SetColorIndex(lcGetColorIndex(4));
gMainWindow->SetTool(LC_TOOL_SELECT);
gMainWindow->SetAddKeys(false);
gMainWindow->UpdateUndoRedo(NULL, NULL);
gMainWindow->UpdateLockSnap();
gMainWindow->UpdateSnap();
mCurrentStep = 1;
gMainWindow->UpdateCurrentStep();
const lcArray<View*>& Views = gMainWindow->GetViews();
for (int i = 0; i < Views.GetSize(); i++)
if (!Views[i]->mCamera->IsSimple())
Views[i]->SetDefaultCamera();
2011-09-07 23:06:51 +02:00
gMainWindow->UpdateCameraMenu();
2011-09-07 23:06:51 +02:00
UpdateSelection();
gMainWindow->UpdateFocusObject(NULL);
2014-10-12 19:34:18 +02:00
}
*/
2011-09-07 23:06:51 +02:00
2014-10-12 01:26:23 +02:00
void Project::SaveImage()
{
/*
2014-10-12 01:26:23 +02:00
lcImageDialogOptions Options;
lcStep LastStep = GetLastStep();
Options.Width = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
Options.Height = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
Options.Start = mCurrentStep;
Options.End = LastStep;
2014-10-12 19:34:18 +02:00
if (!mFileName.isEmpty())
2014-10-12 01:26:23 +02:00
{
2014-10-12 19:34:18 +02:00
Options.FileName = mFileName;
2014-10-12 01:26:23 +02:00
QString Extension = QFileInfo(Options.FileName).suffix();
2014-10-13 05:43:33 +02:00
Options.FileName = Options.FileName.left(Options.FileName.length() - Extension.length());
2014-10-12 01:26:23 +02:00
}
else
Options.FileName = QLatin1String("image");
Options.FileName += lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
if (!gMainWindow->DoDialog(LC_DIALOG_SAVE_IMAGE, &Options))
return;
QString Extension = QFileInfo(Options.FileName).suffix();
if (!Extension.isEmpty())
lcSetProfileString(LC_PROFILE_IMAGE_EXTENSION, Options.FileName.right(Extension.length() + 1));
lcSetProfileInt(LC_PROFILE_IMAGE_WIDTH, Options.Width);
lcSetProfileInt(LC_PROFILE_IMAGE_HEIGHT, Options.Height);
if (Options.Start != Options.End)
Options.FileName = Options.FileName.insert(Options.FileName.length() - Extension.length() - 1, QLatin1String("%1"));
SaveStepImages(Options.FileName, Options.Width, Options.Height, Options.Start, Options.End);
*/
2014-10-12 01:26:23 +02:00
}
void Project::SaveStepImages(const QString& BaseName, int Width, int Height, lcStep Start, lcStep End)
{
/*
2014-10-12 01:26:23 +02:00
gMainWindow->mPreviewWidget->MakeCurrent();
lcContext* Context = gMainWindow->mPreviewWidget->mContext;
if (!Context->BeginRenderToTexture(Width, Height))
2011-09-07 23:06:51 +02:00
{
gMainWindow->DoMessageBox("Error creating images.", LC_MB_ICONERROR | LC_MB_OK);
return;
}
2011-09-07 23:06:51 +02:00
2014-07-06 08:04:09 +02:00
lcStep CurrentStep = mCurrentStep;
2011-09-07 23:06:51 +02:00
2014-10-12 01:26:23 +02:00
View View(this);
View.SetCamera(gMainWindow->GetActiveView()->mCamera, false);
View.mWidth = Width;
View.mHeight = Height;
View.SetContext(Context);
2011-09-07 23:06:51 +02:00
2014-10-12 01:26:23 +02:00
for (lcStep Step = Start; Step <= End; Step++)
{
2014-10-12 01:26:23 +02:00
SetCurrentStep(Step);
2014-11-24 00:48:56 +01:00
View.OnDraw();
2011-09-07 23:06:51 +02:00
2014-10-12 01:26:23 +02:00
QString FileName = BaseName.arg(Step, 2, 10, QLatin1Char('0'));
if (!Context->SaveRenderToTextureImage(FileName, Width, Height))
2014-10-12 01:26:23 +02:00
break;
2011-09-07 23:06:51 +02:00
}
2014-07-06 08:04:09 +02:00
SetCurrentStep(CurrentStep);
2011-09-07 23:06:51 +02:00
2014-10-12 01:26:23 +02:00
Context->EndRenderToTexture();
*/
2011-09-07 23:06:51 +02:00
}
/*
2014-10-13 05:43:33 +02:00
void Project::CreateHTMLPieceList(QTextStream& Stream, lcStep Step, bool Images, const QString& ImageExtension)
2011-09-07 23:06:51 +02:00
{
int* ColorsUsed = new int[gColorList.GetSize()];
memset(ColorsUsed, 0, sizeof(ColorsUsed[0]) * gColorList.GetSize());
int* PiecesUsed = new int[gColorList.GetSize()];
int NumColors = 0;
2011-09-07 23:06:51 +02:00
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
2014-08-07 17:22:33 +02:00
lcPiece* Piece = mPieces[PieceIdx];
2011-09-07 23:06:51 +02:00
2014-07-06 08:04:09 +02:00
if ((Piece->GetStepShow() == Step) || (Step == 0))
ColorsUsed[Piece->mColorIndex]++;
}
2011-09-07 23:06:51 +02:00
2014-10-13 05:43:33 +02:00
Stream << QLatin1String("<br><table border=1><tr><td><center>Piece</center></td>\r\n");
2011-09-07 23:06:51 +02:00
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
{
if (ColorsUsed[ColorIdx])
2011-09-07 23:06:51 +02:00
{
ColorsUsed[ColorIdx] = NumColors;
NumColors++;
2014-10-13 05:43:33 +02:00
Stream << QString("<td><center>%1</center></td>\n").arg(gColorList[ColorIdx].Name);
2011-09-07 23:06:51 +02:00
}
}
NumColors++;
2014-10-13 05:43:33 +02:00
Stream << QLatin1String("</tr>\n");
2011-09-07 23:06:51 +02:00
PieceInfo* pInfo;
for (int j = 0; j < lcGetPiecesLibrary()->mPieces.GetSize(); j++)
2011-09-07 23:06:51 +02:00
{
bool Add = false;
memset(PiecesUsed, 0, sizeof(PiecesUsed[0]) * gColorList.GetSize());
pInfo = lcGetPiecesLibrary()->mPieces[j];
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
2014-08-07 17:22:33 +02:00
lcPiece* Piece = mPieces[PieceIdx];
2014-07-06 08:04:09 +02:00
if ((Piece->mPieceInfo == pInfo) && ((Piece->GetStepShow() == Step) || (Step == 0)))
{
PiecesUsed[Piece->mColorIndex]++;
Add = true;
}
}
if (Add)
{
2014-10-13 05:43:33 +02:00
if (Images)
Stream << QString("<tr><td><IMG SRC=\"%1%2\" ALT=\"%3\"></td>\n").arg(pInfo->m_strName, ImageExtension, pInfo->m_strDescription);
else
2014-10-13 05:43:33 +02:00
Stream << QString("<tr><td>%1</td>\r\n").arg(pInfo->m_strDescription);
int curcol = 1;
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
{
if (PiecesUsed[ColorIdx])
{
while (curcol != ColorsUsed[ColorIdx] + 1)
{
2014-10-13 05:43:33 +02:00
Stream << QLatin1String("<td><center>-</center></td>\r\n");
curcol++;
}
2014-10-13 05:43:33 +02:00
Stream << QString("<td><center>%1</center></td>\r\n").arg(QString::number(PiecesUsed[ColorIdx]));
curcol++;
}
}
while (curcol != NumColors)
{
2014-10-13 05:43:33 +02:00
Stream << QLatin1String("<td><center>-</center></td>\r\n");
curcol++;
}
2014-10-13 05:43:33 +02:00
Stream << QLatin1String("</tr>\r\n");
}
2011-09-07 23:06:51 +02:00
}
2014-10-13 05:43:33 +02:00
Stream << QLatin1String("</table>\r\n<br>");
2011-09-07 23:06:51 +02:00
delete[] PiecesUsed;
delete[] ColorsUsed;
}
2011-09-07 23:06:51 +02:00
2014-10-13 05:43:33 +02:00
void Project::ExportHTML()
{
lcHTMLDialogOptions Options;
if (!mFileName.isEmpty())
Options.PathName = QFileInfo(mFileName).canonicalPath();
int ImageOptions = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_OPTIONS);
int HTMLOptions = lcGetProfileInt(LC_PROFILE_HTML_OPTIONS);
Options.ImageFormat = (LC_IMAGE_FORMAT)(ImageOptions & ~(LC_IMAGE_MASK));
Options.TransparentImages = (ImageOptions & LC_IMAGE_TRANSPARENT) != 0;
Options.SinglePage = (HTMLOptions & LC_HTML_SINGLEPAGE) != 0;
Options.IndexPage = (HTMLOptions & LC_HTML_INDEX) != 0;
Options.StepImagesWidth = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_WIDTH);
Options.StepImagesHeight = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_HEIGHT);
Options.HighlightNewParts = (HTMLOptions & LC_HTML_HIGHLIGHT) != 0;
Options.PartsListStep = (HTMLOptions & LC_HTML_LISTSTEP) != 0;
Options.PartsListEnd = (HTMLOptions & LC_HTML_LISTEND) != 0;
Options.PartsListImages = (HTMLOptions & LC_HTML_IMAGES) != 0;
Options.PartImagesColor = lcGetColorIndex(lcGetProfileInt(LC_PROFILE_HTML_PARTS_COLOR));
Options.PartImagesWidth = lcGetProfileInt(LC_PROFILE_HTML_PARTS_WIDTH);
Options.PartImagesHeight = lcGetProfileInt(LC_PROFILE_HTML_PARTS_HEIGHT);
if (!gMainWindow->DoDialog(LC_DIALOG_EXPORT_HTML, &Options))
return;
HTMLOptions = 0;
if (Options.SinglePage)
HTMLOptions |= LC_HTML_SINGLEPAGE;
if (Options.IndexPage)
HTMLOptions |= LC_HTML_INDEX;
if (Options.HighlightNewParts)
HTMLOptions |= LC_HTML_HIGHLIGHT;
if (Options.PartsListStep)
HTMLOptions |= LC_HTML_LISTSTEP;
if (Options.PartsListEnd)
HTMLOptions |= LC_HTML_LISTEND;
if (Options.PartsListImages)
HTMLOptions |= LC_HTML_IMAGES;
ImageOptions = Options.ImageFormat;
if (Options.TransparentImages)
ImageOptions |= LC_IMAGE_TRANSPARENT;
lcSetProfileInt(LC_PROFILE_HTML_IMAGE_OPTIONS, ImageOptions);
lcSetProfileInt(LC_PROFILE_HTML_OPTIONS, HTMLOptions);
lcSetProfileInt(LC_PROFILE_HTML_IMAGE_WIDTH, Options.StepImagesWidth);
lcSetProfileInt(LC_PROFILE_HTML_IMAGE_HEIGHT, Options.StepImagesHeight);
lcSetProfileInt(LC_PROFILE_HTML_PARTS_COLOR, lcGetColorCode(Options.PartImagesColor));
lcSetProfileInt(LC_PROFILE_HTML_PARTS_WIDTH, Options.PartImagesWidth);
lcSetProfileInt(LC_PROFILE_HTML_PARTS_HEIGHT, Options.PartImagesHeight);
QDir Dir(Options.PathName);
Dir.mkpath(QLatin1String("."));
QString Title = GetTitle();
QString BaseName = Title.left(Title.length() - QFileInfo(Title).suffix().length() - 1);
QString HTMLExtension = QLatin1String(".html");
QString ImageExtension;
lcStep LastStep = GetLastStep();
switch (Options.ImageFormat)
{
case LC_IMAGE_BMP:
ImageExtension = QLatin1String(".bmp");
break;
case LC_IMAGE_JPG:
ImageExtension = QLatin1String(".jpg");
break;
default:
case LC_IMAGE_PNG:
ImageExtension = QLatin1String(".png");
break;
}
if (Options.SinglePage)
{
QString FileName = QFileInfo(Dir, BaseName + HTMLExtension).absoluteFilePath();
QFile File(FileName);
if (!File.open(QIODevice::WriteOnly))
{
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
return;
}
QTextStream Stream(&File);
Stream << QString("<HTML>\r\n<HEAD>\r\n<TITLE>Instructions for %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(Title);
for (lcStep Step = 1; Step <= LastStep; Step++)
{
QString StepString = QString("%1").arg(Step, 2, 10, QLatin1Char('0'));
Stream << QString("<IMG SRC=\"%1-%2%3\" ALT=\"Step %4\" WIDTH=%5 HEIGHT=%6><BR><BR>\r\n").arg(BaseName, StepString, ImageExtension, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight));
if (Options.PartsListStep)
CreateHTMLPieceList(Stream, Step, Options.PartsListImages, ImageExtension);
}
if (Options.PartsListEnd)
CreateHTMLPieceList(Stream, 0, Options.PartsListImages, ImageExtension);
Stream << QLatin1String("</CENTER>\n<BR><HR><BR><B><I>Created by <A HREF=\"http://www.leocad.org\">LeoCAD</A></B></I><BR></HTML>\r\n");
}
else
{
if (Options.IndexPage)
{
QString FileName = QFileInfo(Dir, BaseName + QLatin1String("-index") + HTMLExtension).absoluteFilePath();
QFile File(FileName);
if (!File.open(QIODevice::WriteOnly))
{
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
return;
}
QTextStream Stream(&File);
Stream << QString("<HTML>\r\n<HEAD>\r\n<TITLE>Instructions for %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(Title);
for (lcStep Step = 1; Step <= LastStep; Step++)
Stream << QString("<A HREF=\"%1-%2.html\">Step %3<BR>\r\n</A>").arg(BaseName, QString("%1").arg(Step, 2, 10, QLatin1Char('0')), QString::number(Step));
if (Options.PartsListEnd)
Stream << QString("<A HREF=\"%1-pieces.html\">Pieces Used</A><BR>\r\n").arg(BaseName);
Stream << QLatin1String("</CENTER>\r\n<BR><HR><BR><B><I>Created by <A HREF=\"http://www.leocad.org\">LeoCAD</A></B></I><BR></HTML>\r\n");
}
for (lcStep Step = 1; Step <= LastStep; Step++)
{
QString StepString = QString("%1").arg(Step, 2, 10, QLatin1Char('0'));
QString FileName = QFileInfo(Dir, BaseName + QLatin1String("-") + StepString + HTMLExtension).absoluteFilePath();
QFile File(FileName);
if (!File.open(QIODevice::WriteOnly))
{
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
return;
}
QTextStream Stream(&File);
Stream << QString("<HTML>\r\n<HEAD>\r\n<TITLE>%1 - Step %2</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(Title, QString::number(Step));
Stream << QString("<IMG SRC=\"%1-%2%3\" ALT=\"Step %4\" WIDTH=%5 HEIGHT=%6><BR><BR>\r\n").arg(BaseName, StepString, ImageExtension, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight));
if (Options.PartsListStep)
CreateHTMLPieceList(Stream, Step, Options.PartsListImages, ImageExtension);
Stream << QLatin1String("</CENTER>\r\n<BR><HR><BR>");
if (Step != 1)
Stream << QString("<A HREF=\"%1-%2.html\">Previous</A> ").arg(BaseName, QString("%1").arg(Step - 1, 2, 10, QLatin1Char('0')));
if (Options.IndexPage)
Stream << QString("<A HREF=\"%1-index.html\">Index</A> ").arg(BaseName);
if (Step != LastStep)
Stream << QString("<A HREF=\"%1-%2.html\">Next</A>").arg(BaseName, QString("%1").arg(Step + 1, 2, 10, QLatin1Char('0')));
else if (Options.PartsListEnd)
Stream << QString("<A HREF=\"%1-pieces.html\">Pieces Used</A>").arg(BaseName);
Stream << QLatin1String("<BR></HTML>\r\n");
}
if (Options.PartsListEnd)
{
QString FileName = QFileInfo(Dir, BaseName + QLatin1String("-pieces") + HTMLExtension).absoluteFilePath();
QFile File(FileName);
if (!File.open(QIODevice::WriteOnly))
{
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
return;
}
QTextStream Stream(&File);
Stream << QString("<HTML>\r\n<HEAD>\r\n<TITLE>Pieces used by %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\n").arg(Title);
CreateHTMLPieceList(Stream, 0, Options.PartsListImages, ImageExtension);
Stream << QLatin1String("</CENTER>\n<BR><HR><BR>");
Stream << QString("<A HREF=\"%1-%2.html\">Previous</A> ").arg(BaseName, QString("%1").arg(LastStep, 2, 10, QLatin1Char('0')));
if (Options.IndexPage)
Stream << QString("<A HREF=\"%1-index.html\">Index</A> ").arg(BaseName);
Stream << QLatin1String("<BR></HTML>\r\n");
}
}
QString StepImageBaseName = QFileInfo(Dir, BaseName + QLatin1String("-%1") + ImageExtension).absoluteFilePath();
SaveStepImages(StepImageBaseName, Options.StepImagesWidth, Options.StepImagesHeight, 1, LastStep);
if (Options.PartsListImages)
{
gMainWindow->mPreviewWidget->MakeCurrent();
lcContext* Context = gMainWindow->mPreviewWidget->mContext;
int Width = Options.PartImagesWidth;
int Height = Options.PartImagesHeight;
if (!Context->BeginRenderToTexture(Width, Height))
{
gMainWindow->DoMessageBox("Error creating images.", LC_MB_ICONERROR | LC_MB_OK);
return;
}
float aspect = (float)Width/(float)Height;
Context->SetViewport(0, 0, Width, Height);
2014-10-13 05:43:33 +02:00
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
bool Skip = false;
PieceInfo* Info = Piece->mPieceInfo;
for (int CheckIdx = 0; CheckIdx < PieceIdx; CheckIdx++)
{
if (mPieces[CheckIdx]->mPieceInfo == Info)
{
Skip = true;
break;
}
}
if (Skip)
continue;
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Info->ZoomExtents(30.0f, aspect);
Info->RenderPiece(Options.PartImagesColor);
glFinish();
QString FileName = QFileInfo(Dir, Info->m_strName + ImageExtension).absoluteFilePath();
if (!Context->SaveRenderToTextureImage(FileName, Width, Height))
break;
}
Context->EndRenderToTexture();
}
}
*/