finish cell generate(untested)

This commit is contained in:
yyc12345 2020-04-12 15:19:13 +08:00
parent b24a341da6
commit 812ea62561
9 changed files with 422 additions and 108 deletions

View File

@ -18,7 +18,7 @@ enum pLinkInputOutputType {
pLinkInputOutputType_PTARGET //when using pTarget, omit [index] and [input_is_bb] pLinkInputOutputType_PTARGET //when using pTarget, omit [index] and [input_is_bb]
}; };
typedef struct dbCKBehavior { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
char name[1024]; char name[1024];
CK_BEHAVIOR_TYPE type; CK_BEHAVIOR_TYPE type;
@ -30,16 +30,16 @@ typedef struct dbCKBehavior {
//pTarget, pIn, pOut, bIn, bOut //pTarget, pIn, pOut, bIn, bOut
char pin_count[128]; char pin_count[128];
EXPAND_CK_ID parent; EXPAND_CK_ID parent;
}; }dbCKBehavior;
typedef struct dbCKScript { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
char host_name[1024]; char host_name[1024];
int index; int index;
EXPAND_CK_ID behavior; EXPAND_CK_ID behavior;
}; }dbCKScript;
typedef struct db_pTarget { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
char name[1024]; char name[1024];
char type[1024]; char type[1024];
@ -47,9 +47,9 @@ typedef struct db_pTarget {
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
EXPAND_CK_ID direct_source; EXPAND_CK_ID direct_source;
EXPAND_CK_ID shared_source; EXPAND_CK_ID shared_source;
}; }db_pTarget;
typedef struct db_pIn { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
int index; int index;
char name[1024]; char name[1024];
@ -58,27 +58,27 @@ typedef struct db_pIn {
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
EXPAND_CK_ID direct_source; EXPAND_CK_ID direct_source;
EXPAND_CK_ID shared_source; EXPAND_CK_ID shared_source;
}; }db_pIn;
typedef struct db_pOut { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
int index; int index;
char name[1024]; char name[1024];
char type[1024]; char type[1024];
CKDWORD type_guid[2]; CKDWORD type_guid[2];
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
}; }db_pOut;
typedef struct db_bIO { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
int index; int index;
char name[1024]; char name[1024];
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
}; }db_bIO;
typedef db_bIO db_bIn; typedef db_bIO db_bIn;
typedef db_bIO db_bOut; typedef db_bIO db_bOut;
typedef struct db_bLink { typedef struct {
EXPAND_CK_ID input; EXPAND_CK_ID input;
EXPAND_CK_ID output; EXPAND_CK_ID output;
int delay; int delay;
@ -91,24 +91,24 @@ typedef struct db_bLink {
EXPAND_CK_ID output_obj; EXPAND_CK_ID output_obj;
bLinkInputOutputType output_type; bLinkInputOutputType output_type;
int output_index; int output_index;
}; }db_bLink;
typedef struct db_pLocal { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
char name[1024]; char name[1024];
char type[1024]; char type[1024];
CKDWORD type_guid[2]; CKDWORD type_guid[2];
BOOL is_setting; BOOL is_setting;
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
}; }db_pLocal;
typedef struct db_pLocalData { typedef struct {
char field[1024]; char field[1024];
char data[1024]; char data[1024];
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
}; }db_pLocalData;
typedef struct db_pLink { typedef struct {
EXPAND_CK_ID input; EXPAND_CK_ID input;
EXPAND_CK_ID output; EXPAND_CK_ID output;
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
@ -122,14 +122,14 @@ typedef struct db_pLink {
pLinkInputOutputType output_type; pLinkInputOutputType output_type;
BOOL output_is_bb; BOOL output_is_bb;
int output_index; int output_index;
}; }db_pLink;
typedef struct db_pOper { typedef struct {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
char op[1024]; char op[1024];
CKDWORD op_guid[2]; CKDWORD op_guid[2];
EXPAND_CK_ID belong_to; EXPAND_CK_ID belong_to;
}; }db_pOper;
#pragma endregion #pragma endregion

View File

@ -6,33 +6,7 @@
#pragma region inline func #pragma region inline func
inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) { inline void generate_pLink_in_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget) {
helper->_db_pTarget->thisobj = cache->GetID();
strcpy(helper->_db_pTarget->name, cache->GetName());
strcpy(helper->_db_pTarget->type, helper->_parameterManager->ParameterTypeToName(cache->GetType()));
helper->_db_pTarget->type_guid[0] = cache->GetGUID().d1;
helper->_db_pTarget->type_guid[1] = cache->GetGUID().d2;
helper->_db_pTarget->belong_to = parents;
helper->_db_pTarget->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pTarget->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
db->write_pTarget(helper->_db_pTarget);
}
inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pIn->thisobj = cache->GetID();
helper->_db_pIn->index = index;
strcpy(helper->_db_pIn->name, cache->GetName());
strcpy(helper->_db_pIn->type, helper->_parameterManager->ParameterTypeToName(cache->GetType()));
helper->_db_pIn->type_guid[0] = cache->GetGUID().d1;
helper->_db_pIn->type_guid[1] = cache->GetGUID().d2;
helper->_db_pIn->belong_to = parents;
helper->_db_pIn->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pIn->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
db->write_pIn(helper->_db_pIn);
//=========try generate pLink
//WARNING: i only choose one between [DirectSource] and [SharedSource] bucause i don't find any pIn both have these two field //WARNING: i only choose one between [DirectSource] and [SharedSource] bucause i don't find any pIn both have these two field
CKParameter* directSource = NULL; CKParameter* directSource = NULL;
CKObject* ds_Owner = NULL; CKObject* ds_Owner = NULL;
@ -88,13 +62,46 @@ inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* hel
if (sharedSource != NULL || directSource != NULL) { if (sharedSource != NULL || directSource != NULL) {
helper->_db_pLink->output = cache->GetID(); helper->_db_pLink->output = cache->GetID();
helper->_db_pLink->output_obj = parents; helper->_db_pLink->output_obj = parents;
helper->_db_pLink->output_type = pLinkInputOutputType_PIN; helper->_db_pLink->output_type = isTarget ? pLinkInputOutputType_PTARGET : pLinkInputOutputType_PIN;
helper->_db_pLink->output_is_bb = executedFromBB; helper->_db_pLink->output_is_bb = executedFromBB;
helper->_db_pLink->output_index = index; helper->_db_pLink->output_index = index;
helper->_db_pLink->belong_to = grandparents; helper->_db_pLink->belong_to = grandparents;
db->write_pLink(helper->_db_pLink); db->write_pLink(helper->_db_pLink);
} }
}
inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents) {
helper->_db_pTarget->thisobj = cache->GetID();
strcpy(helper->_db_pTarget->name, cache->GetName());
strcpy(helper->_db_pTarget->type, helper->_parameterManager->ParameterTypeToName(cache->GetType()));
helper->_db_pTarget->type_guid[0] = cache->GetGUID().d1;
helper->_db_pTarget->type_guid[1] = cache->GetGUID().d2;
helper->_db_pTarget->belong_to = parents;
helper->_db_pTarget->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pTarget->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
db->write_pTarget(helper->_db_pTarget);
//=========try generate pLink
generate_pLink_in_pIn(cache, db, helper, parents, grandparents, -1, TRUE, TRUE);
}
inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) {
helper->_db_pIn->thisobj = cache->GetID();
helper->_db_pIn->index = index;
strcpy(helper->_db_pIn->name, cache->GetName());
strcpy(helper->_db_pIn->type, helper->_parameterManager->ParameterTypeToName(cache->GetType()));
helper->_db_pIn->type_guid[0] = cache->GetGUID().d1;
helper->_db_pIn->type_guid[1] = cache->GetGUID().d2;
helper->_db_pIn->belong_to = parents;
helper->_db_pIn->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1;
helper->_db_pIn->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1;
db->write_pIn(helper->_db_pIn);
//=========try generate pLink
generate_pLink_in_pIn(cache, db, helper, parents, grandparents, index, executedFromBB, FALSE);
} }
@ -287,7 +294,7 @@ void IterateBehavior(CKBehavior* bhv, database* db, dbDataStructHelper* helper,
//write target //write target
if (bhv->IsUsingTarget()) if (bhv->IsUsingTarget())
proc_pTarget(bhv->GetTargetParameter(), db, helper, bhv->GetID()); proc_pTarget(bhv->GetTargetParameter(), db, helper, bhv->GetID(), parents);
int count = 0, i = 0; int count = 0, i = 0;
//pIn //pIn

View File

@ -4,7 +4,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "database.h" #include "database.h"
inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents); inline void generate_pLink_in_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget);
inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents);
inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB); inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB); inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB);
inline void proc_bIn(CKBehaviorIO* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, int index); inline void proc_bIn(CKBehaviorIO* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, int index);

View File

@ -1,3 +1,5 @@
import json
FONT_SIZE = 12 FONT_SIZE = 12
GRAPH_POFFSET = 40 # 主体bb的p距离左边框距离 GRAPH_POFFSET = 40 # 主体bb的p距离左边框距离
@ -5,17 +7,16 @@ GRAPH_BOFFSET = 40 # 主体bb的b距离上边框距离
GRAPH_PSPAN = 20 # 主体bb的每个p之间的水平间距 GRAPH_PSPAN = 20 # 主体bb的每个p之间的水平间距
GRAPH_BSPAN = 20 # 主体bb的每个b之间的垂直间距 GRAPH_BSPAN = 20 # 主体bb的每个b之间的垂直间距
GRAPH_LAYER_SPAN = 50 # 绘图中各个bb层之间的间距 GRAPH_LAYER_SPAN = 50 # 绘图中各个bb层之间的间距
GRAPH_BB_SPAN = 25 # 绘图中每个bb之间的距离 GRAPH_BB_SPAN = 25 # 绘图中每个bb之间的距离扩展到Oper和不可插入的local之间的距离
GRAPH_SPAN_BB_POPER = 60 # 每个bb上面挂载的oper和被挂载bb之间的垂直距离 和 每个bb上面挂载的oper的各层之间的垂直距离 GRAPH_SPAN_BB_POPER = 60 # 每个bb上面挂载的oper和被挂载bb之间的垂直距离 和 每个bb上面挂载的oper的各层之间的垂直距离
GRAPH_SPAN_BB_PLOCAL = 10 # 每个bb上面挂载的plocal和被挂载bb之间的垂直距离
GRAPH_CONTENTOFFSET_X = 40 # 绘图内容原点到左边框的距离 GRAPH_CONTENTOFFSET_X = 40 # 绘图内容原点到左边框的距离
GRAPH_CONTENTOFFSET_Y = 40 # 绘图内容原点到顶边框的距离 GRAPH_CONTENTOFFSET_Y = 40 # 绘图内容原点到顶边框的距离
BB_POFFSET = 20 # bb框中的p距离左边框距离 BB_POFFSET = 20 # bb框中的p距离左边框距离
BB_BOFFSET = 10 # bb框中的b距离上边框距离 BB_BOFFSET = 10 # bb框中的b距离上边框距离
BB_PSPAN = 20 # bb框每个p之间的水平间距 BB_PSPAN = 20 # bb框每个p之间的水平间距
BB_BSPAN = 20 # bb框每个b之间的垂直间距 BB_BSPAN = 20 # bb框每个b之间的垂直间距
BB_PBSIZE = 6 # bb框中o和b的正方形符号的边长 BB_PBSIZE = 6 # bb框中o和b的正方形符号的边长扩展到graph中的p/b大小
CELL_WIDTH = 15 CELL_WIDTH = 15
CELL_HEIGHT = 5 CELL_HEIGHT = 5
@ -29,11 +30,31 @@ class dbBLinkInputOutputType(object):
INPUT = 0 INPUT = 0
OUTPUT = 1 OUTPUT = 1
class LinkType(object): class CellType(object):
PLOCAL = 0 PLOCAL = 0
SHORTCUR = 1 SHORTCUT = 1
PIO = 2 PIO = 2
BIO = 3 BIO = 3
PTARGET = 4
class LocalUsageType(object):
PIN = 0
POUT = 1
PLOCAL = 2
class JsonCustomEncoder(json.JSONEncoder):
def default(self, field):
if isinstance(field, PinInformation):
return {'id': field.id, 'name': field.name, 'type': field.type}
else:
return json.JSONEncoder.default(self, field)
class BlockCellItem(object):
def __init__(self, x, y, w, h):
self.x = x
self.y = y
self.w = w
self.h = h
class BBTreeNode(object): class BBTreeNode(object):
def __init__(self, ckid, layer): def __init__(self, ckid, layer):
@ -45,14 +66,15 @@ class BBResult(object):
def __init__(self, name, assistName, pin, pout, bin, bout, expandable): def __init__(self, name, assistName, pin, pout, bin, bout, expandable):
self.name = name self.name = name
self.assistName = assistName self.assistName = assistName
self.ptargetData = None
self.pin = int(pin) self.pin = int(pin)
self.pinData = [] self.pinData = None
self.pout = int(pout) self.pout = int(pout)
self.poutData = [] self.poutData = None
self.bin = int(bin) self.bin = int(bin)
self.binData = [] self.binData = None
self.bout = int(bout) self.bout = int(bout)
self.boutData = [] self.boutData = None
self.x = 0.0 self.x = 0.0
self.y = 0.0 self.y = 0.0
self.width = 0.0 self.width = 0.0
@ -60,7 +82,7 @@ class BBResult(object):
self.expandable = expandable self.expandable = expandable
def computSize(self): def computSize(self):
wText = max(len(self.name), len(self.assistName)) * FONT_SIZE / 2 wText = max(len(self.name), len(self.assistName)) * FONT_SIZE / 3 * 2
hText = FONT_SIZE * 3 hText = FONT_SIZE * 3
wp = max(self.pin, self.pout) * (BB_PBSIZE + BB_PSPAN) wp = max(self.pin, self.pout) * (BB_PBSIZE + BB_PSPAN)
@ -74,13 +96,13 @@ class OperResult(object):
self.name = name self.name = name
self.x = 0.0 self.x = 0.0
self.y = 0.0 self.y = 0.0
self.pinData = [] self.pinData = None
self.poutData = [] self.poutData = None
self.height = 0.0 self.height = 0.0
self.width = 0.0 self.width = 0.0
def computSize(self): def computSize(self):
wText = len(self.name) * FONT_SIZE / 2 wText = len(self.name) * FONT_SIZE / 3 * 2
hText = FONT_SIZE * 3 hText = FONT_SIZE * 3
wp = 2 * BB_POFFSET + 2 * (BB_PBSIZE + BB_PSPAN) wp = 2 * BB_POFFSET + 2 * (BB_PBSIZE + BB_PSPAN)
@ -88,3 +110,18 @@ class OperResult(object):
self.width = max(wp, wText) self.width = max(wp, wText)
self.height = max(hb, hText) self.height = max(hb, hText)
class PinInformation(object):
def __init__(self, id, name, type):
self.id = id
self.name = name
self.type = type
class LocalUsageItem(object):
def __init__(self, count, isshortcut, internal_type):
self.count = count
self.lastUse = -1
self.lastDirection = 0 # 0 for pIn, 1 for pOut
self.lastIndex = -1 # -1 for pTarget, otherwise the real index
self.isshortcut = isshortcut
self.internal_type = internal_type # 0 pIn, 1 pOut, 2 pLocal. for convenient query match data

View File

@ -1,6 +1,6 @@
import sqlite3 import sqlite3
import DecoratorConstValue as dcv import DecoratorConstValue as dcv
import queue import json
def run(): def run():
exportDb = sqlite3.connect('export.db') exportDb = sqlite3.connect('export.db')
@ -16,8 +16,12 @@ def run():
decorateGraph(exportDb, decorateDb, graphList) decorateGraph(exportDb, decorateDb, graphList)
# decorate each graph # decorate each graph
currentGraphBlockCell = {}
for i in graphList: for i in graphList:
(plocal_layer, bbMap, operMap) = buildBlock(exportDb, decorateDb, i) currentGraphBlockCell.clear()
buildBlock(exportDb, decorateDb, i, currentGraphBlockCell)
buildCell(exportDb, decorateDb, i, currentGraphBlockCell)
# give up all change of eexport.db (because no change) # give up all change of eexport.db (because no change)
exportDb.close() exportDb.close()
@ -63,7 +67,7 @@ def decorateGraph(exDb, deDb, graph):
# sub bb # sub bb
deCur.execute("INSERT INTO graph VALUES(?, ?, 0, 0, -1, '')", (lines[0], lines[2])) deCur.execute("INSERT INTO graph VALUES(?, ?, 0, 0, -1, '')", (lines[0], lines[2]))
def buildBlock(exDb, deDb, target): def buildBlock(exDb, deDb, target, currentGraphBlockCell):
exCur = exDb.cursor() exCur = exDb.cursor()
deCur = deDb.cursor() deCur = deDb.cursor()
@ -74,7 +78,8 @@ def buildBlock(exDb, deDb, target):
# layer start from 2, 0 is occupied for pLocal, 1 is occupied for pOper # layer start from 2, 0 is occupied for pLocal, 1 is occupied for pOper
arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, processedBB, 2, 0, target) arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, processedBB, 2, 0, target)
# get no linked bb and place them. linked bb position will be computed following # get no linked bb and place them. linked bb position will be computed
# following
# calc each bb's x postion, as for y, calc later # calc each bb's x postion, as for y, calc later
# flat bb tree # flat bb tree
arrangedLayer+=1 arrangedLayer+=1
@ -82,7 +87,7 @@ def buildBlock(exDb, deDb, target):
bbResult = {} bbResult = {}
bb_layer_map = {} bb_layer_map = {}
baseX = dcv.GRAPH_CONTENTOFFSET_X baseX = dcv.GRAPH_CONTENTOFFSET_X
exCur.execute('SELECT [thisobj], [name], [type], [proto_name], [pin_count] FROM behavior WHERE parent == ?', (target, )) exCur.execute('SELECT [thisobj], [name], [type], [proto_name], [pin_count] FROM behavior WHERE parent == ?', (target,))
for i in exCur.fetchall(): for i in exCur.fetchall():
pinSplit = i[4].split(',') pinSplit = i[4].split(',')
bbCache = dcv.BBResult(i[1], i[3], pinSplit[1], pinSplit[2], pinSplit[3], pinSplit[4], (i[0] if i[2] != 0 else -1)) bbCache = dcv.BBResult(i[1], i[3], pinSplit[1], pinSplit[2], pinSplit[3], pinSplit[4], (i[0] if i[2] != 0 else -1))
@ -103,7 +108,7 @@ def buildBlock(exDb, deDb, target):
processedOper = set() processedOper = set()
pluggedOper = {} pluggedOper = {}
occupiedLayerCountForSpecificBB = {} occupiedLayerCountForSpecificBB = {}
exCur.execute('SELECT [thisobj] FROM pOper WHERE [belong_to] == ?', (target, )) exCur.execute('SELECT [thisobj] FROM pOper WHERE [belong_to] == ?', (target,))
newCur = exDb.cursor() newCur = exDb.cursor()
newCur2 = exDb.cursor() newCur2 = exDb.cursor()
for i in exCur.fetchall(): for i in exCur.fetchall():
@ -151,7 +156,7 @@ def buildBlock(exDb, deDb, target):
# calc oper position # calc oper position
# flat oper tree # flat oper tree
operResult = {} operResult = {}
exCur.execute('SELECT [thisobj], [op] FROM pOper WHERE [belong_to] == ?', (target, )) exCur.execute('SELECT [thisobj], [op] FROM pOper WHERE [belong_to] == ?', (target,))
homelessOperCurrentX = dcv.GRAPH_CONTENTOFFSET_X homelessOperCurrentX = dcv.GRAPH_CONTENTOFFSET_X
for i in exCur.fetchall(): for i in exCur.fetchall():
if i[0] not in processedOper: if i[0] not in processedOper:
@ -169,7 +174,7 @@ def buildBlock(exDb, deDb, target):
jCache = pluggedOper[i][j] jCache = pluggedOper[i][j]
baseX = cache.x baseX = cache.x
for q in jCache: for q in jCache:
exCur.execute("SELECT [op] FROM pOper WHERE [thisobj] == ?", (q, )) exCur.execute("SELECT [op] FROM pOper WHERE [thisobj] == ?", (q,))
cache2 = dcv.OperResult(exCur.fetchone()[0]) cache2 = dcv.OperResult(exCur.fetchone()[0])
cache2.computSize() cache2.computSize()
cache2.x = baseX cache2.x = baseX
@ -178,42 +183,74 @@ def buildBlock(exDb, deDb, target):
operResult[q] = cache2 operResult[q] = cache2
# query bb pin's data # query bb pin's data
listCache = []
listItemCache = None
for i in allBB: for i in allBB:
cache = bbResult[i] cache = bbResult[i]
exCur.execute("SELECT [thisobj] FROM bIn WHERE [belong_to] == ? ORDER BY [index];", (i, )) exCur.execute("SELECT [thisobj], [name], [type] FROM pTarget WHERE [belong_to] == ?;", (i,))
temp = exCur.fetchone()
if temp == None:
cache.ptargetData = ''
else:
cache.ptargetData = json.dumps(dcv.PinInformation(temp[0], temp[1], temp[2]), cls = dcv.JsonCustomEncoder)
listCache.clear()
exCur.execute("SELECT [thisobj], [name] FROM bIn WHERE [belong_to] == ? ORDER BY [index];", (i,))
for j in exCur.fetchall(): for j in exCur.fetchall():
cache.binData.append(str(j[0])) listItemCache = dcv.PinInformation(j[0], j[1], '')
exCur.execute("SELECT [thisobj] FROM bOut WHERE [belong_to] == ? ORDER BY [index];", (i, )) listCache.append(listItemCache)
cache.binData = json.dumps(listCache, cls = dcv.JsonCustomEncoder)
listCache.clear()
exCur.execute("SELECT [thisobj], [name] FROM bOut WHERE [belong_to] == ? ORDER BY [index];", (i,))
for j in exCur.fetchall(): for j in exCur.fetchall():
cache.boutData.append(str(j[0])) listItemCache = dcv.PinInformation(j[0], j[1], '')
exCur.execute("SELECT [thisobj] FROM pIn WHERE [belong_to] == ? ORDER BY [index];", (i, )) listCache.append(listItemCache)
cache.boutData = json.dumps(listCache, cls = dcv.JsonCustomEncoder)
listCache.clear()
exCur.execute("SELECT [thisobj], [name], [type] FROM pIn WHERE [belong_to] == ? ORDER BY [index];", (i,))
for j in exCur.fetchall(): for j in exCur.fetchall():
cache.pinData.append(str(j[0])) listItemCache = dcv.PinInformation(j[0], j[1], j[2])
exCur.execute("SELECT [thisobj] FROM pOut WHERE [belong_to] == ? ORDER BY [index];", (i, )) listCache.append(listItemCache)
cache.pinData = json.dumps(listCache, cls = dcv.JsonCustomEncoder)
listCache.clear()
exCur.execute("SELECT [thisobj], [name], [type] FROM pOut WHERE [belong_to] == ? ORDER BY [index];", (i,))
for j in exCur.fetchall(): for j in exCur.fetchall():
cache.poutData.append(str(j[0])) listItemCache = dcv.PinInformation(j[0], j[1], j[2])
listCache.append(listItemCache)
cache.poutData = json.dumps(listCache, cls = dcv.JsonCustomEncoder)
# query oper pin's data # query oper pin's data
for i in operResult.keys(): for i in operResult.keys():
cache = operResult[i] cache = operResult[i]
exCur.execute("SELECT [thisobj] FROM pIn WHERE [belong_to] == ? ORDER BY [index];", (i, ))
listCache.clear()
exCur.execute("SELECT [thisobj], [name], [type] FROM pIn WHERE [belong_to] == ? ORDER BY [index];", (i,))
for j in exCur.fetchall(): for j in exCur.fetchall():
cache.pinData.append(str(j[0])) listItemCache = dcv.PinInformation(j[0], j[1], j[2])
exCur.execute("SELECT [thisobj] FROM pOut WHERE [belong_to] == ? ORDER BY [index];", (i, )) listCache.append(listItemCache)
cache.pinData = json.dumps(listCache, cls = dcv.JsonCustomEncoder)
listCache.clear()
exCur.execute("SELECT [thisobj], [name], [type] FROM pOut WHERE [belong_to] == ? ORDER BY [index];", (i,))
for j in exCur.fetchall(): for j in exCur.fetchall():
cache.poutData.append(str(j[0])) listItemCache = dcv.PinInformation(j[0], j[1], j[2])
listCache.append(listItemCache)
cache.poutData = json.dumps(listCache, cls = dcv.JsonCustomEncoder)
# write to database and return # write to database and return
for i in bbResult.keys(): for i in bbResult.keys():
cache = bbResult[i] cache = bbResult[i]
currentGraphBlockCell[i] = dcv.BlockCellItem(cache.x, cache.y, cache.width, cache.height)
deCur.execute('INSERT INTO block VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', deCur.execute('INSERT INTO block VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
(target, i, cache.name, cache.assistName, ','.join(cache.pinData), ','.join(cache.poutData), ','.join(cache.binData), ','.join(cache.boutData), cache.x, cache.y, cache.width, cache.height, cache.expandable)) (target, i, cache.name, cache.assistName, cache.pinData, cache.poutData, cache.binData, cache.boutData, cache.x, cache.y, cache.width, cache.height, cache.expandable))
for i in operResult.keys(): for i in operResult.keys():
cache = operResult[i] cache = operResult[i]
deCur.execute("INSERT INTO block VALUES (?, ?, ?, '', ?, ?, '', '', ?, ?, ?, ?, -1)", currentGraphBlockCell[i] = dcv.BlockCellItem(cache.x, cache.y, cache.width, cache.height)
(target, i, cache.name, ','.join(cache.pinData), ','.join(cache.poutData), cache.x, cache.y, cache.width, cache.height)) deCur.execute("INSERT INTO block VALUES (?, ?, ?, '', ?, ?, '[]', '[]', ?, ?, ?, ?, -1)",
(target, i, cache.name, cache.pinData, cache.poutData, cache.x, cache.y, cache.width, cache.height))
return (layer_y[0] - dcv.CELL_HEIGHT, bbResult, operResult)
def recursiveBuildBBTree(node, exCur, processedBB, layer, depth, graphId): def recursiveBuildBBTree(node, exCur, processedBB, layer, depth, graphId):
realLinkedBB = set() realLinkedBB = set()
@ -229,7 +266,8 @@ def recursiveBuildBBTree(node, exCur, processedBB, layer, depth, graphId):
# ignore duplicated bb # ignore duplicated bb
# calc need processed bb first # calc need processed bb first
# and register all gotten bb. for preventing infinity resursive func and keep bb tree structure # and register all gotten bb. for preventing infinity resursive func and
# keep bb tree structure
realLinkedBB = realLinkedBB - processedBB realLinkedBB = realLinkedBB - processedBB
processedBB.update(realLinkedBB) processedBB.update(realLinkedBB)
@ -262,8 +300,9 @@ def recursiveBuildOperTree(oper, bb_layer_map, processedOper, occupiedLayerMap,
if oper in processedOper: if oper in processedOper:
return return
# for avoid fucking export parameter feature. check whether self is current graph's memeber # for avoid fucking export parameter feature. check whether self is
exCur.execute("SELECT [belong_to] FROM pOper WHERE [thisobj] == ?;", (oper, )) # current graph's memeber
exCur.execute("SELECT [belong_to] FROM pOper WHERE [thisobj] == ?;", (oper,))
if (exCur.fetchone()[0] != graphId): if (exCur.fetchone()[0] != graphId):
# fuck export param, exit # fuck export param, exit
return return
@ -289,3 +328,184 @@ def recursiveBuildOperTree(oper, bb_layer_map, processedOper, occupiedLayerMap,
for i in res: for i in res:
recursiveBuildOperTree(i, bb_layer_map, processedOper, occupiedLayerMap, exCur, sublayer + 1, bb, graphId, subLayerColumnMap) recursiveBuildOperTree(i, bb_layer_map, processedOper, occupiedLayerMap, exCur, sublayer + 1, bb, graphId, subLayerColumnMap)
def buildCell(exDb, deDb, target, currentGraphBlockCell):
exCur = exDb.cursor()
deCur = deDb.cursor()
# prepare block set
blockSet = set()
for i in currentGraphBlockCell.keys():
blockSet.add(i)
# find current graph's pio bio
boutx = set()
pouty = set()
graphPIO = set()
# bOut.x and pOut.y data is not confirmed, when graph size was confirmed,
# update it
exCur.execute("SELECT [thisobj], [name], [index] FROM bIn WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
x = 0
y = dcv.GRAPH_BOFFSET + i[2] * dcv.GRAPH_BSPAN
currentGraphBlockCell[i[0]] = dcv.BlockCellItem(x, y, dcv.BB_PBSIZE, dcv.BB_PBSIZE)
deCur.execute("INSERT INTO cell VALUES (?, ?, ?, '', ?, ?, ?)", (target, i[0], i[1], x, y, dcv.CellType.BIO))
exCur.execute("SELECT [thisobj], [name], [index] FROM bOut WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
x = 0
y = dcv.GRAPH_BOFFSET + i[2] * dcv.GRAPH_BSPAN
currentGraphBlockCell[i[0]] = dcv.BlockCellItem(x, y, dcv.BB_PBSIZE, dcv.BB_PBSIZE)
deCur.execute("INSERT INTO cell VALUES (?, ?, ?, '', ?, ?, ?)", (target, i[0], i[1], x, y, dcv.CellType.BIO))
boutx.add(i[0])
exCur.execute("SELECT [thisobj], [name], [index], [type] FROM pIn WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
x = dcv.GRAPH_POFFSET + i[2] * dcv.GRAPH_PSPAN
y = 0
currentGraphBlockCell[i[0]] = dcv.BlockCellItem(x, y, dcv.BB_PBSIZE, dcv.BB_PBSIZE)
deCur.execute("INSERT INTO cell VALUES (?, ?, ?, ?, ?, ?, ?)", (target, i[0], i[1], i[3], x, y, dcv.CellType.PIO))
graphPIO.add(i[0])
exCur.execute("SELECT [thisobj], [name], [index], [type] FROM pOut WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
x = dcv.GRAPH_POFFSET + i[2] * dcv.GRAPH_PSPAN
y = 0
currentGraphBlockCell[i[0]] = dcv.BlockCellItem(x, y, dcv.BB_PBSIZE, dcv.BB_PBSIZE)
deCur.execute("INSERT INTO cell VALUES (?, ?, ?, ?, ?, ?, ?)", (target, i[0], i[1], i[3], x, y, dcv.CellType.PIO))
graphPIO.add(i[0])
pouty.add(i[0])
exCur.execute("SELECT [thisobj], [name], [type] FROM pTarget WHERE [belong_to] == ?", (target,))
cache = exCur.fetchone()
if cache != None:
currentGraphBlockCell[cache[0]] = dcv.BlockCellItem(0, 0, dcv.BB_PBSIZE, dcv.BB_PBSIZE)
deCur.execute("INSERT INTO cell VALUES (?, ?, ?, ?, 0, 0, ?)", (target, i[0], i[1], i[2], dcv.CellType.PTARGET))
graphPIO.add(cache[0])
# query all plocal
allLocal = set()
localUsageCounter = {}
exCur.execute("SELECT [thisobj], [name], [type] FROM pLocal WHERE [belong_to] == ?;", (target,))
for i in exCur.fetchall():
allLocal.add(i[0])
localUsageCounter[i[0]] = dcv.LocalUsageItem(0, False, dcv.LocalUsageType.PLOCAL)
# query all links(don't need to consider export pIO, due to it will not add
# any shortcut)
exCur.execute("SELECT * FROM pLink WHERE [belong_to] == ?", (target,))
for i in exCur.fetchall():
# check export pIO.
if ((i[2] == target) and (i[0] in graphPIO) or (i[6] == target) and (i[1] in graphPIO)):
# fuck export param
continue
# analyse 5 chancee one by one
if (i[7] == dcv.dbPLinkInputOutputType.PTARGET or i[7] == dcv.dbPLinkInputOutputType.PIN):
if (i[3] == dcv.dbPLinkInputOutputType.PLOCAL):
if i[2] in allLocal:
cache = localUsageCounter[i[2]]
else:
cache = dcv.LocalUsageItem(0, True, dcv.LocalUsageType.PLOCAL)
localUsageCounter[i[2]] = cache
cache.count += 1
cache.lastUse = i[6]
cache.lastDirection = 0
cache.lastIndex = i[9]
elif (i[3] == dcv.dbPLinkInputOutputType.PIN):
if i[2] not in blockSet:
cache = dcv.LocalUsageItem(0, True, dcv.LocalUsageType.PIN)
localUsageCounter[i[0]] = cache
cache.count+=1
cache.lastUse = i[6]
cache.lastDirection = 0
cache.lastIndex = i[9]
else:
if i[2] not in blockSet:
cache = dcv.LocalUsageItem(0, True, dcv.LocalUsageType.POUT)
localUsageCounter[i[0]] = cache
cache.count+=1
cache.lastUse = i[6]
cache.lastDirection = 1
cache.lastIndex = i[9]
else:
if (i[7] == dcv.dbPLinkInputOutputType.PLOCAL):
if i[6] in allLocal:
cache = localUsageCounter[i[6]]
else:
cache = dcv.LocalUsageItem(0, True, dcv.LocalUsageType.PLOCAL)
localUsageCounter[i[6]] = cache
cache.count += 1
cache.lastUse = i[2]
cache.lastDirection = 1
cache.lastIndex = i[5]
else:
if i[6] not in blockSet:
cache = dcv.LocalUsageItem(0, True, dcv.LocalUsageType.POUT)
localUsageCounter[i[1]] = cache
cache.count += 1
cache.lastUse = i[2]
cache.lastDirection = 1
cache.lastIndex = i[5]
# apply all cells
defaultCellIndex = 0
for i in localUsageCounter.keys():
cache = localUsageCounter[i]
# comput x,y
if (cache.count == 1):
# attachable
attachTarget = currentGraphBlockCell[cache.lastUse]
(x, y) = computCellPosition(attachTarget.x, attachTarget.y, attachTarget.h, cache.lastDirection, cache.lastIndex)
else:
# place it in default area
y = dcv.GRAPH_CONTENTOFFSET_Y
x = dcv.GRAPH_CONTENTOFFSET_X + defaultCellIndex * (dcv.CELL_WIDTH + dcv.GRAPH_BB_SPAN)
defaultCellIndex += 1
# get information
if (cache.internal_type == dcv.LocalUsageType.PIN):
tableName = 'pIn'
elif (cache.internal_type == dcv.LocalUsageType.POUT):
tableName = 'pOut'
else:
tableName = 'pLocal'
exCur.execute("SELECT [name], [type] FROM {} WHERE [thisobj] == ?".format(tableName), (i,))
temp = exCur.fetchone()
# submit to database and map
currentGraphBlockCell[i] = dcv.BlockCellItem(x, y, dcv.CELL_WIDTH, dcv.CELL_HEIGHT)
deCur.execute("INSERT INTO cell VALUES (?, ?, ?, ?, ?, ?, ?)",
(target, i, temp[0], temp[1], x, y, (dcv.CellType.SHORTCUT if cache.isshortcut else dcv.CellType.PLOCAL)))
# comput size and update database
graphX = 0
graphY = 0
for key, values in currentGraphBlockCell.items():
graphX = max(graphX, values.x + values.w)
graphY = max(graphY, values.y + values.h)
graphX += dcv.GRAPH_POFFSET
graphY += dcv.GRAPH_BOFFSET
deCur.execute("UPDATE graph SET [width] = ?, [height] = ? WHERE [graph] == ?", (graphX, graphY, target))
# update bOut.x and pOut.y data
for i in boutx:
deCur.execute("UPDATE cell SET [x] = ? WHERE ([thisobj] == ? AND [belong_to_graph] == ?)", (graphX - dcv.BB_PBSIZE, i, target))
for i in pouty:
deCur.execute("UPDATE cell SET [y] = ? WHERE ([thisobj] == ? AND [belong_to_graph] == ?)", (graphY - dcv.BB_PBSIZE, i, target))
def computCellPosition(baseX, baseY, height, direction, index):
if (index == -1):
return (0, 0)
if (direction == 0):
return (baseX + dcv.BB_POFFSET + index * (dcv.BB_PBSIZE + dcv.BB_PSPAN), baseY - dcv.GRAPH_SPAN_BB_PLOCAL)
else:
return (baseX + dcv.BB_POFFSET + index * (dcv.BB_PBSIZE + dcv.BB_PSPAN), baseY + height + dcv.GRAPH_SPAN_BB_PLOCAL)
def buildLink(exDb, deDb, target, currentGraphBlockCell):
pass

View File

@ -25,10 +25,7 @@ def close_connection(exception):
@app.template_global(name = 'pinDecoder') @app.template_global(name = 'pinDecoder')
def block_pin_filter(target): def block_pin_filter(target):
if target == '': return json.loads(target)
return []
# return json.loads(target)
return target.split(',')
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def indexHandle(): def indexHandle():
@ -58,20 +55,34 @@ def scriptHandle(scriptPath):
for i in range(len(pathSlice) - 1): for i in range(len(pathSlice) - 1):
hamburger.append(ss.HamburgerItem(hamburgerMap[pathSlice[i]], reduce(lambda x,y: x + '/' + y, pathSlice[0:i + 1], ''))) hamburger.append(ss.HamburgerItem(hamburgerMap[pathSlice[i]], reduce(lambda x,y: x + '/' + y, pathSlice[0:i + 1], '')))
# gei w/h
cur.execute('SELECT [width], [height] FROM graph WHERE [graph] == ?', (pathSlice[-1], ))
cache = cur.fetchone()
width = cache[0]
height = cache[1]
# get blocks # get blocks
cur.execute('SELECT * FROM block WHERE [belong_to_graph] = ?', (pathSlice[-1], )) cur.execute('SELECT * FROM block WHERE [belong_to_graph] = ?', (pathSlice[-1], ))
dbBlocks = cur.fetchall() dbBlocks = cur.fetchall()
# todo:xxxxx # get cells
cur.execute("SELECT * FROM cell WHERE [belong_to_graph] = ?", (pathSlice[-1], ))
dbCells = cur.fetchall()
# get links
# todo:xxxx
# render # render
return render_template('viewer.html', return render_template('viewer.html',
currentPath = scriptPath, currentPath = scriptPath,
gWidth = width,
gHeight = height,
hamburgerHistory = hamburger, hamburgerHistory = hamburger,
static_css = url_for('static', filename='site.css'), static_css = url_for('static', filename='site.css'),
static_js = url_for('static', filename='site.js'), static_js = url_for('static', filename='site.js'),
hamburgerCurrent = currentHamburger, hamburgerCurrent = currentHamburger,
blocks = dbBlocks) blocks = dbBlocks,
cells = dbCells)
def run(): def run():
app.run() app.run()

View File

@ -4,7 +4,7 @@ import os
import sys import sys
# debug use # debug use
# os.remove('decorate.db') os.remove('decorate.db')
print('Super Script View') print('Super Script View')
if not os.path.isfile("decorate.db"): if not os.path.isfile("decorate.db"):

View File

@ -42,3 +42,33 @@ div.block-body {
background: #8f8f8f; background: #8f8f8f;
border: 1px solid #cfcfcf; border: 1px solid #cfcfcf;
} }
div.cell-ptarget {
position: absolute;
background: green
border: 1px solid #cfcfcf;
}
div.cell-plocal {
position: absolute;
background: #8f8f8f;
border: 1px solid #cfcfcf;
}
div.cell-shortcut {
position: absolute;
background: purple
border: 1px solid #cfcfcf;
}
div.cell-pio {
position: absolute;
background: blue
border: 1px solid #cfcfcf;
}
div.cell-bio {
position: absolute;
background: yellow
border: 1px solid #cfcfcf;
}

View File

@ -29,25 +29,26 @@
</div> </div>
<div style="background: #7f7f7f; width: 100%; height: 100%; overflow: scroll; position: relative;"> <div style="background: #7f7f7f; width: 100%; height: 100%; overflow: scroll; position: relative;">
<div> <div>
<svg version="1.1" width="5000px" height="5000px" style="position: absolute; top: 0; left: 0;"> <svg version="1.1" width="{{ gWidth }}px" height="{{ gHeight }}px" style="position: absolute; top: 0; left: 0;">
<line x1="502" y1="210" x2="100" y2="100" stroke="black" stroke-width="1px"></line> <line x1="502" y1="210" x2="100" y2="100" stroke="black" stroke-width="1px"></line>
<line x1="320" y1="200" x2="100" y2="100" stroke="blue" stroke-width="1px" stroke-dasharray="10, 5"> <line x1="320" y1="200" x2="100" y2="100" stroke="blue" stroke-width="1px" stroke-dasharray="10, 5">
</line> </line>
<text x="200" y="155" fill="black">0</text> <text x="200" y="155" fill="black">0</text>
</svg> </svg>
{# blocks content #}
{% for i in blocks %} {% for i in blocks %}
<div class="block-body" style="height: {{ i[11] }}px; width: {{ i[10] }}px; top: {{ i[9] }}px; left: {{ i[8] }}px;"> <div class="block-body" style="height: {{ i[11] }}px; width: {{ i[10] }}px; top: {{ i[9] }}px; left: {{ i[8] }}px;">
{% for pin in pinDecoder(i[4]) %} {% for pin in pinDecoder(i[4]) %}
<div class="block-p" title="{{ pin|e }}" style="height: 6px; width: 6px; top: 0; left: {{ 20 + loop.index0 * ( 6 + 20) }}px;"></div> <div class="block-p" title="{{ "Name: %s &#13;Type: %s"|format(pin.name, pin.type) }}" style="height: 6px; width: 6px; top: 0; left: {{ 20 + loop.index0 * ( 6 + 20) }}px;"></div>
{% endfor %} {% endfor %}
{% for pout in pinDecoder(i[5]) %} {% for pout in pinDecoder(i[5]) %}
<div class="block-p" title="{{ pout|e }}" style="height: 6px; width: 6px; bottom: 0; left: {{ 20 + loop.index0 * ( 6 + 20) }}px;"></div> <div class="block-p" title="{{ "Name: %s &#13;Type: %s"|format(pout.name, pout.type) }}" style="height: 6px; width: 6px; bottom: 0; left: {{ 20 + loop.index0 * ( 6 + 20) }}px;"></div>
{% endfor %} {% endfor %}
{% for bin in pinDecoder(i[6]) %} {% for bin in pinDecoder(i[6]) %}
<div class="block-b" title="{{ bin|e }}" style="height: 6px; width: 6px; top: {{ 10 + loop.index0 * ( 6 + 20) }}px; left: 0;"></div> <div class="block-b" title="{{ "Name: %s &#13;Type: %s"|format(bin.name, bin.type) }}" style="height: 6px; width: 6px; top: {{ 10 + loop.index0 * ( 6 + 20) }}px; left: 0;"></div>
{% endfor %} {% endfor %}
{% for bout in pinDecoder(i[6]) %} {% for bout in pinDecoder(i[7]) %}
<div class="block-b" title="{{ bout|e }}" style="height: 6px; width: 6px; top: {{ 10 + loop.index0 * ( 6 + 20) }}px; right: 0;"></div> <div class="block-b" title="{{ "Name: %s &#13;Type: %s"|format(bout.name, bout.type) }}" style="height: 6px; width: 6px; top: {{ 10 + loop.index0 * ( 6 + 20) }}px; right: 0;"></div>
{% endfor %} {% endfor %}
{% if i[12] != -1 %} {% if i[12] != -1 %}
@ -58,6 +59,13 @@
<p class="block-asstext" style="top: 24px; left: 20px;">{{ i[3]|e }}</p> <p class="block-asstext" style="top: 24px; left: 20px;">{{ i[3]|e }}</p>
</div> </div>
{% endfor %} {% endfor %}
{# cells content #}
{% for i in cells %}
<div class="{% if i[6] == 0 %}cell-plocal{% elif i[6] == 1 %}cell-shortcut{% elif i[6] == 2 %}cell-pio{% elif i[6] == 3 %}bio{% else %}cell-ptarget{% endif %}"
style="height: 5px; width: 15px; top: {{ i[5] }}px; left: {{ i[4] }}px;"
title="{{ "Name: %s &#13;Type: %s"|format(i[2], i[3]) }}"></div>
{% endfor %}
</div> </div>
</div> </div>