modify entity
This commit is contained in:
parent
5c5143e6c2
commit
596d60f6bc
@ -180,7 +180,7 @@ Entity* EntitiesManager::CreateEntity(const QString& type, WorkSpace* workspace)
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity* EntitiesManager::CreateEntityWithComponents(const QString& type, WorkSpace* workspace) {
|
Entity* EntitiesManager::CreateEntityWithComponents(const QString& type, const QString& mesh, bool useLabel, WorkSpace* workspace) {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ Entity* EntitiesManager::CreateEntityWithComponents(const QString& type, WorkSpa
|
|||||||
workspace = WorkSpaceManager::Get().GetCurrent();
|
workspace = WorkSpaceManager::Get().GetCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity* entity = EntityFactory::Get().CreateEntityWithComponents(type, workspace);
|
Entity* entity = EntityFactory::Get().CreateEntityWithComponents(type, mesh, useLabel, workspace);
|
||||||
if (entity) {
|
if (entity) {
|
||||||
AddEntity(entity);
|
AddEntity(entity);
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
// New factory methods
|
// New factory methods
|
||||||
Entity* CreateEntity(const QString& type, WorkSpace* workspace = nullptr);
|
Entity* CreateEntity(const QString& type, WorkSpace* workspace = nullptr);
|
||||||
Entity* CreateEntityWithComponents(const QString& type, WorkSpace* workspace = nullptr);
|
Entity* CreateEntityWithComponents(const QString& type, const QString& mesh, bool useLabel, WorkSpace* workspace = nullptr);
|
||||||
|
|
||||||
// Get supported entity types
|
// Get supported entity types
|
||||||
QStringList GetSupportedEntityTypes() const;
|
QStringList GetSupportedEntityTypes() const;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ Entity* EntityFactory::CreateEntity(const QString& type, WorkSpace* workspace) {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity* EntityFactory::CreateEntityWithComponents(const QString& type, WorkSpace* workspace) {
|
Entity* EntityFactory::CreateEntityWithComponents(const QString& type, const QString& mesh, bool useLabel, WorkSpace* workspace) {
|
||||||
Entity* entity = CreateEntity(type, workspace);
|
Entity* entity = CreateEntity(type, workspace);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -36,15 +36,36 @@ Entity* EntityFactory::CreateEntityWithComponents(const QString& type, WorkSpace
|
|||||||
|
|
||||||
// Get default mesh
|
// Get default mesh
|
||||||
QString defaultMesh = it->second->GetDefaultMesh();
|
QString defaultMesh = it->second->GetDefaultMesh();
|
||||||
|
if (!mesh.isEmpty()) {
|
||||||
|
defaultMesh = mesh;
|
||||||
|
}
|
||||||
if (!defaultMesh.isEmpty()) {
|
if (!defaultMesh.isEmpty()) {
|
||||||
SceneComponent* meshComponent = ComponentFactory::Create("MeshComponent", nullptr);
|
SceneComponent* meshComponent = ComponentFactory::Create("MeshComponent", nullptr);
|
||||||
if (meshComponent) {
|
if (meshComponent) {
|
||||||
meshComponent->SetAttribute("mesh", defaultMesh.toStdString().c_str());
|
meshComponent->SetAttribute("mesh", defaultMesh.toLocal8Bit());
|
||||||
meshComponent->AttachEntity(entity);
|
meshComponent->AttachEntity(entity);
|
||||||
LOG_INFO("EntityFactory::CreateEntityWithComponents - Added MeshComponent with mesh: {}", defaultMesh.toStdString());
|
LOG_INFO("EntityFactory::CreateEntityWithComponents - Added MeshComponent with mesh: {}", defaultMesh.toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (useLabel) {
|
||||||
|
SceneComponent* rootComponent = entity->GetRootComponent();
|
||||||
|
if (nullptr == rootComponent) {
|
||||||
|
SceneComponent* meshComponent = ComponentFactory::Create("LabelComponent", nullptr);
|
||||||
|
if (meshComponent) {
|
||||||
|
meshComponent->AttachEntity(entity);
|
||||||
|
LOG_INFO("EntityFactory::CreateEntityWithComponents - Added LabelComponent with mesh: {}", defaultMesh.toStdString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SceneComponent* LabelComponent = ComponentFactory::Create("LabelComponent", rootComponent);
|
||||||
|
if (LabelComponent) {
|
||||||
|
LabelComponent->AttachTo(rootComponent);
|
||||||
|
LOG_INFO("EntityFactory::CreateEntityWithComponents - Added LabelComponent with mesh: {}", defaultMesh.toStdString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add required components
|
// Add required components
|
||||||
QStringList requiredComponents = it->second->GetRequiredComponents();
|
QStringList requiredComponents = it->second->GetRequiredComponents();
|
||||||
SceneComponent* rootComponent = entity->GetRootComponent();
|
SceneComponent* rootComponent = entity->GetRootComponent();
|
||||||
|
|||||||
@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
Entity* CreateEntity(const QString& type, WorkSpace* workspace);
|
Entity* CreateEntity(const QString& type, WorkSpace* workspace);
|
||||||
|
|
||||||
Entity* CreateEntityWithComponents(const QString& type, WorkSpace* workspace);
|
Entity* CreateEntityWithComponents(const QString& type, const QString& mesh, bool useLabel, WorkSpace* workspace);
|
||||||
|
|
||||||
QStringList GetRegisteredTypes() const;
|
QStringList GetRegisteredTypes() const;
|
||||||
|
|
||||||
|
|||||||
@ -2082,12 +2082,12 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>OsgWidget</name>
|
<name>OsgWidget</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../viewer/OsgWidget.cpp" line="130"/>
|
<location filename="../viewer/OsgWidget.cpp" line="131"/>
|
||||||
<source>warning</source>
|
<source>warning</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../viewer/OsgWidget.cpp" line="131"/>
|
<location filename="../viewer/OsgWidget.cpp" line="132"/>
|
||||||
<source>open dyt file failed</source>
|
<source>open dyt file failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
@ -2188,26 +2188,6 @@
|
|||||||
<source>Preset Models</source>
|
<source>Preset Models</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
|
||||||
<location filename="../ui/ModelBrowser/PresetModelPanel.ui" line="47"/>
|
|
||||||
<source>Ships</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
|
||||||
<location filename="../ui/ModelBrowser/PresetModelPanel.ui" line="87"/>
|
|
||||||
<source>Satellites</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
|
||||||
<location filename="../ui/ModelBrowser/PresetModelPanel.ui" line="127"/>
|
|
||||||
<source>Missiles</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
|
||||||
<location filename="../ui/ModelBrowser/PresetModelPanel.ui" line="167"/>
|
|
||||||
<source>Jammers</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>PropertyBrowser</name>
|
<name>PropertyBrowser</name>
|
||||||
|
|||||||
@ -131,6 +131,8 @@ void PresetModelListWidget::setModelList(const QVector<ModelInfo>& models) {
|
|||||||
painter.drawText(pixmap.rect(), Qt::AlignCenter, "?");
|
painter.drawText(pixmap.rect(), Qt::AlignCenter, "?");
|
||||||
item->setIcon(QIcon(pixmap));
|
item->setIcon(QIcon(pixmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item->setToolTip(modelInfo.description.isEmpty() ? modelInfo.name : modelInfo.description);
|
||||||
|
|
||||||
// Store model name as simple string
|
// Store model name as simple string
|
||||||
item->setData(Qt::UserRole, modelInfo.name);
|
item->setData(Qt::UserRole, modelInfo.name);
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
|||||||
@ -14,11 +14,13 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
#include "common/RecourceHelper.h"
|
#include "common/RecourceHelper.h"
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
#include "ui/DockTitleBar.h"
|
#include "ui/DockTitleBar.h"
|
||||||
#include "ui/DockWidget.h"
|
#include "ui/DockWidget.h"
|
||||||
|
#include "workspace/PresetModelConfigParser.h"
|
||||||
|
|
||||||
#include "ui_PresetModelPanel.h"
|
#include "ui_PresetModelPanel.h"
|
||||||
|
|
||||||
@ -34,6 +36,7 @@ PresetModelPanel::PresetModelPanel(QWidget *parent)
|
|||||||
|
|
||||||
PresetModelPanel::~PresetModelPanel()
|
PresetModelPanel::~PresetModelPanel()
|
||||||
{
|
{
|
||||||
|
ClearDynamicUI();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,80 +60,97 @@ void PresetModelPanel::InitUI()
|
|||||||
QString presetsPath = QString("%1/presets").arg(RecourceHelper::Get().GetResourcesPath());
|
QString presetsPath = QString("%1/presets").arg(RecourceHelper::Get().GetResourcesPath());
|
||||||
if (PresetModelConfigParser::Get().LoadAllConfigs(presetsPath)) {
|
if (PresetModelConfigParser::Get().LoadAllConfigs(presetsPath)) {
|
||||||
// Successfully loaded from configuration files
|
// Successfully loaded from configuration files
|
||||||
|
CreateDynamicUI();
|
||||||
LoadModelsFromConfig();
|
LoadModelsFromConfig();
|
||||||
} else {
|
} else {
|
||||||
// Failed to load configuration files, use hardcoded defaults as fallback
|
// Failed to load configuration files, use hardcoded defaults as fallback
|
||||||
LOG_WARN("Failed to load preset models from config files, using hardcoded defaults. Error: {}",
|
LOG_WARN("Failed to load preset models from config files, using hardcoded defaults. Error: {}",
|
||||||
PresetModelConfigParser::Get().GetLastError().toStdString());
|
PresetModelConfigParser::Get().GetLastError().toStdString());
|
||||||
LoadDefaultModels();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PresetModelPanel::CreateDynamicUI()
|
||||||
|
{
|
||||||
|
// Clear any existing dynamic UI
|
||||||
|
ClearDynamicUI();
|
||||||
|
|
||||||
|
// Get all category names from configuration
|
||||||
|
QStringList categoryNames = PresetModelConfigParser::Get().GetCategoryNames();
|
||||||
|
|
||||||
|
if (categoryNames.isEmpty()) {
|
||||||
|
LOG_WARN("No categories found in configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create UI for each category
|
||||||
|
for (const QString& categoryName : categoryNames) {
|
||||||
|
ModelCategory category = PresetModelConfigParser::Get().GetCategory(categoryName);
|
||||||
|
|
||||||
|
// Create page widget
|
||||||
|
QWidget* page = new QWidget();
|
||||||
|
page->setObjectName(QString("%1Page").arg(categoryName.toLower()));
|
||||||
|
|
||||||
|
// Create layout for the page
|
||||||
|
QVBoxLayout* layout = new QVBoxLayout(page);
|
||||||
|
layout->setSpacing(0);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
|
// Create list widget
|
||||||
|
PresetModelListWidget* listWidget = new PresetModelListWidget(page);
|
||||||
|
listWidget->setObjectName(QString("%1List").arg(categoryName.toLower()));
|
||||||
|
listWidget->setDragDropMode(QAbstractItemView::DragOnly);
|
||||||
|
listWidget->setDefaultDropAction(Qt::CopyAction);
|
||||||
|
|
||||||
|
// Add list widget to layout
|
||||||
|
layout->addWidget(listWidget);
|
||||||
|
|
||||||
|
// Add page to toolbox with display name
|
||||||
|
QString displayName = category.displayName.isEmpty() ? categoryName : category.displayName;
|
||||||
|
ui->PresetModelToolBox->addItem(page, displayName);
|
||||||
|
|
||||||
|
// Store references for later use
|
||||||
|
categoryWidgets_[categoryName] = listWidget;
|
||||||
|
categoryPages_[categoryName] = page;
|
||||||
|
|
||||||
|
LOG_INFO("Created dynamic UI for category: {}", categoryName.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set first page as current if available
|
||||||
|
if (ui->PresetModelToolBox->count() > 0) {
|
||||||
|
ui->PresetModelToolBox->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresetModelPanel::LoadModelsFromConfig() {
|
void PresetModelPanel::LoadModelsFromConfig() {
|
||||||
// Load ship models
|
// Load models for each dynamically created category
|
||||||
ModelCategory shipCategory = PresetModelConfigParser::Get().GetCategory("Ship");
|
QStringList categoryNames = PresetModelConfigParser::Get().GetCategoryNames();
|
||||||
if (!shipCategory.models.isEmpty()) {
|
|
||||||
ui->shipList->setModelType("Ship");
|
|
||||||
ui->shipList->setModelList(shipCategory.models);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load satellite models
|
for (const QString& categoryName : categoryNames) {
|
||||||
ModelCategory satelliteCategory = PresetModelConfigParser::Get().GetCategory("Satellite");
|
ModelCategory category = PresetModelConfigParser::Get().GetCategory(categoryName);
|
||||||
if (!satelliteCategory.models.isEmpty()) {
|
|
||||||
ui->satelliteList->setModelType("Satellite");
|
if (!category.models.isEmpty() && categoryWidgets_.contains(categoryName)) {
|
||||||
ui->satelliteList->setModelList(satelliteCategory.models);
|
PresetModelListWidget* listWidget = categoryWidgets_[categoryName];
|
||||||
}
|
listWidget->setModelType(categoryName);
|
||||||
|
listWidget->setModelList(category.models);
|
||||||
// Load missile models
|
|
||||||
ModelCategory missileCategory = PresetModelConfigParser::Get().GetCategory("Missile");
|
LOG_INFO("Loaded {} models for category: {}",
|
||||||
if (!missileCategory.models.isEmpty()) {
|
category.models.size(), categoryName.toStdString());
|
||||||
ui->missileList->setModelType("Missile");
|
}
|
||||||
ui->missileList->setModelList(missileCategory.models);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load jammer models
|
|
||||||
ModelCategory jammerCategory = PresetModelConfigParser::Get().GetCategory("Jammer");
|
|
||||||
if (!jammerCategory.models.isEmpty()) {
|
|
||||||
ui->jammerList->setModelType("Jammer");
|
|
||||||
ui->jammerList->setModelList(jammerCategory.models);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresetModelPanel::LoadDefaultModels() {
|
void PresetModelPanel::ClearDynamicUI()
|
||||||
// Use hardcoded default models as fallback mechanism
|
{
|
||||||
QVector<ModelInfo> shipModels = {
|
// Clear all dynamic UI elements
|
||||||
{"destroyer", "Destroyer", "Naval destroyer vessel", "", ":/icons/ship.png", true},
|
categoryWidgets_.clear();
|
||||||
{"aircraft_carrier", "Aircraft Carrier", "Large naval vessel", "", ":/icons/ship.png", true},
|
categoryPages_.clear();
|
||||||
{"frigate", "Frigate", "Fast naval vessel", "", ":/icons/ship.png", true},
|
|
||||||
{"submarine", "Submarine", "Underwater vessel", "", ":/icons/ship.png", true}
|
|
||||||
};
|
|
||||||
ui->shipList->setModelType("Ship");
|
|
||||||
ui->shipList->setModelList(shipModels);
|
|
||||||
|
|
||||||
QVector<ModelInfo> satelliteModels = {
|
// Remove all pages from toolbox
|
||||||
{"comm_satellite", "Communication Satellite", "Communication satellite", "", ":/icons/satellite.png", true},
|
while (ui->PresetModelToolBox->count() > 0) {
|
||||||
{"weather_satellite", "Weather Satellite", "Weather monitoring satellite", "", ":/icons/satellite.png", true},
|
QWidget* widget = ui->PresetModelToolBox->widget(0);
|
||||||
{"gps_satellite", "GPS Satellite", "GPS navigation satellite", "", ":/icons/satellite.png", true},
|
ui->PresetModelToolBox->removeItem(0);
|
||||||
{"spy_satellite", "Spy Satellite", "Reconnaissance satellite", "", ":/icons/satellite.png", true}
|
if (widget) {
|
||||||
};
|
widget->deleteLater();
|
||||||
ui->satelliteList->setModelType("Satellite");
|
}
|
||||||
ui->satelliteList->setModelList(satelliteModels);
|
}
|
||||||
|
|
||||||
QVector<ModelInfo> missileModels = {
|
|
||||||
{"cruise_missile", "Cruise Missile", "Long-range cruise missile", "", ":/icons/missile.png", true},
|
|
||||||
{"ballistic_missile", "Ballistic Missile", "Ballistic missile", "", ":/icons/missile.png", true},
|
|
||||||
{"anti_ship_missile", "Anti-Ship Missile", "Anti-ship missile", "", ":/icons/missile.png", true},
|
|
||||||
{"sam_missile", "Surface-to-Air Missile", "Surface-to-air missile", "", ":/icons/missile.png", true}
|
|
||||||
};
|
|
||||||
ui->missileList->setModelType("Missile");
|
|
||||||
ui->missileList->setModelList(missileModels);
|
|
||||||
|
|
||||||
QVector<ModelInfo> jammerModels = {
|
|
||||||
{"electronic_jammer", "Electronic Jammer", "Electronic warfare jammer", "", ":/icons/jammer.png", true},
|
|
||||||
{"comm_jammer", "Communication Jammer", "Communication jammer", "", ":/icons/jammer.png", true},
|
|
||||||
{"radar_jammer", "Radar Jammer", "Radar jamming device", "", ":/icons/jammer.png", true},
|
|
||||||
{"gps_jammer", "GPS Jammer", "GPS jamming device", "", ":/icons/jammer.png", true}
|
|
||||||
};
|
|
||||||
ui->jammerList->setModelType("Jammer");
|
|
||||||
ui->jammerList->setModelList(jammerModels);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,9 +14,10 @@
|
|||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
#include "workspace/ModelInfo.h"
|
#include "workspace/ModelInfo.h"
|
||||||
#include "workspace/PresetModelConfigParser.h"
|
#include "ui/ModelBrowser/PresetModelListWidget.h"
|
||||||
|
|
||||||
namespace Ui { class PresetModelPanel; }
|
namespace Ui { class PresetModelPanel; }
|
||||||
|
|
||||||
@ -26,11 +27,8 @@ class DockWidget;
|
|||||||
/**
|
/**
|
||||||
* @brief Preset model panel class
|
* @brief Preset model panel class
|
||||||
*
|
*
|
||||||
* Provides preset 3D models for users to drag into the 3D scene, including:
|
* Provides preset 3D models for users to drag into the 3D scene.
|
||||||
* - Ships: Destroyer, Aircraft Carrier
|
* Dynamically creates UI based on configuration files, supporting any number of categories.
|
||||||
* - Satellites: Geostationary Satellites
|
|
||||||
* - Missiles: Hypersonic Missiles
|
|
||||||
* - Jammers: Passive Jammers, Active Jammers
|
|
||||||
*/
|
*/
|
||||||
class PresetModelPanel : public QWidget {
|
class PresetModelPanel : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -51,19 +49,28 @@ private:
|
|||||||
*/
|
*/
|
||||||
void InitUI();
|
void InitUI();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create dynamic UI based on configuration
|
||||||
|
*/
|
||||||
|
void CreateDynamicUI();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Load models from configuration file
|
* @brief Load models from configuration file
|
||||||
*/
|
*/
|
||||||
void LoadModelsFromConfig();
|
void LoadModelsFromConfig();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Load default models when config is unavailable
|
* @brief Clear all dynamic UI elements
|
||||||
*/
|
*/
|
||||||
void LoadDefaultModels();
|
void ClearDynamicUI();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::PresetModelPanel *ui;
|
Ui::PresetModelPanel *ui;
|
||||||
|
|
||||||
|
// Dynamic UI management
|
||||||
|
QMap<QString, PresetModelListWidget*> categoryWidgets_;
|
||||||
|
QMap<QString, QWidget*> categoryPages_;
|
||||||
|
|
||||||
// Drag and drop support
|
// Drag and drop support
|
||||||
QPoint dragStartPosition_;
|
QPoint dragStartPosition_;
|
||||||
QListWidget* dragSourceWidget_;
|
QListWidget* dragSourceWidget_;
|
||||||
|
|||||||
@ -32,168 +32,8 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QToolBox" name="PresetModelToolBox">
|
<widget class="QToolBox" name="PresetModelToolBox">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>-1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="shipPage">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>290</width>
|
|
||||||
<height>470</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<attribute name="label">
|
|
||||||
<string>Ships</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="shipLayout">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="PresetModelListWidget" name="shipList">
|
|
||||||
<property name="dragDropMode">
|
|
||||||
<enum>QAbstractItemView::DragOnly</enum>
|
|
||||||
</property>
|
|
||||||
<property name="defaultDropAction">
|
|
||||||
<enum>Qt::CopyAction</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="satellitePage">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>290</width>
|
|
||||||
<height>470</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<attribute name="label">
|
|
||||||
<string>Satellites</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="satelliteLayout">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="PresetModelListWidget" name="satelliteList">
|
|
||||||
<property name="dragDropMode">
|
|
||||||
<enum>QAbstractItemView::DragOnly</enum>
|
|
||||||
</property>
|
|
||||||
<property name="defaultDropAction">
|
|
||||||
<enum>Qt::CopyAction</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="missilePage">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>98</width>
|
|
||||||
<height>73</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<attribute name="label">
|
|
||||||
<string>Missiles</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="missileLayout">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="PresetModelListWidget" name="missileList">
|
|
||||||
<property name="dragDropMode">
|
|
||||||
<enum>QAbstractItemView::DragOnly</enum>
|
|
||||||
</property>
|
|
||||||
<property name="defaultDropAction">
|
|
||||||
<enum>Qt::CopyAction</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="jammerPage">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>98</width>
|
|
||||||
<height>73</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<attribute name="label">
|
|
||||||
<string>Jammers</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="jammerLayout">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="PresetModelListWidget" name="jammerList">
|
|
||||||
<property name="dragDropMode">
|
|
||||||
<enum>QAbstractItemView::DragOnly</enum>
|
|
||||||
</property>
|
|
||||||
<property name="defaultDropAction">
|
|
||||||
<enum>Qt::CopyAction</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
#include "workspace/PresetModelConfigParser.h"
|
#include "workspace/PresetModelConfigParser.h"
|
||||||
|
|
||||||
#include "entities/EntitiesManager.h"
|
#include "entities/EntitiesManager.h"
|
||||||
|
#include "entities/EntityFactory.h"
|
||||||
#include "entities/ComponentFactory.h"
|
#include "entities/ComponentFactory.h"
|
||||||
#include "entities/Entity.h"
|
#include "entities/Entity.h"
|
||||||
#include "entities/Component.h"
|
#include "entities/Component.h"
|
||||||
@ -271,7 +272,14 @@ void OsgWidget::OnPresetModelDropped(const QString& modelType, const QString& mo
|
|||||||
height = 0.0;
|
height = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity* entity = EntitiesManager::Get().CreateEntityWithComponents(modelType, currentWorkSpace);
|
bool success = false;
|
||||||
|
ModelInfo modelInfo = PresetModelConfigParser::Get().GetModelInfo(modelType, modelName, &success);
|
||||||
|
if (!success) {
|
||||||
|
LOG_ERROR("OsgWidget::OnPresetModelDropped - Failed to get model info of type:{} name:{}", modelType.toStdString(), modelName.toStdString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity* entity = EntitiesManager::Get().CreateEntityWithComponents(modelType, modelInfo.meshFile, modelInfo.useLabel, currentWorkSpace);
|
||||||
if (nullptr == entity) {
|
if (nullptr == entity) {
|
||||||
LOG_ERROR("OsgWidget::OnPresetModelDropped - Failed to create entity of type: {}", modelType.toStdString());
|
LOG_ERROR("OsgWidget::OnPresetModelDropped - Failed to create entity of type: {}", modelType.toStdString());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <osgViewer/CompositeViewer>
|
#include <osgViewer/CompositeViewer>
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
* @brief Model information structure
|
* @brief Model information structure
|
||||||
*
|
*
|
||||||
* Contains all information for a single preset model, including name, display name,
|
* Contains all information for a single preset model, including name, display name,
|
||||||
* description, mesh file path, icon path, and enabled status.
|
* description, mesh file path, icon path, enabled status, and entity registration info.
|
||||||
*/
|
*/
|
||||||
struct ModelInfo {
|
struct ModelInfo {
|
||||||
QString name; ///< Model name (unique identifier)
|
QString name; ///< Model name (unique identifier)
|
||||||
@ -15,21 +15,24 @@ struct ModelInfo {
|
|||||||
QString description; ///< Model description
|
QString description; ///< Model description
|
||||||
QString meshFile; ///< 3D mesh file path
|
QString meshFile; ///< 3D mesh file path
|
||||||
QString icon; ///< Icon file path
|
QString icon; ///< Icon file path
|
||||||
|
bool useLabel;
|
||||||
bool enabled; ///< Whether this model is enabled
|
bool enabled; ///< Whether this model is enabled
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default constructor
|
* @brief Default constructor
|
||||||
* Model is enabled by default
|
* Model is enabled by default
|
||||||
*/
|
*/
|
||||||
ModelInfo() : enabled(true) {}
|
ModelInfo() : useLabel(true), enabled(true) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor with parameters
|
* @brief Constructor with parameters
|
||||||
*/
|
*/
|
||||||
ModelInfo(const QString& name, const QString& displayName, const QString& description,
|
ModelInfo(const QString& name, const QString& displayName, const QString& description,
|
||||||
const QString& meshFile, const QString& icon, bool enabled = true)
|
const QString& meshFile, const QString& icon, bool enabled = true,
|
||||||
|
const QString& entityType = "", const QString& entityClass = "",
|
||||||
|
const QStringList& requiredComponents = QStringList())
|
||||||
: name(name), displayName(displayName), description(description),
|
: name(name), displayName(displayName), description(description),
|
||||||
meshFile(meshFile), icon(icon), enabled(enabled) {}
|
meshFile(meshFile), icon(icon), useLabel(true), enabled(enabled) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -105,8 +105,14 @@ bool PresetModelConfigParser::ParseXmlFile(const QString& filePath)
|
|||||||
const char* description = modelElement->Attribute("description");
|
const char* description = modelElement->Attribute("description");
|
||||||
const char* meshFile = modelElement->Attribute("meshFile");
|
const char* meshFile = modelElement->Attribute("meshFile");
|
||||||
const char* modelIcon = modelElement->Attribute("icon");
|
const char* modelIcon = modelElement->Attribute("icon");
|
||||||
|
const char* label = modelElement->Attribute("label");
|
||||||
const char* enabled = modelElement->Attribute("enabled");
|
const char* enabled = modelElement->Attribute("enabled");
|
||||||
|
|
||||||
|
// Entity registration attributes
|
||||||
|
const char* entityType = modelElement->Attribute("entityType");
|
||||||
|
const char* entityClass = modelElement->Attribute("entityClass");
|
||||||
|
const char* requiredComponents = modelElement->Attribute("requiredComponents");
|
||||||
|
|
||||||
if (!modelName) {
|
if (!modelName) {
|
||||||
LOG_WARN("Model element missing name attribute in file: {}", filePath.toStdString());
|
LOG_WARN("Model element missing name attribute in file: {}", filePath.toStdString());
|
||||||
modelElement = modelElement->NextSiblingElement("model");
|
modelElement = modelElement->NextSiblingElement("model");
|
||||||
@ -118,6 +124,7 @@ bool PresetModelConfigParser::ParseXmlFile(const QString& filePath)
|
|||||||
model.description = description ? QString::fromUtf8(description) : "";
|
model.description = description ? QString::fromUtf8(description) : "";
|
||||||
model.meshFile = meshFile ? QString::fromUtf8(meshFile) : "";
|
model.meshFile = meshFile ? QString::fromUtf8(meshFile) : "";
|
||||||
model.icon = modelIcon ? QString::fromUtf8(modelIcon) : "";
|
model.icon = modelIcon ? QString::fromUtf8(modelIcon) : "";
|
||||||
|
model.useLabel = label ? (strcmp(label, "true") == 0) : true;
|
||||||
model.enabled = enabled ? (strcmp(enabled, "true") == 0) : true;
|
model.enabled = enabled ? (strcmp(enabled, "true") == 0) : true;
|
||||||
|
|
||||||
category.models.append(model);
|
category.models.append(model);
|
||||||
|
|||||||
@ -9,5 +9,5 @@
|
|||||||
description="Multi-frequency signal jamming equipment"
|
description="Multi-frequency signal jamming equipment"
|
||||||
meshFile="models/signal_jammer.ive"
|
meshFile="models/signal_jammer.ive"
|
||||||
icon="icons/signal_jammer_icon.png"
|
icon="icons/signal_jammer_icon.png"
|
||||||
enabled="true" />
|
enabled="true"/>
|
||||||
</modelCategory>
|
</modelCategory>
|
||||||
@ -4,10 +4,10 @@
|
|||||||
description="High-speed combat vessel with powerful anti-submarine and air defense capabilities"
|
description="High-speed combat vessel with powerful anti-submarine and air defense capabilities"
|
||||||
meshFile="models/destroyer.ive"
|
meshFile="models/destroyer.ive"
|
||||||
icon="icons/destroyer_icon.png"
|
icon="icons/destroyer_icon.png"
|
||||||
enabled="true" />
|
enabled="true"/>
|
||||||
<model name="Aircraft Carrier" displayName="Aircraft Carrier"
|
<model name="Aircraft Carrier" displayName="Aircraft Carrier"
|
||||||
description="Large aircraft carrier, mobile airfield and command center at sea"
|
description="Large aircraft carrier, mobile airfield and command center at sea"
|
||||||
meshFile="models/carrier.ive"
|
meshFile="models/carrier.ive"
|
||||||
icon="icons/carrier_icon.png"
|
icon="icons/carrier_icon.png"
|
||||||
enabled="true" />
|
enabled="true"/>
|
||||||
</modelCategory>
|
</modelCategory>
|
||||||
Loading…
Reference in New Issue
Block a user