Save files with OMR style header.
This commit is contained in:
@@ -1253,13 +1253,13 @@ QByteArray lcMainWindow::GetTabLayout()
|
||||
DataStream << (quint32)LC_TAB_LAYOUT_VERSION;
|
||||
qint32 NumTabs = mModelTabWidget->count();
|
||||
DataStream << NumTabs;
|
||||
DataStream << ((lcModelTabWidget*)mModelTabWidget->currentWidget())->GetModel()->GetProperties().mName;
|
||||
DataStream << ((lcModelTabWidget*)mModelTabWidget->currentWidget())->GetModel()->GetProperties().mFileName;
|
||||
|
||||
for (int TabIdx = 0; TabIdx < NumTabs; TabIdx++)
|
||||
{
|
||||
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
|
||||
|
||||
DataStream << TabWidget->GetModel()->GetProperties().mName;
|
||||
DataStream << TabWidget->GetModel()->GetProperties().mFileName;
|
||||
|
||||
std::function<void (QWidget*)> SaveWidget = [&DataStream, &SaveWidget, &TabWidget](QWidget* Widget)
|
||||
{
|
||||
@@ -1496,7 +1496,7 @@ void lcMainWindow::SetCurrentModelTab(lcModel* Model)
|
||||
if (!EmptyWidget)
|
||||
{
|
||||
TabWidget = new lcModelTabWidget(Model);
|
||||
mModelTabWidget->addTab(TabWidget, Model->GetProperties().mName);
|
||||
mModelTabWidget->addTab(TabWidget, Model->GetProperties().mFileName);
|
||||
|
||||
QGridLayout* CentralLayout = new QGridLayout(TabWidget);
|
||||
CentralLayout->setContentsMargins(0, 0, 0, 0);
|
||||
@@ -2136,7 +2136,7 @@ void lcMainWindow::UpdateModels()
|
||||
if (ModelIdx < Models.GetSize())
|
||||
{
|
||||
Action->setChecked(CurrentModel == Models[ModelIdx]);
|
||||
Action->setText(QString::fromLatin1("&%1 %2").arg(QString::number(ModelIdx + 1), Models[ModelIdx]->GetProperties().mName));
|
||||
Action->setText(QString::fromLatin1("&%1 %2").arg(QString::number(ModelIdx + 1), Models[ModelIdx]->GetProperties().mFileName));
|
||||
Action->setVisible(true);
|
||||
}
|
||||
else
|
||||
@@ -2152,7 +2152,7 @@ void lcMainWindow::UpdateModels()
|
||||
TabIdx++;
|
||||
else if (Models.FindIndex(Model) != -1)
|
||||
{
|
||||
mModelTabWidget->setTabText(TabIdx, Model->GetProperties().mName);
|
||||
mModelTabWidget->setTabText(TabIdx, Model->GetProperties().mFileName);
|
||||
TabIdx++;
|
||||
}
|
||||
else
|
||||
|
||||
+64
-13
@@ -57,11 +57,9 @@ void lcModelProperties::SaveLDraw(QTextStream& Stream) const
|
||||
{
|
||||
QLatin1String LineEnding("\r\n");
|
||||
|
||||
if (!mAuthor.isEmpty())
|
||||
Stream << QLatin1String("0 !LEOCAD MODEL AUTHOR ") << mAuthor << LineEnding;
|
||||
|
||||
if (!mDescription.isEmpty())
|
||||
Stream << QLatin1String("0 !LEOCAD MODEL DESCRIPTION ") << mDescription << LineEnding;
|
||||
Stream << QLatin1String("0 ") << mDescription << LineEnding;
|
||||
Stream << QLatin1String("0 Name: ") << mModelName << LineEnding;
|
||||
Stream << QLatin1String("0 Author: ") << mAuthor << LineEnding;
|
||||
|
||||
if (!mComments.isEmpty())
|
||||
{
|
||||
@@ -99,6 +97,40 @@ void lcModelProperties::SaveLDraw(QTextStream& Stream) const
|
||||
// lcVector3 mAmbientColor;
|
||||
}
|
||||
|
||||
bool lcModelProperties::ParseLDrawHeader(QString Line, bool FirstLine)
|
||||
{
|
||||
QTextStream LineStream(&Line, QIODevice::ReadOnly);
|
||||
|
||||
QString Token;
|
||||
LineStream >> Token;
|
||||
int StartPos = LineStream.pos();
|
||||
LineStream >> Token;
|
||||
|
||||
if (Token == QLatin1String("!LEOCAD"))
|
||||
return false;
|
||||
|
||||
if (FirstLine)
|
||||
{
|
||||
LineStream.seek(StartPos);
|
||||
mDescription = LineStream.readLine().mid(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == QLatin1String("Name:"))
|
||||
{
|
||||
mModelName = LineStream.readLine().mid(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == QLatin1String("Author:"))
|
||||
{
|
||||
mAuthor = LineStream.readLine().mid(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void lcModelProperties::ParseLDrawLine(QTextStream& Stream)
|
||||
{
|
||||
QString Token;
|
||||
@@ -148,9 +180,10 @@ void lcModelProperties::ParseLDrawLine(QTextStream& Stream)
|
||||
}
|
||||
}
|
||||
|
||||
lcModel::lcModel(const QString& Name)
|
||||
lcModel::lcModel(const QString& FileName)
|
||||
{
|
||||
mProperties.mName = Name;
|
||||
mProperties.mModelName = FileName;
|
||||
mProperties.mFileName = FileName;
|
||||
mProperties.LoadDefaults();
|
||||
|
||||
mActive = false;
|
||||
@@ -259,7 +292,7 @@ void lcModel::DeleteModel()
|
||||
void lcModel::CreatePieceInfo(Project* Project)
|
||||
{
|
||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||
mPieceInfo = Library->FindPiece(mProperties.mName.toLatin1().constData(), Project, true, false);
|
||||
mPieceInfo = Library->FindPiece(mProperties.mFileName.toLatin1().constData(), Project, true, false);
|
||||
mPieceInfo->SetModel(this, true, Project, true);
|
||||
Library->LoadPieceInfo(mPieceInfo, true, true);
|
||||
}
|
||||
@@ -492,13 +525,13 @@ int lcModel::SplitMPD(QIODevice& Device)
|
||||
|
||||
if (Token == QLatin1String("FILE"))
|
||||
{
|
||||
if (!mProperties.mName.isEmpty())
|
||||
if (!mProperties.mFileName.isEmpty())
|
||||
{
|
||||
Device.seek(Pos);
|
||||
break;
|
||||
}
|
||||
|
||||
mProperties.mName = LineStream.readAll().trimmed();
|
||||
SetFileName(LineStream.readAll().trimmed());
|
||||
ModelPos = Pos;
|
||||
}
|
||||
else if (Token == QLatin1String("NOFILE"))
|
||||
@@ -524,6 +557,8 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
||||
mProperties.mAuthor.clear();
|
||||
mProperties.mDescription.clear();
|
||||
mProperties.mComments.clear();
|
||||
bool ReadingHeader = true;
|
||||
bool FirstLine = true;
|
||||
|
||||
while (!Device.atEnd())
|
||||
{
|
||||
@@ -543,7 +578,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
||||
{
|
||||
QString Name = LineStream.readAll().trimmed();
|
||||
|
||||
if (mProperties.mName != Name)
|
||||
if (mProperties.mFileName != Name)
|
||||
{
|
||||
Device.seek(Pos);
|
||||
break;
|
||||
@@ -555,7 +590,17 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (Token == QLatin1String("STEP"))
|
||||
|
||||
if (ReadingHeader)
|
||||
{
|
||||
ReadingHeader = mProperties.ParseLDrawHeader(Line, FirstLine);
|
||||
FirstLine = false;
|
||||
|
||||
if (ReadingHeader)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Token == QLatin1String("STEP"))
|
||||
{
|
||||
CurrentStep++;
|
||||
mFileLines.append(OriginalLine);
|
||||
@@ -645,6 +690,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
||||
}
|
||||
else if (Token == QLatin1String("1"))
|
||||
{
|
||||
ReadingHeader = false;
|
||||
int ColorCode;
|
||||
LineStream >> ColorCode;
|
||||
|
||||
@@ -691,7 +737,12 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
||||
}
|
||||
}
|
||||
else
|
||||
mFileLines.append(OriginalLine);
|
||||
{
|
||||
ReadingHeader = false;
|
||||
mFileLines.append(OriginalLine);
|
||||
}
|
||||
|
||||
FirstLine = false;
|
||||
}
|
||||
|
||||
mCurrentStep = CurrentStep;
|
||||
|
||||
+12
-8
@@ -51,7 +51,7 @@ public:
|
||||
|
||||
bool operator==(const lcModelProperties& Properties)
|
||||
{
|
||||
if (mName != Properties.mName || mAuthor != Properties.mAuthor ||
|
||||
if (mFileName != Properties.mFileName || mModelName != Properties.mModelName || mAuthor != Properties.mAuthor ||
|
||||
mDescription != Properties.mDescription || mComments != Properties.mComments)
|
||||
return false;
|
||||
|
||||
@@ -67,11 +67,13 @@ public:
|
||||
}
|
||||
|
||||
void SaveLDraw(QTextStream& Stream) const;
|
||||
bool ParseLDrawHeader(QString Line, bool FirstLine);
|
||||
void ParseLDrawLine(QTextStream& Stream);
|
||||
|
||||
QString mName;
|
||||
QString mAuthor;
|
||||
QString mFileName;
|
||||
QString mDescription;
|
||||
QString mModelName;
|
||||
QString mAuthor;
|
||||
QString mComments;
|
||||
|
||||
lcBackgroundType mBackgroundType;
|
||||
@@ -93,7 +95,7 @@ struct lcModelHistoryEntry
|
||||
class lcModel
|
||||
{
|
||||
public:
|
||||
lcModel(const QString& Name);
|
||||
lcModel(const QString& FileName);
|
||||
~lcModel();
|
||||
|
||||
bool IsModified() const
|
||||
@@ -137,14 +139,16 @@ public:
|
||||
return mProperties;
|
||||
}
|
||||
|
||||
void SetName(const QString& Name)
|
||||
void SetFileName(const QString& FileName)
|
||||
{
|
||||
mProperties.mName = Name;
|
||||
if (mProperties.mModelName == mProperties.mFileName)
|
||||
mProperties.mModelName = FileName;
|
||||
mProperties.mFileName = FileName;
|
||||
}
|
||||
|
||||
const QString& GetName()
|
||||
const QString& GetFileName() const
|
||||
{
|
||||
return mProperties.mName;
|
||||
return mProperties.mFileName;
|
||||
}
|
||||
|
||||
void SetDescription(const QString& Description)
|
||||
|
||||
+2
-2
@@ -61,9 +61,9 @@ void PieceInfo::SetModel(lcModel* Model, bool UpdateMesh, Project* CurrentProjec
|
||||
mModel = Model;
|
||||
}
|
||||
|
||||
strncpy(mFileName, Model->GetProperties().mName.toLatin1().data(), sizeof(mFileName));
|
||||
strncpy(mFileName, Model->GetProperties().mFileName.toLatin1().data(), sizeof(mFileName));
|
||||
mFileName[sizeof(mFileName)-1] = 0;
|
||||
strncpy(m_strDescription, Model->GetProperties().mName.toLatin1().data(), sizeof(m_strDescription));
|
||||
strncpy(m_strDescription, Model->GetProperties().mFileName.toLatin1().data(), sizeof(m_strDescription));
|
||||
m_strDescription[sizeof(m_strDescription)-1] = 0;
|
||||
|
||||
const QStringList& MeshLines = Model->GetFileLines();
|
||||
|
||||
+25
-28
@@ -76,10 +76,10 @@ Project::~Project()
|
||||
mModels.DeleteAll();
|
||||
}
|
||||
|
||||
lcModel* Project::GetModel(const QString& Name) const
|
||||
lcModel* Project::GetModel(const QString& FileName) const
|
||||
{
|
||||
for (lcModel* Model : mModels)
|
||||
if (Model->GetProperties().mName == Name)
|
||||
if (Model->GetProperties().mFileName == FileName)
|
||||
return Model;
|
||||
|
||||
return nullptr;
|
||||
@@ -153,11 +153,11 @@ void Project::SetActiveModel(int ModelIndex)
|
||||
mActiveModel->UpdateInterface();
|
||||
}
|
||||
|
||||
void Project::SetActiveModel(const QString& ModelName)
|
||||
void Project::SetActiveModel(const QString& FileName)
|
||||
{
|
||||
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
||||
{
|
||||
if (ModelName.compare(mModels[ModelIdx]->GetName(), Qt::CaseInsensitive) == 0)
|
||||
if (FileName.compare(mModels[ModelIdx]->GetFileName(), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
SetActiveModel(ModelIdx);
|
||||
return;
|
||||
@@ -237,7 +237,7 @@ lcModel* Project::CreateNewModel(bool ShowModel)
|
||||
QStringList ModelNames;
|
||||
|
||||
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
||||
ModelNames.append(mModels[ModelIdx]->GetProperties().mName);
|
||||
ModelNames.append(mModels[ModelIdx]->GetProperties().mFileName);
|
||||
|
||||
QString Name = GetNewModelName(gMainWindow, tr("New Submodel"), QString(), ModelNames);
|
||||
|
||||
@@ -271,7 +271,7 @@ void Project::ShowModelListDialog()
|
||||
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
||||
{
|
||||
lcModel* Model = mModels[ModelIdx];
|
||||
Models.append(QPair<QString, lcModel*>(Model->GetProperties().mName, Model));
|
||||
Models.append(QPair<QString, lcModel*>(Model->GetProperties().mFileName, Model));
|
||||
}
|
||||
|
||||
lcQModelListDialog Dialog(gMainWindow, Models);
|
||||
@@ -292,9 +292,9 @@ void Project::ShowModelListDialog()
|
||||
Model->SetSaved();
|
||||
mModified = true;
|
||||
}
|
||||
else if (Model->GetProperties().mName != it->first)
|
||||
else if (Model->GetProperties().mFileName != it->first)
|
||||
{
|
||||
Model->SetName(it->first);
|
||||
Model->SetFileName(it->first);
|
||||
lcGetPiecesLibrary()->RenamePiece(Model->GetPieceInfo(), it->first.toLatin1().constData());
|
||||
|
||||
for (lcModel* CheckModel : mModels)
|
||||
@@ -377,7 +377,7 @@ bool Project::Load(const QString& FileName)
|
||||
lcModel* Model = new lcModel(QString());
|
||||
int Pos = Model->SplitMPD(Buffer);
|
||||
|
||||
if (Models.empty() || !Model->GetProperties().mName.isEmpty())
|
||||
if (Models.empty() || !Model->GetFileName().isEmpty())
|
||||
{
|
||||
mModels.Add(Model);
|
||||
Models.emplace_back(std::make_pair(Pos, Model));
|
||||
@@ -423,9 +423,9 @@ bool Project::Load(const QString& FileName)
|
||||
{
|
||||
lcModel* Model = mModels[0];
|
||||
|
||||
if (Model->GetProperties().mName.isEmpty())
|
||||
if (Model->GetProperties().mFileName.isEmpty())
|
||||
{
|
||||
Model->SetName(FileInfo.fileName());
|
||||
Model->SetFileName(FileInfo.fileName());
|
||||
lcGetPiecesLibrary()->RenamePiece(Model->GetPieceInfo(), FileInfo.fileName().toLatin1());
|
||||
}
|
||||
}
|
||||
@@ -476,7 +476,7 @@ bool Project::Save(QTextStream& Stream)
|
||||
for (lcModel* Model : mModels)
|
||||
{
|
||||
if (MPD)
|
||||
Stream << QLatin1String("0 FILE ") << Model->GetProperties().mName << QLatin1String("\r\n");
|
||||
Stream << QLatin1String("0 FILE ") << Model->GetProperties().mFileName << QLatin1String("\r\n");
|
||||
|
||||
Model->SaveLDraw(Stream, false);
|
||||
Model->SetSaved();
|
||||
@@ -492,7 +492,7 @@ void Project::Merge(Project* Other)
|
||||
{
|
||||
for (lcModel* Model : Other->mModels)
|
||||
{
|
||||
QString Name = Model->GetProperties().mName;
|
||||
QString FileName = Model->GetProperties().mFileName;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@@ -500,7 +500,7 @@ void Project::Merge(Project* Other)
|
||||
|
||||
for (int SearchIdx = 0; SearchIdx < mModels.GetSize(); SearchIdx++)
|
||||
{
|
||||
if (mModels[SearchIdx]->GetProperties().mName == Name)
|
||||
if (mModels[SearchIdx]->GetProperties().mFileName == FileName)
|
||||
{
|
||||
Duplicate = true;
|
||||
break;
|
||||
@@ -510,8 +510,8 @@ void Project::Merge(Project* Other)
|
||||
if (!Duplicate)
|
||||
break;
|
||||
|
||||
Name = tr("Merged ") + Name;
|
||||
Model->SetName(Name);
|
||||
FileName = tr("Merged ") + FileName;
|
||||
Model->SetFileName(FileName);
|
||||
}
|
||||
|
||||
mModels.Add(Model);
|
||||
@@ -533,7 +533,8 @@ bool Project::ImportLDD(const QString& FileName)
|
||||
return false;
|
||||
|
||||
mModels.DeleteAll();
|
||||
lcModel* Model = new lcModel(QString());
|
||||
QString ModelName = QFileInfo(FileName).completeBaseName();
|
||||
lcModel* Model = new lcModel(ModelName);
|
||||
|
||||
if (Model->LoadLDD(QString::fromUtf8((const char*)XMLFile.mBuffer)))
|
||||
{
|
||||
@@ -546,9 +547,6 @@ bool Project::ImportLDD(const QString& FileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Model->GetProperties().mName.isEmpty())
|
||||
Model->SetName(QFileInfo(FileName).completeBaseName());
|
||||
|
||||
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
||||
mModels[ModelIdx]->CreatePieceInfo(this);
|
||||
|
||||
@@ -569,7 +567,7 @@ bool Project::ImportInventory(const QByteArray& Inventory, const QString& Name,
|
||||
return false;
|
||||
|
||||
mModels.DeleteAll();
|
||||
lcModel* Model = new lcModel(QString());
|
||||
lcModel* Model = new lcModel(Name);
|
||||
|
||||
if (Model->LoadInventory(Inventory))
|
||||
{
|
||||
@@ -582,7 +580,6 @@ bool Project::ImportInventory(const QByteArray& Inventory, const QString& Name,
|
||||
return false;
|
||||
}
|
||||
|
||||
Model->SetName(Name);
|
||||
Model->SetDescription(Description);
|
||||
|
||||
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
||||
@@ -1528,8 +1525,8 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options)
|
||||
|
||||
if (Models.GetSize() > 1)
|
||||
{
|
||||
BaseName += '-' + Model->GetProperties().mName;
|
||||
PageTitle = Model->GetProperties().mName;
|
||||
BaseName += '-' + Model->GetProperties().mFileName;
|
||||
PageTitle = Model->GetProperties().mFileName;
|
||||
}
|
||||
else
|
||||
PageTitle = ProjectTitle;
|
||||
@@ -1675,24 +1672,24 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options)
|
||||
for (int ModelIdx = 0; ModelIdx < Models.GetSize(); ModelIdx++)
|
||||
{
|
||||
lcModel* Model = Models[ModelIdx];
|
||||
BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1) + '-' + Model->GetProperties().mName;
|
||||
BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1) + '-' + Model->GetProperties().mFileName;
|
||||
BaseName.replace('#', '_');
|
||||
|
||||
if (Options.SinglePage)
|
||||
{
|
||||
FileName = BaseName + QLatin1String(".html");
|
||||
Stream << QString::fromLatin1("<p><a href=\"%1\">%2</a>").arg(FileName, Model->GetProperties().mName);
|
||||
Stream << QString::fromLatin1("<p><a href=\"%1\">%2</a>").arg(FileName, Model->GetProperties().mFileName);
|
||||
}
|
||||
else if (Options.IndexPage)
|
||||
{
|
||||
FileName = BaseName + QLatin1String("-index.html");
|
||||
Stream << QString::fromLatin1("<p><a href=\"%1\">%2</a>").arg(FileName, Model->GetProperties().mName);
|
||||
Stream << QString::fromLatin1("<p><a href=\"%1\">%2</a>").arg(FileName, Model->GetProperties().mFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcStep LastStep = Model->GetLastStep();
|
||||
|
||||
Stream << QString::fromLatin1("<p>%1</p>").arg(Model->GetProperties().mName);
|
||||
Stream << QString::fromLatin1("<p>%1</p>").arg(Model->GetProperties().mFileName);
|
||||
|
||||
for (lcStep Step = 1; Step <= LastStep; Step++)
|
||||
Stream << QString::fromLatin1("<A HREF=\"%1-%2.html\">Step %3<BR>\r\n</A>").arg(BaseName, QString("%1").arg(Step, 2, 10, QLatin1Char('0')), QString::number(Step));
|
||||
|
||||
+2
-2
@@ -47,7 +47,7 @@ public:
|
||||
return mModels;
|
||||
}
|
||||
|
||||
lcModel* GetModel(const QString& Name) const;
|
||||
lcModel* GetModel(const QString& FileName) const;
|
||||
|
||||
lcModel* GetActiveModel() const
|
||||
{
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
std::vector<std::pair<lcModel*, lcStep>> GetPageLayouts() const;
|
||||
|
||||
void SetActiveModel(int ModelIndex);
|
||||
void SetActiveModel(const QString& ModelName);
|
||||
void SetActiveModel(const QString& FileName);
|
||||
|
||||
lcModel* CreateNewModel(bool ShowModel);
|
||||
QString GetNewModelName(QWidget* ParentWidget, const QString& DialogTitle, const QString& CurrentName, const QStringList& ExistingModels) const;
|
||||
|
||||
@@ -42,7 +42,7 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
|
||||
|
||||
options = (lcPropertiesDialogOptions*)data;
|
||||
|
||||
setWindowTitle(tr("%1 Properties").arg(options->Properties.mName));
|
||||
setWindowTitle(tr("%1 Properties").arg(options->Properties.mFileName));
|
||||
|
||||
ui->descriptionEdit->setText(options->Properties.mDescription);
|
||||
ui->authorEdit->setText(options->Properties.mAuthor);
|
||||
|
||||
Reference in New Issue
Block a user