合并35kg
This commit is contained in:
68
CU/drop.py
68
CU/drop.py
@ -8,7 +8,7 @@ import Constant
|
||||
|
||||
|
||||
class DropPositionManager:
|
||||
def __init__(self, config_path=Constant.dropLine_set_file):
|
||||
def __init__(self, config_path):
|
||||
self.config_path = config_path
|
||||
self.config = configparser.ConfigParser()
|
||||
self._load_config()
|
||||
@ -167,11 +167,14 @@ class DropPositionManager:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
#region 前端UI编辑码垛点位调用方法
|
||||
def load_path_points(self,lineid: int) ->Optional[LineModel]:
|
||||
"""根据lineid加载所有码垛的路径信息"""
|
||||
#默认码垛的lineid从10开始
|
||||
_lineid=lineid+10
|
||||
if self.config_path==Constant.dropLine_set_file_35:
|
||||
_lineid=lineid+11
|
||||
else:
|
||||
_lineid=lineid+10
|
||||
line_model = LineModel(_lineid)
|
||||
line_model.line_category = 2
|
||||
line_model.id = _lineid
|
||||
@ -255,10 +258,13 @@ class DropPositionManager:
|
||||
def save_path_points(self, line_model: LineModel):
|
||||
"""根据lineid保存所有码垛的路径信息"""
|
||||
#默认码垛的lineid从10开始,保存的时候减一
|
||||
_lineid=line_model.id-10
|
||||
if self.config_path==Constant.dropLine_set_file_35:
|
||||
_lineid=line_model.id-11
|
||||
else:
|
||||
_lineid=line_model.id-10
|
||||
if _lineid<=0:
|
||||
return
|
||||
self.config.read(Constant.dropLine_set_file, encoding='utf-8')
|
||||
self.config.read(self.config_path, encoding='utf-8')
|
||||
# 查找主表 DropLineX
|
||||
main_section = f"{Constant.dropLine_set_section}{_lineid}"
|
||||
if not self.config.has_section(main_section):
|
||||
@ -267,7 +273,7 @@ class DropPositionManager:
|
||||
self.config.set(main_section, "id", str(_lineid))
|
||||
_current_reset_index=1
|
||||
_current_mid_index=1
|
||||
_current_drop_section_val=self._current_drop_section[main_section]
|
||||
_current_drop_section_val=self._get_max_drop_section()
|
||||
# 保存每个DropPoints
|
||||
for i, pos in enumerate(line_model.positions):
|
||||
if pos.lineId == _lineid or pos.lineId == line_model.id:
|
||||
@ -300,49 +306,25 @@ class DropPositionManager:
|
||||
#保存数据
|
||||
pos.save_position_model(self.config)
|
||||
|
||||
with open(Constant.dropLine_set_file, 'w', encoding='utf-8') as f:
|
||||
with open(self.config_path, 'w', encoding='utf-8') as f:
|
||||
self.config.write(f)
|
||||
|
||||
def del_drop_point(self,section):
|
||||
self.config.read(Constant.dropLine_set_file, encoding = 'utf-8')
|
||||
self.config.read(self.config_path, encoding = 'utf-8')
|
||||
self.config.remove_section(section)
|
||||
with open(Constant.dropLine_set_file, 'w', encoding='utf-8') as f:
|
||||
with open(self.config_path, 'w', encoding='utf-8') as f:
|
||||
self.config.write(f)
|
||||
|
||||
def _get_point_debug_info(manager, pos, model):
|
||||
config = manager.config
|
||||
for sec in config.sections():
|
||||
if sec.startswith("DropPoints"):
|
||||
try:
|
||||
x, y, z = config.getfloat(sec, "x"), config.getfloat(sec, "y"), config.getfloat(sec, "z")
|
||||
if abs(x - pos.X) < 0.001 and abs(y - pos.Y) < 0.001 and abs(z - pos.Z) < 0.001:
|
||||
point_id = config.getint(sec, "id")
|
||||
return f"📌 DropPoints{point_id} | id={point_id}"
|
||||
except: pass
|
||||
|
||||
elif sec.startswith("DropMidPoint"):
|
||||
try:
|
||||
parts = sec.split('-')
|
||||
if len(parts) != 2: continue
|
||||
point_id = int(''.join(filter(str.isdigit, parts[0])))
|
||||
level = int(parts[1])
|
||||
x, y, z = config.getfloat(sec, "x"), config.getfloat(sec, "y"), config.getfloat(sec, "z")
|
||||
if abs(x - pos.X) < 0.001 and abs(y - pos.Y) < 0.001 and abs(z - pos.Z) < 0.001:
|
||||
return f"📍 DropMidPoint{point_id}-{level} | id={point_id}, level={level}"
|
||||
except: pass
|
||||
|
||||
elif sec.startswith("ResetPoint"):
|
||||
try:
|
||||
parts = sec.split('-')
|
||||
if len(parts) != 2: continue
|
||||
point_id = int(''.join(filter(str.isdigit, parts[0])))
|
||||
level = int(parts[1])
|
||||
x, y, z = config.getfloat(sec, "x"), config.getfloat(sec, "y"), config.getfloat(sec, "z")
|
||||
if abs(x - pos.X) < 0.001 and abs(y - pos.Y) < 0.001 and abs(z - pos.Z) < 0.001:
|
||||
return f"🔙 ResetPoint{point_id}-{level} | id={point_id}, level={level}"
|
||||
except: pass
|
||||
return "❓ 未知点位"
|
||||
|
||||
def _get_max_drop_section(self):
|
||||
"""获取最大的DropPoints序号"""
|
||||
max_section = 1
|
||||
for section in self.config.sections():
|
||||
if section.startswith("DropPoints"):
|
||||
num_part = int(section.replace("DropPoints", "0"))
|
||||
if num_part > max_section:
|
||||
max_section = num_part
|
||||
return max_section
|
||||
#endregion
|
||||
# 测试
|
||||
if __name__ == "__main__":
|
||||
# manager = DropPositionManager("drop.ini")
|
||||
|
||||
Reference in New Issue
Block a user