feat(NetworkManager): change member functions to static
This commit is contained in:
@@ -56,6 +56,16 @@ target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets
|
||||
target_include_directories(${AppExec} PUBLIC src)
|
||||
|
||||
# tests
|
||||
Include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.8.1 # or a later release
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_executable(${TestExec}
|
||||
tests/main-tests.cpp
|
||||
tests/OperatorTests.cpp
|
||||
@@ -68,6 +78,5 @@ add_executable(${TestExec}
|
||||
src/Engine/Operator/GeometryConnection.cpp
|
||||
src/Engine/Operator/GeometryOpDef.cpp
|
||||
)
|
||||
find_package(Catch2 3 REQUIRED)
|
||||
target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core )
|
||||
target_include_directories(${TestExec} PUBLIC src)
|
||||
|
||||
@@ -54,34 +54,8 @@ void enzo::nt::NetworkManager::setDisplayOp(OpId opId)
|
||||
displayOp_=opId;
|
||||
std::vector<enzo::nt::OpId> dependencyGraph = getDependencyGraph(opId);
|
||||
enzo::geo::Geometry prevGeometry;
|
||||
|
||||
// ----
|
||||
// create geometry start
|
||||
// ----
|
||||
// std::shared_ptr<ga::Attribute> PAttr = prevGeometry.getAttribByName(ga::AttrOwner::POINT, "P");
|
||||
// ga::AttributeHandleVector3 PAttrHandle(PAttr);
|
||||
// std::vector<bt::Vector3> pts={
|
||||
// {-1,-1,-1},{1,-1,-1},{1,-1,1},{-1,-1,1},
|
||||
// {-1,1,-1},{1,1,-1},{1,1,1},{-1,1,1},
|
||||
// {0,2,-1},{0,2,1}
|
||||
// };
|
||||
// for(auto& p:pts) PAttrHandle.addValue(p);
|
||||
|
||||
// std::shared_ptr<ga::Attribute> pointAttr = prevGeometry.getAttribByName(ga::AttrOwner::VERTEX, "point");
|
||||
// ga::AttributeHandleInt pointAttrHandle(pointAttr);
|
||||
// std::vector<std::vector<int>> faces={
|
||||
// {3,2,6,9,7},{0,1,5,8,4},{0,3,7,4},{1,2,6,5},
|
||||
// {0,1,2,3},{4,7,9},{4,9,8},{5,6,9},{5,9,8}
|
||||
// };
|
||||
// for(auto& f:faces) for(int i:f) pointAttrHandle.addValue(i);
|
||||
|
||||
// std::shared_ptr<ga::Attribute> vertexCountAttr = prevGeometry.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
|
||||
// ga::AttributeHandleInt vertexCountHandle(vertexCountAttr);
|
||||
// for(auto& f:faces) vertexCountHandle.addValue(f.size());
|
||||
|
||||
// --------
|
||||
|
||||
std::cout << "size: " << dependencyGraph.size() << "\n";
|
||||
|
||||
for(enzo::nt::OpId dependencyOpId : dependencyGraph)
|
||||
{
|
||||
cookOp(dependencyOpId);
|
||||
@@ -127,4 +101,5 @@ std::optional<enzo::nt::OpId> enzo::nt::NetworkManager::getDisplayOp()
|
||||
}
|
||||
|
||||
enzo::nt::NetworkManager* enzo::nt::NetworkManager::instancePtr_ = nullptr;
|
||||
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> enzo::nt::NetworkManager::gopStore_;
|
||||
|
||||
|
||||
@@ -12,30 +12,30 @@ class NetworkManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OpId addOperator();
|
||||
void setDisplayOp(OpId opId);
|
||||
std::optional<OpId> getDisplayOp();
|
||||
// delete copy constructor
|
||||
NetworkManager(const NetworkManager& obj) = delete;
|
||||
|
||||
static NetworkManager* getInstance();
|
||||
|
||||
bool isValidOp(nt::OpId opId);
|
||||
GeometryOperator& getGeoOperator(nt::OpId opId);
|
||||
static OpId addOperator();
|
||||
void setDisplayOp(OpId opId);
|
||||
static std::optional<OpId> getDisplayOp();
|
||||
static bool isValidOp(nt::OpId opId);
|
||||
static GeometryOperator& getGeoOperator(nt::OpId opId);
|
||||
|
||||
private:
|
||||
static NetworkManager* instancePtr_;
|
||||
NetworkManager() {};
|
||||
|
||||
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
||||
static std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
||||
|
||||
void cookOp(enzo::nt::OpId opId);
|
||||
std::vector<enzo::nt::OpId> getDependencyGraph(enzo::nt::OpId opId);
|
||||
static void cookOp(enzo::nt::OpId opId);
|
||||
static std::vector<enzo::nt::OpId> getDependencyGraph(enzo::nt::OpId opId);
|
||||
|
||||
// the highest operator id currently stored
|
||||
enzo::nt::OpId maxOpId_=0;
|
||||
inline static enzo::nt::OpId maxOpId_=0;
|
||||
|
||||
std::optional<OpId> displayOp_=std::nullopt;
|
||||
inline static std::optional<OpId> displayOp_=std::nullopt;
|
||||
signals:
|
||||
void updateDisplay(enzo::geo::Geometry& geometry);
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ const enzo::geo::Geometry& enzo::nt::GeometryOpDef::getInputGeoView(unsigned int
|
||||
enzo::geo::Geometry enzo::nt::GeometryOpDef::cloneInputGeo(unsigned int inputIndex)
|
||||
{
|
||||
// TODO: implement
|
||||
enzo::nt::NetworkManager* nm = nt::NetworkManager::getInstance();
|
||||
enzo::nt::GeometryOperator& selfOp = nm->getGeoOperator(opId_);
|
||||
enzo::nt::GeometryOperator& selfOp = nt::NetworkManager::getGeoOperator(opId_);
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> inputConnections = selfOp.getInputConnections();
|
||||
if(inputConnections.size()==0)
|
||||
{
|
||||
@@ -31,7 +30,7 @@ enzo::geo::Geometry enzo::nt::GeometryOpDef::cloneInputGeo(unsigned int inputInd
|
||||
return enzo::geo::Geometry();
|
||||
}
|
||||
std::shared_ptr<const nt::GeometryConnection> inputConnection = inputConnections.at(inputIndex);
|
||||
return nm->getGeoOperator(inputConnection->getInputOpId()).getOutputGeo(inputConnection->getInputIndex());
|
||||
return nt::NetworkManager::getGeoOperator(inputConnection->getInputOpId()).getOutputGeo(inputConnection->getInputIndex());
|
||||
}
|
||||
|
||||
void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry)
|
||||
|
||||
@@ -8,11 +8,8 @@ using namespace enzo;
|
||||
|
||||
void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex)
|
||||
{
|
||||
// get network manager
|
||||
auto nm = enzo::nt::NetworkManager::getInstance();
|
||||
|
||||
auto& inputOp = nm->getGeoOperator(inputOpId);
|
||||
auto& outputOp = nm->getGeoOperator(outputOpId);
|
||||
auto& inputOp = nt::NetworkManager::getGeoOperator(inputOpId);
|
||||
auto& outputOp = nt::NetworkManager::getGeoOperator(outputOpId);
|
||||
|
||||
auto newConnection = std::make_shared<nt::GeometryConnection>(inputOpId, inputIndex, outputOpId, outputIndex);
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ Network::Network(QWidget* parent)
|
||||
|
||||
scene_ = new NetworkGraphicsScene();
|
||||
view_ = new NetworkGraphicsView(this, this, scene_);
|
||||
nm_ = enzo::nt::NetworkManager::getInstance();
|
||||
|
||||
|
||||
mainLayout_->addWidget(view_);
|
||||
@@ -299,7 +298,7 @@ void Network::keyPressEvent(QKeyEvent *event)
|
||||
|
||||
NodeGraphic* Network::createNode()
|
||||
{
|
||||
if(nt::OpId id = nm_->addOperator())
|
||||
if(nt::OpId id = nt::NetworkManager::addOperator())
|
||||
{
|
||||
NodeGraphic* newNode = new NodeGraphic(id);
|
||||
scene_->addItem(newNode);
|
||||
@@ -365,14 +364,15 @@ void Network::mouseReleaseEvent(QMouseEvent *event)
|
||||
QLineF(event->pos(), leftMouseStart).length()<5.0f
|
||||
)
|
||||
{
|
||||
enzo::nt::NetworkManager* nm = enzo::nt::NetworkManager::getInstance();
|
||||
NodeGraphic* clickedNode = static_cast<NodeGraphic*>(itemOfType<NodeGraphic>(hoverItems));
|
||||
enzo::nt::OpId opId = clickedNode->getOpId();
|
||||
if(auto prevDisplayOpId = nm_->getDisplayOp(); prevDisplayOpId)
|
||||
if(auto prevDisplayOpId = nt::NetworkManager::getDisplayOp(); prevDisplayOpId)
|
||||
{
|
||||
NodeGraphic* prevDisplayNode = nodeStore_.at(*prevDisplayOpId);
|
||||
prevDisplayNode->setDisplayFlag(false);
|
||||
}
|
||||
nm_->setDisplayOp(opId);
|
||||
nm->setDisplayOp(opId);
|
||||
static_cast<DisplayFlagButton*>(clickedDisplayFlag)->setEnabled(true);
|
||||
}
|
||||
if(state_==State::MOVING_NODE)
|
||||
|
||||
@@ -37,8 +37,6 @@ private:
|
||||
NetworkGraphicsScene* scene_;
|
||||
NetworkGraphicsView* view_;
|
||||
|
||||
enzo::nt::NetworkManager* nm_;
|
||||
|
||||
std::unordered_map<enzo::nt::OpId, NodeGraphic*> nodeStore_;
|
||||
|
||||
FloatingEdgeGraphic* floatingEdge_=nullptr;
|
||||
|
||||
@@ -79,8 +79,7 @@ void NodeGraphic::initFlagButtons()
|
||||
|
||||
void NodeGraphic::initSockets()
|
||||
{
|
||||
auto nm = enzo::nt::NetworkManager::getInstance();
|
||||
enzo::nt::GeometryOperator& op = nm->getGeoOperator(opId_);
|
||||
enzo::nt::GeometryOperator& op = enzo::nt::NetworkManager::getGeoOperator(opId_);
|
||||
for(int i=0, max=op.getMaxInputs(); i<max; ++i)
|
||||
{
|
||||
auto* socketInput = new SocketGraphic(enzo::nt::SocketIOType::Input, opId_, i, this);
|
||||
@@ -203,8 +202,7 @@ void NodeGraphic::updatePositions()
|
||||
|
||||
QPointF NodeGraphic::getSocketPosition(int socketIndex, enzo::nt::SocketIOType socketType)
|
||||
{
|
||||
auto nm = enzo::nt::NetworkManager::getInstance();
|
||||
enzo::nt::GeometryOperator& op = nm->getGeoOperator(opId_);
|
||||
enzo::nt::GeometryOperator& op = enzo::nt::NetworkManager::getGeoOperator(opId_);
|
||||
int maxSocketNumber = socketType==enzo::nt::SocketIOType::Input ? op.getMaxInputs() : op.getMaxOutputs();
|
||||
float socketSpread = socketSize_*1.5*maxSocketNumber;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user