leocad/common/lc_model.cpp

682 lines
18 KiB
C++
Raw Normal View History

2014-05-25 03:45:19 +02:00
#include "lc_global.h"
#include "lc_model.h"
#include "piece.h"
#include "camera.h"
#include "light.h"
#include "group.h"
2014-05-25 03:45:19 +02:00
#include "lc_mainwindow.h"
#include "lc_profile.h"
#include "lc_library.h"
2014-05-25 03:45:19 +02:00
void lcModelProperties::LoadDefaults()
{
mAuthor = lcGetProfileString(LC_PROFILE_DEFAULT_AUTHOR_NAME);
mBackgroundType = (lcBackgroundType)lcGetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TYPE);
mBackgroundSolidColor = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_COLOR));
mBackgroundGradientColor1 = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR1));
mBackgroundGradientColor2 = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR2));
mBackgroundImage = lcGetProfileString(LC_PROFILE_DEFAULT_BACKGROUND_TEXTURE);
mBackgroundImageTile = lcGetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TILE);
mFogEnabled = lcGetProfileInt(LC_PROFILE_DEFAULT_FOG_ENABLED);
mFogDensity = lcGetProfileFloat(LC_PROFILE_DEFAULT_FOG_DENSITY);
mFogColor = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_FOG_COLOR));
mAmbientColor = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR));
}
void lcModelProperties::SaveDefaults()
{
lcSetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TYPE, mBackgroundType);
lcSetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_COLOR, lcColorFromVector3(mBackgroundSolidColor));
lcSetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR1, lcColorFromVector3(mBackgroundGradientColor1));
lcSetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR2, lcColorFromVector3(mBackgroundGradientColor2));
lcSetProfileString(LC_PROFILE_DEFAULT_BACKGROUND_TEXTURE, mBackgroundImage);
lcSetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TILE, mBackgroundImageTile);
lcSetProfileInt(LC_PROFILE_DEFAULT_FOG_ENABLED, mFogEnabled);
lcSetProfileFloat(LC_PROFILE_DEFAULT_FOG_DENSITY, mFogDensity);
lcSetProfileInt(LC_PROFILE_DEFAULT_FOG_COLOR, lcColorFromVector3(mFogColor));
lcSetProfileInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR, lcColorFromVector3(mAmbientColor));
}
2014-09-05 02:24:28 +02:00
void lcModelProperties::SaveLDraw(QTextStream& Stream) const
{
2014-09-06 03:34:03 +02:00
QLatin1String LineEnding("\r\n");
2014-09-06 03:34:03 +02:00
if (!mName.isEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL NAME ") << mName << LineEnding;
2014-09-06 03:34:03 +02:00
if (!mAuthor.isEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL AUTHOR ") << mAuthor << LineEnding;
2014-09-06 03:34:03 +02:00
if (!mDescription.isEmpty())
Stream << QLatin1String("0 !LEOCAD MODEL DESCRIPTION ") << mDescription << LineEnding;
if (!mComments.isEmpty())
{
QStringList Comments = mComments.split('\n');
2014-09-08 21:42:20 +02:00
foreach (const QString& Comment, Comments)
2014-09-06 03:34:03 +02:00
Stream << QLatin1String("0 !LEOCAD MODEL COMMENT ") << Comment << LineEnding;
}
2014-09-08 21:42:20 +02:00
for (int BackgroundIdx = 0; BackgroundIdx < LC_NUM_BACKGROUND_TYPES; BackgroundIdx++)
{
2014-09-08 21:42:20 +02:00
switch ((mBackgroundType + 1 + BackgroundIdx) % LC_NUM_BACKGROUND_TYPES)
{
case LC_BACKGROUND_SOLID:
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND COLOR ") << mBackgroundSolidColor[0] << ' ' << mBackgroundSolidColor[1] << ' ' << mBackgroundSolidColor[2] << LineEnding;
break;
case LC_BACKGROUND_GRADIENT:
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())
{
Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND IMAGE ");
if (mBackgroundImageTile)
Stream << QLatin1String("TILE ");
Stream << QLatin1String("NAME ") << mBackgroundImage << LineEnding;
}
break;
}
}
// bool mFogEnabled;
// float mFogDensity;
// lcVector3 mFogColor;
// lcVector3 mAmbientColor;
}
2014-09-08 21:42:20 +02:00
void lcModelProperties::ParseLDrawLine(QTextStream& Stream)
{
2014-09-08 21:42:20 +02:00
QString Token;
Stream >> Token;
if (Token == QLatin1String("NAME"))
Stream >> mName;
else if (Token == QLatin1String("AUTHOR"))
Stream >> mAuthor;
else if (Token == QLatin1String("DESCRIPTION"))
Stream >> mDescription;
else if (Token == QLatin1String("COMMENT"))
{
2014-09-08 21:42:20 +02:00
QString Comment;
Stream >> Comment;
if (!mComments.isEmpty())
mComments += '\n';
mComments += Comment;
}
2014-09-08 21:42:20 +02:00
else if (Token == QLatin1String("BACKGROUND"))
{
2014-09-08 21:42:20 +02:00
Stream >> Token;
if (Token == QLatin1String("COLOR"))
{
2014-09-08 21:42:20 +02:00
mBackgroundType = LC_BACKGROUND_SOLID;
Stream >> mBackgroundSolidColor[0] >> mBackgroundSolidColor[1] >> mBackgroundSolidColor[2];
}
2014-09-08 21:42:20 +02:00
else if (Token == QLatin1String("GRADIENT"))
{
2014-09-08 21:42:20 +02:00
mBackgroundType = LC_BACKGROUND_GRADIENT;
Stream >> mBackgroundGradientColor1[0] >> mBackgroundGradientColor1[1] >> mBackgroundGradientColor1[2] >> mBackgroundGradientColor2[0] >> mBackgroundGradientColor2[1] >> mBackgroundGradientColor2[2];
}
2014-09-08 21:42:20 +02:00
else if (Token == QLatin1String("IMAGE"))
{
2014-09-08 21:42:20 +02:00
Stream >> Token;
2014-09-08 21:42:20 +02:00
if (Token == QLatin1String("TILE"))
{
mBackgroundImageTile = true;
Stream >> Token;
}
2014-09-08 21:42:20 +02:00
if (Token == QLatin1String("NAME"))
mBackgroundImage = Stream.readLine();
}
}
}
2014-05-25 03:45:19 +02:00
lcModel::lcModel()
{
mSavedHistory = NULL;
2014-05-25 03:45:19 +02:00
}
lcModel::~lcModel()
{
}
2014-07-06 08:04:09 +02:00
2014-09-05 02:24:28 +02:00
void lcModel::SaveLDraw(QTextStream& Stream) const
{
2014-09-08 21:42:20 +02:00
QLatin1String LineEnding("\r\n");
2014-09-05 02:24:28 +02:00
mProperties.SaveLDraw(Stream);
lcStep LastStep = GetLastStep();
if (mCurrentStep != LastStep)
2014-09-08 21:42:20 +02:00
Stream << QLatin1String("0 !LEOCAD MODEL CURRENT_STEP") << mCurrentStep << LineEnding;
2014-09-13 08:48:51 +02:00
lcArray<lcGroup*> CurrentGroups;
for (lcStep Step = 1; Step <= LastStep; Step++)
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
2014-09-13 08:48:51 +02:00
if (Piece->GetStepShow() != Step)
continue;
2014-09-08 21:42:20 +02:00
lcGroup* PieceGroup = Piece->GetGroup();
2014-09-13 08:48:51 +02:00
if (PieceGroup)
2014-09-08 21:42:20 +02:00
{
2014-09-13 08:48:51 +02:00
if (CurrentGroups.IsEmpty() || (!CurrentGroups.IsEmpty() && PieceGroup != CurrentGroups[CurrentGroups.GetSize() - 1]))
{
lcArray<lcGroup*> PieceParents;
for (lcGroup* Group = PieceGroup; Group; Group = Group->mGroup)
PieceParents.InsertAt(0, Group);
int FoundParent = -1;
2014-09-08 21:42:20 +02:00
2014-09-13 08:48:51 +02:00
while (!CurrentGroups.IsEmpty())
{
lcGroup* Group = CurrentGroups[CurrentGroups.GetSize() - 1];
int Index = PieceParents.FindIndex(Group);
if (Index == -1)
{
CurrentGroups.RemoveIndex(CurrentGroups.GetSize() - 1);
Stream << QLatin1String("0 !LEOCAD GROUP END\r\n");
}
else
{
FoundParent = Index;
break;
}
}
2014-09-08 21:42:20 +02:00
2014-09-13 08:48:51 +02:00
for (int ParentIdx = FoundParent + 1; ParentIdx < PieceParents.GetSize(); ParentIdx++)
{
lcGroup* Group = PieceParents[ParentIdx];
CurrentGroups.Add(Group);
Stream << QLatin1String("0 !LEOCAD GROUP BEGIN ") << Group->m_strName << LineEnding;
}
}
}
else
{
while (CurrentGroups.GetSize())
2014-09-08 21:42:20 +02:00
{
2014-09-13 08:48:51 +02:00
CurrentGroups.RemoveIndex(CurrentGroups.GetSize() - 1);
Stream << QLatin1String("0 !LEOCAD GROUP END\r\n");
2014-09-08 21:42:20 +02:00
}
}
2014-09-13 08:48:51 +02:00
Piece->SaveLDraw(Stream);
}
if (Step != LastStep)
2014-09-08 21:42:20 +02:00
Stream << QLatin1String("0 STEP\r\n");
}
2014-09-13 08:48:51 +02:00
while (CurrentGroups.GetSize())
{
CurrentGroups.RemoveIndex(CurrentGroups.GetSize() - 1);
2014-09-08 21:42:20 +02:00
Stream << QLatin1String("0 !LEOCAD GROUP END\r\n");
2014-09-13 08:48:51 +02:00
}
2014-09-08 21:42:20 +02:00
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
2014-09-05 02:24:28 +02:00
mCameras[CameraIdx]->SaveLDraw(Stream);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
2014-09-05 02:24:28 +02:00
mLights[LightIdx]->SaveLDraw(Stream);
}
2014-09-14 02:45:45 +02:00
void lcModel::LoadLDraw(QTextStream& Stream)
{
lcPiece* Piece = NULL;
lcCamera* Camera = NULL;
lcLight* Light = NULL;
2014-09-13 08:48:51 +02:00
lcArray<lcGroup*> CurrentGroups;
2014-09-14 02:45:45 +02:00
int CurrentStep = 1;
2014-09-14 02:45:45 +02:00
while (!Stream.atEnd())
{
2014-09-14 02:45:45 +02:00
QString Line = Stream.readLine().trimmed();
QTextStream LineStream(&Line, QIODevice::ReadOnly);
2014-09-03 16:34:53 +02:00
QString Token;
2014-09-14 02:45:45 +02:00
LineStream >> Token;
2014-09-04 16:27:37 +02:00
if (Token == QLatin1String("0"))
{
2014-09-14 02:45:45 +02:00
LineStream >> Token;
2014-09-04 16:27:37 +02:00
if (Token == QLatin1String("STEP"))
{
CurrentStep++;
continue;
}
2014-09-04 16:27:37 +02:00
if (Token != QLatin1String("!LEOCAD"))
continue;
2014-09-14 02:45:45 +02:00
LineStream >> Token;
2014-09-04 16:27:37 +02:00
if (Token == QLatin1String("MODEL"))
{
// if (!strcmp(Tokens[3], "CURRENT_STEP") && Tokens[4])
// mCurrentStep = atoi(Tokens[4]);
2014-09-14 02:45:45 +02:00
mProperties.ParseLDrawLine(LineStream);
}
2014-09-04 16:27:37 +02:00
else if (Token == QLatin1String("PIECE"))
{
if (!Piece)
Piece = new lcPiece(NULL);
2014-09-14 02:45:45 +02:00
Piece->ParseLDrawLine(LineStream);
}
2014-09-04 16:27:37 +02:00
else if (Token == QLatin1String("CAMERA"))
{
if (!Camera)
Camera = new lcCamera(false);
2014-09-14 02:45:45 +02:00
if (Camera->ParseLDrawLine(LineStream))
{
Camera->CreateName(mCameras);
mCameras.Add(Camera);
Camera = NULL;
}
}
2014-09-04 16:27:37 +02:00
else if (Token == QLatin1String("LIGHT"))
{
}
2014-09-04 16:27:37 +02:00
else if (Token == QLatin1String("GROUP"))
{
2014-09-14 02:45:45 +02:00
LineStream >> Token;
2014-09-08 21:42:20 +02:00
if (Token == QLatin1String("BEGIN"))
{
2014-09-14 02:45:45 +02:00
QString Name = LineStream.readAll().trimmed();
2014-09-08 21:42:20 +02:00
QByteArray NameUtf = Name.toUtf8(); // todo: replace with qstring
2014-09-13 08:48:51 +02:00
lcGroup* Group = GetGroup(NameUtf.constData(), true);
if (!CurrentGroups.IsEmpty())
Group->mGroup = CurrentGroups[CurrentGroups.GetSize() - 1];
2014-09-14 02:45:45 +02:00
else
Group->mGroup = NULL;
2014-09-13 08:48:51 +02:00
CurrentGroups.Add(Group);
2014-09-08 21:42:20 +02:00
}
else if (Token == QLatin1String("END"))
{
2014-09-13 08:48:51 +02:00
if (!CurrentGroups.IsEmpty())
CurrentGroups.RemoveIndex(CurrentGroups.GetSize() - 1);
2014-09-08 21:42:20 +02:00
}
}
continue;
}
2014-09-04 16:27:37 +02:00
else if (Token == QLatin1String("1"))
{
int ColorCode;
2014-09-14 02:45:45 +02:00
LineStream >> ColorCode;
float Matrix[12];
for (int TokenIdx = 0; TokenIdx < 12; TokenIdx++)
2014-09-14 02:45:45 +02:00
LineStream >> Matrix[TokenIdx];
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));
QString File;
2014-09-14 02:45:45 +02:00
LineStream >> File;
QString PartID = File.toUpper();
2014-09-04 16:27:37 +02:00
if (PartID.endsWith(QLatin1String(".DAT")))
PartID = PartID.left(PartID.size() - 4);
if (!Piece)
Piece = new lcPiece(NULL);
2014-09-13 08:48:51 +02:00
if (!CurrentGroups.IsEmpty())
Piece->SetGroup(CurrentGroups[CurrentGroups.GetSize() - 1]);
2014-09-08 21:42:20 +02:00
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), false);
if (Info != NULL)
{
float* Matrix = IncludeTransform;
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(0.0f, 0.0f, 0.0f, 1.0f));
lcVector4 AxisAngle = lcMatrix44ToAxisAngle(Transform);
AxisAngle[3] *= LC_RTOD;
Piece->SetPieceInfo(Info);
Piece->Initialize(lcVector3(IncludeTransform[3].x, IncludeTransform[3].z, -IncludeTransform[3].y), AxisAngle, CurrentStep);
Piece->SetColorCode(ColorCode);
Piece->CreateName(mPieces);
mPieces.Add(Piece);
Piece = NULL;
continue;
}
// todo: mpd
// todo: load from disk
Info = lcGetPiecesLibrary()->FindPiece(PartID.toLatin1().constData(), true);
if (Info != NULL)
{
float* Matrix = IncludeTransform;
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(0.0f, 0.0f, 0.0f, 1.0f));
lcVector4 AxisAngle = lcMatrix44ToAxisAngle(Transform);
AxisAngle[3] *= LC_RTOD;
Piece->SetPieceInfo(Info);
Piece->Initialize(lcVector3(IncludeTransform[3].x, IncludeTransform[3].z, -IncludeTransform[3].y), AxisAngle, CurrentStep);
Piece->SetColorCode(ColorCode);
Piece->CreateName(mPieces);
mPieces.Add(Piece);
Piece = NULL;
continue;
}
}
}
delete Piece;
delete Camera;
delete Light;
}
void lcModel::CalculateStep()
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
Piece->UpdatePosition(mCurrentStep);
if (Piece->IsSelected())
{
if (!Piece->IsVisible(mCurrentStep))
Piece->SetSelected(false);
else
SelectGroup(Piece->GetTopGroup(), true);
}
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
mCameras[CameraIdx]->UpdatePosition(mCurrentStep);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
mLights[LightIdx]->UpdatePosition(mCurrentStep);
2014-08-30 01:52:42 +02:00
}
2014-07-06 08:04:09 +02:00
lcStep lcModel::GetLastStep() const
{
lcStep Step = 1;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
Step = lcMax(Step, mPieces[PieceIdx]->GetStepShow());
return Step;
}
2014-08-17 22:44:12 +02:00
lcGroup* lcModel::GetGroup(const char* Name, bool CreateIfMissing)
{
for (int GroupIdx = 0; GroupIdx < mGroups.GetSize(); GroupIdx++)
{
lcGroup* Group = mGroups[GroupIdx];
if (!strcmp(Group->m_strName, Name))
return Group;
}
if (CreateIfMissing)
{
lcGroup* Group = new lcGroup();
mGroups.Add(Group);
strncpy(Group->m_strName, Name, sizeof(Group->m_strName));
Group->m_strName[sizeof(Group->m_strName) - 1] = 0;
return Group;
}
return NULL;
}
2014-08-17 22:44:12 +02:00
lcObject* lcModel::GetFocusObject() const
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsFocused())
return Piece;
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
{
lcCamera* Camera = mCameras[CameraIdx];
if (Camera->IsFocused())
return Camera;
}
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
{
lcLight* Light = mLights[LightIdx];
if (Light->IsFocused())
return Light;
}
return NULL;
}
void lcModel::UpdateSelection() const
{
int Flags = 0;
int SelectedCount = 0;
lcObject* Focus = NULL;
if (mPieces.IsEmpty())
Flags |= LC_SEL_NO_PIECES;
else
{
lcGroup* pGroup = NULL;
bool first = true;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsSelected())
{
SelectedCount++;
if (Piece->IsFocused())
Focus = Piece;
Flags |= LC_SEL_PIECE | LC_SEL_SELECTED;
if (Piece->GetGroup() != NULL)
{
Flags |= LC_SEL_GROUPED;
if (Piece->IsFocused())
Flags |= LC_SEL_FOCUS_GROUPED;
}
if (first)
{
pGroup = Piece->GetGroup();
first = false;
}
else
{
if (pGroup != Piece->GetGroup())
Flags |= LC_SEL_CAN_GROUP;
else
if (pGroup == NULL)
Flags |= LC_SEL_CAN_GROUP;
}
}
else
{
Flags |= LC_SEL_UNSELECTED;
if (Piece->IsHidden())
Flags |= LC_SEL_HIDDEN;
}
}
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
{
lcCamera* Camera = mCameras[CameraIdx];
if (Camera->IsSelected())
{
Flags |= LC_SEL_SELECTED;
SelectedCount++;
if (Camera->IsFocused())
Focus = Camera;
}
}
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
{
lcLight* Light = mLights[LightIdx];
if (Light->IsSelected())
{
Flags |= LC_SEL_SELECTED;
SelectedCount++;
if (Light->IsFocused())
Focus = Light;
}
}
gMainWindow->UpdateSelectedObjects(Flags, SelectedCount, Focus);
}
void lcModel::ClearSelection(bool UpdateInterface)
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
mPieces[PieceIdx]->SetSelected(false);
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
mCameras[CameraIdx]->SetSelected(false);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
mLights[LightIdx]->SetSelected(false);
if (UpdateInterface)
{
UpdateSelection();
gMainWindow->UpdateAllViews();
gMainWindow->UpdateFocusObject(NULL);
}
}
void lcModel::SelectGroup(lcGroup* TopGroup, bool Select)
{
if (!TopGroup)
return;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (!Piece->IsSelected() && Piece->IsVisible(mCurrentStep) && (Piece->GetTopGroup() == TopGroup))
Piece->SetSelected(Select);
}
}
void lcModel::FocusOrDeselectObject(const lcObjectSection& ObjectSection)
{
lcObject* FocusObject = GetFocusObject();
lcObject* Object = ObjectSection.Object;
lcuint32 Section = ObjectSection.Section;
if (Object)
{
bool WasSelected = Object->IsSelected();
if (!Object->IsFocused(Section))
{
if (FocusObject)
FocusObject->SetFocused(FocusObject->GetFocusSection(), false);
Object->SetFocused(Section, true);
}
else
Object->SetSelected(Section, false);
bool IsSelected = Object->IsSelected();
if (Object->IsPiece() && (WasSelected != IsSelected))
SelectGroup(((lcPiece*)Object)->GetTopGroup(), IsSelected);
}
else
{
if (FocusObject)
FocusObject->SetFocused(FocusObject->GetFocusSection(), false);
}
UpdateSelection();
gMainWindow->UpdateAllViews();
gMainWindow->UpdateFocusObject(GetFocusObject());
}
void lcModel::ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section)
{
ClearSelection(false);
if (Object)
{
Object->SetFocused(Section, true);
if (Object->IsPiece())
SelectGroup(((lcPiece*)Object)->GetTopGroup(), true);
}
UpdateSelection();
gMainWindow->UpdateAllViews();
gMainWindow->UpdateFocusObject(Object);
}
void lcModel::ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection)
{
ClearSelectionAndSetFocus(ObjectSection.Object, ObjectSection.Section);
}
void lcModel::SetSelection(const lcArray<lcObjectSection>& ObjectSections)
{
ClearSelection(false);
AddToSelection(ObjectSections);
}
void lcModel::AddToSelection(const lcArray<lcObjectSection>& ObjectSections)
{
for (int ObjectIdx = 0; ObjectIdx < ObjectSections.GetSize(); ObjectIdx++)
{
lcObject* Object = ObjectSections[ObjectIdx].Object;
bool WasSelected = Object->IsSelected();
Object->SetSelected(ObjectSections[ObjectIdx].Section, true);
if (!WasSelected && Object->GetType() == LC_OBJECT_PIECE)
SelectGroup(((lcPiece*)Object)->GetTopGroup(), true);
}
UpdateSelection();
gMainWindow->UpdateAllViews();
gMainWindow->UpdateFocusObject(GetFocusObject());
}