From 1921fbf5de6f3d6f32b2e3692a9bc6a898b87e2c Mon Sep 17 00:00:00 2001 From: parax0 Date: Sat, 19 Mar 2016 21:02:23 -0600 Subject: [PATCH] Added "select connected" action to CSceneViewport context menu --- src/Editor/CSceneViewport.cpp | 41 +++++++++++++++++++++++++++++++- src/Editor/CSceneViewport.h | 3 +++ src/Editor/INodeEditor.cpp | 44 +++++++++++++++++++++++++++++++++++ src/Editor/INodeEditor.h | 2 ++ 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/src/Editor/CSceneViewport.cpp b/src/Editor/CSceneViewport.cpp index 8aac6d01..ad2c2cdb 100644 --- a/src/Editor/CSceneViewport.cpp +++ b/src/Editor/CSceneViewport.cpp @@ -179,6 +179,9 @@ void CSceneViewport::CreateContextMenu() mpToggleSelectAction = new QAction("ToggleSelect", this); connect(mpToggleSelectAction, SIGNAL(triggered()), this, SLOT(OnToggleSelect())); + mpSelectConnectedAction = new QAction("Select connected", this); + connect(mpSelectConnectedAction, SIGNAL(triggered()), this, SLOT(OnSelectConnected())); + mpHideSelectionSeparator = new QAction(this); mpHideSelectionSeparator->setSeparator(true); @@ -207,7 +210,7 @@ void CSceneViewport::CreateContextMenu() connect(mpUnhideAllAction, SIGNAL(triggered()), this, SLOT(OnUnhideAll())); QList Actions; - Actions << mpToggleSelectAction + Actions << mpToggleSelectAction << mpSelectConnectedAction << mpHideSelectionSeparator << mpHideSelectionAction << mpHideUnselectedAction << mpHideHoverSeparator << mpHideHoverNodeAction << mpHideHoverTypeAction << mpHideHoverLayerAction << mpUnhideSeparator << mpUnhideAllAction; @@ -220,6 +223,29 @@ QMouseEvent CSceneViewport::CreateMouseEvent() return QMouseEvent(QEvent::MouseMove, mapFromGlobal(QCursor::pos()), Qt::NoButton, qApp->mouseButtons(), qApp->keyboardModifiers()); } +void CSceneViewport::FindConnectedObjects(u32 InstanceID, QList& rIDList) +{ + CScriptNode *pScript = mpScene->NodeForInstanceID(InstanceID); + CScriptObject *pInst = pScript->Object(); + rIDList << InstanceID; + + for (u32 iLink = 0; iLink < pInst->NumLinks(eOutgoing); iLink++) + { + CLink *pLink = pInst->Link(eOutgoing, iLink); + + if (!rIDList.contains(pLink->ReceiverID())) + FindConnectedObjects(pLink->ReceiverID(), rIDList); + } + + for (u32 iLink = 0; iLink < pInst->NumLinks(eIncoming); iLink++) + { + CLink *pLink = pInst->Link(eIncoming, iLink); + + if (!rIDList.contains(pLink->SenderID())) + FindConnectedObjects(pLink->SenderID(), rIDList); + } +} + // ************ PROTECTED SLOTS ************ void CSceneViewport::CheckUserInput() { @@ -302,6 +328,7 @@ void CSceneViewport::ContextMenu(QContextMenuEvent* pEvent) bool IsScriptNode = (mpHoverNode && mpHoverNode->NodeType() == eScriptNode); mpToggleSelectAction->setVisible(HasHoverNode); + mpSelectConnectedAction->setVisible(IsScriptNode); mpHideSelectionSeparator->setVisible(HasHoverNode); mpHideSelectionAction->setVisible(HasSelection); mpHideUnselectedAction->setVisible(HasSelection); @@ -385,6 +412,18 @@ void CSceneViewport::OnToggleSelect() mpEditor->SelectNode(mpMenuNode); } +void CSceneViewport::OnSelectConnected() +{ + QList InstanceIDs; + FindConnectedObjects(static_cast(mpMenuNode)->Object()->InstanceID(), InstanceIDs); + + QList Nodes; + foreach (u32 ID, InstanceIDs) + Nodes << mpScene->NodeForInstanceID(ID); + + mpEditor->BatchSelectNodes(Nodes); +} + void CSceneViewport::OnHideSelection() { for (CSelectionIterator It(mpEditor->Selection()); It; ++It) diff --git a/src/Editor/CSceneViewport.h b/src/Editor/CSceneViewport.h index 3aab662c..2e976215 100644 --- a/src/Editor/CSceneViewport.h +++ b/src/Editor/CSceneViewport.h @@ -23,6 +23,7 @@ class CSceneViewport : public CBasicViewport // Context Menu QMenu *mpContextMenu; QAction *mpToggleSelectAction; + QAction *mpSelectConnectedAction; QAction *mpHideSelectionSeparator; QAction *mpHideSelectionAction; QAction *mpHideUnselectedAction; @@ -68,6 +69,7 @@ public: protected: void CreateContextMenu(); QMouseEvent CreateMouseEvent(); + void FindConnectedObjects(u32 InstanceID, QList& rIDList); signals: void InputProcessed(const SRayIntersection& rkIntersect, QMouseEvent *pEvent); @@ -85,6 +87,7 @@ protected slots: // Menu Actions void OnToggleSelect(); + void OnSelectConnected(); void OnHideSelection(); void OnHideUnselected(); void OnHideNode(); diff --git a/src/Editor/INodeEditor.cpp b/src/Editor/INodeEditor.cpp index ae180924..d8f7a51d 100644 --- a/src/Editor/INodeEditor.cpp +++ b/src/Editor/INodeEditor.cpp @@ -135,6 +135,28 @@ void INodeEditor::SelectNode(CSceneNode *pNode) } } +void INodeEditor::BatchSelectNodes(QList Nodes) +{ + if (!mSelectionLocked) + { + foreach (CSceneNode *pNode, Nodes) + { + if (pNode->IsSelected()) + Nodes.removeOne(pNode); + } + + if (Nodes.size() > 0) + { + mUndoStack.beginMacro("Select"); + + foreach (CSceneNode *pNode, Nodes) + SelectNode(pNode); + + mUndoStack.endMacro(); + } + } +} + void INodeEditor::DeselectNode(CSceneNode *pNode) { if (!mSelectionLocked) @@ -144,6 +166,28 @@ void INodeEditor::DeselectNode(CSceneNode *pNode) } } +void INodeEditor::BatchDeselectNodes(QList Nodes) +{ + if (!mSelectionLocked) + { + foreach (CSceneNode *pNode, Nodes) + { + if (!pNode->IsSelected()) + Nodes.removeOne(pNode); + } + + if (Nodes.size() > 0) + { + mUndoStack.beginMacro("Deselect"); + + foreach (CSceneNode *pNode, Nodes) + DeselectNode(pNode); + + mUndoStack.endMacro(); + } + } +} + void INodeEditor::ClearSelection() { if (!mSelectionLocked) diff --git a/src/Editor/INodeEditor.h b/src/Editor/INodeEditor.h index 471c2cf9..76ad0aa5 100644 --- a/src/Editor/INodeEditor.h +++ b/src/Editor/INodeEditor.h @@ -63,7 +63,9 @@ public: ETransformSpace CurrentTransformSpace(); void SelectNode(CSceneNode *pNode); + void BatchSelectNodes(QList Nodes); void DeselectNode(CSceneNode *pNode); + void BatchDeselectNodes(QList Nodes); void ClearSelection(); void ClearAndSelectNode(CSceneNode *pNode); void SelectAll(FNodeFlags NodeFlags);