Commit f4a41a08 authored by Claes Sjofors's avatar Claes Sjofors

Plc trace, version check and warning added

parent a361054a
......@@ -111,12 +111,12 @@ void WFoe::activate_save()
}
}
clock_cursor();
sts = create_flow();
sts = gre->undelete_reset();
disable_ldh_cb();
sts = vldh_wind_save( gre->wind);
enable_ldh_cb();
error_msg( sts);
sts = create_flow();
normal_cursor();
......@@ -1455,10 +1455,10 @@ void WFoe::exit_save( WFoe *foe)
}
}
foe->clock_cursor();
sts = foe->create_flow();
foe->disable_ldh_cb();
sts = vldh_wind_save( foe->gre->wind);
foe->error_msg( sts);
sts = foe->create_flow();
foe->normal_cursor();
if ( sts == VLDH__PLCNOTSAVED ) {
......
......@@ -3127,6 +3127,15 @@ int WGre::set_trace_attributes( char *host)
char *np;
char *s;
unsigned int options;
pwr_tUInt32 *version;
// Set version
sts = ldh_GetObjectPar( wind->hw.ldhses, wind->lw.oid,
"RtBody", "Version", (char **)&version, &size);
if ( EVEN(sts)) return sts;
flow_SetCtxUserVersion( flow_ctx, *version);
free( (char *)version);
sts = vldh_get_nodes( wind, &node_count, &nodelist);
if ( EVEN(sts)) return sts;
......
......@@ -1206,6 +1206,8 @@ int vldh_wind_save (
time_GetTime( &time);
sts = ldh_SetObjectPar( wind->hw.ldhses, wind->lw.oid,
"DevBody", "Modified", (char *)&time, sizeof( time));
sts = ldh_SetObjectPar( wind->hw.ldhses, wind->lw.oid,
"RtBody", "Version", (char *)&time.tv_sec, sizeof( time.tv_sec));
}
/* Save the nodes that is created or modified */
......
......@@ -434,6 +434,7 @@ typedef enum {
flow_eSave_Ctx_refcon_height = 131,
flow_eSave_Ctx_refcon_textsize = 132,
flow_eSave_Ctx_refcon_linewidth = 133,
flow_eSave_Ctx_user_version = 134,
flow_eSave_Array_a = 200,
flow_eSave_NodeClass_nc_name = 300,
flow_eSave_NodeClass_a = 301,
......
......@@ -526,6 +526,16 @@ void flow_SetCtxUserData( flow_tCtx ctx, void *user_data)
((FlowCtx *)ctx)->set_user_data( user_data);
}
void flow_GetCtxUserVersion( flow_tCtx ctx, unsigned int *user_version)
{
((FlowCtx *)ctx)->get_user_version( user_version);
}
void flow_SetCtxUserVersion( flow_tCtx ctx, unsigned int user_version)
{
((FlowCtx *)ctx)->set_user_version( user_version);
}
flow_tCtx flow_GetCtx( flow_tObject object)
{
return (flow_tCtx)((FlowArrayElem *)object)->get_ctx();
......
......@@ -218,6 +218,8 @@ void flow_GetUserData( flow_tObject object, void **user_data);
void flow_SetUserData( flow_tObject object, void *user_data);
void flow_GetCtxUserData( flow_tCtx ctx, void **user_data);
void flow_SetCtxUserData( flow_tCtx ctx, void *user_data);
void flow_GetCtxUserVersion( flow_tCtx ctx, unsigned int *user_version);
void flow_SetCtxUserVersion( flow_tCtx ctx, unsigned int user_version);
flow_tCtx flow_GetCtx( flow_tObject object);
void flow_SetTraceAttr( flow_tObject object, char *trace_object,
char *trace_attribute, flow_eTraceType trace_attr_type, int inverted);
......
......@@ -97,7 +97,7 @@ FlowCtx::FlowCtx( const char *ctx_name, double zoom_fact, int offs_x, int offs_y
grafcet_con_delta(2), refcon_cnt(0), refcon_width(1.5),
refcon_height(0.8), refcon_textsize(3), refcon_linewidth(2),
trace_connect_func(0), trace_scan_func(0), trace_started(0),
unobscured(1), nodraw(0), no_nav(1), widget_cnt(0),
user_version(0), unobscured(1), nodraw(0), no_nav(1), widget_cnt(0),
select_policy(flow_eSelectPolicy_Partial), tiptext(0),
inverse_color(flow_eDrawType_Line), text_coding(flow_eTextCoding_ISO8859_1),
display_level(flow_mDisplayLevel_1),
......@@ -195,6 +195,7 @@ int FlowCtx::save( char *filename, flow_eSaveMode mode)
fp << int(flow_eSave_Ctx_refcon_height) << FSPACE << refcon_height << endl;
fp << int(flow_eSave_Ctx_refcon_textsize) << FSPACE << refcon_textsize << endl;
fp << int(flow_eSave_Ctx_refcon_linewidth) << FSPACE << refcon_linewidth << endl;
fp << int(flow_eSave_Ctx_user_version) << FSPACE << user_version << endl;
fp << int(flow_eSave_Ctx_a_nc) << endl;
a_nc.save( fp, mode);
fp << int(flow_eSave_Ctx_a_cc) << endl;
......@@ -259,6 +260,7 @@ int FlowCtx::open( char *filename, flow_eSaveMode mode)
case flow_eSave_Ctx_refcon_height: fp >> refcon_height; break;
case flow_eSave_Ctx_refcon_textsize: fp >> refcon_textsize; break;
case flow_eSave_Ctx_refcon_linewidth: fp >> refcon_linewidth; break;
case flow_eSave_Ctx_user_version: fp >> user_version; break;
case flow_eSave_Ctx_a_nc: a_nc.open( this, fp); break;
case flow_eSave_Ctx_a_cc: a_cc.open( this, fp); break;
case flow_eSave_Ctx_a: a.open( this, fp); break;
......
......@@ -288,8 +288,11 @@ class FlowCtx {
void trace_close();
void trace_scan();
void *user_data;
void set_user_data( void *data) { user_data = data;};
void get_user_data( void **data) { *data = user_data;};
unsigned int user_version;
void set_user_data( void *data) { user_data = data;}
void get_user_data( void **data) { *data = user_data;}
void set_user_version( unsigned int version) { user_version = version;}
void get_user_version( unsigned int *version) { *version = user_version;}
void get_selected_nodes( FlowArrayElem ***nodes, int *num);
void get_selected_cons( FlowArrayElem ***cons, int *num);
void position_to_pixel( double x, double y, int *pix_x, int *pix_y)
......
......@@ -699,204 +699,22 @@ RtTraceGtk::RtTraceGtk( void *tr_parent_ctx, GtkWidget *tr_parent_wid, pwr_tObji
version = info.st_ctime;
}
#endif
#if 0
FlowWidget fwidget;
char uid_filename[120] = {"xtt_trace.uid"};
char *uid_filename_p = uid_filename;
Arg args[20];
unsigned long sts;
pwr_tOName name;
int i;
pwr_tObjid window_objid;
pwr_tClassId cid;
char title[220];
pwr_tOName hostname;
pwr_tOName plcconnect;
MrmHierarchy s_DRMh;
MrmType dclass;
Widget trace_widget;
static MrmRegisterArg reglist[] = {
{ "tra_ctx", 0 },
{"tra_activate_close",(caddr_t)activate_close },
{"tra_activate_print",(caddr_t)activate_print },
{"tra_activate_printselect",(caddr_t)activate_printselect },
{"tra_activate_savetrace",(caddr_t)activate_savetrace },
{"tra_activate_restoretrace",(caddr_t)activate_restoretrace },
{"tra_activate_cleartrace",(caddr_t)activate_cleartrace },
{"tra_activate_trace",(caddr_t)activate_trace },
{"tra_activate_display_object",(caddr_t)activate_display_object },
{"tra_activate_open_object",(caddr_t)activate_open_object },
{"tra_activate_show_cross",(caddr_t)activate_show_cross },
{"tra_activate_open_classgraph",(caddr_t)activate_open_classgraph },
{"tra_activate_collect_insert",(caddr_t)activate_collect_insert },
{"tra_activate_view",(caddr_t)activate_view },
{"tra_activate_simulate",(caddr_t)activate_simulate },
{"tra_activate_zoomin",(caddr_t)activate_zoomin },
{"tra_activate_zoomout",(caddr_t)activate_zoomout },
{"tra_activate_zoomreset",(caddr_t)activate_zoomreset },
{"tra_activate_scantime1",(caddr_t)activate_scantime1 },
{"tra_activate_scantime2",(caddr_t)activate_scantime2 },
{"tra_activate_scantime3",(caddr_t)activate_scantime3 },
{"tra_activate_scantime4",(caddr_t)activate_scantime4 },
{"tra_activate_scantime5",(caddr_t)activate_scantime5 },
{"tra_activate_help",(caddr_t)activate_help },
{"tra_activate_helpplc",(caddr_t)activate_helpplc },
{"tra_create_form",(caddr_t)create_form },
{"tra_create_menu",(caddr_t)create_menu }
};
static int reglist_num = (sizeof reglist / sizeof reglist[0]);
lng_get_uid( uid_filename, uid_filename);
sts = gdh_ObjidToName( tr_objid, name, sizeof(name), cdh_mNName);
if (EVEN(sts)) {
*status = sts;
return;
}
strcpy( title, "Trace ");
strcat( title, name);
/* Find plcwindow */
sts = gdh_GetObjectClass( tr_objid, &cid);
if ( EVEN(sts)) {
*status = sts;
return;
}
if ( !(cid == pwr_cClass_windowplc ||
cid == pwr_cClass_windowcond ||
cid == pwr_cClass_windoworderact ||
cid == pwr_cClass_windowsubstep ))
{
sts = gdh_GetChild( tr_objid, &window_objid);
if ( EVEN(sts)) {
*status = sts;
return;
}
}
else
window_objid = tr_objid;
sts = gdh_GetObjectClass( window_objid, &cid);
if ( EVEN(sts)) {
*status = sts;
return;
}
if ( !(cid == pwr_cClass_windowplc ||
cid == pwr_cClass_windowcond ||
cid == pwr_cClass_windoworderact ||
cid == pwr_cClass_windowsubstep )) {
*status = 0;
return;
}
// Check version
unsigned int flow_version;
pwr_tUInt32 window_version;
pwr_tAName aname;
sts = get_filename( window_objid, filename, &m_has_host, hostname,
plcconnect);
if ( EVEN(sts)) {
*status = sts;
return;
}
flow_GetCtxUserVersion( flow_ctx, &flow_version);
/* Create object context */
objid = window_objid;
if ( m_has_host) {
strcpy( m_hostname, hostname);
strcpy( m_plcconnect, plcconnect);
}
reglist[0].value = (caddr_t) this;
toplevel = XtCreatePopupShell( name,
topLevelShellWidgetClass, parent_wid, args, 0);
/* Save the context structure in the widget */
XtSetArg (args[0], XmNuserData, (unsigned int) this);
sts = MrmOpenHierarchy( 1, &uid_filename_p, NULL, &s_DRMh);
if (sts != MrmSUCCESS) printf("can't open %s\n", uid_filename);
MrmRegisterNames(reglist, reglist_num);
sts = MrmFetchWidgetOverride( s_DRMh, "trace_window", toplevel,
title, args, 1, &trace_widget, &dclass);
if (sts != MrmSUCCESS) printf("can't fetch %s\n", name);
MrmCloseHierarchy(s_DRMh);
i = 0;
XtSetArg(args[i],XmNwidth,800);i++;
XtSetArg(args[i],XmNheight,600);i++;
XtSetValues( toplevel ,args,i);
XtManageChild( trace_widget);
i = 0;
/*
XtSetArg(args[i],XmNwidth,790);i++;
XtSetArg(args[i],XmNheight,560);i++;
*/
XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET);i++;
XtSetArg( args[i], XmNtopWidget, menu);i++;
XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM);i++;
XtSetArg( args[i], XmNleftAttachment, XmATTACH_FORM);i++;
XtSetArg( args[i], XmNbottomAttachment, XmATTACH_FORM);i++;
flow_widget = FlowCreate( form, "Flow window", args, i,
init_flow, (void *)this);
XtManageChild( (Widget) flow_widget);
/*
XtRealizeWidget(toplevel);
*/
XtPopup( toplevel, XtGrabNone);
fwidget = (FlowWidget) flow_widget;
flow_ctx = (flow_tCtx)fwidget->flow.flow_ctx;
flow_SetCtxUserData( flow_ctx, this);
/* Create navigator popup */
i = 0;
XtSetArg(args[i],XmNallowShellResize, TRUE); i++;
XtSetArg(args[i],XmNallowResize, TRUE); i++;
XtSetArg(args[i],XmNwidth,200);i++;
XtSetArg(args[i],XmNheight,200);i++;
XtSetArg(args[i],XmNx,500);i++;
XtSetArg(args[i],XmNy,500);i++;
nav_shell = XmCreateDialogShell( flow_widget, "Navigator",
args, i);
XtManageChild( nav_shell);
i = 0;
XtSetArg(args[i],XmNwidth,200);i++;
XtSetArg(args[i],XmNheight,200);i++;
nav_widget = FlowCreateNav( nav_shell, "navigator",
args, i, flow_widget);
XtManageChild( nav_widget);
XtRealizeWidget( nav_shell);
// Connect the window manager close-button to exit
flow_AddCloseVMProtocolCb( toplevel,
(XtCallbackProc)activate_close, this);
wow = new CoWowGtk( toplevel);
trace_timerid = wow->timer_new();
viewsetup();
flow_Open( flow_ctx, filename);
trasetup();
trace_start();
strcpy( aname, name);
strcat( aname, ".Version");
#if defined OS_LINUX
{
struct stat info;
sts = gdh_GetObjectInfo( aname, &window_version, sizeof(window_version));
if ( EVEN(sts)) return;
if ( stat( filename, &info) != -1)
version = info.st_ctime;
}
#endif
#endif
if ( flow_version > window_version)
wow->DisplayError( "Version mismatch", "Trace file is newer than database version");
else if ( flow_version < window_version)
wow->DisplayError( "Version mismatch", "Trace file is older than database version");
}
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