Compare commits

...

3 Commits

Author SHA1 Message Date
codeboss 819bd70426 资源管理实体的路径操作机制 2025-06-14 14:29:43 +08:00
codeboss 438820944a 平面路径操作消息 2025-06-14 13:30:42 +08:00
codeboss 4e4b2ff9b4 重构改名 2025-06-14 13:07:51 +08:00
15 changed files with 421 additions and 34 deletions

View File

@ -104,13 +104,13 @@
<ClCompile Include="componentbasic.cpp" />
<ClCompile Include="DeduceFramework.cpp" />
<ClCompile Include="InvisibleComponent.cpp" />
<ClCompile Include="MapRoute.cpp" />
<ClCompile Include="RouteManage.cpp" />
<ClCompile Include="VisibleCube.cpp" />
<ClInclude Include="componentbasic_global.h" />
<ClInclude Include="componentbasic.h" />
<QtMoc Include="DeduceFramework.h" />
<ClInclude Include="InvisibleComponent.h" />
<ClInclude Include="MapRoute.h" />
<ClInclude Include="RouteManage.h" />
<ClInclude Include="VisibleCube.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -32,7 +32,7 @@
<ClInclude Include="VisibleCube.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MapRoute.h">
<ClInclude Include="RouteManage.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="InvisibleComponent.h">
@ -43,7 +43,7 @@
<ClCompile Include="VisibleCube.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MapRoute.cpp">
<ClCompile Include="RouteManage.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DeduceFramework.cpp">

View File

@ -59,6 +59,7 @@ DeduceFramework::DeduceFramework()
:_factory_ins(std::make_shared<ComponentFactory>()) {
}
#include "RouteManage.h"
void DeduceFramework::init_framework()
{
auto mgr_e = std::make_shared<RtEntityManager>();
@ -70,6 +71,8 @@ void DeduceFramework::init_framework()
auto res_e = std::make_shared<RtResourceManager>();
info_pulls = std::make_shared<ComponentsInfoPull>();
res_e->append(info_pulls);
auto route_mgr = std::make_shared<PlainRouteManage>();
res_e->append(route_mgr);
this->_entity_map_over_0xffff[res_e->entityID()] = res_e;
}
@ -322,7 +325,7 @@ void DeduceFramework::execute(std::shared_ptr<Immediate> map,
out << result;
}
#include "VisibleBox.h"
#include "VisibleCube.h"
ComponentFactory::ComponentFactory()
{
auto ins = std::make_shared<VisibleCubePlugin>();

View File

@ -1 +0,0 @@
#include "MapRoute.h"

View File

@ -1,5 +0,0 @@
#pragma once
class MapRoute
{
};

View File

@ -0,0 +1,138 @@
#include "RouteManage.h"
PlainRouteManage::PlainRouteManage()
{
}
#include <QJsonArray>
void PlainRouteManage::execute(std::shared_ptr<Immediate> map, std::shared_ptr<const NewPlainRoute> in, QList<std::shared_ptr<RespondDefault>>& out)
{
auto resp = std::make_shared<RespondDefault>();
resp->reset(in->targetEntity(), in->sourceEntity());
if(!this->_route_resource_map.contains(in->_route_name)){
resp->_success_mark = true;
this->_route_resource_map[in->_route_name] = RouteResource();
}
else {
resp->_reason_text = "已包含指定名称的路径";
}
out << resp;
}
void PlainRouteManage::execute(std::shared_ptr<Immediate> map, std::shared_ptr<const RemovePlainRoute> in, QList<std::shared_ptr<RespondDefault>>& out)
{
auto resp = std::make_shared<RespondDefault>();
resp->reset(in->targetEntity(), in->sourceEntity());
if (this->_route_resource_map.contains(in->_route_name)) {
resp->_success_mark = true;
this->_route_resource_map.remove(in->_route_name);
}
else {
resp->_reason_text = "不包含指定名称的路径";
}
out << resp;
}
void PlainRouteManage::execute(std::shared_ptr<Immediate> map, std::shared_ptr<const PlainRouteReset> in, QList<std::shared_ptr<RespondDefault>>& out)
{
auto resp = std::make_shared<RespondDefault>();
resp->reset(in->targetEntity(), in->sourceEntity());
if (this->_route_resource_map.contains(in->_route_name)) {
resp->_success_mark = true;
RouteResource res;
res._route_points = in->_lonlat_list;
this->_route_resource_map[in->_route_name] = res;
}
else {
resp->_reason_text = "不包含指定名称的路径";
}
out << resp;
}
void PlainRouteManage::execute(std::shared_ptr<Immediate> map, std::shared_ptr<const PlainRouteQuery> in, QList<std::shared_ptr<PlainRouteInfo>>& out)
{
auto resp = std::make_shared<PlainRouteInfo>();
resp->reset(in->targetEntity(), in->sourceEntity());
if (this->_route_resource_map.contains(in->_route_name)) {
resp->_success_mark = true;
resp->_route_name = in->_route_name;
resp->_lonlat_list = this->_route_resource_map[in->_route_name]._route_points;
}
else {
resp->_reason_text = "不包含指定名称的路径";
}
out << resp;
}
void PlainRouteManage::recoveryFrom(const QJsonObject& obj)
{
auto route_array = obj["total_route"].toArray();
for (auto idx = 0; idx < route_array.size(); ++idx) {
auto track_record = route_array.at(idx).toObject();
auto track_name = track_record["name"].toString();
auto track_points = track_record["points"].toArray();
RouteResource value;
for (auto tidx = 0; tidx < track_points.size(); tidx++) {
auto point = track_points.at(tidx).toObject();
auto pins = LonLatPos{ point["point_lon"].toDouble(), point["point_lat"].toDouble() };
value._route_points << pins;
}
this->_route_resource_map[track_name] = value;
}
}
void PlainRouteManage::saveTo(QJsonObject& obj) const
{
QJsonArray route_array;
for (auto route_name : this->_route_resource_map.keys()) {
QJsonObject track_record;
track_record["name"] = route_name;
QJsonArray point_array;
for (auto pointv : this->_route_resource_map[route_name]._route_points) {
QJsonObject point;
point["point_lon"] = pointv._lon_deg;
point["point_lat"] = pointv._lat_deg;
point_array.append(point);
}
track_record["points"] = point_array;
route_array.append(track_record);
}
obj["total_route"] = route_array;
}
std::shared_ptr<WsComponent> PlainRouteManage::defaultNew() const
{
return nullptr;
}
void PlainRouteManage::bindEntity(std::weak_ptr<WsEntity> host)
{
this->_bind_entity = host;
}
QString PlainRouteManage::name() const
{
return NAME(PlainRouteManage);
}
RouteResource& RouteResource::operator=(const RouteResource& other)
{
this->_route_points = other._route_points;
return *this;
}

View File

@ -0,0 +1,44 @@
#pragma once
#include "componentbasic.h"
#include <route_access.h>
#include <QHash>
/// <summary>
/// 路径资源
/// </summary>
struct RouteResource {
QList<LonLatPos> _route_points;
RouteResource& operator=(const RouteResource& other);
};
/// <summary>
/// 平面路径管理插件
/// </summary>
class PlainRouteManage : public ProcList<
WsRespond<NewPlainRoute, RespondDefault>,
WsRespond<RemovePlainRoute, RespondDefault>,
WsRespond<PlainRouteReset, RespondDefault>,
WsRespond<PlainRouteQuery, PlainRouteInfo>
> {
private:
std::weak_ptr<WsEntity> _bind_entity;
QHash<QString, RouteResource> _route_resource_map;
public:
PlainRouteManage();
// 通过 ProcList 继承
void execute(std::shared_ptr<Immediate> map, std::shared_ptr<const NewPlainRoute> in, QList<std::shared_ptr<RespondDefault>>& out) override;
void execute(std::shared_ptr<Immediate> map, std::shared_ptr<const RemovePlainRoute> in, QList<std::shared_ptr<RespondDefault>>& out) override;
void execute(std::shared_ptr<Immediate> map, std::shared_ptr<const PlainRouteReset> in, QList<std::shared_ptr<RespondDefault>>& out) override;
void execute(std::shared_ptr<Immediate> map, std::shared_ptr<const PlainRouteQuery> in, QList<std::shared_ptr<PlainRouteInfo>>& out) override;
void recoveryFrom(const QJsonObject& obj) override;
void saveTo(QJsonObject& obj) const override;
std::shared_ptr<WsComponent> defaultNew() const override;
void bindEntity(std::weak_ptr<WsEntity> host) override;
QString name() const override;
};

View File

@ -15,8 +15,8 @@ class COMPONENTBASIC_EXPORT VisibleCubePlugin : public ProcList<
{
private:
std::weak_ptr<WsEntity> _bind_entity;
D3Data _self_d3;
LLAPos _self_lla;
VolumeData _self_d3;
LonLatAltPos _self_lla;
Posture _self_posture;
public:

View File

@ -100,9 +100,11 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="route_access.cpp" />
<ClInclude Include="messagebasic_global.h" />
<ClInclude Include="messagebasic.h" />
<ClCompile Include="messagebasic.cpp" />
<ClInclude Include="route_access.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">

View File

@ -32,5 +32,13 @@
<ClInclude Include="messagebasic.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="route_access.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="route_access.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -20,11 +20,10 @@
#define STRLIST_PEAK(u) u = obj[NAME(u)].toString().split(",")
class MESSAGEBASIC_EXPORT AbstractMessage : public WsMessage {
private:
protected:
uint64_t _from_id = 0, _to_id = 0;
QString _topic_string;
protected:
AbstractMessage(const QString& topic);
public:
@ -94,7 +93,7 @@ struct Posture {
/// <summary>
/// 三维数据结构定义
/// </summary>
struct D3Data {
struct VolumeData {
double _length_m = 0;
double _width_m = 0;
double _height_m = 0;
@ -104,9 +103,9 @@ struct D3Data {
/// 体积盒详细数据定义
/// </summary>
struct MESSAGEBASIC_EXPORT Box3DDesc : public AbstractMessage {
D3Data _d3_data;
VolumeData _d3_data;
Posture _posture_d3;
LLAPos _lla_pos;
LonLatAltPos _lla_pos;
Box3DDesc();
@ -116,7 +115,7 @@ struct MESSAGEBASIC_EXPORT Box3DDesc : public AbstractMessage {
};
struct MESSAGEBASIC_EXPORT Set3DBoxD3Data : public AbstractMessage {
D3Data _d3_data;
VolumeData _d3_data;
Set3DBoxD3Data();
@ -138,7 +137,7 @@ struct MESSAGEBASIC_EXPORT Set3DBoxPosture : public AbstractMessage
struct MESSAGEBASIC_EXPORT Set3DBoxLLAPos : public AbstractMessage
{
LLAPos _lla_pos;
LonLatAltPos _lla_pos;
Set3DBoxLLAPos();

View File

@ -0,0 +1,121 @@
#include "route_access.h"
PlainRouteReset::PlainRouteReset()
:AbstractMessage(NAME(PlainRouteReset)) {
}
void PlainRouteReset::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
STRING_PEAK(this->_route_name);
QStringList lonlist, latlist;
STRLIST_PEAK(lonlist);
STRLIST_PEAK(latlist);
for (auto idx = 0; idx < lonlist.size(); ++idx) {
auto lon = lonlist.at(idx).toDouble();
auto lat = latlist.at(idx).toDouble();
this->_lonlat_list << LonLatPos{ lon, lat };
}
}
void PlainRouteReset::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
STRING_SAVE(this->_route_name);
QStringList lonlist, latlist;
for (auto pos : this->_lonlat_list) {
lonlist << QString("%1").arg(pos._lon_deg);
latlist << QString("%1").arg(pos._lat_deg);
}
STRLIST_SAVE(lonlist);
STRLIST_SAVE(latlist);
}
NewPlainRoute::NewPlainRoute()
:AbstractMessage(NAME(NewPlainRoute)) {
}
void NewPlainRoute::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
STRING_PEAK(_route_name);
}
void NewPlainRoute::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
STRING_SAVE(_route_name);
}
RemovePlainRoute::RemovePlainRoute()
:AbstractMessage(NAME(RemovePlainRoute))
{
}
void RemovePlainRoute::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
STRING_PEAK(_route_name);
}
void RemovePlainRoute::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
STRING_SAVE(_route_name);
}
PlainRouteQuery::PlainRouteQuery()
:AbstractMessage(NAME(PlainRouteQuery))
{
}
void PlainRouteQuery::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
STRING_PEAK(_route_name);
}
void PlainRouteQuery::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
STRING_SAVE(_route_name);
}
PlainRouteInfo::PlainRouteInfo()
:RespondDefault() {
_topic_string = NAME(PlainRouteInfo);
}
void PlainRouteInfo::recoveryFrom(const QJsonObject& obj)
{
RespondDefault::recoveryFrom(obj);
STRING_PEAK(this->_route_name);
QStringList lonlist, latlist;
STRLIST_PEAK(lonlist);
STRLIST_PEAK(latlist);
for (auto idx = 0; idx < lonlist.size(); ++idx) {
auto lon = lonlist.at(idx).toDouble();
auto lat = latlist.at(idx).toDouble();
this->_lonlat_list << LonLatPos{ lon, lat };
}
}
void PlainRouteInfo::saveTo(QJsonObject& obj) const
{
RespondDefault::saveTo(obj);
STRING_SAVE(this->_route_name);
QStringList lonlist, latlist;
for (auto pos : this->_lonlat_list) {
lonlist << QString("%1").arg(pos._lon_deg);
latlist << QString("%1").arg(pos._lat_deg);
}
STRLIST_SAVE(lonlist);
STRLIST_SAVE(latlist);
}

View File

@ -0,0 +1,70 @@
#pragma once
#include "messagebasic.h"
#include <standardglobe.h>
/// <summary>
/// 新建平面路径
/// </summary>
struct MESSAGEBASIC_EXPORT NewPlainRoute : public AbstractMessage {
QString _route_name;
NewPlainRoute();
// Serializable
void recoveryFrom(const QJsonObject& obj) override;
void saveTo(QJsonObject& obj) const override;
};
/// <summary>
/// 删除平面路径
/// </summary>
struct MESSAGEBASIC_EXPORT RemovePlainRoute : public AbstractMessage {
QString _route_name;
RemovePlainRoute();
// Serializable
void recoveryFrom(const QJsonObject& obj) override;
void saveTo(QJsonObject& obj) const override;
};
/// <summary>
/// 重置平面路径
/// </summary>
struct MESSAGEBASIC_EXPORT PlainRouteReset : public AbstractMessage {
QList<LonLatPos> _lonlat_list;
QString _route_name;
PlainRouteReset();
// Serializable
void recoveryFrom(const QJsonObject& obj) override;
void saveTo(QJsonObject& obj) const override;
};
/// <summary>
/// 平面路径数据查询
/// </summary>
struct MESSAGEBASIC_EXPORT PlainRouteQuery : public AbstractMessage {
QString _route_name;
PlainRouteQuery();
// Serializable
void recoveryFrom(const QJsonObject& obj) override;
void saveTo(QJsonObject& obj) const override;
};
/// <summary>
/// 返回平面路径数据
/// </summary>
struct MESSAGEBASIC_EXPORT PlainRouteInfo : public RespondDefault {
QList<LonLatPos> _lonlat_list;
QString _route_name;
PlainRouteInfo();
// Serializable
void recoveryFrom(const QJsonObject& obj) override;
void saveTo(QJsonObject& obj) const override;
};

View File

@ -11,7 +11,7 @@ StandardGlobe::StandardGlobe()
{
}
ECEFPos StandardGlobe::llaToEcef(const LLAPos& v)
ECEFPos StandardGlobe::llaToEcef(const LonLatAltPos& v)
{
// 柴麻鉦宣白伉鉦宣
auto axis_r_g = v._alt_m + _radius_m;
@ -27,7 +27,7 @@ ECEFPos StandardGlobe::llaToEcef(const LLAPos& v)
return ECEFPos{ axis_x, axis_y, axis_z };
}
LLAPos StandardGlobe::ecefToLLA(const ECEFPos& v)
LonLatAltPos StandardGlobe::ecefToLLA(const ECEFPos& v)
{
auto r2 = std::sqrt(v._x_pos * v._x_pos + v._y_pos * v._y_pos);
auto rad_lon = acos(v._x_pos / r2);
@ -36,7 +36,7 @@ LLAPos StandardGlobe::ecefToLLA(const ECEFPos& v)
auto rx = std::sqrt(v._x_pos * v._x_pos + v._y_pos * v._y_pos + v._z_pos * v._z_pos);
auto rad_lat = asin(v._z_pos / rx);
LLAPos ret;
LonLatAltPos ret;
ret._lon_deg = rad2d(rad_lon);
ret._lat_deg = rad2d(rad_lat);
ret._alt_m = rx - _radius_m;
@ -44,7 +44,7 @@ LLAPos StandardGlobe::ecefToLLA(const ECEFPos& v)
return ret;
}
void StandardGlobe::getDistanceWithTargetLLA(const LLAPos& base, const LLAPos& target, double& dist, double& azi)
void StandardGlobe::getDistanceWithTargetLLA(const LonLatAltPos& base, const LonLatAltPos& target, double& dist, double& azi)
{
// ecef文楚
auto vec_base = llaToEcef(base).getVec3();
@ -75,7 +75,7 @@ void StandardGlobe::getDistanceWithTargetLLA(const LLAPos& base, const LLAPos& t
}
#include <qquaternion.h>
void StandardGlobe::getTargetLLAWithDistance(const LLAPos& base, double dist, double azi, LLAPos& target)
void StandardGlobe::getTargetLLAWithDistance(const LonLatAltPos& base, double dist, double azi, LonLatAltPos& target)
{
auto ecef_bvec = llaToEcef(base).getVec3().normalized();
QQuaternion u0(-deg2a(azi), ecef_bvec);
@ -96,7 +96,7 @@ void StandardGlobe::getTargetLLAWithDistance(const LLAPos& base, double dist, do
target = ecefToLLA(sv);
}
PolarPos StandardGlobe::getPolarWithLLA(const LLAPos& base, const LLAPos& target)
PolarPos StandardGlobe::getPolarWithLLA(const LonLatAltPos& base, const LonLatAltPos& target)
{
// ecef文楚
auto vec_base = llaToEcef(base).getVec3();
@ -134,7 +134,7 @@ PolarPos StandardGlobe::getPolarWithLLA(const LLAPos& base, const LLAPos& target
return p;
}
LLAPos StandardGlobe::getLLAWithPolar(const LLAPos& base, const PolarPos& target)
LonLatAltPos StandardGlobe::getLLAWithPolar(const LonLatAltPos& base, const PolarPos& target)
{
auto ecef_b = llaToEcef(base).getVec3();
auto u_azi = QQuaternion(-deg2a(target._azimuth_deg), ecef_b.normalized());

View File

@ -4,10 +4,18 @@
class QVector3D;
/// <summary>
/// ¾­Î³¶È×ø±ê
/// </summary>
struct LonLatPos {
double _lon_deg = 0;
double _lat_deg = 0;
};
/// <summary>
/// 经纬高坐标系坐标
/// </summary>
struct LLAPos {
struct LonLatAltPos {
double _lon_deg = 0;
double _lat_deg = 0;
double _alt_m = 0;
@ -56,8 +64,8 @@ private:
public:
StandardGlobe();
static ECEFPos llaToEcef(const LLAPos &v);
static LLAPos ecefToLLA(const ECEFPos &v);
static ECEFPos llaToEcef(const LonLatAltPos &v);
static LonLatAltPos ecefToLLA(const ECEFPos &v);
/// <summary>
/// 根据LLA坐标获取两点之间的大地线长度和b->t初始方位角warning本计算忽视LLA的高度值
/// </summary>
@ -65,7 +73,7 @@ public:
/// <param name="target"></param>
/// <param name="dist"></param>
/// <param name="azi"></param>
static void getDistanceWithTargetLLA(const LLAPos &base, const LLAPos &target, double &dist, double &azi);
static void getDistanceWithTargetLLA(const LonLatAltPos &base, const LonLatAltPos &target, double &dist, double &azi);
/// <summary>
/// 根据两点之间的大地线长度和b->t初始方位角计算目标LLA定位坐标
/// </summary>
@ -73,19 +81,19 @@ public:
/// <param name="dist"></param>
/// <param name="azi"></param>
/// <param name="target"></param>
static void getTargetLLAWithDistance(const LLAPos& base, double dist, double azi, LLAPos& target);
static void getTargetLLAWithDistance(const LonLatAltPos& base, double dist, double azi, LonLatAltPos& target);
/// <summary>
/// 通过LLA坐标获取目标极坐标
/// </summary>
/// <param name="base"></param>
/// <param name="target"></param>
/// <returns></returns>
static PolarPos getPolarWithLLA(const LLAPos &base, const LLAPos &target);
static PolarPos getPolarWithLLA(const LonLatAltPos &base, const LonLatAltPos &target);
/// <summary>
/// 通过极坐标获取目标LLA坐标
/// </summary>
/// <param name="base"></param>
/// <param name="target"></param>
/// <returns></returns>
static LLAPos getLLAWithPolar(const LLAPos &base, const PolarPos &target);
static LonLatAltPos getLLAWithPolar(const LonLatAltPos &base, const PolarPos &target);
};