mirror of
https://github.com/leozide/leocad
synced 2025-02-06 08:46:06 +01:00
Removed binary file save.
This commit is contained in:
parent
6315ff0b55
commit
4e44915e49
7 changed files with 82 additions and 229 deletions
|
@ -234,24 +234,25 @@ void lcModel::SaveLDraw(QTextStream& Stream) const
|
||||||
mLights[LightIdx]->SaveLDraw(Stream);
|
mLights[LightIdx]->SaveLDraw(Stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcModel::LoadLDraw(const QStringList& Lines, const lcMatrix44& CurrentTransform, int& CurrentStep)
|
void lcModel::LoadLDraw(QTextStream& Stream)
|
||||||
{
|
{
|
||||||
lcPiece* Piece = NULL;
|
lcPiece* Piece = NULL;
|
||||||
lcCamera* Camera = NULL;
|
lcCamera* Camera = NULL;
|
||||||
lcLight* Light = NULL;
|
lcLight* Light = NULL;
|
||||||
lcArray<lcGroup*> CurrentGroups;
|
lcArray<lcGroup*> CurrentGroups;
|
||||||
|
int CurrentStep = 1;
|
||||||
|
|
||||||
for (int LineIdx = 0; LineIdx < Lines.size(); LineIdx++)
|
while (!Stream.atEnd())
|
||||||
{
|
{
|
||||||
QString Line = Lines[LineIdx].trimmed();
|
QString Line = Stream.readLine().trimmed();
|
||||||
QTextStream Stream(&Line, QIODevice::ReadOnly);
|
QTextStream LineStream(&Line, QIODevice::ReadOnly);
|
||||||
|
|
||||||
QString Token;
|
QString Token;
|
||||||
Stream >> Token;
|
LineStream >> Token;
|
||||||
|
|
||||||
if (Token == QLatin1String("0"))
|
if (Token == QLatin1String("0"))
|
||||||
{
|
{
|
||||||
Stream >> Token;
|
LineStream >> Token;
|
||||||
|
|
||||||
if (Token == QLatin1String("STEP"))
|
if (Token == QLatin1String("STEP"))
|
||||||
{
|
{
|
||||||
|
@ -262,28 +263,28 @@ void lcModel::LoadLDraw(const QStringList& Lines, const lcMatrix44& CurrentTrans
|
||||||
if (Token != QLatin1String("!LEOCAD"))
|
if (Token != QLatin1String("!LEOCAD"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Stream >> Token;
|
LineStream >> Token;
|
||||||
|
|
||||||
if (Token == QLatin1String("MODEL"))
|
if (Token == QLatin1String("MODEL"))
|
||||||
{
|
{
|
||||||
// if (!strcmp(Tokens[3], "CURRENT_STEP") && Tokens[4])
|
// if (!strcmp(Tokens[3], "CURRENT_STEP") && Tokens[4])
|
||||||
// mCurrentStep = atoi(Tokens[4]);
|
// mCurrentStep = atoi(Tokens[4]);
|
||||||
|
|
||||||
mProperties.ParseLDrawLine(Stream);
|
mProperties.ParseLDrawLine(LineStream);
|
||||||
}
|
}
|
||||||
else if (Token == QLatin1String("PIECE"))
|
else if (Token == QLatin1String("PIECE"))
|
||||||
{
|
{
|
||||||
if (!Piece)
|
if (!Piece)
|
||||||
Piece = new lcPiece(NULL);
|
Piece = new lcPiece(NULL);
|
||||||
|
|
||||||
Piece->ParseLDrawLine(Stream);
|
Piece->ParseLDrawLine(LineStream);
|
||||||
}
|
}
|
||||||
else if (Token == QLatin1String("CAMERA"))
|
else if (Token == QLatin1String("CAMERA"))
|
||||||
{
|
{
|
||||||
if (!Camera)
|
if (!Camera)
|
||||||
Camera = new lcCamera(false);
|
Camera = new lcCamera(false);
|
||||||
|
|
||||||
if (Camera->ParseLDrawLine(Stream))
|
if (Camera->ParseLDrawLine(LineStream))
|
||||||
{
|
{
|
||||||
Camera->CreateName(mCameras);
|
Camera->CreateName(mCameras);
|
||||||
mCameras.Add(Camera);
|
mCameras.Add(Camera);
|
||||||
|
@ -295,15 +296,17 @@ void lcModel::LoadLDraw(const QStringList& Lines, const lcMatrix44& CurrentTrans
|
||||||
}
|
}
|
||||||
else if (Token == QLatin1String("GROUP"))
|
else if (Token == QLatin1String("GROUP"))
|
||||||
{
|
{
|
||||||
Stream >> Token;
|
LineStream >> Token;
|
||||||
|
|
||||||
if (Token == QLatin1String("BEGIN"))
|
if (Token == QLatin1String("BEGIN"))
|
||||||
{
|
{
|
||||||
QString Name = Stream.readAll().trimmed();
|
QString Name = LineStream.readAll().trimmed();
|
||||||
QByteArray NameUtf = Name.toUtf8(); // todo: replace with qstring
|
QByteArray NameUtf = Name.toUtf8(); // todo: replace with qstring
|
||||||
lcGroup* Group = GetGroup(NameUtf.constData(), true);
|
lcGroup* Group = GetGroup(NameUtf.constData(), true);
|
||||||
if (!CurrentGroups.IsEmpty())
|
if (!CurrentGroups.IsEmpty())
|
||||||
Group->mGroup = CurrentGroups[CurrentGroups.GetSize() - 1];
|
Group->mGroup = CurrentGroups[CurrentGroups.GetSize() - 1];
|
||||||
|
else
|
||||||
|
Group->mGroup = NULL;
|
||||||
CurrentGroups.Add(Group);
|
CurrentGroups.Add(Group);
|
||||||
}
|
}
|
||||||
else if (Token == QLatin1String("END"))
|
else if (Token == QLatin1String("END"))
|
||||||
|
@ -318,19 +321,17 @@ void lcModel::LoadLDraw(const QStringList& Lines, const lcMatrix44& CurrentTrans
|
||||||
else if (Token == QLatin1String("1"))
|
else if (Token == QLatin1String("1"))
|
||||||
{
|
{
|
||||||
int ColorCode;
|
int ColorCode;
|
||||||
Stream >> ColorCode;
|
LineStream >> ColorCode;
|
||||||
|
|
||||||
float Matrix[12];
|
float Matrix[12];
|
||||||
for (int TokenIdx = 0; TokenIdx < 12; TokenIdx++)
|
for (int TokenIdx = 0; TokenIdx < 12; TokenIdx++)
|
||||||
Stream >> Matrix[TokenIdx];
|
LineStream >> Matrix[TokenIdx];
|
||||||
|
|
||||||
lcMatrix44 IncludeTransform(lcVector4(Matrix[3], Matrix[6], Matrix[9], 0.0f), lcVector4(Matrix[4], Matrix[7], Matrix[10], 0.0f),
|
lcMatrix44 IncludeTransform(lcVector4(Matrix[3], Matrix[6], Matrix[9], 0.0f), lcVector4(Matrix[4], Matrix[7], Matrix[10], 0.0f),
|
||||||
lcVector4(Matrix[5], Matrix[8], Matrix[11], 0.0f), lcVector4(Matrix[0], Matrix[1], Matrix[2], 1.0f));
|
lcVector4(Matrix[5], Matrix[8], Matrix[11], 0.0f), lcVector4(Matrix[0], Matrix[1], Matrix[2], 1.0f));
|
||||||
|
|
||||||
IncludeTransform = lcMul(IncludeTransform, CurrentTransform);
|
|
||||||
|
|
||||||
QString File;
|
QString File;
|
||||||
Stream >> File;
|
LineStream >> File;
|
||||||
|
|
||||||
QString PartID = File.toUpper();
|
QString PartID = File.toUpper();
|
||||||
if (PartID.endsWith(QLatin1String(".DAT")))
|
if (PartID.endsWith(QLatin1String(".DAT")))
|
||||||
|
|
|
@ -96,7 +96,7 @@ enum lcTool
|
||||||
|
|
||||||
struct lcModelHistoryEntry
|
struct lcModelHistoryEntry
|
||||||
{
|
{
|
||||||
lcMemFile File;
|
QByteArray File;
|
||||||
char Description[64];
|
char Description[64];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ public:
|
||||||
lcGroup* GetGroup(const char* Name, bool CreateIfMissing);
|
lcGroup* GetGroup(const char* Name, bool CreateIfMissing);
|
||||||
|
|
||||||
void SaveLDraw(QTextStream& Stream) const;
|
void SaveLDraw(QTextStream& Stream) const;
|
||||||
void LoadLDraw(const QStringList& Lines, const lcMatrix44& CurrentTransform, int& CurrentStep);
|
void LoadLDraw(QTextStream& Stream);
|
||||||
|
|
||||||
void SaveBinary(lcFile& File) const;
|
void SaveBinary(lcFile& File) const;
|
||||||
void LoadBinary(lcFile& File);
|
void LoadBinary(lcFile& File);
|
||||||
|
|
|
@ -50,15 +50,6 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lcLight::FileLoad(lcFile& file)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void lcLight::FileSave(lcFile& file) const
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void lcLight::CreateName(const lcArray<lcLight*>& Lights)
|
void lcLight::CreateName(const lcArray<lcLight*>& Lights)
|
||||||
{
|
{
|
||||||
int i, max = 0;
|
int i, max = 0;
|
||||||
|
|
|
@ -197,8 +197,6 @@ public:
|
||||||
void Move(lcStep Step, bool AddKey, const lcVector3& Distance);
|
void Move(lcStep Step, bool AddKey, const lcVector3& Distance);
|
||||||
bool Setup(int LightIndex);
|
bool Setup(int LightIndex);
|
||||||
void CreateName(const lcArray<lcLight*>& Lights);
|
void CreateName(const lcArray<lcLight*>& Lights);
|
||||||
bool FileLoad(lcFile& file);
|
|
||||||
void FileSave(lcFile& file) const;
|
|
||||||
|
|
||||||
// Temporary parameters
|
// Temporary parameters
|
||||||
lcMatrix44 mWorldLight;
|
lcMatrix44 mWorldLight;
|
||||||
|
|
|
@ -150,7 +150,6 @@ void Project::LoadDefaults(bool cameras)
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Standard file menu commands
|
// Standard file menu commands
|
||||||
|
|
||||||
// Read a .lcd file
|
|
||||||
bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
{
|
{
|
||||||
lcint32 i, count;
|
lcint32 i, count;
|
||||||
|
@ -213,7 +212,6 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
file->ReadU32();//m_nScene
|
file->ReadU32();//m_nScene
|
||||||
|
|
||||||
file->ReadS32(&count, 1);
|
file->ReadS32(&count, 1);
|
||||||
// SystemStartProgressBar(0, count, 1, "Loading project...");
|
|
||||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||||
Library->OpenCache();
|
Library->OpenCache();
|
||||||
|
|
||||||
|
@ -270,12 +268,9 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
// pPiece->SetGroup((lcGroup*)group);
|
// pPiece->SetGroup((lcGroup*)group);
|
||||||
SystemPieceComboAdd(pInfo->m_strDescription);
|
SystemPieceComboAdd(pInfo->m_strDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SytemStepProgressBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Library->CloseCache();
|
Library->CloseCache();
|
||||||
// SytemEndProgressBar();
|
|
||||||
|
|
||||||
if (!bMerge)
|
if (!bMerge)
|
||||||
{
|
{
|
||||||
|
@ -411,16 +406,9 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
if (fv >= 0.6f)
|
if (fv >= 0.6f)
|
||||||
{
|
{
|
||||||
if (fv < 1.0f)
|
if (fv < 1.0f)
|
||||||
{
|
file->Seek(4, SEEK_CUR);
|
||||||
lcuint32 ViewportMode;
|
|
||||||
file->ReadU32(&ViewportMode, 1);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
file->Seek(2, SEEK_CUR);
|
||||||
lcuint8 ViewportMode, ActiveViewport;
|
|
||||||
file->ReadU8(&ViewportMode, 1);
|
|
||||||
file->ReadU8(&ActiveViewport, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
file->ReadS32(&count, 1);
|
file->ReadS32(&count, 1);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
|
@ -442,15 +430,7 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
|
|
||||||
if (fv >= 0.7f)
|
if (fv >= 0.7f)
|
||||||
{
|
{
|
||||||
for (count = 0; count < 4; count++)
|
file->Seek(16, SEEK_CUR);
|
||||||
{
|
|
||||||
file->ReadS32(&i, 1);
|
|
||||||
|
|
||||||
// lcCamera* pCam = m_pCameras;
|
|
||||||
// while (i--)
|
|
||||||
// pCam = pCam->m_pNext;
|
|
||||||
// m_pViewCameras[count] = pCam;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->ReadU32(&rgb, 1);
|
file->ReadU32(&rgb, 1);
|
||||||
mProperties.mFogColor[0] = (float)((unsigned char) (rgb))/255;
|
mProperties.mFogColor[0] = (float)((unsigned char) (rgb))/255;
|
||||||
|
@ -501,27 +481,9 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
mProperties.mAmbientColor[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
mProperties.mAmbientColor[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
||||||
|
|
||||||
if (fv < 1.3f)
|
if (fv < 1.3f)
|
||||||
{
|
file->Seek(23, SEEK_CUR);
|
||||||
file->ReadS32(&i, 1); // m_bAnimation = (i != 0);
|
|
||||||
file->ReadS32(&i, 1); // mAddKeys = (i != 0);
|
|
||||||
file->ReadU8(&ch, 1); // m_nFPS
|
|
||||||
file->ReadS32(&i, 1); // m_nCurFrame = i;
|
|
||||||
file->ReadU16(&sh, 1); // m_nTotalFrames
|
|
||||||
file->ReadS32(&i, 1); // m_nGridSize = i;
|
|
||||||
file->ReadS32(&i, 1); // m_nMoveSnap = i;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
file->Seek(11, SEEK_CUR);
|
||||||
file->ReadU8(&ch, 1); // m_bAnimation = (ch != 0);
|
|
||||||
file->ReadU8(&ch, 1); // mAddKeys = (ch != 0);
|
|
||||||
file->ReadU8(&ch, 1); // m_nFPS
|
|
||||||
file->ReadU16(&sh, 1); // m_nCurFrame
|
|
||||||
file->ReadU16(&sh, 1); // m_nTotalFrames
|
|
||||||
file->ReadU16(&sh, 1); // m_nGridSize = sh;
|
|
||||||
file->ReadU16(&sh, 1);
|
|
||||||
if (fv >= 1.4f)
|
|
||||||
m_nMoveSnap = sh;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fv > 1.0f)
|
if (fv > 1.0f)
|
||||||
|
@ -534,15 +496,6 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
mProperties.mBackgroundGradientColor2[0] = (float)((unsigned char) (rgb))/255;
|
mProperties.mBackgroundGradientColor2[0] = (float)((unsigned char) (rgb))/255;
|
||||||
mProperties.mBackgroundGradientColor2[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
|
mProperties.mBackgroundGradientColor2[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
|
||||||
mProperties.mBackgroundGradientColor2[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
mProperties.mBackgroundGradientColor2[2] = (float)((unsigned char) ((rgb) >> 16))/255;
|
||||||
|
|
||||||
if (fv > 1.1f)
|
|
||||||
m_pTerrain->FileLoad (file);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
file->Seek(4, SEEK_CUR);
|
|
||||||
file->ReadBuffer(&ch, 1);
|
|
||||||
file->Seek(ch, SEEK_CUR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,106 +538,6 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::FileSave(lcFile* file, bool bUndo)
|
|
||||||
{
|
|
||||||
float ver_flt = 1.4f; // LeoCAD 0.75 - (and this should have been an integer).
|
|
||||||
lcuint32 rgb;
|
|
||||||
lcuint8 ch;
|
|
||||||
lcuint16 sh;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
const char LC_STR_VERSION[32] = "LeoCAD 0.7 Project\0\0";
|
|
||||||
|
|
||||||
file->Seek(0, SEEK_SET);
|
|
||||||
file->WriteBuffer(LC_STR_VERSION, 32);
|
|
||||||
file->WriteFloats(&ver_flt, 1);
|
|
||||||
|
|
||||||
rgb = LC_FLOATRGB(mProperties.mBackgroundSolidColor);
|
|
||||||
file->WriteU32(&rgb, 1);
|
|
||||||
|
|
||||||
i = m_nAngleSnap; file->WriteS32(&i, 1);
|
|
||||||
file->WriteU32(&m_nSnap, 1);
|
|
||||||
file->WriteFloat(1.0f);//m_fLineWidth
|
|
||||||
file->WriteU32(0); // m_nDetail
|
|
||||||
i = 0;//i = m_nCurGroup;
|
|
||||||
file->WriteS32(&i, 1);
|
|
||||||
i = 0;//i = m_nCurColor;
|
|
||||||
file->WriteS32(&i, 1);
|
|
||||||
i = 0; file->WriteS32(&i, 1); // m_nCurAction
|
|
||||||
i = mCurrentStep; file->WriteS32(&i, 1);
|
|
||||||
file->WriteU32(0);//m_nScene
|
|
||||||
|
|
||||||
file->WriteS32(mPieces.GetSize());
|
|
||||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
|
||||||
mPieces[PieceIdx]->FileSave(*file);
|
|
||||||
|
|
||||||
QByteArray Author = mProperties.mAuthor.toUtf8();
|
|
||||||
ch = lcMin(strlen(Author), 100U);
|
|
||||||
file->WriteBuffer(&ch, 1);
|
|
||||||
file->WriteBuffer(Author, ch);
|
|
||||||
QByteArray Description = mProperties.mDescription.toUtf8();
|
|
||||||
ch = lcMin(strlen(Description), 100U);
|
|
||||||
file->WriteBuffer(&ch, 1);
|
|
||||||
file->WriteBuffer(Description, ch);
|
|
||||||
QByteArray Comments = mProperties.mComments.toUtf8();
|
|
||||||
ch = lcMin(strlen(Comments), 255U);
|
|
||||||
file->WriteBuffer(&ch, 1);
|
|
||||||
file->WriteBuffer(Comments, ch);
|
|
||||||
|
|
||||||
i = mGroups.GetSize();
|
|
||||||
file->WriteS32(&i, 1);
|
|
||||||
|
|
||||||
for (int GroupIdx = 0; GroupIdx < mGroups.GetSize(); GroupIdx++)
|
|
||||||
mGroups[GroupIdx]->FileSave(file, mGroups);
|
|
||||||
|
|
||||||
lcuint8 ViewportMode = 0, ActiveViewport = 0;
|
|
||||||
file->WriteU8(&ViewportMode, 1);
|
|
||||||
file->WriteU8(&ActiveViewport, 1);
|
|
||||||
|
|
||||||
i = mCameras.GetSize();
|
|
||||||
file->WriteS32(&i, 1);
|
|
||||||
|
|
||||||
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
|
|
||||||
mCameras[CameraIdx]->FileSave(*file);
|
|
||||||
|
|
||||||
for (j = 0; j < 4; j++)
|
|
||||||
file->WriteS32(0);
|
|
||||||
|
|
||||||
rgb = LC_FLOATRGB(mProperties.mFogColor);
|
|
||||||
file->WriteU32(&rgb, 1);
|
|
||||||
file->WriteFloats(&mProperties.mFogDensity, 1);
|
|
||||||
QByteArray BackgroundImage = mProperties.mBackgroundImage.toLatin1();
|
|
||||||
sh = strlen(BackgroundImage.constData());
|
|
||||||
file->WriteU16(&sh, 1);
|
|
||||||
file->WriteBuffer(BackgroundImage.constData(), sh);
|
|
||||||
ch = strlen(m_strHeader);
|
|
||||||
file->WriteBuffer(&ch, 1);
|
|
||||||
file->WriteBuffer(m_strHeader, ch);
|
|
||||||
ch = strlen(m_strFooter);
|
|
||||||
file->WriteBuffer(&ch, 1);
|
|
||||||
file->WriteBuffer(m_strFooter, ch);
|
|
||||||
// 0.60 (1.0)
|
|
||||||
rgb = LC_FLOATRGB(mProperties.mAmbientColor);
|
|
||||||
file->WriteU32(&rgb, 1);
|
|
||||||
ch = 0;// m_bAnimation;
|
|
||||||
file->WriteBuffer(&ch, 1);
|
|
||||||
ch = 0;// mAddKeys;
|
|
||||||
file->WriteU8(&ch, 1);
|
|
||||||
file->WriteU8 (24); // m_nFPS
|
|
||||||
file->WriteU16(1); // m_nCurFrame
|
|
||||||
file->WriteU16(100); // m_nTotalFrames
|
|
||||||
file->WriteU16(0); // m_nGridSize
|
|
||||||
file->WriteU16(&m_nMoveSnap, 1);
|
|
||||||
// 0.62 (1.1)
|
|
||||||
rgb = LC_FLOATRGB(mProperties.mBackgroundGradientColor1);
|
|
||||||
file->WriteU32(&rgb, 1);
|
|
||||||
rgb = LC_FLOATRGB(mProperties.mBackgroundGradientColor2);
|
|
||||||
file->WriteU32(&rgb, 1);
|
|
||||||
// 0.64 (1.2)
|
|
||||||
m_pTerrain->FileSave(file);
|
|
||||||
file->WriteU32(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Project::FileReadMPD(lcFile& MPD, lcArray<LC_FILEENTRY*>& FileArray) const
|
void Project::FileReadMPD(lcFile& MPD, lcArray<LC_FILEENTRY*>& FileArray) const
|
||||||
{
|
{
|
||||||
LC_FILEENTRY* CurFile = NULL;
|
LC_FILEENTRY* CurFile = NULL;
|
||||||
|
@ -936,48 +789,29 @@ bool Project::DoSave(const char* FileName)
|
||||||
if (iBad != -1)
|
if (iBad != -1)
|
||||||
SaveFileName[iBad] = 0;
|
SaveFileName[iBad] = 0;
|
||||||
|
|
||||||
strcat(SaveFileName, ".lcd");
|
strcat(SaveFileName, ".ldr");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gMainWindow->DoDialog(LC_DIALOG_SAVE_PROJECT, SaveFileName))
|
if (!gMainWindow->DoDialog(LC_DIALOG_SAVE_PROJECT, SaveFileName))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ext[4];
|
if (QFileInfo(SaveFileName).suffix().toLower() == QLatin1String("lcd"))
|
||||||
memset(ext, 0, 4);
|
|
||||||
const char* ptr = strrchr(SaveFileName, '.');
|
|
||||||
if (ptr != NULL)
|
|
||||||
{
|
{
|
||||||
strncpy(ext, ptr+1, 3);
|
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Saving files in LCD format is no longer supported, please use the LDR format instead."));
|
||||||
strlwr(ext);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strcmp(ext, "dat") == 0) || (strcmp(ext, "ldr") == 0))
|
|
||||||
{
|
|
||||||
QFile File(SaveFileName);
|
QFile File(SaveFileName);
|
||||||
|
|
||||||
if (!File.open(QIODevice::WriteOnly))
|
if (!File.open(QIODevice::WriteOnly))
|
||||||
{
|
{
|
||||||
QMessageBox::warning(gMainWindow->mHandle, "Error", QString("Error writing to file '%1':\n%2").arg(SaveFileName, File.errorString()));
|
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(SaveFileName, File.errorString()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream Stream(&File);
|
QTextStream Stream(&File);
|
||||||
SaveLDraw(Stream);
|
SaveLDraw(Stream);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lcDiskFile file;
|
|
||||||
if (!file.Open(SaveFileName, "wb"))
|
|
||||||
{
|
|
||||||
// MessageBox("Failed to save.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSave(&file, false); // save me
|
|
||||||
|
|
||||||
file.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
mSavedHistory = mUndoHistory[0];
|
mSavedHistory = mUndoHistory[0];
|
||||||
|
|
||||||
|
@ -1131,15 +965,11 @@ bool Project::OnOpenDocument(const char* lpszPathName)
|
||||||
|
|
||||||
if (!File.open(QIODevice::ReadOnly))
|
if (!File.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
QMessageBox::warning(gMainWindow->mHandle, "Error", QString("Error reading file '%1':\n%2").arg(lpszPathName, File.errorString()));
|
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error reading file '%1':\n%2").arg(lpszPathName, File.errorString()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Lines;
|
LoadLDraw(QTextStream(&File));
|
||||||
while (!File.atEnd())
|
|
||||||
Lines.append(File.readLine());
|
|
||||||
|
|
||||||
LoadLDraw(Lines, mat, step);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrentStep = step;
|
mCurrentStep = step;
|
||||||
|
@ -1202,7 +1032,9 @@ void Project::CheckPoint(const char* Description)
|
||||||
lcModelHistoryEntry* ModelHistoryEntry = new lcModelHistoryEntry();
|
lcModelHistoryEntry* ModelHistoryEntry = new lcModelHistoryEntry();
|
||||||
|
|
||||||
strcpy(ModelHistoryEntry->Description, Description);
|
strcpy(ModelHistoryEntry->Description, Description);
|
||||||
FileSave(&ModelHistoryEntry->File, true);
|
|
||||||
|
QTextStream Stream(&ModelHistoryEntry->File);
|
||||||
|
SaveLDraw(Stream);
|
||||||
|
|
||||||
mUndoHistory.InsertAt(0, ModelHistoryEntry);
|
mUndoHistory.InsertAt(0, ModelHistoryEntry);
|
||||||
mRedoHistory.DeleteAll();
|
mRedoHistory.DeleteAll();
|
||||||
|
@ -1214,6 +1046,38 @@ void Project::CheckPoint(const char* Description)
|
||||||
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::LoadCheckPoint(lcModelHistoryEntry* CheckPoint)
|
||||||
|
{
|
||||||
|
DeleteContents(true);
|
||||||
|
LoadLDraw(QTextStream(CheckPoint->File, QIODevice::ReadOnly));
|
||||||
|
|
||||||
|
const lcArray<View*> Views = gMainWindow->GetViews();
|
||||||
|
for (int i = 0; i < Views.GetSize (); i++)
|
||||||
|
{
|
||||||
|
Views[i]->MakeCurrent();
|
||||||
|
RenderInitialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
CalculateStep();
|
||||||
|
|
||||||
|
gMainWindow->UpdateFocusObject(GetFocusObject());
|
||||||
|
|
||||||
|
for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++)
|
||||||
|
{
|
||||||
|
View* view = Views[ViewIdx];
|
||||||
|
|
||||||
|
if (!view->mCamera->IsSimple())
|
||||||
|
view->SetDefaultCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
gMainWindow->UpdateLockSnap(m_nSnap);
|
||||||
|
gMainWindow->UpdateSnap();
|
||||||
|
gMainWindow->UpdateCameraMenu();
|
||||||
|
UpdateSelection();
|
||||||
|
gMainWindow->UpdateCurrentStep();
|
||||||
|
gMainWindow->UpdateAllViews();
|
||||||
|
}
|
||||||
|
|
||||||
// Only this function should be called.
|
// Only this function should be called.
|
||||||
void Project::Render(View* View, bool ToMemory)
|
void Project::Render(View* View, bool ToMemory)
|
||||||
{
|
{
|
||||||
|
@ -3488,8 +3352,7 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
mUndoHistory.RemoveIndex(0);
|
mUndoHistory.RemoveIndex(0);
|
||||||
mRedoHistory.InsertAt(0, Undo);
|
mRedoHistory.InsertAt(0, Undo);
|
||||||
|
|
||||||
DeleteContents(true);
|
LoadCheckPoint(mUndoHistory[0]);
|
||||||
FileLoad(&mUndoHistory[0]->File, true, false);
|
|
||||||
|
|
||||||
gMainWindow->UpdateModified(IsModified());
|
gMainWindow->UpdateModified(IsModified());
|
||||||
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
||||||
|
@ -3505,8 +3368,7 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
mRedoHistory.RemoveIndex(0);
|
mRedoHistory.RemoveIndex(0);
|
||||||
mUndoHistory.InsertAt(0, Redo);
|
mUndoHistory.InsertAt(0, Redo);
|
||||||
|
|
||||||
DeleteContents(true);
|
LoadCheckPoint(Redo);
|
||||||
FileLoad(&Redo->File, true, false);
|
|
||||||
|
|
||||||
gMainWindow->UpdateModified(IsModified());
|
gMainWindow->UpdateModified(IsModified());
|
||||||
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
||||||
|
@ -6029,8 +5891,7 @@ void Project::EndMouseTool(lcTool Tool, bool Accept)
|
||||||
{
|
{
|
||||||
if (!Accept)
|
if (!Accept)
|
||||||
{
|
{
|
||||||
DeleteContents(true);
|
LoadCheckPoint(mUndoHistory[0]);
|
||||||
FileLoad(&mUndoHistory[0]->File, true, false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,8 @@ enum lcObjectProperty
|
||||||
|
|
||||||
class Project : public lcModel
|
class Project : public lcModel
|
||||||
{
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(Project)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Project();
|
Project();
|
||||||
~Project();
|
~Project();
|
||||||
|
@ -186,6 +188,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void CheckPoint(const char* Description);
|
void CheckPoint(const char* Description);
|
||||||
|
void LoadCheckPoint(lcModelHistoryEntry* CheckPoint);
|
||||||
|
|
||||||
bool RemoveSelectedObjects();
|
bool RemoveSelectedObjects();
|
||||||
void GetPieceInsertPosition(lcPiece* OffsetPiece, lcVector3& Position, lcVector4& Rotation);
|
void GetPieceInsertPosition(lcPiece* OffsetPiece, lcVector3& Position, lcVector4& Rotation);
|
||||||
|
@ -236,7 +239,6 @@ protected:
|
||||||
protected:
|
protected:
|
||||||
bool DoSave(const char* FileName);
|
bool DoSave(const char* FileName);
|
||||||
bool FileLoad(lcFile* file, bool bUndo, bool bMerge);
|
bool FileLoad(lcFile* file, bool bUndo, bool bMerge);
|
||||||
void FileSave(lcFile* file, bool bUndo);
|
|
||||||
void FileReadLDraw(lcFile* file, const lcMatrix44& CurrentTransform, int* nOk, int DefColor, int* nStep, lcArray<LC_FILEENTRY*>& FileArray);
|
void FileReadLDraw(lcFile* file, const lcMatrix44& CurrentTransform, int* nOk, int DefColor, int* nStep, lcArray<LC_FILEENTRY*>& FileArray);
|
||||||
void FileReadMPD(lcFile& MPD, lcArray<LC_FILEENTRY*>& FileArray) const;
|
void FileReadMPD(lcFile& MPD, lcArray<LC_FILEENTRY*>& FileArray) const;
|
||||||
|
|
||||||
|
|
|
@ -298,7 +298,7 @@ bool lcBaseWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_DIALOG_SAVE_PROJECT:
|
case LC_DIALOG_SAVE_PROJECT:
|
||||||
result = QFileDialog::getSaveFileName(parent, parent->tr("Save Project"), FileName, parent->tr("Supported Files (*.lcd *.ldr *.dat);;All Files (*.*)"));
|
result = QFileDialog::getSaveFileName(parent, parent->tr("Save Project"), FileName, parent->tr("Supported Files (*.ldr *.dat);;All Files (*.*)"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_DIALOG_MERGE_PROJECT:
|
case LC_DIALOG_MERGE_PROJECT:
|
||||||
|
|
Loading…
Add table
Reference in a new issue