diff --git a/src/ui/Panel/LightPanel.cpp b/src/ui/Panel/LightPanel.cpp index 69b642ae..a7980cde 100644 --- a/src/ui/Panel/LightPanel.cpp +++ b/src/ui/Panel/LightPanel.cpp @@ -5,9 +5,10 @@ #include #include #include +#include LightPanel::LightPanel(int index, const QString& filePath, QWidget* parent) - : DataPanel(index, FileEntryType::Curve, filePath, parent) + : DataPanel(index, FileEntryType::Light, filePath, parent) { LOG_INFO("Created LightPanel {} for file: {}", index, filePath.toStdString()); } @@ -45,10 +46,6 @@ void LightPanel::RefreshPanel() void LightPanel::InitUI() { - QHBoxLayout* mainLayout = new QHBoxLayout(this); - mainLayout->setContentsMargins(0, 0, 0, 0); - //mainLayout->addWidget(m_pTableWidget); - setLayout(mainLayout); } QString LightPanel::GetTypeDisplayName() const @@ -61,19 +58,41 @@ void LightPanel::OnDataPanelUpdated(FileEntryLight* fileEntry) QString strName = fileEntry->GetName(); updateTitle(strName); - //FileEntryTable::ChartProperties propChart = fileEntry->GetChartProperties(); + FileEntryLight::ColorProperties propChart = fileEntry->GetColorProperties(); - //QStringList tableHeader = propChart.headerString.split(',', Qt::SkipEmptyParts); - //SetHeader(tableHeader); + QString openColor = QColorToString(propChart.openColor); + QString closeColor = QColorToString(propChart.closeColor); + updateLampColor(openColor, closeColor); - //QString strFile = fileEntry->GetPath() + "/" + fileEntry->GetFileName(); - //FileEntryTable::TableProperties listCurve = fileEntry->GetTableProperties(); - //updateParseFile(strFile, propChart.timeParam, listCurve); + QString strFile = fileEntry->GetPath() + "/" + fileEntry->GetFileName(); + FileEntryLight::LightProperties listCurve = fileEntry->GetLightProperties(); + updateParseFile(strFile, propChart.timeParam, listCurve); } void LightPanel::OnTimeChanged(double time) { - + if (m_dataLamp.size() > 0) + { + QMap< double, QVariantMap >::const_iterator ite = m_dataLamp.lowerBound(time); + if (ite == m_dataLamp.end()) + { + ite--; + } + + QVariantMap mapData = ite.value(); + for (QVariantMap::Iterator it = mapData.begin(); it != mapData.end(); it++) + { + QString strKey = it.key(); + int nState = it.value().toFloat(); + + SignalLabel* pLampLab = m_mapLamp.value(strKey); + if (pLampLab) + { + QString strStyle = m_lampColor.value(nState); + pLampLab->setStyleSheet(strStyle); + } + } + } } void LightPanel::updateTitle(const QString & title) @@ -83,3 +102,86 @@ void LightPanel::updateTitle(const QString & title) dockWidget_->setWindowTitle(title); } } + +void LightPanel::updateParseFile(const QString & strFile, int nT, FileEntryLight::LightProperties listCurve) +{ + if (strFile.isEmpty()) + { + QMessageBox::information(nullptr, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请检查数据文件路径!")); + return; + } + + QFile file(strFile); + if (file.open(QIODevice::ReadOnly)) + { + /*QGridLayout* pMainLyt = new QGridLayout(this); + for (int nI = 0; nI < listCurve.size(); nI++) + { + QVariantMap mapCurve = listCurve.at(nI).toMap(); + QString strName = mapCurve.value("Name").toString(); + QStringList lamps = strName.split(","); + + for (auto i = 0; i < lamps.size(); ++i) + { + SignalLabel* pLampLab = new SignalLabel; + pLampLab->setFixedSize(24, 24); + + QString strStyle = m_lampColor.value(0); + pLampLab->setStyleSheet(strStyle); + + QLabel* pTextLab = new QLabel; + pTextLab->setText(lamps[i]); + + QHBoxLayout* pLyt = new QHBoxLayout; + pLyt->addWidget(pLampLab); + pLyt->addWidget(pTextLab); + + pMainLyt->addLayout(pLyt, nI, i); + + QString strKey = QString::number(nI) + "-" + QString::number(i); + m_mapLamp.insert(strKey, pLampLab); + } + } + + while (!file.atEnd()) + { + QString strLine = file.readLine().simplified(); + if (!strLine.isEmpty()) + { + QStringList listLine = strLine.split(" "); + double t = listLine.at(nT).toDouble(); + + QVariantMap mapData; + for (int nI = 0; nI < listCurve.size(); nI++) + { + QVariantMap mapCurve = listCurve.at(nI).toMap(); + QString strData = mapCurve.value("Data").toString(); + QStringList lamps = strData.split(","); + + for (int nJ = 0; nJ < lamps.size(); ++nJ) + { + int nIndex = lamps.at(nJ).toInt(); + QString nState = listLine.at(nIndex); + QString strKey = QString::number(nI) + "-" + QString::number(nJ); + mapData.insert(strKey, nState); + } + } + m_dataLamp.insert(t, mapData); + } + }*/ + + file.close(); + } +} + +void LightPanel::updateLampColor(const QString & strOpenColor, const QString & strCloseColor) +{ + { + QString strStyle = "QLabel{background-color: rgb(" + strCloseColor + ");border-radius: 10px;}; "; + m_lampColor.insert(0, strStyle); + } + { + QString strStyle = "QLabel{background-color: rgb(" + strOpenColor + ");border-radius: 10px;}; "; + m_lampColor.insert(1, strStyle); + } +} \ No newline at end of file diff --git a/src/ui/Panel/LightPanel.h b/src/ui/Panel/LightPanel.h index 1748d564..e0102228 100644 --- a/src/ui/Panel/LightPanel.h +++ b/src/ui/Panel/LightPanel.h @@ -3,6 +3,8 @@ #include "DataPanel.h" #include "workspace/FileEntry.h" #include +#include "ui/Layout/SignalLabel.h" +#include class LightPanel : public DataPanel { @@ -59,5 +61,12 @@ protected: private: void updateTitle(const QString& title); + void updateParseFile(const QString& strFile, int nT, FileEntryLight::LightProperties listCurve); + void updateLampColor(const QString& strOpenColor, const QString& strCloseColor); + +private: + QMap m_lampColor; + QMap m_mapLamp; + QMap< double, QVariantMap > m_dataLamp; }; diff --git a/src/ui/Panel/SurfacePanel.cpp b/src/ui/Panel/SurfacePanel.cpp index cde15ecd..0f9bc92a 100644 --- a/src/ui/Panel/SurfacePanel.cpp +++ b/src/ui/Panel/SurfacePanel.cpp @@ -8,7 +8,7 @@ #include SurfacePanel::SurfacePanel(int index, const QString& filePath, QWidget* parent) - : DataPanel(index, FileEntryType::Curve, filePath, parent) + : DataPanel(index, FileEntryType::Surface, filePath, parent) { m_iMinX = 0; m_iMaxX = 0; m_iMinY = 0; m_iMaxY = 0; diff --git a/src/ui/Panel/TablePanel.cpp b/src/ui/Panel/TablePanel.cpp index bb7a9a2e..99beb1f3 100644 --- a/src/ui/Panel/TablePanel.cpp +++ b/src/ui/Panel/TablePanel.cpp @@ -8,7 +8,7 @@ #include TablePanel::TablePanel(int index, const QString& filePath, QWidget* parent) - : DataPanel(index, FileEntryType::Curve, filePath, parent) + : DataPanel(index, FileEntryType::Table, filePath, parent) { LOG_INFO("Created TablePanel {} for file: {}", index, filePath.toStdString()); } diff --git a/src/workspace/FileEntry.cpp b/src/workspace/FileEntry.cpp index 850599e9..02db6bb7 100644 --- a/src/workspace/FileEntry.cpp +++ b/src/workspace/FileEntry.cpp @@ -545,4 +545,54 @@ bool FileEntryCurve::ParseFiles(const tinyxml2::XMLElement* chartElement) { } return true; -} \ No newline at end of file +} + +bool FileEntryLight::SaveFiles(tinyxml2::XMLElement * scene, tinyxml2::XMLDocument * doc) +{ + return false; +} + +bool FileEntryLight::ParseFiles(const tinyxml2::XMLElement * element) +{ + if (!element) { + LOG_ERROR("Invalid XML element"); + return false; + } + + // 瑙f瀽chart灞炴 + const char* nameAttr = element->Attribute("name"); + const char* pathAttr = element->Attribute("path"); + if (nameAttr) name_ = QString::fromUtf8(nameAttr); + if (pathAttr) { + QString fullPath = QString::fromUtf8(pathAttr); + QFileInfo fileInfo(fullPath); + fileName_ = fileInfo.fileName(); + path_ = fileInfo.absolutePath(); + } + + const char* openColorAttr = element->Attribute("openColor"); + if (openColorAttr) colorProperties_.openColor = StringToQColor(QString::fromUtf8(openColorAttr)); + + const char* closeColorAttr = element->Attribute("closeColor"); + if (closeColorAttr) colorProperties_.closeColor = StringToQColor(QString::fromUtf8(closeColorAttr)); + + colorProperties_.timeParam = element->DoubleAttribute("t", 0.0); + + // 瑙f瀽鎵鏈鍏冪礌 + lightProperties_.clear(); + for (const tinyxml2::XMLElement* curveElement = element->FirstChildElement("curve"); + curveElement != nullptr; + curveElement = curveElement->NextSiblingElement("curve")) { + + LightProperty light; + + const char* curveNameAttr = curveElement->Attribute("name"); + const char* dataAttr = curveElement->Attribute("data"); + //if (curveNameAttr) light.names = QString::fromUtf8(curveNameAttr); + //if (dataAttr) light.datas = QString::fromUtf8(dataAttr); + + lightProperties_.append(light); + } + + return true; +} diff --git a/src/workspace/FileEntry.h b/src/workspace/FileEntry.h index 4125b279..112f31cf 100644 --- a/src/workspace/FileEntry.h +++ b/src/workspace/FileEntry.h @@ -86,6 +86,9 @@ protected: QString name_; }; +QString QColorToString(const QColor& color); +QColor StringToQColor(const QString& colorStr); + // Factory functions for creating FileEntry objects std::shared_ptr CreateFileEntry(FileEntryType type, const QString& filePath); std::shared_ptr CreateFileEntryCurve(const QString& filePath); @@ -262,11 +265,13 @@ public: struct ColorProperties { QColor openColor; QColor closeColor; + double timeParam; }; struct LightProperty { QString name; - int index; + int indexRow; + int indexColumn; }; using LightProperties = QList; @@ -283,6 +288,10 @@ public: FileEntryLight* AsLight() override { return this; } + // XML澶勭悊鏂规硶 + bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override; + bool ParseFiles(const tinyxml2::XMLElement* element) override; + private: ColorProperties colorProperties_; LightProperties lightProperties_;