feat: network manager singleton, connect network manager to network ui
This commit is contained in:
@@ -46,6 +46,8 @@ qt_add_executable(${AppExec}
|
|||||||
|
|
||||||
src/Engine/Operator/Attribute.cpp
|
src/Engine/Operator/Attribute.cpp
|
||||||
src/Engine/Operator/Geometry.cpp
|
src/Engine/Operator/Geometry.cpp
|
||||||
|
src/Engine/Operator/GeometryOperator.cpp
|
||||||
|
src/Engine/Network/NetworkManager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen)
|
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen)
|
||||||
|
|||||||
@@ -1,14 +1,27 @@
|
|||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
#include "Engine/Operator/GeometryOperator.h"
|
#include "Engine/Operator/GeometryOperator.h"
|
||||||
|
#include "Engine/Types.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
bool enzo::nt::NetworkManager::addOperator()
|
enzo::nt::OpId enzo::nt::NetworkManager::addOperator()
|
||||||
{
|
{
|
||||||
|
|
||||||
gopStore_.emplace(++maxOpId_, std::make_unique<GeometryOperator>());
|
gopStore_.emplace(++maxOpId_, std::make_unique<GeometryOperator>());
|
||||||
std::cout << "adding operator\n";
|
std::cout << "adding operator " << maxOpId_ << "\n";
|
||||||
|
|
||||||
return true;
|
return maxOpId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enzo::nt::NetworkManager* enzo::nt::NetworkManager::getInstance()
|
||||||
|
{
|
||||||
|
if(instancePtr_==nullptr)
|
||||||
|
{
|
||||||
|
instancePtr_ = new enzo::nt::NetworkManager();
|
||||||
|
}
|
||||||
|
return instancePtr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
enzo::nt::NetworkManager* enzo::nt::NetworkManager::instancePtr_ = nullptr;
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,16 @@ namespace enzo::nt {
|
|||||||
class NetworkManager
|
class NetworkManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool addOperator();
|
OpId addOperator();
|
||||||
|
// delete copy constructor
|
||||||
|
NetworkManager(const NetworkManager& obj) = delete;
|
||||||
|
|
||||||
|
static NetworkManager* getInstance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static NetworkManager* instancePtr_;
|
||||||
|
NetworkManager() {};
|
||||||
|
|
||||||
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
||||||
enzo::nt::OpId maxOpId_=0;
|
enzo::nt::OpId maxOpId_=0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "gui/network/Network.h"
|
#include "gui/network/Network.h"
|
||||||
|
#include "Engine/Types.h"
|
||||||
#include "gui/network/DisplayFlagButton.h"
|
#include "gui/network/DisplayFlagButton.h"
|
||||||
#include "gui/network/NodeEdgeGraphic.h"
|
#include "gui/network/NodeEdgeGraphic.h"
|
||||||
#include "gui/network/NetworkGraphicsView.h"
|
#include "gui/network/NetworkGraphicsView.h"
|
||||||
@@ -6,6 +7,7 @@
|
|||||||
#include "gui/network/NodeGraphic.h"
|
#include "gui/network/NodeGraphic.h"
|
||||||
#include "gui/network/FloatingEdgeGraphic.h"
|
#include "gui/network/FloatingEdgeGraphic.h"
|
||||||
#include "gui/network/SocketGraphic.h"
|
#include "gui/network/SocketGraphic.h"
|
||||||
|
#include "Engine/Network/NetworkManager.h"
|
||||||
#include <qboxlayout.h>
|
#include <qboxlayout.h>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
@@ -13,6 +15,8 @@
|
|||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
|
|
||||||
|
using namespace enzo;
|
||||||
|
|
||||||
Network::Network(QWidget* parent)
|
Network::Network(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
@@ -29,42 +33,6 @@ Network::Network(QWidget* parent)
|
|||||||
scene_ = new NetworkGraphicsScene();
|
scene_ = new NetworkGraphicsScene();
|
||||||
view_ = new NetworkGraphicsView(this, this, scene_);
|
view_ = new NetworkGraphicsView(this, this, scene_);
|
||||||
|
|
||||||
// QPen greenPen = QPen(Qt::green);
|
|
||||||
// greenPen.setWidth(6);
|
|
||||||
|
|
||||||
// auto* rect1 = scene_->addRect(50, 50, 100, 100, greenPen);
|
|
||||||
// rect1->setFlag(QGraphicsItem::ItemIsMovable);
|
|
||||||
|
|
||||||
// auto* rect2 = scene_->addRect(80, 120, 100, 100, greenPen);
|
|
||||||
// rect2->setFlag(QGraphicsItem::ItemIsMovable);
|
|
||||||
|
|
||||||
// auto* rect3 = scene_->addRect(80, -120, 100, 100, greenPen);
|
|
||||||
// rect3->setFlag(QGraphicsItem::ItemIsMovable);
|
|
||||||
|
|
||||||
NodeGraphic* node1 = new NodeGraphic();
|
|
||||||
node1->setPos(-50, -50);
|
|
||||||
scene_->addItem(node1);
|
|
||||||
|
|
||||||
NodeGraphic* node2 = new NodeGraphic();
|
|
||||||
node2->setPos(50, 50);
|
|
||||||
scene_->addItem(node2);
|
|
||||||
|
|
||||||
NodeGraphic* node3 = new NodeGraphic();
|
|
||||||
node3->setPos(50, 200);
|
|
||||||
scene_->addItem(node3);
|
|
||||||
|
|
||||||
NodeGraphic* node4 = new NodeGraphic();
|
|
||||||
node4->setPos(50, -200);
|
|
||||||
scene_->addItem(node4);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// scene_->addItem(new NodeEdgeGraphic(node1->getOutput(0), node2->getInput(0)));
|
|
||||||
|
|
||||||
// node1->addEdge(edge1);
|
|
||||||
// node2->addEdge(edge1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mainLayout_->addWidget(view_);
|
mainLayout_->addWidget(view_);
|
||||||
|
|
||||||
@@ -247,25 +215,41 @@ void Network::keyPressEvent(QKeyEvent *event)
|
|||||||
// get pos
|
// get pos
|
||||||
QPoint globalPos = QCursor::pos();
|
QPoint globalPos = QCursor::pos();
|
||||||
QPoint widgetPos = mapFromGlobal(globalPos);
|
QPoint widgetPos = mapFromGlobal(globalPos);
|
||||||
|
QPointF viewPos = view_->mapToScene(widgetPos);
|
||||||
|
|
||||||
|
|
||||||
QList<QGraphicsItem*> hoverItems = view_->items(widgetPos);
|
QList<QGraphicsItem*> hoverItems = view_->items(widgetPos);
|
||||||
|
|
||||||
// edge detection
|
// edge detection
|
||||||
if(
|
switch(event->key())
|
||||||
event->key() == Qt::Key_Control
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
QGraphicsItem* hoverItem = itemOfType<NodeEdgeGraphic>(hoverItems);
|
|
||||||
if(hoverItem!=nullptr)
|
case( Qt::Key_Control):
|
||||||
{
|
{
|
||||||
highlightEdge(hoverItem, true);
|
QGraphicsItem* hoverItem = itemOfType<NodeEdgeGraphic>(hoverItems);
|
||||||
|
if(hoverItem!=nullptr)
|
||||||
|
{
|
||||||
|
highlightEdge(hoverItem, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case(Qt::Key_Escape):
|
||||||
|
{
|
||||||
|
destroyFloatingEdge();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(Qt::Key_Tab):
|
||||||
|
{
|
||||||
|
nt::NetworkManager* nm = nt::NetworkManager::getInstance();
|
||||||
|
if(nt::OpId id = nm->addOperator())
|
||||||
|
{
|
||||||
|
NodeGraphic* newNode = new NodeGraphic(id);
|
||||||
|
newNode->setPos(viewPos);
|
||||||
|
scene_->addItem(newNode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
if(event->key() == Qt::Key_Escape)
|
|
||||||
{
|
|
||||||
destroyFloatingEdge();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
#include <QGraphicsSvgItem>
|
#include <QGraphicsSvgItem>
|
||||||
#include "gui/network/NodeIconGraphic.h"
|
#include "gui/network/NodeIconGraphic.h"
|
||||||
|
|
||||||
NodeGraphic::NodeGraphic(QGraphicsItem *parent)
|
NodeGraphic::NodeGraphic(enzo::nt::OpId id, QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent)
|
: QGraphicsItem(parent), opId_{id}
|
||||||
{
|
{
|
||||||
socketSize_ = 3;
|
socketSize_ = 3;
|
||||||
titlePadding_=1;
|
titlePadding_=1;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include "Engine/Types.h"
|
||||||
#include "gui/network/DisplayFlagButton.h"
|
#include "gui/network/DisplayFlagButton.h"
|
||||||
#include "gui/network/SocketGraphic.h"
|
#include "gui/network/SocketGraphic.h"
|
||||||
#include "gui/network/NodeIconGraphic.h"
|
#include "gui/network/NodeIconGraphic.h"
|
||||||
@@ -11,7 +12,7 @@ class NodeGraphic
|
|||||||
: public QGraphicsItem
|
: public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NodeGraphic(QGraphicsItem *parent = nullptr);
|
NodeGraphic(enzo::nt::OpId id, QGraphicsItem *parent = nullptr);
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
|
|
||||||
SocketGraphic* getInput(int indx) const;
|
SocketGraphic* getInput(int indx) const;
|
||||||
@@ -36,6 +37,7 @@ private:
|
|||||||
void initIcon();
|
void initIcon();
|
||||||
void initFonts();
|
void initFonts();
|
||||||
|
|
||||||
|
enzo::nt::OpId opId_;
|
||||||
std::vector<SocketGraphic*> inputs_;
|
std::vector<SocketGraphic*> inputs_;
|
||||||
std::vector<SocketGraphic*> outputs_;
|
std::vector<SocketGraphic*> outputs_;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
TEST_CASE("network")
|
TEST_CASE("network")
|
||||||
{
|
{
|
||||||
enzo::nt::NetworkManager networkManager;
|
using namespace enzo;
|
||||||
networkManager.addOperator();
|
nt::NetworkManager* nm = nt::NetworkManager::getInstance();
|
||||||
|
nm->addOperator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user