diff --git a/.gitignore b/.gitignore
index fc8f233..9b84d6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,8 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+*.db
+
# User-specific files
*.rsuser
*.suo
diff --git a/SuperScriptMaterializer/database.cpp b/SuperScriptMaterializer/database.cpp
index 44883cd..4a8e772 100644
--- a/SuperScriptMaterializer/database.cpp
+++ b/SuperScriptMaterializer/database.cpp
@@ -118,6 +118,14 @@ void database::close() {
//stop job
sqlite3_exec(db, "commit;", NULL, NULL, &errmsg);
+ //create index for quick select in following app
+ sqlite3_exec(db, "begin;", NULL, NULL, &errmsg);
+ sqlite3_exec(db, "CREATE INDEX 'quick_where1' ON bIn (thisobj)", NULL, NULL, &errmsg);
+ sqlite3_exec(db, "CREATE INDEX 'quick_where2' ON bOut (thisobj)", NULL, NULL, &errmsg);
+ sqlite3_exec(db, "CREATE INDEX 'quick_where3' ON pIn (thisobj)", NULL, NULL, &errmsg);
+ sqlite3_exec(db, "CREATE INDEX 'quick_where4' ON pOut (thisobj)", NULL, NULL, &errmsg);
+ sqlite3_exec(db, "commit;", NULL, NULL, &errmsg);
+
//release res
sqlite3_close(db);
db = NULL;
diff --git a/SuperScriptMaterializer/script_export.cpp b/SuperScriptMaterializer/script_export.cpp
index dd49d93..56298c6 100644
--- a/SuperScriptMaterializer/script_export.cpp
+++ b/SuperScriptMaterializer/script_export.cpp
@@ -186,7 +186,7 @@ void IterateBehavior(CKBehavior* bhv, database* db, dbDataStructHelper* helper,
helper->_dbCKBehavior->priority = bhv->GetPriority();
helper->_dbCKBehavior->version = bhv->GetVersion();
helper->_dbCKBehavior->parent = parents;
- sprintf(helper->_dbCKBehavior->pin_count, "%d, %d, %d, %d, %d",
+ sprintf(helper->_dbCKBehavior->pin_count, "%d,%d,%d,%d,%d",
(bhv->IsUsingTarget() ? 1 : 0),
bhv->GetInputParameterCount(),
bhv->GetOutputParameterCount(),
diff --git a/SuperScriptViewer/DecoratorConstValue.py b/SuperScriptViewer/DecoratorConstValue.py
new file mode 100644
index 0000000..6e7f749
--- /dev/null
+++ b/SuperScriptViewer/DecoratorConstValue.py
@@ -0,0 +1,56 @@
+FONT_SIZE = 12
+
+GRAPH_POFFSET = 40
+GRAPH_BOFFSET = 40
+GRAPH_CONTENTOFFSET_X = 40
+GRAPH_CONTENTOFFSET_Y = 40
+GRAPH_PSPAN = 20
+GRAPH_BSPAN = 20
+GRAPH_LAYER_SPAN = 100
+GRAPH_BB_SPAN = 50
+
+BB_POFFSET = 20
+BB_BOFFSET = 10
+BB_PSPAN = 10
+BB_BSPAN = 10
+BB_PBSIZE = 6
+
+CELL_WIDTH = 15
+CELL_HEIGHT = 5
+
+
+class LinkType(object):
+ PLOCAL = 0
+ SHORTCUR = 1
+ PIO = 2
+ BIO = 3
+
+class BBTreeNode(object):
+ def __init__(self, ckid, layer):
+ self.bb = ckid
+ self.layer = layer
+ self.nodes = []
+
+class BBResult(object):
+ def __init__(self, name, assistName, pin, pout, bin, bout, expandable):
+ self.name = name
+ self.assistName = assistName
+ self.pin = int(pin)
+ self.pout = int(pout)
+ self.bin = int(bin)
+ self.bout = int(bout)
+ self.x = 0.0
+ self.y = 0.0
+ self.width = 0.0
+ self.height = 0.0
+ self.expandable = expandable
+
+ def computSize(self):
+ wText = max(len(self.name), len(self.assistName)) * FONT_SIZE
+ hText = FONT_SIZE * 4
+
+ wp = 2 * BB_POFFSET + max(self.pin, self.pout) * (BB_PBSIZE + BB_PSPAN)
+ hb = 2 * BB_BOFFSET + max(self.bin, self.bout) * (BB_PBSIZE + BB_BSPAN)
+
+ self.width = max(wp, wText)
+ self.height = max(hb, hText)
diff --git a/SuperScriptViewer/DecoratorCore.py b/SuperScriptViewer/DecoratorCore.py
index 8b13789..aa1d550 100644
--- a/SuperScriptViewer/DecoratorCore.py
+++ b/SuperScriptViewer/DecoratorCore.py
@@ -1 +1,159 @@
+import sqlite3
+import DecoratorConstValue as dcv
+import queue
+def run():
+ exportDb = sqlite3.connect('export.db')
+ decorateDb = sqlite3.connect('decorate.db')
+ exportCur = exportDb.cursor()
+ decorateCur = decorateDb.cursor()
+
+ # init table
+ print('Init decorate.dll')
+ initDecorateDb(decorateCur)
+ decorateDb.commit()
+
+ # decorate graph
+ graphList = []
+ decorateGraph(exportCur, decorateCur, graphList)
+
+ # decorate each graph
+ for i in graphList:
+ buildBBTree(exportCur, decorateCur, i)
+
+ # give up all change of eexport.db (because no change)
+ exportDb.close()
+ decorateDb.commit()
+ decorateDb.close()
+
+def initDecorateDb(cur):
+ cur.execute("CREATE TABLE graph([graph] INTEGER, [width] INTEGER, [height] INTEGER, [index] INTEGER, [belong_to] TEXT);")
+ cur.execute("CREATE TABLE info([target] INTEGER, [field] TEXT, [data] TEXT);")
+
+ cur.execute("CREATE TABLE block([belong_to_graph] INETGER, [thisobj] INTEGER, [name] TEXT, [assist_text] TEXT, [pin-pin] INTEGER, [pin-pout] INTEGER, [pin-bin] INTEGER, [pin-bout] INTEGER, [x] INTEGER, [y] INTEGER, [width] INTEGER, [height] INTEGER, [expandable] INTEGER);")
+ cur.execute("CREATE TABLE cell([belong_to_graph] INETGER, [thisobj] INTEGER, [name] TEXT, [assist_text] TEXT, [x] INTEGER, [y] INTEGER, [type] INTEGER);")
+ cur.execute("CREATE TABLE link([belong_to_graph] INETGER, [thisobj] INTEGER, [delay] INTEGER, [startobj] INTEGER, [endobj] INTEGER, [start_index] INTEGER, [end_index] INTEGER, [x1] INTEGER, [y1] INTEGER, [x2] INTEGER, [y2] INTEGER);")
+
+def decorateGraph(exCur, deCur, graph):
+ scriptMap = {}
+
+ exCur.execute("SELECT [behavior], [index], [name] FROM script;")
+ while True:
+ lines = exCur.fetchone()
+ if lines == None:
+ break
+ scriptMap[lines[0]] = (lines[1], lines[2])
+
+ exCur.execute("SELECT [thisobj], [type] FROM behavior WHERE [type] != 0;")
+ while True:
+ lines = exCur.fetchone()
+ if lines == None:
+ break
+
+ # add into global graph list
+ graph.append(lines[0])
+
+ # width and height will be computed by following method and use update
+ # statement to change it
+ if lines[1] == 1:
+ # script
+ deCur.execute("INSERT INTO graph VALUES(?, 0, 0, ?, ?)", (lines[0], scriptMap[lines[0]][0], scriptMap[lines[0]][1]))
+ else:
+ # sub bb
+ deCur.execute("INSERT INTO graph VALUES(?, 0, 0, -1, '')", (lines[0],))
+
+def buildBBTree(exCur, deCur, target):
+ # sort inner bb
+ # use current graph input as the start point
+ treeRoot = dcv.BBTreeNode(target, -1)
+ processedBB = set()
+ bb_layer_map = {}
+ # layer start from 1, 0 is occupied for pLocal
+ arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, deCur, processedBB, 1, 0, target)
+
+ # get no linked bb and place them. linked bb position will be computed following
+ # calc each bb's x postion, as for y, we need wait for oOper to confirm each layer's height
+ arrangedLayer+=1
+ singleBB = set()
+ bbResult = {}
+ baseX = dcv.GRAPH_CONTENTOFFSET_X
+ 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[0], pinSplit[1], pinSplit[2], pinSplit[3], (i[0] if i[2] != 0 else -1))
+ bbCache.computSize()
+ if i[0] not in processedBB:
+ # single bb, process it
+ singleBB.add(i[0])
+ bbCache.x = baseX
+ baseX += bbCache.width + dcv.GRAPH_BB_SPAN
+
+ bbResult[i[0]] = bbCache
+
+ recursiveCalcBBX(treeRoot, dcv.GRAPH_CONTENTOFFSET_X, bbResult)
+ pass
+
+def recursiveBuildBBTree(node, exCur, deCur, processedBB, layer, depth, graphId):
+ cache = []
+ if depth == 0:
+ # find bIn
+ exCur.execute('SELECT [thisobj] FROM bIn WHERE [belong_to] == ?;', (node.bb,))
+ else:
+ # find bOut
+ exCur.execute('SELECT [thisobj] FROM bOut WHERE [belong_to] == ?;', (node.bb,))
+
+ for i in exCur.fetchall():
+ cache.append(i[0])
+
+ if (len(cache) == 0):
+ return layer
+
+ # find links
+ exCur.execute("SELECT [output] FROM bLink WHERE ([belong_to] == ? AND ([input] IN ({})));".format(','.join(map(lambda x:str(x), cache))), (graphId,))
+ cache.clear()
+ for i in exCur.fetchall():
+ cache.append(i[0])
+
+ if (len(cache) == 0):
+ return layer
+
+ #find bIn (find in bIn list to omit the line linked to current bb's output)
+ exCur.execute("SELECT [belong_to] FROM bIn WHERE [thisobj] IN ({});".format(','.join(map(lambda x:str(x), cache))))
+ cache.clear()
+ for i in exCur.fetchall():
+ cache.append(i[0])
+
+ if (len(cache) == 0):
+ return layer
+
+ # ignore duplicated bb
+ realLinkedBB = set(cache)
+ # calc need processed bb first
+ # and register all gotten bb. for preventing infinity resursive func and keep bb tree structure
+ realLinkedBB = realLinkedBB - processedBB
+ processedBB.update(realLinkedBB)
+
+ # iterate each bb
+ for i in realLinkedBB:
+ # recursive execute this method
+ newNode = dcv.BBTreeNode(i, layer)
+ layer = recursiveBuildBBTree(newNode, exCur, deCur, processedBB, layer, depth + 1, graphId)
+ # add new node into list and ++layer
+ layer+=1
+ node.nodes.append(newNode)
+
+ # minus extra ++ due to for
+ if (len(realLinkedBB) != 0):
+ layer-=1
+
+ return layer
+
+
+def recursiveCalcBBX(node, baseX, resultList):
+ maxExpand = 0
+ for i in node.nodes:
+ resultList[i.bb].x = baseX
+ maxExpand = max(maxExpand, resultList[i.bb].width)
+
+ for i in node.nodes:
+ recursiveCalcBBX(i, baseX + maxExpand + dcv.GRAPH_BB_SPAN, resultList)
\ No newline at end of file
diff --git a/SuperScriptViewer/SuperScriptViewer.py b/SuperScriptViewer/SuperScriptViewer.py
index 6e0e104..4199daf 100644
--- a/SuperScriptViewer/SuperScriptViewer.py
+++ b/SuperScriptViewer/SuperScriptViewer.py
@@ -1 +1,20 @@
+import DecoratorCore
+import os
+import sys
+
+# debug use
+os.remove('decorate.db')
+
+
print('Super Script View')
+if not os.path.isfile("decorate.db"):
+ print('No decorated database, generating it.')
+ if not os.path.isfile('export.db'):
+ print('No export.db. Fail to generate. Exit app.')
+ sys.exit(1)
+
+ # generate db
+ DecoratorCore.run()
+ print('Decorated database generating done.')
+
+# todo: start flask
diff --git a/SuperScriptViewer/SuperScriptViewer.pyproj b/SuperScriptViewer/SuperScriptViewer.pyproj
index 44be931..9e678c2 100644
--- a/SuperScriptViewer/SuperScriptViewer.pyproj
+++ b/SuperScriptViewer/SuperScriptViewer.pyproj
@@ -21,6 +21,9 @@
false
+
+ Code
+
Code
diff --git a/SuperScriptViewer/templates/viewer.html b/SuperScriptViewer/templates/viewer.html
index aeb0584..30b00ea 100644
--- a/SuperScriptViewer/templates/viewer.html
+++ b/SuperScriptViewer/templates/viewer.html
@@ -23,24 +23,33 @@
>>
Current BB
-
+
-
-
-
-
-
-
-
-
-
Get Cell
+
+
+
+
+
+
+
+
+
+
+
Get Cell
+
+
+