From b261712661105f54cd0621ab0af2180ab839b67b Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 9 Apr 2020 11:21:52 +0800 Subject: [PATCH] update viewer and add more field for exporter --- SuperScriptMaterializer/database.cpp | 54 +++++---- SuperScriptMaterializer/database.h | 28 +++++ SuperScriptMaterializer/script_export.cpp | 121 ++++++++++++++++++--- SuperScriptMaterializer/script_export.h | 4 +- SuperScriptViewer/DecoratorConstValue.py | 32 +++++- SuperScriptViewer/DecoratorCore.py | 80 ++++++++++---- SuperScriptViewer/ServerCore.py | 67 ++++++++++++ SuperScriptViewer/ServerStruct.py | 4 + SuperScriptViewer/SuperScriptViewer.py | 5 +- SuperScriptViewer/SuperScriptViewer.pyproj | 3 + SuperScriptViewer/static/site.css | 26 +++++ SuperScriptViewer/static/site.js | 0 SuperScriptViewer/templates/index.html | 25 +---- SuperScriptViewer/templates/viewer.html | 50 +++++---- 14 files changed, 394 insertions(+), 105 deletions(-) create mode 100644 SuperScriptViewer/ServerStruct.py create mode 100644 SuperScriptViewer/static/site.css create mode 100644 SuperScriptViewer/static/site.js diff --git a/SuperScriptMaterializer/database.cpp b/SuperScriptMaterializer/database.cpp index 4a8e772..3966401 100644 --- a/SuperScriptMaterializer/database.cpp +++ b/SuperScriptMaterializer/database.cpp @@ -54,51 +54,51 @@ void database::open(const char* file) { //init table result = sqlite3_exec(db, - "CREATE TABLE script('thisobj' INTEGER, 'name' TEXT, 'index' INTEGER, 'behavior' INTEGER);", + "CREATE TABLE script([thisobj] INTEGER, [name] TEXT, [index] INTEGER, [behavior] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE behavior('thisobj' INTEGER, 'name' TEXT, 'type' INTEGER, 'proto_name' TEXT, 'proto_guid' TEXT, 'flags' INTEGER, 'priority' INTEGER, 'version' INTEGER, 'pin_count' TEXT, 'parent' INTEGER);", + "CREATE TABLE behavior([thisobj] INTEGER, [name] TEXT, [type] INTEGER, [proto_name] TEXT, [proto_guid] TEXT, [flags] INTEGER, [priority] INTEGER, [version] INTEGER, [pin_count] TEXT, [parent] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE pTarget('thisobj' INTEGER, 'name' TEXT, 'type' TEXT, 'type_guid' TEXT, 'belong_to' INTEGER, 'direct_source' INTEGER, 'shard_source' INTEGER);", + "CREATE TABLE pTarget([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE pIn('thisobj' INTEGER, 'index' INTEGER, 'name' TEXT, 'type' TEXT, 'type_guid' TEXT, 'belong_to' INTEGER, 'direct_source' INTEGER, 'shard_source' INTEGER);", + "CREATE TABLE pIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE pOut('thisobj' INTEGER, 'index' INTEGER, 'name' TEXT, 'type' TEXT, 'type_guid' TEXT, 'belong_to' INTEGER);", + "CREATE TABLE pOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE bIn('thisobj' INTEGER, 'index' INTEGER, 'name' TEXT, 'belong_to' INTEGER);", + "CREATE TABLE bIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE bOut('thisobj' INTEGER, 'index' INTEGER, 'name' TEXT, 'belong_to' INTEGER);", + "CREATE TABLE bOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE bLink('input' INTEGER, 'output' INTEGER, 'delay' INTEGER, 'belong_to' INTEGER);", + "CREATE TABLE bLink([input] INTEGER, [output] INTEGER, [delay] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE pLocal('thisobj' INTEGER, 'name' TEXT, 'type' TEXT, 'type_guid' TEXT, 'is_setting' INTEGER, 'belong_to' INTEGER);", + "CREATE TABLE pLocal([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [is_setting] INTEGER, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE pLocalData('field' TEXT, 'data' TEXT, 'belong_to' INTEGER);", + "CREATE TABLE pLocalData([field] TEXT, [data] TEXT, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE pLink('input' INTEGER, 'output' INTEGER, 'belong_to' INTEGER);", + "CREATE TABLE pLink([input] INTEGER, [output] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_is_bb] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_is_bb] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; result = sqlite3_exec(db, - "CREATE TABLE pOper('thisobj' INTEGER, 'op' TEXT, 'op_guid' TEXT, 'belong_to' INTEGER);", + "CREATE TABLE pOper([thisobj] INTEGER, [op] TEXT, [op_guid] TEXT, [belong_to] INTEGER);", NULL, NULL, &errmsg); if (result != SQLITE_OK) goto fail; @@ -119,12 +119,12 @@ void database::close() { 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); + /*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); @@ -244,10 +244,16 @@ void database::write_bOut(db_bOut* data) { void database::write_bLink(db_bLink* data) { if (db == NULL) return; - sprintf(commandStr, "INSERT INTO bLink VALUES (%d, %d, %d, %d);", + sprintf(commandStr, "INSERT INTO bLink VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d);", data->input, data->output, data->delay, + data->input_obj, + data->input_type, + data->input_index, + data->output_obj, + data->output_type, + data->output_index, data->belong_to); sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); @@ -271,9 +277,17 @@ void database::write_pLocal(db_pLocal* data) { void database::write_pLink(db_pLink* data) { if (db == NULL) return; - sprintf(commandStr, "INSERT INTO pLink VALUES (%d, %d, %d);", + sprintf(commandStr, "INSERT INTO pLink VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);", data->input, data->output, + data->input_obj, + data->input_type, + data->input_is_bb, + data->input_index, + data->output_obj, + data->output_type, + data->output_is_bb, + data->output_index, data->belong_to); sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); diff --git a/SuperScriptMaterializer/database.h b/SuperScriptMaterializer/database.h index 5eea5fd..b1040c7 100644 --- a/SuperScriptMaterializer/database.h +++ b/SuperScriptMaterializer/database.h @@ -7,6 +7,16 @@ #pragma region data struct define typedef long EXPAND_CK_ID; +enum bLinkInputOutputType { + bLinkInputOutputType_INPUT, + bLinkInputOutputType_OUTPUT +}; +enum pLinkInputOutputType { + pLinkInputOutputType_PIN, + pLinkInputOutputType_POUT, + pLinkInputOutputType_PLOCAL, //when using pLocal, omit [index] and [input_is_bb] + pLinkInputOutputType_PTARGET //when using pTarget, omit [index] and [input_is_bb] +}; typedef struct dbCKBehavior { EXPAND_CK_ID thisobj; @@ -73,6 +83,14 @@ typedef struct db_bLink { EXPAND_CK_ID output; int delay; EXPAND_CK_ID belong_to; + + //additional field + EXPAND_CK_ID input_obj; + bLinkInputOutputType input_type; + int input_index; + EXPAND_CK_ID output_obj; + bLinkInputOutputType output_type; + int output_index; }; typedef struct db_pLocal { @@ -94,6 +112,16 @@ typedef struct db_pLink { EXPAND_CK_ID input; EXPAND_CK_ID output; EXPAND_CK_ID belong_to; + + //additional field + EXPAND_CK_ID input_obj; + pLinkInputOutputType input_type; + BOOL input_is_bb; + int input_index; + EXPAND_CK_ID output_obj; + pLinkInputOutputType output_type; + BOOL output_is_bb; + int output_index; }; typedef struct db_pOper { diff --git a/SuperScriptMaterializer/script_export.cpp b/SuperScriptMaterializer/script_export.cpp index 56298c6..47a851e 100644 --- a/SuperScriptMaterializer/script_export.cpp +++ b/SuperScriptMaterializer/script_export.cpp @@ -1,4 +1,6 @@ #include "script_export.h" +//disable shit tip +#pragma warning(disable:26812) #define changeSuffix(a) prefix[endIndex]='\0';strcat(prefix,a) @@ -17,7 +19,7 @@ inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* 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) { +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()); @@ -31,18 +33,72 @@ inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* hel db->write_pIn(helper->_db_pIn); //=========try generate pLink - EXPAND_CK_ID origin = -1; - if (cache->GetDirectSource()) origin = cache->GetDirectSource()->GetID(); - if (cache->GetSharedSource()) origin = cache->GetSharedSource()->GetID(); - if (origin == -1) return; - helper->_db_pLink->input = origin; - helper->_db_pLink->output = cache->GetID(); - helper->_db_pLink->belong_to = grandparents; + //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; + CKParameterIn* sharedSource = NULL; + CKBehavior* ss_Owner = NULL; + if (directSource = cache->GetDirectSource()) { + helper->_db_pLink->input = directSource->GetID(); + if (directSource->GetClassID() == CKCID_PARAMETERLOCAL) { + //pLocal + helper->_db_pLink->input_obj = directSource->GetID(); + helper->_db_pLink->input_type = pLinkInputOutputType_PLOCAL; + helper->_db_pLink->input_is_bb = FALSE; + helper->_db_pLink->input_index = -1; + } else { + //pOut + ds_Owner = directSource->GetOwner(); + helper->_db_pLink->input_obj = ds_Owner->GetID(); + helper->_db_pLink->input_type = pLinkInputOutputType_POUT; + //WARNING: untested doe to GetClassID() may have chance to return Attributes or CKDataArray accoring to document + if (helper->_db_pLink->input_index = (ds_Owner->GetClassID() != CKCID_PARAMETEROPERATION)) { + //bb + helper->_db_pLink->input_index = ((CKBehavior*)ds_Owner)->GetOutputParameterPosition((CKParameterOut*)directSource); + + } else { + //pOper + helper->_db_pLink->input_index = 0; + + } + } + } + if (sharedSource = cache->GetSharedSource()) { + //pIn from BB + helper->_db_pLink->input = sharedSource->GetID(); + ss_Owner = (CKBehavior*)sharedSource->GetOwner(); + helper->_db_pLink->input_obj = ss_Owner->GetID(); + + if (ss_Owner->IsUsingTarget() && (ss_Owner->GetTargetParameter() == sharedSource)) { + //pTarget + helper->_db_pLink->input_type = pLinkInputOutputType_PTARGET; + helper->_db_pLink->input_is_bb = TRUE; + helper->_db_pLink->input_index = -1; + + } else { + //pIn + helper->_db_pLink->input_type = pLinkInputOutputType_PIN; + helper->_db_pLink->input_is_bb = TRUE; + helper->_db_pLink->input_index = ss_Owner->GetInputParameterPosition(sharedSource); + } + + + } + + 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_is_bb = executedFromBB; + helper->_db_pLink->output_index = index; + helper->_db_pLink->belong_to = grandparents; + + db->write_pLink(helper->_db_pLink); + } - db->write_pLink(helper->_db_pLink); } -inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index) { +inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) { helper->_db_pOut->thisobj = cache->GetID(); helper->_db_pOut->index = index; strcpy(helper->_db_pOut->name, cache->GetName()); @@ -55,11 +111,35 @@ inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* h //=========try generate pLink CKParameter* cache_Dest = NULL; + CKObject* cache_DestOwner = NULL; for (int j = 0, jCount = cache->GetDestinationCount(); j < jCount; j++) { cache_Dest = cache->GetDestination(j); helper->_db_pLink->input = cache->GetID(); + helper->_db_pLink->input_obj = parents; + helper->_db_pLink->input_type = pLinkInputOutputType_POUT; + helper->_db_pLink->input_is_bb = executedFromBB; + helper->_db_pLink->input_index = index; + helper->_db_pLink->output = cache_Dest->GetID(); + if (cache_Dest->GetClassID() == CKCID_PARAMETERLOCAL) { + //pLocal + helper->_db_pLink->output_obj = cache_Dest->GetID(); + helper->_db_pLink->output_type = pLinkInputOutputType_PLOCAL; + helper->_db_pLink->output_is_bb = FALSE; + helper->_db_pLink->output_index = -1; + + } else { + //pOut, it must belong to a BB + + cache_DestOwner = cache_Dest->GetOwner(); + helper->_db_pLink->output_obj = cache_DestOwner->GetID(); + helper->_db_pLink->output_type = pLinkInputOutputType_POUT; + helper->_db_pLink->output_is_bb = TRUE; + helper->_db_pLink->output_index = ((CKBehavior*)cache_DestOwner)->GetOutputParameterPosition((CKParameterOut*)cache_Dest); + + } + helper->_db_pLink->belong_to = grandparents; db->write_pLink(helper->_db_pLink); @@ -85,8 +165,15 @@ inline void proc_bOut(CKBehaviorIO* cache, database* db, dbDataStructHelper* hel } inline void proc_bLink(CKBehaviorLink* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) { - helper->_db_bLink->input = cache->GetInBehaviorIO()->GetID(); - helper->_db_bLink->output = cache->GetOutBehaviorIO()->GetID(); + CKBehaviorIO* io = cache->GetInBehaviorIO(); + helper->_db_bLink->input = io->GetID(); + helper->_db_bLink->input_type = (io->GetType() == CK_BEHAVIORIO_IN ? bLinkInputOutputType_INPUT : bLinkInputOutputType_OUTPUT); + helper->_db_bLink->input_index = (io->GetType() == CK_BEHAVIORIO_IN ? io->GetOwner()->GetInputPosition(io) : io->GetOwner()->GetOutputPosition(io)); + io = cache->GetOutBehaviorIO(); + helper->_db_bLink->output = io->GetID(); + helper->_db_bLink->output_type = (io->GetType() == CK_BEHAVIORIO_IN ? bLinkInputOutputType_INPUT : bLinkInputOutputType_OUTPUT); + helper->_db_bLink->output_index = (io->GetType() == CK_BEHAVIORIO_IN ? io->GetOwner()->GetInputPosition(io) : io->GetOwner()->GetOutputPosition(io)); + helper->_db_bLink->delay = cache->GetActivationDelay(); helper->_db_bLink->belong_to = parents; @@ -118,9 +205,9 @@ inline void proc_pOper(CKParameterOperation* cache, database* db, dbDataStructHe db->write_pOper(helper->_db_pOper); //export 2 input param and 1 output param - proc_pIn(cache->GetInParameter1(), db, helper, cache->GetID(), parents, 0); - proc_pIn(cache->GetInParameter2(), db, helper, cache->GetID(), parents, 1); - proc_pOut(cache->GetOutParameter(), db, helper, cache->GetID(), parents, 0); + proc_pIn(cache->GetInParameter1(), db, helper, cache->GetID(), parents, 0, FALSE); + proc_pIn(cache->GetInParameter2(), db, helper, cache->GetID(), parents, 1, FALSE); + proc_pOut(cache->GetOutParameter(), db, helper, cache->GetID(), parents, 0, FALSE); } @@ -201,10 +288,10 @@ void IterateBehavior(CKBehavior* bhv, database* db, dbDataStructHelper* helper, int count = 0, i = 0; //pIn for (i = 0, count = bhv->GetInputParameterCount(); i < count; i++) - proc_pIn(bhv->GetInputParameter(i), db, helper, bhv->GetID(), parents, i); + proc_pIn(bhv->GetInputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE); //pOut for (i = 0, count = bhv->GetOutputParameterCount(); i < count; i++) - proc_pOut(bhv->GetOutputParameter(i), db, helper, bhv->GetID(), parents, i); + proc_pOut(bhv->GetOutputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE); //bIn for (i = 0, count = bhv->GetInputCount(); i < count; i++) proc_bIn(bhv->GetInput(i), db, helper, bhv->GetID(), i); diff --git a/SuperScriptMaterializer/script_export.h b/SuperScriptMaterializer/script_export.h index f55cb65..3dc0fe2 100644 --- a/SuperScriptMaterializer/script_export.h +++ b/SuperScriptMaterializer/script_export.h @@ -5,8 +5,8 @@ #include "database.h" inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents); -inline void proc_pIn(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index); -inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index); +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); inline void proc_bOut(CKBehaviorIO* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents, int index); inline void proc_bLink(CKBehaviorLink* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents); diff --git a/SuperScriptViewer/DecoratorConstValue.py b/SuperScriptViewer/DecoratorConstValue.py index 6e7f749..b35843d 100644 --- a/SuperScriptViewer/DecoratorConstValue.py +++ b/SuperScriptViewer/DecoratorConstValue.py @@ -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) diff --git a/SuperScriptViewer/DecoratorCore.py b/SuperScriptViewer/DecoratorCore.py index aa1d550..ab0431e 100644 --- a/SuperScriptViewer/DecoratorCore.py +++ b/SuperScriptViewer/DecoratorCore.py @@ -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) \ No newline at end of file + recursiveCalcBBX(i, baseX + maxExpand + dcv.GRAPH_BB_SPAN, resultList, layerMap) diff --git a/SuperScriptViewer/ServerCore.py b/SuperScriptViewer/ServerCore.py index 8b13789..0049ca6 100644 --- a/SuperScriptViewer/ServerCore.py +++ b/SuperScriptViewer/ServerCore.py @@ -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('/', 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() + diff --git a/SuperScriptViewer/ServerStruct.py b/SuperScriptViewer/ServerStruct.py new file mode 100644 index 0000000..6b6a49f --- /dev/null +++ b/SuperScriptViewer/ServerStruct.py @@ -0,0 +1,4 @@ +class ScriptItem(object): + def __init__(self, name, id): + self.name = name + self.id = id diff --git a/SuperScriptViewer/SuperScriptViewer.py b/SuperScriptViewer/SuperScriptViewer.py index 4199daf..bd898c7 100644 --- a/SuperScriptViewer/SuperScriptViewer.py +++ b/SuperScriptViewer/SuperScriptViewer.py @@ -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() diff --git a/SuperScriptViewer/SuperScriptViewer.pyproj b/SuperScriptViewer/SuperScriptViewer.pyproj index 9e678c2..871403e 100644 --- a/SuperScriptViewer/SuperScriptViewer.pyproj +++ b/SuperScriptViewer/SuperScriptViewer.pyproj @@ -30,6 +30,9 @@ Code + + Code + diff --git a/SuperScriptViewer/static/site.css b/SuperScriptViewer/static/site.css new file mode 100644 index 0000000..d30a61f --- /dev/null +++ b/SuperScriptViewer/static/site.css @@ -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; +} \ No newline at end of file diff --git a/SuperScriptViewer/static/site.js b/SuperScriptViewer/static/site.js new file mode 100644 index 0000000..e69de29 diff --git a/SuperScriptViewer/templates/index.html b/SuperScriptViewer/templates/index.html index 2a45fa3..9fd8c0a 100644 --- a/SuperScriptViewer/templates/index.html +++ b/SuperScriptViewer/templates/index.html @@ -11,27 +11,14 @@

Choose a script to read it.



-

MfObj

+{% for key, value in scripts.items() %} +

{{ key|e }}

    -
  1. shit
  2. -
  3. shit
  4. -
  5. shit
  6. -
  7. shit
  8. -
  9. shit
  10. -
-

MfObj

-
    -
  1. shit
  2. -
  3. shit
  4. -
-

MfObj

-
    -
  1. shit
  2. -
  3. shit
  4. -
  5. shit
  6. -
  7. shit
  8. -
  9. shit
  10. + {% for i in value %} +
  11. {{ i.name }}
  12. + {% endfor %}
+{% endfor %} diff --git a/SuperScriptViewer/templates/viewer.html b/SuperScriptViewer/templates/viewer.html index 30b00ea..3a2fd0c 100644 --- a/SuperScriptViewer/templates/viewer.html +++ b/SuperScriptViewer/templates/viewer.html @@ -4,25 +4,23 @@ Script Viewer + +
-

Script Hierarchy

+

Script Hierarchy

-

>>

-

Base BB 1

-

>>

-

Base BB 1

-

>>

-

Base BB 1

-

>>

-

Base BB 1

+ {% for i in hamburgerHistory %} +

>>

+

{{ i|e }}

+ {% endfor %} -

>>

-

Current BB

+

>>

+

{{ hamburgerCurrent|e }}

@@ -31,18 +29,26 @@
-
-
-
-
-
-
-
-
-

Get Cell

+ {% for i in blocks %} +
+ {% for pin in range(i[4]) %} +
+ {% endfor %} + {% for pout in range(i[5]) %} +
+ {% endfor %} + {% for bin in range(i[6]) %} +
+ {% endfor %} + {% for bout in range(i[6]) %} +
+ {% endfor %} + +

{{ i[2]|e }}

+

{{ i[3]|e }}

- + {% endfor %} +