#include "qtworkspaceattribute.h" #include "workspace/WorkSpace.h" #include "workspace/Timestep.h" #include "entities/Entity.h" #include "entities/MeshComponent.h" #include "entities/PathComponent.h" #include "entities/ConeWaveComponent.h" #include "entities/DashedLineComponent.h" #include "entities/EntitiesManager.h" #include "utils/Transform.h" #include "utils/OsgUtils.h" #include "workspace/WorkSpaceManager.h" QWorkspaceAttribute::QWorkspaceAttribute(class WorkSpace* workspace) : workspace_(workspace) { if (workspace_) { filesSeq_ = workspace_->GetFilesSeq(); } } bool QWorkspaceAttribute::operator==(const QWorkspaceAttribute& other) { return workspace_ == other.workspace_ && filesSeq_ == other.filesSeq_; } QWorkspaceAttribute& QWorkspaceAttribute::operator=(const QWorkspaceAttribute& other) { workspace_ = other.workspace_; filesSeq_ = other.filesSeq_; return *this; } void QWorkspaceAttribute::SetName(const QString& name) { if (nullptr == workspace_) { return; } workspace_->SetName(name); } const QString QWorkspaceAttribute::GetName() const { if (nullptr == workspace_) { return ""; } return workspace_->GetName(); } void QWorkspaceAttribute::SetDescription(const QString& desc) { if (nullptr == workspace_) { return; } workspace_->SetDescribe(desc); } const QString QWorkspaceAttribute::GetDescription() const { if (nullptr == workspace_) { return ""; } return workspace_->GetDescribe(); } void QWorkspaceAttribute::SetTimeStep(const QString& timestep) { if (nullptr == workspace_) { return; } Timestep* obj = workspace_->GetTimestep(); if (nullptr == obj) { workspace_->SetTimestepPath(timestep); return; } const QString& path = obj->GetPath(); if (path == timestep) { return; } workspace_->SetTimestepPath(timestep); } const QString QWorkspaceAttribute::GetTimeStep() const { if (nullptr == workspace_) { return ""; } Timestep* timestep = workspace_->GetTimestep(); if (nullptr == timestep) { return ""; } return timestep->GetPath(); } // Deprecated workspace path setters/getters removed void QWorkspaceAttribute::SetCommondFilePath(const QString& path) { if (nullptr == workspace_) { return; } workspace_->SetCommondFilePath(path); } const QString QWorkspaceAttribute::GetCommondFilePath() const { if (nullptr == workspace_) { return ""; } return workspace_->GetCommondFilePath(); } std::vector> QWorkspaceAttribute::GetFileEntries(FileEntryType type) const { if (nullptr == workspace_) { return {}; } return workspace_->GetFileEntries(type); } void QWorkspaceAttribute::SetFileEntryCount(FileEntryType type, int count) { if (nullptr == workspace_) { return; } workspace_->SetFileEntryCount(type, count); } void QWorkspaceAttribute::SetFileEntryPath(FileEntryType type, int index, const QString& path) { if (nullptr == workspace_) { return; } // Get the file entries for this type auto entries = workspace_->GetFileEntries(type); if (index < 0 || index >= static_cast(entries.size())) { return; } // Update the path of the specific entry entries[index]->SetPath(path); // Trigger files changed signal properly workspace_->NotifyFileEntryUpdated(type); } QString QWorkspaceAttribute::GetFileEntryAbsPath(FileEntryType type, int index) const { if (nullptr == workspace_) { return QString(); } return workspace_->GetFileEntryAbsPath(type, index); } QTransformAttribute::QTransformAttribute(class Transform* obj) : object_(obj) { } bool QTransformAttribute::operator!=(const QTransformAttribute& other) { return object_ != other.object_; } void QTransformAttribute::SetLocation(const osg::Vec3& l) { object_->SetLocation(l); } const osg::Vec3 QTransformAttribute::GetLocation() const { if (nullptr == object_) { return osg::Vec3(0.0f, 0.0f, 0.0f); } return object_->GetLocation(); } void QTransformAttribute::SetRotation(const osg::Vec3& r) { object_->SetRotation(r); } const osg::Vec3 QTransformAttribute::GetRotation() const { if (nullptr == object_) { return osg::Vec3(0.0f, 0.0f, 0.0f); } return object_->GetRotation(); } void QTransformAttribute::SetScale(const osg::Vec3& s) { object_->SetScale(s); } const osg::Vec3 QTransformAttribute::GetScale() const { if (nullptr == object_) { return osg::Vec3(1.0f, 1.0f, 1.0f); } return object_->GetScale(); } bool QTransformAttribute::operator==(const QTransformAttribute& other) { return object_ == other.object_; } QTransformAttribute& QTransformAttribute::operator=(const QTransformAttribute& other) { if (this == &other) { return *this; } object_ = other.object_; return *this; } QEntityAttribute::QEntityAttribute(class Entity* entity) : entity_(entity) { if (nullptr == entity) { return; } transform_ = (new QTransformAttribute(entity->GetTransform())); visible_ = entity->IsVisible(); } bool QEntityAttribute::operator==(const QEntityAttribute& other) { return entity_ == other.entity_; } QEntityAttribute& QEntityAttribute::operator=(const QEntityAttribute& other) { entity_ = other.entity_; return *this; } void QEntityAttribute::SetName(const QString& name) { if (nullptr == entity_) { return; } entity_->SetName(name); } const QString QEntityAttribute::GetName() const { if (nullptr == entity_) { return ""; } return entity_->GetName(); } QTransformAttribute QEntityAttribute::GetTransform() const { if (nullptr == transform_) { return QTransformAttribute(); } return *transform_; } void QEntityAttribute::SetVisible(bool v) { visible_ = v; if (nullptr == entity_) { return; } entity_->SetVisible(v); } bool QEntityAttribute::IsVisible() const { return visible_; } QMeshComponentAttribute::QMeshComponentAttribute(class MeshComponent* object) : object_(object) { } void QMeshComponentAttribute::SetMesh(const QString& mesh) { if (nullptr == object_) { return; } if (mesh.toStdString() == object_->GetMesh()) { return; } object_->LoadNode(mesh.toStdString().c_str()); } QString QMeshComponentAttribute::GetMesh() const { if (nullptr == object_) { return ""; } return QString(object_->GetMesh().c_str()); } bool QMeshComponentAttribute::operator==(const QMeshComponentAttribute& other) { return object_ == other.object_; } QMeshComponentAttribute& QMeshComponentAttribute::operator=(const QMeshComponentAttribute& other) { if (this == &other) { return *this; } object_ = other.object_; return *this; } QPathComponentAttribute::QPathComponentAttribute(PathComponent* object) : object_(object) { } void QPathComponentAttribute::SetPath(const QString& path) { if (nullptr == object_) { return; } object_->SetPath(path); } QString QPathComponentAttribute::GetPath() const { if (nullptr == object_) { return ""; } return object_->GetPath(); } bool QPathComponentAttribute::operator==(const QPathComponentAttribute& other) { return object_ == other.object_; } QPathComponentAttribute& QPathComponentAttribute::operator=(const QPathComponentAttribute& other) { if (this == &other) { return *this; } object_ = other.object_; return *this; } QConeWaveComponentAttribute::QConeWaveComponentAttribute(ConeWaveComponent* object) : object_(object) { } void QConeWaveComponentAttribute::SetRadius(float r) { if (nullptr == object_) { return; } if (r == object_->GetRadius()) { return; } object_->SetRadius(r); } float QConeWaveComponentAttribute::GetRadius() const { if (nullptr == object_) { return 10.0f; } return object_->GetRadius(); } void QConeWaveComponentAttribute::SetBaseColor(const QColor& c) { if (nullptr == object_) { return; } osg::Vec4 vColor = object_->GetBaseColor(); QColor color; OsgUtils::Vec4ToQColor(vColor, &color); if (c == color) { return; } OsgUtils::QColorToVec4(c, &vColor); object_->SetBaseColor(vColor); } QColor QConeWaveComponentAttribute::GetBaseColor() const { if (nullptr == object_) { return QColor(); } osg::Vec4 vColor = object_->GetBaseColor(); QColor color; OsgUtils::Vec4ToQColor(vColor, &color); return color; } void QConeWaveComponentAttribute::SetWaveColor(const QColor& c) { if (nullptr == object_) { return; } osg::Vec4 vColor = object_->GetWaveColor(); QColor color; OsgUtils::Vec4ToQColor(vColor, &color); if (c == color) { return; } OsgUtils::QColorToVec4(c, &vColor); object_->SetWaveColor(vColor); } QColor QConeWaveComponentAttribute::GetWaveColor() const { if (nullptr == object_) { return QColor(); } osg::Vec4 vColor = object_->GetWaveColor(); QColor color; OsgUtils::Vec4ToQColor(vColor, &color); return color; } void QConeWaveComponentAttribute::SetRingBrightAlpha(float a) { if (nullptr == object_) { return; } if (a == object_->GetRingBrightAlpha()) { return; } object_->SetRingBrightAlpha(a); } float QConeWaveComponentAttribute::GetRingBrightAlpha() const { if (nullptr == object_) { return 0.5f; } return object_->GetRingBrightAlpha(); } void QConeWaveComponentAttribute::SetRingDarkAlpha(float a) { if (nullptr == object_) { return; } a = std::max(a, 0.0f); a = std::min(a, 1.0f); object_->SetRingDarkAlpha(a); } float QConeWaveComponentAttribute::GetRingDarkAlpha() const { if (nullptr == object_) { return 0.5f; } return object_->GetRingDarkAlpha(); } void QConeWaveComponentAttribute::SetHeight(float h) { if (nullptr == object_) { return; } if (h == object_->GetHeight()) { return; } object_->SetHeight(h); } float QConeWaveComponentAttribute::GetHeight() const { if (nullptr == object_) { return 60.0f; } return object_->GetHeight(); } void QConeWaveComponentAttribute::SetWaveCount(int c) { if (nullptr == object_) { return; } if (c == object_->GetWaveCount()) { return; } object_->SetWaveCount(c); } int QConeWaveComponentAttribute::GetWaveCount() const { if (nullptr == object_) { return 4; } return object_->GetWaveCount(); } void QConeWaveComponentAttribute::SetWaveSpeed(float h) { if (nullptr == object_) { return; } if (h == object_->GetWaveSpeed()) { return; } object_->SetWaveSpeed(h); } float QConeWaveComponentAttribute::GetWaveSpeed() const { if (nullptr == object_) { return 500.0f; } return object_->GetWaveSpeed(); } bool QConeWaveComponentAttribute::operator==(const QConeWaveComponentAttribute& other) { return object_ == other.object_; } QConeWaveComponentAttribute& QConeWaveComponentAttribute::operator=(const QConeWaveComponentAttribute& other) { if (this == &other) { return *this; } object_ = other.object_; return *this; } QDashedLineComponentAttribute::QDashedLineComponentAttribute(class DashedLineComponent* obj) : object_(obj) { if (nullptr == obj) { return; } startEntity_ = QEntityAttribute(obj->GetStartEntityPtr()); endEntity_ = QEntityAttribute(obj->GetEndEntityPtr()); } void QDashedLineComponentAttribute::SetStart(const QString& uuid) { if (nullptr == object_) { return; } startUUid_ = object_->GetStartEntity(); startName_ = object_->GetStartEntityName(); if (uuid == startName_ || uuid == startUUid_) { return; } std::string suuid = uuid.toStdString(); std::string suuid_ = startName_.toStdString(); std::string suuid2 = startUUid_.toStdString(); object_->SetStartEntity(uuid); } void QDashedLineComponentAttribute::SetStart(const QEntityAttribute& start) { startEntity_ = start; } const QEntityAttribute& QDashedLineComponentAttribute::GetStart() const { return startEntity_; } //QString QDashedLineComponentAttribute::GetStart() const { // if (nullptr == object_) { // return ""; // } // // startUUid_ = object_->GetStartEntity(); // startName_ = object_->GetStartEntityName(); // return startName_; //} void QDashedLineComponentAttribute::SetEnd(const QString& uuid) { if (nullptr == object_) { return; } endUUid_ = object_->GetEndEntity(); endName_ = object_->GetEndEntityName(); if (uuid == endUUid_ || uuid == endName_) { return; } object_->SetEndEntity(uuid); } void QDashedLineComponentAttribute::SetEnd(const QEntityAttribute& end) { endEntity_ = end; } //QString QDashedLineComponentAttribute::GetEnd() const { // if (nullptr == object_) { // return ""; // } // endUUid_ = object_->GetEndEntity(); // endName_ = object_->GetEndEntityName(); // return endName_; //} void QDashedLineComponentAttribute::SetRadius(float r) { if (nullptr == object_) { return; } if (r == object_->GetRadius()) { return; } object_->SetRadius(r); } float QDashedLineComponentAttribute::GetRadius() const { if (nullptr == object_) { return 2.0f; } return object_->GetRadius(); } void QDashedLineComponentAttribute::SetColor(const QColor& c) { if (nullptr == object_) { return; } osg::Vec4 vColor = object_->GetBaseColor(); QColor color; OsgUtils::Vec4ToQColor(vColor, &color); if (c == color) { return; } OsgUtils::QColorToVec4(color, &vColor); object_->SetBaseColor(vColor); } QColor QDashedLineComponentAttribute::GetColor() const { if (nullptr == object_) { return QColor(); } osg::Vec4 vColor = object_->GetBaseColor(); QColor color; OsgUtils::Vec4ToQColor(vColor, &color); return color; } bool QDashedLineComponentAttribute::operator==(const QDashedLineComponentAttribute& other) { return object_ == other.object_; } QDashedLineComponentAttribute& QDashedLineComponentAttribute::operator=(const QDashedLineComponentAttribute& other) { if (this == &other) { return *this; } object_ = other.object_; return *this; } // ---- QCurveEntryAttribute ---- QCurveEntryAttribute::QCurveEntryAttribute(FileEntryCurve* entry) : entry_(entry) { } bool QCurveEntryAttribute::operator==(const QCurveEntryAttribute& other) { return entry_ == other.entry_; } QCurveEntryAttribute& QCurveEntryAttribute::operator=(const QCurveEntryAttribute& other) { entry_ = other.entry_; return *this; } void QCurveEntryAttribute::SetName(const QString& name) { if (!entry_) return; entry_->SetName(name); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } QString QCurveEntryAttribute::GetName() const { if (!entry_) return QString(); return entry_->GetName(); } void QCurveEntryAttribute::SetChartType(ChartType type) { if (!entry_) return; entry_->SetChartType(type); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } ChartType QCurveEntryAttribute::GetChartType() const { if (!entry_) return ChartType::Wave; return entry_->GetChartType(); } int QCurveEntryAttribute::GetCurveCount() const { if (!entry_) return 0; return entry_->GetCurveProperties().size(); } void QCurveEntryAttribute::SetCurveCount(int count) { if (!entry_) return; if (count < 0) count = 0; auto props = entry_->GetCurveProperties(); int current = props.size(); if (count == current) return; if (count > current) { // Append default curve properties for (int i = current; i < count; ++i) { FileEntryCurve::CurveProperty cp; cp.name = QString("Curve %1").arg(i + 1); cp.color = QColor(0, 255, 0); cp.data.wave.start = 0; cp.data.wave.stop = 0; entry_->AddCurveProperty(cp); } } else { // Remove surplus from the end for (int i = current - 1; i >= count; --i) { entry_->RemoveCurveProperty(i); } } if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } QString QCurveEntryAttribute::GetCurveName(int index) const { if (!entry_) return QString(); const auto& cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return QString(); return cps.at(index).name; } void QCurveEntryAttribute::SetCurveName(int index, const QString& name) { if (!entry_) return; auto cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return; auto cp = cps.at(index); cp.name = name; // overwrite by remove/add pattern entry_->RemoveCurveProperty(index); entry_->AddCurveProperty(cp); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } QColor QCurveEntryAttribute::GetCurveColor(int index) const { if (!entry_) return QColor(); const auto& cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return QColor(); return cps.at(index).color; } void QCurveEntryAttribute::SetCurveColor(int index, const QColor& color) { if (!entry_) return; auto cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return; auto cp = cps.at(index); cp.color = color; entry_->RemoveCurveProperty(index); entry_->AddCurveProperty(cp); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } int QCurveEntryAttribute::GetWaveStart(int index) const { if (!entry_) return 0; const auto& cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return 0; return cps.at(index).data.wave.start; } void QCurveEntryAttribute::SetWaveStart(int index, int start) { if (!entry_) return; auto cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return; auto cp = cps.at(index); cp.data.wave.start = start; entry_->RemoveCurveProperty(index); entry_->AddCurveProperty(cp); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } int QCurveEntryAttribute::GetWaveStop(int index) const { if (!entry_) return 0; const auto& cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return 0; return cps.at(index).data.wave.stop; } void QCurveEntryAttribute::SetWaveStop(int index, int stop) { if (!entry_) return; auto cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return; auto cp = cps.at(index); cp.data.wave.stop = stop; entry_->RemoveCurveProperty(index); entry_->AddCurveProperty(cp); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } double QCurveEntryAttribute::GetReportX(int index) const { if (!entry_) return 0.0; const auto& cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return 0.0; return cps.at(index).data.report.x; } void QCurveEntryAttribute::SetReportX(int index, double x) { if (!entry_) return; auto cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return; auto cp = cps.at(index); cp.data.report.x = x; entry_->RemoveCurveProperty(index); entry_->AddCurveProperty(cp); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } } double QCurveEntryAttribute::GetReportY(int index) const { if (!entry_) return 0.0; const auto& cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return 0.0; return cps.at(index).data.report.y; } void QCurveEntryAttribute::SetReportY(int index, double y) { if (!entry_) return; auto cps = entry_->GetCurveProperties(); if (index < 0 || index >= cps.size()) return; auto cp = cps.at(index); cp.data.report.y = y; entry_->RemoveCurveProperty(index); entry_->AddCurveProperty(cp); if (auto ws = WorkSpaceManager::Get().GetCurrent()) { ws->NotifyFileEntryUpdated(FileEntryType::Curve); } }