More cleanup.

This commit is contained in:
leo
2014-11-29 02:55:58 +00:00
parent deabf0524a
commit d4ab2e9f90
16 changed files with 689 additions and 745 deletions
+6 -9
View File
@@ -732,9 +732,8 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
if (lcBoundingBoxIntersectsVolume(Min, Max, LocalPlanes))
{
lcObjectSection& ObjectSection = ObjectBoxTest.ObjectSections.Add();
ObjectSection.Object = const_cast<lcCamera*>(this);
ObjectSection.Section = LC_CAMERA_SECTION_POSITION;
ObjectBoxTest.Objects.Add(const_cast<lcCamera*>(this));
return;
}
Min = lcVector3(-LC_CAMERA_TARGET_EDGE, -LC_CAMERA_TARGET_EDGE, -LC_CAMERA_TARGET_EDGE);
@@ -751,9 +750,8 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
if (lcBoundingBoxIntersectsVolume(Min, Max, LocalPlanes))
{
lcObjectSection& ObjectSection = ObjectBoxTest.ObjectSections.Add();
ObjectSection.Object = const_cast<lcCamera*>(this);
ObjectSection.Section = LC_CAMERA_SECTION_TARGET;
ObjectBoxTest.Objects.Add(const_cast<lcCamera*>(this));
return;
}
lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView);
@@ -770,9 +768,8 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
if (lcBoundingBoxIntersectsVolume(Min, Max, LocalPlanes))
{
lcObjectSection& ObjectSection = ObjectBoxTest.ObjectSections.Add();
ObjectSection.Object = const_cast<lcCamera*>(this);
ObjectSection.Section = LC_CAMERA_SECTION_UPVECTOR;
ObjectBoxTest.Objects.Add(const_cast<lcCamera*>(this));
return;
}
}
+1 -2
View File
@@ -92,7 +92,6 @@ struct lcPOVRayDialogOptions
struct lcPropertiesDialogOptions
{
lcModelProperties Properties;
QString Title;
bool SetDefault;
lcArray<lcPartsListEntry> PartsList;
@@ -115,7 +114,7 @@ struct lcEditGroupsDialogOptions
struct lcSelectDialogOptions
{
lcArray<bool> Selection;
lcArray<lcObject*> Objects;
};
struct lcPreferencesDialogOptions
-5
View File
@@ -92,11 +92,6 @@ public:
{
}
lcVector3(const lcVector3& a)
: x(a.x), y(a.y), z(a.z)
{
}
operator const float*() const
{
return (const float*)this;
+405 -18
View File
@@ -1403,6 +1403,8 @@ bool lcModel::RotateSelectedPieces(const lcVector3& Angles)
RotationQuaternion = lcQuaternionMultiply(FocusToWorldQuaternion, RotationQuaternion);
}
bool Rotated = false;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
@@ -1438,9 +1440,345 @@ bool lcModel::RotateSelectedPieces(const lcVector3& Angles)
Piece->SetPosition(Center + Distance, mCurrentStep, gMainWindow->GetAddKeys());
Piece->SetRotation(NewRotation, mCurrentStep, gMainWindow->GetAddKeys());
Piece->UpdatePosition(mCurrentStep);
Rotated = true;
}
return true;
return Rotated;
}
void lcModel::TransformSelectedObjects(lcTransformType TransformType, const lcVector3& Transform)
{
switch (TransformType)
{
case LC_TRANSFORM_ABSOLUTE_TRANSLATION:
{
lcVector3 Center = GetFocusOrSelectionCenter();
lcVector3 Offset = Transform - Center;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsSelected())
{
Piece->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset);
Piece->UpdatePosition(mCurrentStep);
}
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
{
lcCamera* Camera = mCameras[CameraIdx];
if (Camera->IsSelected())
{
Camera->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset);
Camera->UpdatePosition(mCurrentStep);
}
}
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
{
lcLight* Light = mLights[LightIdx];
if (Light->IsSelected())
{
Light->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset);
Light->UpdatePosition(mCurrentStep);
}
}
gMainWindow->UpdateAllViews();
SaveCheckpoint("Moving");
gMainWindow->UpdateFocusObject(GetFocusObject());
}
break;
case LC_TRANSFORM_RELATIVE_TRANSLATION:
{
if (MoveSelectedObjects(Transform, Transform))
{
gMainWindow->UpdateAllViews();
SaveCheckpoint("Moving");
gMainWindow->UpdateFocusObject(GetFocusObject());
}
}
break;
case LC_TRANSFORM_ABSOLUTE_ROTATION:
{
lcVector4 RotationQuaternion(0, 0, 0, 1);
if (Transform[0] != 0.0f)
{
lcVector4 q = lcQuaternionRotationX(Transform[0] * LC_DTOR);
RotationQuaternion = lcQuaternionMultiply(q, RotationQuaternion);
}
if (Transform[1] != 0.0f)
{
lcVector4 q = lcQuaternionRotationY(Transform[1] * LC_DTOR);
RotationQuaternion = lcQuaternionMultiply(q, RotationQuaternion);
}
if (Transform[2] != 0.0f)
{
lcVector4 q = lcQuaternionRotationZ(Transform[2] * LC_DTOR);
RotationQuaternion = lcQuaternionMultiply(q, RotationQuaternion);
}
lcVector4 NewRotation = lcQuaternionToAxisAngle(RotationQuaternion);
NewRotation[3] *= LC_RTOD;
bool Rotated = false;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsSelected())
{
Piece->SetRotation(NewRotation, mCurrentStep, gMainWindow->GetAddKeys());
Piece->UpdatePosition(mCurrentStep);
Rotated = true;
}
}
if (Rotated)
{
gMainWindow->UpdateAllViews();
SaveCheckpoint("Rotating");
gMainWindow->UpdateFocusObject(GetFocusObject());
}
}
break;
case LC_TRANSFORM_RELATIVE_ROTATION:
{
lcVector3 Rotate(Transform);
if (RotateSelectedPieces(Rotate))
{
gMainWindow->UpdateAllViews();
SaveCheckpoint("Rotating");
gMainWindow->UpdateFocusObject(GetFocusObject());
}
}
break;
}
}
void lcModel::SetObjectProperty(lcObject* Object, lcObjectPropertyType ObjectPropertyType, const void* Value)
{
QString CheckPointString;
switch (ObjectPropertyType)
{
case LC_PIECE_PROPERTY_POSITION:
{
const lcVector3& Position = *(lcVector3*)Value;
lcPiece* Piece = (lcPiece*)Object;
if (Piece->mPosition != Position)
{
Piece->SetPosition(Position, mCurrentStep, gMainWindow->GetAddKeys());
Piece->UpdatePosition(mCurrentStep);
CheckPointString = tr("Moving");
}
} break;
case LC_PIECE_PROPERTY_ROTATION:
{
const lcVector4& Rotation = *(lcVector4*)Value;
lcPiece* Piece = (lcPiece*)Object;
if (Rotation != Piece->mRotation)
{
Piece->SetRotation(Rotation, mCurrentStep, gMainWindow->GetAddKeys());
Piece->UpdatePosition(mCurrentStep);
CheckPointString = tr("Rotating");
}
} break;
case LC_PIECE_PROPERTY_SHOW:
{
lcStep Step = *(lcStep*)Value;
lcPiece* Part = (lcPiece*)Object;
if (Step != Part->GetStepShow())
{
Part->SetStepShow(Step);
if (Part->IsSelected() && !Part->IsVisible(mCurrentStep))
Part->SetSelected(false);
CheckPointString = tr("Showing");
}
} break;
case LC_PIECE_PROPERTY_HIDE:
{
lcStep Step = *(lcuint32*)Value;
lcPiece* Part = (lcPiece*)Object;
if (Step != Part->GetStepHide())
{
Part->SetStepHide(Step);
CheckPointString = tr("Hiding");
}
} break;
case LC_PIECE_PROPERTY_COLOR:
{
int ColorIndex = *(int*)Value;
lcPiece* Part = (lcPiece*)Object;
if (ColorIndex != Part->mColorIndex)
{
Part->SetColorIndex(ColorIndex);
CheckPointString = tr("Setting Color");
}
} break;
case LC_PIECE_PROPERTY_ID:
{
lcPiece* Part = (lcPiece*)Object;
PieceInfo* Info = (PieceInfo*)Value;
if (Info != Part->mPieceInfo)
{
Part->mPieceInfo->Release();
Part->mPieceInfo = Info;
Part->mPieceInfo->AddRef();
CheckPointString = tr("Setting Part");
}
} break;
case LC_CAMERA_PROPERTY_POSITION:
{
const lcVector3& Position = *(lcVector3*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->mPosition != Position)
{
Camera->SetPosition(Position, mCurrentStep, gMainWindow->GetAddKeys());
Camera->UpdatePosition(mCurrentStep);
CheckPointString = tr("Moving Camera");
}
} break;
case LC_CAMERA_PROPERTY_TARGET:
{
const lcVector3& TargetPosition = *(lcVector3*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->mTargetPosition != TargetPosition)
{
Camera->SetTargetPosition(TargetPosition, mCurrentStep, gMainWindow->GetAddKeys());
Camera->UpdatePosition(mCurrentStep);
CheckPointString = tr("Moving Camera");
}
} break;
case LC_CAMERA_PROPERTY_UPVECTOR:
{
const lcVector3& Up = *(lcVector3*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->mUpVector != Up)
{
Camera->SetUpVector(Up, mCurrentStep, gMainWindow->GetAddKeys());
Camera->UpdatePosition(mCurrentStep);
CheckPointString = tr("Rotating Camera");
}
} break;
case LC_CAMERA_PROPERTY_ORTHO:
{
bool Ortho = *(bool*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->IsOrtho() != Ortho)
{
Camera->SetOrtho(Ortho);
Camera->UpdatePosition(mCurrentStep);
CheckPointString = tr("Changing Camera");
}
} break;
case LC_CAMERA_PROPERTY_FOV:
{
float FOV = *(float*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->m_fovy != FOV)
{
Camera->m_fovy = FOV;
Camera->UpdatePosition(mCurrentStep);
CheckPointString = tr("Setting FOV");
}
} break;
case LC_CAMERA_PROPERTY_NEAR:
{
float Near = *(float*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->m_zNear != Near)
{
Camera->m_zNear= Near;
Camera->UpdatePosition(mCurrentStep);
CheckPointString = tr("Setting Camera");
}
} break;
case LC_CAMERA_PROPERTY_FAR:
{
float Far = *(float*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->m_zFar != Far)
{
Camera->m_zFar = Far;
Camera->UpdatePosition(mCurrentStep);
CheckPointString = tr("Setting Camera");
}
} break;
case LC_CAMERA_PROPERTY_NAME:
{
const char* Name = (const char*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (strcmp(Camera->m_strName, Name))
{
strncpy(Camera->m_strName, Name, sizeof(Camera->m_strName));
Camera->m_strName[sizeof(Camera->m_strName) - 1] = 0;
gMainWindow->UpdateCameraMenu();
CheckPointString = tr("Naming Camera");
}
}
}
if (!CheckPointString.isEmpty())
{
SaveCheckpoint(CheckPointString);
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
}
}
bool lcModel::AnyPiecesSelected() const
@@ -1836,20 +2174,20 @@ void lcModel::ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection)
ClearSelectionAndSetFocus(ObjectSection.Object, ObjectSection.Section);
}
void lcModel::SetSelection(const lcArray<lcObjectSection>& ObjectSections)
void lcModel::SetSelection(const lcArray<lcObject*>& Objects)
{
ClearSelection(false);
AddToSelection(ObjectSections);
AddToSelection(Objects);
}
void lcModel::AddToSelection(const lcArray<lcObjectSection>& ObjectSections)
void lcModel::AddToSelection(const lcArray<lcObject*>& Objects)
{
for (int ObjectIdx = 0; ObjectIdx < ObjectSections.GetSize(); ObjectIdx++)
for (int ObjectIdx = 0; ObjectIdx < Objects.GetSize(); ObjectIdx++)
{
lcObject* Object = ObjectSections[ObjectIdx].Object;
lcObject* Object = Objects[ObjectIdx];
bool WasSelected = Object->IsSelected();
Object->SetSelected(ObjectSections[ObjectIdx].Section, true);
Object->SetSelected(Objects[ObjectIdx]);
if (!WasSelected && Object->GetType() == LC_OBJECT_PIECE)
SelectGroup(((lcPiece*)Object)->GetTopGroup(), true);
@@ -1874,6 +2212,21 @@ void lcModel::SelectAllPieces()
gMainWindow->UpdateAllViews();
}
void lcModel::InvertSelection()
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsVisible(mCurrentStep))
Piece->SetSelected(!Piece->IsSelected());
}
gMainWindow->UpdateFocusObject(GetFocusObject());
UpdateSelection();
gMainWindow->UpdateAllViews();
}
void lcModel::HideSelectedPieces()
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
@@ -2304,6 +2657,46 @@ void lcModel::Zoom(lcCamera* Camera, float Amount)
SaveCheckpoint(tr("Zoom"));
}
void lcModel::ShowPropertiesDialog()
{
lcPropertiesDialogOptions Options;
Options.Properties = mProperties;
Options.SetDefault = false;
GetPartsList(Options.PartsList);
if (!gMainWindow->DoDialog(LC_DIALOG_PROPERTIES, &Options))
return;
if (Options.SetDefault)
Options.Properties.SaveDefaults();
if (mProperties == Options.Properties)
return;
mProperties = Options.Properties;
UpdateBackgroundTexture();
SaveCheckpoint(tr("Changing Properties"));
}
void lcModel::ShowSelectByNameDialog()
{
if (mPieces.IsEmpty() && mCameras.IsEmpty() && mLights.IsEmpty())
{
gMainWindow->DoMessageBox("Nothing to select.", LC_MB_OK | LC_MB_ICONINFORMATION);
return;
}
lcSelectDialogOptions Options;
if (!gMainWindow->DoDialog(LC_DIALOG_SELECT_BY_NAME, &Options))
return;
SetSelection(Options.Objects);
}
void lcModel::ShowArrayDialog()
{
lcVector3 Center;
@@ -2330,7 +2723,7 @@ void lcModel::ShowArrayDialog()
return;
}
lcArray<lcObjectSection> NewPieces;
lcArray<lcObject*> NewPieces;
for (int Step1 = 0; Step1 < Options.Counts[0]; Step1++)
{
@@ -2368,10 +2761,7 @@ void lcModel::ShowArrayDialog()
NewPiece->Initialize(Position + Offset, AxisAngle, mCurrentStep);
NewPiece->SetColorIndex(Piece->mColorIndex);
lcObjectSection ObjectSection;
ObjectSection.Object = NewPiece;
ObjectSection.Section = LC_PIECE_SECTION_POSITION;
NewPieces.Add(ObjectSection);
NewPieces.Add(NewPiece);
}
}
}
@@ -2379,7 +2769,7 @@ void lcModel::ShowArrayDialog()
for (int PieceIdx = 0; PieceIdx < NewPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = (lcPiece*)NewPieces[PieceIdx].Object;
lcPiece* Piece = (lcPiece*)NewPieces[PieceIdx];
Piece->CreateName(mPieces);
Piece->UpdatePosition(mCurrentStep);
mPieces.Add(Piece);
@@ -2397,7 +2787,7 @@ void lcModel::ShowMinifigDialog()
return;
lcGroup* Group = AddGroup("Minifig #", NULL);
lcArray<lcObjectSection> Pieces(LC_MFW_NUMITEMS);
lcArray<lcObject*> Pieces(LC_MFW_NUMITEMS);
for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++)
{
@@ -2416,10 +2806,7 @@ void lcModel::ShowMinifigDialog()
mPieces.Add(Piece);
Piece->UpdatePosition(mCurrentStep);
lcObjectSection ObjectSection;
ObjectSection.Object = Piece;
ObjectSection.Section = LC_PIECE_SECTION_POSITION;
Pieces.Add(ObjectSection);
Pieces.Add(Piece);
}
SetSelection(Pieces);
+9 -3
View File
@@ -186,11 +186,13 @@ public:
void GetPartsList(lcArray<lcPartsListEntry>& PartsList) const;
void FocusOrDeselectObject(const lcObjectSection& ObjectSection);
void ClearSelection(bool UpdateInterface);
void ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section);
void ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection);
void SetSelection(const lcArray<lcObjectSection>& ObjectSections);
void AddToSelection(const lcArray<lcObjectSection>& ObjectSections);
void SetSelection(const lcArray<lcObject*>& Objects);
void AddToSelection(const lcArray<lcObject*>& Objects);
void SelectAllPieces();
void InvertSelection();
void HideSelectedPieces();
void HideUnselectedPieces();
@@ -231,6 +233,11 @@ public:
void ZoomExtents(lcCamera* Camera, float Aspect);
void Zoom(lcCamera* Camera, float Amount);
void TransformSelectedObjects(lcTransformType TransformType, const lcVector3& Transform);
void SetObjectProperty(lcObject* Object, lcObjectPropertyType ObjectPropertyType, const void* Value);
void ShowPropertiesDialog();
void ShowSelectByNameDialog();
void ShowArrayDialog();
void ShowMinifigDialog();
@@ -256,7 +263,6 @@ protected:
void UpdateSelection() const;
void SelectGroup(lcGroup* TopGroup, bool Select);
void ClearSelection(bool UpdateInterface);
lcModelProperties mProperties;
+5 -10
View File
@@ -151,10 +151,7 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
if (lcDot3(mPosition, ObjectBoxTest.Planes[PlaneIdx]) + ObjectBoxTest.Planes[PlaneIdx][3] > LC_LIGHT_SPHERE_RADIUS)
return;
lcObjectSection& ObjectSection = ObjectBoxTest.ObjectSections.Add();
ObjectSection.Object = const_cast<lcLight*>(this);
ObjectSection.Section = LC_LIGHT_SECTION_POSITION;
ObjectBoxTest.Objects.Add(const_cast<lcLight*>(this));
return;
}
@@ -171,9 +168,8 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
if (lcBoundingBoxIntersectsVolume(Min, Max, LocalPlanes))
{
lcObjectSection& ObjectSection = ObjectBoxTest.ObjectSections.Add();
ObjectSection.Object = const_cast<lcLight*>(this);
ObjectSection.Section = LC_LIGHT_SECTION_POSITION;
ObjectBoxTest.Objects.Add(const_cast<lcLight*>(this));
return;
}
Min = lcVector3(-LC_LIGHT_TARGET_EDGE, -LC_LIGHT_TARGET_EDGE, -LC_LIGHT_TARGET_EDGE);
@@ -190,9 +186,8 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
if (lcBoundingBoxIntersectsVolume(Min, Max, LocalPlanes))
{
lcObjectSection& ObjectSection = ObjectBoxTest.ObjectSections.Add();
ObjectSection.Object = const_cast<lcLight*>(this);
ObjectSection.Section = LC_LIGHT_SECTION_TARGET;
ObjectBoxTest.Objects.Add(const_cast<lcLight*>(this));
return;
}
}
+19 -1
View File
@@ -41,7 +41,25 @@ struct lcObjectBoxTest
{
lcCamera* ViewCamera;
lcVector4 Planes[6];
lcArray<lcObjectSection> ObjectSections;
lcArray<lcObject*> Objects;
};
enum lcObjectPropertyType
{
LC_PIECE_PROPERTY_POSITION,
LC_PIECE_PROPERTY_ROTATION,
LC_PIECE_PROPERTY_SHOW,
LC_PIECE_PROPERTY_HIDE,
LC_PIECE_PROPERTY_COLOR,
LC_PIECE_PROPERTY_ID,
LC_CAMERA_PROPERTY_POSITION,
LC_CAMERA_PROPERTY_TARGET,
LC_CAMERA_PROPERTY_UPVECTOR,
LC_CAMERA_PROPERTY_ORTHO,
LC_CAMERA_PROPERTY_FOV,
LC_CAMERA_PROPERTY_NEAR,
LC_CAMERA_PROPERTY_FAR,
LC_CAMERA_PROPERTY_NAME
};
class lcObject
+2 -6
View File
@@ -429,7 +429,7 @@ void lcPiece::Initialize(const lcVector3& Position, const lcVector4& AxisAngle,
ChangeKey(mPositionKeys, Position, 1, true);
ChangeKey(mRotationKeys, AxisAngle, 1, true);
UpdatePosition(1);
UpdatePosition(Step);
}
void lcPiece::CreateName(const lcArray<lcPiece*>& Pieces)
@@ -610,11 +610,7 @@ void lcPiece::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
return;
if (OutcodesOR == 0 || mPieceInfo->mMesh->IntersectsPlanes(LocalPlanes))
{
lcObjectSection& ObjectSection = ObjectBoxTest.ObjectSections.Add();
ObjectSection.Object = const_cast<lcPiece*>(this);
ObjectSection.Section = 0;
}
ObjectBoxTest.Objects.Add(const_cast<lcPiece*>(this));
}
void lcPiece::DrawInterface(lcContext* Context, const lcMatrix44& ViewMatrix) const
+36 -513
View File
@@ -1372,39 +1372,17 @@ void Project::HandleCommand(LC_COMMANDS id)
ExportWavefront();
break;
case LC_FILE_PROPERTIES:
{
lcPropertiesDialogOptions Options;
case LC_FILE_PROPERTIES:
ShowPropertiesDialog();
break;
Options.Properties = mProperties;
Options.Title = GetTitle();
Options.SetDefault = false;
case LC_FILE_PRINT_PREVIEW:
gMainWindow->TogglePrintPreview();
break;
GetPartsList(Options.PartsList);
if (!gMainWindow->DoDialog(LC_DIALOG_PROPERTIES, &Options))
break;
if (Options.SetDefault)
Options.Properties.SaveDefaults();
if (mProperties == Options.Properties)
break;
mProperties = Options.Properties;
UpdateBackgroundTexture();
CheckPoint("Properties");
} break;
case LC_FILE_PRINT_PREVIEW:
gMainWindow->TogglePrintPreview();
break;
case LC_FILE_PRINT:
gMainWindow->DoDialog(LC_DIALOG_PRINT, NULL);
break;
case LC_FILE_PRINT:
gMainWindow->DoDialog(LC_DIALOG_PRINT, NULL);
break;
// TODO: printing
case LC_FILE_PRINT_BOM:
@@ -1628,64 +1606,13 @@ void Project::HandleCommand(LC_COMMANDS id)
ClearSelection(true);
break;
case LC_EDIT_SELECT_INVERT:
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
case LC_EDIT_SELECT_INVERT:
InvertSelection();
break;
if (Piece->IsVisible(mCurrentStep))
Piece->SetSelected(!Piece->IsSelected());
}
gMainWindow->UpdateFocusObject(GetFocusObject());
UpdateSelection();
gMainWindow->UpdateAllViews();
} break;
case LC_EDIT_SELECT_BY_NAME:
{
lcSelectDialogOptions Options;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
Options.Selection.Add(mPieces[PieceIdx]->IsSelected());
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
if (mCameras[CameraIdx]->IsVisible())
Options.Selection.Add(mCameras[CameraIdx]->IsSelected());
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
if (mLights[LightIdx]->IsVisible())
Options.Selection.Add(mLights[LightIdx]->IsSelected());
if (Options.Selection.GetSize() == 0)
{
gMainWindow->DoMessageBox("Nothing to select.", LC_MB_OK | LC_MB_ICONINFORMATION);
break;
}
if (!gMainWindow->DoDialog(LC_DIALOG_SELECT_BY_NAME, &Options))
break;
ClearSelection(false);
int ObjectIndex = 0;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++, ObjectIndex++)
if (Options.Selection[ObjectIndex])
mPieces[PieceIdx]->SetSelected(true);
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++, ObjectIndex++)
if (Options.Selection[ObjectIndex])
mCameras[CameraIdx]->SetSelected(true);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
if (Options.Selection[ObjectIndex])
mLights[LightIdx]->SetSelected(true);
UpdateSelection();
gMainWindow->UpdateAllViews();
gMainWindow->UpdateFocusObject(GetFocusObject());
} break;
case LC_EDIT_SELECT_BY_NAME:
ShowSelectByNameDialog();
break;
case LC_VIEW_SPLIT_HORIZONTAL:
gMainWindow->SplitHorizontal();
@@ -1752,7 +1679,6 @@ void Project::HandleCommand(LC_COMMANDS id)
break;
lcPiece* Last = mPieces.IsEmpty() ? NULL : mPieces[mPieces.GetSize() - 1];
lcPiece* pPiece = new lcPiece(CurPiece);
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
@@ -1765,23 +1691,28 @@ void Project::HandleCommand(LC_COMMANDS id)
}
}
lcVector3 Position(0, 0, 0);
lcVector4 Rotation(0, 0, 1, 0);
if (Last != NULL)
{
lcVector3 Pos;
lcVector4 Rot;
lcVector3 Dist(0, 0, Last->mPieceInfo->m_fDimensions[2] - CurPiece->m_fDimensions[5]);
Dist = SnapPosition(Dist);
GetPieceInsertPosition(Last, Pos, Rot);
pPiece->Initialize(Pos, Rot, mCurrentStep);
pPiece->UpdatePosition(mCurrentStep);
Position = lcMul31(Dist, Last->mModelWorld);
Rotation = Last->mRotation;
}
else
pPiece->Initialize(lcVector3(0, 0, 0), lcVector4(0, 0, 1, 0), mCurrentStep);
{
Position[2] = -CurPiece->m_fDimensions[5];
}
pPiece->SetColorIndex(gMainWindow->mColorIndex);
pPiece->CreateName(mPieces);
mPieces.Add(pPiece);
ClearSelectionAndSetFocus(pPiece, LC_PIECE_SECTION_POSITION);
lcPiece* Piece = new lcPiece(CurPiece);
Piece->Initialize(Position, Rotation, mCurrentStep);
Piece->SetColorIndex(gMainWindow->mColorIndex);
Piece->CreateName(mPieces);
mPieces.Add(Piece);
ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION);
CheckPoint("Inserting");
} break;
@@ -2267,420 +2198,12 @@ void Project::HandleCommand(LC_COMMANDS id)
gMainWindow->SetTool(LC_TOOL_ROLL);
break;
case LC_EDIT_CANCEL:
{
View* ActiveView = gMainWindow->GetActiveView();
if (ActiveView && ActiveView->mTrackButton != LC_TRACKBUTTON_NONE)
ActiveView->StopTracking(false);
else
ClearSelection(true);
} break;
case LC_EDIT_CANCEL:
gMainWindow->GetActiveView()->CancelTrackingOrClearSelection();
break;
case LC_NUM_COMMANDS:
break;
}
}
// Find a good starting position/orientation relative to an existing piece.
void Project::GetPieceInsertPosition(lcPiece* OffsetPiece, lcVector3& Position, lcVector4& Rotation)
{
PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece();
lcVector3 Dist(0, 0, OffsetPiece->mPieceInfo->m_fDimensions[2] - CurPiece->m_fDimensions[5]);
Dist = SnapPosition(Dist);
Position = lcMul31(Dist, OffsetPiece->mModelWorld);
Rotation = OffsetPiece->mRotation;
}
// Try to find a good starting position/orientation for a new piece.
void Project::GetPieceInsertPosition(View* view, lcVector3& Position, lcVector4& Rotation)
{
// Check if the mouse is over a piece.
lcPiece* HitPiece = (lcPiece*)view->FindObjectUnderPointer(true).Object;
if (HitPiece)
{
GetPieceInsertPosition(HitPiece, Position, Rotation);
return;
}
// Try to hit the base grid.
lcVector3 ClickPoints[2] = { lcVector3((float)view->mInputState.x, (float)view->mInputState.y, 0.0f), lcVector3((float)view->mInputState.x, (float)view->mInputState.y, 1.0f) };
view->UnprojectPoints(ClickPoints, 2);
PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece();
lcVector3 Intersection;
if (lcLinePlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, CurPiece->m_fDimensions[5])))
{
Intersection = SnapPosition(Intersection);
Position = Intersection;
Rotation = lcVector4(0, 0, 1, 0);
return;
}
// Couldn't find a good position, so just place the piece somewhere near the camera.
Position = view->UnprojectPoint(lcVector3((float)view->mInputState.x, (float)view->mInputState.y, 0.9f));
Rotation = lcVector4(0, 0, 1, 0);
}
void Project::TransformSelectedObjects(lcTransformType Type, const lcVector3& Transform)
{
switch (Type)
{
case LC_TRANSFORM_ABSOLUTE_TRANSLATION:
{
float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
lcVector3 Center;
int nSel = 0;
lcPiece* pFocus = NULL;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsSelected())
{
if (Piece->IsFocused())
pFocus = Piece;
Piece->CompareBoundingBox(bs);
nSel++;
}
}
if (pFocus != NULL)
Center = pFocus->mPosition;
else
Center = lcVector3((bs[0]+bs[3])/2, (bs[1]+bs[4])/2, (bs[2]+bs[5])/2);
lcVector3 Offset = Transform - Center;
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
{
lcCamera* pCamera = mCameras[CameraIdx];
if (pCamera->IsSelected())
{
pCamera->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset);
pCamera->UpdatePosition(mCurrentStep);
}
}
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
{
lcLight* pLight = mLights[LightIdx];
if (pLight->IsSelected())
{
pLight->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset);
pLight->UpdatePosition (mCurrentStep);
}
}
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsSelected())
{
Piece->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset);
Piece->UpdatePosition(mCurrentStep);
}
}
if (nSel)
{
gMainWindow->UpdateAllViews();
CheckPoint("Moving");
gMainWindow->UpdateFocusObject(GetFocusObject());
}
} break;
case LC_TRANSFORM_RELATIVE_TRANSLATION:
{
/* lcVector3 Move(Transform);
if (MoveSelectedObjects(Move, false, false))
{
gMainWindow->UpdateAllViews();
CheckPoint("Moving");
gMainWindow->UpdateFocusObject(GetFocusObject());
}*/
} break;
case LC_TRANSFORM_ABSOLUTE_ROTATION:
{
// Create the rotation matrix.
lcVector4 RotationQuaternion(0, 0, 0, 1);
if (Transform[0] != 0.0f)
{
lcVector4 q = lcQuaternionRotationX(Transform[0] * LC_DTOR);
RotationQuaternion = lcQuaternionMultiply(q, RotationQuaternion);
}
if (Transform[1] != 0.0f)
{
lcVector4 q = lcQuaternionRotationY(Transform[1] * LC_DTOR);
RotationQuaternion = lcQuaternionMultiply(q, RotationQuaternion);
}
if (Transform[2] != 0.0f)
{
lcVector4 q = lcQuaternionRotationZ(Transform[2] * LC_DTOR);
RotationQuaternion = lcQuaternionMultiply(q, RotationQuaternion);
}
lcVector4 NewRotation = lcQuaternionToAxisAngle(RotationQuaternion);
NewRotation[3] *= LC_RTOD;
int nSel = 0;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
if (Piece->IsSelected())
{
Piece->SetRotation(NewRotation, mCurrentStep, gMainWindow->GetAddKeys());
Piece->UpdatePosition(mCurrentStep);
nSel++;
}
}
if (nSel)
{
gMainWindow->UpdateAllViews();
CheckPoint("Rotating");
gMainWindow->UpdateFocusObject(GetFocusObject());
}
} break;
case LC_TRANSFORM_RELATIVE_ROTATION:
{
lcVector3 Rotate(Transform);
if (RotateSelectedPieces(Rotate))
{
gMainWindow->UpdateAllViews();
CheckPoint("Rotating");
gMainWindow->UpdateFocusObject(GetFocusObject());
}
} break;
}
}
void Project::ModifyObject(lcObject* Object, lcObjectProperty Property, void* Value)
{
const char* CheckPointString = NULL;
switch (Property)
{
case LC_PIECE_PROPERTY_POSITION:
{
const lcVector3& Position = *(lcVector3*)Value;
lcPiece* Piece = (lcPiece*)Object;
if (Piece->mPosition != Position)
{
Piece->SetPosition(Position, mCurrentStep, gMainWindow->GetAddKeys());
Piece->UpdatePosition(mCurrentStep);
CheckPointString = "Moving";
}
} break;
case LC_PIECE_PROPERTY_ROTATION:
{
const lcVector4& Rotation = *(lcVector4*)Value;
lcPiece* Piece = (lcPiece*)Object;
if (Rotation != Piece->mRotation)
{
Piece->SetRotation(Rotation, mCurrentStep, gMainWindow->GetAddKeys());
Piece->UpdatePosition(mCurrentStep);
CheckPointString = "Rotating";
}
} break;
case LC_PIECE_PROPERTY_SHOW:
{
lcStep Step = *(lcStep*)Value;
lcPiece* Part = (lcPiece*)Object;
if (Step != Part->GetStepShow())
{
Part->SetStepShow(Step);
if (Part->IsSelected() && !Part->IsVisible(mCurrentStep))
Part->SetSelected(false);
CheckPointString = "Show";
}
} break;
case LC_PIECE_PROPERTY_HIDE:
{
lcStep Step = *(lcuint32*)Value;
lcPiece* Part = (lcPiece*)Object;
if (Step != Part->GetStepHide())
{
Part->SetStepHide(Step);
CheckPointString = "Hide";
}
} break;
case LC_PIECE_PROPERTY_COLOR:
{
int ColorIndex = *(int*)Value;
lcPiece* Part = (lcPiece*)Object;
if (ColorIndex != Part->mColorIndex)
{
Part->SetColorIndex(ColorIndex);
CheckPointString = "Color";
}
} break;
case LC_PIECE_PROPERTY_ID:
{
lcPiece* Part = (lcPiece*)Object;
PieceInfo* Info = (PieceInfo*)Value;
if (Info != Part->mPieceInfo)
{
Part->mPieceInfo->Release();
Part->mPieceInfo = Info;
Part->mPieceInfo->AddRef();
CheckPointString = "Part";
}
} break;
case LC_CAMERA_PROPERTY_POSITION:
{
const lcVector3& Position = *(lcVector3*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->mPosition != Position)
{
Camera->SetPosition(Position, mCurrentStep, gMainWindow->GetAddKeys());
Camera->UpdatePosition(mCurrentStep);
CheckPointString = "Camera";
}
} break;
case LC_CAMERA_PROPERTY_TARGET:
{
const lcVector3& TargetPosition = *(lcVector3*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->mTargetPosition != TargetPosition)
{
Camera->SetTargetPosition(TargetPosition, mCurrentStep, gMainWindow->GetAddKeys());
Camera->UpdatePosition(mCurrentStep);
CheckPointString = "Camera";
}
} break;
case LC_CAMERA_PROPERTY_UPVECTOR:
{
const lcVector3& Up = *(lcVector3*)Value;
lcCamera* Camera = (lcCamera*)Object;
if (Camera->mUpVector != Up)
{
Camera->SetUpVector(Up, mCurrentStep, gMainWindow->GetAddKeys());
Camera->UpdatePosition(mCurrentStep);
CheckPointString = "Camera";
}
} break;
case LC_CAMERA_PROPERTY_ORTHO:
{
bool Ortho = *(bool*)Value;
lcCamera* camera = (lcCamera*)Object;
if (camera->IsOrtho() != Ortho)
{
camera->SetOrtho(Ortho);
camera->UpdatePosition(mCurrentStep);
CheckPointString = "Camera";
}
} break;
case LC_CAMERA_PROPERTY_FOV:
{
float FOV = *(float*)Value;
lcCamera* camera = (lcCamera*)Object;
if (camera->m_fovy != FOV)
{
camera->m_fovy = FOV;
camera->UpdatePosition(mCurrentStep);
CheckPointString = "Camera";
}
} break;
case LC_CAMERA_PROPERTY_NEAR:
{
float Near = *(float*)Value;
lcCamera* camera = (lcCamera*)Object;
if (camera->m_zNear != Near)
{
camera->m_zNear= Near;
camera->UpdatePosition(mCurrentStep);
CheckPointString = "Camera";
}
} break;
case LC_CAMERA_PROPERTY_FAR:
{
float Far = *(float*)Value;
lcCamera* camera = (lcCamera*)Object;
if (camera->m_zFar != Far)
{
camera->m_zFar = Far;
camera->UpdatePosition(mCurrentStep);
CheckPointString = "Camera";
}
} break;
case LC_CAMERA_PROPERTY_NAME:
{
const char* Name = (const char*)Value;
lcCamera* camera = (lcCamera*)Object;
if (strcmp(camera->m_strName, Name))
{
strncpy(camera->m_strName, Name, sizeof(camera->m_strName));
camera->m_strName[sizeof(camera->m_strName) - 1] = 0;
gMainWindow->UpdateCameraMenu();
CheckPointString = "Camera";
}
}
}
if (CheckPointString)
{
CheckPoint(CheckPointString);
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
case LC_NUM_COMMANDS:
break;
}
}
-23
View File
@@ -41,24 +41,6 @@ struct LC_FILEENTRY
char FileName[LC_MAXPATH];
};
enum lcObjectProperty
{
LC_PIECE_PROPERTY_POSITION,
LC_PIECE_PROPERTY_ROTATION,
LC_PIECE_PROPERTY_SHOW,
LC_PIECE_PROPERTY_HIDE,
LC_PIECE_PROPERTY_COLOR,
LC_PIECE_PROPERTY_ID,
LC_CAMERA_PROPERTY_POSITION,
LC_CAMERA_PROPERTY_TARGET,
LC_CAMERA_PROPERTY_UPVECTOR,
LC_CAMERA_PROPERTY_ORTHO,
LC_CAMERA_PROPERTY_FOV,
LC_CAMERA_PROPERTY_NEAR,
LC_CAMERA_PROPERTY_FAR,
LC_CAMERA_PROPERTY_NAME
};
#include "lc_model.h"
class Project : public lcModel
@@ -82,16 +64,11 @@ public:
void LoadDefaults();
void SaveImage();
void SaveStepImages(const QString& BaseName, int Width, int Height, lcStep Start, lcStep End);
void TransformSelectedObjects(lcTransformType Type, const lcVector3& Transform);
void ModifyObject(lcObject* Object, lcObjectProperty Property, void* Value);
void GetPieceInsertPosition(View* view, lcVector3& Position, lcVector4& Orientation);
void HandleCommand(LC_COMMANDS id);
protected:
void CheckPoint(const char* Description);
void GetPieceInsertPosition(lcPiece* OffsetPiece, lcVector3& Position, lcVector4& Rotation);
static int InstanceOfName(const String& existingString, const String& candidateString, String& baseNameOut);
void ExportHTML();
+52 -18
View File
@@ -9,6 +9,7 @@
#include "texfont.h"
#include "lc_texture.h"
#include "preview.h"
#include "piece.h"
#include "pieceinf.h"
View::View(Project *project)
@@ -164,6 +165,39 @@ LC_CURSOR_TYPE View::GetCursor() const
return CursorFromTrackTool[mTrackTool];
}
void View::GetPieceInsertPosition(lcVector3& Position, lcVector4& Rotation) const
{
PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece();
lcPiece* HitPiece = (lcPiece*)FindObjectUnderPointer(true).Object;
if (HitPiece)
{
lcVector3 Dist(0, 0, HitPiece->mPieceInfo->m_fDimensions[2] - CurPiece->m_fDimensions[5]);
Dist = mProject->SnapPosition(Dist);
Position = lcMul31(Dist, HitPiece->mModelWorld);
Rotation = HitPiece->mRotation;
return;
}
lcVector3 ClickPoints[2] = { lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f) };
UnprojectPoints(ClickPoints, 2);
lcVector3 Intersection;
if (lcLinePlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, CurPiece->m_fDimensions[5])))
{
Intersection = mProject->SnapPosition(Intersection);
Position = Intersection;
Rotation = lcVector4(0, 0, 1, 0);
return;
}
Position = UnprojectPoint(lcVector3((float)mInputState.x, (float)mInputState.y, 0.9f));
Rotation = lcVector4(0, 0, 1, 0);
}
lcObjectSection View::FindObjectUnderPointer(bool PiecesOnly) const
{
lcVector3 StartEnd[2] =
@@ -189,7 +223,7 @@ lcObjectSection View::FindObjectUnderPointer(bool PiecesOnly) const
return ObjectRayTest.ObjectSection;
}
lcArray<lcObjectSection> View::FindObjectsInBox(float x1, float y1, float x2, float y2) const
lcArray<lcObject*> View::FindObjectsInBox(float x1, float y1, float x2, float y2) const
{
float Left, Top, Bottom, Right;
@@ -246,7 +280,7 @@ lcArray<lcObjectSection> View::FindObjectsInBox(float x1, float y1, float x2, fl
mProject->BoxTest(ObjectBoxTest);
return ObjectBoxTest.ObjectSections;
return ObjectBoxTest.Objects;
}
void View::OnDraw()
@@ -321,7 +355,7 @@ void View::OnDraw()
{
lcVector3 Position;
lcVector4 Rotation;
mProject->GetPieceInsertPosition(this, Position, Rotation);
GetPieceInsertPosition(Position, Rotation);
lcMatrix44 WorldMatrix = lcMatrix44FromAxisAngle(lcVector3(Rotation[0], Rotation[1], Rotation[2]), Rotation[3] * LC_DTOR);
WorldMatrix.SetTranslation(Position);
@@ -1005,7 +1039,7 @@ void View::DrawGrid()
{
lcVector3 Position;
lcVector4 Rotation;
mProject->GetPieceInsertPosition(this, Position, Rotation);
GetPieceInsertPosition(Position, Rotation);
PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece();
lcVector3 Points[8] =
@@ -1320,7 +1354,7 @@ void View::EndPieceDrag(bool Accept)
{
lcVector3 Position;
lcVector4 Rotation;
mProject->GetPieceInsertPosition(this, Position, Rotation);
GetPieceInsertPosition(Position, Rotation);
mProject->InsertPieceToolClicked(Position, Rotation);
}
@@ -1786,12 +1820,12 @@ void View::StopTracking(bool Accept)
case LC_TOOL_SELECT:
if (Accept && mMouseDownX != mInputState.x && mMouseDownY != mInputState.y)
{
lcArray<lcObjectSection> ObjectSections = FindObjectsInBox(mMouseDownX, mMouseDownY, mInputState.x, mInputState.y);
lcArray<lcObject*> Objects = FindObjectsInBox(mMouseDownX, mMouseDownY, mInputState.x, mInputState.y);
if (mInputState.Control)
mProject->AddToSelection(ObjectSections);
mProject->AddToSelection(Objects);
else
mProject->SetSelection(ObjectSections);
mProject->SetSelection(Objects);
}
break;
@@ -1835,6 +1869,14 @@ void View::StopTracking(bool Accept)
gMainWindow->UpdateAllViews();
}
void View::CancelTrackingOrClearSelection()
{
if (mTrackButton != LC_TRACKBUTTON_NONE)
StopTracking(false);
else
mProject->ClearSelection(true);
}
void View::OnLeftButtonDown()
{
if (mTrackButton != LC_TRACKBUTTON_NONE)
@@ -1864,7 +1906,7 @@ void View::OnLeftButtonDown()
{
lcVector3 Position;
lcVector4 Rotation;
mProject->GetPieceInsertPosition(this, Position, Rotation);
GetPieceInsertPosition(Position, Rotation);
mProject->InsertPieceToolClicked(Position, Rotation);
if (!mInputState.Control)
@@ -2066,15 +2108,7 @@ void View::OnMouseMove()
UpdateTrackTool();
if (mTrackTool == LC_TRACKTOOL_INSERT)
{
/* lcVector3 Position;
lcVector4 AxisAngle;
GetPieceInsertPosition(&Position, &AxisAngle);
mProject->mActiveModel->SetPreviewTransform(Position, AxisAngle);
*/ gMainWindow->UpdateAllViews();
}
gMainWindow->UpdateAllViews();
return;
}
+3 -1
View File
@@ -72,6 +72,7 @@ public:
void OnMouseMove();
void OnMouseWheel(float Direction);
void CancelTrackingOrClearSelection();
void BeginPieceDrag();
void EndPieceDrag(bool Accept);
void ZoomExtents();
@@ -84,8 +85,9 @@ public:
lcMatrix44 GetProjectionMatrix() const;
LC_CURSOR_TYPE GetCursor() const;
void GetPieceInsertPosition(lcVector3& Position, lcVector4& Rotation) const;
lcObjectSection FindObjectUnderPointer(bool PiecesOnly) const;
lcArray<lcObjectSection> FindObjectsInBox(float x1, float y1, float x2, float y2) const;
lcArray<lcObject*> FindObjectsInBox(float x1, float y1, float x2, float y2) const;
Project* mProject;
lcCamera* mCamera;
-2
View File
@@ -23,8 +23,6 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
options = (lcPropertiesDialogOptions*)data;
setWindowTitle(QString(tr("%1 Properties")).arg(options->Title));
ui->descriptionEdit->setText(options->Properties.mDescription);
ui->authorEdit->setText(options->Properties.mAuthor);
ui->commentsEdit->setText(options->Properties.mComments);
+14 -14
View File
@@ -502,7 +502,7 @@ void lcQPropertiesTree::slotToggled(bool value)
{
if (item == cameraOrtho)
{
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_ORTHO, &value);
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_ORTHO, &value);
}
}
}
@@ -532,7 +532,7 @@ void lcQPropertiesTree::slotReturnPressed()
else if (item == partPositionZ)
position[2] = value;
project->ModifyObject(focusObject, LC_PIECE_PROPERTY_POSITION, &position);
project->SetObjectProperty(focusObject, LC_PIECE_PROPERTY_POSITION, &position);
}
else if (item == partRotationX || item == partRotationY || item == partRotationZ)
{
@@ -549,19 +549,19 @@ void lcQPropertiesTree::slotReturnPressed()
lcVector4 axisAngle = lcMatrix44ToAxisAngle(lcMatrix44FromEulerAngles(rotation * LC_DTOR));
axisAngle[3] *= LC_RTOD;
project->ModifyObject(focusObject, LC_PIECE_PROPERTY_ROTATION, &axisAngle);
project->SetObjectProperty(focusObject, LC_PIECE_PROPERTY_ROTATION, &axisAngle);
}
else if (item == partShow)
{
lcStep value = editor->text().toUInt();
project->ModifyObject(focusObject, LC_PIECE_PROPERTY_SHOW, &value);
project->SetObjectProperty(focusObject, LC_PIECE_PROPERTY_SHOW, &value);
}
else if (item == partHide)
{
lcStep value = editor->text().toUInt();
project->ModifyObject(focusObject, LC_PIECE_PROPERTY_HIDE, &value);
project->SetObjectProperty(focusObject, LC_PIECE_PROPERTY_HIDE, &value);
}
}
else if (focusObject->GetType() == LC_OBJECT_CAMERA)
@@ -580,7 +580,7 @@ void lcQPropertiesTree::slotReturnPressed()
else if (item == cameraPositionZ)
position[2] = value;
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_POSITION, &position);
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_POSITION, &position);
}
else if (item == cameraTargetX || item == cameraTargetY || item == cameraTargetZ)
{
@@ -594,7 +594,7 @@ void lcQPropertiesTree::slotReturnPressed()
else if (item == cameraTargetZ)
target[2] = value;
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_TARGET, &target);
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_TARGET, &target);
}
else if (item == cameraUpX || item == cameraUpY || item == cameraUpZ)
{
@@ -608,31 +608,31 @@ void lcQPropertiesTree::slotReturnPressed()
else if (item == cameraUpZ)
up[2] = value;
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_UPVECTOR, &up);
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_UPVECTOR, &up);
}
else if (item == cameraFOV)
{
float value = editor->text().toFloat();
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_FOV, &value);
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_FOV, &value);
}
else if (item == cameraNear)
{
float value = editor->text().toFloat();
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_NEAR, &value);
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_NEAR, &value);
}
else if (item == cameraFar)
{
float value = editor->text().toFloat();
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_FAR, &value);
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_FAR, &value);
}
else if (item == cameraName)
{
QString value = editor->text();
project->ModifyObject(focusObject, LC_CAMERA_PROPERTY_NAME, value.toLocal8Bit().data());
project->SetObjectProperty(focusObject, LC_CAMERA_PROPERTY_NAME, value.toLocal8Bit().data());
}
}
}
@@ -649,7 +649,7 @@ void lcQPropertiesTree::slotSetValue(int value)
{
if (item == partColor)
{
project->ModifyObject(focusObject, LC_PIECE_PROPERTY_COLOR, &value);
project->SetObjectProperty(focusObject, LC_PIECE_PROPERTY_COLOR, &value);
QPushButton *editor = (QPushButton*)m_delegate->editor();
updateColorEditor(editor, value);
@@ -658,7 +658,7 @@ void lcQPropertiesTree::slotSetValue(int value)
{
QComboBox *editor = (QComboBox*)sender();
project->ModifyObject(focusObject, LC_PIECE_PROPERTY_ID, editor->itemData(value).value<void*>());
project->SetObjectProperty(focusObject, LC_PIECE_PROPERTY_ID, editor->itemData(value).value<void*>());
}
}
}
+136 -116
View File
@@ -17,7 +17,8 @@ lcQSelectDialog::lcQSelectDialog(QWidget *parent, void *data) :
options = (lcSelectDialogOptions*)data;
addChildren(ui->treeWidget->invisibleRootItem(), NULL);
AddChildren(ui->treeWidget->invisibleRootItem(), NULL);
ui->treeWidget->expandAll();
connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*, int)));
}
@@ -29,188 +30,207 @@ lcQSelectDialog::~lcQSelectDialog()
void lcQSelectDialog::accept()
{
saveSelection(ui->treeWidget->invisibleRootItem());
options->Objects.RemoveAll();
QList<QTreeWidgetItem*> Items;
Items.append(ui->treeWidget->invisibleRootItem());
while (!Items.isEmpty())
{
QTreeWidgetItem* Item = Items[0];
Items.removeFirst();
if (!Item->childCount())
{
if (Item->checkState(0) == Qt::Checked)
{
lcObject* Object = (lcObject*)Item->data(0, IndexRole).value<uintptr_t>();
options->Objects.Add(Object);
}
}
else
{
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
Items.append(Item->child(ChildIdx));
}
}
QDialog::accept();
}
void lcQSelectDialog::on_selectAll_clicked()
{
for (int objectIdx = 0; objectIdx < options->Selection.GetSize(); objectIdx++)
options->Selection[objectIdx] = true;
ui->treeWidget->blockSignals(true);
loadSelection(ui->treeWidget->invisibleRootItem());
QList<QTreeWidgetItem*> Items;
Items.append(ui->treeWidget->invisibleRootItem());
while (!Items.isEmpty())
{
QTreeWidgetItem* Item = Items[0];
Items.removeFirst();
if (!Item->childCount())
Item->setCheckState(0, Qt::Checked);
else
{
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
Items.append(Item->child(ChildIdx));
}
}
ui->treeWidget->blockSignals(false);
}
void lcQSelectDialog::on_selectNone_clicked()
{
for (int objectIdx = 0; objectIdx < options->Selection.GetSize(); objectIdx++)
options->Selection[objectIdx] = false;
ui->treeWidget->blockSignals(true);
loadSelection(ui->treeWidget->invisibleRootItem());
QList<QTreeWidgetItem*> Items;
Items.append(ui->treeWidget->invisibleRootItem());
while (!Items.isEmpty())
{
QTreeWidgetItem* Item = Items[0];
Items.removeFirst();
if (!Item->childCount())
Item->setCheckState(0, Qt::Unchecked);
else
{
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
Items.append(Item->child(ChildIdx));
}
}
ui->treeWidget->blockSignals(false);
}
void lcQSelectDialog::on_selectInvert_clicked()
{
for (int objectIdx = 0; objectIdx < options->Selection.GetSize(); objectIdx++)
options->Selection[objectIdx] = !options->Selection[objectIdx];
ui->treeWidget->blockSignals(true);
loadSelection(ui->treeWidget->invisibleRootItem());
QList<QTreeWidgetItem*> Items;
Items.append(ui->treeWidget->invisibleRootItem());
while (!Items.isEmpty())
{
QTreeWidgetItem* Item = Items[0];
Items.removeFirst();
if (!Item->childCount())
Item->setCheckState(0, Item->checkState(0) == Qt::Checked ? Qt::Unchecked : Qt::Checked);
else
{
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
Items.append(Item->child(ChildIdx));
}
}
ui->treeWidget->blockSignals(false);
}
void lcQSelectDialog::itemChanged(QTreeWidgetItem *item, int column)
{
int itemIndex = item->data(0, IndexRole).value<int>();
bool selected = (item->checkState(0) == Qt::Checked);
QTreeWidgetItem* ParentItem = item->parent();
if (options->Selection[itemIndex] == selected)
if (!ParentItem)
return;
options->Selection[itemIndex] = selected;
QTreeWidgetItem *parentItem = item->parent();
if (!parentItem)
return;
Qt::CheckState State = item->checkState(0);
for (;;)
{
QTreeWidgetItem *parentParentItem = parentItem->parent();
QTreeWidgetItem* ParentParentItem = ParentItem->parent();
if (parentParentItem)
parentItem = parentParentItem;
if (ParentParentItem)
ParentItem = ParentParentItem;
else
break;
}
ui->treeWidget->blockSignals(true);
setSelection(parentItem, selected);
QList<QTreeWidgetItem*> Items;
Items.append(ParentItem);
while (!Items.isEmpty())
{
QTreeWidgetItem* Item = Items[0];
Items.removeFirst();
if (!Item->childCount())
Item->setCheckState(0, State);
else
{
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
Items.append(Item->child(ChildIdx));
}
}
ui->treeWidget->blockSignals(false);
}
void lcQSelectDialog::setSelection(QTreeWidgetItem *parentItem, bool selected)
void lcQSelectDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup)
{
for (int childIndex = 0; childIndex < parentItem->childCount(); childIndex++)
Project* Project = lcGetActiveProject();
const lcArray<lcGroup*>& Groups = Project->GetGroups();
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
{
QTreeWidgetItem *childItem = parentItem->child(childIndex);
lcGroup* Group = Groups[GroupIdx];
if (childItem->childCount())
setSelection(childItem, selected);
else
{
int itemIndex = childItem->data(0, IndexRole).value<int>();
options->Selection[itemIndex] = selected;
childItem->setCheckState(0, selected ? Qt::Checked : Qt::Unchecked);
}
}
}
void lcQSelectDialog::loadSelection(QTreeWidgetItem *parentItem)
{
for (int childIndex = 0; childIndex < parentItem->childCount(); childIndex++)
{
QTreeWidgetItem *childItem = parentItem->child(childIndex);
if (childItem->childCount())
loadSelection(childItem);
else
{
int itemIndex = childItem->data(0, IndexRole).value<int>();
childItem->setCheckState(0, options->Selection[itemIndex] ? Qt::Checked : Qt::Unchecked);
}
}
}
void lcQSelectDialog::saveSelection(QTreeWidgetItem *parentItem)
{
for (int childIndex = 0; childIndex < parentItem->childCount(); childIndex++)
{
QTreeWidgetItem *childItem = parentItem->child(childIndex);
if (childItem->childCount())
saveSelection(childItem);
else
{
int itemIndex = childItem->data(0, IndexRole).value<int>();
options->Selection[itemIndex] = (childItem->checkState(0) == Qt::Checked);
}
}
}
void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, lcGroup *parentGroup)
{
Project *project = lcGetActiveProject();
int numObjects = 0;
const lcArray<lcGroup*>& groups = project->GetGroups();
for (int groupIdx = 0; groupIdx < groups.GetSize(); groupIdx++)
{
lcGroup* group = groups[groupIdx];
if (group->mGroup != parentGroup)
if (Group->mGroup != ParentGroup)
continue;
QTreeWidgetItem *groupItem = new QTreeWidgetItem(parentItem, QStringList(group->m_strName));
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->m_strName));
addChildren(groupItem, group);
AddChildren(GroupItem, Group);
}
const lcArray<lcPiece*>& pieces = project->GetPieces();
lcStep currentStep = project->GetCurrentStep();
const lcArray<lcPiece*>& Pieces = Project->GetPieces();
lcStep currentStep = Project->GetCurrentStep();
for (int pieceIdx = 0; pieceIdx < pieces.GetSize(); pieceIdx++, numObjects++)
for (int PieceIdx = 0; PieceIdx < Pieces.GetSize(); PieceIdx++)
{
lcPiece *piece = pieces[pieceIdx];
lcPiece* Piece = Pieces[PieceIdx];
if (piece->GetGroup() != parentGroup)
if (Piece->GetGroup() != ParentGroup || !Piece->IsVisible(currentStep))
continue;
if (!piece->IsVisible(currentStep))
continue;
QTreeWidgetItem *pieceItem = new QTreeWidgetItem(parentItem, QStringList(piece->GetName()));
pieceItem->setData(0, IndexRole, qVariantFromValue(numObjects));
pieceItem->setCheckState(0, options->Selection[numObjects] ? Qt::Checked : Qt::Unchecked);
QTreeWidgetItem* PieceItem = new QTreeWidgetItem(ParentItem, QStringList(Piece->GetName()));
PieceItem->setData(0, IndexRole, qVariantFromValue<uintptr_t>((uintptr_t)Piece));
PieceItem->setCheckState(0, Piece->IsSelected() ? Qt::Checked : Qt::Unchecked);
}
if (!parentGroup)
if (!ParentGroup)
{
const lcArray<lcCamera*>& cameras = project->GetCameras();
const lcArray<lcCamera*>& Cameras = Project->GetCameras();
for (int cameraIdx = 0; cameraIdx < cameras.GetSize(); cameraIdx++, numObjects++)
for (int CameraIdx = 0; CameraIdx < Cameras.GetSize(); CameraIdx++)
{
lcCamera *camera = cameras[cameraIdx];
lcCamera* Camera = Cameras[CameraIdx];
if (!camera->IsVisible())
if (!Camera->IsVisible())
continue;
QTreeWidgetItem *cameraItem = new QTreeWidgetItem(parentItem, QStringList(camera->GetName()));
cameraItem->setData(0, IndexRole, qVariantFromValue(numObjects));
cameraItem->setCheckState(0, options->Selection[numObjects] ? Qt::Checked : Qt::Unchecked);
QTreeWidgetItem *cameraItem = new QTreeWidgetItem(ParentItem, QStringList(Camera->GetName()));
cameraItem->setData(0, IndexRole, qVariantFromValue<uintptr_t>((uintptr_t)Camera));
cameraItem->setCheckState(0, Camera->IsSelected() ? Qt::Checked : Qt::Unchecked);
}
const lcArray<lcLight*>& lights = project->GetLights();
const lcArray<lcLight*>& Lights = Project->GetLights();
for (int lightIdx = 0; lightIdx < lights.GetSize(); lightIdx++, numObjects++)
for (int LightIdx = 0; LightIdx < Lights.GetSize(); LightIdx++)
{
lcLight* light = lights[lightIdx];
lcLight* Light = Lights[LightIdx];
if (!light->IsVisible())
if (!Light->IsVisible())
continue;
QTreeWidgetItem *lightItem = new QTreeWidgetItem(parentItem, QStringList(light->GetName()));
lightItem->setData(0, IndexRole, qVariantFromValue(numObjects));
lightItem->setCheckState(0, options->Selection[numObjects] ? Qt::Checked : Qt::Unchecked);
QTreeWidgetItem *lightItem = new QTreeWidgetItem(ParentItem, QStringList(Light->GetName()));
lightItem->setData(0, IndexRole, qVariantFromValue<uintptr_t>((uintptr_t)Light));
lightItem->setCheckState(0, Light->IsSelected() ? Qt::Checked : Qt::Unchecked);
}
}
}
+1 -4
View File
@@ -33,10 +33,7 @@ public slots:
private:
Ui::lcQSelectDialog *ui;
void setSelection(QTreeWidgetItem *parentItem, bool selected);
void loadSelection(QTreeWidgetItem *parentItem);
void saveSelection(QTreeWidgetItem *parentItem);
void addChildren(QTreeWidgetItem *parentItem, lcGroup *parentGroup);
void AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup);
};
#endif // _LC_QSELECTDIALOG_H_