From 18f85d6e766f4439ae20f9276f887df8c039cfd6 Mon Sep 17 00:00:00 2001 From: parker Date: Sat, 5 Jul 2025 17:14:47 +0100 Subject: [PATCH] feat: signle displayFlag --- src/Engine/Network/NetworkManager.cpp | 9 ++++++++ src/Engine/Network/NetworkManager.h | 6 ++++++ src/gui/network/Network.cpp | 31 +++++++++++++++++++++++---- src/gui/network/Network.h | 10 +++++++++ src/gui/network/NodeGraphic.cpp | 12 +++++++++++ src/gui/network/NodeGraphic.h | 2 ++ 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/Engine/Network/NetworkManager.cpp b/src/Engine/Network/NetworkManager.cpp index 7ecca8c..bb1f1b8 100644 --- a/src/Engine/Network/NetworkManager.cpp +++ b/src/Engine/Network/NetworkManager.cpp @@ -38,6 +38,15 @@ bool enzo::nt::NetworkManager::isValidOp(nt::OpId opId) return true; } +void enzo::nt::NetworkManager::setDisplayOp(OpId opId) +{ + displayOp_=opId; +} + +std::optional enzo::nt::NetworkManager::getDisplayOp() +{ + return displayOp_; +} enzo::nt::NetworkManager* enzo::nt::NetworkManager::instancePtr_ = nullptr; diff --git a/src/Engine/Network/NetworkManager.h b/src/Engine/Network/NetworkManager.h index 4d95b8c..026b806 100644 --- a/src/Engine/Network/NetworkManager.h +++ b/src/Engine/Network/NetworkManager.h @@ -9,6 +9,8 @@ class NetworkManager { public: OpId addOperator(); + void setDisplayOp(OpId opId); + std::optional getDisplayOp(); // delete copy constructor NetworkManager(const NetworkManager& obj) = delete; @@ -22,7 +24,11 @@ private: NetworkManager() {}; std::unordered_map> gopStore_; + + // the highest operator id currently stored enzo::nt::OpId maxOpId_=0; + std::optional displayOp_=std::nullopt; + }; } diff --git a/src/gui/network/Network.cpp b/src/gui/network/Network.cpp index 7aec02a..d0a73dc 100644 --- a/src/gui/network/Network.cpp +++ b/src/gui/network/Network.cpp @@ -35,6 +35,7 @@ Network::Network(QWidget* parent) scene_ = new NetworkGraphicsScene(); view_ = new NetworkGraphicsView(this, this, scene_); + nm_ = enzo::nt::NetworkManager::getInstance(); mainLayout_->addWidget(view_); @@ -106,6 +107,14 @@ void Network::leftMousePressed(QMouseEvent *event) // display flag else if(QGraphicsItem* clickedDisplayFlag = itemOfType(clickedItems)) { + NodeGraphic* clickedNode = static_cast(itemOfType(clickedItems)); + enzo::nt::OpId opId = clickedNode->getOpId(); + if(auto prevDisplayOpId = nm_->getDisplayOp(); prevDisplayOpId) + { + NodeGraphic* prevDisplayNode = nodeStore_.at(*prevDisplayOpId); + prevDisplayNode->setDisplayFlag(false); + } + nm_->setDisplayOp(opId); static_cast(clickedDisplayFlag)->setEnabled(true); } else if(QGraphicsItem* clickedNode = itemOfType(clickedItems)) @@ -276,12 +285,9 @@ void Network::keyPressEvent(QKeyEvent *event) } case(Qt::Key_Tab): { - nt::NetworkManager* nm = nt::NetworkManager::getInstance(); - if(nt::OpId id = nm->addOperator()) + if(auto newNode = createNode()) { - NodeGraphic* newNode = new NodeGraphic(id); newNode->setPos(viewPos); - scene_->addItem(newNode); } break; @@ -289,6 +295,23 @@ void Network::keyPressEvent(QKeyEvent *event) } } +NodeGraphic* Network::createNode() +{ + if(nt::OpId id = nm_->addOperator()) + { + NodeGraphic* newNode = new NodeGraphic(id); + scene_->addItem(newNode); + nodeStore_.emplace(id, newNode); + + return newNode; + } + else + { + return nullptr; + } +} + + void Network::highlightEdge(QGraphicsItem* edge, bool state) { if(!edge || !isType(edge)) return; diff --git a/src/gui/network/Network.h b/src/gui/network/Network.h index 881f5ba..50b6a0d 100644 --- a/src/gui/network/Network.h +++ b/src/gui/network/Network.h @@ -3,13 +3,17 @@ #include #include #include +#include "Engine/Network/NetworkManager.h" +#include "Engine/Types.h" #include "gui/network/NetworkGraphicsView.h" #include "gui/network/NodeEdgeGraphic.h" #include "gui/network/NetworkGraphicsScene.h" +#include "gui/network/NodeGraphic.h" #include "gui/network/SocketGraphic.h" #include "gui/network/FloatingEdgeGraphic.h" #include #include +#include class Network : public QWidget @@ -31,6 +35,10 @@ private: NetworkGraphicsScene* scene_; NetworkGraphicsView* view_; + enzo::nt::NetworkManager* nm_; + + std::unordered_map nodeStore_; + FloatingEdgeGraphic* floatingEdge_=nullptr; SocketGraphic* startSocket_=nullptr; @@ -46,6 +54,8 @@ private: void destroyFloatingEdge(); void deleteEdge(QGraphicsItem* edge); + NodeGraphic* createNode(); + void highlightEdge(QGraphicsItem* edge, bool state); void leftMousePressed(QMouseEvent* event); diff --git a/src/gui/network/NodeGraphic.cpp b/src/gui/network/NodeGraphic.cpp index 0e91fb6..411ab5c 100644 --- a/src/gui/network/NodeGraphic.cpp +++ b/src/gui/network/NodeGraphic.cpp @@ -7,6 +7,7 @@ #include #include "Engine/Network/NetworkManager.h" #include "Engine/Operator/GeometryOperator.h" +#include "Engine/Types.h" #include "gui/network/DisplayFlagButton.h" #include "gui/network/SocketGraphic.h" #include @@ -220,6 +221,17 @@ QPointF NodeGraphic::getSocketScenePosition(int socketIndex, enzo::nt::SocketIOT return this->pos()+getSocketPosition(socketIndex, socketType); } +enzo::nt::OpId NodeGraphic::getOpId() const +{ + return opId_; +} + +void NodeGraphic::setDisplayFlag(bool state) +{ + displayFlagButton_->setEnabled(state); +} + + QRectF NodeGraphic::getBodyRect() { return bodyRect_; diff --git a/src/gui/network/NodeGraphic.h b/src/gui/network/NodeGraphic.h index f46d4b7..42c9384 100644 --- a/src/gui/network/NodeGraphic.h +++ b/src/gui/network/NodeGraphic.h @@ -17,9 +17,11 @@ public: SocketGraphic* getInput(int indx) const; SocketGraphic* getOutput(int indx) const; + enzo::nt::OpId getOpId() const; QPointF getSocketPosition(int socketIndex, enzo::nt::SocketIOType socketType); QPointF getSocketScenePosition(int socketIndex, enzo::nt::SocketIOType socketType); QRectF getBodyRect(); + void setDisplayFlag(bool state); // void addEdge(NodeEdgeGraphic* edge);