relevante Datei für 2D Library Erzeugung
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="1e3" height="1e3" fill-rule="evenodd" stroke-linecap="square" stroke-linejoin="round" version="1.1" viewBox="0 0 1e3 1e3" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="#ffe31b" stroke-linecap="square" stroke-miterlimit="0" stroke-width="3.7795">
|
||||
<svg width="1e3" height="1e3" fill-rule="evenodd" stroke-linecap="square" stroke-linejoin="round" version="1.1"
|
||||
viewBox="0 0 1e3 1e3" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
|
||||
<g fill="none" stroke="#ffe31b" stroke-linecap="square" stroke-miterlimit="0" stroke-width="3.7795">
|
||||
|
||||
|
||||
|
||||
<path d="m1.8898 1.8898v62.471" style="paint-order:fill markers stroke"/><path d="m1.8898 33.125h200.42c202.78 3e-6 397.25 80.552 540.63 223.94 143.38 143.38 223.94 337.85 223.94 540.63v200.42" style="paint-order:fill markers stroke"/><path d="m935.64 998.11h62.471" style="paint-order:fill markers stroke"/></g></svg>
|
||||
<path d="m1.8898 1.8898v62.471" style="paint-order:fill markers stroke" />
|
||||
<path
|
||||
d="m1.8898 33.125h200.42c202.78 3e-6 397.25 80.552 540.63 223.94 143.38 143.38 223.94 337.85 223.94 540.63v200.42"
|
||||
style="paint-order:fill markers stroke" />
|
||||
<path d="m935.64 998.11h62.471" style="paint-order:fill markers stroke" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 719 B |
@@ -0,0 +1,2 @@
|
||||
call setenv.bat
|
||||
start
|
||||
@@ -9,7 +9,7 @@ set RD_CONF_LIB=%RD_CONF%\lib
|
||||
|
||||
set RD_CONF_BOGEN=%RD_CONF%\Bogen
|
||||
set RD_CONF_TEFBOGEN=%RD_CONF%\TEFBogen
|
||||
set RD_CONF_WEICHEN=%RD_CONF%\Weichen
|
||||
set RD_CONF_WEICHEN=%RD_CONF%\Weichen\neu_backup
|
||||
set RD_CONF_TEFWEICHEN=%RD_CONF%\TEFWeichen
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
# Vorgehen Erzeugung 2D Library
|
||||
|
||||
für die Umsetzung der 2D-Library im Rule Designer sind folgende Schritte vorgesehen – unterteilt in TXT und SVG:
|
||||
|
||||
**TXT-Daten:**
|
||||
1. JSON-Struktur vorbereiten: inkl. Gesamtbreite, Gesamthöhe sowie Breite und Höhe der Mittellinie.
|
||||
2. CPs (Connection Points): Richtung und Position der CPs berechnen.
|
||||
3. Daten aus JSON in der lokalen RD-Installation als Props importieren.
|
||||
|
||||
**SVG-Daten:**
|
||||
1. DWG-Dateien exportieren und in SVG umwandeln.
|
||||
2. SVG optimieren: z. B. Polylinien in einfache Linien umwandeln.
|
||||
3. Viewbox im SVG definieren, um saubere Skalierung zu gewährleisten.
|
||||
4. Aus dem SVG Symbol generieren.
|
||||
@@ -375,7 +375,7 @@ def optimize_svg(input_path, output_path):
|
||||
elem.set('stroke', '#ffe31b')
|
||||
elif stroke == '#000' or stroke == 'rgb(255,0,0)'or stroke == 'rgb(0,0,0)':
|
||||
elem.set('stroke', '#ffe31b')
|
||||
elem.set('stroke-width', '1')
|
||||
elem.set('stroke-width', f'{1}px')
|
||||
|
||||
# Generate final XML
|
||||
rough_string = ET.tostring(root, encoding='utf-8', xml_declaration=True)
|
||||
|
||||
@@ -4,8 +4,7 @@ import xml.etree.ElementTree as ET
|
||||
from typing import Tuple, List
|
||||
|
||||
def parse_svg_path(d: str) -> List[Tuple[float, float]]:
|
||||
"""Extract all coordinates from SVG path data (assumes all units are converted to px)"""
|
||||
d = re.sub(r'(?<=\d)(mm|pt|cm|in|px)\b', '', d)
|
||||
"""Extract all coordinates from SVG path data (including curve control points)"""
|
||||
points = []
|
||||
commands = re.findall(
|
||||
r'([MmLlCcQqAaHhVvZz])([^MmLlCcQqAaHhVvZz]*)',
|
||||
@@ -43,11 +42,9 @@ def parse_svg_path(d: str) -> List[Tuple[float, float]]:
|
||||
return points
|
||||
|
||||
def calculate_bounding_box(svg_file: str) -> Tuple[float, float, float, float]:
|
||||
"""Calculate true bounding box of all paths in SVG (assumes all coordinates are in px)"""
|
||||
"""Calculate true bounding box of all paths in SVG"""
|
||||
tree = ET.parse(svg_file)
|
||||
root = tree.getroot()
|
||||
|
||||
|
||||
all_points = []
|
||||
|
||||
for path in root.findall('.//{http://www.w3.org/2000/svg}path'):
|
||||
@@ -64,7 +61,6 @@ def calculate_bounding_box(svg_file: str) -> Tuple[float, float, float, float]:
|
||||
return (x_min, y_min, x_max, y_max)
|
||||
|
||||
|
||||
|
||||
def normalize_stroke_widths2(root, scale):
|
||||
"""Normalize stroke widths to ensure consistent appearance after scaling"""
|
||||
for elem in root.iter():
|
||||
@@ -75,103 +71,65 @@ def normalize_stroke_widths2(root, scale):
|
||||
elem.set('stroke-width', f'{1/scale:.6f}mm')
|
||||
|
||||
def apply_non_scaling_stroke(root):
|
||||
"""Ensure stroke widths don't scale with the SVG"""
|
||||
"""确保所有有描边的元素的描边宽度不随缩放变化"""
|
||||
for elem in root.iter():
|
||||
if 'stroke' in elem.attrib and elem.attrib['stroke'] != 'none':
|
||||
# 强制设置 stroke-width=1(无单位)
|
||||
elem.set('stroke-width', '1')
|
||||
# 确保 vector-effect 生效
|
||||
elem.set('vector-effect', 'non-scaling-stroke')
|
||||
# 递归清理所有<g>的transform
|
||||
def remove_all_transforms(root):
|
||||
for g in root.findall('.//{http://www.w3.org/2000/svg}g'):
|
||||
if 'transform' in g.attrib:
|
||||
del g.attrib['transform']
|
||||
|
||||
def scale_svg_file(input_path: str, output_path: str):
|
||||
# 手动移除ns0前缀(字符串替换)
|
||||
with open(input_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
content = content.replace('ns0:', '').replace(':ns0=', '=')
|
||||
tree = ET.ElementTree(ET.fromstring(content))
|
||||
"""Scale SVG file with consistent stroke widths"""
|
||||
print(f"\nProcessing: {os.path.basename(input_path)}")
|
||||
|
||||
tree = ET.parse(input_path)
|
||||
root = tree.getroot()
|
||||
|
||||
# Calculate bounding box INCLUDING stroke width
|
||||
# Calculate original bounding box
|
||||
x_min, y_min, x_max, y_max = calculate_bounding_box(input_path)
|
||||
width = x_max - x_min
|
||||
height = y_max - y_min
|
||||
print(f"Old dimensions: {width:.3f} × {height:.3f}")
|
||||
# Determine scale factor (larger dimension → 1000px)
|
||||
scale = 1000.0 / max(width, height)
|
||||
print(f"Scale factor: {scale:.6f}")
|
||||
remove_all_transforms(root)
|
||||
|
||||
for path in root.findall('.//{http://www.w3.org/2000/svg}path'):
|
||||
d = path.get('d', '')
|
||||
d = re.sub(r'(?<=\d)(mm|px|cm|in)', '', d) # 匹配 "10mm" → "10"
|
||||
scaled_d = scale_svg_path(d, scale, (-x_min, -y_min))
|
||||
path.set('d', scaled_d)
|
||||
for g in root.findall('.//{http://www.w3.org/2000/svg}g'):
|
||||
if 'transform' in g.attrib:
|
||||
del g.attrib['transform']
|
||||
new_width = round(width * scale,3)
|
||||
new_height = round(height * scale)
|
||||
print(f"Original bounding box: ({x_min:.3f}, {y_min:.3f}) to ({x_max:.3f}, {y_max:.3f})")
|
||||
print(f"Original dimensions: {width:.3f} (w) × {height:.3f} (h)")
|
||||
|
||||
|
||||
# Determine scaling base (larger dimension → 1000px)
|
||||
if width > height:
|
||||
scale = 1000.0 / width
|
||||
new_width = 1000.0
|
||||
new_height = round(height * scale)
|
||||
print(f"Scaling base: Width (larger dimension)")
|
||||
else:
|
||||
scale = 1000.0 / height
|
||||
new_height = 1000.0
|
||||
new_width = round(width * scale,3)
|
||||
print(f"Scaling base: Height (larger dimension)")
|
||||
|
||||
print(f"Scale factor: {scale:.6f}")
|
||||
print(f"New dimensions: {new_width:.3f}px × {new_height:.3f}px")
|
||||
print(f"ViewBox: 0 0 {new_width:.3f} {new_height:.3f}")
|
||||
# apply_non_scaling_stroke(root)
|
||||
# normalize_stroke_widths2(root, scale)
|
||||
# normalize_stroke_widths2(root, scale)
|
||||
apply_non_scaling_stroke(root)
|
||||
#
|
||||
# Update SVG attributes
|
||||
root.set('viewBox', f'0 0 {new_width:.3f} {new_height:.3f}')
|
||||
root.set('width', f'{new_width:.3f}px')
|
||||
root.set('height', f'{new_height:.3f}px')
|
||||
root.set('width', f'{new_width:.3f}')
|
||||
root.set('height', f'{new_height:.3f}')
|
||||
|
||||
# Apply translation and scaling
|
||||
# for g in root.findall('{http://www.w3.org/2000/svg}g'):
|
||||
# transform = g.get('transform', '')
|
||||
# new_transform = f'translate({-x_min*scale},{-y_min*scale}) scale({scale})'
|
||||
# if transform:
|
||||
# new_transform = f'{transform} {new_transform}'
|
||||
# g.set('transform', new_transform)
|
||||
for g in root.findall('{http://www.w3.org/2000/svg}g'):
|
||||
transform = g.get('transform', '')
|
||||
new_transform = f'translate({-x_min*scale},{-y_min*scale}) scale({scale})'
|
||||
if transform:
|
||||
new_transform = f'{transform} {new_transform}'
|
||||
g.set('transform', new_transform)
|
||||
|
||||
# Save modified SVG
|
||||
ET.register_namespace('', 'http://www.w3.org/2000/svg')
|
||||
tree.write(output_path, encoding='utf-8', xml_declaration=True)
|
||||
print(f"Finished processing: {os.path.basename(input_path)}")
|
||||
|
||||
def scale_svg_path(d: str, scale: float, offset: Tuple[float, float]) -> str:
|
||||
d = re.sub(r'(?<=\d)(mm|pt|cm|in|px)\b', '', d)
|
||||
commands = re.findall(
|
||||
r'([MmLlCcQqAaHhVvZz])([^MmLlCcQqAaHhVvZz]*)',
|
||||
d.strip().replace(',', ' ')
|
||||
)
|
||||
scaled_parts = []
|
||||
offset_x, offset_y = offset
|
||||
|
||||
for cmd, args in commands:
|
||||
nums = list(map(float, re.findall(r'[-+]?\d*\.?\d+', args)))
|
||||
scaled_nums = []
|
||||
i= 0
|
||||
while i < len(nums):
|
||||
if cmd in ('A', 'a'): # 圆弧命令特殊处理
|
||||
# rx ry x-axis-rotation large-arc-flag sweep-flag x y
|
||||
scaled_nums.extend([
|
||||
f"{nums[i] * scale:.3f}", # rx
|
||||
f"{nums[i+1] * scale:.3f}", # ry
|
||||
f"{nums[i+2]:.3f}", # x-axis-rotation (不缩放)
|
||||
f"{int(nums[i+3])}", # large-arc-flag
|
||||
f"{int(nums[i+4])}", # sweep-flag
|
||||
f"{(nums[i+5] + (offset_x if cmd == 'a' else 0)) * scale:.3f}", # x
|
||||
f"{(nums[i+6] + (offset_y if cmd == 'a' else 0)) * scale:.3f}" # y
|
||||
])
|
||||
i += 7
|
||||
else: # 其他命令
|
||||
if i % 2 == 0: # x坐标
|
||||
val = (nums[i] + (offset_x if cmd.islower() else 0)) * scale
|
||||
else: # y坐标
|
||||
val = (nums[i] + (offset_y if cmd.islower() else 0)) * scale
|
||||
scaled_nums.append(f"{val:.3f}")
|
||||
i += 1
|
||||
|
||||
scaled_part = cmd + ' '.join(scaled_nums)
|
||||
scaled_parts.append(scaled_part.replace(' -', '-')) # 优化负号格式
|
||||
|
||||
return ' '.join(scaled_parts).replace(' ', ' ')
|
||||
def batch_process_svg(input_dir: str, output_dir: str):
|
||||
"""Batch process SVG files in directory (non-recursive)"""
|
||||
if not os.path.exists(output_dir):
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 350.129,
|
||||
"OFWeiche_center_line_height_mm": 700.123,
|
||||
"Objekte_width_mm": 386.007,
|
||||
"Objekte_width_mm": 418.55,
|
||||
"Objekte_height_mm": 715.001,
|
||||
"OFWeiche_CP1_x_mm": 365.007,
|
||||
"OFWeiche_CP1_y_mm": 355.001,
|
||||
@@ -26,7 +26,7 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 350.129,
|
||||
"OFWeiche_center_line_height_mm": 700.123,
|
||||
"Objekte_width_mm": 386.007,
|
||||
"Objekte_width_mm": 418.55,
|
||||
"Objekte_height_mm": 715.001,
|
||||
"OFWeiche_CP1_x_mm": 365.007,
|
||||
"OFWeiche_CP1_y_mm": 355.001,
|
||||
@@ -64,15 +64,15 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 350.129,
|
||||
"OFWeiche_center_line_height_mm": 700.123,
|
||||
"Objekte_width_mm": 386.007,
|
||||
"Objekte_width_mm": 418.55,
|
||||
"Objekte_height_mm": 715.001,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 355.001,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 715.001,
|
||||
"OFWeiche_CP3_x_mm": 371.129,
|
||||
"OFWeiche_CP3_x_mm": 403.673,
|
||||
"OFWeiche_CP3_y_mm": 14.878
|
||||
},
|
||||
{
|
||||
@@ -83,15 +83,15 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 350.129,
|
||||
"OFWeiche_center_line_height_mm": 700.123,
|
||||
"Objekte_width_mm": 386.007,
|
||||
"Objekte_width_mm": 418.55,
|
||||
"Objekte_height_mm": 715.001,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 355.001,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 715.001,
|
||||
"OFWeiche_CP3_x_mm": 371.129,
|
||||
"OFWeiche_CP3_x_mm": 403.673,
|
||||
"OFWeiche_CP3_y_mm": 14.878
|
||||
},
|
||||
{
|
||||
@@ -121,7 +121,7 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 400,
|
||||
"OFWeiche_center_line_height_mm": 750,
|
||||
"Objekte_width_mm": 435.878,
|
||||
"Objekte_width_mm": 468.421,
|
||||
"Objekte_height_mm": 764.878,
|
||||
"OFWeiche_CP1_x_mm": 414.878,
|
||||
"OFWeiche_CP1_y_mm": 404.878,
|
||||
@@ -140,7 +140,7 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 400,
|
||||
"OFWeiche_center_line_height_mm": 750,
|
||||
"Objekte_width_mm": 435.878,
|
||||
"Objekte_width_mm": 468.421,
|
||||
"Objekte_height_mm": 764.878,
|
||||
"OFWeiche_CP1_x_mm": 414.878,
|
||||
"OFWeiche_CP1_y_mm": 404.878,
|
||||
@@ -178,15 +178,15 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 400,
|
||||
"OFWeiche_center_line_height_mm": 750,
|
||||
"Objekte_width_mm": 435.878,
|
||||
"Objekte_width_mm": 468.421,
|
||||
"Objekte_height_mm": 764.878,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 404.878,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 764.878,
|
||||
"OFWeiche_CP3_x_mm": 421.0,
|
||||
"OFWeiche_CP3_x_mm": 453.544,
|
||||
"OFWeiche_CP3_y_mm": 14.878
|
||||
},
|
||||
{
|
||||
@@ -197,15 +197,15 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 400,
|
||||
"OFWeiche_center_line_height_mm": 750,
|
||||
"Objekte_width_mm": 435.878,
|
||||
"Objekte_width_mm": 468.421,
|
||||
"Objekte_height_mm": 764.878,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 404.878,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 764.878,
|
||||
"OFWeiche_CP3_x_mm": 421.0,
|
||||
"OFWeiche_CP3_x_mm": 453.544,
|
||||
"OFWeiche_CP3_y_mm": 14.878
|
||||
},
|
||||
{
|
||||
@@ -235,7 +235,7 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 500.23,
|
||||
"OFWeiche_center_line_height_mm": 600.197,
|
||||
"Objekte_width_mm": 521.23,
|
||||
"Objekte_width_mm": 553.774,
|
||||
"Objekte_height_mm": 621.237,
|
||||
"OFWeiche_CP1_x_mm": 521.27,
|
||||
"OFWeiche_CP1_y_mm": 261.237,
|
||||
@@ -254,7 +254,7 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 500.23,
|
||||
"OFWeiche_center_line_height_mm": 600.197,
|
||||
"Objekte_width_mm": 521.23,
|
||||
"Objekte_width_mm": 553.774,
|
||||
"Objekte_height_mm": 621.237,
|
||||
"OFWeiche_CP1_x_mm": 521.27,
|
||||
"OFWeiche_CP1_y_mm": 261.237,
|
||||
@@ -292,15 +292,15 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 500.23,
|
||||
"OFWeiche_center_line_height_mm": 600.197,
|
||||
"Objekte_width_mm": 521.23,
|
||||
"Objekte_width_mm": 553.774,
|
||||
"Objekte_height_mm": 621.237,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 261.237,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 621.237,
|
||||
"OFWeiche_CP3_x_mm": 521.23,
|
||||
"OFWeiche_CP3_x_mm": 553.774,
|
||||
"OFWeiche_CP3_y_mm": 21.04
|
||||
},
|
||||
{
|
||||
@@ -311,15 +311,15 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 500.23,
|
||||
"OFWeiche_center_line_height_mm": 600.197,
|
||||
"Objekte_width_mm": 521.23,
|
||||
"Objekte_width_mm": 553.774,
|
||||
"Objekte_height_mm": 621.237,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 261.237,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 621.237,
|
||||
"OFWeiche_CP3_x_mm": 521.23,
|
||||
"OFWeiche_CP3_x_mm": 553.774,
|
||||
"OFWeiche_CP3_y_mm": 21.04
|
||||
},
|
||||
{
|
||||
@@ -349,7 +349,7 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 700.374,
|
||||
"OFWeiche_center_line_height_mm": 700.185,
|
||||
"Objekte_width_mm": 721.374,
|
||||
"Objekte_width_mm": 753.918,
|
||||
"Objekte_height_mm": 721.225,
|
||||
"OFWeiche_CP1_x_mm": 721.414,
|
||||
"OFWeiche_CP1_y_mm": 361.225,
|
||||
@@ -368,7 +368,7 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 700.374,
|
||||
"OFWeiche_center_line_height_mm": 700.185,
|
||||
"Objekte_width_mm": 721.374,
|
||||
"Objekte_width_mm": 753.918,
|
||||
"Objekte_height_mm": 721.225,
|
||||
"OFWeiche_CP1_x_mm": 721.414,
|
||||
"OFWeiche_CP1_y_mm": 361.225,
|
||||
@@ -406,15 +406,15 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 700.374,
|
||||
"OFWeiche_center_line_height_mm": 700.185,
|
||||
"Objekte_width_mm": 721.374,
|
||||
"Objekte_width_mm": 753.918,
|
||||
"Objekte_height_mm": 721.225,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 361.225,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 721.225,
|
||||
"OFWeiche_CP3_x_mm": 721.374,
|
||||
"OFWeiche_CP3_x_mm": 753.918,
|
||||
"OFWeiche_CP3_y_mm": 21.04
|
||||
},
|
||||
{
|
||||
@@ -425,15 +425,15 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 700.374,
|
||||
"OFWeiche_center_line_height_mm": 700.185,
|
||||
"Objekte_width_mm": 721.374,
|
||||
"Objekte_width_mm": 753.918,
|
||||
"Objekte_height_mm": 721.225,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 361.225,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 721.225,
|
||||
"OFWeiche_CP3_x_mm": 721.374,
|
||||
"OFWeiche_CP3_x_mm": 753.918,
|
||||
"OFWeiche_CP3_y_mm": 21.04
|
||||
},
|
||||
{
|
||||
@@ -463,7 +463,7 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 200.007,
|
||||
"OFWeiche_center_line_height_mm": 749.8,
|
||||
"Objekte_width_mm": 242.047,
|
||||
"Objekte_width_mm": 274.591,
|
||||
"Objekte_height_mm": 749.8,
|
||||
"OFWeiche_CP1_x_mm": 200.007,
|
||||
"OFWeiche_CP1_y_mm": 389.8,
|
||||
@@ -482,7 +482,7 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 200.007,
|
||||
"OFWeiche_center_line_height_mm": 749.8,
|
||||
"Objekte_width_mm": 242.047,
|
||||
"Objekte_width_mm": 274.591,
|
||||
"Objekte_height_mm": 749.8,
|
||||
"OFWeiche_CP1_x_mm": 200.007,
|
||||
"OFWeiche_CP1_y_mm": 389.8,
|
||||
@@ -501,15 +501,15 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 200.007,
|
||||
"OFWeiche_center_line_height_mm": 749.8,
|
||||
"Objekte_width_mm": 242.047,
|
||||
"Objekte_width_mm": 274.591,
|
||||
"Objekte_height_mm": 749.8,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 389.8,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 749.8,
|
||||
"OFWeiche_CP3_x_mm": 221.007,
|
||||
"OFWeiche_CP3_x_mm": 253.551,
|
||||
"OFWeiche_CP3_y_mm": 0.0
|
||||
},
|
||||
{
|
||||
@@ -520,15 +520,15 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 200.007,
|
||||
"OFWeiche_center_line_height_mm": 749.8,
|
||||
"Objekte_width_mm": 242.047,
|
||||
"Objekte_width_mm": 274.591,
|
||||
"Objekte_height_mm": 749.8,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 389.8,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 749.8,
|
||||
"OFWeiche_CP3_x_mm": 221.007,
|
||||
"OFWeiche_CP3_x_mm": 253.551,
|
||||
"OFWeiche_CP3_y_mm": 0.0
|
||||
},
|
||||
{
|
||||
@@ -1549,7 +1549,7 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 101.5,
|
||||
"OFWeiche_center_line_height_mm": 360,
|
||||
"Objekte_width_mm": 141.938,
|
||||
"Objekte_width_mm": 174.482,
|
||||
"Objekte_height_mm": 360,
|
||||
"OFWeiche_CP1_x_mm": 109.552,
|
||||
"OFWeiche_CP1_y_mm": 0.0,
|
||||
@@ -1568,15 +1568,15 @@
|
||||
"Schaltungstyp": "M",
|
||||
"OFWeiche_center_line_width_mm": 101.5,
|
||||
"OFWeiche_center_line_height_mm": 360,
|
||||
"Objekte_width_mm": 141.938,
|
||||
"Objekte_width_mm": 174.482,
|
||||
"Objekte_height_mm": 360,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 0.0,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 360,
|
||||
"OFWeiche_CP3_x_mm": 122.5,
|
||||
"OFWeiche_CP3_x_mm": 155.044,
|
||||
"OFWeiche_CP3_y_mm": 8.052
|
||||
},
|
||||
{
|
||||
@@ -1587,7 +1587,7 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 101.5,
|
||||
"OFWeiche_center_line_height_mm": 360,
|
||||
"Objekte_width_mm": 141.938,
|
||||
"Objekte_width_mm": 174.482,
|
||||
"Objekte_height_mm": 360,
|
||||
"OFWeiche_CP1_x_mm": 109.552,
|
||||
"OFWeiche_CP1_y_mm": 0.0,
|
||||
@@ -1606,15 +1606,15 @@
|
||||
"Schaltungstyp": "P",
|
||||
"OFWeiche_center_line_width_mm": 101.5,
|
||||
"OFWeiche_center_line_height_mm": 360,
|
||||
"Objekte_width_mm": 141.938,
|
||||
"Objekte_width_mm": 174.482,
|
||||
"Objekte_height_mm": 360,
|
||||
"OFWeiche_CP1_x_mm": 21.0,
|
||||
"OFWeiche_CP1_x_mm": 53.544,
|
||||
"OFWeiche_CP1_y_mm": 0.0,
|
||||
"KurvenRichtung": 2,
|
||||
"SivasnrTEF": null,
|
||||
"OFWeiche_CP2_x_mm": 21.0,
|
||||
"OFWeiche_CP2_x_mm": 53.544,
|
||||
"OFWeiche_CP2_y_mm": 360,
|
||||
"OFWeiche_CP3_x_mm": 122.5,
|
||||
"OFWeiche_CP3_x_mm": 155.044,
|
||||
"OFWeiche_CP3_y_mm": 8.052
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
|
||||
import json
|
||||
import math
|
||||
|
||||
def modify_json_values(json_file):
|
||||
# 常量定义
|
||||
# Constant definitions
|
||||
WeichenKoerperWidth = 32.5437
|
||||
BogenProfileWidth = 42.080
|
||||
WeichenkProfileWidth = 42.000
|
||||
WeichenGerade = 360.000
|
||||
|
||||
# 读取JSON文件
|
||||
# Read JSON file
|
||||
with open(json_file, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, WeichenGerade)
|
||||
process_einzelweiche_items(data,WeichenKoerperWidth, WeichenkProfileWidth,BogenProfileWidth, WeichenGerade)
|
||||
|
||||
process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade)
|
||||
|
||||
process_dreifachweiche_items(data, WeichenkProfileWidth)
|
||||
# 询问是否保存
|
||||
save_choice = input("\n是否保存所有修改? (直接回车保存,输入n取消): ").lower()
|
||||
# Ask for save confirmation
|
||||
save_choice = input("\nSave all changes? (Press Enter to save, 'n' to cancel): ").lower()
|
||||
if save_choice == 'n':
|
||||
print("所有修改未保存")
|
||||
print("All changes discarded")
|
||||
else:
|
||||
with open(json_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, indent=2, ensure_ascii=False)
|
||||
print("所有修改已保存!")
|
||||
print("All changes saved!")
|
||||
|
||||
def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, WeichenGerade): # 筛选符合条件的项
|
||||
def process_einzelweiche_items(data,WeichenKoerperWidth, WeichenkProfileWidth,BogenProfileWidth, WeichenGerade): # Filter matching items
|
||||
filtered_items = [
|
||||
item for item in data
|
||||
if (item.get("SivasnrTEF") is None and
|
||||
@@ -33,59 +33,59 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
item.get("Schaltungstyp") == "M")
|
||||
]
|
||||
|
||||
print(f"共找到 {len(filtered_items)} 项符合条件的记录")
|
||||
print(f"Found {len(filtered_items)} matching records")
|
||||
print("="*50)
|
||||
|
||||
# 遍历每一项
|
||||
# Process each item
|
||||
for idx, item in enumerate(filtered_items, 1):
|
||||
print(f"\n第 {idx} 项:")
|
||||
print(f"\nItem {idx}:")
|
||||
print(f"Sivasnr: {item['Sivasnr']}")
|
||||
print(f"ProfilTyp: {item['ProfilTyp']}")
|
||||
print(f"Schaltungstyp: {item['Schaltungstyp']}")
|
||||
|
||||
# 处理 OFWeiche_center_line_width_mm
|
||||
# Process OFWeiche_center_line_width_mm
|
||||
current_value = item.get("OFWeiche_center_line_width_mm")
|
||||
print(f"\n当前 OFWeiche_center_line_width_mm: {current_value}")
|
||||
choice = input("是否修改? (y修改,直接回车跳过): ").lower()
|
||||
print(f"\nCurrent OFWeiche_center_line_width_mm: {current_value}")
|
||||
choice = input("Modify? (y to modify, Enter to skip): ").lower()
|
||||
if choice == 'y':
|
||||
new_value = input(f"请输入新值 (当前: {current_value}): ")
|
||||
new_value = input(f"Enter new value (current: {current_value}): ")
|
||||
try:
|
||||
old_value = item["OFWeiche_center_line_width_mm"]
|
||||
item["OFWeiche_center_line_width_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None
|
||||
print(f"值已更新: {old_value} → {item['OFWeiche_center_line_width_mm']}")
|
||||
print(f"Value updated: {old_value} → {item['OFWeiche_center_line_width_mm']}")
|
||||
except ValueError:
|
||||
print("输入无效,保持原值")
|
||||
print("Invalid input, keeping original value")
|
||||
else:
|
||||
print("跳过修改")
|
||||
print("Skipping modification")
|
||||
|
||||
# 处理 OFWeiche_center_line_height_mm
|
||||
# Process OFWeiche_center_line_height_mm
|
||||
current_value = item.get("OFWeiche_center_line_height_mm")
|
||||
print(f"\n当前 OFWeiche_center_line_height_mm: {current_value}")
|
||||
choice = input("是否修改? (y修改,直接回车跳过): ").lower()
|
||||
print(f"\nCurrent OFWeiche_center_line_height_mm: {current_value}")
|
||||
choice = input("Modify? (y to modify, Enter to skip): ").lower()
|
||||
if choice == 'y':
|
||||
new_value = input(f"请输入新值 (当前: {current_value}): ")
|
||||
new_value = input(f"Enter new value (current: {current_value}): ")
|
||||
try:
|
||||
old_value = item["OFWeiche_center_line_height_mm"]
|
||||
item["OFWeiche_center_line_height_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None
|
||||
print(f"值已更新: {old_value} → {item['OFWeiche_center_line_height_mm']}")
|
||||
print(f"Value updated: {old_value} → {item['OFWeiche_center_line_height_mm']}")
|
||||
except ValueError:
|
||||
print("输入无效,保持原值")
|
||||
print("Invalid input, keeping original value")
|
||||
else:
|
||||
print("跳过修改")
|
||||
print("Skipping modification")
|
||||
|
||||
# 计算相关值
|
||||
# Calculate related values
|
||||
if (item["OFWeiche_center_line_width_mm"] is not None and
|
||||
item["OFWeiche_center_line_height_mm"] is not None):
|
||||
|
||||
angle_rad = math.radians(item["KurvenWinkel"])
|
||||
|
||||
# 计算并打印基本值
|
||||
# Calculate and print basic values
|
||||
old_width = item.get("Objekte_width_mm")
|
||||
item["Objekte_width_mm"] = round(
|
||||
item["Objekte_width_mm"] = round(WeichenKoerperWidth+
|
||||
(BogenProfileWidth/2 * math.cos(angle_rad)) +
|
||||
item["OFWeiche_center_line_width_mm"] +
|
||||
WeichenkProfileWidth/2, 3)
|
||||
print(f"\nObjekte_width_mm 计算更新: {old_width} → {item['Objekte_width_mm']}")
|
||||
print(f"\nObjekte_width_mm calculated update: {old_width} → {item['Objekte_width_mm']}")
|
||||
|
||||
old_height = item.get("Objekte_height_mm")
|
||||
if item["KurvenWinkel"] == 22.5:
|
||||
@@ -95,35 +95,35 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
item["Objekte_height_mm"] = round(
|
||||
(BogenProfileWidth/2 * math.sin(angle_rad)) +
|
||||
item["OFWeiche_center_line_height_mm"], 3)
|
||||
print(f"Objekte_height_mm 计算更新: {old_height} → {item['Objekte_height_mm']}")
|
||||
print(f"Objekte_height_mm calculated update: {old_height} → {item['Objekte_height_mm']}")
|
||||
|
||||
# 计算并打印CP点坐标
|
||||
# Calculate and print CP point coordinates
|
||||
old_cp1x = item.get("OFWeiche_CP1_x_mm")
|
||||
item["OFWeiche_CP1_x_mm"] = round(
|
||||
(BogenProfileWidth/2 * math.sin(angle_rad)) +
|
||||
item["OFWeiche_center_line_width_mm"], 3)
|
||||
print(f"OFWeiche_CP1_x_mm 计算更新: {old_cp1x} → {item['OFWeiche_CP1_x_mm']}")
|
||||
print(f"OFWeiche_CP1_x_mm calculated update: {old_cp1x} → {item['OFWeiche_CP1_x_mm']}")
|
||||
|
||||
old_cp1y = item.get("OFWeiche_CP1_y_mm")
|
||||
item["OFWeiche_CP1_y_mm"] = round(
|
||||
item["Objekte_height_mm"] - WeichenGerade, 3)
|
||||
print(f"OFWeiche_CP1_y_mm 计算更新: {old_cp1y} → {item['OFWeiche_CP1_y_mm']}")
|
||||
print(f"OFWeiche_CP1_y_mm calculated update: {old_cp1y} → {item['OFWeiche_CP1_y_mm']}")
|
||||
|
||||
item["OFWeiche_CP2_x_mm"] = round(item["OFWeiche_CP1_x_mm"], 3)
|
||||
print(f"OFWeiche_CP2_x_mm 设置: {item['OFWeiche_CP2_x_mm']}")
|
||||
print(f"OFWeiche_CP2_x_mm set: {item['OFWeiche_CP2_x_mm']}")
|
||||
|
||||
item["OFWeiche_CP2_y_mm"] = round(item["Objekte_height_mm"], 3)
|
||||
print(f"OFWeiche_CP2_y_mm 设置: {item['OFWeiche_CP2_y_mm']}")
|
||||
print(f"OFWeiche_CP2_y_mm set: {item['OFWeiche_CP2_y_mm']}")
|
||||
|
||||
item["OFWeiche_CP3_x_mm"] = round(
|
||||
BogenProfileWidth/2 * math.cos(angle_rad), 3)
|
||||
print(f"OFWeiche_CP3_x_mm 计算更新: {item['OFWeiche_CP3_x_mm']}")
|
||||
print(f"OFWeiche_CP3_x_mm calculated update: {item['OFWeiche_CP3_x_mm']}")
|
||||
|
||||
item["OFWeiche_CP3_y_mm"] = round(
|
||||
BogenProfileWidth/2 * math.sin(angle_rad), 3)
|
||||
print(f"OFWeiche_CP3_y_mm 计算更新: {item['OFWeiche_CP3_y_mm']}")
|
||||
print(f"OFWeiche_CP3_y_mm calculated update: {item['OFWeiche_CP3_y_mm']}")
|
||||
|
||||
# 1. 查找Schaltungstyp为P的相似项(更新所有CP点)
|
||||
# 1. Find similar items with Schaltungstyp=P (update all CP points)
|
||||
current_profil = item["ProfilTyp"]
|
||||
if "S" in current_profil:
|
||||
prefix = current_profil.rsplit(" ", 1)[0]
|
||||
@@ -136,12 +136,12 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
x.get("Schaltungstyp") == "P"]
|
||||
|
||||
if similar_items_p:
|
||||
print(f"\n找到 {len(similar_items_p)} 个Schaltungstyp=P的相似项")
|
||||
print(f"\nFound {len(similar_items_p)} similar items with Schaltungstyp=P")
|
||||
for similar in similar_items_p:
|
||||
print(f"正在更新相似项: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
print(f"Updating similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
|
||||
|
||||
# 更新所有字段包括CP点
|
||||
# Update all fields including CP points
|
||||
fields_to_copy = [
|
||||
"OFWeiche_center_line_width_mm",
|
||||
"OFWeiche_center_line_height_mm",
|
||||
@@ -161,9 +161,9 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
print(f" {field}: {old_val} → {similar[field]}")
|
||||
|
||||
else:
|
||||
print("没有找到Schaltungstyp=P的相似项")
|
||||
print("No similar items with Schaltungstyp=P found")
|
||||
|
||||
# 2. 查找L→R且KurvenRichtung=2的相似项
|
||||
# 2. Find L→R similar items with KurvenRichtung=2
|
||||
if "S" in current_profil and "-L-" in current_profil:
|
||||
r_profil = current_profil.replace("-L-", "-R-")
|
||||
|
||||
@@ -174,11 +174,11 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
x.get("Schaltungstyp") == "M"]
|
||||
|
||||
if similar_items_r:
|
||||
print(f"\n找到 {len(similar_items_r)} 个L→R的相似项(KurvenRichtung=2)")
|
||||
print(f"\nFound {len(similar_items_r)} L→R similar items (KurvenRichtung=2)")
|
||||
for similar in similar_items_r:
|
||||
print(f"正在更新R型相似项: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
print(f"Updating R-type similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
|
||||
# 复制基础值
|
||||
# Copy basic values
|
||||
base_fields = [
|
||||
"OFWeiche_center_line_width_mm",
|
||||
"OFWeiche_center_line_height_mm",
|
||||
@@ -191,33 +191,33 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
similar[field] = item[field]
|
||||
print(f" {field}: {old_val} → {similar[field]}")
|
||||
|
||||
# 计算并打印R型特有的CP点
|
||||
# Calculate and print R-type specific CP points
|
||||
old_cp1x = similar.get("OFWeiche_CP1_x_mm")
|
||||
similar["OFWeiche_CP1_x_mm"] = round(WeichenkProfileWidth/2, 3)
|
||||
print(f" OFWeiche_CP1_x_mm (R型): {old_cp1x} → {similar['OFWeiche_CP1_x_mm']}")
|
||||
similar["OFWeiche_CP1_x_mm"] = round(WeichenKoerperWidth+WeichenkProfileWidth/2, 3)
|
||||
print(f" OFWeiche_CP1_x_mm (R-type): {old_cp1x} → {similar['OFWeiche_CP1_x_mm']}")
|
||||
|
||||
old_cp1y = similar.get("OFWeiche_CP1_y_mm")
|
||||
similar["OFWeiche_CP1_y_mm"] = round(item["Objekte_height_mm"] - WeichenGerade, 3)
|
||||
print(f" OFWeiche_CP1_y_mm (R型): {old_cp1y} → {similar['OFWeiche_CP1_y_mm']}")
|
||||
print(f" OFWeiche_CP1_y_mm (R-type): {old_cp1y} → {similar['OFWeiche_CP1_y_mm']}")
|
||||
|
||||
similar["OFWeiche_CP2_x_mm"] = similar["OFWeiche_CP1_x_mm"]
|
||||
print(f" OFWeiche_CP2_x_mm (R型): 设置为 {similar['OFWeiche_CP2_x_mm']}")
|
||||
print(f" OFWeiche_CP2_x_mm (R-type): Set to {similar['OFWeiche_CP2_x_mm']}")
|
||||
|
||||
old_cp2y = similar.get("OFWeiche_CP2_y_mm")
|
||||
similar["OFWeiche_CP2_y_mm"] = round(item["Objekte_height_mm"], 3)
|
||||
print(f" OFWeiche_CP2_y_mm (R型): {old_cp2y} → {similar['OFWeiche_CP2_y_mm']}")
|
||||
print(f" OFWeiche_CP2_y_mm (R-type): {old_cp2y} → {similar['OFWeiche_CP2_y_mm']}")
|
||||
|
||||
old_cp3x = similar.get("OFWeiche_CP3_x_mm")
|
||||
similar["OFWeiche_CP3_x_mm"] = round(
|
||||
similar["OFWeiche_CP1_x_mm"] + item["OFWeiche_center_line_width_mm"], 3)
|
||||
print(f" OFWeiche_CP3_x_mm (R型): {old_cp3x} → {similar['OFWeiche_CP3_x_mm']}")
|
||||
print(f" OFWeiche_CP3_x_mm (R-type): {old_cp3x} → {similar['OFWeiche_CP3_x_mm']}")
|
||||
|
||||
old_cp3y = similar.get("OFWeiche_CP3_y_mm")
|
||||
similar["OFWeiche_CP3_y_mm"] = round(
|
||||
BogenProfileWidth/2 * math.sin(angle_rad), 3)
|
||||
print(f" OFWeiche_CP3_y_mm (R型): {old_cp3y} → {similar['OFWeiche_CP3_y_mm']}")
|
||||
print(f" OFWeiche_CP3_y_mm (R-type): {old_cp3y} → {similar['OFWeiche_CP3_y_mm']}")
|
||||
|
||||
# 3. 查找该R型项的P型对应项
|
||||
# 3. Find P-type counterparts for this R-type item
|
||||
r_p_profil = r_profil.replace("MIT M", "MIT P")
|
||||
|
||||
similar_items_r_p = [x for x in data
|
||||
@@ -226,9 +226,9 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
x.get("Schaltungstyp") == "P"]
|
||||
|
||||
if similar_items_r_p:
|
||||
print(f"\n找到 {len(similar_items_r_p)} 个R型P型对应项")
|
||||
print(f"\nFound {len(similar_items_r_p)} R-type P-type counterparts")
|
||||
for similar_r_p in similar_items_r_p:
|
||||
print(f"正在更新R型P型对应项: {similar_r_p['ProfilTyp']} (Sivasnr: {similar_r_p['Sivasnr']})")
|
||||
print(f"Updating R-type P-type counterpart: {similar_r_p['ProfilTyp']} (Sivasnr: {similar_r_p['Sivasnr']})")
|
||||
|
||||
fields_to_copy_r_p = [
|
||||
"OFWeiche_center_line_width_mm",
|
||||
@@ -248,112 +248,110 @@ def process_einzelweiche_items(data, WeichenkProfileWidth,BogenProfileWidth, Wei
|
||||
similar_r_p[field] = similar[field]
|
||||
print(f" {field}: {old_val} → {similar_r_p[field]}")
|
||||
|
||||
save_choice = input(f"是否确认更新此项? (直接回车确认,输入n取消): ").lower()
|
||||
save_choice = input(f"Confirm update for this item? (Enter to confirm, 'n' to cancel): ").lower()
|
||||
if save_choice == 'n':
|
||||
print("此项更新已取消")
|
||||
# 恢复原值
|
||||
print("Update for this item cancelled")
|
||||
# Restore original values
|
||||
for field in fields_to_copy_r_p:
|
||||
if field in similar_r_p:
|
||||
similar_r_p[field] = old_val
|
||||
else:
|
||||
print("没有找到R型P型对应项")
|
||||
print("No R-type P-type counterparts found")
|
||||
else:
|
||||
|
||||
print("没有找到L→R的相似项")
|
||||
print("No L→R similar items found")
|
||||
|
||||
def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
# 筛选Doppelweiche类型的项
|
||||
# Filter Doppelweiche type items
|
||||
filtered_items = [
|
||||
|
||||
item for item in data
|
||||
if (item.get("WeichenTyp") == "Doppelweiche" and
|
||||
item.get("Schaltungstyp") == "M" and
|
||||
item.get("SivasnrTEF") is None)
|
||||
]
|
||||
|
||||
print(f"\n\n共找到 {len(filtered_items)} 项Doppelweiche类型记录")
|
||||
print(f"\n\nFound {len(filtered_items)} Doppelweiche type records")
|
||||
print("="*50)
|
||||
|
||||
# 遍历每一项Doppelweiche
|
||||
# Process each Doppelweiche item
|
||||
for idx, item in enumerate(filtered_items, 1):
|
||||
print(f"\n第 {idx} 项Doppelweiche:")
|
||||
print(f"\nDoppelweiche item {idx}:")
|
||||
print(f"Sivasnr: {item['Sivasnr']}")
|
||||
print(f"ProfilTyp: {item['ProfilTyp']}")
|
||||
print(f"Schaltungstyp: {item['Schaltungstyp']}")
|
||||
print(f"KurvenWinkel: {item['KurvenWinkel']}")
|
||||
|
||||
# 处理 OFWeiche_center_line_width_mm
|
||||
# Process OFWeiche_center_line_width_mm
|
||||
current_value = item.get("OFWeiche_center_line_width_mm")
|
||||
print(f"\n当前 OFWeiche_center_line_width_mm: {current_value}")
|
||||
choice = input("是否修改? (y修改,直接回车跳过): ").lower()
|
||||
print(f"\nCurrent OFWeiche_center_line_width_mm: {current_value}")
|
||||
choice = input("Modify? (y to modify, Enter to skip): ").lower()
|
||||
if choice == 'y':
|
||||
new_value = input(f"请输入新值 (当前: {current_value}): ")
|
||||
new_value = input(f"Enter new value (current: {current_value}): ")
|
||||
try:
|
||||
old_value = item["OFWeiche_center_line_width_mm"]
|
||||
item["OFWeiche_center_line_width_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None
|
||||
print(f"值已更新: {old_value} → {item['OFWeiche_center_line_width_mm']}")
|
||||
print(f"Value updated: {old_value} → {item['OFWeiche_center_line_width_mm']}")
|
||||
except ValueError:
|
||||
print("输入无效,保持原值")
|
||||
print("Invalid input, keeping original value")
|
||||
else:
|
||||
print("跳过修改")
|
||||
print("Skipping modification")
|
||||
|
||||
# 处理 OFWeiche_center_line_height_mm
|
||||
# Process OFWeiche_center_line_height_mm
|
||||
current_value = item.get("OFWeiche_center_line_height_mm")
|
||||
print(f"\n当前 OFWeiche_center_line_height_mm: {current_value}")
|
||||
choice = input("是否修改? (y修改,直接回车跳过): ").lower()
|
||||
print(f"\nCurrent OFWeiche_center_line_height_mm: {current_value}")
|
||||
choice = input("Modify? (y to modify, Enter to skip): ").lower()
|
||||
if choice == 'y':
|
||||
new_value = input(f"请输入新值 (当前: {current_value}): ")
|
||||
new_value = input(f"Enter new value (current: {current_value}): ")
|
||||
try:
|
||||
old_value = item["OFWeiche_center_line_height_mm"]
|
||||
item["OFWeiche_center_line_height_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None
|
||||
print(f"值已更新: {old_value} → {item['OFWeiche_center_line_height_mm']}")
|
||||
print(f"Value updated: {old_value} → {item['OFWeiche_center_line_height_mm']}")
|
||||
except ValueError:
|
||||
print("输入无效,保持原值")
|
||||
print("Invalid input, keeping original value")
|
||||
else:
|
||||
print("跳过修改")
|
||||
print("Skipping modification")
|
||||
|
||||
# 计算相关值
|
||||
# Calculate related values
|
||||
if (item["OFWeiche_center_line_width_mm"] is not None and
|
||||
item["OFWeiche_center_line_height_mm"] is not None):
|
||||
|
||||
angle_rad = math.radians(item["KurvenWinkel"])
|
||||
|
||||
# 计算并打印基本值(Doppelweiche特有公式)
|
||||
# Calculate and print basic values (Doppelweiche specific formula)
|
||||
old_width = item.get("Objekte_width_mm")
|
||||
item["Objekte_width_mm"] = round(
|
||||
(BogenProfileWidth/2 * math.cos(angle_rad)) +
|
||||
item["OFWeiche_center_line_width_mm"] +
|
||||
BogenProfileWidth/2 * math.cos(angle_rad), 3)
|
||||
print(f"\nObjekte_width_mm 计算更新: {old_width} → {item['Objekte_width_mm']}")
|
||||
print(f"\nObjekte_width_mm calculated update: {old_width} → {item['Objekte_width_mm']}")
|
||||
|
||||
old_height = item.get("Objekte_height_mm")
|
||||
item["Objekte_height_mm"] = round(
|
||||
(BogenProfileWidth/2 * math.sin(angle_rad)) +
|
||||
item["OFWeiche_center_line_height_mm"], 3)
|
||||
print(f"Objekte_height_mm 计算更新: {old_height} → {item['Objekte_height_mm']}")
|
||||
print(f"Objekte_height_mm calculated update: {old_height} → {item['Objekte_height_mm']}")
|
||||
|
||||
# 计算并打印CP点坐标(Doppelweiche特有公式)
|
||||
# Calculate and print CP point coordinates (Doppelweiche specific formula)
|
||||
item["OFWeiche_CP1_x_mm"] = round(item["Objekte_width_mm"]/2, 3)
|
||||
print(f"OFWeiche_CP1_x_mm 计算更新: {item['OFWeiche_CP1_x_mm']}")
|
||||
print(f"OFWeiche_CP1_x_mm calculated update: {item['OFWeiche_CP1_x_mm']}")
|
||||
|
||||
item["OFWeiche_CP1_y_mm"] = round(item["Objekte_height_mm"], 3)
|
||||
print(f"OFWeiche_CP1_y_mm 计算更新: {item['OFWeiche_CP1_y_mm']}")
|
||||
print(f"OFWeiche_CP1_y_mm calculated update: {item['OFWeiche_CP1_y_mm']}")
|
||||
|
||||
item["OFWeiche_CP2_x_mm"] = round(BogenProfileWidth/2 * math.cos(angle_rad), 3)
|
||||
print(f"OFWeiche_CP2_x_mm 计算更新: {item['OFWeiche_CP2_x_mm']}")
|
||||
print(f"OFWeiche_CP2_x_mm calculated update: {item['OFWeiche_CP2_x_mm']}")
|
||||
|
||||
item["OFWeiche_CP2_y_mm"] = round(BogenProfileWidth/2 * math.sin(angle_rad), 3)
|
||||
print(f"OFWeiche_CP2_y_mm 计算更新: {item['OFWeiche_CP2_y_mm']}")
|
||||
print(f"OFWeiche_CP2_y_mm calculated update: {item['OFWeiche_CP2_y_mm']}")
|
||||
|
||||
item["OFWeiche_CP3_x_mm"] = round(
|
||||
BogenProfileWidth/2 * math.cos(angle_rad) +
|
||||
item["OFWeiche_center_line_width_mm"], 3)
|
||||
print(f"OFWeiche_CP3_x_mm 计算更新: {item['OFWeiche_CP3_x_mm']}")
|
||||
print(f"OFWeiche_CP3_x_mm calculated update: {item['OFWeiche_CP3_x_mm']}")
|
||||
|
||||
item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"]
|
||||
print(f"OFWeiche_CP3_y_mm 设置: {item['OFWeiche_CP3_y_mm']}")
|
||||
print(f"OFWeiche_CP3_y_mm set: {item['OFWeiche_CP3_y_mm']}")
|
||||
|
||||
# 1. 查找类似项1(D型P型)
|
||||
# 1. Find similar items (D-type P-type)
|
||||
current_profil = item["ProfilTyp"]
|
||||
if "S D" in current_profil:
|
||||
d_p_profil = current_profil.replace("MIT M", "MIT P")
|
||||
@@ -363,11 +361,11 @@ def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
x.get("SivasnrTEF") is None]
|
||||
|
||||
if similar_items_d_p:
|
||||
print(f"\n找到 {len(similar_items_d_p)} 个D型P型相似项")
|
||||
print(f"\nFound {len(similar_items_d_p)} D-type P-type similar items")
|
||||
for similar in similar_items_d_p:
|
||||
print(f"正在更新D型P型相似项: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
print(f"Updating D-type P-type similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
|
||||
# 更新所有字段
|
||||
# Update all fields
|
||||
fields_to_copy = [
|
||||
"OFWeiche_center_line_width_mm",
|
||||
"OFWeiche_center_line_height_mm",
|
||||
@@ -386,9 +384,9 @@ def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
similar[field] = item[field]
|
||||
print(f" {field}: {old_val} → {similar[field]}")
|
||||
else:
|
||||
print("没有找到D型P型相似项")
|
||||
print("No D-type P-type similar items found")
|
||||
|
||||
# 2. 查找类似项2(T型M型)
|
||||
# 2. Find similar items (T-type M-type)
|
||||
if "S D" in current_profil:
|
||||
t_m_profil = current_profil.replace("S D", "S T")
|
||||
|
||||
@@ -398,13 +396,13 @@ def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
x.get("Schaltungstyp") == "M"]
|
||||
|
||||
if similar_items_t_m:
|
||||
print(f"\n找到 {len(similar_items_t_m)} 个T型M型相似项")
|
||||
print(f"\nFound {len(similar_items_t_m)} T-type M-type similar items")
|
||||
for similar in similar_items_t_m:
|
||||
print(f"正在更新T型M型相似项: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
print(f"Updating T-type M-type similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
if similar["KurvenWinkel"] == 22.5:
|
||||
print("检测到KurvenWinkel=22.5,采用特殊处理方式")
|
||||
print("Detected KurvenWinkel=22.5, applying special handling")
|
||||
|
||||
# 特殊处理逻辑
|
||||
# Special handling logic
|
||||
similar["OFWeiche_center_line_width_mm"] = item["OFWeiche_center_line_width_mm"]
|
||||
print(f" OFWeiche_center_line_width_mm: → {similar['OFWeiche_center_line_width_mm']}")
|
||||
|
||||
@@ -436,7 +434,7 @@ def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
print(f" OFWeiche_CP3_y_mm: → 20")
|
||||
|
||||
else:
|
||||
# 更新基本字段
|
||||
# Update basic fields
|
||||
base_fields = [
|
||||
"OFWeiche_center_line_width_mm",
|
||||
"OFWeiche_center_line_height_mm",
|
||||
@@ -455,14 +453,14 @@ def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
similar[field] = item[field]
|
||||
print(f" {field}: {old_val} → {similar[field]}")
|
||||
|
||||
# 添加CP4点(T型特有)
|
||||
# Add CP4 point (T-type specific)
|
||||
similar["OFWeiche_CP4_x_mm"] = round(item["Objekte_width_mm"]/2, 3)
|
||||
print(f" OFWeiche_CP4_x_mm 添加: {similar['OFWeiche_CP4_x_mm']}")
|
||||
print(f" OFWeiche_CP4_x_mm added: {similar['OFWeiche_CP4_x_mm']}")
|
||||
|
||||
similar["OFWeiche_CP4_y_mm"] = round(item["Objekte_height_mm"] - WeichenGerade, 3)
|
||||
print(f" OFWeiche_CP4_y_mm 添加: {similar['OFWeiche_CP4_y_mm']}")
|
||||
print(f" OFWeiche_CP4_y_mm added: {similar['OFWeiche_CP4_y_mm']}")
|
||||
|
||||
# 3. 查找T型P型对应项
|
||||
# 3. Find T-type P-type counterparts
|
||||
t_p_profil = t_m_profil.replace("MIT M", "MIT P")
|
||||
|
||||
similar_items_t_p = [x for x in data
|
||||
@@ -471,11 +469,11 @@ def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
x.get("Schaltungstyp") == "P"]
|
||||
|
||||
if similar_items_t_p:
|
||||
print(f"\n找到 {len(similar_items_t_p)} 个T型P型对应项")
|
||||
print(f"\nFound {len(similar_items_t_p)} T-type P-type counterparts")
|
||||
for similar_t_p in similar_items_t_p:
|
||||
print(f"正在更新T型P型对应项: {similar_t_p['ProfilTyp']} (Sivasnr: {similar_t_p['Sivasnr']})")
|
||||
print(f"Updating T-type P-type counterpart: {similar_t_p['ProfilTyp']} (Sivasnr: {similar_t_p['Sivasnr']})")
|
||||
|
||||
# 更新所有字段包括CP4点
|
||||
# Update all fields including CP4 point
|
||||
fields_to_copy_t_p = [
|
||||
"OFWeiche_center_line_width_mm",
|
||||
"OFWeiche_center_line_height_mm",
|
||||
@@ -496,19 +494,19 @@ def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade):
|
||||
similar_t_p[field] = similar[field]
|
||||
print(f" {field}: {old_val} → {similar_t_p[field]}")
|
||||
|
||||
# 添加保存确认提示
|
||||
save_choice = input(f"是否确认更新此项? (直接回车确认,输入n取消): ").lower()
|
||||
# Add save confirmation prompt
|
||||
save_choice = input(f"Confirm update for this item? (Enter to confirm, 'n' to cancel): ").lower()
|
||||
if save_choice == 'n':
|
||||
print("此项更新已取消")
|
||||
# 恢复原值
|
||||
print("Update for this item cancelled")
|
||||
# Restore original values
|
||||
for field in fields_to_copy_t_p:
|
||||
similar_t_p[field] = old_val
|
||||
else:
|
||||
print("没有找到T型P型对应项")
|
||||
print("No T-type P-type counterparts found")
|
||||
else:
|
||||
print("没有找到T型M型相似项")
|
||||
print("No T-type M-type similar items found")
|
||||
def process_dreifachweiche_items(data, WeichenkProfileWidth):
|
||||
# 筛选Dreifachweiche类型的项
|
||||
# Filter Dreifachweiche type items
|
||||
filtered_items = [
|
||||
item for item in data
|
||||
if (item.get("WeichenTyp") == "Dreifachweiche" and
|
||||
@@ -516,52 +514,52 @@ def process_dreifachweiche_items(data, WeichenkProfileWidth):
|
||||
item.get("SivasnrTEF") is None)
|
||||
]
|
||||
|
||||
print(f"\n\n共找到 {len(filtered_items)} 项Dreifachweiche类型记录")
|
||||
print(f"\n\nFound {len(filtered_items)} Dreifachweiche type records")
|
||||
print("="*50)
|
||||
|
||||
for idx, item in enumerate(filtered_items, 1):
|
||||
print(f"\n第 {idx} 项Dreifachweiche:")
|
||||
print(f"\nDreifachweiche item {idx}:")
|
||||
print(f"Sivasnr: {item['Sivasnr']}")
|
||||
print(f"ProfilTyp: {item['ProfilTyp']}")
|
||||
|
||||
# 交互修改OFWeiche_center_line_width_mm
|
||||
# Interactive modification of OFWeiche_center_line_width_mm
|
||||
current_value = item.get("OFWeiche_center_line_width_mm")
|
||||
print(f"\n当前 OFWeiche_center_line_width_mm: {current_value}")
|
||||
choice = input("是否修改? (y修改,直接回车跳过): ").lower()
|
||||
print(f"\nCurrent OFWeiche_center_line_width_mm: {current_value}")
|
||||
choice = input("Modify? (y to modify, Enter to skip): ").lower()
|
||||
if choice == 'y':
|
||||
new_value = input(f"请输入新值 (当前: {current_value}): ")
|
||||
new_value = input(f"Enter new value (current: {current_value}): ")
|
||||
try:
|
||||
old_value = item["OFWeiche_center_line_width_mm"]
|
||||
item["OFWeiche_center_line_width_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None
|
||||
print(f"值已更新: {old_value} → {item['OFWeiche_center_line_width_mm']}")
|
||||
print(f"Value updated: {old_value} → {item['OFWeiche_center_line_width_mm']}")
|
||||
except ValueError:
|
||||
print("输入无效,保持原值")
|
||||
print("Invalid input, keeping original value")
|
||||
|
||||
# 交互修改OFWeiche_center_line_height_mm
|
||||
# Interactive modification of OFWeiche_center_line_height_mm
|
||||
current_value = item.get("OFWeiche_center_line_height_mm")
|
||||
print(f"\n当前 OFWeiche_center_line_height_mm: {current_value}")
|
||||
choice = input("是否修改? (y修改,直接回车跳过): ").lower()
|
||||
print(f"\nCurrent OFWeiche_center_line_height_mm: {current_value}")
|
||||
choice = input("Modify? (y to modify, Enter to skip): ").lower()
|
||||
if choice == 'y':
|
||||
new_value = input(f"请输入新值 (当前: {current_value}): ")
|
||||
new_value = input(f"Enter new value (current: {current_value}): ")
|
||||
try:
|
||||
old_value = item["OFWeiche_center_line_height_mm"]
|
||||
item["OFWeiche_center_line_height_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None
|
||||
print(f"值已更新: {old_value} → {item['OFWeiche_center_line_height_mm']}")
|
||||
print(f"Value updated: {old_value} → {item['OFWeiche_center_line_height_mm']}")
|
||||
except ValueError:
|
||||
print("输入无效,保持原值")
|
||||
print("Invalid input, keeping original value")
|
||||
|
||||
# 计算相关值
|
||||
# Calculate related values
|
||||
if (item["OFWeiche_center_line_width_mm"] is not None and
|
||||
item["OFWeiche_center_line_height_mm"] is not None):
|
||||
|
||||
# 计算基本尺寸
|
||||
# Calculate basic dimensions
|
||||
item["Objekte_width_mm"] = round(item["OFWeiche_center_line_width_mm"], 3)
|
||||
print(f"\nObjekte_width_mm 计算更新: {item['Objekte_width_mm']}")
|
||||
print(f"\nObjekte_width_mm calculated update: {item['Objekte_width_mm']}")
|
||||
|
||||
item["Objekte_height_mm"] = round(WeichenkProfileWidth/2 + item["OFWeiche_center_line_height_mm"], 3)
|
||||
print(f"Objekte_height_mm 计算更新: {item['Objekte_height_mm']}")
|
||||
print(f"Objekte_height_mm calculated update: {item['Objekte_height_mm']}")
|
||||
|
||||
# 计算控制点
|
||||
# Calculate control points
|
||||
item["OFWeiche_CP1_x_mm"] = round(item["Objekte_width_mm"]/2, 3)
|
||||
item["OFWeiche_CP1_y_mm"] = 0
|
||||
item["OFWeiche_CP2_x_mm"] = 0
|
||||
@@ -575,7 +573,7 @@ def process_dreifachweiche_items(data, WeichenkProfileWidth):
|
||||
print(f"OFWeiche_CP3_x_mm: {item['OFWeiche_CP3_x_mm']}")
|
||||
print(f"OFWeiche_CP3_y_mm: {item['OFWeiche_CP3_y_mm']}")
|
||||
|
||||
# 查找相似项(P型)
|
||||
# Find similar items (P-type)
|
||||
if "WEICHE S C DELTA" in item["ProfilTyp"]:
|
||||
similar_profil = item["ProfilTyp"].replace("KPL. M", "KPL. P")
|
||||
|
||||
@@ -584,9 +582,9 @@ def process_dreifachweiche_items(data, WeichenkProfileWidth):
|
||||
x.get("SivasnrTEF") is None]
|
||||
|
||||
if similar_items:
|
||||
print(f"\n找到 {len(similar_items)} 个相似P型项")
|
||||
print(f"\nFound {len(similar_items)} similar P-type items")
|
||||
for similar in similar_items:
|
||||
print(f"\n正在更新: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
print(f"\nUpdating: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})")
|
||||
|
||||
fields_to_copy = [
|
||||
"OFWeiche_center_line_width_mm",
|
||||
@@ -601,22 +599,22 @@ def process_dreifachweiche_items(data, WeichenkProfileWidth):
|
||||
"OFWeiche_CP3_y_mm"
|
||||
]
|
||||
|
||||
print("\n更新中:")
|
||||
print("\nUpdating:")
|
||||
for field in fields_to_copy:
|
||||
print(f" {field}: {similar.get(field)} → {item[field]}")
|
||||
similar[field] = item[field]# 实际更新相似项的值
|
||||
similar[field] = item[field] # Actually update the similar item's value
|
||||
|
||||
choice = input("\n确认更新此项? (回车确认/n取消): ").lower()
|
||||
choice = input("\nConfirm update for this item? (Enter to confirm/n to cancel): ").lower()
|
||||
if choice == 'n':
|
||||
print("取消此项更新")
|
||||
print("Update for this item cancelled")
|
||||
for field in fields_to_copy:
|
||||
similar[field] = similar[field]
|
||||
else:
|
||||
print("此项更新已确认")
|
||||
print("Update for this item confirmed")
|
||||
|
||||
else:
|
||||
print("没有找到相似P型项")
|
||||
print("No similar P-type items found")
|
||||
|
||||
if __name__ == "__main__":
|
||||
json_file_path = "omniflo_weichen.json" # 替换为你的JSON文件路径
|
||||
json_file_path = "omniflo_weichen.json" # Replace with your JSON file path
|
||||
modify_json_values(json_file_path)
|
||||
Reference in New Issue
Block a user