Add new api getnodetype, getlinktype, getelementtype and getelementtypevalue
This commit is contained in:
@@ -21,6 +21,30 @@ CURVE = 'curve'
|
||||
|
||||
REGION = 'region'
|
||||
|
||||
# DingZQ, 2025-02-05
|
||||
'''
|
||||
C++ 代码里已经定义了这些 enum 值
|
||||
{
|
||||
kNothing = -1,
|
||||
|
||||
//Node
|
||||
kReservoir = 0,
|
||||
kTank,
|
||||
kJunction,
|
||||
|
||||
//Link
|
||||
kPipe,
|
||||
kPump,
|
||||
kValve,
|
||||
'''
|
||||
ELEMENT_TYPES : dict[str, int] = {
|
||||
RESERVOIR : 0,
|
||||
TANK : 1,
|
||||
JUNCTION : 2,
|
||||
PIPE : 3,
|
||||
PUMP : 4,
|
||||
VALVE : 5,
|
||||
}
|
||||
|
||||
def _get_from(name: str, id: str, base_type: str) -> Row | None:
|
||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
||||
@@ -65,14 +89,36 @@ def is_valve(name: str, id: str) -> bool:
|
||||
row = _get_from(name, id, _LINK)
|
||||
return row != None and row['type'] == VALVE
|
||||
|
||||
# DingZQ, 2025-02-05
|
||||
def get_node_type(name: str, node_id: str) -> str:
|
||||
row = _get_from(name, node_id, _NODE)
|
||||
return row['type']
|
||||
|
||||
|
||||
def get_link_type(name: str, link_id: str) -> str:
|
||||
row = _get_from(name, link_id, _LINK)
|
||||
return row['type']
|
||||
|
||||
def get_element_type(name: str, element_id: str) -> str:
|
||||
if is_node(name, element_id):
|
||||
return get_node_type(name, element_id)
|
||||
elif is_link(name, element_id):
|
||||
return get_link_type(name, element_id)
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_element_type_value(name: str, element_id: str) -> int:
|
||||
return ELEMENT_TYPES[get_element_type(name, element_id)]
|
||||
|
||||
def is_curve(name: str, id: str) -> bool:
|
||||
|
||||
return _get_from(name, id, _CURVE) != None
|
||||
|
||||
|
||||
def is_pattern(name: str, id: str) -> bool:
|
||||
return _get_from(name, id, _PATTERN) != None
|
||||
|
||||
|
||||
def is_region(name: str, id: str) -> bool:
|
||||
return _get_from(name, id, _REGION) != None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user