Fixed comments in saved files being moved in some cases. Fixes #35, #36.

This commit is contained in:
Leonardo Zide 2017-03-18 17:42:34 -07:00
parent 29aae2b6be
commit 9b933b6c57
2 changed files with 30 additions and 6 deletions

View file

@ -278,12 +278,10 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
mProperties.SaveLDraw(Stream);
if (mCurrentStep != GetLastStep())
Stream << QLatin1String("0 !LEOCAD MODEL CURRENT_STEP") << mCurrentStep << LineEnding;
lcArray<lcGroup*> CurrentGroups;
lcStep Step = 1;
int CurrentLine = 0;
int AddedSteps = 0;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
@ -315,13 +313,18 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
}
if (!Skip)
{
Stream << mFileLines[CurrentLine];
if (AddedSteps > 0)
AddedSteps--;
}
CurrentLine++;
}
while (Piece->GetStepShow() > Step)
{
Stream << QLatin1String("0 STEP\r\n");
AddedSteps++;
Step++;
}
@ -401,6 +404,22 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly) const
while (CurrentLine < mFileLines.size())
{
QString Line = mFileLines[CurrentLine];
QTextStream LineStream(&Line, QIODevice::ReadOnly);
QString Token;
LineStream >> Token;
bool Skip = false;
if (Token == QLatin1String("0"))
{
LineStream >> Token;
if (Token == QLatin1String("STEP") && AddedSteps-- > 0)
Skip = true;
}
if (!Skip)
Stream << mFileLines[CurrentLine];
CurrentLine++;
}
@ -1030,6 +1049,7 @@ void lcModel::Paste()
lcPiece* Piece = PastedPieces[PieceIdx];
lcStep Step = Piece->GetStepShow();
Piece->SetFileLine(-1);
if (Step > mCurrentStep)
Piece->SetStepShow(mCurrentStep);
@ -2270,6 +2290,7 @@ void lcModel::MoveSelectionToModel(lcModel* Model)
for (int PieceIdx = 0; PieceIdx < Pieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = Pieces[PieceIdx];
Piece->SetFileLine(-1);
Piece->SetStepShow(Piece->GetStepShow() - FirstStep + 1);
Model->AddPiece(Piece);
}

View file

@ -439,8 +439,11 @@ public:
if (Step == LC_STEP_MAX)
Step = LC_STEP_MAX - 1;
if (mStepShow != Step)
{
mFileLine = -1;
mStepShow = Step;
}
if (mStepHide <= mStepShow)
mStepHide = mStepShow + 1;