44
55from dxf import SurveyDXFManager
66from models .plan import PlanProps
7- from utils import polygon_orientation , line_normals , line_direction
7+ from utils import polygon_orientation , line_normals , line_direction , html_to_mtext
88
99app = Flask (__name__ )
1010app .config ["SECRET_KEY" ] = "secret"
@@ -22,7 +22,7 @@ def generate_cadastral_plan():
2222 extent = plan .get_extent ()
2323 beacon_size = extent * 0.02
2424
25- drawer = SurveyDXFManager (plan_name = plan .name , scale = plan .scale )
25+ drawer = SurveyDXFManager (plan_name = plan .name , scale = plan .get_drawing_scale () )
2626 drawer .setup_beacon_style (type_ = plan .beacon_type , size = beacon_size or 1.0 )
2727 drawer .setup_font (plan .font )
2828
@@ -81,7 +81,6 @@ def generate_cadastral_plan():
8181
8282 drawer .add_text (f"{ leg .distance :.2f} m" , mid_x , mid_y , angle = text_angle , height = label_height )
8383 ld = line_direction (angle_deg )
84- print (leg .from_ .id , leg .to .id , ld )
8584 if ld == "left → right" :
8685 drawer .add_text (f"{ leg .bearing .degrees } °" , first_x , first_y , angle = text_angle , height = label_height )
8786 drawer .add_text (f"{ leg .bearing .minutes } '" , last_x , last_y , angle = text_angle , height = label_height )
@@ -96,21 +95,31 @@ def generate_cadastral_plan():
9695 height = max_y - min_y
9796
9897 # Draw frame
99- margin_x = max (width , height ) * 0.4
100- margin_y = max (height , width ) * 0.75
101- drawer .draw_frame (min_x - margin_x , min_y - margin_y , max_x + margin_x , max_y + margin_y )
98+ margin_x = max (width , height ) * 0.35
99+ margin_y = max (height , width ) * 0.7
100+ frame_left = min_x - margin_x
101+ frame_bottom = min_y - margin_y
102+ frame_right = max_x + margin_x
103+ frame_top = max_y + margin_y
104+ drawer .draw_frame (frame_left , frame_bottom , frame_right ,frame_top )
102105
103106 # offset frame
104- offset_x = max (width , height ) * 0.43
105- offset_y = max (height , width ) * 0.78
107+ offset_x = max (width , height ) * 0.38
108+ offset_y = max (height , width ) * 0.73
106109 drawer .draw_frame (min_x - offset_x , min_y - offset_y , max_x + offset_x , max_y + offset_y )
107110
108111 # add title block
109- box_width = (max_x + margin_x ) - (min_x - margin_x ) * 0.6
110- title_x = ((min_x - margin_x ) + (max_x + margin_x )) / 2
111- title_y = (max_y + margin_y ) - (margin_y * 0.15 )
112- text_height = plan .font_size or ((max_y + margin_y ) - (min_y - margin_y )) * 0.02
113- drawer .add_title (plan .title .upper (), title_x , title_y , width = box_width , height = text_height )
112+ # Calculate center position for title
113+ frame_width = frame_right - frame_left
114+ frame_center_x = frame_left + (frame_width / 2 )
115+
116+ # Title positioning
117+ title_y = frame_top - (margin_y * 0.2 ) # 5 units below the top of frame
118+ title_height = plan .font_size # Height of title text
119+ title_width = frame_width * 0.6 # Use 60% of frame width for title box
120+
121+ drawer .add_title (html_to_mtext (plan .build_title ()), frame_center_x , title_y , title_width , title_height )
122+
114123
115124 drawer .save_dxf ()
116125 return jsonify ({"message" : "Cadastral plan generated" , "filename" : plan .name }), 200
0 commit comments