SimsWorld/MessageBasic/messagebasic.cpp

425 lines
10 KiB
C++
Raw Permalink Blame History

#include "messagebasic.h"
#include "visiblecube_access.h"
#include "entity_operate.h"
#include "componentinfo_access.h"
#include <QVariant>
void from_to_save(uint64_t f, uint64_t t, QJsonObject& o) {
o["source_entity"] = QJsonValue::fromVariant(QVariant::fromValue(f));
o["target_entity"] = QJsonValue::fromVariant(QVariant::fromValue(t));
}
void from_to_recovery(uint64_t& f, uint64_t& t, const QJsonObject& o) {
f = o["source_entity"].toVariant().toULongLong();
t = o["target_entity"].toVariant().toULongLong();
}
DeduceRequest::DeduceRequest()
:AbstractMessage(NAME(DeduceRequest)) {
}
std::shared_ptr<Serializable> DeduceRequest::newDefault() const
{
return std::make_shared<DeduceRequest>();
}
SyncRequest::SyncRequest()
:AbstractMessage(NAME(SyncRequest)),
_time_current(0) {
}
std::shared_ptr<Serializable> SyncRequest::newDefault() const
{
return std::make_shared<SyncRequest>();
}
void SyncRequest::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUBLE_PEAK(_time_current);
}
void SyncRequest::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_time_current);
}
RespondDefault::RespondDefault()
:AbstractMessage(NAME(RespondDefault)),
_time_consume(0) {
}
std::shared_ptr<Serializable> RespondDefault::newDefault() const
{
return std::make_shared<RespondDefault>();
}
void RespondDefault::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUBLE_PEAK(_time_consume);
UINT64_PEAK(_success_mark);
STRING_PEAK(_reason_text);
}
void RespondDefault::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_time_consume);
UINT64_SAVE(_success_mark);
STRING_SAVE(_reason_text);
}
Get3DBox::Get3DBox()
:AbstractMessage(NAME(Get3DBox)) {
}
Box3DDesc::Box3DDesc()
:AbstractMessage(NAME(Box3DDesc)) {
}
void Box3DDesc::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUBLE_PEAK(this->_d3_data._height_m);
DOUBLE_PEAK(this->_d3_data._length_m);
DOUBLE_PEAK(this->_d3_data._width_m);
DOUBLE_PEAK(this->_lla_pos._lon_deg);
DOUBLE_PEAK(this->_lla_pos._lat_deg);
DOUBLE_PEAK(this->_lla_pos._alt_m);
DOUBLE_PEAK(this->_posture_d3._azimuth_deg);
DOUBLE_PEAK(this->_posture_d3._pitch_deg);
DOUBLE_PEAK(this->_posture_d3._roll_deg);
}
void Box3DDesc::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(this->_d3_data._height_m);
DOUBLE_SAVE(this->_d3_data._length_m);
DOUBLE_SAVE(this->_d3_data._width_m);
DOUBLE_SAVE(this->_lla_pos._lon_deg);
DOUBLE_SAVE(this->_lla_pos._lat_deg);
DOUBLE_SAVE(this->_lla_pos._alt_m);
DOUBLE_SAVE(this->_posture_d3._azimuth_deg);
DOUBLE_SAVE(this->_posture_d3._pitch_deg);
DOUBLE_SAVE(this->_posture_d3._roll_deg);
}
EntityOperate::EntityOperate()
:AbstractMessage(NAME(EntityOperate)) {
}
void EntityOperate::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
UINT64_PEAK(_operate_code);
STRING_PEAK(_template_name);
STRING_PEAK(_entity_name);
UINT64_PEAK(_entity_id_over_0xffff);
}
void EntityOperate::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
UINT64_SAVE(_operate_code);
STRING_SAVE(_template_name);
STRING_SAVE(_entity_name);
UINT64_SAVE(_entity_id_over_0xffff);
}
AbstractMessage::AbstractMessage(const QString& topic) :_topic_string(topic) {}
void AbstractMessage::reset(uint64_t from, uint64_t to) {
this->_from_id = from;
this->_to_id = to;
}
// ͨ<><CDA8> WsMessage <20>̳<EFBFBD>
void AbstractMessage::recoveryFrom(const QJsonObject& obj) {
from_to_recovery(_from_id, _to_id, obj);
STRING_PEAK(this->_topic_string);
}
void AbstractMessage::saveTo(QJsonObject& obj) const
{
from_to_save(_from_id, _to_id, obj);
STRING_SAVE(this->_topic_string);
}
QString AbstractMessage::topicString() const
{
return _topic_string;
}
uint64_t AbstractMessage::targetEntity() const
{
return _to_id;
}
uint64_t AbstractMessage::sourceEntity() const
{
return _from_id;
}
EntityTotalGet::EntityTotalGet()
:AbstractMessage(NAME(EntityTotalGet)) {
}
EntityTotalList::EntityTotalList()
:AbstractMessage(NAME(EntityTotalList)) {
}
void EntityTotalList::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
QStringList strs;
STRLIST_PEAK(strs);
std::transform(strs.begin(), strs.end(),
std::back_inserter(_entities_list), [](QString v) { return v.toULongLong(); });
}
void EntityTotalList::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
QStringList strs;
std::transform(_entities_list.begin(), _entities_list.end(),
std::back_inserter(strs), [](int v) { return QString("%1").arg(v); });
STRLIST_SAVE(strs);
}
TypesQueryResult::TypesQueryResult()
:AbstractMessage(NAME(TypesQueryResult)) {
}
auto ilist_conv = [](const QList<uint64_t>& ilist) {
QStringList _templets_ids;
std::transform(ilist.begin(), ilist.end(),
std::back_inserter(_templets_ids), [](uint64_t v) {return QString("%1").arg(v); });
return _templets_ids;
};
auto ilist_from = [](const QStringList& slist) {
QList<uint64_t> _ids;
std::transform(slist.begin(), slist.end(),
std::back_inserter(_ids), [](QString s) { return s.toULongLong(); });
return _ids;
};
void TypesQueryResult::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
STRLIST_PEAK(_component_types);
QStringList _templet_types;
STRLIST_SAVE(_templet_types);
QStringList _templets_ids;
STRLIST_SAVE(_templets_ids);
auto idlist = ilist_from(_templets_ids);
_entity_templets.clear();
for (auto idx = 0; idx < _templets_ids.size(); idx++) {
_entity_templets[_templet_types.at(idx)] = idlist.at(idx);
}
}
void TypesQueryResult::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
STRLIST_SAVE(_component_types);
QStringList _templet_types = _entity_templets.keys();
STRLIST_SAVE(_templet_types);
QList<uint64_t> _templet_ids;
for (auto key : _templet_types)
_templet_ids << _entity_templets[key];
QStringList _templets_ids = ilist_conv(_templet_ids);
STRLIST_SAVE(_templets_ids);
}
TypesQuery::TypesQuery()
:AbstractMessage(NAME(TypesQuery)) {
}
ComponentDatasQuery::ComponentDatasQuery()
:AbstractMessage(NAME(ComponentDatasQuery)) {
}
ComponentDatasQueryResult::ComponentDatasQueryResult()
:AbstractMessage(NAME(ComponentDatasQueryResult)) {
}
void ComponentDatasQueryResult::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
_entity_json = obj["result_json"].toObject();
}
void ComponentDatasQueryResult::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
obj["result_json"] = _entity_json;
}
TempletOperate::TempletOperate()
:AbstractMessage(NAME(TempletOperate)) {
}
void TempletOperate::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
UINT64_PEAK(_operate_code);
STRING_PEAK(_template_name);
UINT64_PEAK(_template_id_within_0x2ff_0xffff);
}
void TempletOperate::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
UINT64_SAVE(_operate_code);
STRING_SAVE(_template_name);
UINT64_SAVE(_template_id_within_0x2ff_0xffff);
}
ComponentOperate::ComponentOperate()
:AbstractMessage(NAME(ComponentOperate)) {
}
void ComponentOperate::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
UINT64_PEAK(_entity_id_within_0x2ff_0xffffffffffffffff);
STRLIST_PEAK(_component_types);
}
void ComponentOperate::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
UINT64_SAVE(_entity_id_within_0x2ff_0xffffffffffffffff);
STRLIST_SAVE(_component_types);
}
ProcedureSignatureQuery::ProcedureSignatureQuery()
: AbstractMessage(NAME(ProcedureSignatureQuery)) {
}
ProcedureSignatureQueryResult::ProcedureSignatureQueryResult()
:AbstractMessage(NAME(ProcedureSignatureQueryResult)) {
}
void ProcedureSignatureQueryResult::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
QStringList input, output;
STRLIST_PEAK(input);
STRLIST_PEAK(output);
for (auto idx = 0; idx < input.size(); ++idx)
this->_signature_list << std::make_pair(input[idx], output[idx]);
}
void ProcedureSignatureQueryResult::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
QStringList input, output;
for (auto sig : this->_signature_list)
{
input << sig.first;
output << sig.second;
}
STRLIST_SAVE(input);
STRLIST_SAVE(output);
}
Set3DBoxD3Data::Set3DBoxD3Data()
:AbstractMessage(NAME(Set3DBoxD3Data)) {
}
void Set3DBoxD3Data::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUBLE_PEAK(_d3_data._length_m);
DOUBLE_PEAK(_d3_data._width_m);
DOUBLE_PEAK(_d3_data._height_m);
}
void Set3DBoxD3Data::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_d3_data._length_m);
DOUBLE_SAVE(_d3_data._width_m);
DOUBLE_SAVE(_d3_data._height_m);
}
Set3DBoxPosture::Set3DBoxPosture()
:AbstractMessage(NAME(Set3DBoxPosture)) {
}
void Set3DBoxPosture::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUBLE_PEAK(_posture_d3._azimuth_deg);
DOUBLE_PEAK(_posture_d3._pitch_deg);
DOUBLE_PEAK(_posture_d3._roll_deg);
}
void Set3DBoxPosture::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_posture_d3._azimuth_deg);
DOUBLE_SAVE(_posture_d3._pitch_deg);
DOUBLE_SAVE(_posture_d3._roll_deg);
}
Set3DBoxLLAPos::Set3DBoxLLAPos()
:AbstractMessage(NAME(Set3DBoxLLAPos)) {
}
void Set3DBoxLLAPos::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUBLE_PEAK(_lla_pos._lon_deg);
DOUBLE_PEAK(_lla_pos._lat_deg);
DOUBLE_PEAK(_lla_pos._alt_m);
}
void Set3DBoxLLAPos::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_lla_pos._lon_deg);
DOUBLE_SAVE(_lla_pos._lat_deg);
DOUBLE_SAVE(_lla_pos._alt_m);
}
EntityInitialRequest::EntityInitialRequest()
:AbstractMessage(NAME(EntityInitialRequest)) {
}
std::shared_ptr<Serializable> EntityInitialRequest::newDefault() const
{
return std::make_shared<EntityInitialRequest>();
}
EntityPreparedRequest::EntityPreparedRequest()
:AbstractMessage(NAME(EntityPreparedRequest)) {
}
std::shared_ptr<Serializable> EntityPreparedRequest::newDefault() const
{
return std::make_shared<EntityPreparedRequest>();
}