一、Lane 的内聚性(上一轮建议 5,本轮完成)
- 新增 struct LanePanelState { bool open = true; double x = -1.0; double y = -1.0; };
- Lane 的 12 个平铺面板字段(edgePanelOpen/X/Y 等 × 4 类实验性功能)
→ 4 个聚合成员 edgePanel / edgeCenterPanel / meanFilterPanel / weakPeakPanel;
- 访问点全部改为 lane.edgePanel.open 形式(DataModelTab.cpp 快照拷贝、
PlotViewInteraction.cpp 面板拖拽、PlotViewPaint.cpp 面板层序绘制);
- RebuildLanes 内部的 LaneCarry 同步收敛为 4 个 LanePanelState,
12 行逐字段赋值简化为 4 行整体赋值。
- 教训:批量改名不能对“声明”和“使用”跑同一组替换对,
否则声明行会变成 `bool edgePanel.open = true;` 这类非法代码。
二、错误提示与模态阻塞解耦(上一轮建议 1,本轮完成)
- Application 新增 SetModalErrorsEnabled(bool) / ModalErrorsEnabled(),
成员 m_modalErrorsEnabled 默认 true(交互场景行为不变);
- Initialize 最先执行 SetModalErrorsEnabled(showCommand != SW_HIDE):
隐藏窗口(自动化/离屏)下没人能点掉模态框,等于把进程钉死;
- SetStatusMessage(text, isError=true):允许模态时原样 MessageBoxW,
否则改走非模态通道 m_plot.ShowPersistentHint(text)(绘图区底部浮层);
普通提示与空文本依旧被忽略;
- PlotView 新增公开接口 ShowPersistentHint(text)(内部转 SetHintSticky),
不向宿主暴露粘滞/淡出等内部细节。
三、顺带修掉一个真实缺陷
- PlotView::Paint 在 m_lanes.empty() 时提前 return,而提示浮层在其后的
叠加层绘制 ⇒ 一个信号都没勾选时任何错误都显示不出来,恰恰是
“文件加载失败”最需要提示的场景;该分支补一次 PaintHint(g)。
四、验证(全部离屏:SW_HIDE + 不注入输入 + BELOW_NORMAL)
- make release / make debug:通过,零警告;Build/Release/Target.exe = 764416 B;
- verify 49/49、datacheck 69/69、edgecheck 46/46、panelanim 156/156;
- 新增探针 .preflight/perf/errcheck 19/19:默认值 / 隐藏窗口自动降级 / 宿主显式开关;
工作线程 + 5s 超时判定“不阻塞”(旧行为会永久阻塞,判失败并 ExitProcess,
探针不会挂住);EnumWindows 统计本进程 #32770 顶层窗口数量前后不变;
错误文本进入 m_hintText / m_hintSticky / HintNeedsAnimation / m_hintShownAt;
像素级:有提示帧与无提示帧在绘图区内的差异像素 3781,且全帧差异同为 3781
(证明差异只来自提示)。
五、文档
- Documents/agent_mem.md:§9.37 新增第八节(本轮补齐)、第九节(仅剩 MF4 项)、
§11.2 新增第 93–95 条硬约束、变更日志新增一行;
- Documents/refactor_report_2026-10-16.md:§7.3 / §7.4 标记完成,新增 §九 收尾补记
(含 9.1–9.5:聚合化、解耦、探针、验证结果、变更清单)。
337 lines
11 KiB
C++
337 lines
11 KiB
C++
#ifndef __DATAMODEL_INTERNAL_HPP__
|
||
#define __DATAMODEL_INTERNAL_HPP__
|
||
|
||
// DataModel 组件内部共享的常量与工具函数(私有头,仅本组件的 .cpp 使用)。
|
||
//
|
||
// 本组件的实现按功能拆成多个协作文件,它们共用这一份内部工具集。
|
||
//
|
||
// ⚠️ 为让多个翻译单元都能使用,原匿名命名空间改为**具名**命名空间 `dmdetail`,
|
||
// 并把其中每个函数与常量标为 `inline` —— 单一定义、单一副本,不会产生代码重复。
|
||
// 各实现文件在包含本头之后用 `using namespace dmdetail;` 引入这些工具,
|
||
// 因此函数体里原有的非限定调用一行都不用改。
|
||
|
||
#include <windows.h>
|
||
#include <objidl.h>
|
||
#include <gdiplus.h>
|
||
|
||
#include <algorithm>
|
||
#include <atomic>
|
||
#include <cmath>
|
||
#include <cstdio>
|
||
#include <cstdint>
|
||
#include <cstdlib>
|
||
#include <cstring>
|
||
#include <cwctype>
|
||
#include <deque>
|
||
#include <limits>
|
||
#include <new>
|
||
#include <string>
|
||
#include <utility>
|
||
#include <vector>
|
||
|
||
#include "DataModel.hpp"
|
||
#include "Theme.hpp"
|
||
#include "Utf8Util.hpp"
|
||
|
||
namespace jdi
|
||
{
|
||
|
||
namespace dmdetail
|
||
{
|
||
/**
|
||
* @brief DataModel 内部工具集(常量与自由函数)。
|
||
*
|
||
* 全部符号都是 `inline` ⇒ 多个翻译单元共用同一个定义:既不重复符号,也不产生多份代码。
|
||
* 不要把它们移回匿名命名空间(那样每个 .cpp 都会各自复制一份)。
|
||
*/
|
||
inline const double kMissing = std::numeric_limits<double>::quiet_NaN(); /**< 缺失值占位。 */
|
||
inline const double kDefaultLineWidth = 1.6; /**< 默认线宽。 */
|
||
|
||
/**
|
||
* @brief 为网格范围补充留白,避免波形紧贴边界。
|
||
*
|
||
* ⚠️ 实际规则实现在 `DataModel.hpp` 的 `PadValueRange()`:它同时被
|
||
* 「选区 Y 轴自适应」使用,两处必须逐位一致(否则两种自适应会算出不同区间)。
|
||
*
|
||
* @param [IN, OUT] yMin 范围下限。
|
||
* @param [IN, OUT] yMax 范围上限。
|
||
*/
|
||
inline void PadRange(double& yMin, double& yMax)
|
||
{
|
||
PadValueRange(yMin, yMax);
|
||
}
|
||
|
||
/**
|
||
* @brief 依据全部可见信号重新生成网格划分。
|
||
* @param [IN] visible 各信号的可见性(按 [分组][信号] 索引)。
|
||
* @param [IN] lanes 网格集合(原地更新)。
|
||
* @param [IN] mode 网格划分策略。
|
||
*/
|
||
inline void RebuildLanes(const std::vector<std::vector<bool>>& visible, std::vector<Lane>& lanes,
|
||
LaneMode mode)
|
||
{
|
||
// 随网格携带的“网格自身状态”(按信号继承):重建网格时不能丢。
|
||
struct LaneCarry
|
||
{
|
||
bool matched = false; /**< 是否找到该信号原本所在的网格(false = 新出现的信号)。 */
|
||
bool fitYToSelection = false;
|
||
bool edgeCount = false;
|
||
double edgeValue = 0.0;
|
||
bool edgeValueValid = false;
|
||
LanePanelState edgePanel;
|
||
bool edgeCenter = false;
|
||
std::vector<Lane::EdgeCenterItem> edgeCenterItems;
|
||
LanePanelState edgeCenterPanel;
|
||
bool meanFilter = false;
|
||
std::vector<Lane::MeanFilterItem> meanFilterItems;
|
||
LanePanelState meanFilterPanel;
|
||
bool weakPeak = false;
|
||
std::vector<Lane::WeakPeakItem> weakPeakItems;
|
||
LanePanelState weakPeakPanel;
|
||
};
|
||
|
||
// 先记下每个信号原来所在网格的网格自身状态:
|
||
// 勾选可见性会重建网格,若不携带,用户刚打开的开关会被悄悄清掉。
|
||
//
|
||
// ⚠️ 同时记下「重建之前是否**每个**网格都开着 `fitYToSelection`」:
|
||
// 那就是「全局 Y 轴自适应」的正式定义。新勾选信号产生的**新网格**必须继承它,
|
||
// 否则全局开关看着是开的、新网格却不按当前视界自适应(用户报告的缺陷)。
|
||
bool previousAllAutoFit = !lanes.empty();
|
||
for (const Lane& lane : lanes)
|
||
{
|
||
if (!lane.fitYToSelection)
|
||
{
|
||
previousAllAutoFit = false;
|
||
break;
|
||
}
|
||
}
|
||
|
||
std::vector<std::pair<SignalRef, LaneCarry>> previousCarry;
|
||
for (const Lane& lane : lanes)
|
||
{
|
||
LaneCarry carry;
|
||
carry.matched = true;
|
||
carry.fitYToSelection = lane.fitYToSelection;
|
||
carry.edgeCount = lane.edgeCount;
|
||
carry.edgeValue = lane.edgeValue;
|
||
carry.edgeValueValid = lane.edgeValueValid;
|
||
carry.edgePanel = lane.edgePanel;
|
||
carry.edgeCenter = lane.edgeCenter;
|
||
carry.edgeCenterItems = lane.edgeCenterItems;
|
||
carry.edgeCenterPanel = lane.edgeCenterPanel;
|
||
carry.meanFilter = lane.meanFilter;
|
||
carry.meanFilterItems = lane.meanFilterItems;
|
||
carry.meanFilterPanel = lane.meanFilterPanel;
|
||
carry.weakPeak = lane.weakPeak;
|
||
carry.weakPeakItems = lane.weakPeakItems;
|
||
carry.weakPeakPanel = lane.weakPeakPanel;
|
||
for (const SignalRef& ref : lane.signals)
|
||
{
|
||
previousCarry.emplace_back(ref, carry);
|
||
}
|
||
}
|
||
const auto inheritedCarry = [&previousCarry](const SignalRef& ref)
|
||
{
|
||
for (const std::pair<SignalRef, LaneCarry>& entry : previousCarry)
|
||
{
|
||
if (entry.first == ref)
|
||
{
|
||
return entry.second;
|
||
}
|
||
}
|
||
return LaneCarry();
|
||
};
|
||
const auto applyCarry = [&inheritedCarry, previousAllAutoFit](Lane& lane, const SignalRef& ref)
|
||
{
|
||
const LaneCarry carry = inheritedCarry(ref);
|
||
// 新出现的信号(之前没有网格):继承「全局 Y 轴自适应」是否开启。
|
||
lane.fitYToSelection = carry.matched ? carry.fitYToSelection : previousAllAutoFit;
|
||
lane.edgeCount = carry.edgeCount;
|
||
lane.edgeValue = carry.edgeValue;
|
||
lane.edgeValueValid = carry.edgeValueValid;
|
||
lane.edgePanel.open = carry.edgePanel.open;
|
||
lane.edgePanel.x = carry.edgePanel.x;
|
||
lane.edgePanel.y = carry.edgePanel.y;
|
||
lane.edgeCenter = carry.edgeCenter;
|
||
lane.edgeCenterItems = carry.edgeCenterItems;
|
||
lane.edgeCenterPanel.open = carry.edgeCenterPanel.open;
|
||
lane.edgeCenterPanel.x = carry.edgeCenterPanel.x;
|
||
lane.edgeCenterPanel.y = carry.edgeCenterPanel.y;
|
||
lane.meanFilter = carry.meanFilter;
|
||
lane.meanFilterItems = carry.meanFilterItems;
|
||
lane.meanFilterPanel.open = carry.meanFilterPanel.open;
|
||
lane.meanFilterPanel.x = carry.meanFilterPanel.x;
|
||
lane.meanFilterPanel.y = carry.meanFilterPanel.y;
|
||
lane.weakPeak = carry.weakPeak;
|
||
lane.weakPeakItems = carry.weakPeakItems;
|
||
lane.weakPeakPanel.open = carry.weakPeakPanel.open;
|
||
lane.weakPeakPanel.x = carry.weakPeakPanel.x;
|
||
lane.weakPeakPanel.y = carry.weakPeakPanel.y;
|
||
};
|
||
|
||
// 收集全部可见信号引用。
|
||
std::vector<SignalRef> visibleRefs;
|
||
for (std::size_t groupIndex = 0; groupIndex < visible.size(); ++groupIndex)
|
||
{
|
||
for (std::size_t signalIndex = 0; signalIndex < visible[groupIndex].size(); ++signalIndex)
|
||
{
|
||
if (visible[groupIndex][signalIndex])
|
||
{
|
||
SignalRef ref;
|
||
ref.groupIndex = static_cast<int>(groupIndex);
|
||
ref.signalIndex = static_cast<int>(signalIndex);
|
||
visibleRefs.push_back(ref);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 判断某引用对应的信号是否可见(越界视为不可见)。
|
||
const auto isVisibleRef = [&visible](const SignalRef& ref)
|
||
{
|
||
if (ref.groupIndex < 0 || static_cast<std::size_t>(ref.groupIndex) >= visible.size())
|
||
{
|
||
return false;
|
||
}
|
||
const std::vector<bool>& fileVisible = visible[static_cast<std::size_t>(ref.groupIndex)];
|
||
if (ref.signalIndex < 0 || static_cast<std::size_t>(ref.signalIndex) >= fileVisible.size())
|
||
{
|
||
return false;
|
||
}
|
||
return fileVisible[static_cast<std::size_t>(ref.signalIndex)];
|
||
};
|
||
|
||
// 某信号当前所属的网格下标(-1 表示尚未分配网格)。
|
||
const auto laneIndexOf = [&lanes](const SignalRef& ref)
|
||
{
|
||
for (std::size_t index = 0; index < lanes.size(); ++index)
|
||
{
|
||
const std::vector<SignalRef>& refs = lanes[index].signals;
|
||
if (std::find(refs.begin(), refs.end(), ref) != refs.end())
|
||
{
|
||
return static_cast<int>(index);
|
||
}
|
||
}
|
||
return -1;
|
||
};
|
||
|
||
if (mode == LaneMode::PER_SIGNAL)
|
||
{
|
||
// 每条可见信号独占一个网格:网格数量严格跟随可见信号数量。
|
||
// **顺序按"原有网格位置"优先**:已经分配过网格的信号保持其相对次序,
|
||
// 新勾选(此前没有网格)的信号统一追加到最下方。
|
||
// 若直接按 visibleRefs(文件/列序)重建,新勾选的信号会按其列序
|
||
// 插到中间,位置看起来"不确定"。
|
||
std::vector<SignalRef> ordered;
|
||
ordered.reserve(visibleRefs.size());
|
||
for (const SignalRef& ref : visibleRefs)
|
||
{
|
||
if (laneIndexOf(ref) >= 0)
|
||
{
|
||
ordered.push_back(ref);
|
||
}
|
||
}
|
||
std::stable_sort(ordered.begin(), ordered.end(),
|
||
[&laneIndexOf](const SignalRef& a, const SignalRef& b)
|
||
{ return laneIndexOf(a) < laneIndexOf(b); });
|
||
for (const SignalRef& ref : visibleRefs)
|
||
{
|
||
if (laneIndexOf(ref) < 0)
|
||
{
|
||
ordered.push_back(ref);
|
||
}
|
||
}
|
||
|
||
lanes.clear();
|
||
lanes.reserve(ordered.size());
|
||
for (const SignalRef& ref : ordered)
|
||
{
|
||
Lane lane;
|
||
lane.autoRange = true;
|
||
applyCarry(lane, ref);
|
||
lane.signals.push_back(ref);
|
||
lanes.push_back(std::move(lane));
|
||
}
|
||
}
|
||
else if (mode == LaneMode::MERGED)
|
||
{
|
||
// 全部可见信号合并到同一网格;无可见信号时不保留空网格。
|
||
bool previousAutoRange = true;
|
||
double previousYMin = -1.0;
|
||
double previousYMax = 1.0;
|
||
if (lanes.size() == 1)
|
||
{
|
||
previousAutoRange = lanes[0].autoRange;
|
||
previousYMin = lanes[0].yMin;
|
||
previousYMax = lanes[0].yMax;
|
||
}
|
||
|
||
lanes.clear();
|
||
if (!visibleRefs.empty())
|
||
{
|
||
Lane lane;
|
||
lane.autoRange = previousAutoRange;
|
||
lane.yMin = previousYMin;
|
||
lane.yMax = previousYMax;
|
||
applyCarry(lane, visibleRefs.front());
|
||
lane.signals = visibleRefs;
|
||
lanes.push_back(std::move(lane));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 自定义划分:仅移除不可见信号与由此产生的空网格,保持用户排布。
|
||
for (Lane& lane : lanes)
|
||
{
|
||
std::vector<SignalRef>& refs = lane.signals;
|
||
refs.erase(std::remove_if(refs.begin(), refs.end(),
|
||
[&isVisibleRef](const SignalRef& ref)
|
||
{ return !isVisibleRef(ref); }),
|
||
refs.end());
|
||
}
|
||
|
||
lanes.erase(std::remove_if(lanes.begin(), lanes.end(),
|
||
[](const Lane& lane) { return lane.signals.empty(); }),
|
||
lanes.end());
|
||
|
||
// 未分配网格的可见信号各自独占一个新网格。
|
||
// 注意:不能把它们塞进已有的第一个网格——那会导致“拖拽合并后新勾选的信号
|
||
// 被悄悄并入合并网格”,用户看不到新增的独立泳道。
|
||
for (const SignalRef& ref : visibleRefs)
|
||
{
|
||
bool placed = false;
|
||
for (const Lane& lane : lanes)
|
||
{
|
||
if (std::find(lane.signals.begin(), lane.signals.end(), ref) != lane.signals.end())
|
||
{
|
||
placed = true;
|
||
break;
|
||
}
|
||
}
|
||
if (placed)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
Lane lane;
|
||
lane.autoRange = true;
|
||
applyCarry(lane, ref);
|
||
lane.signals.push_back(ref);
|
||
lanes.push_back(std::move(lane));
|
||
}
|
||
}
|
||
|
||
// 统一重命名,保证编号连续。
|
||
for (std::size_t index = 0; index < lanes.size(); ++index)
|
||
{
|
||
lanes[index].name = L"网格 " + std::to_wstring(index + 1);
|
||
}
|
||
}
|
||
} // namespace dmdetail
|
||
|
||
using namespace dmdetail;
|
||
|
||
} // namespace jdi
|
||
|
||
#endif // __DATAMODEL_INTERNAL_HPP__
|
||
|