Add addNodeWithCoord

This commit is contained in:
DingZQ
2022-08-27 10:01:27 +08:00
parent 633b7867f4
commit cbb88986c2

26
main.py
View File

@@ -1,3 +1,5 @@
from itertools import count
from netrc import netrc
import os
import io
from typing import Union, Optional
@@ -27,7 +29,7 @@ if not os.path.exists(tmpDir):
app = FastAPI()
# project operations
# undo/redo
@app.post("/undo/")
async def fastapi_undo(network: str):
undo(network)
@@ -40,6 +42,7 @@ async def fastapi_redo(network: str):
return True
# project operations
@app.get("/haveproject/")
async def fastapi_have_project(network: str):
return have_project(network)
@@ -62,6 +65,7 @@ async def fastapi_delete_project(network: str):
delete_project(network)
return True
# element operations
@app.get("/getnodes/")
async def fastapi_get_nodes(network: str):
nodeCount = get_count(network, NODE_COUNT)
@@ -80,6 +84,17 @@ async def fastapi_add_node(network: str, node: str):
print("add node")
count = get_count(network, NODE_COUNT)
print(count.value)
return idx
@app.post("/addnodewithcoord/")
async def fastapi_add_node_with_coord(network: str, node: str, x: int, y: int):
idx = add_node(network, node, JUNCTION)
print(idx)
count = get_count(network, NODE_COUNT)
print(count.value)
set_node_coord(network, node, x, y)
return idx
@app.post("/deletenode/")
@@ -91,6 +106,7 @@ async def fastapi_delete_node(network: str, node: str):
async def fastapi_count_node(network: str):
count = get_count(network, NODE_COUNT)
print(count)
return count.value
@app.get("/getnodecoord/")
@@ -105,6 +121,7 @@ async def fastapi_get_node_coord(network: str, node: str):
@app.post("/setnodecoord/")
async def fastapi_set_node_coord(network: str, node: str, x: int, y: int):
set_node_coord(network, node, x, y)
return True
@app.get("/getlinks/")
@@ -122,17 +139,20 @@ async def fastapi_get_links(network: str):
async def fastapi_add_link(network: str, link: str, fromNode: str, toNode: str):
idx = add_link(network, link, PIPE, fromNode, toNode)
print(idx)
return idx
@app.post("/deletelink/")
async def fastapi_delete_link(network: str, link: str):
delete_link(network, link)
return True
@app.get("/countlink/")
async def fastapi_count_link(network: str):
count = get_count(network, LINK_COUNT)
print(count)
return count.value
@app.post("/uploadinp/", status_code=status.HTTP_200_OK)
@@ -142,6 +162,8 @@ async def upload_inp(file: bytes = File(), name: str = None):
f.write(file)
f.close()
return True
@app.get("/downloadinp/", status_code=status.HTTP_200_OK)
async def download_inp(name: str, response: Response):
filePath = inpDir + name
@@ -149,6 +171,8 @@ async def download_inp(name: str, response: Response):
return FileResponse(filePath, media_type='application/octet-stream', filename="inp.inp")
else:
response.status_code = status.HTTP_400_BAD_REQUEST
return True