更新代码
This commit is contained in:
@@ -409,7 +409,6 @@ class BCLCalcItemContext(BCLPrevContext):
|
||||
result = BCLVariant(item.get_value(value_name))
|
||||
else:
|
||||
result = BCLVariant("")
|
||||
|
||||
elif prefix_name == self._data_name or prefix_name == "curnode":
|
||||
result = BCLVariant(self._data_source[self._index - 1].get_value(parts[1]))
|
||||
elif (
|
||||
@@ -417,6 +416,8 @@ class BCLCalcItemContext(BCLPrevContext):
|
||||
and prefix_name == self._data_source[self._index - 1].get_parent().get_dataname()
|
||||
):
|
||||
result = BCLVariant(self._data_source[self._index - 1].get_parent().get_value(parts[1]))
|
||||
else:
|
||||
result = super()._get_variable_value(var_name)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@@ -1167,12 +1168,22 @@ class BCLCalculator:
|
||||
self.register_function("getparam", getparam_func)
|
||||
self.register_function("strFind", strfind_func)
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
重置计算器的可变状态,确保跨工程运行时不复用上一次的脚本与表达式。
|
||||
"""
|
||||
# logging.info("[BCLCalculator.reset] 清空已加载状态: expressions/loaded_scripts/last_error")
|
||||
self.expressions.clear()
|
||||
self.loaded_scripts.clear()
|
||||
self.last_error = None
|
||||
|
||||
def __copy__(self):
|
||||
# 创建新实例,复制基本属性
|
||||
new_instance = self.__class__()
|
||||
new_instance.loaded_scripts = self.loaded_scripts # 直接引用
|
||||
new_instance.expressions = self.expressions # 直接引用
|
||||
new_instance.functions = self.functions # 直接引用
|
||||
# 改为独立拷贝,避免实例之间共享状态导致跨工程串扰
|
||||
new_instance.loaded_scripts = list(self.loaded_scripts)
|
||||
new_instance.expressions = dict(self.expressions)
|
||||
new_instance.functions = dict(self.functions)
|
||||
return new_instance
|
||||
|
||||
def load_scripts_dir(self, dir_path: str) -> bool:
|
||||
@@ -1206,6 +1217,13 @@ class BCLCalculator:
|
||||
self.last_error = f"文件'{xml_path}'不存在\n"
|
||||
return False
|
||||
|
||||
# 日志:当前读取的XML路径与文件名,及self的内存地址
|
||||
try:
|
||||
_xml_name = os.path.basename(xml_path)
|
||||
except Exception:
|
||||
_xml_name = "<unknown>"
|
||||
# logging.info(f"[load_script] 正在读取XML | 路径: {xml_path} | 文件名: {_xml_name} | self地址: {hex(id(self))}")
|
||||
|
||||
# 读取并清理XML文件内容
|
||||
import chardet
|
||||
|
||||
@@ -1232,6 +1250,11 @@ class BCLCalculator:
|
||||
relative_path = os.path.relpath(xml_path, start=os.getcwd())
|
||||
self.loaded_scripts.append(relative_path)
|
||||
|
||||
# 日志:累计已加载的XML数量
|
||||
# logging.info(
|
||||
# f"[load_script] 已记录XML脚本 | 当前累计数量: {len(self.loaded_scripts)} | 最近一次: {relative_path}"
|
||||
# )
|
||||
|
||||
# 验证根节点 - 兼容BclDocument作为根节点或在Document-DataDefs下
|
||||
if root.tag == "Document":
|
||||
data_defs = root.find("DataDefs")
|
||||
|
||||
Reference in New Issue
Block a user