Skip to content

Commit 9813e4c

Browse files
committed
main
1 parent c519e9a commit 9813e4c

File tree

8 files changed

+294
-517
lines changed

8 files changed

+294
-517
lines changed

app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
22
from dotenv import load_dotenv
3+
4+
from route import RoutePlan
5+
36
load_dotenv() # reads .env into environment
47

58
from flask import Flask, request, jsonify
@@ -46,6 +49,16 @@ def generate_layout_plan():
4649
url = plan.save()
4750
return jsonify({"message": "Layout plan generated", "filename": plan.name, "url": url}), 200
4851

52+
@app.route("/route/plan", methods=["POST"])
53+
def generate_route_plan():
54+
data = request.get_json()
55+
56+
plan = RoutePlan(**data)
57+
plan.draw()
58+
59+
url = plan.save()
60+
return jsonify({"message": "Route plan generated", "filename": plan.name, "url": url}), 200
61+
4962

5063
@app.errorhandler(404)
5164
def not_found(e):

cadastral.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import math
77

88
class CadastralPlan(PlanProps):
9-
_drawer: SurveyDXFManager = PrivateAttr()
10-
119
def __init__(self, **kwargs):
1210
super().__init__(**kwargs)
1311
if self.type != PlanType.CADASTRAL:
@@ -23,7 +21,7 @@ def __init__(self, **kwargs):
2321
self._drawer = self._setup_drawer()
2422

2523
def _setup_drawer(self) -> SurveyDXFManager:
26-
drawer = SurveyDXFManager(plan_name=self.name, scale=self.get_drawing_scale())
24+
drawer = SurveyDXFManager(plan_name=self.name, scale=self.get_drawing_scale(), dxf_version=self.dxf_version)
2725
drawer.setup_cadastral_layers()
2826
drawer.setup_font(self.font)
2927
drawer.setup_beacon_style(self.beacon_type, self.beacon_size)

dxf.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
from ezdxf.addons.drawing import Frontend, RenderContext, pymupdf, layout, config
55
from ezdxf.tools.text import MTextEditor
66
from ezdxf.addons import odafc
7-
import tempfile
87
import os
98
from datetime import datetime
109
import uuid
1110
import zipfile
12-
from upload import upload_file
1311
from ezdxf import bbox, colors
1412
import math
1513
from typing import List, Tuple
@@ -34,16 +32,17 @@ def __init__(self, plan_name: str = "Survey Plan", scale: float = 1.0, dxf_versi
3432
self.doc.header["$ANGBASE"] = 90.0 # set 0° direction to North
3533

3634
def setup_layers(self):
37-
self.doc.layers.add(name="BEACONS", color=colors.BLACK)
3835
self.doc.layers.add(name="LABELS", color=colors.BLACK)
3936
self.doc.layers.add(name="FRAME", color=colors.BLACK)
4037
self.doc.layers.add(name="TITLE_BLOCK", color=colors.BLACK)
4138
self.doc.layers.add(name="FOOTER", color=colors.BLACK)
4239

4340
def setup_cadastral_layers(self):
41+
self.doc.layers.add(name="BEACONS", color=colors.BLACK)
4442
self.doc.layers.add(name="PARCELS", color=colors.RED)
4543

4644
def setup_topographic_layers(self):
45+
self.doc.layers.add(name="BEACONS", color=colors.BLACK)
4746
self.doc.layers.add(name="BOUNDARY", color=colors.RED)
4847
self.doc.layers.add('CONTOUR_MAJOR', true_color=ezdxf.colors.rgb2int((127, 31, 0)), linetype="Continuous",
4948
lineweight=35)
@@ -58,6 +57,7 @@ def setup_topographic_layers(self):
5857
lineweight=25)
5958

6059
def setup_layout_layers(self):
60+
self.doc.layers.add(name="BEACONS", color=colors.BLACK)
6161
self.doc.layers.add(name="BOUNDARY", color=colors.RED, linetype="CONTINUOUS", lineweight=50)
6262
self.doc.layers.add(name="PARCELS", color=colors.GREEN, linetype="CONTINUOUS", lineweight=25)
6363
self.doc.layers.add(name="ROADS", color=colors.BLACK, linetype="CONTINUOUS", lineweight=35)
@@ -71,6 +71,11 @@ def setup_layout_layers(self):
7171
lineweight=18)
7272
self.doc.layers.add(name="BUILDABLE", color=colors.GRAY, linetype="DASHDOT", lineweight=18)
7373

74+
def setup_route_layers(self):
75+
self.doc.layers.add(name="GRID", color=colors.BLACK)
76+
self.doc.layers.add(name="F-GRID", color=colors.YELLOW, linetype="DASHDOT")
77+
self.doc.layers.add(name="TEXT", color=colors.BLUE)
78+
self.doc.layers.add(name="PROFILE", color=colors.RED)
7479

7580
def setup_beacon_style(self, type_: str = "box", size: float = 1.0):
7681
size = size * self.scale
@@ -221,7 +226,6 @@ def add_greenspace(self, points: List[Tuple[float, float]], coords):
221226
hatch.set_pattern_fill('ANSI31', scale=0.5)
222227
hatch.paths.add_polyline_path(coords, is_closed=True)
223228

224-
225229
def add_label(self, text: str, x: float, y: float, angle: float = 0.0, height: float = 1.0):
226230
x = x * self.scale
227231
y = y * self.scale
@@ -241,21 +245,23 @@ def add_label(self, text: str, x: float, y: float, angle: float = 0.0, height: f
241245
align=TextEntityAlignment.MIDDLE_CENTER
242246
)
243247

244-
def add_text(self, text: str, x: float, y: float, height: float = 1.0):
248+
def add_text(self, text: str, x: float, y: float, height: float = 1.0, rotation: float = 0.0, alignment=TextEntityAlignment.TOP_LEFT):
245249
x = x * self.scale
246250
y = y * self.scale
247251
height = height * self.scale
248252

249253
"""Add arbitrary text at given coordinates with optional rotation"""
250-
text = self.msp.add_text(
254+
self.msp.add_text(
251255
text,
252256
dxfattribs={
253257
'layer': 'TEXT',
254258
'height': height,
255-
'style': 'STANDARD'
259+
'style': 'STANDARD',
260+
"rotation": rotation,
256261
}
257262
).set_placement(
258263
(x , y),
264+
align=alignment
259265
)
260266

261267
def draw_north_arrow(self, x: float, y: float, height: float = 100.0):
@@ -644,6 +650,27 @@ def add_spline(self, points: List[Tuple[float, float, float]], layer="CONTOUR_MI
644650
dxfattribs={'layer': layer}
645651
)
646652

653+
def add_grid_line(self, x1: float, y1: float, x2: float, y2: float):
654+
x1 = x1 * self.scale
655+
y1 = y1 * self.scale
656+
x2 = x2 * self.scale
657+
y2 = y2 * self.scale
658+
659+
self.msp.add_line((x1, y1), (x2, y2), dxfattribs={'layer': 'GRID'})
660+
661+
def add_f_grid_line(self, x1: float, y1: float, x2: float, y2: float):
662+
x1 = x1 * self.scale
663+
y1 = y1 * self.scale
664+
x2 = x2 * self.scale
665+
y2 = y2 * self.scale
666+
667+
self.msp.add_line((x1, y1), (x2, y2), dxfattribs={'layer': 'F-GRID'})
668+
669+
def add_profile(self, points: List[Tuple[float, float]]):
670+
points = [(x * self.scale, y * self.scale) for x, y in points]
671+
672+
self.msp.add_spline(points, dxfattribs={'layer': 'PROFILE'})
673+
647674
def toggle_layer(self, layer: str, state: bool):
648675
"""Toggle the visibility of a layer"""
649676
layer_ = self.doc.layers.get(layer)

layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, **kwargs):
7575
self._drawer = self._setup_drawer()
7676

7777
def _setup_drawer(self) -> SurveyDXFManager:
78-
drawer = SurveyDXFManager(plan_name=self.name, scale=self.get_drawing_scale())
78+
drawer = SurveyDXFManager(plan_name=self.name, scale=self.get_drawing_scale(), dxf_version=self.dxf_version)
7979
drawer.setup_layout_layers()
8080
drawer.setup_font(self.font)
8181
drawer.setup_beacon_style(self.beacon_type, self.beacon_size)

0 commit comments

Comments
 (0)