update viewer and add more field for exporter

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

View File

@ -54,51 +54,51 @@ void database::open(const char* file) {
//init table //init table
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
result = sqlite3_exec(db, 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); NULL, NULL, &errmsg);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
@ -119,12 +119,12 @@ void database::close() {
sqlite3_exec(db, "commit;", NULL, NULL, &errmsg); sqlite3_exec(db, "commit;", NULL, NULL, &errmsg);
//create index for quick select in following app //create index for quick select in following app
sqlite3_exec(db, "begin;", 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_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_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_where3] ON pIn (thisobj)", NULL, NULL, &errmsg);
sqlite3_exec(db, "CREATE INDEX 'quick_where4' ON pOut (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, "commit;", NULL, NULL, &errmsg);*/
//release res //release res
sqlite3_close(db); sqlite3_close(db);
@ -244,10 +244,16 @@ void database::write_bOut(db_bOut* data) {
void database::write_bLink(db_bLink* data) { void database::write_bLink(db_bLink* data) {
if (db == NULL) return; 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->input,
data->output, data->output,
data->delay, data->delay,
data->input_obj,
data->input_type,
data->input_index,
data->output_obj,
data->output_type,
data->output_index,
data->belong_to); data->belong_to);
sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); 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) { void database::write_pLink(db_pLink* data) {
if (db == NULL) return; 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->input,
data->output, 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); data->belong_to);
sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); sqlite3_exec(db, commandStr, NULL, NULL, &errmsg);

View File

@ -7,6 +7,16 @@
#pragma region data struct define #pragma region data struct define
typedef long EXPAND_CK_ID; 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 { typedef struct dbCKBehavior {
EXPAND_CK_ID thisobj; EXPAND_CK_ID thisobj;
@ -73,6 +83,14 @@ typedef struct db_bLink {
EXPAND_CK_ID output; EXPAND_CK_ID output;
int delay; int delay;
EXPAND_CK_ID belong_to; 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 { typedef struct db_pLocal {
@ -94,6 +112,16 @@ typedef struct db_pLink {
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;
//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 { typedef struct db_pOper {

View File

@ -1,4 +1,6 @@
#include "script_export.h" #include "script_export.h"
//disable shit tip
#pragma warning(disable:26812)
#define changeSuffix(a) prefix[endIndex]='\0';strcat(prefix,a) #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); 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->thisobj = cache->GetID();
helper->_db_pIn->index = index; helper->_db_pIn->index = index;
strcpy(helper->_db_pIn->name, cache->GetName()); 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); db->write_pIn(helper->_db_pIn);
//=========try generate pLink //=========try generate pLink
EXPAND_CK_ID origin = -1; //WARNING: i only choose one between [DirectSource] and [SharedSource] bucause i don't find any pIn both have these two field
if (cache->GetDirectSource()) origin = cache->GetDirectSource()->GetID(); CKParameter* directSource = NULL;
if (cache->GetSharedSource()) origin = cache->GetSharedSource()->GetID(); CKObject* ds_Owner = NULL;
if (origin == -1) return; CKParameterIn* sharedSource = NULL;
helper->_db_pLink->input = origin; CKBehavior* ss_Owner = NULL;
helper->_db_pLink->output = cache->GetID(); if (directSource = cache->GetDirectSource()) {
helper->_db_pLink->belong_to = grandparents; 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->thisobj = cache->GetID();
helper->_db_pOut->index = index; helper->_db_pOut->index = index;
strcpy(helper->_db_pOut->name, cache->GetName()); strcpy(helper->_db_pOut->name, cache->GetName());
@ -55,11 +111,35 @@ inline void proc_pOut(CKParameterOut* cache, database* db, dbDataStructHelper* h
//=========try generate pLink //=========try generate pLink
CKParameter* cache_Dest = NULL; CKParameter* cache_Dest = NULL;
CKObject* cache_DestOwner = NULL;
for (int j = 0, jCount = cache->GetDestinationCount(); j < jCount; j++) { for (int j = 0, jCount = cache->GetDestinationCount(); j < jCount; j++) {
cache_Dest = cache->GetDestination(j); cache_Dest = cache->GetDestination(j);
helper->_db_pLink->input = cache->GetID(); 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(); 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; helper->_db_pLink->belong_to = grandparents;
db->write_pLink(helper->_db_pLink); 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) { inline void proc_bLink(CKBehaviorLink* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents) {
helper->_db_bLink->input = cache->GetInBehaviorIO()->GetID(); CKBehaviorIO* io = cache->GetInBehaviorIO();
helper->_db_bLink->output = cache->GetOutBehaviorIO()->GetID(); 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->delay = cache->GetActivationDelay();
helper->_db_bLink->belong_to = parents; 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); db->write_pOper(helper->_db_pOper);
//export 2 input param and 1 output param //export 2 input param and 1 output param
proc_pIn(cache->GetInParameter1(), 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); proc_pIn(cache->GetInParameter2(), db, helper, cache->GetID(), parents, 1, FALSE);
proc_pOut(cache->GetOutParameter(), db, helper, cache->GetID(), parents, 0); 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; int count = 0, i = 0;
//pIn //pIn
for (i = 0, count = bhv->GetInputParameterCount(); i < count; i++) 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 //pOut
for (i = 0, count = bhv->GetOutputParameterCount(); i < count; i++) 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 //bIn
for (i = 0, count = bhv->GetInputCount(); i < count; i++) for (i = 0, count = bhv->GetInputCount(); i < count; i++)
proc_bIn(bhv->GetInput(i), db, helper, bhv->GetID(), i); proc_bIn(bhv->GetInput(i), db, helper, bhv->GetID(), i);

View File

@ -5,8 +5,8 @@
#include "database.h" #include "database.h"
inline void proc_pTarget(CKParameterIn* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents); 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_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); 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);
inline void proc_bOut(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); inline void proc_bLink(CKBehaviorLink* cache, database* db, dbDataStructHelper* helper, EXPAND_CK_ID parents);

View File

@ -2,12 +2,10 @@ FONT_SIZE = 12
GRAPH_POFFSET = 40 GRAPH_POFFSET = 40
GRAPH_BOFFSET = 40 GRAPH_BOFFSET = 40
GRAPH_CONTENTOFFSET_X = 40
GRAPH_CONTENTOFFSET_Y = 40
GRAPH_PSPAN = 20 GRAPH_PSPAN = 20
GRAPH_BSPAN = 20 GRAPH_BSPAN = 20
GRAPH_LAYER_SPAN = 100 GRAPH_LAYER_SPAN = 50
GRAPH_BB_SPAN = 50 GRAPH_BB_SPAN = 25
BB_POFFSET = 20 BB_POFFSET = 20
BB_BOFFSET = 10 BB_BOFFSET = 10
@ -18,6 +16,9 @@ BB_PBSIZE = 6
CELL_WIDTH = 15 CELL_WIDTH = 15
CELL_HEIGHT = 5 CELL_HEIGHT = 5
GRAPH_CONTENTOFFSET_X = 40
GRAPH_CONTENTOFFSET_Y = 40
class LinkType(object): class LinkType(object):
PLOCAL = 0 PLOCAL = 0
@ -54,3 +55,26 @@ class BBResult(object):
self.width = max(wp, wText) self.width = max(wp, wText)
self.height = max(hb, hText) 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 # decorate each graph
for i in graphList: 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) # give up all change of eexport.db (because no change)
exportDb.close() exportDb.close()
@ -27,12 +27,12 @@ def run():
decorateDb.close() decorateDb.close()
def initDecorateDb(cur): 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 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 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] INTEGER, [y] INTEGER, [type] 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] INTEGER, [y1] INTEGER, [x2] INTEGER, [y2] 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): def decorateGraph(exCur, deCur, graph):
scriptMap = {} scriptMap = {}
@ -44,7 +44,7 @@ def decorateGraph(exCur, deCur, graph):
break break
scriptMap[lines[0]] = (lines[1], lines[2]) 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: while True:
lines = exCur.fetchone() lines = exCur.fetchone()
if lines == None: if lines == None:
@ -57,41 +57,83 @@ def decorateGraph(exCur, deCur, graph):
# statement to change it # statement to change it
if lines[1] == 1: if lines[1] == 1:
# script # 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: else:
# sub bb # 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 # sort inner bb
# use current graph input as the start point # use current graph input as the start point
treeRoot = dcv.BBTreeNode(target, -1) treeRoot = dcv.BBTreeNode(target, -1)
processedBB = set() processedBB = set()
bb_layer_map = {} # layer start from 2, 0 is occupied for pLocal, 1 is occupied for pOper
# layer start from 1, 0 is occupied for pLocal arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, deCur, processedBB, 2, 0, target)
arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, deCur, processedBB, 1, 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, we need wait for oOper to confirm each layer's height # calc each bb's x postion, as for y, calc later
arrangedLayer+=1 arrangedLayer+=1
singleBB = set() singleBB = set()
bbResult = {} bbResult = {}
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[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() bbCache.computSize()
if i[0] not in processedBB: if i[0] not in processedBB:
# single bb, process it # single bb, process it
singleBB.add(i[0]) singleBB.add(i[0])
bbCache.x = baseX bbCache.x = baseX
baseX += bbCache.width + dcv.GRAPH_BB_SPAN baseX += bbCache.width + dcv.GRAPH_BB_SPAN
bb_layer_map[i[0]] = arrangedLayer
bbResult[i[0]] = bbCache bbResult[i[0]] = bbCache
recursiveCalcBBX(treeRoot, dcv.GRAPH_CONTENTOFFSET_X, bbResult) recursiveCalcBBX(treeRoot, dcv.GRAPH_CONTENTOFFSET_X, bbResult, bb_layer_map)
pass
# 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): def recursiveBuildBBTree(node, exCur, deCur, processedBB, layer, depth, graphId):
cache = [] cache = []
@ -148,12 +190,12 @@ def recursiveBuildBBTree(node, exCur, deCur, processedBB, layer, depth, graphId)
return layer return layer
def recursiveCalcBBX(node, baseX, resultList, layerMap):
def recursiveCalcBBX(node, baseX, resultList):
maxExpand = 0 maxExpand = 0
for i in node.nodes: for i in node.nodes:
layerMap[i.bb] = i.layer
resultList[i.bb].x = baseX resultList[i.bb].x = baseX
maxExpand = max(maxExpand, resultList[i.bb].width) maxExpand = max(maxExpand, resultList[i.bb].width)
for i in node.nodes: 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 DecoratorCore
import ServerCore
import os 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"):
@ -18,3 +18,4 @@ if not os.path.isfile("decorate.db"):
print('Decorated database generating done.') print('Decorated database generating done.')
# todo: start flask # todo: start flask
ServerCore.run()

View File

@ -30,6 +30,9 @@
<Compile Include="ServerCore.py"> <Compile Include="ServerCore.py">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="ServerStruct.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="SuperScriptViewer.py" /> <Compile Include="SuperScriptViewer.py" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" /> <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> <p>Choose a script to read it.</p>
<br /> <br />
<br /> <br />
<h2>MfObj</h2> {% for key, value in scripts.items() %}
<h2>{{ key|e }}</h2>
<ol> <ol>
<li><a href="">shit</a></li> {% for i in value %}
<li><a href="">shit</a></li> <li><a href="{{ "./%s"|format(i.id) }}">{{ i.name }}</a></li>
<li><a href="">shit</a></li> {% endfor %}
<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>
</ol> </ol>
{% endfor %}
</body> </body>

View File

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