diff --git a/common/lc_model.h b/common/lc_model.h index ee0f54c9..b21da28f 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -78,7 +78,27 @@ public: lcModel(); ~lcModel(); -public: + const lcArray& GetPieces() const + { + return mPieces; + } + + const lcArray& GetCameras() const + { + return mCameras; + } + + const lcArray& GetLights() const + { + return mLights; + } + + const lcArray& GetGroups() const + { + return mGroups; + } + +protected: lcModelProperties mProperties; lcArray mPieces; diff --git a/common/project.cpp b/common/project.cpp index 8066cf43..cbb049cb 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -32,8 +32,6 @@ Project::Project() { m_bModified = false; - m_nTracking = LC_TRACK_NONE; - mDropPiece = NULL; m_pUndoList = NULL; m_pRedoList = NULL; mTransformType = LC_TRANSFORM_RELATIVE_TRANSLATION; @@ -1642,13 +1640,11 @@ void Project::RenderSceneObjects(View* view) RenderDebugPrimitives(); #endif - // Draw cameras & lights - if (gMainWindow->GetTool() == LC_TOOL_INSERT || mDropPiece) + if (view->mTrackTool == LC_TRACKTOOL_INSERT) { lcVector3 Position; lcVector4 Rotation; GetPieceInsertPosition(view, Position, Rotation); - PieceInfo* PreviewPiece = mDropPiece ? mDropPiece : m_pCurPiece; lcMatrix44 WorldMatrix = lcMatrix44FromAxisAngle(lcVector3(Rotation[0], Rotation[1], Rotation[2]), Rotation[3] * LC_DTOR); WorldMatrix.SetTranslation(Position); @@ -1656,11 +1652,11 @@ void Project::RenderSceneObjects(View* view) Context->SetWorldViewMatrix(lcMul(WorldMatrix, ViewMatrix)); Context->SetLineWidth(2.0f * Preferences.mLineWidth); - PreviewPiece->RenderPiece(gMainWindow->mColorIndex); + m_pCurPiece->RenderPiece(gMainWindow->mColorIndex); } if (Preferences.mLightingMode != LC_LIGHTING_FLAT) - glDisable (GL_LIGHTING); + glDisable(GL_LIGHTING); for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++) { @@ -1685,7 +1681,7 @@ void Project::RenderSceneObjects(View* view) const int Spacing = lcMax(Preferences.mGridLineSpacing, 1); int MinX = 0, MaxX = 0, MinY = 0, MaxY = 0; - if (!mPieces.IsEmpty() || (gMainWindow->GetTool() == LC_TOOL_INSERT || mDropPiece)) + if (!mPieces.IsEmpty() || view->mTrackTool == LC_TRACKTOOL_INSERT) { float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 }; @@ -1697,24 +1693,22 @@ void Project::RenderSceneObjects(View* view) Piece->CompareBoundingBox(bs); } - if (gMainWindow->GetTool() == LC_TOOL_INSERT || mDropPiece) + if (view->mTrackTool == LC_TRACKTOOL_INSERT) { lcVector3 Position; lcVector4 Rotation; GetPieceInsertPosition(view, Position, Rotation); - PieceInfo* PreviewPiece = mDropPiece ? mDropPiece : m_pCurPiece; - lcVector3 Points[8] = { - lcVector3(PreviewPiece->m_fDimensions[0],PreviewPiece->m_fDimensions[1], PreviewPiece->m_fDimensions[5]), - lcVector3(PreviewPiece->m_fDimensions[3],PreviewPiece->m_fDimensions[1], PreviewPiece->m_fDimensions[5]), - lcVector3(PreviewPiece->m_fDimensions[0],PreviewPiece->m_fDimensions[1], PreviewPiece->m_fDimensions[2]), - lcVector3(PreviewPiece->m_fDimensions[3],PreviewPiece->m_fDimensions[4], PreviewPiece->m_fDimensions[5]), - lcVector3(PreviewPiece->m_fDimensions[3],PreviewPiece->m_fDimensions[4], PreviewPiece->m_fDimensions[2]), - lcVector3(PreviewPiece->m_fDimensions[0],PreviewPiece->m_fDimensions[4], PreviewPiece->m_fDimensions[2]), - lcVector3(PreviewPiece->m_fDimensions[0],PreviewPiece->m_fDimensions[4], PreviewPiece->m_fDimensions[5]), - lcVector3(PreviewPiece->m_fDimensions[3],PreviewPiece->m_fDimensions[1], PreviewPiece->m_fDimensions[2]) + lcVector3(m_pCurPiece->m_fDimensions[0], m_pCurPiece->m_fDimensions[1], m_pCurPiece->m_fDimensions[5]), + lcVector3(m_pCurPiece->m_fDimensions[3], m_pCurPiece->m_fDimensions[1], m_pCurPiece->m_fDimensions[5]), + lcVector3(m_pCurPiece->m_fDimensions[0], m_pCurPiece->m_fDimensions[1], m_pCurPiece->m_fDimensions[2]), + lcVector3(m_pCurPiece->m_fDimensions[3], m_pCurPiece->m_fDimensions[4], m_pCurPiece->m_fDimensions[5]), + lcVector3(m_pCurPiece->m_fDimensions[3], m_pCurPiece->m_fDimensions[4], m_pCurPiece->m_fDimensions[2]), + lcVector3(m_pCurPiece->m_fDimensions[0], m_pCurPiece->m_fDimensions[4], m_pCurPiece->m_fDimensions[2]), + lcVector3(m_pCurPiece->m_fDimensions[0], m_pCurPiece->m_fDimensions[4], m_pCurPiece->m_fDimensions[5]), + lcVector3(m_pCurPiece->m_fDimensions[3], m_pCurPiece->m_fDimensions[1], m_pCurPiece->m_fDimensions[2]) }; lcMatrix44 ModelWorld = lcMatrix44FromAxisAngle(lcVector3(Rotation[0], Rotation[1], Rotation[2]), Rotation[3] * LC_DTOR); @@ -5651,8 +5645,9 @@ void Project::HandleCommand(LC_COMMANDS id) case LC_EDIT_CANCEL: { - if (m_nTracking != LC_TRACK_NONE) - StopTracking(false); + View* ActiveView = gMainWindow->GetActiveView(); + if (ActiveView && ActiveView->mTrackButton != LC_TRACKBUTTON_NONE) + ActiveView->StopTracking(false); else { SelectAndFocusNone(false); @@ -6061,64 +6056,6 @@ void Project::BoxTest(lcObjectBoxTest& ObjectBoxTest) const mLights[LightIdx]->BoxTest(ObjectBoxTest); } -bool Project::StopTracking(bool bAccept) -{ - if (m_nTracking == LC_TRACK_NONE) - return false; - - View* ActiveView = gMainWindow->GetActiveView(); - - m_nTracking = LC_TRACK_NONE; - - if (bAccept && mDropPiece) - { - int x = m_nDownX; - int y = m_nDownY; - - if ((x > 0) && (x < ActiveView->mWidth) && (y > 0) && (y < ActiveView->mHeight)) - { - lcVector3 Pos; - lcVector4 Rot; - - GetPieceInsertPosition(ActiveView, Pos, Rot); - - Piece* pPiece = new Piece(mDropPiece); - pPiece->Initialize(Pos[0], Pos[1], Pos[2], m_nCurStep); - pPiece->SetColorIndex(gMainWindow->mColorIndex); - - pPiece->ChangeKey(m_nCurStep, false, Rot, LC_PK_ROTATION); - pPiece->UpdatePosition(m_nCurStep); - - pPiece->CreateName(mPieces); - mPieces.Add(pPiece); - SystemPieceComboAdd(mDropPiece->m_strDescription); - ClearSelectionAndSetFocus(pPiece, LC_PIECE_SECTION_POSITION); - - if (mDropPiece) - { - mDropPiece->Release(); - mDropPiece = NULL; - } - - SetModifiedFlag(true); - CheckPoint("Inserting"); - } - } - - if (mDropPiece) - { - mDropPiece->Release(); - mDropPiece = NULL; - } - - return true; -} - -void Project::StartTracking(int mode) -{ - m_nTracking = mode; -} - void Project::GetSnapIndex(int* SnapXY, int* SnapZ, int* SnapAngle) const { if (SnapXY) @@ -6890,42 +6827,6 @@ void Project::ZoomActiveView(int Amount) gMainWindow->UpdateAllViews(); } -void Project::BeginPieceDrop(PieceInfo* Info) -{ - StartTracking(LC_TRACK_LEFT); - - mDropPiece = Info; - mDropPiece->AddRef(); -} - -void Project::OnPieceDropMove(int x, int y) -{ - if (!mDropPiece) - return; - - if (m_nDownX != x || m_nDownY != y) - { - m_nDownX = x; - m_nDownY = y; - - gMainWindow->UpdateAllViews(); - } -} - -void Project::EndPieceDrop(bool Accept) -{ - StopTracking(Accept); - - if (!Accept) - gMainWindow->UpdateAllViews(); -} - -void Project::BeginColorDrop() -{ - StartTracking(LC_TRACK_LEFT); - gMainWindow->SetTool(LC_TOOL_PAINT); -} - void Project::BeginMouseTool() { mMouseToolDistance = lcVector3(0.0f, 0.0f, 0.0f); diff --git a/common/project.h b/common/project.h index 628014f8..46b576d5 100644 --- a/common/project.h +++ b/common/project.h @@ -210,10 +210,6 @@ public: public: void DeleteContents(bool bUndo); void LoadDefaults(bool cameras); - void BeginPieceDrop(PieceInfo* Info); - void OnPieceDropMove(int x, int y); - void EndPieceDrop(bool Accept); - void BeginColorDrop(); void RenderInitialize(); void GetPiecesUsed(lcArray& PiecesUsed) const; @@ -280,12 +276,6 @@ protected: void ExportPOVRay(lcFile& File); void ZoomExtents(int FirstView, int LastView); - int m_nTracking; - int m_nDownX; - int m_nDownY; - - bool StopTracking(bool bAccept); - void StartTracking(int mode); void UpdateSelection(); void RemoveEmptyGroups(); @@ -299,7 +289,6 @@ protected: // State variables int mTransformType; PieceInfo* m_pCurPiece; - PieceInfo* mDropPiece; unsigned char m_nCurStep; lcuint16 m_nMoveSnap; diff --git a/common/view.cpp b/common/view.cpp index 90503d64..6cc8764f 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -13,6 +13,7 @@ View::View(Project *project) mProject = project; mCamera = NULL; + mDragState = LC_DRAGSTATE_NONE; mTrackButton = LC_TRACKBUTTON_NONE; mTrackTool = LC_TRACKTOOL_NONE; @@ -922,6 +923,26 @@ float View::GetOverlayScale() const return Dist.Length() * 5.0f; } +void View::BeginPieceDrag() +{ + mDragState = LC_DRAGSTATE_PIECE; + UpdateTrackTool(); +} + +void View::EndPieceDrag(bool Accept) +{ + if (Accept) + { + lcVector3 Position; + lcVector4 Rotation; + mProject->GetPieceInsertPosition(this, Position, Rotation); + mProject->InsertPieceToolClicked(Position, Rotation); + } + + mDragState = LC_DRAGSTATE_NONE; + UpdateTrackTool(); +} + void View::UpdateTrackTool() { lcTool CurrentTool = gMainWindow->GetTool(); @@ -1240,6 +1261,17 @@ void View::UpdateTrackTool() break; } + switch (mDragState) + { + case LC_DRAGSTATE_NONE: + break; + + case LC_DRAGSTATE_PIECE: + NewTrackTool = LC_TRACKTOOL_INSERT; + Redraw = true; + break; + } + if (NewTrackTool != mTrackTool) { mTrackTool = NewTrackTool; @@ -1641,6 +1673,8 @@ void View::OnMouseMove() { if (mTrackButton == LC_TRACKBUTTON_NONE) { + UpdateTrackTool(); + if (mTrackTool == LC_TRACKTOOL_INSERT) { /* lcVector3 Position; @@ -1650,11 +1684,8 @@ void View::OnMouseMove() mProject->mActiveModel->SetPreviewTransform(Position, AxisAngle); */ gMainWindow->UpdateAllViews(); - - return; } - UpdateTrackTool(); return; } diff --git a/common/view.h b/common/view.h index ae481cee..31c77908 100644 --- a/common/view.h +++ b/common/view.h @@ -46,6 +46,13 @@ enum lcTrackTool LC_TRACKTOOL_ZOOM_REGION }; +enum lcDragState +{ + LC_DRAGSTATE_NONE, + LC_DRAGSTATE_PIECE +// LC_DRAGSTATE_COLOR +}; + class View : public lcGLWidget { public: @@ -65,6 +72,9 @@ public: void OnMouseMove(); void OnMouseWheel(float Direction); + void BeginPieceDrag(); + void EndPieceDrag(bool Accept); + void SetCamera(Camera* camera, bool ForceCopy); void SetDefaultCamera(); lcMatrix44 GetProjectionMatrix() const; @@ -107,10 +117,13 @@ protected: void StartTracking(lcTrackButton TrackButton); void StopTracking(bool Accept); + lcDragState mDragState; lcTrackButton mTrackButton; lcTrackTool mTrackTool; int mMouseDownX; int mMouseDownY; + + friend class Project; }; #endif // _VIEW_H_ diff --git a/qt/lc_qeditgroupsdialog.cpp b/qt/lc_qeditgroupsdialog.cpp index 1684af90..469fdb1a 100644 --- a/qt/lc_qeditgroupsdialog.cpp +++ b/qt/lc_qeditgroupsdialog.cpp @@ -96,6 +96,8 @@ void lcQEditGroupsDialog::timerEvent(QTimerEvent *event) void lcQEditGroupsDialog::updateParents(QTreeWidgetItem *parentItem, Group *parentGroup) { Project *project = lcGetActiveProject(); + const lcArray& pieces = project->GetPieces(); + const lcArray& groups = project->GetGroups(); for (int childIndex = 0; childIndex < parentItem->childCount(); childIndex++) { @@ -105,7 +107,7 @@ void lcQEditGroupsDialog::updateParents(QTreeWidgetItem *parentItem, Group *pare if (itemPiece) { - int pieceIndex = project->mPieces.FindIndex(itemPiece); + int pieceIndex = pieces.FindIndex(itemPiece); if (pieceIndex != -1) options->PieceParents[pieceIndex] = parentGroup; } @@ -116,9 +118,9 @@ void lcQEditGroupsDialog::updateParents(QTreeWidgetItem *parentItem, Group *pare strncpy(itemGroup->m_strName, childItem->text(0).toLocal8Bit(), sizeof(itemGroup->m_strName)); itemGroup->m_strName[sizeof(itemGroup->m_strName) - 1] = 0; - for (int groupIdx = 0; groupIdx < project->mGroups.GetSize(); groupIdx++) + for (int groupIdx = 0; groupIdx < groups.GetSize(); groupIdx++) { - lcGroup *group = project->mGroups[groupIdx]; + lcGroup *group = groups[groupIdx]; if (itemGroup == group) { @@ -135,10 +137,12 @@ void lcQEditGroupsDialog::updateParents(QTreeWidgetItem *parentItem, Group *pare void lcQEditGroupsDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGroup) { Project *project = lcGetActiveProject(); + const lcArray& pieces = project->GetPieces(); + const lcArray& groups = project->GetGroups(); - for (int groupIdx = 0; groupIdx < project->mGroups.GetSize(); groupIdx++) + for (int groupIdx = 0; groupIdx < groups.GetSize(); groupIdx++) { - lcGroup *group = project->mGroups[groupIdx]; + lcGroup *group = groups[groupIdx]; if (group->mGroup != parentGroup) continue; @@ -150,9 +154,9 @@ void lcQEditGroupsDialog::addChildren(QTreeWidgetItem *parentItem, Group *parent addChildren(groupItem, group); } - for (int pieceIndex = 0; pieceIndex < project->mPieces.GetSize(); pieceIndex++) + for (int pieceIndex = 0; pieceIndex < pieces.GetSize(); pieceIndex++) { - Piece *piece = project->mPieces[pieceIndex]; + Piece *piece = pieces[pieceIndex]; if (piece->GetGroup() != parentGroup) continue; diff --git a/qt/lc_qglwidget.cpp b/qt/lc_qglwidget.cpp index b21792ea..0d8a40ad 100644 --- a/qt/lc_qglwidget.cpp +++ b/qt/lc_qglwidget.cpp @@ -7,6 +7,7 @@ #include "lc_qmainwindow.h" #include "lc_mainwindow.h" #include "lc_context.h" +#include "view.h" void lcGLWidget::MakeCurrent() { @@ -303,7 +304,7 @@ void lcQGLWidget::dragEnterEvent(QDragEnterEvent *event) dataStream >> id; - lcGetActiveProject()->BeginPieceDrop(lcGetPiecesLibrary()->FindPiece(id.toLocal8Bit().data(), false)); + ((View*)widget)->BeginPieceDrag(); } else event->ignore(); @@ -314,7 +315,7 @@ void lcQGLWidget::dragLeaveEvent(QDragLeaveEvent *event) if (!isView) return; - lcGetActiveProject()->EndPieceDrop(false); + ((View*)widget)->EndPieceDrag(false); event->accept(); } @@ -326,7 +327,13 @@ void lcQGLWidget::dragMoveEvent(QDragMoveEvent *event) float scale = deviceScale(); - lcGetActiveProject()->OnPieceDropMove(event->pos().x() * scale, widget->mHeight - event->pos().y() * scale - 1); + widget->mInputState.x = event->pos().x() * scale; + widget->mInputState.y = widget->mHeight - event->pos().y() * scale - 1; + widget->mInputState.Control = (event->keyboardModifiers() & Qt::ControlModifier) != 0; + widget->mInputState.Shift = (event->keyboardModifiers() & Qt::ShiftModifier) != 0; + widget->mInputState.Alt = (event->keyboardModifiers() & Qt::AltModifier) != 0; + + widget->OnMouseMove(); event->accept(); } @@ -336,7 +343,7 @@ void lcQGLWidget::dropEvent(QDropEvent *event) if (!isView || !event->mimeData()->hasFormat("application/vnd.leocad-part")) return; - lcGetActiveProject()->EndPieceDrop(true); + ((View*)widget)->EndPieceDrag(true); event->accept(); } diff --git a/qt/lc_qmainwindow.cpp b/qt/lc_qmainwindow.cpp index d0714a10..a4977653 100644 --- a/qt/lc_qmainwindow.cpp +++ b/qt/lc_qmainwindow.cpp @@ -54,7 +54,7 @@ lcQMainWindow::lcQMainWindow(QWidget *parent) GL_EnableVertexBufferObject(); - if (!lcGetActiveProject()->mPieces.IsEmpty()) + if (!lcGetActiveProject()->GetPieces().IsEmpty()) { for (int PieceIdx = 0; PieceIdx < Library->mPieces.GetSize(); PieceIdx++) { @@ -1218,7 +1218,7 @@ void lcQMainWindow::updateTransformType(int newType) void lcQMainWindow::updateCameraMenu() { - const lcArray& cameras = lcGetActiveProject()->mCameras; + const lcArray& cameras = lcGetActiveProject()->GetCameras(); Camera* currentCamera = gMainWindow->GetActiveView()->mCamera; int actionIdx, currentIndex = -1; diff --git a/qt/lc_qselectdialog.cpp b/qt/lc_qselectdialog.cpp index 53951c31..caf1c624 100644 --- a/qt/lc_qselectdialog.cpp +++ b/qt/lc_qselectdialog.cpp @@ -149,10 +149,13 @@ void lcQSelectDialog::saveSelection(QTreeWidgetItem *parentItem) void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGroup) { Project *project = lcGetActiveProject(); + int numObjects = 0; - for (int groupIdx = 0; groupIdx < project->mGroups.GetSize(); groupIdx++) + const lcArray& groups = project->GetGroups(); + + for (int groupIdx = 0; groupIdx < groups.GetSize(); groupIdx++) { - lcGroup* group = project->mGroups[groupIdx]; + lcGroup* group = groups[groupIdx]; if (group->mGroup != parentGroup) continue; @@ -162,11 +165,11 @@ void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGrou addChildren(groupItem, group); } - int numObjects = 0; + const lcArray& pieces = project->GetPieces(); - for (int pieceIdx = 0; pieceIdx < project->mPieces.GetSize(); pieceIdx++, numObjects++) + for (int pieceIdx = 0; pieceIdx < pieces.GetSize(); pieceIdx++, numObjects++) { - lcPiece *piece = project->mPieces[pieceIdx]; + lcPiece *piece = pieces[pieceIdx]; if (piece->GetGroup() != parentGroup) continue; @@ -181,9 +184,11 @@ void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGrou if (!parentGroup) { - for (int cameraIdx = 0; cameraIdx < project->mCameras.GetSize(); cameraIdx++, numObjects++) + const lcArray& cameras = project->GetCameras(); + + for (int cameraIdx = 0; cameraIdx < cameras.GetSize(); cameraIdx++, numObjects++) { - lcCamera *camera = project->mCameras[cameraIdx]; + lcCamera *camera = cameras[cameraIdx]; if (!camera->IsVisible()) continue; @@ -193,9 +198,11 @@ void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGrou cameraItem->setCheckState(0, options->Selection[numObjects] ? Qt::Checked : Qt::Unchecked); } - for (int lightIdx = 0; lightIdx < project->mLights.GetSize(); lightIdx++, numObjects++) + const lcArray& lights = project->GetLights(); + + for (int lightIdx = 0; lightIdx < lights.GetSize(); lightIdx++, numObjects++) { - lcLight* light = project->mLights[lightIdx]; + lcLight* light = lights[lightIdx]; if (!light->IsVisible()) continue;