diff --git a/src/lib/component/controller/FeatureController.cpp b/src/lib/component/controller/FeatureController.cpp index 20dd4238..2a20dc35 100644 --- a/src/lib/component/controller/FeatureController.cpp +++ b/src/lib/component/controller/FeatureController.cpp @@ -95,12 +95,12 @@ void FeatureController::handleMessage(MessageActivateNodes* message) void FeatureController::handleMessage(MessageActivateTokenLocations* message) { - std::vector nodeIds; - MessageActivateNodes msg; + std::vector nodeIds = m_storageAccess->getNodeIdsForLocationIds(message->locationIds); + nodeIds = m_storageAccess->getActiveTokenIdsForTokenIds(nodeIds); - for (Id locationId : message->locationIds) + MessageActivateNodes msg; + for (Id nodeId : nodeIds) { - Id nodeId = m_storageAccess->getActiveNodeIdForLocationId(locationId); msg.addNode( nodeId, m_storageAccess->getNodeTypeForNodeWithId(nodeId), @@ -112,7 +112,10 @@ void FeatureController::handleMessage(MessageActivateTokenLocations* message) void FeatureController::handleMessage(MessageSearch* message) { - MessageActivateTokens m(m_storageAccess->getTokenIdsForMatches(message->getMatches())); + std::vector tokenIds = m_storageAccess->getTokenIdsForMatches(message->getMatches()); + tokenIds = m_storageAccess->getActiveTokenIdsForTokenIds(tokenIds); + + MessageActivateTokens m(tokenIds); m.undoRedoType = message->undoRedoType; m.dispatchImmediately(); } diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index c1159d70..39c1d554 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -174,8 +174,6 @@ void GraphController::createDummyGraphForTokenIds(const std::vector& tokenId autoExpandActiveNode(tokenIds); setActiveAndVisibility(tokenIds); - splitNamespaceNodes(); - bundleNodes(); layoutNesting(); @@ -276,45 +274,6 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node) return result; } -void GraphController::splitNamespaceNodes() -{ - std::vector nodes; - - for (const DummyNode& node : m_dummyNodes) - { - std::vector newNodes = splitNamespaceNodesRecursive(node, false, true); - nodes.insert(nodes.end(), newNodes.begin(), newNodes.end()); - } - - m_dummyNodes = nodes; -} - -std::vector GraphController::splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel) -{ - std::vector nodes; - active |= node.active; - - if (node.isGraphNode() && node.data->isType(Node::NODE_NOT_VISIBLE)) - { - for (const DummyNode& subNode : node.subNodes) - { - std::vector newNodes = splitNamespaceNodesRecursive(subNode, active, false); - for (DummyNode& newNode : newNodes) - { - newNode.hasParent = false; - } - - nodes.insert(nodes.end(), newNodes.begin(), newNodes.end()); - } - } - else if (topLevel || active || node.connected) - { - nodes.push_back(node); - } - - return nodes; -} - void GraphController::autoExpandActiveNode(const std::vector& activeTokenIds) { DummyNode* node = nullptr; @@ -419,8 +378,7 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool pa if ((node.isGraphNode() && node.isExpanded()) || (node.isAccessNode() && parentExpanded) || - (node.isGraphNode() && node.data->isType(Node::NODE_ENUM)) || - (node.isGraphNode() && node.data->isType(Node::NODE_NOT_VISIBLE))) + (node.isGraphNode() && node.data->isType(Node::NODE_ENUM))) { for (DummyNode& subNode : node.subNodes) { @@ -897,20 +855,9 @@ DummyNode* GraphController::findTopLevelDummyNodeRecursive(std::vectorgetId() == tokenId) { - if (node.data->isType(Node::NODE_NOT_VISIBLE)) - { - DummyNode* result = findDummyNodeRecursive(node.subNodes, tokenId); - if (result != nullptr) - { - return result; - } - } - else if (node.data->getId() == tokenId) - { - return &node; - } + return &node; } } diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 49062ea4..72da41a2 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -51,9 +51,6 @@ private: void createDummyGraphForTokenIds(const std::vector& tokenIds); DummyNode createDummyNodeTopDown(Node* node); - void splitNamespaceNodes(); - std::vector splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel); - void autoExpandActiveNode(const std::vector& activeTokenIds); void setActiveAndVisibility(const std::vector& activeTokenIds); diff --git a/src/lib/component/controller/helper/BucketGrid.cpp b/src/lib/component/controller/helper/BucketGrid.cpp index 16e389b6..fd3f1329 100644 --- a/src/lib/component/controller/helper/BucketGrid.cpp +++ b/src/lib/component/controller/helper/BucketGrid.cpp @@ -4,6 +4,8 @@ #include "component/controller/helper/DummyNode.h" #include "component/view/GraphViewStyle.h" +const Edge::EdgeTypeMask BucketGrid::s_verticalEdgeMask = Edge::EDGE_INHERITANCE | Edge::EDGE_OVERRIDE; + Bucket::Bucket() : i(0) , j(0) @@ -157,7 +159,7 @@ void BucketGrid::createBuckets(std::vector& nodes, const std::vector< } else { - bool horizontal = edge->data ? !edge->data->isType(Edge::EDGE_INHERITANCE) : true; + bool horizontal = edge->data ? !edge->data->isType(s_verticalEdgeMask) : true; removeEdge = addNode(owner, target, horizontal); } diff --git a/src/lib/component/controller/helper/BucketGrid.h b/src/lib/component/controller/helper/BucketGrid.h index b0e706df..137cf055 100644 --- a/src/lib/component/controller/helper/BucketGrid.h +++ b/src/lib/component/controller/helper/BucketGrid.h @@ -6,6 +6,8 @@ #include "utility/math/Vector2.h" #include "utility/types.h" +#include "data/graph/Edge.h" + struct DummyEdge; struct DummyNode; @@ -41,6 +43,8 @@ public: static void layout(std::vector& nodes, const std::vector& edges, Vec2i viewSize); private: + static const Edge::EdgeTypeMask s_verticalEdgeMask; + BucketGrid(Vec2i viewSize); void createBuckets(std::vector& nodes, const std::vector& edges); diff --git a/src/lib/data/HierarchyCache.cpp b/src/lib/data/HierarchyCache.cpp index d465a2db..e6123c31 100644 --- a/src/lib/data/HierarchyCache.cpp +++ b/src/lib/data/HierarchyCache.cpp @@ -54,6 +54,21 @@ void HierarchyCache::HierarchyNode::addChildIdsRecursive(std::vector* nodeId } } +void HierarchyCache::HierarchyNode::addVisibleNodeIdsRecursive(std::vector* nodeIds) const +{ + if (isVisible()) + { + nodeIds->push_back(getNodeId()); + } + else + { + for (const HierarchyNode* child : m_children) + { + child->addVisibleNodeIdsRecursive(nodeIds); + } + } +} + bool HierarchyCache::HierarchyNode::isVisible() const { return m_isVisible; @@ -65,7 +80,6 @@ void HierarchyCache::HierarchyNode::setIsVisible(bool isVisible) } - void HierarchyCache::clear() { m_nodes.clear(); @@ -108,6 +122,19 @@ void HierarchyCache::addAllChildIdsForNodeId(Id nodeId, std::vector* nodeIds } } +void HierarchyCache::addFirstVisibleChildIdsForNodeId(Id nodeId, std::vector* nodeIds) const +{ + HierarchyNode* node = getNode(nodeId); + if (node) + { + node->addVisibleNodeIdsRecursive(nodeIds); + } + else + { + nodeIds->push_back(nodeId); + } +} + HierarchyCache::HierarchyNode* HierarchyCache::getNode(Id nodeId) const { std::map>::const_iterator it = m_nodes.find(nodeId); diff --git a/src/lib/data/HierarchyCache.h b/src/lib/data/HierarchyCache.h index d14f22c7..efea6eb8 100644 --- a/src/lib/data/HierarchyCache.h +++ b/src/lib/data/HierarchyCache.h @@ -15,7 +15,9 @@ public: void createConnection(Id edgeId, Id fromId, Id toId, bool fromVisible); Id getLastVisibleParentNodeId(Id nodeId) const; + void addAllChildIdsForNodeId(Id nodeId, std::vector* nodeIds, std::vector* edgeIds) const; + void addFirstVisibleChildIdsForNodeId(Id nodeId, std::vector* nodeIds) const; private: class HierarchyNode @@ -33,7 +35,9 @@ private: void addChild(HierarchyNode* child); const std::vector& getChildren() const; + void addChildIdsRecursive(std::vector* nodeIds, std::vector* edgeIds) const; + void addVisibleNodeIdsRecursive(std::vector* nodeIds) const; bool isVisible() const; void setIsVisible(bool isVisible); diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 7232dd97..20d8c5ff 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -824,6 +824,25 @@ std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& return g; } +std::vector Storage::getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const +{ + std::vector activeIds; + + for (Id id : tokenIds) + { + if (m_sqliteStorage.isNode(id)) + { + m_hierarchyCache.addFirstVisibleChildIdsForNodeId(id, &activeIds); + } + else + { + activeIds.push_back(id); + } + } + + return activeIds; +} + // TODO: rename: getActiveElementIdsForId; TODO: make separate function for declarationId std::vector Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) const { @@ -849,16 +868,26 @@ std::vector Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) c return activeTokenIds; } -Id Storage::getActiveNodeIdForLocationId(Id locationId) const +std::vector Storage::getNodeIdsForLocationIds(const std::vector& locationIds) const { - Id activeElementId = m_sqliteStorage.getElementIdByLocationId(locationId); + std::vector nodeIds; - StorageEdge edge = m_sqliteStorage.getEdgeById(activeElementId); - if (edge.id != 0) // here we test if location is an edge. + for (Id locationId : locationIds) { - activeElementId = edge.targetNodeId; + Id elementId = m_sqliteStorage.getElementIdByLocationId(locationId); + + StorageEdge edge = m_sqliteStorage.getEdgeById(elementId); + if (edge.id != 0) // here we test if location is an edge. + { + nodeIds.push_back(edge.targetNodeId); + } + else + { + nodeIds.push_back(elementId); + } } - return activeElementId; + + return nodeIds; } std::vector Storage::getTokenIdsForMatches(const std::vector& matches) const diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index b8cfee37..4b5a991b 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -132,8 +132,10 @@ public: virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const; + virtual std::vector getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const; virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const; - virtual Id getActiveNodeIdForLocationId(Id locationId) const; + + virtual std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const; virtual std::vector getTokenIdsForMatches(const std::vector& matches) const; virtual Id getTokenIdForFileNode(const FilePath& filePath) const; diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 75b6d2cc..782465a5 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -34,8 +34,10 @@ public: virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const = 0; + virtual std::vector getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const = 0; virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const = 0; - virtual Id getActiveNodeIdForLocationId(Id locationId) const = 0; + + virtual std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const = 0; virtual std::vector getTokenIdsForMatches(const std::vector& matches) const = 0; virtual Id getTokenIdForFileNode(const FilePath& filePath) const = 0; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index db02693a..6654d10f 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -103,6 +103,16 @@ std::shared_ptr StorageAccessProxy::getGraphForActiveTokenIds(const std:: return std::make_shared(); } +std::vector StorageAccessProxy::getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const +{ + if (hasSubject()) + { + return m_subject->getActiveTokenIdsForTokenIds(tokenIds); + } + + return std::vector(); +} + std::vector StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const { if (hasSubject()) @@ -113,14 +123,14 @@ std::vector StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delca return std::vector(); } -Id StorageAccessProxy::getActiveNodeIdForLocationId(Id locationId) const +std::vector StorageAccessProxy::getNodeIdsForLocationIds(const std::vector& locationIds) const { if (hasSubject()) { - return m_subject->getActiveNodeIdForLocationId(locationId); + return m_subject->getNodeIdsForLocationIds(locationIds); } - return 0; + return std::vector(); } std::vector StorageAccessProxy::getTokenIdsForMatches(const std::vector& matches) const diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 9c13adec..7c3e3aa0 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -25,8 +25,10 @@ public: virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const; + virtual std::vector getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const; virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const; - virtual Id getActiveNodeIdForLocationId(Id locationId) const; + + virtual std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const; virtual std::vector getTokenIdsForMatches(const std::vector& matches) const; virtual Id getTokenIdForFileNode(const FilePath& filePath) const; diff --git a/src/lib/utility/messaging/type/MessageActivateTokens.h b/src/lib/utility/messaging/type/MessageActivateTokens.h index d62ff8f1..04d7b641 100644 --- a/src/lib/utility/messaging/type/MessageActivateTokens.h +++ b/src/lib/utility/messaging/type/MessageActivateTokens.h @@ -16,14 +16,6 @@ public: { } - MessageActivateTokens(Id tokenId) - : tokenIds(1, tokenId) - , isEdge(false) - , isAggregation(false) - , isFromSystem(false) - { - } - static const std::string getStaticType() { return "MessageActivateTokens";