Die OFWEICHEN und TEFWEICHEN in 2D Libary sind neu angepasst.

This commit is contained in:
2025-09-25 11:39:08 +02:00
parent bbb6b9f40a
commit 89b3018d41
387 changed files with 12050 additions and 11255 deletions
@@ -5,7 +5,7 @@ import os
def modify_json_values(json_file):
# Constant definitions
WeichenKoerperWidth = 32.5437
BogenProfileWidth = 42.080
BogenProfileWidth = 42.0801
WeichenkProfileWidth = 42.000
WeichenGerade = 360.000
@@ -15,7 +15,7 @@ def modify_json_values(json_file):
process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth, BogenProfileWidth, WeichenGerade)
process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade)
process_deltaweiche_items(data, WeichenkProfileWidth)
process_deltaweiche_items(data, WeichenkProfileWidth,WeichenKoerperWidth)
process_sternweiche_items(data)
# Save changes without confirmation
with open(json_file, 'w', encoding='utf-8') as f:
@@ -40,40 +40,36 @@ def process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth,
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"])
angle_rad = round(math.radians(item["KurvenWinkel"]),8)
sin_value=round(math.sin(angle_rad),8)
cos_value=round(math.cos(angle_rad),8)
# Calculate basic values
item["Objekt_width_mm"] = round(WeichenKoerperWidth +
(BogenProfileWidth/2 * math.cos(angle_rad)) +
(round(BogenProfileWidth/2,7) * cos_value)+
item["OFWeiche_center_line_width_mm"] +
WeichenkProfileWidth/2, 3)
round(WeichenkProfileWidth/2,7), 4)
if item["KurvenWinkel"] == 22.5:
item["Objekt_height_mm"] = round(
item["OFWeiche_center_line_height_mm"], 3)
item["OFWeiche_center_line_height_mm"], 4)
else:
item["Objekt_height_mm"] = round(
(BogenProfileWidth/2 * math.sin(angle_rad)) +
item["OFWeiche_center_line_height_mm"], 3)
(round(BogenProfileWidth/2,7) * sin_value) +
item["OFWeiche_center_line_height_mm"], 4)
# 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_x_mm"] = round((round(BogenProfileWidth/2,7) * cos_value) + item["OFWeiche_center_line_width_mm"], 4)
item["OFWeiche_CP1_y_mm"] = round(item["Objekt_height_mm"], 4)
item["OFWeiche_CP4_x_mm"] = round(item["OFWeiche_CP1_x_mm"], 4)
item["OFWeiche_CP4_y_mm"] = round(item["Objekt_height_mm"] - WeichenGerade, 4)
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)
item["OFWeiche_CP2_x_mm"] = round(round(BogenProfileWidth/2,7) * cos_value, 4)
if item["KurvenWinkel"] == 22.5:
item["OFWeiche_CP2_y_mm"] =20
else:
item["OFWeiche_CP2_y_mm"] = round(round(BogenProfileWidth/2,7) * sin_value, 4)
# Update items with identical ProfilTyp
current_profil = item["ProfilTyp"]
exact_matches = [x for x in data
@@ -92,8 +88,8 @@ def process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth,
"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:
@@ -120,8 +116,8 @@ def process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth,
"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:
@@ -150,14 +146,15 @@ def process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth,
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)
similar["OFWeiche_CP1_x_mm"] = round(WeichenKoerperWidth+round(WeichenkProfileWidth/2,7), 4)
similar["OFWeiche_CP1_y_mm"] = round(item["Objekt_height_mm"], 4)
similar["OFWeiche_CP4_x_mm"] = similar["OFWeiche_CP1_x_mm"]
similar["OFWeiche_CP4_y_mm"] = round(item["Objekt_height_mm"] - WeichenGerade, 4)
similar["OFWeiche_CP3_x_mm"] = round(similar["OFWeiche_CP1_x_mm"] + item["OFWeiche_center_line_width_mm"], 4)
if item["KurvenWinkel"] == 22.5:
similar["OFWeiche_CP3_y_mm"] =20
else:
similar["OFWeiche_CP3_y_mm"] = round(round(BogenProfileWidth/2,7) * sin_value, 4)
# Find P-type counterparts for this R-type item
r_p_profil = r_profil.replace("MIT M", "MIT P")
@@ -175,10 +172,10 @@ def process_einzelweiche_items(data, WeichenKoerperWidth, WeichenkProfileWidth,
"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_CP3_y_mm",
"OFWeiche_CP4_x_mm",
"OFWeiche_CP4_y_mm"
]
for field in fields_to_copy_r_p:
@@ -202,24 +199,28 @@ def process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade):
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"])
angle_rad = round(math.radians(item["KurvenWinkel"]),8)
sin_value=round(math.sin(angle_rad),8)
cos_value=round(math.cos(angle_rad),8)
# Calculate basic values (Doppelweiche specific formula)
item["Objekt_width_mm"] = round(
(BogenProfileWidth/2 * math.cos(angle_rad)) +
(round(BogenProfileWidth/2,7) * cos_value) +
item["OFWeiche_center_line_width_mm"] +
BogenProfileWidth/2 * math.cos(angle_rad), 3)
round(BogenProfileWidth/2,7) * cos_value, 4)
item["Objekt_height_mm"] = round(
(BogenProfileWidth/2 * math.sin(angle_rad)) +
item["OFWeiche_center_line_height_mm"], 3)
(round(BogenProfileWidth/2,7) * sin_value) +
item["OFWeiche_center_line_height_mm"], 4)
# 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_CP1_x_mm"] = round(item["Objekt_width_mm"]/2, 4)
item["OFWeiche_CP1_y_mm"] = round(item["Objekt_height_mm"], 4)
item["OFWeiche_CP2_x_mm"] = round(round(BogenProfileWidth/2,7) * cos_value, 4)
if item["KurvenWinkel"] == 22.5:
item["OFWeiche_CP2_y_mm"] =20
else:
item["OFWeiche_CP2_y_mm"] = round(round(BogenProfileWidth/2,7) * sin_value, 4)
item["OFWeiche_CP3_x_mm"] = round(round(BogenProfileWidth/2,7) * cos_value + item["OFWeiche_center_line_width_mm"], 4)
item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"]
# Update items with identical ProfilTyp
@@ -313,8 +314,8 @@ def process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade):
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)
similar["OFWeiche_CP4_x_mm"] = round(similar["Objekt_width_mm"]/2, 4)
similar["OFWeiche_CP4_y_mm"] = round(similar["Objekt_height_mm"] - WeichenGerade, 4)
# Find T-type P-type counterparts
t_p_profil = t_m_profil.replace("MIT M", "MIT P")
@@ -343,7 +344,7 @@ def process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade):
for field in fields_to_copy_t_p:
similar_t_p[field] = similar[field]
def process_deltaweiche_items(data, WeichenkProfileWidth):
def process_deltaweiche_items(data, WeichenkProfileWidth,WeichenKoerperWidth):
# Filter deltaweiche type items
filtered_items = [
item for item in data
@@ -361,15 +362,15 @@ def process_deltaweiche_items(data, WeichenkProfileWidth):
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)
item["Objekt_width_mm"] = round(item["OFWeiche_center_line_width_mm"], 4)
item["Objekt_height_mm"] = round(round(WeichenkProfileWidth/2,7) + item["OFWeiche_center_line_height_mm"]+WeichenKoerperWidth, 4)
# Calculate control points
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_CP1_x_mm"] = round(item["Objekt_width_mm"]/2, 4)
item["OFWeiche_CP1_y_mm"] = round(item["Objekt_height_mm"], 4)
item["OFWeiche_CP2_x_mm"] = 0
item["OFWeiche_CP2_y_mm"] = round(WeichenkProfileWidth/2+32.5437 , 3)
item["OFWeiche_CP3_x_mm"] = round(item["Objekt_width_mm"], 3)
item["OFWeiche_CP2_y_mm"] = round(round(WeichenkProfileWidth/2,7)+WeichenKoerperWidth , 4)
item["OFWeiche_CP3_x_mm"] = round(item["Objekt_width_mm"], 4)
item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"]
# Update items with identical ProfilTyp
@@ -439,16 +440,16 @@ def process_sternweiche_items(data):
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(item["OFWeiche_center_line_height_mm"], 3)
item["Objekt_width_mm"] = round(item["OFWeiche_center_line_width_mm"], 4)
item["Objekt_height_mm"] = round(item["OFWeiche_center_line_height_mm"], 4)
# Calculate control points
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_CP1_x_mm"] = round(item["Objekt_width_mm"]/2,4)
item["OFWeiche_CP1_y_mm"] = round(item["Objekt_height_mm"], 4)
item["OFWeiche_CP2_x_mm"] = 0
item["OFWeiche_CP2_y_mm"] = round(item["OFWeiche_center_line_height_mm"]/2, 3)
item["OFWeiche_CP3_x_mm"] = round(item["OFWeiche_center_line_width_mm"], 3)
item["OFWeiche_CP2_y_mm"] = round(item["OFWeiche_center_line_height_mm"]/2, 4)
item["OFWeiche_CP3_x_mm"] = round(item["OFWeiche_center_line_width_mm"], 4)
item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"]
item["OFWeiche_CP4_x_mm"] = item["OFWeiche_CP1_x_mm"]
item["OFWeiche_CP4_y_mm"] = 0
@@ -508,6 +509,6 @@ def process_sternweiche_items(data):
similar[field] = item[field]
if __name__ == "__main__":
json_path = os.environ.get("JSON_PATH_OFWEICHE", "JSON")
input_filename = os.path.join(json_path, "omniflo_weichen.json")
input_filename = os.path.join(json_path, "omniflo_weichen_new.json")
modify_json_values(input_filename)
@@ -21,22 +21,22 @@ def process_json_file(input_file, output_file):
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)
item["Objekt_width_px"] = round(width_mm * 3.779527592, 4)
item["Objekt_height_px"] = round(height_mm * 3.779527592, 4)
# Determine which dimension is larger and calculate scaling factor
if width_mm >= height_mm:
scale = 1000 / width_mm
scale = round(1000 / width_mm,7)
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)
item["calculated_SVG_height_px"] = round(height_mm * scale, 7)
scale_RD_H = round(1000 / item["calculated_SVG_height_px"],7)
scale_RD_W = 1
else:
scale = 1000 / height_mm
item["calculated_SVG_width_px"] = round(width_mm * scale, 3)
scale = round(1000 / height_mm,7)
item["calculated_SVG_width_px"] = round(width_mm * scale, 7)
item["calculated_SVG_height_px"] = 1000.0
scale_RD_W = round(1000 / item["calculated_SVG_width_px"], 6)
scale_RD_W = round(1000 / item["calculated_SVG_width_px"], 7)
scale_RD_H = 1
@@ -45,76 +45,74 @@ def process_json_file(input_file, output_file):
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 "-R-" 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 == "Dreifachweiche":
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 = 0.0
cp1_dir = 180.0
# 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)
connection_points.append({
"id": "cp4",
"x": cp4_x,
"y": cp4_y,
"direction": cp4_dir
"id": "cp1",
"x": cp1_x,
"y": cp1_y,
"direction": cp1_dir
})
# Add common connection points
elif weichen_typ == "Sternweiche":
cp1_dir = 180
cp2_dir = round(360 - kurven_winkel, 1)
cp3_dir = round(kurven_winkel, 1)
# CP4 exists for Dreiwegeweiche
if "-L-" in profil_typ:
# 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)
cp2_dir = round(360 - kurven_winkel, 1)
connection_points.append({
"id": "cp2",
"x": cp2_x,
"y": cp2_y,
"direction": cp2_dir
})
elif "-R-" in profil_typ:
# 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)
cp3_dir = round(kurven_winkel, 1)
connection_points.append({
"id": "cp3",
"x": cp3_x,
"y": cp3_y,
"direction": cp3_dir
})
# CP4
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 = 0
connection_points.append({
"id": "cp4",
"x": cp4_x,
"y": cp4_y,
"direction": cp4_dir
})
elif weichen_typ == "Doppelweiche":
# 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)
connection_points.extend([
# 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)
cp1_dir = 180.0
cp2_dir = round(360 - kurven_winkel, 1)
cp3_dir = round(kurven_winkel, 1)
connection_points.extend([
{
"id": "cp1",
"x": cp1_x,
@@ -134,6 +132,142 @@ def process_json_file(input_file, output_file):
"direction": cp3_dir
}
])
elif weichen_typ == "Dreifachweiche":
# 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)
cp1_dir = 180.0
cp2_dir = round(360 - kurven_winkel, 1)
cp3_dir = round(kurven_winkel, 1)
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
}
])
elif weichen_typ == "Dreiwegeweiche":
# 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)
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 = 0.0
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
},
{
"id": "cp4",
"x": cp4_x,
"y": cp4_y,
"direction": cp4_dir
}
])
# Add common connection points
elif weichen_typ == "Sternweiche":
# 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)
# CP4
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)
cp1_dir = 180
cp2_dir = round(360 - kurven_winkel, 1)
cp3_dir = round(kurven_winkel, 1)
cp4_dir = 0
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
},
{
"id": "cp4",
"x": cp4_x,
"y": cp4_y,
"direction": cp4_dir
}
])
item["connectionPoints"] = connection_points
@@ -143,7 +277,7 @@ def process_json_file(input_file, output_file):
if __name__ == "__main__":
json_path = os.environ.get("JSON_PATH_OFWEICHE", "JSON")
input_filename = os.path.join(json_path, "omniflo_weichen.json")
input_filename = os.path.join(json_path, "omniflo_weichen_new.json")
output_filename = os.path.join(json_path, "omniflo_weichen_output.json")
try:
@@ -75,36 +75,36 @@ def process_files(json_file_path, txt_files_dir):
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)
new_width = round(json_item["Objekt_width_px"], 4)
new_height = round(json_item["Objekt_height_px"], 4)
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
for i, cp in enumerate(txt_content["connectionPoints"]):
if i < len(json_item["connectionPoints"]):
json_cp = json_item["connectionPoints"][i]
# 记录旧值
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
if json_cp["direction"]==360:
cp["direction"] = 0
else:
cp["direction"] = json_cp["direction"]
# 记录变更
cp_changes.append({
"id": cp_id,
"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)
@@ -378,61 +378,24 @@ def batch_process_svgs(input_dir, output_dir):
print(f"Successfully processed: {success_count} files")
print(f"Failed to process: {failure_count} files")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='copies svg files from directory and optimizes them', prog='svg_optimizer')
parser.add_argument('-f', '--file', action='store', help='just optimize this file')
parser.add_argument('-i', '--inputdir', action='store', help='input directory for all svg files which should be rewritten. Mandatory argument')
parser.add_argument('-o', '--outputdir', action='store', help='output directory for all svg files which are writte new')
parser.add_argument('-c', '--console', action='store_true', help='put the result to console')
parser.add_argument( '--bogen', action='store_true', help='just optimize all "bogen"')
parser.add_argument( '--tefbogen', action='store_true', help='just optimize all "tefbogen"')
parser.add_argument( '--weichen', action='store_true', help='just optimize all "weichen"')
parser.add_argument( '--tefweichen', action='store_true', help='just optimize all "tefweichen"')
args = parser.parse_args()
in_dir = None
if args.inputdir:
in_dir = args.inputdir
else:
if args.bogen:
in_dir = os.environ.get('RD_CONF_OFBOGEN')
elif args.tefbogen:
in_dir = os.environ.get('RD_CONF_TEFBOGEN')
elif args.weichen:
in_dir = os.environ.get('RD_CONF_OFWEICHEN')
elif args.tefweichen:
in_dir = os.environ.get('RD_CONF_TEFWEICHEN')
out_dir = os.environ.get('RD_CONF_WORK')
if not out_dir:
print("Error: RD_CONF_WORK environment variable must be set as output directory")
input_dir = os.environ.get('RD_CONF_OFWEICHEN')
print(input_dir)
output_dir = os.environ.get('RD_CONF_WORK')
print(output_dir)
if not input_dir or not output_dir:
print("Error: Environment variable RD_CONF_WORK is not set")
exit(1)
# Check if input directory exists
if not os.path.exists(in_dir):
print(f"Error: Input directory does not exist - {in_dir}")
if not os.path.exists(input_dir):
print(f"Error: Input directory '{input_dir}' does not exist")
exit(1)
# Ensure output directory exists (create if doesn't exist, ignore if already exists)
os.makedirs(out_dir, exist_ok=True)
# Processing logic
if args.file:
filename = args.file
input_path = os.path.join(in_dir, filename)
if os.path.exists(input_path):
optimize_svg(input_path, out_dir)
else:
print(f"file {filename} does not exist")
if in_dir:
# 清空 output_dir
clear_output_dir(out_dir)
batch_process_svgs(in_dir, out_dir)
else:
print("Error: No input directory specified")
parser.print_help()
exit(1)
clear_output_dir(output_dir)
print(f"Starting SVG file processing, working directory: {input_dir}")
print("=" * 50)
batch_process_svgs(input_dir, output_dir)
print("Processing completed!")
@@ -330,15 +330,15 @@
"Schaltungstyp": "P",
"OFWeiche_center_line_width_mm": 500.23,
"OFWeiche_center_line_height_mm": 600.197,
"Objekt_width_mm": 553.774,
"Objekt_height_mm": 621.237,
"OFWeiche_CP1_x_mm": 53.544,
"Objekt_width_mm": 553.7739,
"Objekt_height_mm": 621.2369,
"OFWeiche_CP1_x_mm": 53.5437,
"OFWeiche_CP1_y_mm": 261.237,
"KurvenRichtung": 2,
"SivasnrTEF": null,
"OFWeiche_CP2_x_mm": 53.544,
"OFWeiche_CP2_x_mm": 53.5437,
"OFWeiche_CP2_y_mm": 621.237,
"OFWeiche_CP3_x_mm": 553.774,
"OFWeiche_CP3_x_mm": 553.7737,
"OFWeiche_CP3_y_mm": 21.04
},
{
@@ -1766,16 +1766,16 @@
"Schaltungstyp": "M",
"OFWeiche_center_line_width_mm": 101.5,
"OFWeiche_center_line_height_mm": 360,
"Objekt_width_mm": 174.482,
"Objekt_width_mm": 174.4822,
"Objekt_height_mm": 360,
"OFWeiche_CP1_x_mm": 120.938,
"OFWeiche_CP1_y_mm": 0.0,
"KurvenRichtung": 1,
"SivasnrTEF": null,
"OFWeiche_CP2_x_mm": 120.938,
"OFWeiche_CP2_y_mm": 360,
"OFWeiche_CP3_x_mm": 19.438,
"OFWeiche_CP3_y_mm": 8.052
"OFWeiche_CP1_x_mm": 120.938,
"OFWeiche_CP1_y_mm": 360,
"OFWeiche_CP2_x_mm": 19.4385,
"OFWeiche_CP2_y_mm": 20,
"OFWeiche_CP4_x_mm": 120.9385,
"OFWeiche_CP4_y_mm": 0.0
},
{
"Sivasnr": "OFWeichenkoerperEinfach",
@@ -1787,14 +1787,14 @@
"OFWeiche_center_line_height_mm": 360,
"Objekt_width_mm": 174.482,
"Objekt_height_mm": 360,
"OFWeiche_CP1_x_mm": 120.938,
"OFWeiche_CP1_y_mm": 0.0,
"KurvenRichtung": 1,
"SivasnrTEF": null,
"OFWeiche_CP2_x_mm": 120.938,
"OFWeiche_CP2_y_mm": 360,
"OFWeiche_CP3_x_mm": 19.438,
"OFWeiche_CP3_y_mm": 8.052
"OFWeiche_CP1_x_mm": 120.938,
"OFWeiche_CP1_y_mm": 360,
"OFWeiche_CP2_x_mm": 19.4385,
"OFWeiche_CP2_y_mm": 20,
"OFWeiche_CP4_x_mm": 120.9385,
"OFWeiche_CP4_y_mm": 0.0
},
{
"Sivasnr": 834342001,
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -262,16 +262,16 @@
"OFWeiche_center_line_width_mm": 800.0,
"OFWeiche_center_line_height_mm": 750,
"Objekt_width_mm": 853.96,
"Objekt_height_mm": 903.949,
"Objekt_height_mm": 903.9492,
"TEFWeiche_center_line_width_mm": 316.9403,
"TEFWeiche_center_line_height_mm": 764.5864,
"OFWeiche_CP1_x_mm": 414.8776,
"OFWeiche_CP1_y_mm": 764.8776,
"OFWeiche_CP2_x_mm": 14.8775,
"OFWeiche_CP2_y_mm": 14.8775,
"OFWeiche_CP2_x_mm": 14.8776,
"OFWeiche_CP2_y_mm": 14.8776,
"OFWeiche_CP3_x_mm": 814.8776,
"OFWeiche_CP3_y_mm": 14.8775,
"TEFWeiche_CPR1_x_mm": 414.8776,
"OFWeiche_CP3_y_mm": 14.8776,
"TEFWeiche_CPR1_x_mm": 514.8876,
"TEFWeiche_CPR1_y_mm": 903.9492,
"TEFWeiche_CPR2_x_mm": 831.8279,
"TEFWeiche_CPR2_y_mm": 139.3628,
@@ -286,16 +286,16 @@
"Schaltungstyp": "P",
"OFWeiche_center_line_width_mm": 800.0,
"OFWeiche_center_line_height_mm": 750,
"Objekt_width_mm": 878.165,
"Objekt_height_mm": 903.949,
"Objekt_width_mm": 878.1655,
"Objekt_height_mm": 903.9492,
"TEFWeiche_center_line_width_mm": 833.9006,
"TEFWeiche_center_line_height_mm": 764.5864,
"OFWeiche_CP1_x_mm": 439.0827,
"OFWeiche_CP1_y_mm": 764.8776,
"OFWeiche_CP2_x_mm": 39.0827,
"OFWeiche_CP2_y_mm": 14.8775,
"OFWeiche_CP2_y_mm": 14.8776,
"OFWeiche_CP3_x_mm": 839.0827,
"OFWeiche_CP3_y_mm": 14.8775,
"OFWeiche_CP3_y_mm": 14.8776,
"TEFWeiche_CPL1_x_mm": 339.0727,
"TEFWeiche_CPL1_y_mm": 903.9492,
"TEFWeiche_CPL2_x_mm": 22.1324,
@@ -649,14 +649,14 @@
"WeichenTyp": "Dreifachweiche",
"KurvenWinkel": 90,
"Schaltungstyp": "P",
"OFWeiche_center_line_width_mm": 1600.384,
"OFWeiche_center_line_height_mm": 800.266,
"OFWeiche_center_line_width_mm": 1600.3844,
"OFWeiche_center_line_height_mm": 800.2662,
"Objekt_width_mm": 1878.94,
"Objekt_height_mm": 994.044,
"TEFWeiche_center_line_width_mm": 1878.94,
"TEFWeiche_center_line_height_mm": 838.62,
"OFWeiche_CP1_x_mm": 938.630,
"OFWeiche_CP1_y_mm": 800.266,
"OFWeiche_CP1_y_mm": 853.8099,
"OFWeiche_CP2_x_mm": 138.5055,
"OFWeiche_CP2_y_mm": 53.5437,
"OFWeiche_CP3_x_mm": 1738.8898,
@@ -678,12 +678,12 @@
"WeichenTyp": "Dreifachweiche",
"KurvenWinkel": 90,
"Schaltungstyp": "P",
"OFWeiche_center_line_width_mm": 1600.384,
"OFWeiche_center_line_height_mm": 800.266,
"Objekt_width_mm": 1878.9400,
"OFWeiche_center_line_width_mm": 1600.3844,
"OFWeiche_center_line_height_mm": 800.2662,
"Objekt_width_mm": 1738.8898,
"Objekt_height_mm": 994.0437,
"TEFWeiche_center_line_width_mm": 840.49,
"TEFWeiche_center_line_height_mm": 838.62,
"TEFWeiche_center_line_width_mm": 838.62,
"TEFWeiche_center_line_height_mm": 840.49,
"OFWeiche_CP1_x_mm": 938.630,
"OFWeiche_CP1_y_mm": 853.8099,
"OFWeiche_CP2_x_mm": 138.5055,
@@ -716,24 +716,24 @@
"OFWeiche_center_line_width_mm": 800.0,
"OFWeiche_center_line_height_mm": 750,
"Objekt_width_mm": 853.96,
"Objekt_height_mm": 903.949,
"Objekt_height_mm": 903.9492,
"TEFWeiche_center_line_width_mm": 316.9403,
"TEFWeiche_center_line_height_mm": 764.5864,
"OFWeiche_CP1_x_mm": 414.8776,
"OFWeiche_CP1_y_mm": 764.8776,
"OFWeiche_CP2_x_mm": 14.8775,
"OFWeiche_CP2_y_mm": 14.8775,
"OFWeiche_CP2_x_mm": 14.8776,
"OFWeiche_CP2_y_mm": 14.8776,
"OFWeiche_CP3_x_mm": 814.8776,
"OFWeiche_CP3_y_mm": 14.8775,
"TEFWeiche_CPR1_x_mm": 414.8776,
"OFWeiche_CP3_y_mm": 14.8776,
"TEFWeiche_CPR1_x_mm": 514.8876,
"TEFWeiche_CPR1_y_mm": 903.9492,
"TEFWeiche_CPR2_x_mm": 831.8279,
"TEFWeiche_CPR2_y_mm": 139.3628,
"KurvenRichtung": 3,
"SivasnrTEF": "0_B10090+0_B10090",
"Objekt_width_px": 3227.5653,
"Objekt_height_px": 3416.5001,
"calculated_SVG_width_px": 944.699314,
"Objekt_height_px": 3416.5009,
"calculated_SVG_width_px": 944.699105,
"calculated_SVG_height_px": 1000.0,
"scale_factor": 1.106257,
"scale_factor_RD_Width": 1.058538,
@@ -762,7 +762,7 @@
},
{
"id": "cpr1",
"x": 485.828,
"x": 602.941,
"y": 1000.0,
"direction": 180,
"linkClass": "TEFOmniflo"
@@ -784,16 +784,16 @@
"Schaltungstyp": "P",
"OFWeiche_center_line_width_mm": 800.0,
"OFWeiche_center_line_height_mm": 750,
"Objekt_width_mm": 878.165,
"Objekt_height_mm": 903.949,
"Objekt_width_mm": 878.1655,
"Objekt_height_mm": 903.9492,
"TEFWeiche_center_line_width_mm": 833.9006,
"TEFWeiche_center_line_height_mm": 764.5864,
"OFWeiche_CP1_x_mm": 439.0827,
"OFWeiche_CP1_y_mm": 764.8776,
"OFWeiche_CP2_x_mm": 39.0827,
"OFWeiche_CP2_y_mm": 14.8775,
"OFWeiche_CP2_y_mm": 14.8776,
"OFWeiche_CP3_x_mm": 839.0827,
"OFWeiche_CP3_y_mm": 14.8775,
"OFWeiche_CP3_y_mm": 14.8776,
"TEFWeiche_CPL1_x_mm": 339.0727,
"TEFWeiche_CPL1_y_mm": 903.9492,
"TEFWeiche_CPL2_x_mm": 22.1324,
@@ -804,9 +804,9 @@
"TEFWeiche_CPR2_y_mm": 139.3628,
"KurvenRichtung": 3,
"SivasnrTEF": "0_B10090+0_B10090+0_B10090+0_B10090",
"Objekt_width_px": 3319.0488,
"Objekt_height_px": 3416.5001,
"calculated_SVG_width_px": 971.476267,
"Objekt_width_px": 3319.0507,
"Objekt_height_px": 3416.5009,
"calculated_SVG_width_px": 971.476605,
"calculated_SVG_height_px": 1000.0,
"scale_factor": 1.106257,
"scale_factor_RD_Width": 1.029361,
@@ -1850,14 +1850,14 @@
"WeichenTyp": "Dreifachweiche",
"KurvenWinkel": 90,
"Schaltungstyp": "P",
"OFWeiche_center_line_width_mm": 1600.384,
"OFWeiche_center_line_height_mm": 800.266,
"OFWeiche_center_line_width_mm": 1600.3844,
"OFWeiche_center_line_height_mm": 800.2662,
"Objekt_width_mm": 1878.94,
"Objekt_height_mm": 994.044,
"TEFWeiche_center_line_width_mm": 1878.94,
"TEFWeiche_center_line_height_mm": 838.62,
"OFWeiche_CP1_x_mm": 938.63,
"OFWeiche_CP1_y_mm": 800.266,
"OFWeiche_CP1_y_mm": 853.8099,
"OFWeiche_CP2_x_mm": 138.5055,
"OFWeiche_CP2_y_mm": 53.5437,
"OFWeiche_CP3_x_mm": 1738.8898,
@@ -1883,7 +1883,7 @@
{
"id": "cp1",
"x": 499.553,
"y": 805.061,
"y": 858.926,
"direction": 180,
"linkClass": "Omniflo"
},
@@ -1937,12 +1937,12 @@
"WeichenTyp": "Dreifachweiche",
"KurvenWinkel": 90,
"Schaltungstyp": "P",
"OFWeiche_center_line_width_mm": 1600.384,
"OFWeiche_center_line_height_mm": 800.266,
"Objekt_width_mm": 1878.94,
"OFWeiche_center_line_width_mm": 1600.3844,
"OFWeiche_center_line_height_mm": 800.2662,
"Objekt_width_mm": 1738.8898,
"Objekt_height_mm": 994.0437,
"TEFWeiche_center_line_width_mm": 840.49,
"TEFWeiche_center_line_height_mm": 838.62,
"TEFWeiche_center_line_width_mm": 838.62,
"TEFWeiche_center_line_height_mm": 840.49,
"OFWeiche_CP1_x_mm": 938.63,
"OFWeiche_CP1_y_mm": 853.8099,
"OFWeiche_CP2_x_mm": 138.5055,
@@ -1955,38 +1955,38 @@
"TEFWeiche_CPL2_y_mm": 153.5537,
"KurvenRichtung": 7,
"SivasnrTEF": "0_B10071+0_B10090+0_B10090",
"Objekt_width_px": 7101.5054,
"Objekt_width_px": 6572.1818,
"Objekt_height_px": 3757.0155,
"calculated_SVG_width_px": 1000.0,
"calculated_SVG_height_px": 529.04494,
"scale_factor": 0.532215,
"calculated_SVG_height_px": 571.654224,
"scale_factor": 0.57508,
"scale_factor_RD_Width": 1,
"scale_factor_RD_Height": 1.890199,
"scale_factor_RD_Height": 1.749309,
"connectionPoints": [
{
"id": "cp1",
"x": 499.553,
"x": 539.787,
"y": 858.926,
"direction": 180,
"linkClass": "Omniflo"
},
{
"id": "cp2",
"x": 73.715,
"x": 79.652,
"y": 53.865,
"direction": 270,
"linkClass": "Omniflo"
},
{
"id": "cp3",
"x": 925.463,
"x": 1000.0,
"y": 53.865,
"direction": 90,
"linkClass": "Omniflo"
},
{
"id": "cpl1",
"x": 446.326,
"x": 482.273,
"y": 1000.0,
"direction": 180,
"linkClass": "TEFOmniflo"