mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Preserve file comments when saving.
This commit is contained in:
parent
39ef058aaa
commit
35fe45ada8
8 changed files with 156 additions and 89 deletions
|
@ -360,6 +360,11 @@ inline bool operator==(const lcVector3& a, const lcVector3& b)
|
|||
return a.x == b.x && a.y == b.y && a.z == b.z;
|
||||
}
|
||||
|
||||
inline bool operator!=(const lcVector3& a, const lcVector3& b)
|
||||
{
|
||||
return a.x != b.x || a.y != b.y || a.z != b.z;
|
||||
}
|
||||
|
||||
inline void lcVector3::Normalize()
|
||||
{
|
||||
float InvLength = 1.0f / Length();
|
||||
|
|
|
@ -63,16 +63,21 @@ void lcModelProperties::SaveLDraw(QTextStream& Stream, bool MPD) const
|
|||
Stream << QLatin1String("0 !LEOCAD MODEL COMMENT ") << Comment << LineEnding;
|
||||
}
|
||||
|
||||
for (int BackgroundIdx = 0; BackgroundIdx < LC_NUM_BACKGROUND_TYPES; BackgroundIdx++)
|
||||
{
|
||||
switch ((mBackgroundType + 1 + BackgroundIdx) % LC_NUM_BACKGROUND_TYPES)
|
||||
bool TypeChanged = (mBackgroundType != lcGetDefaultProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TYPE));
|
||||
|
||||
switch (mBackgroundType)
|
||||
{
|
||||
case LC_BACKGROUND_SOLID:
|
||||
if (mBackgroundSolidColor != lcVector3FromColor(lcGetDefaultProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_COLOR)) || TypeChanged)
|
||||
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND COLOR ") << mBackgroundSolidColor[0] << ' ' << mBackgroundSolidColor[1] << ' ' << mBackgroundSolidColor[2] << LineEnding;
|
||||
break;
|
||||
|
||||
case LC_BACKGROUND_GRADIENT:
|
||||
if (mBackgroundGradientColor1 != lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR1)) ||
|
||||
mBackgroundGradientColor2 != lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR2)) || TypeChanged)
|
||||
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND GRADIENT ") << mBackgroundGradientColor1[0] << ' ' << mBackgroundGradientColor1[1] << ' ' << mBackgroundGradientColor1[2] << ' ' << mBackgroundGradientColor2[0] << ' ' << mBackgroundGradientColor2[1] << ' ' << mBackgroundGradientColor2[2] << LineEnding;
|
||||
break;
|
||||
|
||||
case LC_BACKGROUND_IMAGE:
|
||||
if (!mBackgroundImage.isEmpty())
|
||||
{
|
||||
|
@ -83,7 +88,6 @@ void lcModelProperties::SaveLDraw(QTextStream& Stream, bool MPD) const
|
|||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// bool mFogEnabled;
|
||||
// float mFogDensity;
|
||||
|
@ -205,7 +209,7 @@ void lcModel::DeleteModel()
|
|||
mCameras.DeleteAll();
|
||||
mLights.DeleteAll();
|
||||
mGroups.DeleteAll();
|
||||
mMeshLines.clear();
|
||||
mFileLines.clear();
|
||||
}
|
||||
|
||||
void lcModel::CreatePieceInfo(Project* Project)
|
||||
|
@ -275,21 +279,32 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool MPD, bool SelectedOnly) const
|
|||
|
||||
mProperties.SaveLDraw(Stream, MPD);
|
||||
|
||||
lcStep LastStep = GetLastStep();
|
||||
if (mCurrentStep != LastStep)
|
||||
if (mCurrentStep != GetLastStep())
|
||||
Stream << QLatin1String("0 !LEOCAD MODEL CURRENT_STEP") << mCurrentStep << LineEnding;
|
||||
|
||||
lcArray<lcGroup*> CurrentGroups;
|
||||
lcStep Step = 1;
|
||||
int CurrentLine = 0;
|
||||
|
||||
for (lcStep Step = 1; Step <= LastStep; Step++)
|
||||
{
|
||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
lcPiece* Piece = mPieces[PieceIdx];
|
||||
|
||||
if (Piece->GetStepShow() != Step || (SelectedOnly && !Piece->IsSelected()))
|
||||
if (SelectedOnly && !Piece->IsSelected())
|
||||
continue;
|
||||
|
||||
while (Piece->GetFileLine() > CurrentLine && CurrentLine < mFileLines.size())
|
||||
{
|
||||
Stream << mFileLines[CurrentLine];
|
||||
CurrentLine++;
|
||||
}
|
||||
|
||||
while (Piece->GetStepShow() < Step)
|
||||
{
|
||||
Stream << QLatin1String("0 STEP\r\n");
|
||||
Step++;
|
||||
}
|
||||
|
||||
lcGroup* PieceGroup = Piece->GetGroup();
|
||||
|
||||
if (PieceGroup)
|
||||
|
@ -340,8 +355,10 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool MPD, bool SelectedOnly) const
|
|||
Piece->SaveLDraw(Stream);
|
||||
}
|
||||
|
||||
if (Step != LastStep)
|
||||
Stream << QLatin1String("0 STEP\r\n");
|
||||
while (CurrentLine < mFileLines.size())
|
||||
{
|
||||
Stream << mFileLines[CurrentLine];
|
||||
CurrentLine++;
|
||||
}
|
||||
|
||||
while (CurrentGroups.GetSize())
|
||||
|
@ -380,9 +397,9 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
|||
while (!Device.atEnd())
|
||||
{
|
||||
qint64 Pos = Device.pos();
|
||||
QString Line = Device.readLine().trimmed();
|
||||
QString OriginalLine = Device.readLine();
|
||||
QString Line = OriginalLine.trimmed();
|
||||
QTextStream LineStream(&Line, QIODevice::ReadOnly);
|
||||
bool MeshLine = false;
|
||||
|
||||
QString Token;
|
||||
LineStream >> Token;
|
||||
|
@ -413,7 +430,10 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
|||
}
|
||||
|
||||
if (Token != QLatin1String("!LEOCAD"))
|
||||
{
|
||||
mFileLines.append(OriginalLine);
|
||||
continue;
|
||||
}
|
||||
|
||||
LineStream >> Token;
|
||||
|
||||
|
@ -489,7 +509,9 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
|||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||
|
||||
if (Library->IsPrimitive(PartID.toLatin1().constData()))
|
||||
MeshLine = true;
|
||||
{
|
||||
mFileLines.append(OriginalLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Piece)
|
||||
|
@ -507,6 +529,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
|||
lcMatrix44 Transform(lcVector4(Matrix[0], Matrix[2], -Matrix[1], 0.0f), lcVector4(Matrix[8], Matrix[10], -Matrix[9], 0.0f),
|
||||
lcVector4(-Matrix[4], -Matrix[6], Matrix[5], 0.0f), lcVector4(Matrix[12], Matrix[14], -Matrix[13], 1.0f));
|
||||
|
||||
Piece->SetFileLine(mFileLines.size());
|
||||
Piece->SetPieceInfo(Info);
|
||||
Piece->Initialize(Transform, CurrentStep);
|
||||
Piece->SetColorCode(ColorCode);
|
||||
|
@ -514,11 +537,8 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
|||
Piece = NULL;
|
||||
}
|
||||
}
|
||||
else if (Token == QLatin1String("2") || Token == QLatin1String("3") || Token == QLatin1String("4"))
|
||||
MeshLine = true;
|
||||
|
||||
if (MeshLine)
|
||||
mMeshLines.append(Line);
|
||||
else
|
||||
mFileLines.append(OriginalLine);
|
||||
}
|
||||
|
||||
mCurrentStep = CurrentStep;
|
||||
|
@ -816,6 +836,7 @@ void lcModel::Merge(lcModel* Other)
|
|||
for (int PieceIdx = 0; PieceIdx < Other->mPieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
lcPiece* Piece = Other->mPieces[PieceIdx];
|
||||
Piece->SetFileLine(-1);
|
||||
AddPiece(Piece);
|
||||
}
|
||||
|
||||
|
@ -1909,7 +1930,11 @@ void lcModel::ShowSelectedPiecesEarlier()
|
|||
return;
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < MovedPieces.GetSize(); PieceIdx++)
|
||||
AddPiece(MovedPieces[PieceIdx]);
|
||||
{
|
||||
lcPiece* Piece = MovedPieces[PieceIdx];
|
||||
Piece->SetFileLine(-1);
|
||||
AddPiece(Piece);
|
||||
}
|
||||
|
||||
SaveCheckpoint("Modifying");
|
||||
gMainWindow->UpdateAllViews();
|
||||
|
@ -1950,7 +1975,11 @@ void lcModel::ShowSelectedPiecesLater()
|
|||
return;
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < MovedPieces.GetSize(); PieceIdx++)
|
||||
AddPiece(MovedPieces[PieceIdx]);
|
||||
{
|
||||
lcPiece* Piece = MovedPieces[PieceIdx];
|
||||
Piece->SetFileLine(-1);
|
||||
AddPiece(Piece);
|
||||
}
|
||||
|
||||
SaveCheckpoint("Modifying");
|
||||
gMainWindow->UpdateAllViews();
|
||||
|
|
|
@ -165,9 +165,9 @@ public:
|
|||
mProperties.mName = Name;
|
||||
}
|
||||
|
||||
const QStringList& GetMeshLines() const
|
||||
const QStringList& GetFileLines() const
|
||||
{
|
||||
return mMeshLines;
|
||||
return mFileLines;
|
||||
}
|
||||
|
||||
lcStep GetLastStep() const;
|
||||
|
@ -345,7 +345,7 @@ protected:
|
|||
lcArray<lcCamera*> mCameras;
|
||||
lcArray<lcLight*> mLights;
|
||||
lcArray<lcGroup*> mGroups;
|
||||
QStringList mMeshLines;
|
||||
QStringList mFileLines;
|
||||
|
||||
lcModelHistoryEntry* mSavedHistory;
|
||||
lcArray<lcModelHistoryEntry*> mUndoHistory;
|
||||
|
|
|
@ -112,6 +112,21 @@ void lcRemoveProfileKey(LC_PROFILE_KEY Key)
|
|||
Settings.remove(QString("%1/%2").arg(Entry.mSection, Entry.mKey));
|
||||
}
|
||||
|
||||
int lcGetDefaultProfileInt(LC_PROFILE_KEY Key)
|
||||
{
|
||||
return gProfileEntries[Key].mDefault.IntValue;
|
||||
}
|
||||
|
||||
float lcGetDefaultProfileFloat(LC_PROFILE_KEY Key)
|
||||
{
|
||||
return gProfileEntries[Key].mDefault.FloatValue;
|
||||
}
|
||||
|
||||
QString lcGetDefaultProfileString(LC_PROFILE_KEY Key)
|
||||
{
|
||||
return QString::fromLatin1(gProfileEntries[Key].mDefault.StringValue);
|
||||
}
|
||||
|
||||
int lcGetProfileInt(LC_PROFILE_KEY Key)
|
||||
{
|
||||
lcProfileEntry& Entry = gProfileEntries[Key];
|
||||
|
|
|
@ -97,6 +97,10 @@ extern lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS];
|
|||
|
||||
void lcRemoveProfileKey(LC_PROFILE_KEY Key);
|
||||
|
||||
int lcGetDefaultProfileInt(LC_PROFILE_KEY Key);
|
||||
float lcGetDefaultProfileFloat(LC_PROFILE_KEY Key);
|
||||
QString lcGetDefaultProfileString(LC_PROFILE_KEY Key);
|
||||
|
||||
int lcGetProfileInt(LC_PROFILE_KEY Key);
|
||||
float lcGetProfileFloat(LC_PROFILE_KEY Key);
|
||||
QString lcGetProfileString(LC_PROFILE_KEY Key);
|
||||
|
|
|
@ -32,6 +32,7 @@ lcPiece::lcPiece(PieceInfo* pPieceInfo)
|
|||
mStepShow = 1;
|
||||
mStepHide = LC_STEP_MAX;
|
||||
mGroup = NULL;
|
||||
mFileLine = -1;
|
||||
|
||||
if (mPieceInfo != NULL)
|
||||
mPieceInfo->AddRef();
|
||||
|
|
|
@ -91,6 +91,16 @@ public:
|
|||
void SaveLDraw(QTextStream& Stream) const;
|
||||
bool ParseLDrawLine(QTextStream& Stream);
|
||||
|
||||
void SetFileLine(int Line)
|
||||
{
|
||||
mFileLine = Line;
|
||||
}
|
||||
|
||||
int GetFileLine() const
|
||||
{
|
||||
return mFileLine;
|
||||
}
|
||||
|
||||
virtual void RayTest(lcObjectRayTest& ObjectRayTest) const;
|
||||
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const;
|
||||
virtual void DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) const;
|
||||
|
@ -150,6 +160,7 @@ public:
|
|||
|
||||
void SetStepShow(lcStep Step)
|
||||
{
|
||||
mFileLine = -1;
|
||||
mStepShow = Step;
|
||||
}
|
||||
|
||||
|
@ -187,6 +198,8 @@ protected:
|
|||
lcArray<lcObjectKey<lcVector3>> mPositionKeys;
|
||||
lcArray<lcObjectKey<lcMatrix33>> mRotationKeys;
|
||||
|
||||
int mFileLine;
|
||||
|
||||
// Atributes
|
||||
lcGroup* mGroup;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ void PieceInfo::SetModel(lcModel* Model, bool UpdateMesh)
|
|||
strncpy(m_strDescription, Model->GetProperties().mName.toLatin1().data(), sizeof(m_strDescription));
|
||||
m_strDescription[sizeof(m_strDescription)-1] = 0;
|
||||
|
||||
const QStringList& MeshLines = Model->GetMeshLines();
|
||||
const QStringList& MeshLines = Model->GetFileLines();
|
||||
|
||||
if (UpdateMesh && !MeshLines.isEmpty())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue