commit 7ca9cb5d281ec8c090f1e55955b8cab8895cb6a3 Author: DingZQ Date: Sun Aug 21 11:13:13 2022 +0800 Initial commit diff --git a/TJNetworkServer.dll b/TJNetworkServer.dll new file mode 100644 index 0000000..9137911 Binary files /dev/null and b/TJNetworkServer.dll differ diff --git a/VCRUNTIME140_1.dll.zip b/VCRUNTIME140_1.dll.zip new file mode 100644 index 0000000..76273cc Binary files /dev/null and b/VCRUNTIME140_1.dll.zip differ diff --git a/VCRUNTIME140_1.dll的位置.txt b/VCRUNTIME140_1.dll的位置.txt new file mode 100644 index 0000000..510e4e9 --- /dev/null +++ b/VCRUNTIME140_1.dll的位置.txt @@ -0,0 +1,5 @@ +1、问题描述: +在卸载office等应用或电脑崩溃后会出现缺VCRUNTIME140_1.dll的情况 +2、解决方法: +64位的电脑把“VCRUNTIME140_1.dll”文件放到“C:\Windows\System32”文件夹里即可 +32位的电脑把“VCRUNTIME140_1.dll”文件放到“C:\Windows\SysWOW64”文件夹里即可 \ No newline at end of file diff --git a/__pycache__/main.cpython-37.pyc b/__pycache__/main.cpython-37.pyc new file mode 100644 index 0000000..11524be Binary files /dev/null and b/__pycache__/main.cpython-37.pyc differ diff --git a/__pycache__/tjnetwork.cpython-37.pyc b/__pycache__/tjnetwork.cpython-37.pyc new file mode 100644 index 0000000..dcaafef Binary files /dev/null and b/__pycache__/tjnetwork.cpython-37.pyc differ diff --git a/a.rpt b/a.rpt new file mode 100644 index 0000000..e69de29 diff --git a/abc.rpt b/abc.rpt new file mode 100644 index 0000000..e69de29 diff --git a/afjdajflajdfljaskfl.rpt b/afjdajflajdfljaskfl.rpt new file mode 100644 index 0000000..e69de29 diff --git a/demo.py b/demo.py new file mode 100644 index 0000000..fccfbff --- /dev/null +++ b/demo.py @@ -0,0 +1,57 @@ +from tjnetwork import * + +JUNCTION = 0 +RESERVOIR = 1 +TANK = 2 +PIPE = 1 +NODE_COUNT = 0 +LINK_COUNT = 2 + +create_project("net1") +open_project("net1") + +add_node("net1", "node-1", JUNCTION) + +undo("net1") +redo("net1") + +add_node("net1", "node-2", RESERVOIR) +add_node("net1", "node-3", TANK) + +set_node_coord("net1", "node-3", 10.0, 10.0) + +delete_node("net1", "node-3") +undo("net1") + +set_node_coord("net1", "node-1", 10.0, 10.0) +undo("net1") +redo("net1") + +set_node_coord("net1", "node-2", 20.0, 20.0) + +add_link("net1", "link-1", PIPE, "node-1", "node-2") + +add_link("net1", "link-2", PIPE, "node-1", "node-3") +undo("net1") +redo("net1") + +add_link("net1", "link-3", PIPE, "node-2", "node-3") +undo("net1") + +# this could fail since link-1 & link-2 ref node-1 +delete_node("net1", "node-1") + +node_count = get_count("net1", NODE_COUNT) +print(node_count.value) +for i in range(1, node_count.value + 1): + node_id = get_node_id("net1", i) + print(node_id.value) + +link_count = get_count("net1", LINK_COUNT) +print(link_count.value) +for i in range(1, link_count.value + 1): + link_id = get_link_id("net1", i) + print(link_id.value) + +close_project("net1") +delete_project("net1") \ No newline at end of file diff --git a/epanet2.dll b/epanet2.dll new file mode 100644 index 0000000..3bb592e Binary files /dev/null and b/epanet2.dll differ diff --git a/libpq.dll b/libpq.dll new file mode 100644 index 0000000..8978a3d Binary files /dev/null and b/libpq.dll differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..cc83b8d --- /dev/null +++ b/main.py @@ -0,0 +1,82 @@ +import os +import io +from typing import Union, Optional +from fastapi import FastAPI, File, UploadFile +from pydantic import BaseModel +from starlette.responses import FileResponse +from fastapi import FastAPI, Response, status +import pytjnetwork as tj +from tjnetwork import * + +JUNCTION = 0 +RESERVOIR = 1 +TANK = 2 +PIPE = 1 +NODE_COUNT = 0 +LINK_COUNT = 2 + +prjs = [] +inpDir = "C:/inpfiles/" +tmpDir = "C:/tmpfiles/" + +if not os.path.exists(inpDir): + os.mkdir(inpDir) + +if not os.path.exists(tmpDir): + os.mkdir(tmpDir) + +app = FastAPI() + +# project operations +@app.post("/undo/") +async def fastapi_undo(network: str): + undo(network) + + return True + +@app.post("/redo/") +async def fastapi_redo(network: str): + redo(network) + + return True + +@app.post("/createproject/") +async def fastapi_create_project(network: str): + create_project(network) + open_project(network) + + print(network) + return network + +@app.post("/addnode/") +async def fastapi_add_node(network: str, node: str): + idx = add_node(network, node, JUNCTION) + print(idx) + return idx + +@app.post("/deletenode/") +async def fastapi_delete_node(network: str, node: str): + delete_node(network, node) + return True + +@app.get("/countnode/") +async def fastapi_count_node(network: str): + count = get_count(network, NODE_COUNT) + print(count) + return count.value + +@app.post("/uploadinp/", status_code=status.HTTP_200_OK) +async def upload_inp(file: bytes = File(), name: str = None): + filePath = inpDir + str(name) + f = open(filePath, 'wb') + f.write(file) + f.close() + +@app.get("/downloadinp/", status_code=status.HTTP_200_OK) +async def download_inp(name: str, response: Response): + filePath = inpDir + name + if os.path.exists(filePath): + return FileResponse(filePath, media_type='application/octet-stream', filename="inp.inp") + else: + response.status_code = status.HTTP_400_BAD_REQUEST + diff --git a/n1.rpt b/n1.rpt new file mode 100644 index 0000000..e69de29 diff --git a/net.rpt b/net.rpt new file mode 100644 index 0000000..e69de29 diff --git a/net1.rpt b/net1.rpt new file mode 100644 index 0000000..e69de29 diff --git a/network.rpt b/network.rpt new file mode 100644 index 0000000..e69de29 diff --git a/pytjnetwork.pyd b/pytjnetwork.pyd new file mode 100644 index 0000000..d195915 Binary files /dev/null and b/pytjnetwork.pyd differ diff --git a/startserver.bat b/startserver.bat new file mode 100644 index 0000000..2e882c4 --- /dev/null +++ b/startserver.bat @@ -0,0 +1 @@ +uvicorn main:app --host 0.0.0.0 --port 80 --reload diff --git a/table.sql b/table.sql new file mode 100644 index 0000000..1b3c0f2 --- /dev/null +++ b/table.sql @@ -0,0 +1,36 @@ +drop table if exists Link; +drop table if exists Node; + +drop type if exists EN_NodeType; +create type EN_NodeType as enum ( + 'EN_JUNCTION', + 'EN_RESERVOIR', + 'EN_TANK' +); + +drop type if exists EN_LinkType; +create type EN_LinkType as enum ( + 'EN_CVPIPE', + 'EN_PIPE', + 'EN_PUMP', + 'EN_PRV', + 'EN_PSV', + 'EN_PBV', + 'EN_FCV', + 'EN_TCV', + 'EN_GPV' +); + +create table Node ( + Id varchar(32) primary key, + Type EN_NodeType not null, + Coord point not null default(point(0.0, 0.0)), + Elevation numeric not null default(0.0) +); + +create table Link ( + Id varchar(32) primary key, + Type EN_LinkType not null, + FromNode varchar(32) not null references Node(Id), + ToNode varchar(32) not null references Node(Id) +); \ No newline at end of file diff --git a/tjnetwork.py b/tjnetwork.py new file mode 100644 index 0000000..3309876 --- /dev/null +++ b/tjnetwork.py @@ -0,0 +1,98 @@ +import ctypes + +max_name_len = 32 + +server = ctypes.windll.LoadLibrary("./TJNetworkServer.dll") + +class LinkNodes: + def __init__(self, from_node, to_node): + self.from_node = from_node + self.to_node = to_node + +class Point: + def __init__(self, x, y): + self.x = x + self.y = y + +class Result: + def __init__(self, ec, v): + self.error_code = ec + self.value = v + +def c_str(value): + return ctypes.c_char_p(value.encode()) + +def c_ref(value): + return ctypes.byref(value) + +# have database +def have_project(name): + yes = 406 + ec = server.TJ_haveproject(c_str(name)) + return True if ec == yes else False + +# create database +def create_project(name): + return server.TJ_createproject(c_str(name)) + +# delete database +def delete_project(name): + return server.TJ_deleteproject(c_str(name)) + +# create runtime project and connect to database +def open_project(name): + return server.TJ_openproject(c_str(name)) + +# delete runtime project and disconnect from database +def close_project(name): + return server.TJ_closeproject(c_str(name)) + +def undo(name): + return server.TJ_undo(c_str(name)) + +def redo(name): + return server.TJ_redo(c_str(name)) + +def get_count(name, object_type): + count = ctypes.c_int() + ec = server.TJ_getcount(c_str(name), object_type, c_ref(count)) + return Result(ec, count.value) + +def add_node(name, node_id, node_type): + return server.TJ_addnode(c_str(name), c_str(node_id), node_type) + +def delete_node(name, node_id): + return server.TJ_deletenode(c_str(name), c_str(node_id)) + +def get_node_id(name, node_index): + id = ctypes.create_string_buffer(max_name_len) + ec = server.TJ_getnodeid(c_str(name), node_index, c_ref(id)) + return Result(ec, id.value) + +def get_node_coord(name, node_id): + x = ctypes.c_double() + y = ctypes.c_double() + ec = server.TJ_getnodecoord(c_str(name), c_str(node_id), c_ref(x), c_ref(y)) + return Result(ec, Point(x.value, y.value)) + +def set_node_coord(name, node_id, x, y): + func = server.TJ_setnodecoord + func.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_double, ctypes.c_double] + return func(c_str(name), c_str(node_id), x, y) + +def add_link(name, link_id, link_type, from_node, to_node): + return server.TJ_addlink(c_str(name), c_str(link_id), link_type, c_str(from_node), c_str(to_node)) + +def delete_link(name, link_id): + return server.TJ_deletelink(c_str(name), c_str(link_id)) + +def get_link_id(name, link_index): + id = ctypes.create_string_buffer(max_name_len) + ec = server.TJ_getlinkid(c_str(name), link_index, c_ref(id)) + return Result(ec, id.value) + +def get_link_nodes(name, link_id): + from_node = ctypes.create_string_buffer(max_name_len) + to_node = ctypes.create_string_buffer(max_name_len) + ec = server.TJ_getlinknodes(c_str(name), c_str(link_id), c_ref(from_node), c_ref(to_node)) + return Result(ec, LinkNodes(from_node.value, to_node.value)) diff --git a/vcruntime140_1.dll b/vcruntime140_1.dll new file mode 100644 index 0000000..3ebabde Binary files /dev/null and b/vcruntime140_1.dll differ