Commit 5c7e21f8 authored by Claes Sjofors's avatar Claes Sjofors

Ge dynamic DigSwap to swap subscriptions

parent 319c558f
......@@ -128,6 +128,7 @@ public class Dyn {
public static final int mDynType2_ScrollingText = 1 << 4;
public static final int mDynType2_ColorThemeLightness = 1 << 5;
public static final int mDynType2_DigBackgroundColor = 1 << 6;
public static final int mDynType2_DigSwap = 1 << 7;
public static final int mActionType1_No = 0;
public static final int mActionType1_Inherit = 1 << 0;
......@@ -217,6 +218,7 @@ public class Dyn {
public static final int eDynPrio_MethodPulldownMenu = 55;
public static final int eDynPrio_ScrollingText = 56;
public static final int eDynPrio_ColorThemeLightness = 57;
public static final int eDynPrio_DigSwap = 58;
public static final int eDynPrio_Script = 9998;
public static final int eDynPrio_Command = 9999;
public static final int eDynPrio_CloseGraph = 10000;
......@@ -259,6 +261,7 @@ public class Dyn {
public static final int eSave_ScrollingText = 42;
public static final int eSave_ColorThemeLightness = 43;
public static final int eSave_DigBackgroundColor = 44;
public static final int eSave_DigSwap = 45;
public static final int eSave_PopupMenu = 50;
public static final int eSave_SetDig = 51;
public static final int eSave_ResetDig = 52;
......@@ -482,6 +485,8 @@ public class Dyn {
public static final int eSave_DigBackgroundColor_color = 4401;
public static final int eSave_DigBackgroundColor_instance = 4402;
public static final int eSave_DigBackgroundColor_instance_mask = 4403;
public static final int eSave_DigSwap_attribute = 4500;
public static final int eSave_DigSwap_reset_value = 4501;
public static final int eSave_PopupMenu_ref_object = 5000;
public static final int eSave_SetDig_attribute = 5100;
public static final int eSave_SetDig_instance = 5101;
......@@ -809,6 +814,8 @@ public class Dyn {
e = new DynColorThemeLightness((DynColorThemeLightness) x.elements.get(i)); break;
case Dyn.mDynType2_DigBackgroundColor:
e = new DynDigBackgroundColor((DynDigBackgroundColor) x.elements.get(i)); break;
case Dyn.mDynType2_DigSwap:
e = new DynDigSwap((DynDigSwap) x.elements.get(i)); break;
default: ;
}
switch( x.elements.get(i).action_type1) {
......@@ -1072,6 +1079,9 @@ public class Dyn {
case mDynType2_DigBackgroundColor:
e = (DynElem) new DynDigBackgroundColor((DynDigBackgroundColor) x);
break;
case mDynType2_DigSwap:
e = (DynElem) new DynDigSwap((DynDigSwap) x);
break;
default: ;
}
}
......@@ -1203,6 +1213,9 @@ public class Dyn {
case Dyn.eSave_DigBackgroundColor:
elem = (DynElem) new DynDigBackgroundColor(this);
break;
case Dyn.eSave_DigSwap:
elem = (DynElem) new DynDigSwap(this);
break;
case Dyn.eSave_Animation:
elem = (DynElem) new DynAnimation(this);
break;
......@@ -5381,6 +5394,135 @@ public class Dyn {
}
public class DynDigSwap extends DynElem {
String attribute;
int reset_value;
PwrtRefId subid;
int p;
int database;
boolean inverted;
boolean attrFound = false;
boolean oldValue;
boolean firstScan = true;
int bitmask;
int a_typeid;
public DynDigSwap( Dyn dyn) {
super(dyn, 0, Dyn.mDynType2_DigSwap, 0, 0, Dyn.eDynPrio_DigSwap);
}
public DynDigSwap( DynDigSwap x) {
super(x);
reset_value = x.reset_value;
attribute = x.attribute;
}
public int connect(GlowArrayElem o) {
GrowNode object = (GrowNode)o;
DynParsedAttrName pname = dyn.parseAttrName(attribute);
if ( pname == null || pname.name.equals(""))
return 1;
GdhrRefObjectInfo ret = null;
switch( pname.database) {
case GraphIfc.eDatabase_Gdh:
ret = dyn.graph.getGdh().refObjectInfo( pname.tname);
break;
default:
ret = null;
}
if ( ret == null || ret.evenSts()) {
System.out.println("DigSwap: " + attribute);
return 1;
}
p = ret.id;
subid = ret.refid;
inverted = pname.inverted;
a_typeid = pname.type;
bitmask = pname.bitmask;
database = pname.database;
attrFound = true;
return 1;
}
public void disconnect() {
if ( attrFound && database == GraphIfc.eDatabase_Gdh)
dyn.graph.getGdh().unrefObjectInfo(subid);
}
public void scan( GlowArrayElem o) {
GrowNode object = (GrowNode)o;
if ( !attrFound)
return;
boolean value = dyn.getDig(p, a_typeid, bitmask, database);
if ( !firstScan) {
oldValue = value;
firstScan = false;
return;
}
if ( inverted)
value = !value;
if ( oldValue == value) {
// No change since last time
return;
}
if ( value) {
// Todo
// dyn.graph.swap();
}
dyn.repaintNow = true;
oldValue = value;
}
public void open( BufferedReader reader) {
String line;
StringTokenizer token;
boolean end_found = false;
try {
while( (line = reader.readLine()) != null) {
token = new StringTokenizer(line);
int key = Integer.valueOf(token.nextToken());
if ( Dyn.debug) System.out.println( "DynDigSwap : " + line);
switch ( key) {
case Dyn.eSave_DigSwap:
break;
case Dyn.eSave_DigSwap_attribute:
if ( token.hasMoreTokens())
attribute = token.nextToken();
break;
case Dyn.eSave_DigSwap_reset_value:
reset_value = Integer.valueOf(token.nextToken());
break;
case Dyn.eSave_End:
end_found = true;
break;
default:
System.out.println( "Syntax error in DynDigSwap");
break;
}
if ( end_found)
break;
}
} catch ( Exception e) {
System.out.println( "IOException DynDigSwap");
}
}
}
public class DynAnimation extends DynElem {
String attribute;
int sequence;
......
......@@ -116,7 +116,8 @@ static attrnav_sEnumElement elem_dyn_type2[] = {
{ (unsigned int) ge_mDynType2_DigFourShift , "DigFourShift"},
{ (unsigned int) ge_mDynType2_ScrollingText , "ScrollingText"},
{ (unsigned int) ge_mDynType2_ColorThemeLightness, "ColorThemeLightness"},
{ (unsigned int) ge_mDynType2_DigBackgroundColor, "DigBackgroundColor"},
{ (unsigned int) ge_mDynType2_DigBackgroundColor , "DigBackgroundColor"},
{ (unsigned int) ge_mDynType2_DigSwap , "DigSwap"},
{ 0, ""}};
static attrnav_sEnumElement elem_dyn_type1_tone[] = {
......
......@@ -465,6 +465,8 @@ GeDyn::GeDyn( const GeDyn& x) :
e = new GeColorThemeLightness((const GeColorThemeLightness&) *elem); break;
case ge_mDynType2_DigBackgroundColor:
e = new GeDigBackgroundColor((const GeDigBackgroundColor&) *elem); break;
case ge_mDynType2_DigSwap:
e = new GeDigSwap((const GeDigSwap&) *elem); break;
default: ;
}
switch( elem->action_type1) {
......@@ -601,6 +603,7 @@ void GeDyn::open( ifstream& fp)
case ge_eSave_ScrollingText: e = (GeDynElem *) new GeScrollingText(this); break;
case ge_eSave_ColorThemeLightness: e = (GeDynElem *) new GeColorThemeLightness(this); break;
case ge_eSave_DigBackgroundColor: e = (GeDynElem *) new GeDigBackgroundColor(this); break;
case ge_eSave_DigSwap: e = (GeDynElem *) new GeDigSwap(this); break;
case ge_eSave_Animation: e = (GeDynElem *) new GeAnimation(this); break;
case ge_eSave_Video: e = (GeDynElem *) new GeVideo(this); break;
case ge_eSave_Bar: e = (GeDynElem *) new GeBar(this); break;
......@@ -1568,6 +1571,9 @@ GeDynElem *GeDyn::create_dyn2_element( int mask, int instance)
case ge_mDynType2_DigBackgroundColor:
e = (GeDynElem *) new GeDigBackgroundColor(this, (ge_mInstance)instance);
break;
case ge_mDynType2_DigSwap:
e = (GeDynElem *) new GeDigSwap(this, (ge_mInstance)instance);
break;
default: ;
}
return e;
......@@ -1774,6 +1780,9 @@ GeDynElem *GeDyn::copy_element( GeDynElem& x)
case ge_mDynType2_DigBackgroundColor:
e = (GeDynElem *) new GeDigBackgroundColor((GeDigBackgroundColor&) x);
break;
case ge_mDynType2_DigSwap:
e = (GeDynElem *) new GeDigSwap((GeDigSwap&) x);
break;
default: ;
}
}
......@@ -7164,6 +7173,173 @@ int GeDigBackgroundColor::export_java( grow_tObject object, ofstream& fp, bool f
return 1;
}
void GeDigSwap::get_attributes( attr_sItem *attrinfo, int *item_count)
{
int i = *item_count;
strcpy( attrinfo[i].name, "DigSwap.Attribute");
attrinfo[i].value = attribute;
attrinfo[i].type = glow_eType_String;
attrinfo[i++].size = sizeof( attribute);
strcpy( attrinfo[i].name, "DigSwap.ResetValue");
attrinfo[i].value = &reset_value;
attrinfo[i].type = glow_eType_Boolean;
attrinfo[i++].size = sizeof( reset_value);
*item_count = i;
}
void GeDigSwap::set_attribute( grow_tObject object, const char *attr_name, int *cnt)
{
(*cnt)--;
if ( *cnt == 0) {
char msg[200];
strncpy( attribute, attr_name, sizeof( attribute));
if ( instance == ge_mInstance_1) {
snprintf( msg, sizeof(msg), "DigSwap.Attribute = %s", attr_name);
}
else {
snprintf( msg, sizeof(msg), "DigSwap%d.Attribute = %s", GeDyn::instance_to_number( instance),
attr_name);
}
msg[sizeof(msg)-1] = 0;
dyn->graph->message( 'I', msg);
}
}
void GeDigSwap::replace_attribute( char *from, char *to, int *cnt, int strict)
{
GeDyn::replace_attribute( attribute, sizeof(attribute), from, to, cnt, strict);
}
void GeDigSwap::save( ofstream& fp)
{
fp << int(ge_eSave_DigSwap) << endl;
fp << int(ge_eSave_DigSwap_attribute) << FSPACE << attribute << endl;
fp << int(ge_eSave_DigSwap_reset_value) << FSPACE << reset_value << endl;
fp << int(ge_eSave_End) << endl;
}
void GeDigSwap::open( ifstream& fp)
{
int type;
int end_found = 0;
char dummy[40];
for (;;)
{
if ( !fp.good()) {
fp.clear();
fp.getline( dummy, sizeof(dummy));
printf( "** Read error GeDigSwap: \"%d %s\"\n", type, dummy);
}
fp >> type;
switch( type) {
case ge_eSave_DigSwap: break;
case ge_eSave_DigSwap_attribute:
fp.get();
fp.getline( attribute, sizeof(attribute));
break;
case ge_eSave_DigSwap_reset_value: fp >> reset_value; break;
case ge_eSave_End: end_found = 1; break;
default:
cout << "GeDigSwap:open syntax error" << endl;
fp.getline( dummy, sizeof(dummy));
}
if ( end_found)
break;
}
}
int GeDigSwap::connect( grow_tObject object, glow_sTraceData *trace_data)
{
int attr_type, attr_size;
pwr_tAName parsed_name;
int sts;
size = 4;
p = 0;
db = dyn->parse_attr_name( attribute, parsed_name,
&inverted, &attr_type, &attr_size);
if ( strcmp( parsed_name,"") == 0)
return 1;
get_bit( parsed_name, attr_type, &bitmask);
sts = dyn->graph->ref_object_info( dyn->cycle, parsed_name, (void **)&p, &subid, size, object);
a_typeid = attr_type;
if ( EVEN(sts)) return sts;
trace_data->p = &pdummy;
first_scan = true;
return 1;
}
int GeDigSwap::disconnect( grow_tObject object)
{
if ( p && db == graph_eDatabase_Gdh)
gdh_UnrefObjectInfo( subid);
p = 0;
return 1;
}
int GeDigSwap::scan( grow_tObject object)
{
pwr_tBoolean val = *p;
if ( !get_dig( &val, p, a_typeid, bitmask))
return 1;
if ( first_scan) {
old_value = val;
first_scan = 0;
return 1;
}
if ( inverted)
val = !val;
if ( old_value == val) {
// No change since last time
return 1;
}
if ( val) {
if ( reset_value) {
int attr_type, attr_size;
pwr_tAName parsed_name;
pwr_tStatus sts;
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));
break;
}
default: ;
}
}
dyn->graph->swap(0);
dyn->graph->swap(1);
return GLOW__TERMINATED;
}
old_value = val;
return 1;
}
int GeDigSwap::export_java( grow_tObject object, ofstream& fp, bool first, char *var_name)
{
return 1;
}
void GeAnimation::get_attributes( attr_sItem *attrinfo, int *item_count)
{
int i = *item_count;
......
......@@ -191,6 +191,7 @@
ge_eDynPrio_MethodPulldownMenu,
ge_eDynPrio_ScrollingText,
ge_eDynPrio_ColorThemeLightness,
ge_eDynPrio_DigSwap,
// This should always be last
ge_eDynPrio_Script = 9998,
......@@ -243,7 +244,8 @@
ge_mDynType2_DigFourShift = 1 << 3,
ge_mDynType2_ScrollingText = 1 << 4,
ge_mDynType2_ColorThemeLightness = 1 << 5,
ge_mDynType2_DigBackgroundColor = 1 << 6
ge_mDynType2_DigBackgroundColor = 1 << 6,
ge_mDynType2_DigSwap = 1 << 7
} ge_mDynType2;
//! Action types.
......@@ -359,6 +361,7 @@
ge_eSave_ScrollingText = 42,
ge_eSave_ColorThemeLightness = 43,
ge_eSave_DigBackgroundColor = 44,
ge_eSave_DigSwap = 45,
ge_eSave_PopupMenu = 50,
ge_eSave_SetDig = 51,
ge_eSave_ResetDig = 52,
......@@ -582,6 +585,8 @@
ge_eSave_DigBackgroundColor_color = 4401,
ge_eSave_DigBackgroundColor_instance = 4402,
ge_eSave_DigBackgroundColor_instance_mask = 4403,
ge_eSave_DigSwap_attribute = 4500,
ge_eSave_DigSwap_reset_value = 4501,
ge_eSave_PopupMenu_ref_object = 5000,
ge_eSave_SetDig_attribute = 5100,
ge_eSave_SetDig_instance = 5101,
......@@ -1107,7 +1112,7 @@ class GeDigColor : public GeDynElem {
int export_java( grow_tObject object, ofstream& fp, bool first, char *var_name);
};
//! Set the supplied fillcolor when the value is high.
//! Set the supplied backgroundcolor when the value is high.
class GeDigBackgroundColor : public GeDynElem {
public:
pwr_tAName attribute; //!< Database reference for digital attribute.
......@@ -1941,7 +1946,7 @@ class GeHostObject : public GeDynElem {
int export_java( grow_tObject object, ofstream& fp, bool first, char *var_name);
};
//! Play sound specified by a Sound or SoundSequence object.
//! Play sound specified by a Sound or SoundSequence object.
class GeDigSound : public GeDynElem {
public:
pwr_tAName attribute;
......@@ -1999,6 +2004,40 @@ class GeColorThemeLightness : public GeDynElem {
};
//! Set the supplied backgroundcolor when the value is high.
class GeDigSwap : public GeDynElem {
public:
pwr_tAName attribute; //!< Database reference for digital attribute.
pwr_tBoolean reset_value;
pwr_tBoolean *p;
pwr_tSubid subid;
int size;
graph_eDatabase db;
int inverted;
bool first_scan;
pwr_tBoolean old_value;
int a_typeid;
unsigned int bitmask;
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)
{ 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)
{ strcpy( attribute, x.attribute); }
void get_attributes( attr_sItem *attrinfo, int *item_count);
void save( ofstream& fp);
void open( ifstream& fp);
int connect( grow_tObject object, glow_sTraceData *trace_data);
int disconnect( grow_tObject object);
int scan( grow_tObject object);
void set_attribute( grow_tObject object, const char *attr_name, int *cnt);
void replace_attribute( char *from, char *to, int *cnt, int strict);
int export_java( grow_tObject object, ofstream& fp, bool first, char *var_name);
};
//! Display the methods popup menu.
class GePopupMenu : public GeDynElem {
public:
......
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