continusly promoting Decorator.

This commit is contained in:
yyc12345 2023-02-21 22:27:38 +08:00
parent 442d46cdd9
commit 9edbb79542
2 changed files with 111 additions and 13 deletions

View File

@ -0,0 +1,41 @@
import sqlite3
import DecoratorData
class BlocksFactory(object):
def __init__(self, db: sqlite3.Connection, graph: int):
# assign members
self.m_GraphCKID: int = graph
self.m_Db: sqlite3.Connection = db
self.__Cursor: sqlite3.Cursor = db.cursor()
self.m_BBDict: dict[int, DecoratorData.BBTreeNode] = {}
self.m_OperDict: dict[int, DecoratorData.OperTreeNode] = {}
self.__AllBB: set[int] = set()
self.__AllOper: set[int] = set()
self.m_PassiveOperLayer: DecoratorData.TreeLayout = DecoratorData.TreeLayout()
self.m_ActiveBBLayer: DecoratorData.TreeLayout = DecoratorData.TreeLayout()
self.m_PassiveBBLayer: DecoratorData.TreeLayout = DecoratorData.TreeLayout()
# fill data first
self.__FillDataFromDb()
def __GetOneFromSet(self, vals: set[int]) -> int:
return next(iter(vals))
def __FillDataFromDb(self):
self.__Cursor.execute('SELECT * FROM [script_behavior] WHERE parent == ?', (self.m_GraphCKID, ))
for sqldata in self.__Cursor.fetchall():
payload: DecoratorData.BBDataPayload = DecoratorData.BBDataPayload(sqldata)
self.m_BBDict[payload.m_CKID] = DecoratorData.BBTreeNode(payload)
self.__AllBB.add(payload.m_CKID)
self.__Cursor.execute('SELECT * FROM [script_pOper] WHERE parent == ?', (self.m_GraphCKID, ))
for sqldata in self.__Cursor.fetchall():
payload: DecoratorData.OperDataPayload = DecoratorData.OperDataPayload(sqldata)
self.m_OperDict[payload.m_CKID] = DecoratorData.OperTreeNode(payload)
self.__AllOper.add(payload.m_CKID)
def __BuildBB(self, tree: DecoratorData.TreeLayout, start_io: tuple[int]):
pass

View File

@ -1,9 +1,26 @@
import typing, collections, sqlite3 import typing, collections, sqlite3
class Vector(object): class Vector(object):
def __init__(self):
self.X: float = 0.0
self.Y: float = 0.0
def __init__(self, x: float, y: float): def __init__(self, x: float, y: float):
self.X: float = x self.X: float = x
self.Y: float = y self.Y: float = y
@property
def LenLeavesDir(self):
return self.X
@LenLeavesDir.setter
def LenLeavesDir(self, v):
self.X = v
@property
def LenRootsDir(self):
return self.Y
@LenRootsDir.setter
def LenRootsDir(self, v):
self.Y = v
def __add__(self, other): def __add__(self, other):
if not isinstance(other, Vector): return NotImplemented if not isinstance(other, Vector): return NotImplemented
return Vector(self.X + other.X, self.Y + other.Y) return Vector(self.X + other.X, self.Y + other.Y)
@ -36,6 +53,12 @@ class Vector(object):
if not isinstance(other, Vector): return NotImplemented if not isinstance(other, Vector): return NotImplemented
return (self.X != other.X or self.Y != other.Y) return (self.X != other.X or self.Y != other.Y)
class Margin(object):
def __init__(self):
self.m_TopSize: Vector = Vector()
self.m_BodySize: Vector = Vector()
self.m_BottomSize: Vector = Vector()
class ICanComputeSize(object): class ICanComputeSize(object):
''' '''
This class is served for TreeLayout class. This class is served for TreeLayout class.
@ -47,27 +70,51 @@ class ICanComputeSize(object):
The reason is that the vertical and horizonal direction between BB and Oper is opposited. The reason is that the vertical and horizonal direction between BB and Oper is opposited.
So we use Leaves and Root to give theme an uniformed concept. So we use Leaves and Root to give theme an uniformed concept.
''' '''
def GetLeavesDirLength() -> float: def GetPos() -> Vector:
''' '''
Get the length of the direction where leaves grow up. Get current node's start position.
''' '''
raise NotImplementedError() raise NotImplementedError()
def GetRootDirLength() -> float: def GetSize() -> Vector:
''' '''
Get the length of the direction where the tree planted. Get current node's size.
'''
raise NotImplementedError()
def ComputeSize() -> Vector:
'''
Get current node's start position
''' '''
raise NotImplementedError() raise NotImplementedError()
TNode = typing.TypeVar('TNode') TNode = typing.TypeVar('TNode', bound=ICanComputeSize)
class TreeLayoutLayer(typing.Generic[TNode]):
def __init__(self, ref_layer: int, start_pos_of_ref_layer: int):
self.m_Container: collections.deque[TNode] = collections.deque()
self.m_RefLayer: int = ref_layer
self.m_RefLayerIndex: int = start_pos_of_ref_layer
class TreeLayout(typing.Generic[TNode]): class TreeLayout(typing.Generic[TNode]):
pass NO_REFERENCE_LAYER: int = -1
def __init__(self):
self.m_Layers: collections.deque[TreeLayoutLayer[TNode]] = collections.deque()
self.__CurrentLayer: TreeLayoutLayer[TNode] = None
def NewLayer(self, ref_layer: int, start_pos_of_ref_layer: int):
self.__CurrentLayer = TreeLayoutLayer(ref_layer, start_pos_of_ref_layer)
self.m_Layers.append(self.__CurrentLayer)
def NewItem(self, node: TNode):
if self.__CurrentLayer is None: raise Exception("No layer to append data!")
self.__CurrentLayer.m_Container.append(node)
SqlTableProto_Behavior = collections.namedtuple('Behavior', 'thisobj, name, type, proto_name, proto_guid, flags, priority, version, pin_count, parent')
class BBDataPayload(object): class BBDataPayload(object):
SqlTableProto = collections.namedtuple('Behavior', 'thisobj, name, type, proto_name, proto_guid, flags, priority, version, pin_count, parent')
def __init__(self, sql_data: tuple): def __init__(self, sql_data: tuple):
v = SqlTableProto_Behavior._make(sql_data) v = BBDataPayload.SqlTableProto._make(sql_data)
self.m_CKID: int = v.thisobj self.m_CKID: int = v.thisobj
self.m_Name: str = v.name self.m_Name: str = v.name
@ -86,17 +133,27 @@ class BBDataPayload(object):
self.m_bInCount: int = int(div_pin_count[3]) self.m_bInCount: int = int(div_pin_count[3])
self.m_bOutCount: int = int(div_pin_count[4]) self.m_bOutCount: int = int(div_pin_count[4])
class OperDataPayload(object):
SqlTableProto = collections.namedtuple('Oper', 'thisobj, name, op_guid, parent')
def __init__(self, sql_data: tuple):
v = OperDataPayload.SqlTableProto._make(sql_data)
self.m_CKID: int = v.thisobj
self.m_Name: str = v.name
self.m_OpGuid: str = v.op_guid
self.m_Parent: int = v.parent
class OperTreeNode(ICanComputeSize): class OperTreeNode(ICanComputeSize):
def __init__(self): def __init__(self, payload: OperDataPayload):
pass self.m_Payload: OperDataPayload = payload
class BBTreeNode(ICanComputeSize): class BBTreeNode(ICanComputeSize):
def __init__(self): def __init__(self, payload: BBDataPayload):
self.m_UpperOper: TreeLayout[OperTreeNode] = TreeLayout() self.m_UpperOper: TreeLayout[OperTreeNode] = TreeLayout()
self.m_LowerOper: TreeLayout[OperTreeNode] = TreeLayout() self.m_LowerOper: TreeLayout[OperTreeNode] = TreeLayout()
self.m_Upperval: collections.deque = collections.deque() self.m_Upperval: collections.deque = collections.deque()
self.m_LowerVal: collections.deque = collections.deque() self.m_LowerVal: collections.deque = collections.deque()
self.m_Payload: BBDataPayload = None self.m_Payload: BBDataPayload = payload
class GraphWork(ICanComputeSize): class GraphWork(ICanComputeSize):