2025-06-11 15:09:20 +00:00
|
|
|
|
#include "DeduceFramework.h"
|
2025-06-08 04:12:15 +00:00
|
|
|
|
#include <stdexcept>
|
2025-06-10 18:05:00 +00:00
|
|
|
|
#include <QMutex>
|
|
|
|
|
#include <QMutexLocker>
|
2025-06-08 04:12:15 +00:00
|
|
|
|
|
2025-06-10 18:05:00 +00:00
|
|
|
|
QMutex DeduceFramework::_static_mutex;
|
2025-06-08 12:17:02 +00:00
|
|
|
|
QList<std::shared_ptr<WsMessage>> deduct_each(std::shared_ptr<WsEntity> item)
|
2025-06-08 04:12:15 +00:00
|
|
|
|
{
|
2025-06-10 18:05:00 +00:00
|
|
|
|
QMutexLocker loc(&DeduceFramework::_static_mutex);
|
|
|
|
|
|
2025-06-08 04:12:15 +00:00
|
|
|
|
QList<std::shared_ptr<WsMessage>> rets;
|
2025-06-10 04:41:33 +00:00
|
|
|
|
auto immediate = std::make_shared<ImmediateKernel>(item);
|
2025-06-08 04:12:15 +00:00
|
|
|
|
|
|
|
|
|
for (auto msg : DeduceFramework::_accept_stack) {
|
|
|
|
|
if (msg->targetEntity() == item->entityID()) {
|
|
|
|
|
auto enters = item->getEntryWithInType(msg->topicString());
|
|
|
|
|
for (auto e : enters)
|
|
|
|
|
e(immediate, msg, rets);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<std::shared_ptr<WsMessage>> DeduceFramework::_accept_stack;
|
|
|
|
|
void DeduceFramework::accept(const QList<std::shared_ptr<WsMessage>>& set)
|
|
|
|
|
{
|
2025-06-10 18:05:00 +00:00
|
|
|
|
QMutexLocker loc(&DeduceFramework::_static_mutex);
|
2025-06-08 04:12:15 +00:00
|
|
|
|
_accept_stack.append(set);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QtConcurrent>
|
|
|
|
|
void DeduceFramework::deduceBegin(std::shared_ptr<const DeduceRequest> ins)
|
|
|
|
|
{
|
|
|
|
|
auto dt = QTime::currentTime();
|
|
|
|
|
|
2025-06-10 18:05:00 +00:00
|
|
|
|
DeduceFramework::_static_mutex.lock();
|
|
|
|
|
auto items = _entity_map_over_0xffff.values();
|
|
|
|
|
for(auto item : _templets_within_0x2ff_0xffff.values())
|
|
|
|
|
items.append(item);
|
|
|
|
|
DeduceFramework::_static_mutex.unlock();
|
|
|
|
|
|
|
|
|
|
auto ret_list_set = QtConcurrent::blockingMapped(items, deduct_each);
|
2025-06-08 04:12:15 +00:00
|
|
|
|
|
|
|
|
|
_accept_stack.clear();
|
|
|
|
|
for (auto vlist : ret_list_set)
|
|
|
|
|
emit this->reply(vlist);
|
|
|
|
|
|
|
|
|
|
auto fmsg = std::make_shared<RespondDefault>();
|
|
|
|
|
fmsg->reset(ins->targetEntity(), ins->sourceEntity());
|
|
|
|
|
fmsg->_time_consume = dt.msecsTo(QTime::currentTime());
|
|
|
|
|
emit this->complete(fmsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <simsbasic.h>
|
2025-06-10 13:00:30 +00:00
|
|
|
|
#include "InvisibleComponent.h"
|
2025-06-08 12:17:02 +00:00
|
|
|
|
DeduceFramework::DeduceFramework()
|
|
|
|
|
:_factory_ins(std::make_shared<ComponentFactory>()) {
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-14 06:29:43 +00:00
|
|
|
|
#include "RouteManage.h"
|
2025-06-10 13:01:20 +00:00
|
|
|
|
void DeduceFramework::init_framework()
|
2025-06-08 12:17:02 +00:00
|
|
|
|
{
|
2025-06-10 04:41:33 +00:00
|
|
|
|
auto mgr_e = std::make_shared<RtEntityManager>();
|
2025-06-08 04:12:15 +00:00
|
|
|
|
mgr_e->append(this->shared_from_this());
|
2025-06-10 15:44:38 +00:00
|
|
|
|
auto info_pulls = std::make_shared<ComponentsInfoPull>();
|
|
|
|
|
mgr_e->append(info_pulls);
|
2025-06-08 12:17:02 +00:00
|
|
|
|
this->_entity_map_over_0xffff[mgr_e->entityID()] = mgr_e;
|
2025-06-12 00:04:17 +00:00
|
|
|
|
|
|
|
|
|
auto res_e = std::make_shared<RtResourceManager>();
|
|
|
|
|
info_pulls = std::make_shared<ComponentsInfoPull>();
|
|
|
|
|
res_e->append(info_pulls);
|
2025-06-22 02:05:31 +00:00
|
|
|
|
auto route_mgr = std::make_shared<PlainRouteManagePlugin>();
|
2025-06-14 06:29:43 +00:00
|
|
|
|
res_e->append(route_mgr);
|
2025-06-12 00:04:17 +00:00
|
|
|
|
this->_entity_map_over_0xffff[res_e->entityID()] = res_e;
|
2025-06-08 04:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<WsComponent> DeduceFramework::defaultNew() const
|
|
|
|
|
{
|
|
|
|
|
throw std::logic_error("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 12:17:02 +00:00
|
|
|
|
void DeduceFramework::bindEntity(std::weak_ptr<WsEntity> ins)
|
2025-06-08 04:12:15 +00:00
|
|
|
|
{
|
2025-06-08 12:17:02 +00:00
|
|
|
|
this->_bind_entity = ins;
|
2025-06-08 04:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DeduceFramework::name() const
|
|
|
|
|
{
|
|
|
|
|
return NAME(DeduceFramework);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DeduceFramework::recoveryFrom(const QJsonObject& obj)
|
|
|
|
|
{
|
|
|
|
|
throw std::logic_error("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DeduceFramework::saveTo(QJsonObject& obj) const
|
|
|
|
|
{
|
|
|
|
|
throw std::logic_error("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 04:41:33 +00:00
|
|
|
|
void DeduceFramework::execute(std::shared_ptr<Immediate> map,
|
2025-06-08 12:17:02 +00:00
|
|
|
|
std::shared_ptr<const EntityOperate> in, QList<std::shared_ptr<RespondDefault>>& out)
|
2025-06-08 04:12:15 +00:00
|
|
|
|
{
|
2025-06-08 12:17:02 +00:00
|
|
|
|
auto dt = QTime::currentTime();
|
|
|
|
|
|
|
|
|
|
auto result = std::make_shared<RespondDefault>();
|
|
|
|
|
result->reset(in->targetEntity(), in->sourceEntity());
|
|
|
|
|
|
|
|
|
|
switch ((EntityOperateType)in->_operate_code)
|
|
|
|
|
{
|
|
|
|
|
case EntityOperateType::NEW: {
|
|
|
|
|
if (!this->_templets_within_0x2ff_0xffff.contains(in->_template_name)) {
|
|
|
|
|
result->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Template<EFBFBD><EFBFBD>%1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(in->_template_name);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result->_success_mark = true;
|
|
|
|
|
|
|
|
|
|
auto ins_t = this->_templets_within_0x2ff_0xffff[in->_template_name];
|
2025-06-10 04:41:33 +00:00
|
|
|
|
auto new_copy = std::static_pointer_cast<RtWsEntity>(ins_t->defaultNew());
|
2025-06-08 12:17:02 +00:00
|
|
|
|
new_copy->resetID(0xffff);
|
|
|
|
|
auto desc_p = std::make_shared<ComponentsInfoPull>();
|
|
|
|
|
new_copy->append(desc_p);
|
|
|
|
|
|
|
|
|
|
while (_entity_map_over_0xffff.contains(new_copy->entityID()))
|
|
|
|
|
{
|
|
|
|
|
auto ncode = new_copy->entityID() + 1;
|
|
|
|
|
new_copy->resetID(ncode);
|
|
|
|
|
}
|
|
|
|
|
_entity_map_over_0xffff[new_copy->entityID()] = new_copy;
|
|
|
|
|
}
|
|
|
|
|
}break;
|
|
|
|
|
case EntityOperateType::DELETE: {
|
|
|
|
|
if (!this->_entity_map_over_0xffff.contains(in->_entity_id_over_0xffff)) {
|
|
|
|
|
result->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>id<EFBFBD><EFBFBD>%1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(in->_entity_id_over_0xffff);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result->_success_mark = true;
|
|
|
|
|
this->_entity_map_over_0xffff.remove(in->_entity_id_over_0xffff);
|
|
|
|
|
}
|
|
|
|
|
}break;
|
|
|
|
|
case EntityOperateType::MODIFY: {
|
|
|
|
|
if (!this->_entity_map_over_0xffff.contains(in->_entity_id_over_0xffff)) {
|
|
|
|
|
result->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>id<EFBFBD><EFBFBD>%1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(in->_entity_id_over_0xffff);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result->_success_mark = true;
|
2025-06-08 04:12:15 +00:00
|
|
|
|
|
2025-06-10 04:41:33 +00:00
|
|
|
|
auto target_ins = std::static_pointer_cast<RtWsEntity>(
|
2025-06-08 12:17:02 +00:00
|
|
|
|
this->_entity_map_over_0xffff[in->_entity_id_over_0xffff]
|
|
|
|
|
);
|
|
|
|
|
target_ins->resetName(in->_entity_name);
|
|
|
|
|
target_ins->resetTemplet(in->_template_name);
|
|
|
|
|
}
|
|
|
|
|
}break;
|
|
|
|
|
default:
|
|
|
|
|
result->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>%1").arg(in->_operate_code);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result->_time_consume = dt.msecsTo(QTime::currentTime());
|
|
|
|
|
out << result;
|
2025-06-08 04:12:15 +00:00
|
|
|
|
}
|
2025-06-08 12:17:02 +00:00
|
|
|
|
|
2025-06-10 04:41:33 +00:00
|
|
|
|
void DeduceFramework::execute(std::shared_ptr<Immediate> map,
|
2025-06-08 04:12:15 +00:00
|
|
|
|
std::shared_ptr<const EntityTotalGet> in, QList<std::shared_ptr<EntityTotalList>>& out)
|
|
|
|
|
{
|
|
|
|
|
auto rst = std::make_shared<EntityTotalList>();
|
|
|
|
|
rst->reset(in->targetEntity(), in->sourceEntity());
|
2025-06-08 12:17:02 +00:00
|
|
|
|
rst->_entities_list = _entity_map_over_0xffff.keys();
|
2025-06-08 04:12:15 +00:00
|
|
|
|
out << rst;
|
|
|
|
|
}
|
2025-06-08 12:17:02 +00:00
|
|
|
|
|
2025-06-10 04:41:33 +00:00
|
|
|
|
void DeduceFramework::execute(std::shared_ptr<Immediate> map,
|
2025-06-08 12:17:02 +00:00
|
|
|
|
std::shared_ptr<const TypesQuery> in, QList<std::shared_ptr<TypesQueryResult>>& out)
|
|
|
|
|
{
|
|
|
|
|
auto ins = std::make_shared<TypesQueryResult>();
|
|
|
|
|
ins->reset(in->targetEntity(), in->sourceEntity());
|
|
|
|
|
ins->_component_types = this->_factory_ins->allComponentTypes();
|
2025-06-10 15:44:38 +00:00
|
|
|
|
|
|
|
|
|
ins->_entity_templets[NAME(RtEntityManager)] = RtEntityManager::const_id;
|
2025-06-12 00:04:17 +00:00
|
|
|
|
ins->_entity_templets[NAME(RtResourceManager)] = RtResourceManager::const_id;
|
2025-06-08 12:17:02 +00:00
|
|
|
|
for (auto ekey : this->_templets_within_0x2ff_0xffff.keys())
|
|
|
|
|
ins->_entity_templets[ekey] = this->_templets_within_0x2ff_0xffff[ekey]->entityID();
|
|
|
|
|
|
|
|
|
|
out << ins;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 04:41:33 +00:00
|
|
|
|
void DeduceFramework::execute(std::shared_ptr<Immediate> map,
|
2025-06-08 12:17:02 +00:00
|
|
|
|
std::shared_ptr<const TempletOperate> in, QList<std::shared_ptr<RespondDefault>>& out)
|
|
|
|
|
{
|
|
|
|
|
auto dt = QTime::currentTime();
|
|
|
|
|
|
|
|
|
|
auto nins = std::make_shared<RespondDefault>();
|
|
|
|
|
nins->reset(in->targetEntity(), in->sourceEntity());
|
|
|
|
|
|
|
|
|
|
switch ((EntityOperateType)in->_operate_code) {
|
|
|
|
|
case EntityOperateType::NEW: {
|
|
|
|
|
nins->_success_mark = true;
|
2025-06-10 04:41:33 +00:00
|
|
|
|
auto ent_t = std::make_shared<RtWsEntity>();
|
2025-06-10 18:05:00 +00:00
|
|
|
|
ent_t->resetID(0x2ff);
|
2025-06-08 12:17:02 +00:00
|
|
|
|
ent_t->resetTemplet(in->_template_name);
|
2025-06-10 18:05:00 +00:00
|
|
|
|
|
2025-06-08 12:17:02 +00:00
|
|
|
|
auto desc_p = std::make_shared<ComponentsInfoPull>();
|
|
|
|
|
ent_t->append(desc_p);
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD>ģ<EFBFBD><C4A3>id
|
|
|
|
|
auto _tm_ins = _templets_within_0x2ff_0xffff.values();
|
|
|
|
|
QList<uint64_t> allids;
|
2025-06-10 18:05:00 +00:00
|
|
|
|
std::transform(_templets_within_0x2ff_0xffff.begin(), _templets_within_0x2ff_0xffff.end(),
|
|
|
|
|
std::back_inserter(allids), [](std::shared_ptr<RtWsEntity> i) { return i->entityID(); });
|
2025-06-08 12:17:02 +00:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>id
|
|
|
|
|
while (allids.contains(ent_t->entityID())) {
|
|
|
|
|
auto nid = ent_t->entityID() + 1;
|
|
|
|
|
ent_t->resetID(nid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
|
|
|
|
_templets_within_0x2ff_0xffff[in->_template_name] = ent_t;
|
|
|
|
|
}break;
|
|
|
|
|
case EntityOperateType::DELETE: {
|
|
|
|
|
for (auto ekey : this->_templets_within_0x2ff_0xffff.keys()) {
|
|
|
|
|
auto eins = this->_templets_within_0x2ff_0xffff[ekey];
|
|
|
|
|
nins->_success_mark = false;
|
|
|
|
|
nins->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>id<EFBFBD><EFBFBD>%1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(in->_template_id_within_0x2ff_0xffff);
|
|
|
|
|
|
|
|
|
|
if (eins->entityID() == in->_template_id_within_0x2ff_0xffff) {
|
|
|
|
|
this->_templets_within_0x2ff_0xffff.remove(ekey);
|
|
|
|
|
nins->_success_mark = true;
|
|
|
|
|
nins->_reason_text = "";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}break;
|
|
|
|
|
case EntityOperateType::MODIFY: {
|
|
|
|
|
for (auto ekey : this->_templets_within_0x2ff_0xffff.keys()) {
|
|
|
|
|
auto eins = this->_templets_within_0x2ff_0xffff[ekey];
|
|
|
|
|
nins->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>id<EFBFBD><EFBFBD>%1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(in->_template_id_within_0x2ff_0xffff);
|
|
|
|
|
nins->_success_mark = false;
|
|
|
|
|
|
|
|
|
|
if (eins->entityID() == in->_template_id_within_0x2ff_0xffff) {
|
|
|
|
|
eins->resetTemplet(in->_template_name);
|
|
|
|
|
nins->_success_mark = true;
|
|
|
|
|
nins->_reason_text = "";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}break;
|
|
|
|
|
default:
|
|
|
|
|
nins->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>%1").arg(in->_operate_code);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nins->_time_consume = dt.msecsTo(QTime::currentTime());
|
|
|
|
|
out << nins;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 04:41:33 +00:00
|
|
|
|
void DeduceFramework::execute(std::shared_ptr<Immediate> map,
|
2025-06-08 12:17:02 +00:00
|
|
|
|
std::shared_ptr<const ComponentOperate> in, QList<std::shared_ptr<RespondDefault>>& out)
|
|
|
|
|
{
|
|
|
|
|
auto dt = QTime::currentTime();
|
|
|
|
|
|
|
|
|
|
auto result = std::make_shared<RespondDefault>();
|
|
|
|
|
result->reset(in->targetEntity(), in->sourceEntity());
|
|
|
|
|
|
|
|
|
|
// <20><>ȡĿ<C8A1><C4BF>ʵ<EFBFBD><CAB5> ====================================================
|
2025-06-10 04:41:33 +00:00
|
|
|
|
std::shared_ptr<RtWsEntity> target_ins = nullptr;
|
2025-06-08 12:17:02 +00:00
|
|
|
|
if (in->_entity_id_within_0x2ff_0xffffffffffffffff < 0xffff) {
|
|
|
|
|
for (auto info_t : this->_templets_within_0x2ff_0xffff) {
|
|
|
|
|
if (info_t->entityID() == in->_entity_id_within_0x2ff_0xffffffffffffffff) {
|
|
|
|
|
target_ins = info_t;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (this->_entity_map_over_0xffff.contains(in->_entity_id_within_0x2ff_0xffffffffffffffff)) {
|
2025-06-10 04:41:33 +00:00
|
|
|
|
target_ins = std::static_pointer_cast<RtWsEntity>(
|
2025-06-08 12:17:02 +00:00
|
|
|
|
this->_entity_map_over_0xffff[in->_entity_id_within_0x2ff_0xffffffffffffffff]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!target_ins) {
|
|
|
|
|
result->_reason_text = QString("ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>id<EFBFBD><EFBFBD>%1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(in->_entity_id_within_0x2ff_0xffffffffffffffff);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result->_success_mark = true;
|
|
|
|
|
|
|
|
|
|
QStringList total_component_types = this->_factory_ins->allComponentTypes();
|
|
|
|
|
for (auto chk : in->_component_types) {
|
|
|
|
|
if (!total_component_types.contains(chk)) {
|
|
|
|
|
result->_success_mark = false;
|
|
|
|
|
result->_reason_text = QString("ComponentType<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%1").arg(chk);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result->_success_mark) {
|
|
|
|
|
auto comps_list = target_ins->components();
|
2025-06-10 06:12:53 +00:00
|
|
|
|
for (auto comp : comps_list) {
|
|
|
|
|
if (!in->_component_types.contains(comp->name())) {
|
|
|
|
|
target_ins->remove(comp->name());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-08 12:17:02 +00:00
|
|
|
|
|
2025-06-10 06:12:53 +00:00
|
|
|
|
comps_list = target_ins->components();
|
2025-06-08 12:17:02 +00:00
|
|
|
|
QStringList exists_component_types;
|
|
|
|
|
std::transform(comps_list.begin(), comps_list.end(),
|
|
|
|
|
std::back_inserter(exists_component_types),
|
|
|
|
|
[](std::shared_ptr<WsComponent> c) { return c->name(); });
|
|
|
|
|
|
|
|
|
|
for (auto comp : in->_component_types) {
|
|
|
|
|
if (!exists_component_types.contains(comp)) {
|
|
|
|
|
auto ins_comp = this->_factory_ins->makeNew(comp);
|
|
|
|
|
target_ins->append(ins_comp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result->_time_consume = dt.msecsTo(QTime::currentTime());
|
|
|
|
|
out << result;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-14 05:30:42 +00:00
|
|
|
|
#include "VisibleCube.h"
|
2025-06-08 12:17:02 +00:00
|
|
|
|
ComponentFactory::ComponentFactory()
|
|
|
|
|
{
|
|
|
|
|
auto ins = std::make_shared<VisibleCubePlugin>();
|
|
|
|
|
_comp_types[ins->name()] = ins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<WsComponent> ComponentFactory::makeNew(const QString& type)
|
|
|
|
|
{
|
|
|
|
|
if (!this->_comp_types.contains(type))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
auto ntype = _comp_types[type];
|
|
|
|
|
return ntype->defaultNew();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QString> ComponentFactory::allComponentTypes() const
|
|
|
|
|
{
|
|
|
|
|
return _comp_types.keys();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentFactory::recoveryFrom(const QJsonObject& obj)
|
|
|
|
|
{
|
|
|
|
|
QStringList tlist;
|
|
|
|
|
STRLIST_PEAK(tlist);
|
|
|
|
|
|
|
|
|
|
auto curr_list = _comp_types.keys();
|
|
|
|
|
for (auto chk : tlist)
|
|
|
|
|
if (!curr_list.contains(chk))
|
|
|
|
|
throw std::logic_error("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentFactory::saveTo(QJsonObject& obj) const
|
|
|
|
|
{
|
|
|
|
|
QStringList tlist = _comp_types.keys();
|
|
|
|
|
std::sort(tlist.begin(), tlist.end());
|
|
|
|
|
STRLIST_SAVE(tlist);
|
|
|
|
|
}
|