Initial commit

This commit is contained in:
DingZQ
2022-08-21 11:13:13 +08:00
commit 7ca9cb5d28
21 changed files with 279 additions and 0 deletions

BIN
TJNetworkServer.dll Normal file

Binary file not shown.

BIN
VCRUNTIME140_1.dll.zip Normal file

Binary file not shown.

View File

@@ -0,0 +1,5 @@
1、问题描述
在卸载office等应用或电脑崩溃后会出现缺VCRUNTIME140_1.dll的情况
2、解决方法
64位的电脑把“VCRUNTIME140_1.dll”文件放到“C:\Windows\System32”文件夹里即可
32位的电脑把“VCRUNTIME140_1.dll”文件放到“C:\Windows\SysWOW64”文件夹里即可

Binary file not shown.

Binary file not shown.

0
a.rpt Normal file
View File

0
abc.rpt Normal file
View File

0
afjdajflajdfljaskfl.rpt Normal file
View File

57
demo.py Normal file
View File

@@ -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")

BIN
epanet2.dll Normal file

Binary file not shown.

BIN
libpq.dll Normal file

Binary file not shown.

82
main.py Normal file
View File

@@ -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

0
n1.rpt Normal file
View File

0
net.rpt Normal file
View File

0
net1.rpt Normal file
View File

0
network.rpt Normal file
View File

BIN
pytjnetwork.pyd Normal file

Binary file not shown.

1
startserver.bat Normal file
View File

@@ -0,0 +1 @@
uvicorn main:app --host 0.0.0.0 --port 80 --reload

36
table.sql Normal file
View File

@@ -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)
);

98
tjnetwork.py Normal file
View File

@@ -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))

BIN
vcruntime140_1.dll Normal file

Binary file not shown.