Commit fdb53010 authored by Claes Sjofors's avatar Claes Sjofors

Ge, variable index with [&( )] syntax, display of parent attributes for object...

Ge, variable index with [&( )] syntax, display of parent attributes for object graphs iwith .<, window for object graphs works for more than two levels
parent 4778b81c
......@@ -86,7 +86,7 @@ public class GrowFrame implements GraphApplIfc {
public String getObject() {
return instance;
}
public Object loadGrowCtx( String fname) {
public Object loadGrowCtx( String fname, String owner) {
return null;
}
public int loadSubgraph( String fname) {
......
......@@ -314,12 +314,51 @@ public class Graph implements GraphIfc, GrowApplIfc {
}
if ( (idx = str.indexOf("$object")) != -1) {
if ( appl != null) {
String oname = cmn.getOwner();
str = str.substring(0, idx) + oname + str.substring(idx+7);
for ( int i = 0; i < 4; i++) {
if ( (idx = str.indexOf("$object")) != -1) {
if ( appl != null) {
String oname = cmn.getOwner();
str = str.substring(0, idx) + oname + str.substring(idx+7);
}
}
else
break;
}
// Translate index variable
for ( int i = 0; i < 4; i++) {
if ( (idx = str.indexOf("[&(")) != -1) {
String iname = str.substring(idx+3);
int idx2 = iname.indexOf(')');
if ( idx2 != -1) {
String rest = iname.substring( idx2 + 1);
iname = iname.substring( 0, idx2);
CdhrInt ret = getGdh().getObjectInfoInt( iname);
if ( ret.evenSts()) break;
str = str.substring( 0, idx + 1) + ret.value + rest;
}
else
break;
}
else
break;
}
for ( int i = 0; i < 4; i++) {
// Remove attribute before
if ( (idx = str.indexOf(".<")) != -1) {
String rest = str.substring( idx + 2);
int idx2 = str.lastIndexOf( '.', idx - 2);
if ( idx2 != -1)
str = str.substring( 0, idx2) + rest;
else
break;
}
else
break;
}
pname.tname = new String(str);
......@@ -505,13 +544,14 @@ public class Graph implements GraphIfc, GrowApplIfc {
cmnPush();
}
public Object loadCtx( String file) {
return appl.loadGrowCtx( file);
public Object loadCtx( String file, String owner) {
return appl.loadGrowCtx( file, owner);
}
public Object loadGrowCtx( BufferedReader reader) {
public Object loadGrowCtx( BufferedReader reader, String owner) {
GrowCtx ctx = new GrowCtx(this);
GrowCmn cmn = ctx.getCmn();
cmn.setOwner(owner);
cmn.setGdraw(gdraw);
ctx.open( reader);
ctx.traceConnect();
......
......@@ -45,7 +45,7 @@ public interface GraphApplIfc {
public int getWidth();
public int getHeight();
public String getObject();
public Object loadGrowCtx( String file);
public Object loadGrowCtx( String file, String owner);
public int loadSubgraph( String file);
public void closeGraph();
public boolean isAuthorized(int access);
......
......@@ -45,7 +45,7 @@ public interface GrowApplIfc {
public void eventHandler(GlowEvent e);
public int getWidth();
public int getHeight();
public Object loadCtx( String file);
public Object loadCtx( String file, String owner);
public int loadSubgraph( String file);
public void signalSend( String signalName);
}
......@@ -585,7 +585,7 @@ public class GrowFrame extends JFrame implements GraphApplIfc, ActionListener {
return instance;
}
public Object loadGrowCtx( String fname) {
public Object loadGrowCtx( String fname, String owner) {
String filename;
BufferedReader reader = null;
......@@ -637,7 +637,7 @@ public class GrowFrame extends JFrame implements GraphApplIfc, ActionListener {
return null;
}
}
return graph.loadGrowCtx( reader);
return graph.loadGrowCtx( reader, owner);
}
public int loadSubgraph( String fname) {
......
......@@ -242,15 +242,26 @@ public class GrowWindow extends GrowRect implements GrowScrollBarIfc {
if ( file_name.indexOf('.') == -1)
file_name = file_name + ".pwg";
String windOwner = owner;
for ( int i = 0; i < 4; i++) {
int idx;
if ( (idx = windOwner.indexOf("$object")) != -1) {
String oname = cmn.getOwner();
windOwner = windOwner.substring(0, idx) + oname +
windOwner.substring(idx+7);
}
else
break;
}
System.out.println("GrowWindow loading " + file_name);
GrowCtxIfc ctx = (GrowCtxIfc)cmn.appl.loadCtx( file_name);
GrowCtxIfc ctx = (GrowCtxIfc)cmn.appl.loadCtx( file_name, windOwner);
if ( ctx == null)
return;
windowCmn = (GrowCmn)ctx.getCmn();
windowCmn.appl = cmn.appl;
windowCmn.owner = owner;
windowCmn.mw.subwindow_scale = window_scale;
windowCmn.mw.zoom_factor_x = windowCmn.mw.zoom_factor_y =
windowCmn.mw.subwindow_scale * cmn.mw.zoom_factor_x;
......
......@@ -7920,7 +7920,17 @@ int GeDigSwap::connect( grow_tObject object, glow_sTraceData *trace_data)
get_bit( parsed_name, attr_type, &bitmask);
sts = dyn->graph->ref_object_info( dyn->cycle, parsed_name, (void **)&p, &subid, size, object);
switch ( db) {
case graph_eDatabase_Gdh:
sts = dyn->graph->ref_object_info( dyn->cycle, parsed_name, (void **)&p, &subid, size, object);
if ( EVEN(sts)) return sts;
break;
case graph_eDatabase_Local:
p = (pwr_tBoolean *)dyn->graph->localdb_ref_or_create( parsed_name, attr_type);
sts = 1;
break;
default: ;
}
a_typeid = attr_type;
if ( EVEN(sts)) return sts;
......@@ -7954,9 +7964,16 @@ int GeDigSwap::scan( grow_tObject object)
if ( inverted)
val = !val;
if ( old_value == val) {
// No change since last time
return 1;
if ( reset_value) {
if ( since_reset < 100)
since_reset++;
if ( since_reset < 3)
return 1;
}
else {
if ( old_value == val)
// No change since last time
return 1;
}
if ( val) {
......@@ -7965,11 +7982,22 @@ int GeDigSwap::scan( grow_tObject object)
pwr_tAName parsed_name;
pwr_tStatus sts;
since_reset = 0;
dyn->parse_attr_name( attribute, parsed_name, &inverted, &attr_type, &attr_size);
switch ( attr_type) {
case pwr_eType_Boolean: {
pwr_tBoolean ivalue = 0;
sts = gdh_SetObjectInfo( parsed_name, &ivalue, sizeof(ivalue));
switch ( db) {
case graph_eDatabase_Local: {
sts = dyn->graph->localdb_set_value( parsed_name, &ivalue, sizeof(ivalue));
if ( EVEN(sts)) printf("DigSwap error: %s\n", attribute);
break;
}
case graph_eDatabase_Gdh:
sts = gdh_SetObjectInfo( parsed_name, &ivalue, sizeof(ivalue));
break;
default: ;
}
break;
}
default: ;
......@@ -7996,7 +8024,7 @@ int GeDigSwap::syntax_check( grow_tObject object, int *error_cnt, int *warning_c
{
int types[] = {pwr_eType_Boolean, pwr_eType_Int32, pwr_eType_UInt32, pwr_eType_Int64, pwr_eType_UInt64,
graph_eType_Bit, pwr_eType_Float32, pwr_eType_Float64, pwr_eType_String, 0};
graph_eDatabase databases[] = {graph_eDatabase_Gdh, graph_eDatabase__};
graph_eDatabase databases[] = {graph_eDatabase_Gdh, graph_eDatabase_Local, graph_eDatabase__};
dyn->syntax_check_attribute( object, "DigSwap.Attribute", attribute, 0, types, databases, error_cnt, warning_cnt);
return 1;
......
......@@ -2074,13 +2074,14 @@ class GeDigSwap : public GeDynElem {
pwr_tBoolean old_value;
int a_typeid;
unsigned int bitmask;
unsigned int since_reset;
GeDigSwap( GeDyn *e_dyn, ge_mInstance e_instance = ge_mInstance_1) :
GeDynElem(e_dyn, ge_mDynType1_No, ge_mDynType2_DigSwap, ge_mActionType1_No, ge_mActionType2_No, ge_eDynPrio_DigSwap),
reset_value(0), bitmask(0)
reset_value(0), bitmask(0), since_reset(0)
{ strcpy( attribute, "");}
GeDigSwap( const GeDigSwap& x) :
GeDynElem(x.dyn,x.dyn_type1,x.dyn_type2,x.action_type1,x.action_type2,x.prio), reset_value(x.reset_value)
GeDynElem(x.dyn,x.dyn_type1,x.dyn_type2,x.action_type1,x.action_type2,x.prio), reset_value(x.reset_value), since_reset(x.since_reset)
{ strcpy( attribute, x.attribute); }
void get_attributes( attr_sItem *attrinfo, int *item_count);
void save( ofstream& fp);
......@@ -3351,4 +3352,4 @@ class GeEmitSignal : public GeDynElem {
/*@}*/
#endif
\ No newline at end of file
#endif
......@@ -573,6 +573,9 @@ void Graph::open( char *filename)
grow_EnableEvent( grow->ctx, glow_eEvent_Translate,
glow_eEventType_CallBack, graph_grow_cb);
if ( strcmp( object_name[0], "") != 0)
grow_SetOwner( grow->ctx, object_name[0]);
if ( strcmp( filename, "_none_.pwg") != 0) {
get_filename( filename, fname);
sts = grow_Open( grow->ctx, fname);
......@@ -4821,42 +4824,92 @@ graph_eDatabase Graph::parse_attr_name( char *name, char *parsed_name,
return graph_eDatabase_Ccm;
}
if ( (s = strstr( str, "$object"))) {
pwr_tAName oname[4];
for ( int i = 1; i < 4; i++)
strcpy( oname[i], object_name[i]);
if ( grow->stack_cnt == 0)
strcpy( oname[0], object_name[0]);
else {
grow_GetOwner( grow->ctx, oname[0]);
for ( int i = 0; i < 4; i++) {
if ( (s = strstr( str, "$object"))) {
pwr_tAName oname[4];
for ( int i = 1; i < 4; i++)
strcpy( oname[i], object_name[i]);
if ( grow->stack_cnt == 0)
strcpy( oname[0], object_name[0]);
else {
grow_GetOwner( grow->ctx, oname[0]);
// Replace $object in oname (one level only)
char *s1;
if ( (s1 = strstr( oname[0], "$object"))) {
strcpy( str1, s1 + strlen("$object"));
strcpy( s1, object_name[0]);
strcat( oname[0], str1);
// Replace $object in oname (one level only)
char *s1;
if ( (s1 = strstr( oname[0], "$object"))) {
strcpy( str1, s1 + strlen("$object"));
strcpy( s1, object_name[0]);
strcat( oname[0], str1);
}
}
int idx;
char *sidx = s + strlen("$object");
switch ( *sidx) {
case '2':
idx = 1;
break;
case '3':
idx = 2;
break;
case '4':
idx = 3;
break;
default:
idx = 0;
}
strcpy( str1, s + strlen("$object") + (idx > 0 ? 1 : 0));
strcpy( s, oname[idx]);
strcat( str, str1);
}
else
break;
}
int idx;
char *sidx = s + strlen("$object");
switch ( *sidx) {
case '2':
idx = 1;
// Translate index variable
for ( int i = 0; i < 2; i++) {
if ( (s = strstr( str, "[&("))) {
int idx;
pwr_tAName iname, rest;
pwr_tStatus sts;
int len;
s++;
strcpy( iname, s+2);
s1 = strchr( iname, ')');
strncpy( rest, s1+1, sizeof(rest));
if ( s1) {
*s1 = 0;
sts = gdh_GetObjectInfo( iname, &idx, sizeof(idx));
if ( ODD(sts) && idx >= 0 && idx <= 100) {
len = sprintf( s, "%d", idx);
strcpy( s + len, rest);
}
}
else
break;
}
else
break;
case '3':
idx = 2;
}
for ( int i = 0; i < 4; i++) {
// Remove attribute before
if ( (s = strstr( str, ".<"))) {
pwr_tAName rest;
strcpy( rest, s + 2);
for ( s--; s >= str; s--) {
if ( *s == '.') {
strcpy( s, rest);
break;
}
}
}
else
break;
case '4':
idx = 3;
if ( s == str)
break;
default:
idx = 0;
}
strcpy( str1, s + strlen("$object") + (idx > 0 ? 1 : 0));
strcpy( s, oname[idx]);
strcat( str, str1);
}
if ( ((s = strstr( str, "$node")) || (s = strstr( str, "$NODE"))) &&
......@@ -6219,4 +6272,4 @@ int GraphRecallBuff::get( GeDyn **data, char *k)
}
}
return 0;
}
\ No newline at end of file
}
......@@ -899,6 +899,8 @@ void GrowWindow::new_ctx()
{
char fname[200];
int sts;
char *s;
bool copied;
int no_file = strcmp( file_name, "_no_") == 0 ? 1 : 0; // No initial graph
if ( strchr( file_name, '/') == 0) {
......@@ -927,9 +929,23 @@ void GrowWindow::new_ctx()
memcpy( window_ctx->event_callback, ctx->event_callback, sizeof( ctx->event_callback));
window_ctx->event_move_node = ctx->event_move_node;
window_ctx->background_disabled = 1;
if ( strcmp( owner, "$object") == 0 && ctx->is_subwindow)
strcpy( window_ctx->owner, ctx->owner);
else
copied = false;
for ( int i = 0; i < 4; i++) {
if ( (s = strstr( owner, "$object"))) {
if ( strcmp( ctx->owner, "") != 0) {
int len = s - owner;
strncpy( window_ctx->owner, owner, len);
window_ctx->owner[len] = 0;
strcat( window_ctx->owner, ctx->owner);
strcat( window_ctx->owner, s + 7);
copied = true;
}
}
else
break;
}
if ( !copied)
strcpy( window_ctx->owner, owner);
window_ctx->customcolors = ctx->gdraw->create_customcolors();
......@@ -1080,4 +1096,4 @@ int GrowWindow::set_source( char *source, char *new_owner)
ctx->gdraw->set_clip_rectangle( &ctx->mw, 0, 0, ctx->mw.window_width, ctx->mw.window_height);
return sts;
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment