kangyu 2 mesi fa
parent
commit
0b795b00e8
8 ha cambiato i file con 118 aggiunte e 132 eliminazioni
  1. 18 5
      drawer/CADJson.py
  2. 6 6
      drawer/FanMainDrawer.py
  3. 9 6
      drawer/GateDrawer.py
  4. 1 1
      drawer/TunDrawer.py
  5. 2 0
      main_3.py
  6. 22 0
      restart.sh
  7. 10 0
      test.py
  8. 50 114
      web.py

+ 18 - 5
drawer/CADJson.py

@@ -1,6 +1,8 @@
 import json
 import math
 
+import requests
+
 import core
 
 # 旋转
@@ -25,13 +27,24 @@ def calculate_route_middle(wind_flow_unit):
     return path_middle, route
 
 
+def request_graph_point(url):
+    response = requests.get(url)
+    print(f"请求耗时 {response.elapsed.total_seconds()} 秒")
+    cad_json = {}
+    if response.status_code == 200:
+        cad_json = response.json()  # 将响应内容解析为JSON格式
+    else:
+        print(f"请求失败,状态码:{response.status_code}")
+    return cad_json
+
+
 class CADJson:
     def __init__(self, path):
-        print()
-        with open(path, 'r', encoding='utf-8') as r:
-            cad_json = json.loads(r.read())
-
-        self.json = cad_json
+        if "http://" in path or "http://" in path:
+            self.json = request_graph_point(path)
+        else:
+            with open(path, 'r', encoding='utf-8') as r:
+                self.json = json.loads(r.read())
 
         self.tun_list = self.get_tuns()
 

+ 6 - 6
drawer/FanMainDrawer.py

@@ -4,7 +4,7 @@ import core
 
 
 class FanMainDrawer:
-    def __init__(self, msp,layer, gap, center, route):
+    def __init__(self, msp, layer, gap, center, route):
         self.layer = layer
         self.msp = msp
         self.gap = gap
@@ -12,11 +12,11 @@ class FanMainDrawer:
         self.route = route
 
     def draw_fan_main(self):
-        rad = 3 / 10 * self.gap
+        rad = 0.5 * self.gap
         a = math.pi / 8
         b = 10 / 3 * rad
 
-        self.msp.add_circle(center=self.center, radius=rad,dxfattribs={"layer":f"图层{self.layer}"})
+        self.msp.add_circle(center=self.center, radius=rad, dxfattribs={"layer": f"图层{self.layer}"})
 
         A = (rad * math.cos(a) + self.center[0], rad * math.sin(a) + self.center[1])
 
@@ -31,8 +31,8 @@ class FanMainDrawer:
         C = core.rotate_point_around_another(C, self.center, self.route)
         D = core.rotate_point_around_another(D, self.center, self.route)
 
-        self.msp.add_line(A, B,dxfattribs={"layer":f"图层{self.layer}"})
+        self.msp.add_line(A, B, dxfattribs={"layer": f"图层{self.layer}"})
 
-        self.msp.add_line(B, D,dxfattribs={"layer":f"图层{self.layer}"})
+        self.msp.add_line(B, D, dxfattribs={"layer": f"图层{self.layer}"})
 
-        self.msp.add_line(C, D,dxfattribs={"layer":f"图层{self.layer}"})
+        self.msp.add_line(C, D, dxfattribs={"layer": f"图层{self.layer}"})

+ 9 - 6
drawer/GateDrawer.py

@@ -3,15 +3,16 @@ from ezdxf import math as mt
 
 
 class GateDrawer:
-    def __init__(self, msp,layer, gap,center,route):
+    def __init__(self, msp, layer, gap, center, route):
         self.layer = layer
         self.msp = msp
         self.gap = gap
         self.center = center
         self.route = route
+
     def draw_gate(self):
-        grid = 1.125 * self.gap
-        rad = self.gap / 0.75
+        grid = 0.8 * self.gap
+        rad = self.gap * 0.8
 
         point_center = self.center
         route = self.route
@@ -42,7 +43,9 @@ class GateDrawer:
         self.add_gate_part(gate2_a, gate2_b, gate2_c)
 
     def add_gate_part(self, start_point, end_point, def_point):
-        carc = mt.arc.ConstructionArc()  # 假设这是一个可用的类
+        carc = mt.arc.ConstructionArc()
         b = carc.from_3p(start_point=start_point, def_point=def_point, end_point=end_point)
-        self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle,dxfattribs={"layer":f"图层{self.layer}"})
-        self.msp.add_line(start_point, end_point,dxfattribs={"layer":f"图层{self.layer}"})
+        self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle,
+                         dxfattribs={"layer": f"图层{self.layer}"})
+        # self.msp.add_lwpolyline([(start_point[0], start_point[1], 1), (end_point[0], end_point[1], 0)], format="xyb", dxfattribs={"layer": f"图层{self.layer}"})
+        self.msp.add_line(start_point, end_point, dxfattribs={"layer": f"图层{self.layer}"})

+ 1 - 1
drawer/TunDrawer.py

@@ -44,7 +44,7 @@ class TunDrawer:
         if length > 70:
             route = core.calculate_route(self.from_point, self.to_point)
             angle = math.degrees(route)
-            from_point, to_point = core.parallel_line(self.from_point, self.to_point, self.width)
+            from_point, to_point = core.parallel_line(self.from_point, self.to_point, 1.5*self.width)
             tun_center = core.find_point_on_line(from_point, to_point, 1 / 2)
             dxfattribs = {
                 'insert': tun_center, 'style': 'msyh', 'color': core.get_color_by_layer(self.layer), "layer": f"图层{self.layer}"}

+ 2 - 0
main_3.py

@@ -14,6 +14,8 @@ from drawer.WindBridgeDrawer import WindBridgeDrawer
 
 import requests
 
+url = 'http://192.168.183.216:8008/python/tunCAD'
+
 if __name__ == '__main__':
     # doc = ezdxf.new('R2000')
 

+ 22 - 0
restart.sh

@@ -0,0 +1,22 @@
+#!/bin/bash  
+  
+# 应用的启动命令  
+APP_COMMAND="python web.py"  
+  
+# 日志文件路径  
+LOG_FILE="web.log"  
+  
+# 查找并杀死当前运行的web.py进程(这里假设端口是5000,根据你的实际情况调整)
+PID=$(sudo netstat -tulnp | grep :5000 | awk '{print $7}' | cut -d/ -f1)
+if [ -n "$PID" ]; then  
+    echo "Stopping existing web.py process with PID: $PID"  
+    kill $PID  
+    # 等待进程结束,这里使用sleep作为简单示例,实际情况可能需要更复杂的逻辑  
+    sleep 2  
+fi  
+  
+# 使用nohup和&在后台运行应用,并将输出重定向到日志文件  
+echo "Starting web.py..."
+source activate ventDXF
+nohup $APP_COMMAND > $LOG_FILE 2>&1 &  
+echo "Web.py started in background with output to $LOG_FILE"

+ 10 - 0
test.py

@@ -0,0 +1,10 @@
+import time
+
+import ezdxf
+
+doc = ezdxf.new("R2000")
+msp = doc.modelspace()
+
+msp.add_lwpolyline([(10, 10, 1), (0, 0, 0)], format="xyb")
+
+doc.saveas(f"lwpolyline2{str(time.time())}.dxf")

+ 50 - 114
web.py

@@ -10,14 +10,15 @@ from tqdm import tqdm
 
 import core
 from drawer import ShaftDrawer, TunDrawer, WindowDrawer, GateDrawer, FanMainDrawer, FanSystemDrawer, WindFlowDrawer
+from drawer.CADJson import CADJson
 from drawer.WindBridgeDrawer import WindBridgeDrawer
 
 app = Flask(__name__)
 
 cur_dir = os.getcwd()
 
-url = 'http://192.168.183.216:8008/python/tunCAD'
-
+# url = 'http://192.168.183.216:8008/python/tunCAD'
+url = 'data/cad.json'
 
 @app.route('/sysvent/draw/<int:model_id>', methods=['GET'])
 def post_json(model_id):
@@ -51,8 +52,7 @@ def download_dxf_file(model_id):
     # 指定文件的完整路径
     filename = str(model_id) + ".dxf"
 
-    cad_json = request_graph_point(model_id)
-    draw_system_vent(cad_json,model_id)
+    draw_system_vent(url,model_id)
 
     file_path = f'save\\{filename}'
     # 使用send_file发送文件,as_attachment=True表示以附件形式发送
@@ -78,133 +78,69 @@ def calculate_route_middle(wind_flow_unit):
     return path_middle, route
 
 
-def draw_system_vent(cad_json, model_id):
-    doc = ezdxf.new('R2000')
-    doc.styles.add("LiberationSerif", font="LiberationSerif.ttf")
-    msp = doc.modelspace()
+def draw_system_vent(path, model_id):
+    # doc = ezdxf.new('R2000')
 
-    node_list = cad_json["tunsMapCAD"]
-    tun_list = []
-    window_list = []
-    gate_list = []
-    fan_list = []
-    for node in node_list:
-        node = node[1]
-        tun = {
-            "vec12": node["vec12"],
-            "vec34": node["vec34"],
-            "tun_id": node["ntunid"],
-            "from": (node["nfrom"]["x"], node["nfrom"]["z"]),
-            "to": (node["nto"]["x"], node["nto"]["z"]),
-            "layer_id": node["nlayerid"],
-            "width": node["fwidth"],
-            "type": node["tunType"],
-            "angle": node["angleRad"],
-            "route": core.calculate_angle_with_x_axis((node["nfrom"]["x"], node["nfrom"]["z"]),
-                                                      (node["nto"]["x"], node["nto"]["z"]))
-        }
-        tun_list.append(tun)
-        for window in node["windows"]:
-            window["route"] = tun["route"]
-            window["gap"] = node["fwidth"]
+    cad_json = CADJson(path)
 
-        window_list.extend(node["windows"])
-        for gate in node["gates"]:
-            gate["route"] = tun["route"]
-            gate["gap"] = node["fwidth"]
-        gate_list.extend(node["gates"])
+    # tun_list = cad_json.tun_list
+    # fan_list = cad_json.fan_list
+    # window_list = cad_json.window_list
 
-        for fan in node["fans"]:
-            fan["route"] = tun["route"]
-            fan["gap"] = node["fwidth"]
+    doc = ezdxf.readfile("data/moban.dxf")
+    doc.styles.add("msyh", font="data/msyh.ttc")
+    for layer in cad_json.json['layerMap']:
+        doc.layers.new(name=f'图层{layer[0]}')
 
-        fan_list.extend(node["fans"])
+    msp = doc.modelspace()
 
-    for tun in tqdm(tun_list, desc=' 【巷道绘制中】'):
+    for tun in tqdm(cad_json.tun_list, desc=' 【巷道绘制中】'):
         if tun['type'] == '1':
             shaft_center = tun['from'][0], tun['from'][1]
-            sd = ShaftDrawer(msp, tun['width'], shaft_center, tun["route"], 42)
+            sd = ShaftDrawer(msp, tun['layer_id'], tun['width'], shaft_center, 0)
             sd.draw_shaft_drawer()
         else:
-            vec12 = []
-            vec34 = []
-            for item in tun['vec12']:
-                vec12.append({
-                    "x": item["x"],
-                    "y": item["z"]
-                })
-            for item in tun['vec34']:
-                vec12.append({
-                    "x": item["x"],
-                    "y": item["z"]
-                })
-            color = core.get_color_by_layer(tun['layer_id'])
-
-            td = TunDrawer(msp, tun['layer_id'], color, vec12, vec34, tun["from"], tun["to"])
+            td = TunDrawer(msp, tun['layer_id'], tun["vec12"], tun["vec34"], tun["from"], tun["to"], tun["name"],
+                           tun["width"])
             td.draw_tun()
 
-    for window in tqdm(window_list, desc=f' 【风窗绘制中】'):
-        point_c = window['x'], window['z']
-        wd = WindowDrawer(msp, window["gap"], point_c, window["route"])
+    for window in tqdm(cad_json.window_list, desc=f' 【风窗绘制中】'):
+        wd = WindowDrawer(msp, window["width"], window["layer"], window["center"], window["route"])
         wd.draw_window()
 
-    for gate in tqdm(gate_list, desc=f' 【风窗绘制中】'):
-        point_c = gate['x'], gate['z']
-        gd = GateDrawer(msp, gate["gap"], point_c, gate["route"])
+    for gate in tqdm(cad_json.gate_list, desc=f' 【风门绘制中】'):
+        gd = GateDrawer(msp, gate["layer"], gate["width"], gate['center'], gate["route"])
         gd.draw_gate()
 
-    for fan in tqdm(fan_list, desc=f' 【风扇绘制中】'):
-        if 'fanmain' in str(fan['strtype']):
-            point_c = fan['x'], fan['z']
-            fmd = FanMainDrawer(msp, fan["gap"], point_c, fan["route"])
+    for fan in tqdm(cad_json.fan_list, desc=f' 【风扇绘制中】'):
+        if 'fanmain' in str(fan['type']):
+            fmd = FanMainDrawer(msp, fan["layer"], fan["width"], fan['center'], fan["route"])
             fmd.draw_fan_main()
-        if 'fansystem' in str(fan['strtype']):
-            point_c = fan['x'], fan['z']
-            fsd = FanSystemDrawer(msp, fan["gap"], point_c, fan["route"])
+        if 'fansystem' in str(fan['type']):
+            fsd = FanSystemDrawer(msp, fan["width"], fan['center'], fan["route"])
             fsd.draw_fan_system()
-
-    path_point_layers = cad_json["pathPointMap"]
-
-    for path_point in path_point_layers:
-
-        in_paths = path_point[1]['inPaths']
-        for in_path in tqdm(in_paths, desc=f'图层{path_point[0]} 【进风方向绘制中】'):
-            if len(in_path) != 0:
-                path_middle, route = calculate_route_middle(in_path)
-                wfd = WindFlowDrawer(msp, 5, path_middle, route, 3)
-                wfd.draw_wind_flow()
-        no_paths = path_point[1]['noPaths']
-        for no_path in tqdm(no_paths, desc=f'图层{path_point[0]} 【未指定方向绘制中】'):
-            if len(no_path) != 0:
-                path_middle, route = calculate_route_middle(no_path)
-                wfd = WindFlowDrawer(msp, 5, path_middle, route, 3)
-                wfd.draw_wind_flow()
-        out_paths = path_point[1]['outPaths']
-        for out_path in tqdm(out_paths, desc=f'图层{path_point[0]} 【回风方向绘制中】'):
-            if len(out_path) != 0:
-                path_middle, route = calculate_route_middle(out_path)
-                wfd = WindFlowDrawer(msp, 5, path_middle, route, 1)
-                wfd.draw_wind_flow()
-        use_paths = path_point[1]['usePaths']
-        for use_path in tqdm(use_paths, desc=f'图层{path_point[0]} 【用风方向绘制中】'):
-            if len(use_path) != 0:
-                path_middle, route = calculate_route_middle(use_path)
-                wfd = WindFlowDrawer(msp, 5, path_middle, route, 1)
-
-    layer_map = cad_json["layerMap"]
-
-    for layer in layer_map:
-        cross_nodes = layer[1]['crossNodes']
-        for cross_node in tqdm(cross_nodes, desc=f'图层{layer[0]} 【风桥绘制中】'):
-            center = cross_node['crossPoint']['x'], -cross_node['crossPoint']['y']
-            tun = [tun_ for tun_ in tun_list if tun_.get("tun_id") == cross_node['tun1Id']][0]
-            route = core.calculate_angle_with_x_axis(tun["from"], tun["to"])
-            line_1 = (tun["vec12"][0]["x"], tun["vec12"][0]["z"]), (tun["vec12"][-1]["x"], tun["vec12"][-1]["z"])
-            line_2 = (tun["vec34"][0]["x"], tun["vec34"][0]["z"]), (tun["vec34"][-1]["x"], tun["vec34"][-1]["z"])
-            gap = core.min_distance_between_segments(line_1,
-                                                     line_2)
-            wbd = WindBridgeDrawer(msp, center, cross_node['tun1Id'], cross_node['tun2Id'], layer[0], tun["angle"], gap)
-            wbd.draw_wind_bridge_drawer()
+    wind_flow_list = cad_json.wind_flow_list
+    for in_path in tqdm(wind_flow_list['in'], desc=f' 【进风方向绘制中】'):
+        if len(in_path) != 0:
+            wfd = WindFlowDrawer(msp, in_path['layer'], 3, in_path['center'], in_path['route'], in_path['type'])
+            wfd.draw_wind_flow()
+    for no_path in tqdm(wind_flow_list['no'], desc=f'【未指定方向绘制中】'):
+        if len(no_path) != 0:
+            wfd = WindFlowDrawer(msp, no_path['layer'], 3, no_path['center'], no_path['route'], no_path['type'])
+            wfd.draw_wind_flow()
+    for out_path in tqdm(wind_flow_list['out'], desc=f'【回风方向绘制中】'):
+        if len(out_path) != 0:
+            wfd = WindFlowDrawer(msp, out_path['layer'], 3, out_path['center'], out_path['route'], out_path['type'])
+            wfd.draw_wind_flow()
+    for use_path in tqdm(wind_flow_list['use'], desc=f' 【用风方向绘制中】'):
+        if len(use_path) != 0:
+            wfd = WindFlowDrawer(msp, use_path['layer'], 3, use_path['center'], use_path['route'], use_path['type'])
+            wfd.draw_wind_flow()
+
+    for wind_bridge in tqdm(cad_json.wind_bridge_list, desc=f' 【风桥绘制中】'):
+        wbd = WindBridgeDrawer(msp, wind_bridge['center'], wind_bridge['layer'],
+                               wind_bridge['route'], wind_bridge['width'])
+        wbd.draw_wind_bridge_drawer()
 
     doc.saveas(f'save/{str(model_id)}.dxf')