import json import sys import os # 경로 설정을 위해 현재 파일의 디렉토리를 sys.path에 추가 current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(current_dir) from pid_geometric_extractor import PidGeometricExtractor from pid_topology_builder import PidTopologyBuilder, analyze_impact def run_pipeline(): # 1. 경로 설정 (현재 디렉토리 기준 상대 경로) input_dxf = os.path.join(current_dir, "No-10_Plant_PID.dxf") geo_json_path = os.path.join(current_dir, "shared_geo_data.json") graph_json_path = os.path.join(current_dir, "pid_graph_topology.json") print("--- Phase 1: Geometric Extraction ---") try: extractor = PidGeometricExtractor(input_dxf) extractor.extract_and_save(geo_json_path) print(f"Geometric data saved to {geo_json_path}") except Exception as e: print(f"Phase 1 failed: {e}") return print("\n--- Phase 2: Topology Modeling ---") try: with open(geo_json_path, 'r', encoding='utf-8') as f: geometric_data = json.load(f) # 테스트를 위해 all_extracted_tags는 빈 리스트로 전달 # config를 None으로 전달하여 topology_config.json 설정을 사용하도록 함 builder = PidTopologyBuilder( geometric_data=geometric_data, all_extracted_tags=[], config=None ) builder.build_graph() # 위상 검증 validation = builder.validate_topology() print(f"Topology Validation: {validation}") # 그래프 저장 builder.save_graph(graph_json_path) print(f"Graph topology saved to {graph_json_path}") # 영향도 분석 테스트 (노드가 존재하는 경우) if validation['node_count'] > 0: sample_node = list(builder.G.nodes())[0] impacted = analyze_impact(builder.G, sample_node) print(f"Impact analysis for node {sample_node}: {impacted}") except Exception as e: print(f"Phase 2 failed: {e}") import traceback traceback.print_exc() if __name__ == "__main__": run_pipeline()