diff --git a/SuperScriptMaterializer/database.h b/SuperScriptMaterializer/database.h index b1040c7..cab7a04 100644 --- a/SuperScriptMaterializer/database.h +++ b/SuperScriptMaterializer/database.h @@ -18,7 +18,7 @@ enum pLinkInputOutputType { pLinkInputOutputType_PTARGET //when using pTarget, omit [index] and [input_is_bb] }; -typedef struct dbCKBehavior { +typedef struct { EXPAND_CK_ID thisobj; char name[1024]; CK_BEHAVIOR_TYPE type; @@ -30,16 +30,16 @@ typedef struct dbCKBehavior { //pTarget, pIn, pOut, bIn, bOut char pin_count[128]; EXPAND_CK_ID parent; -}; +}dbCKBehavior; -typedef struct dbCKScript { +typedef struct { EXPAND_CK_ID thisobj; char host_name[1024]; int index; EXPAND_CK_ID behavior; -}; +}dbCKScript; -typedef struct db_pTarget { +typedef struct { EXPAND_CK_ID thisobj; char name[1024]; char type[1024]; @@ -47,9 +47,9 @@ typedef struct db_pTarget { EXPAND_CK_ID belong_to; EXPAND_CK_ID direct_source; EXPAND_CK_ID shared_source; -}; +}db_pTarget; -typedef struct db_pIn { +typedef struct { EXPAND_CK_ID thisobj; int index; char name[1024]; @@ -58,27 +58,27 @@ typedef struct db_pIn { EXPAND_CK_ID belong_to; EXPAND_CK_ID direct_source; EXPAND_CK_ID shared_source; -}; +}db_pIn; -typedef struct db_pOut { +typedef struct { EXPAND_CK_ID thisobj; int index; char name[1024]; char type[1024]; CKDWORD type_guid[2]; EXPAND_CK_ID belong_to; -}; +}db_pOut; -typedef struct db_bIO { +typedef struct { EXPAND_CK_ID thisobj; int index; char name[1024]; EXPAND_CK_ID belong_to; -}; +}db_bIO; typedef db_bIO db_bIn; typedef db_bIO db_bOut; -typedef struct db_bLink { +typedef struct { EXPAND_CK_ID input; EXPAND_CK_ID output; int delay; @@ -91,24 +91,24 @@ typedef struct db_bLink { EXPAND_CK_ID output_obj; bLinkInputOutputType output_type; int output_index; -}; +}db_bLink; -typedef struct db_pLocal { +typedef struct { EXPAND_CK_ID thisobj; char name[1024]; char type[1024]; CKDWORD type_guid[2]; BOOL is_setting; EXPAND_CK_ID belong_to; -}; +}db_pLocal; -typedef struct db_pLocalData { +typedef struct { char field[1024]; char data[1024]; EXPAND_CK_ID belong_to; -}; +}db_pLocalData; -typedef struct db_pLink { +typedef struct { EXPAND_CK_ID input; EXPAND_CK_ID output; EXPAND_CK_ID belong_to; @@ -122,14 +122,14 @@ typedef struct db_pLink { pLinkInputOutputType output_type; BOOL output_is_bb; int output_index; -}; +}db_pLink; -typedef struct db_pOper { +typedef struct { EXPAND_CK_ID thisobj; char op[1024]; CKDWORD op_guid[2]; EXPAND_CK_ID belong_to; -}; +}db_pOper; #pragma endregion diff --git a/SuperScriptMaterializer/script_export.cpp b/SuperScriptMaterializer/script_export.cpp index 25bd843..1032ab3 100644 --- a/SuperScriptMaterializer/script_export.cpp +++ b/SuperScriptMaterializer/script_export.cpp @@ -6,33 +6,7 @@ #pragma region inline func -inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) { - 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 +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) { //WARNING: i only choose one between [DirectSource] and [SharedSource] bucause i don't find any pIn both have these two field CKParameter* directSource = NULL; CKObject* ds_Owner = NULL; @@ -59,7 +33,7 @@ inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* hel } else { //pOper helper->_db_pLink->input_index = 0; - + } } } @@ -88,13 +62,46 @@ inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* hel if (sharedSource != NULL || directSource != NULL) { helper->_db_pLink->output = cache->GetID(); 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_index = index; helper->_db_pLink->belong_to = grandparents; 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 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; //pIn diff --git a/SuperScriptMaterializer/script_export.h b/SuperScriptMaterializer/script_export.h index 3dc0fe2..c1b446e 100644 --- a/SuperScriptMaterializer/script_export.h +++ b/SuperScriptMaterializer/script_export.h @@ -4,7 +4,8 @@ #include "stdafx.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_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); diff --git a/SuperScriptViewer/DecoratorConstValue.py b/SuperScriptViewer/DecoratorConstValue.py index fe00f77..16fcfab 100644 --- a/SuperScriptViewer/DecoratorConstValue.py +++ b/SuperScriptViewer/DecoratorConstValue.py @@ -1,3 +1,5 @@ +import json + FONT_SIZE = 12 GRAPH_POFFSET = 40 # 主体bb的p距离左边框距离 @@ -5,17 +7,16 @@ GRAPH_BOFFSET = 40 # 主体bb的b距离上边框距离 GRAPH_PSPAN = 20 # 主体bb的每个p之间的水平间距 GRAPH_BSPAN = 20 # 主体bb的每个b之间的垂直间距 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_PLOCAL = 10 # 每个bb上面挂载的plocal和被挂载bb之间的垂直距离 GRAPH_CONTENTOFFSET_X = 40 # 绘图内容原点到左边框的距离 GRAPH_CONTENTOFFSET_Y = 40 # 绘图内容原点到顶边框的距离 - BB_POFFSET = 20 # bb框中的p距离左边框距离 BB_BOFFSET = 10 # bb框中的b距离上边框距离 BB_PSPAN = 20 # bb框每个p之间的水平间距 BB_BSPAN = 20 # bb框每个b之间的垂直间距 -BB_PBSIZE = 6 # bb框中o和b的正方形符号的边长 - +BB_PBSIZE = 6 # bb框中o和b的正方形符号的边长(扩展到graph中的p/b大小) CELL_WIDTH = 15 CELL_HEIGHT = 5 @@ -29,11 +30,31 @@ class dbBLinkInputOutputType(object): INPUT = 0 OUTPUT = 1 -class LinkType(object): +class CellType(object): PLOCAL = 0 - SHORTCUR = 1 + SHORTCUT = 1 PIO = 2 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): def __init__(self, ckid, layer): @@ -45,14 +66,15 @@ class BBResult(object): def __init__(self, name, assistName, pin, pout, bin, bout, expandable): self.name = name self.assistName = assistName + self.ptargetData = None self.pin = int(pin) - self.pinData = [] + self.pinData = None self.pout = int(pout) - self.poutData = [] + self.poutData = None self.bin = int(bin) - self.binData = [] + self.binData = None self.bout = int(bout) - self.boutData = [] + self.boutData = None self.x = 0.0 self.y = 0.0 self.width = 0.0 @@ -60,7 +82,7 @@ class BBResult(object): self.expandable = expandable 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 wp = max(self.pin, self.pout) * (BB_PBSIZE + BB_PSPAN) @@ -74,13 +96,13 @@ class OperResult(object): self.name = name self.x = 0.0 self.y = 0.0 - self.pinData = [] - self.poutData = [] + self.pinData = None + self.poutData = None self.height = 0.0 self.width = 0.0 def computSize(self): - wText = len(self.name) * FONT_SIZE / 2 + wText = len(self.name) * FONT_SIZE / 3 * 2 hText = FONT_SIZE * 3 wp = 2 * BB_POFFSET + 2 * (BB_PBSIZE + BB_PSPAN) @@ -88,3 +110,18 @@ class OperResult(object): self.width = max(wp, wText) 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 \ No newline at end of file diff --git a/SuperScriptViewer/DecoratorCore.py b/SuperScriptViewer/DecoratorCore.py index c6c6424..b70b9f5 100644 --- a/SuperScriptViewer/DecoratorCore.py +++ b/SuperScriptViewer/DecoratorCore.py @@ -1,6 +1,6 @@ import sqlite3 import DecoratorConstValue as dcv -import queue +import json def run(): exportDb = sqlite3.connect('export.db') @@ -16,8 +16,12 @@ def run(): decorateGraph(exportDb, decorateDb, graphList) # decorate each graph + currentGraphBlockCell = {} 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) exportDb.close() @@ -63,7 +67,7 @@ def decorateGraph(exDb, deDb, graph): # sub bb 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() 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 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 # flat bb tree arrangedLayer+=1 @@ -82,7 +87,7 @@ def buildBlock(exDb, deDb, target): bbResult = {} bb_layer_map = {} 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(): 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)) @@ -103,7 +108,7 @@ def buildBlock(exDb, deDb, target): processedOper = set() pluggedOper = {} occupiedLayerCountForSpecificBB = {} - exCur.execute('SELECT [thisobj] FROM pOper WHERE [belong_to] == ?', (target, )) + exCur.execute('SELECT [thisobj] FROM pOper WHERE [belong_to] == ?', (target,)) newCur = exDb.cursor() newCur2 = exDb.cursor() for i in exCur.fetchall(): @@ -151,7 +156,7 @@ def buildBlock(exDb, deDb, target): # calc oper position # flat oper tree 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 for i in exCur.fetchall(): if i[0] not in processedOper: @@ -169,7 +174,7 @@ def buildBlock(exDb, deDb, target): jCache = pluggedOper[i][j] baseX = cache.x 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.computSize() cache2.x = baseX @@ -178,42 +183,74 @@ def buildBlock(exDb, deDb, target): operResult[q] = cache2 # query bb pin's data + listCache = [] + listItemCache = None for i in allBB: 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(): - cache.binData.append(str(j[0])) - exCur.execute("SELECT [thisobj] FROM bOut WHERE [belong_to] == ? ORDER BY [index];", (i, )) + listItemCache = dcv.PinInformation(j[0], j[1], '') + 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(): - cache.boutData.append(str(j[0])) - exCur.execute("SELECT [thisobj] FROM pIn WHERE [belong_to] == ? ORDER BY [index];", (i, )) + listItemCache = dcv.PinInformation(j[0], j[1], '') + 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(): - cache.pinData.append(str(j[0])) - exCur.execute("SELECT [thisobj] FROM pOut WHERE [belong_to] == ? ORDER BY [index];", (i, )) + listItemCache = dcv.PinInformation(j[0], j[1], j[2]) + 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(): - 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 for i in operResult.keys(): 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(): - cache.pinData.append(str(j[0])) - exCur.execute("SELECT [thisobj] FROM pOut WHERE [belong_to] == ? ORDER BY [index];", (i, )) + listItemCache = dcv.PinInformation(j[0], j[1], j[2]) + 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(): - 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 for i in bbResult.keys(): cache = bbResult[i] + currentGraphBlockCell[i] = dcv.BlockCellItem(cache.x, cache.y, cache.width, cache.height) 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(): cache = operResult[i] - deCur.execute("INSERT INTO block VALUES (?, ?, ?, '', ?, ?, '', '', ?, ?, ?, ?, -1)", - (target, i, cache.name, ','.join(cache.pinData), ','.join(cache.poutData), cache.x, cache.y, cache.width, cache.height)) - - return (layer_y[0] - dcv.CELL_HEIGHT, bbResult, operResult) + currentGraphBlockCell[i] = dcv.BlockCellItem(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)) def recursiveBuildBBTree(node, exCur, processedBB, layer, depth, graphId): realLinkedBB = set() @@ -229,7 +266,8 @@ def recursiveBuildBBTree(node, exCur, processedBB, layer, depth, graphId): # ignore duplicated bb # 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 processedBB.update(realLinkedBB) @@ -262,8 +300,9 @@ def recursiveBuildOperTree(oper, bb_layer_map, processedOper, occupiedLayerMap, if oper in processedOper: return - # for avoid fucking export parameter feature. check whether self is current graph's memeber - exCur.execute("SELECT [belong_to] FROM pOper WHERE [thisobj] == ?;", (oper, )) + # for avoid fucking export parameter feature. check whether self is + # current graph's memeber + exCur.execute("SELECT [belong_to] FROM pOper WHERE [thisobj] == ?;", (oper,)) if (exCur.fetchone()[0] != graphId): # fuck export param, exit return @@ -289,3 +328,184 @@ def recursiveBuildOperTree(oper, bb_layer_map, processedOper, occupiedLayerMap, for i in res: 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 \ No newline at end of file diff --git a/SuperScriptViewer/ServerCore.py b/SuperScriptViewer/ServerCore.py index bea3789..4742f98 100644 --- a/SuperScriptViewer/ServerCore.py +++ b/SuperScriptViewer/ServerCore.py @@ -25,10 +25,7 @@ def close_connection(exception): @app.template_global(name = 'pinDecoder') def block_pin_filter(target): - if target == '': - return [] - # return json.loads(target) - return target.split(',') + return json.loads(target) @app.route('/', methods=['GET']) def indexHandle(): @@ -58,20 +55,34 @@ def scriptHandle(scriptPath): for i in range(len(pathSlice) - 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 cur.execute('SELECT * FROM block WHERE [belong_to_graph] = ?', (pathSlice[-1], )) 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 return render_template('viewer.html', currentPath = scriptPath, + gWidth = width, + gHeight = height, hamburgerHistory = hamburger, static_css = url_for('static', filename='site.css'), static_js = url_for('static', filename='site.js'), hamburgerCurrent = currentHamburger, - blocks = dbBlocks) + blocks = dbBlocks, + cells = dbCells) def run(): app.run() diff --git a/SuperScriptViewer/SuperScriptViewer.py b/SuperScriptViewer/SuperScriptViewer.py index bd898c7..07388bc 100644 --- a/SuperScriptViewer/SuperScriptViewer.py +++ b/SuperScriptViewer/SuperScriptViewer.py @@ -4,7 +4,7 @@ import os import sys # debug use -# os.remove('decorate.db') +os.remove('decorate.db') print('Super Script View') if not os.path.isfile("decorate.db"): diff --git a/SuperScriptViewer/static/site.css b/SuperScriptViewer/static/site.css index c86a378..b209aac 100644 --- a/SuperScriptViewer/static/site.css +++ b/SuperScriptViewer/static/site.css @@ -41,4 +41,34 @@ div.block-body { position: absolute; background: #8f8f8f; 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; } \ No newline at end of file diff --git a/SuperScriptViewer/templates/viewer.html b/SuperScriptViewer/templates/viewer.html index 2dcdcea..b9338d3 100644 --- a/SuperScriptViewer/templates/viewer.html +++ b/SuperScriptViewer/templates/viewer.html @@ -29,25 +29,26 @@