Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
forked from 附离/NodeSim
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
node-sim
/
src
/
node_node.cpp
node-sim
/
src
/
node_node.cpp
node_node.cpp 7.79 KB
Copy Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322

#include <spdlog/spdlog.h>
#include <iostream>
#include"node_node.h"
#include "node_scene.h"
#include "node_edge.h"
#include "node_graphics_node.h"
#include "FlowChartScene.h"
#include "node_content_widget.h"
inline static bool NODEDEBUG = false;
unsigned int Node::m_count = 10000;
/**
* @brief Node
* 1.在这个类中创建了QDMGraphicsNode对象
* 2.向FlowChart场景中加入了QDMGraphicsNode对象
* 3.此类中可获取所绑定的场景(Scene)
* 4.为啥不直接在QDMGraphicsNode中实现所有功能而是要使用Node这个类来添加暂未明晰。可能和代码的优化有一定关系?
* 5.感觉主要是为了明晰场景中有哪些图形项而实现的此级代码
* 6. 【todo】此构造函数中有必要强制指定必须为智能指针么?
*/
Node::Node(std::weak_ptr<Scene> scene, QString title)
:m_scene(scene),m_title(title)
{
m_id = ++m_count;
if (NODEDEBUG)
{
spdlog::info("Node {0} create sucess", m_title.toStdString());
}
}
Node::~Node()
{
m_grNode=nullptr;//这里不要调用删除,m_grnode被被FcScene管理,赋空即可
spdlog::info("Node {} delete sucess",m_title.toStdString());
}
void Node::initUi(QList<int> inputindexs, QList<int> outputindexs)
{
if (m_id > 19999)
{
spdlog::critical("Attention! node id is more than limit");
};
//创建一个QDMGraphicsNode对象 此处的m_grNode被FcScene管理
m_grNode = new QDMGraphicsNode(shared_from_this());
//向场景中添加此对象,会被scene管理,所以不用delete
m_scene.lock()->getFcScene()->addItem(m_grNode);
m_scene.lock()->addNode(shared_from_this());
//向Node中添加socket 且在此处定义了socket的方向
int counter = 0;
for (int i = 0; i < inputindexs.size(); ++i)
{
auto socket = std::make_shared<Socket>(shared_from_this(), counter, SOCKETPOS::LEFT_BOTTOM, SOCKETTYPE::SCOKETIN);
socket->initUi();
counter += 1;
m_inputs.append(socket);
// 在这里对每个元素进行操作
}
counter = 0;
for (int i = 0; i < outputindexs.size(); ++i)
{
auto socket = std::make_shared<Socket>(shared_from_this(), counter, SOCKETPOS::RIGHT_TOP, SOCKETTYPE::SCOKETOUT);
socket->initUi();
counter += 1;
m_outputs.append(socket);
// 在这里对每个元素进行操作
}
}
const QString Node::getTitle()
{
return m_title;
}
void Node::setPos(QPointF pos)
{
m_grNode->setPos(pos);
}
void Node::setPos(qreal x, qreal y)
{
m_grNode->setPos(x,y);
}
const QPointF Node::getPos()
{
return m_grNode->pos();
}
const QPointF Node::getSocketPos(int index, SOCKETPOS postion)
{
qreal x = 0.0;
if (postion == SOCKETPOS::LEFT_TOP || postion == SOCKETPOS::LEFT_BOTTOM)
{
x = 0.0;
}
else
{
x = getGrNode()->getWidth();
}
qreal y = 0;
if (postion == SOCKETPOS::LEFT_BOTTOM || postion == SOCKETPOS::RIGHT_BOTTOM)
{
//start from bottom
y = getGrNode()->getHeight() - getGrNode()->getEdgeSize() - index * m_socketSpacing;
}
else
{
y = getGrNode()->getTitleHeight() + getGrNode()->getPadding() + getGrNode()->getEdgeSize()
+ index * m_socketSpacing;
}
return QPointF(x, y);
}
QList<std::shared_ptr<Socket>> Node::getInputs()
{
return m_inputs;
}
QList<std::shared_ptr<Socket>> Node::getOutputs()
{
return m_outputs;
}
void Node::updateConnectedEdge()
{
for (int i = 0; i < m_inputs.count(); ++i)
{
if (!m_inputs[i]->getEdge().expired())
{
m_inputs[i]->getEdge().lock()->updatePosition();
}
}
for (int i = 0; i < m_outputs.count(); ++i)
{
if (!m_outputs[i]->getEdge().expired())
{
m_outputs[i]->getEdge().lock()->updatePosition();
}
}
}
void Node::remove()
{
m_grNode->hide();
//从gr场景中删除grNode,子类grSocket会一起删除
for (auto const& socket : m_inputs+ m_outputs)
{
if (socket->hasEdge())
{
socket->getEdge().lock()->remove();
}
}
m_scene.lock()->getFcScene()->removeItem(m_grNode);
m_scene.lock()->getFcScene()->update();
//在场景中删除Node
m_scene.lock()->removeNode(shared_from_this());
}
const rapidjson::Document Node::serialize()
{
// 创建一个空的Document对象
rapidjson::Document d; // 创建JSON对象
d.SetObject();
d.AddMember("id", m_id, d.GetAllocator());
//d.AddMember需要一个Value对象作为其值。const char* 不是RapidJSON的Value类型,因此你不能直接这样使用。
//创建一个Value对象,并将其设置为字符串。
const std::string& str = m_title.toStdString();
rapidjson::Value val(str.c_str(), d.GetAllocator());
d.AddMember("title", val, d.GetAllocator());
d.AddMember("pos_x", getPos().x(), d.GetAllocator());
d.AddMember("pos_y", getPos().y(), d.GetAllocator());
rapidjson::Value inputSocketsArray(rapidjson::kArrayType);//生成一个Array类型的元素,用来存放Object
for (const auto& socket : m_inputs)
{
rapidjson::Value nodeValue;
nodeValue.CopyFrom(socket->serialize(), d.GetAllocator());
inputSocketsArray.PushBack(nodeValue, d.GetAllocator());
}
d.AddMember("inputs", inputSocketsArray, d.GetAllocator());
rapidjson::Value outSocketsArray(rapidjson::kArrayType);//生成一个Array类型的元素,用来存放Object
for (const auto& socket : m_outputs)
{
rapidjson::Value nodeValue;
nodeValue.CopyFrom(socket->serialize(), d.GetAllocator());
outSocketsArray.PushBack(nodeValue, d.GetAllocator());
}
d.AddMember("outputs", outSocketsArray, d.GetAllocator());
//content serialize
//生成一个object
rapidjson::Value contentObj(rapidjson::kObjectType);//生成一个Array类型的元素,用来存放Object
contentObj.CopyFrom(m_grNode->getContentWidget()->serialize(),d.GetAllocator());
d.AddMember("Content", contentObj, d.GetAllocator());
return d;
}
void Node::deserialize(const rapidjson::Value& value)
{
//nothing
}
void Node::deserializePre(const rapidjson::Value& value)
{
//Node初始化完成前更新
if (value.HasMember("id"))
{
m_id = value["id"].GetUint();
}
if (value.HasMember("title"))
{
m_title = value["title"].GetString();
}
}
void Node::deserializePost(const rapidjson::Value& value)
{
//Node初始化完成后更新
qreal posx = 0.0, posy = 0.0;
if (value.HasMember("pos_x"))
{
posx = value["pos_x"].GetDouble();
}
if (value.HasMember("pos_y"))
{
posy = value["pos_y"].GetDouble();
}
setPos(posx, posy);
m_grNode->update();
if (value["inputs"].IsArray())
{
int size = value["inputs"].Size();
//socket属于调用它的node
for (int i = 0; i < size; i++)
{
int counter = 0;
unsigned int postion = 0;
unsigned int socketType = 0;
if (value["inputs"][i].HasMember("index"))
{
counter = value["inputs"][i]["index"].GetUint();
};
if (value["inputs"][i].HasMember("position"))
{
postion = value["inputs"][i]["position"].GetUint();
};
if (value["inputs"][i].HasMember("socket_Type"))
{
socketType = value["inputs"][i]["socket_Type"].GetUint();
};
auto socket = std::make_shared<Socket>(shared_from_this(), counter, SOCKETPOS(postion), SOCKETTYPE(socketType));
socket->initUi();
socket->deserialize(value["inputs"][i]);
m_inputs.append(socket);
// 在这里对每个元素进行操作
}
}
if (value["outputs"].IsArray())
{
int size = value["outputs"].Size();
//socket属于调用它的node
for (int i = 0; i < size; i++)
{
int counter = 0;
unsigned int postion = 0;
unsigned int socketType = 0;
if (value["outputs"][i].HasMember("index"))
{
counter = value["outputs"][i]["index"].GetUint();
};
if (value["outputs"][i].HasMember("position"))
{
postion = value["outputs"][i]["position"].GetUint();
};
if (value["outputs"][i].HasMember("socket_Type"))
{
socketType = value["outputs"][i]["socket_Type"].GetUint();
};
auto socket = std::make_shared<Socket>(shared_from_this(), counter, SOCKETPOS(postion), SOCKETTYPE(socketType));
socket->initUi();
socket->deserialize(value["outputs"][i]);
m_outputs.append(socket);
// 在这里对每个元素进行操作
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

C++重写nodeeditor的代码,目前写到了序列化反序列化。 暂时不太会有更新了。 代码水平一般,借鉴思路即可;
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/obslee/node-sim.git
git@gitee.com:obslee/node-sim.git
obslee
node-sim
NodeSim
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /