feat: signle displayFlag
This commit is contained in:
@@ -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::OpId> enzo::nt::NetworkManager::getDisplayOp()
|
||||
{
|
||||
return displayOp_;
|
||||
}
|
||||
|
||||
enzo::nt::NetworkManager* enzo::nt::NetworkManager::instancePtr_ = nullptr;
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ class NetworkManager
|
||||
{
|
||||
public:
|
||||
OpId addOperator();
|
||||
void setDisplayOp(OpId opId);
|
||||
std::optional<OpId> getDisplayOp();
|
||||
// delete copy constructor
|
||||
NetworkManager(const NetworkManager& obj) = delete;
|
||||
|
||||
@@ -22,7 +24,11 @@ private:
|
||||
NetworkManager() {};
|
||||
|
||||
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
||||
|
||||
// the highest operator id currently stored
|
||||
enzo::nt::OpId maxOpId_=0;
|
||||
|
||||
std::optional<OpId> displayOp_=std::nullopt;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<DisplayFlagButton>(clickedItems))
|
||||
{
|
||||
NodeGraphic* clickedNode = static_cast<NodeGraphic*>(itemOfType<NodeGraphic>(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<DisplayFlagButton*>(clickedDisplayFlag)->setEnabled(true);
|
||||
}
|
||||
else if(QGraphicsItem* clickedNode = itemOfType<NodeGraphic>(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<NodeEdgeGraphic>(edge)) return;
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
#include <memory>
|
||||
#include <qgraphicsitem.h>
|
||||
#include <typeinfo>
|
||||
#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 <iostream>
|
||||
#include <QPointer>
|
||||
#include <unordered_map>
|
||||
|
||||
class Network
|
||||
: public QWidget
|
||||
@@ -31,6 +35,10 @@ private:
|
||||
NetworkGraphicsScene* scene_;
|
||||
NetworkGraphicsView* view_;
|
||||
|
||||
enzo::nt::NetworkManager* nm_;
|
||||
|
||||
std::unordered_map<enzo::nt::OpId, NodeGraphic*> 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);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#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 <QGraphicsScene>
|
||||
@@ -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_;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user