update viewer and add more field for exporter

This commit is contained in:
2020-04-09 11:21:52 +08:00
parent 2173836255
commit b261712661
14 changed files with 394 additions and 105 deletions

View File

@ -2,12 +2,10 @@ 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
GRAPH_LAYER_SPAN = 50
GRAPH_BB_SPAN = 25
BB_POFFSET = 20
BB_BOFFSET = 10
@ -18,6 +16,9 @@ BB_PBSIZE = 6
CELL_WIDTH = 15
CELL_HEIGHT = 5
GRAPH_CONTENTOFFSET_X = 40
GRAPH_CONTENTOFFSET_Y = 40
class LinkType(object):
PLOCAL = 0
@ -54,3 +55,26 @@ class BBResult(object):
self.width = max(wp, wText)
self.height = max(hb, hText)
class pOperArrangement(object):
def __init__(self, attachedBB, sublayer):
self.attachedBB = attachedBB
self.sublayer = sublayer
class OperResult(object):
def __init__(self, name, x):
self.name = name
self.x = x
self.y = 0.0
self.height = 0.0
self.width = 0.0
def computSize(self):
wText = len(self.name) * FONT_SIZE
hText = FONT_SIZE * 4
wp = 2 * BB_POFFSET + 2 * (BB_PBSIZE + BB_PSPAN)
hb = 2 * BB_BOFFSET + 0 * (BB_PBSIZE + BB_BSPAN)
self.width = max(wp, wText)
self.height = max(hb, hText)

View File

@ -19,7 +19,7 @@ def run():
# decorate each graph
for i in graphList:
buildBBTree(exportCur, decorateCur, i)
(plocal_layer, bbMap, operMap) = buildBB(exportCur, decorateCur, i)
# give up all change of eexport.db (because no change)
exportDb.close()
@ -27,12 +27,12 @@ def run():
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 graph([graph] INTEGER, [graph_name] TEXT, [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);")
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] REAL, [y] REAL, [width] REAL, [height] REAL, [expandable] INTEGER);")
cur.execute("CREATE TABLE cell([belong_to_graph] INETGER, [thisobj] INTEGER, [name] TEXT, [assist_text] TEXT, [x] REAL, [y] REAL, [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] REAL, [y1] REAL, [x2] REAL, [y2] REAL);")
def decorateGraph(exCur, deCur, graph):
scriptMap = {}
@ -44,7 +44,7 @@ def decorateGraph(exCur, deCur, graph):
break
scriptMap[lines[0]] = (lines[1], lines[2])
exCur.execute("SELECT [thisobj], [type] FROM behavior WHERE [type] != 0;")
exCur.execute("SELECT [thisobj], [type], [name] FROM behavior WHERE [type] != 0;")
while True:
lines = exCur.fetchone()
if lines == None:
@ -57,41 +57,83 @@ def decorateGraph(exCur, deCur, graph):
# 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]))
deCur.execute("INSERT INTO graph VALUES(?, ?, 0, 0, ?, ?)", (lines[0], lines[2], scriptMap[lines[0]][0], scriptMap[lines[0]][1]))
else:
# sub bb
deCur.execute("INSERT INTO graph VALUES(?, 0, 0, -1, '')", (lines[0],))
deCur.execute("INSERT INTO graph VALUES(?, ?, 0, 0, -1, '')", (lines[0], lines[2]))
def buildBBTree(exCur, deCur, target):
def buildBB(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)
# layer start from 2, 0 is occupied for pLocal, 1 is occupied for pOper
arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, deCur, processedBB, 2, 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
# calc each bb's x postion, as for y, calc later
arrangedLayer+=1
singleBB = set()
bbResult = {}
bb_layer_map = {}
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 = dcv.BBResult(i[1], i[3], pinSplit[1], pinSplit[2], pinSplit[3], pinSplit[4], (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
bb_layer_map[i[0]] = arrangedLayer
bbResult[i[0]] = bbCache
recursiveCalcBBX(treeRoot, dcv.GRAPH_CONTENTOFFSET_X, bbResult)
pass
recursiveCalcBBX(treeRoot, dcv.GRAPH_CONTENTOFFSET_X, bbResult, bb_layer_map)
# calc bb y
layer_height = {}
layer_y = {}
layer_height[0] = 25
layer_height[1] = 50
for i in bb_layer_map.keys():
curLayer = bb_layer_map[i]
if curLayer not in layer_height.keys():
layer_height[curLayer] = bbResult[i].height
else:
layer_height[curLayer] = max(layer_height.get(curLayer, 0), bbResult[i].height)
layer_height[arrangedLayer] = layer_height.get(arrangedLayer, 0) # make sure misc bb height exist
baseY = dcv.GRAPH_CONTENTOFFSET_Y
for i in range(arrangedLayer + 1):
baseY += layer_height[i] + dcv.GRAPH_LAYER_SPAN
layer_y[i] = baseY
for i in bbResult.keys():
cache = bbResult[i]
layer = bb_layer_map[i]
cache.y = layer_y[layer] - layer_height[layer] + cache.height
# calc poper
operResult = {}
baseX = dcv.GRAPH_CONTENTOFFSET_X
exCur.execute('SELECT [thisobj], [op] FROM pOper WHERE [belong_to] == ?', (target, ))
for i in exCur.fetchall():
cache = dcv.OperResult(i[1], baseX)
cache.computSize()
baseX += cache.width + dcv.GRAPH_BB_SPAN
cache.y = layer_y[1] - cache.height
operResult[i[0]] = cache
# write to database and return
for i in bbResult.keys():
cache = bbResult[i]
deCur.execute('INSERT INTO block VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (target, i, cache.name, cache.assistName, cache.pin, cache.pout, cache.bin, cache.bout, cache.x, cache.y, cache.width, cache.height, cache.expandable))
for i in operResult.keys():
cache = operResult[i]
deCur.execute("INSERT INTO block VALUES (?, ?, ?, '', 2, 1, 0, 0, ?, ?, ?, ?, -1)", (target, i, cache.name, cache.x, cache.y, cache.width, cache.height))
return (layer_y[0] - dcv.CELL_HEIGHT, bbResult, operResult)
def recursiveBuildBBTree(node, exCur, deCur, processedBB, layer, depth, graphId):
cache = []
@ -148,12 +190,12 @@ def recursiveBuildBBTree(node, exCur, deCur, processedBB, layer, depth, graphId)
return layer
def recursiveCalcBBX(node, baseX, resultList):
def recursiveCalcBBX(node, baseX, resultList, layerMap):
maxExpand = 0
for i in node.nodes:
layerMap[i.bb] = i.layer
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)
recursiveCalcBBX(i, baseX + maxExpand + dcv.GRAPH_BB_SPAN, resultList, layerMap)

View File

@ -1 +1,68 @@
from flask import Flask
from flask import g
from flask import render_template
from flask import url_for
from flask import request
import sqlite3
import ServerStruct as ss
app = Flask(__name__)
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect('decorate.db')
return db
@app.teardown_appcontext
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()
@app.route('/', methods=['GET'])
def indexHandle():
cur = get_db().cursor()
cur.execute("SELECT [graph], [graph_name], [belong_to] FROM graph WHERE [index] != -1 ORDER BY [belong_to], [index] ASC;")
data = {}
for i in cur.fetchall():
if i[2] not in data.keys():
data[i[2]] = [ss.ScriptItem(i[1], i[0])]
else:
data[i[2]].append(ss.ScriptItem(i[1], i[0]))
return render_template('index.html', scripts = data)
@app.route('/<path:scriptPath>', methods=['GET'])
def scriptHandle(scriptPath):
# comput hamburger
pathSlice = scriptPath.split('/')
cur = get_db().cursor()
cur.execute("SELECT [graph], [graph_name] FROM graph WHERE [graph] IN ({});".format(','.join(pathSlice)))
hamburgerMap = {}
hamburger = []
for i in cur.fetchall():
hamburgerMap[i[0]] = i[1]
for i in pathSlice:
hamburger.append(hamburgerMap[int(i)])
currentHamburger = hamburger.pop()
# get blocks
cur.execute('SELECT * FROM block WHERE [belong_to_graph] = ?', (pathSlice[-1],))
dbBlocks = cur.fetchall()
# todo:xxxxx
# render
return render_template('viewer.html',
hamburgerHistory = hamburger,
static_css = url_for('static', filename='site.css'),
static_js = url_for('static', filename='site.js'),
hamburgerCurrent = currentHamburger,
blocks = dbBlocks)
def run():
app.run()

View File

@ -0,0 +1,4 @@
class ScriptItem(object):
def __init__(self, name, id):
self.name = name
self.id = id

View File

@ -1,10 +1,10 @@
import DecoratorCore
import ServerCore
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"):
@ -18,3 +18,4 @@ if not os.path.isfile("decorate.db"):
print('Decorated database generating done.')
# todo: start flask
ServerCore.run()

View File

@ -30,6 +30,9 @@
<Compile Include="ServerCore.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="ServerStruct.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="SuperScriptViewer.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />

View File

@ -0,0 +1,26 @@
p.hamburger {
margin: 0 5px 0 5px;
padding: 0;
}
div.block-b {
position: absolute;
background: yellow;
}
div.block-p {
position: absolute;
background: blue;
}
p.block-text {
position: absolute;
margin: 0;
padding: 0;
}
div.block-body {
position: absolute;
background: #8f8f8f;
border: 1px solid #cfcfcf;
}

View File

View File

@ -11,27 +11,14 @@
<p>Choose a script to read it.</p>
<br />
<br />
<h2>MfObj</h2>
{% for key, value in scripts.items() %}
<h2>{{ key|e }}</h2>
<ol>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
</ol>
<h2>MfObj</h2>
<ol>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
</ol>
<h2>MfObj</h2>
<ol>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
<li><a href="">shit</a></li>
{% for i in value %}
<li><a href="{{ "./%s"|format(i.id) }}">{{ i.name }}</a></li>
{% endfor %}
</ol>
{% endfor %}
</body>

View File

@ -4,25 +4,23 @@
<head>
<meta charset="utf-8">
<title>Script Viewer</title>
<link rel="stylesheet" href="{{static_css}}">
<script src="{{static_js}}"></script>
</head>
<body style="display: flex; flex-flow: column; height: 100%; width: 100%; margin: 0; padding: 0;">
<div style="display: flex; background: #cfcfcf; flex-flow: row; width: 100%; height: 50px;">
<div style="display: flex; flex-flow: row; width: 100%; height: 100%; overflow: scroll;">
<p style="margin: 0 5px 0 5px; padding: 0;"><a href=""><b>Script Hierarchy</b></a></p>
<p class="hamburger"><a href="/"><b>Script Hierarchy</b></a></p>
<p style="margin: 0 5px 0 5px; padding: 0;">&gt;&gt;</p>
<p style="margin: 0 5px 0 5px; padding: 0;"><a href="">Base BB 1</a></p>
<p style="margin: 0 5px 0 5px; padding: 0;">&gt;&gt;</p>
<p style="margin: 0 5px 0 5px; padding: 0;"><a href="">Base BB 1</a></p>
<p style="margin: 0 5px 0 5px; padding: 0;">&gt;&gt;</p>
<p style="margin: 0 5px 0 5px; padding: 0;"><a href="">Base BB 1</a></p>
<p style="margin: 0 5px 0 5px; padding: 0;">&gt;&gt;</p>
<p style="margin: 0 5px 0 5px; padding: 0;"><a href="">Base BB 1</a></p>
{% for i in hamburgerHistory %}
<p class="hamburger">&gt;&gt;</p>
<p class="hamburger"><a href="{{ "../" * loop.revindex }}">{{ i|e }}</a></p>
{% endfor %}
<p style="margin: 0 5px 0 5px; padding: 0;">&gt;&gt;</p>
<p style="margin: 0 5px 0 5px; padding: 0;"><b>Current BB</b></p>
<p class="hamburger">&gt;&gt;</p>
<p class="hamburger"><b>{{ hamburgerCurrent|e }}</b></p>
</div>
<div style="width: 100px;">
@ -31,18 +29,26 @@
</div>
<div style="background: #7f7f7f; width: 100%; height: 100%; overflow: scroll; position: relative;">
<div>
<div
style="position: absolute; height: 50px; width: 200px; top: 200px; left: 300px; background: #8f8f8f; border: 1px solid #cfcfcf;">
<div style="position: absolute; height: 6px; width: 6px; top: 0; left: 20px; background: blue;"></div>
<div style="position: absolute; height: 6px; width: 6px; top: 0; left: 35px; background: blue;"></div>
<div style="position: absolute; height: 6px; width: 6px; bottom: 0; left: 20px; background: blue;">
</div>
<div style="position: absolute; height: 6px; width: 6px; top: 10px; left: 0; background: yellow;"></div>
<div style="position: absolute; height: 6px; width: 6px; top: 10px; right: 0; background: yellow;">
</div>
<p style="position: absolute; top: 10px; left: 10px; margin: 0; padding: 0;">Get Cell</p>
{% 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;">
{% for pin in range(i[4]) %}
<div class="block-p" style="height: 6px; width: 6px; top: 0; left: {{ 20 + pin * ( 6 + 20) }}px;"></div>
{% endfor %}
{% for pout in range(i[5]) %}
<div class="block-p" style="height: 6px; width: 6px; bottom: 0; left: {{ 20 + pout * ( 6 + 20) }}px;"></div>
{% endfor %}
{% for bin in range(i[6]) %}
<div class="block-b" style="height: 6px; width: 6px; top: {{ 10 + bin * ( 6 + 20) }}px; left: 0;"></div>
{% endfor %}
{% for bout in range(i[6]) %}
<div class="block-b" style="height: 6px; width: 6px; top: {{ 10 + bout * ( 6 + 20) }}px; right: 0;"></div>
{% endfor %}
<p class="block-text" style="top: 10px; left: 20px;">{{ i[2]|e }}</p>
<p class="block-text" style="top: 24px; left: 20px;"><i>{{ i[3]|e }}</i></p>
</div>
<svg version="1.1" width="1000px" height="1000px" style="position: absolute; top: 0; left: 0;">
{% endfor %}
<svg version="1.1" width="5000px" height="5000px" style="position: absolute; top: 0; left: 0;">
<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>