Die Code zur automatischen Erzeungung der SVG für OFWeiche wurde funitoniert.

This commit is contained in:
2025-07-16 15:52:47 +02:00
parent 489eaac2c5
commit 352f6b89be
98 changed files with 1895 additions and 1152 deletions
@@ -1,431 +0,0 @@
import json
import math
import os
def modify_json_values(json_file):
# Constant definitions
WeichenKoerperWidth = 32.5437
BogenProfileWidth = 42.080
WeichenkProfileWidth = 42.000
WeichenGerade = 360.000
# Read JSON file
with open(json_file, 'r', encoding='utf-8') as f:
data = json.load(f)
process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth, BogenProfileWidth, WeichenGerade)
process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade)
process_deltaweiche_items(data, WeichenkProfileWidth)
# Save changes without confirmation
with open(json_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
print("All changes saved automatically!")
def process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth, BogenProfileWidth, WeichenGerade):
# Filter matching items with additional Sivasnr check
filtered_items = [
item for item in data
if (item.get("SivasnrTEF") is None and
item.get("KurvenRichtung") == 1 and
item.get("Schaltungstyp") == "M" and
str(item.get("Sivasnr", "")).isdigit())
]
print(f"Found {len(filtered_items)} matching records with numeric Sivasnr")
# Process each item
for item in filtered_items:
# 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 basic values
item["Objekt_width_mm"] = round(WeichenKoerperWidth +
(BogenProfileWidth/2 * math.cos(angle_rad)) +
item["OFWeiche_center_line_width_mm"] +
WeichenkProfileWidth/2, 3)
if item["KurvenWinkel"] == 22.5:
item["Objekt_height_mm"] = round(
item["OFWeiche_center_line_height_mm"], 3)
else:
item["Objekt_height_mm"] = round(
(BogenProfileWidth/2 * math.sin(angle_rad)) +
item["OFWeiche_center_line_height_mm"], 3)
# Calculate CP point coordinates
item["OFWeiche_CP1_x_mm"] = round(
(BogenProfileWidth/2 * math.cos(angle_rad)) +
item["OFWeiche_center_line_width_mm"], 3)
item["OFWeiche_CP1_y_mm"] = round(
item["Objekt_height_mm"] - WeichenGerade, 3)
item["OFWeiche_CP2_x_mm"] = round(item["OFWeiche_CP1_x_mm"], 3)
item["OFWeiche_CP2_y_mm"] = round(item["Objekt_height_mm"], 3)
item["OFWeiche_CP3_x_mm"] = round(
BogenProfileWidth/2 * math.cos(angle_rad), 3)
item["OFWeiche_CP3_y_mm"] = round(
BogenProfileWidth/2 * math.sin(angle_rad), 3)
# Update items with identical ProfilTyp
current_profil = item["ProfilTyp"]
exact_matches = [x for x in data
if x["ProfilTyp"] == current_profil and
x is not item and
x.get("SivasnrTEF") is None]
if exact_matches:
for match in exact_matches:
fields_to_copy = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in fields_to_copy:
match[field] = item[field]
# Find similar items with Schaltungstyp=P
if "S" in current_profil:
prefix = current_profil.rsplit(" ", 1)[0]
similar_items_p = [x for x in data
if x["ProfilTyp"].startswith(prefix) and
x["ProfilTyp"] != current_profil and
"WEICHE" in x["ProfilTyp"] and
x.get("SivasnrTEF") is None and
x.get("Schaltungstyp") == "P"]
for similar in similar_items_p:
fields_to_copy = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in fields_to_copy:
similar[field] = item[field]
# 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-")
similar_items_r = [x for x in data
if x["ProfilTyp"] == r_profil and
x.get("SivasnrTEF") is None and
x.get("KurvenRichtung") == 2 and
x.get("Schaltungstyp") == "M"]
for similar in similar_items_r:
# Copy basic values
base_fields = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm"
]
for field in base_fields:
similar[field] = item[field]
# Calculate R-type specific CP points
similar["OFWeiche_CP1_x_mm"] = round(WeichenKoerperWidth+WeichenkProfileWidth/2, 3)
similar["OFWeiche_CP1_y_mm"] = round(item["Objekt_height_mm"] - WeichenGerade, 3)
similar["OFWeiche_CP2_x_mm"] = similar["OFWeiche_CP1_x_mm"]
similar["OFWeiche_CP2_y_mm"] = round(item["Objekt_height_mm"], 3)
similar["OFWeiche_CP3_x_mm"] = round(
similar["OFWeiche_CP1_x_mm"] + item["OFWeiche_center_line_width_mm"], 3)
similar["OFWeiche_CP3_y_mm"] = round(
BogenProfileWidth/2 * math.sin(angle_rad), 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
if x["ProfilTyp"] == r_p_profil and
x.get("SivasnrTEF") is None and
x.get("Schaltungstyp") == "P"]
for similar_r_p in similar_items_r_p:
fields_to_copy_r_p = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in fields_to_copy_r_p:
similar_r_p[field] = similar[field]
def process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade):
# Filter Doppelweiche type items with numeric Sivasnr check
filtered_items = [
item for item in data
if (item.get("WeichenTyp") == "Doppelweiche" and
item.get("Schaltungstyp") == "M" and
item.get("SivasnrTEF") is None and
str(item.get("Sivasnr", "")).isdigit())
]
print(f"\nFound {len(filtered_items)} Doppelweiche type records with numeric Sivasnr")
# Process each Doppelweiche item
for item in filtered_items:
# 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 basic values (Doppelweiche specific formula)
item["Objekt_width_mm"] = round(
(BogenProfileWidth/2 * math.cos(angle_rad)) +
item["OFWeiche_center_line_width_mm"] +
BogenProfileWidth/2 * math.cos(angle_rad), 3)
item["Objekt_height_mm"] = round(
(BogenProfileWidth/2 * math.sin(angle_rad)) +
item["OFWeiche_center_line_height_mm"], 3)
# Calculate CP point coordinates (Doppelweiche specific formula)
item["OFWeiche_CP1_x_mm"] = round(item["Objekt_width_mm"]/2, 3)
item["OFWeiche_CP1_y_mm"] = round(item["Objekt_height_mm"], 3)
item["OFWeiche_CP2_x_mm"] = round(BogenProfileWidth/2 * math.cos(angle_rad), 3)
item["OFWeiche_CP2_y_mm"] = round(BogenProfileWidth/2 * math.sin(angle_rad), 3)
item["OFWeiche_CP3_x_mm"] = round(
BogenProfileWidth/2 * math.cos(angle_rad) +
item["OFWeiche_center_line_width_mm"], 3)
item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"]
# Update items with identical ProfilTyp
current_profil = item["ProfilTyp"]
exact_matches = [x for x in data
if x["ProfilTyp"] == current_profil and
x is not item and
x.get("SivasnrTEF") is None]
if exact_matches:
for match in exact_matches:
fields_to_copy = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in fields_to_copy:
match[field] = item[field]
# Find similar items (D-type P-type)
if "S D" in current_profil:
d_p_profil = current_profil.replace("MIT M", "MIT P")
similar_items_d_p = [x for x in data
if x["ProfilTyp"] == d_p_profil and
x.get("SivasnrTEF") is None]
for similar in similar_items_d_p:
fields_to_copy = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in fields_to_copy:
similar[field] = item[field]
# Find similar items (T-type M-type)
if "S D" in current_profil:
t_m_profil = current_profil.replace("S D", "S T")
similar_items_t_m = [x for x in data
if x["ProfilTyp"] == t_m_profil and
x.get("SivasnrTEF") is None and
x.get("Schaltungstyp") == "M"]
for similar in similar_items_t_m:
if similar["KurvenWinkel"] == 22.5:
# Special handling for KurvenWinkel=22.5
similar["OFWeiche_center_line_width_mm"] = item["OFWeiche_center_line_width_mm"]
similar["OFWeiche_center_line_height_mm"] = WeichenGerade
similar["Objekt_width_mm"] = item["Objekt_width_mm"]
similar["Objekt_height_mm"] = WeichenGerade
similar["OFWeiche_CP1_x_mm"] = item["OFWeiche_CP1_x_mm"]
similar["OFWeiche_CP1_y_mm"] = similar["Objekt_height_mm"]
similar["OFWeiche_CP2_x_mm"] = item["OFWeiche_CP2_x_mm"]
similar["OFWeiche_CP2_y_mm"] = 20
similar["OFWeiche_CP3_x_mm"] = item["OFWeiche_CP3_x_mm"]
similar["OFWeiche_CP3_y_mm"] = 20
else:
# Update basic fields
base_fields = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in base_fields:
similar[field] = item[field]
# Add CP4 point (T-type specific)
similar["OFWeiche_CP4_x_mm"] = round(similar["Objekt_width_mm"]/2, 3)
similar["OFWeiche_CP4_y_mm"] = round(similar["Objekt_height_mm"] - WeichenGerade, 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
if x["ProfilTyp"] == t_p_profil and
x.get("SivasnrTEF") is None and
x.get("Schaltungstyp") == "P"]
for similar_t_p in similar_items_t_p:
fields_to_copy_t_p = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm",
"OFWeiche_CP4_x_mm",
"OFWeiche_CP4_y_mm"
]
for field in fields_to_copy_t_p:
similar_t_p[field] = similar[field]
def process_deltaweiche_items(data, WeichenkProfileWidth):
# Filter deltaweiche type items
filtered_items = [
item for item in data
if (item.get("WeichenTyp") == "Dreifachweiche" and
item.get("Schaltungstyp") == "M" and
item.get("SivasnrTEF") is None and
str(item.get("Sivasnr", "")).isdigit())
]
print(f"\nFound {len(filtered_items)} deltaweiche type records")
for item in filtered_items:
# 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["Objekt_width_mm"] = round(item["OFWeiche_center_line_width_mm"], 3)
item["Objekt_height_mm"] = round(WeichenkProfileWidth/2 + item["OFWeiche_center_line_height_mm"]+32.5437, 3)
# Calculate control points
item["OFWeiche_CP1_x_mm"] = round(item["Objekt_width_mm"]/2, 3)
item["OFWeiche_CP1_y_mm"] = 0
item["OFWeiche_CP2_x_mm"] = 0
item["OFWeiche_CP2_y_mm"] = round(item["OFWeiche_center_line_height_mm"], 3)
item["OFWeiche_CP3_x_mm"] = round(item["OFWeiche_center_line_width_mm"], 3)
item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"]
# Update items with identical ProfilTyp
current_profil = item["ProfilTyp"]
exact_matches = [x for x in data
if x["ProfilTyp"] == current_profil and
x is not item and
x.get("SivasnrTEF") is None]
if exact_matches:
for match in exact_matches:
fields_to_copy = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in fields_to_copy:
match[field] = item[field]
# Find similar items (P-type)
if "WEICHE S C DELTA" in item["ProfilTyp"]:
similar_profil = item["ProfilTyp"].replace("KPL. MIT M", "KPL. MIT P")
similar_items = [x for x in data
if x["ProfilTyp"] == similar_profil and
x.get("SivasnrTEF") is None]
for similar in similar_items:
fields_to_copy = [
"OFWeiche_center_line_width_mm",
"OFWeiche_center_line_height_mm",
"Objekt_width_mm",
"Objekt_height_mm",
"OFWeiche_CP1_x_mm",
"OFWeiche_CP1_y_mm",
"OFWeiche_CP2_x_mm",
"OFWeiche_CP2_y_mm",
"OFWeiche_CP3_x_mm",
"OFWeiche_CP3_y_mm"
]
for field in fields_to_copy:
similar[field] = item[field]
if __name__ == "__main__":
json_path = os.environ.get("JSON_PATH", "JSON")
input_filename = os.path.join(json_path, "omniflo_weichen.json")
modify_json_values(input_filename)
@@ -1,135 +0,0 @@
import json
import os
def process_json_file(input_file, output_file):
# 确保输出目录存在
os.makedirs(os.path.dirname(output_file), exist_ok=True)
# 检查输入文件是否存在
if not os.path.exists(input_file):
raise FileNotFoundError(f"输入文件不存在: {input_file}")
# 加载JSON数据
with open(input_file, 'r', encoding='utf-8') as f:
data = json.load(f)
# Process each item in the JSON data
for item in data:
if item.get("SivasnrTEF") is None:
# Step 1: Calculate pixel dimensions
width_mm = item["Objekt_width_mm"]
height_mm = item["Objekt_height_mm"]
# Calculate initial pixel values
item["Objekt_width_px"] = round(width_mm * 3.7795, 3)
item["Objekt_height_px"] = round(height_mm * 3.7795, 3)
# Determine which dimension is larger and calculate scaling factor
if width_mm >= height_mm:
scale = 1000 / width_mm
item["calculated_SVG_width_px"] = 1000.0
item["calculated_SVG_height_px"] = round(height_mm * scale, 3)
scale_RD_H = round(1000 / item["calculated_SVG_height_px"],6)
scale_RD_W = 1
else:
scale = 1000 / height_mm
item["calculated_SVG_width_px"] = round(width_mm * scale, 3)
item["calculated_SVG_height_px"] = 1000.0
scale_RD_W = round(1000 / item["calculated_SVG_width_px"], 6)
scale_RD_H = 1
item["scale_factor"] = round(scale, 6)
item["scale_factor_RD_Width"] = round(scale_RD_W, 6)
item["scale_factor_RD_Height"] = round(scale_RD_H, 6)
# Process connection points
connection_points = []
# CP1
cp1_x = round(item["OFWeiche_CP1_x_mm"] * scale*scale_RD_W, 3)
cp1_y = round(item["OFWeiche_CP1_y_mm"] * scale*scale_RD_H, 3)
# CP2
cp2_x = round(item["OFWeiche_CP2_x_mm"] * scale*scale_RD_W, 3)
cp2_y = round(item["OFWeiche_CP2_y_mm"] * scale*scale_RD_H, 3)
# CP3
cp3_x = round(item["OFWeiche_CP3_x_mm"] * scale*scale_RD_W, 3)
cp3_y = round(item["OFWeiche_CP3_y_mm"] * scale*scale_RD_H, 3)
# Determine directions based on WeichenTyp
weichen_typ = item["WeichenTyp"]
kurven_winkel = item["KurvenWinkel"]
profil_typ = item["ProfilTyp"]
if weichen_typ == "Einzelweiche":
cp1_dir = 0.0
cp2_dir = 180.0
if "-L-" in profil_typ:
cp3_dir = round(360 - kurven_winkel, 1)
elif "--" in profil_typ:
cp3_dir = round(kurven_winkel, 1)
else:
cp3_dir = 0.0 # Default if pattern not found
elif weichen_typ == "Doppelweiche":
cp1_dir = 180.0
cp2_dir = round(360 - kurven_winkel, 1)
cp3_dir = round(kurven_winkel, 1)
elif weichen_typ == "Dreiwegeweiche":
cp1_dir = 180.0
cp2_dir = round(360 - kurven_winkel, 1)
cp3_dir = round(kurven_winkel, 1)
# CP4 exists for Dreiwegeweiche
cp4_x = round(item["OFWeiche_CP4_x_mm"] * scale*scale_RD_W, 3)
cp4_y = round(item["OFWeiche_CP4_y_mm"] * scale*scale_RD_H, 3)
cp4_dir = 90.0
connection_points.append({
"id": "cp4",
"x": cp4_x,
"y": cp4_y,
"direction": cp4_dir
})
elif weichen_typ == "Dreifachweiche":
cp1_dir = 0
cp2_dir = round(360 - kurven_winkel, 1)
cp3_dir = round(kurven_winkel, 1)
# Add common connection points
connection_points.extend([
{
"id": "cp1",
"x": cp1_x,
"y": cp1_y,
"direction": cp1_dir
},
{
"id": "cp2",
"x": cp2_x,
"y": cp2_y,
"direction": cp2_dir
},
{
"id": "cp3",
"x": cp3_x,
"y": cp3_y,
"direction": cp3_dir
}
])
item["connectionPoints"] = connection_points
# Save the processed data
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
if __name__ == "__main__":
json_path = os.environ.get("JSON_PATH", "JSON")
input_filename = os.path.join(json_path, "omniflo_weichen.json")
output_filename = os.path.join(json_path, "omniflo_weichen_output.json")
try:
process_json_file(input_filename, output_filename)
print(f"Process is finished , the File is saved as: {output_filename}")
except Exception as e:
print(f"Errno: {str(e)}")
@@ -1,191 +0,0 @@
''' Script Analysis
This Python script processes JSON and TXT files to update dimensions and connection points in SVG-related data, but only for entries where SivasnrTEF is null. Here's the main logic:
Input Handling:
Reads a JSON file containing reference data
Processes all TXT files in a specified directory
Data Processing:
Creates a mapping between Sivasnr (from filenames) and JSON data (only for entries with SivasnrTEF = null)
For each matching TXT file:
Updates width and height based on JSON data (converting mm to px)
Updates connection points (x, y, direction) from JSON data
Preserves the original file structure while updating specific values
Reporting:
Prints detailed change reports to console
Skips files without matching JSON data or where SivasnrTEF is not null '''
import json
import os
import glob
from datetime import datetime
def process_files(json_file_path, txt_files_dir):
# Create a log file with timestamp
if not os.path.exists(json_file_path):
print(f"Error: JSON file does not exist at {json_file_path}")
exit(1)
if not os.path.exists(txt_files_dir):
print(f"Error: Directory does not exist at {txt_files_dir}")
exit(1)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
log_file_path = os.path.join(txt_files_dir, f"modification_report_OFWeiche_{timestamp}.txt")
# Read JSON file
with open(json_file_path, 'r', encoding='utf-8') as f:
json_data = json.load(f)
# Create Sivasnr to JSON data mapping ONLY for items with SivasnrTEF = null
sivasnr_mapping = {str(item["Sivasnr"]): item for item in json_data if item["SivasnrTEF"] is None}
# Initialize counters
total_files = 0
processed_files = 0
skipped_files = 0
skipped_due_to_tef = 0
# Prepare report content
report_content = []
report_content.append(f"Modification Report - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
report_content.append(f"JSON Reference File: {json_file_path}")
report_content.append(f"TXT Files Directory: {txt_files_dir}")
report_content.append("Processing only files where SivasnrTEF is null")
report_content.append(f"Total JSON entries with SivasnrTEF=null: {len(sivasnr_mapping)}")
report_content.append("="*50 + "\n")
# Process all TXT files
for txt_file_path in glob.glob(os.path.join(txt_files_dir, '*.txt')):
total_files += 1
filename = os.path.basename(txt_file_path)
sivasnr = os.path.splitext(filename)[0]
# Check if corresponding JSON data exists and SivasnrTEF is null
if sivasnr in sivasnr_mapping:
json_item = sivasnr_mapping[sivasnr]
try:
# Read TXT file content
with open(txt_file_path, 'r', encoding='utf-8-sig') as f:
txt_content = json.load(f)
# Record old values
old_width = txt_content["width"]
old_height = txt_content["height"]
old_cps = {cp["id"]: {"x": cp["x"], "y": cp["y"], "direction": cp["direction"]}
for cp in txt_content["connectionPoints"]}
# Update width and height (using direct pixel values now)
new_width = round(json_item["Objekt_width_px"], 3)
new_height = round(json_item["Objekt_height_px"], 3)
txt_content["width"] = new_width
txt_content["height"] = new_height
# Update connectionPoints
cp_changes = []
for cp in txt_content["connectionPoints"]:
cp_id = cp["id"]
# Find corresponding connection point in JSON data
json_cp = next((item for item in json_item["connectionPoints"] if item["id"] == cp_id), None)
if json_cp:
# Record old values
old_x = cp["x"]
old_y = cp["y"]
old_dir = cp["direction"]
# Update values
cp["x"] = json_cp["x"]
cp["y"] = json_cp["y"]
cp["direction"] = json_cp["direction"]
# Record changes
cp_changes.append({
"id": cp_id,
"x": (old_x, cp["x"]),
"y": (old_y, cp["y"]),
"direction": (old_dir, cp["direction"])
})
# Write back to TXT file
with open(txt_file_path, 'w', encoding='utf-8') as f:
json.dump(txt_content, f, indent=2, ensure_ascii=False)
# Print success message to console
print(f"\nSuccessfully processed file: {filename}")
print("[Dimension Changes]")
print(f"width: {old_width}{new_width}")
print(f"height: {old_height}{new_height}")
if cp_changes:
print("\n[Connection Point Changes]")
for change in cp_changes:
print(f"Connection point {change['id']}:")
print(f" x: {change['x'][0]}{change['x'][1]}")
print(f" y: {change['y'][0]}{change['y'][1]}")
print(f" direction: {change['direction'][0]}{change['direction'][1]}")
print("="*50)
# Add to report
file_entry = []
file_entry.append(f"\nProcessing file: {filename}")
file_entry.append("="*50)
file_entry.append("[Dimension Changes]")
file_entry.append(f"width: {old_width}{new_width}")
file_entry.append(f"height: {old_height}{new_height}")
if cp_changes:
file_entry.append("\n[Connection Point Changes]")
for change in cp_changes:
file_entry.append(f"Connection point {change['id']}:")
file_entry.append(f" x: {change['x'][0]}{change['x'][1]}")
file_entry.append(f" y: {change['y'][0]}{change['y'][1]}")
file_entry.append(f" direction: {change['direction'][0]}{change['direction'][1]}")
processed_files += 1
file_entry.append(f"\nFile processed successfully")
file_entry.append("="*50)
report_content.extend(file_entry)
except Exception as e:
report_content.append(f"\nError processing file {filename}: {str(e)}")
else:
skipped_files += 1
# Check if the file was skipped because SivasnrTEF is not null
matching_json_items = [item for item in json_data if str(item["Sivasnr"]) == sivasnr]
if matching_json_items and matching_json_items[0]["SivasnrTEF"] is not None:
skipped_due_to_tef += 1
# Add processing statistics to report
report_content.append("\n" + "="*50)
report_content.append("Processing Statistics:")
report_content.append(f"Total TXT files found: {total_files}")
report_content.append(f"Total JSON records available: {len(json_data)}")
report_content.append(f"JSON records with SivasnrTEF = null: {len(sivasnr_mapping)}")
report_content.append(f"Successfully processed: {processed_files}")
report_content.append(f"Skipped files (no match): {skipped_files - skipped_due_to_tef}")
report_content.append(f"Skipped files (SivasnrTEF not null): {skipped_due_to_tef}")
if len(sivasnr_mapping) > 0:
success_rate = (processed_files / len(sivasnr_mapping)) * 100
report_content.append(f"Success rate: {success_rate:.2f}%")
report_content.append("="*50)
# Print final statistics to console
print("\n" + "="*50)
print("Processing Complete - Summary Statistics:")
print(f"Successfully processed files: {processed_files}")
print(f"Total files found in directory: {total_files}")
if len(sivasnr_mapping) > 0:
print(f"Success rate: {success_rate:.2f}%")
print("="*50)
print(f"Detailed report saved to: {log_file_path}")
# Write the report file
with open(log_file_path, 'w', encoding='utf-8') as f:
f.write("\n".join(report_content))
if __name__ == "__main__":
json_path = os.environ.get("JSON_PATH", "JSON")
json_file_path = os.path.join(json_path, "omniflo_weichen_output.json")
txt_files_dir = r"C:\Program Files\RuleDesigner\RDConfigurator Fusion\WebApi\Editor2D\SSG\shapes\props"
process_files(json_file_path, txt_files_dir)
@@ -1,69 +0,0 @@
import json
import os
import xml.etree.ElementTree as ET
def process_json_and_modify_xml(json_file_path, xml_folder_path):
# Initialize counter for total modifications
total_modified = 0
# Read JSON file
with open(json_file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
# Process each item in JSON data
for item in data:
if isinstance(item, dict) and (item.get("WeichenTyp") == "Einzelweiche" or item.get("WeichenTyp") == "Dreifachweiche") :
sivasnr = item.get("Sivasnr")
if sivasnr:
xml_file_name = f"{sivasnr}.xml"
xml_file_path = os.path.join(xml_folder_path, xml_file_name)
if os.path.exists(xml_file_path):
try:
# Register SVG namespace and parse XML
ET.register_namespace('', 'http://www.w3.org/2000/svg')
tree = ET.parse(xml_file_path)
root = tree.getroot()
file_modified_count = 0
# Find all path elements recursively
for path in root.iter('{http://www.w3.org/2000/svg}path'):
# Check for target attributes
if (path.get('stroke') == "none" and
path.get('stroke-width') == "1px" ):
# Remove original attributes
for attr in ['stroke', 'stroke-width', 'fill']:
if attr in path.attrib:
del path.attrib[attr]
# Set new style attribute
path.set('style', 'stroke:none;fill:none;')
file_modified_count += 1
total_modified += 1
if file_modified_count > 0:
# Save with proper formatting
xml_str = ET.tostring(root, encoding='unicode')
xml_str = xml_str.replace('><', '>\n<')
with open(xml_file_path, 'w', encoding='utf-8') as xml_file:
xml_file.write(xml_str)
print(f"Successfully modified {file_modified_count} path(s) in: {xml_file_name}")
else:
print(f"No target paths found in: {xml_file_name}")
except Exception as e:
print(f"Error processing {xml_file_name}: {str(e)}")
else:
print(f"XML file not found: {xml_file_name}")
# Print total modifications summary
print(f"\nTotal paths modified across all files: {total_modified}")
if __name__ == "__main__":
json_file_path = r"C:\Users\y.wang\Documents\SSG-Ruledesigner-Konfigurator\SVGs\Omniflo\python\OFWeiche\JSON\omniflo_weichen_output.json"
xml_folder_path = r"C:\Program Files\RuleDesigner\RDConfigurator Fusion\WebApi\Editor2D\SSG\shapes\svg"
process_json_and_modify_xml(json_file_path, xml_folder_path)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,15 +0,0 @@
@echo off
set "OFWeiche_PATH=%~dp0"
set PROPS_PATH=C:\Program Files\RuleDesigner\RDConfigurator Fusion\WebApi\Editor2D\SSG\shapes\props
set "JSON_PATH=%OFWeiche_PATH%JSON"
echo "[DEBUG] OFWeiche_PATH: %OFWeiche_PATH%"
echo "[DEBUG] PROPS_PATH: %PROPS_PATH%"
echo "[DEBUG] JSON_PATH: %JSON_PATH%"
python 1_omniflo_weichen.py
python 2_calculations_to_standardize_the_dimensions_and_add_connection_points.py
python 3_update_dimensions_and_connection_points_in_props.py
pause