Commit db3bfb13 authored by Claes Sjofors's avatar Claes Sjofors

Backup file display window and list command added

parent a53155ac
...@@ -905,7 +905,7 @@ bck_insert_listentry ( ...@@ -905,7 +905,7 @@ bck_insert_listentry (
if (dynamic) { if (dynamic) {
blep->datablk.head.dynamic = dynamic; blep->datablk.head.dynamic = dynamic;
gdh_GetObjectClass(attrref->Objid, &blep->datablk.head.class); gdh_GetObjectClass(attrref->Objid, &blep->datablk.head.cid);
blep->datablk.name = calloc(1, strlen(objectname) + 1); blep->datablk.name = calloc(1, strlen(objectname) + 1);
strcpy(blep->datablk.name, objectname); strcpy(blep->datablk.name, objectname);
blep->datablk.head.namesize = strlen(objectname); blep->datablk.head.namesize = strlen(objectname);
...@@ -1324,7 +1324,7 @@ void *bck_coll_process ( ...@@ -1324,7 +1324,7 @@ void *bck_coll_process (
dhp = (bck_t_writeheader *)p; /* dhp points to data header */ dhp = (bck_t_writeheader *)p; /* dhp points to data header */
p += sizeof *dhp; /* p points to data part */ p += sizeof *dhp; /* p points to data part */
dhp->objid = blep->datablk.head.attrref.Objid; dhp->objid = blep->datablk.head.attrref.Objid;
dhp->class = blep->datablk.head.class; dhp->cid = blep->datablk.head.cid;
dhp->dynamic = blep->datablk.head.dynamic; dhp->dynamic = blep->datablk.head.dynamic;
dhp->namesize = blep->datablk.head.namesize; dhp->namesize = blep->datablk.head.namesize;
dhp->size = blep->datablk.head.attrref.Size; dhp->size = blep->datablk.head.attrref.Size;
......
...@@ -128,7 +128,7 @@ int main (int argc, char **argv) ...@@ -128,7 +128,7 @@ int main (int argc, char **argv)
fread (&dh, sizeof dh, 1, f); fread (&dh, sizeof dh, 1, f);
printf (" Valid: %x\n", dh.valid); printf (" Valid: %x\n", dh.valid);
printf (" Dynamic: %x\n", dh.dynamic); printf (" Dynamic: %x\n", dh.dynamic);
printf (" Class: %x\n", dh.class); printf (" Class: %x\n", dh.cid);
printf (" Attrref.Vid: %x\n", dh.attrref.Objid.vid); printf (" Attrref.Vid: %x\n", dh.attrref.Objid.vid);
printf (" Attrref.Oix: %x\n", dh.attrref.Objid.oix); printf (" Attrref.Oix: %x\n", dh.attrref.Objid.oix);
printf (" Attrref.Offset: %x\n", dh.attrref.Offset); printf (" Attrref.Offset: %x\n", dh.attrref.Offset);
......
...@@ -171,7 +171,7 @@ bck_LoadBackup () ...@@ -171,7 +171,7 @@ bck_LoadBackup ()
strp = strchr(dh_old.dataname, '.'); /* always is a full object! */ strp = strchr(dh_old.dataname, '.'); /* always is a full object! */
if (strp != NULL) *strp = '\0'; /* Just make sure... */ if (strp != NULL) *strp = '\0'; /* Just make sure... */
sts = gdh_CreateObject(dh_old.dataname, dh_old.class, dh_old.attrref.Size, sts = gdh_CreateObject(dh_old.dataname, dh_old.cid, dh_old.attrref.Size,
&objid, dh_old.attrref.Objid, 0, pwr_cNObjid); &objid, dh_old.attrref.Objid, 0, pwr_cNObjid);
if (strp != NULL) *strp = '.'; if (strp != NULL) *strp = '.';
...@@ -228,7 +228,7 @@ bck_LoadBackup () ...@@ -228,7 +228,7 @@ bck_LoadBackup ()
strp = strchr(namep, '.'); /* always is a full object! */ strp = strchr(namep, '.'); /* always is a full object! */
if (strp != NULL) *strp = '\0'; /* Just make sure... */ if (strp != NULL) *strp = '\0'; /* Just make sure... */
sts = gdh_CreateObject(namep, dh.class, dh.size, sts = gdh_CreateObject(namep, dh.cid, dh.size,
&objid, dh.objid, 0, pwr_cNObjid); &objid, dh.objid, 0, pwr_cNObjid);
if (strp != NULL) *strp = '.'; if (strp != NULL) *strp = '.';
...@@ -295,7 +295,7 @@ bck_LoadBackup () ...@@ -295,7 +295,7 @@ bck_LoadBackup ()
strp = strchr(namep, '.'); /* always is a full object! */ strp = strchr(namep, '.'); /* always is a full object! */
if (strp != NULL) *strp = '\0'; /* Just make sure... */ if (strp != NULL) *strp = '\0'; /* Just make sure... */
sts = gdh_CreateObject(namep, dh.class, dh.size, sts = gdh_CreateObject(namep, dh.cid, dh.size,
&objid, dh.objid, 0, pwr_cNObjid); &objid, dh.objid, 0, pwr_cNObjid);
if (strp != NULL) *strp = '.'; if (strp != NULL) *strp = '.';
......
...@@ -118,7 +118,7 @@ typedef struct { ...@@ -118,7 +118,7 @@ typedef struct {
typedef struct { typedef struct {
pwr_sAttrRef attrref; /* Objid for the object */ pwr_sAttrRef attrref; /* Objid for the object */
pwr_tClassId class; /* Class of object */ pwr_tClassId cid; /* Class of object */
pwr_tBoolean valid; /* Validity flag */ pwr_tBoolean valid; /* Validity flag */
pwr_tBoolean dynamic; /* Dynamic object */ pwr_tBoolean dynamic; /* Dynamic object */
pwr_tString80 dataname; /* Name of object[.attribute] */ pwr_tString80 dataname; /* Name of object[.attribute] */
...@@ -126,7 +126,7 @@ typedef struct { ...@@ -126,7 +126,7 @@ typedef struct {
typedef struct { typedef struct {
pwr_sAttrRef attrref; /* Objid for the object */ pwr_sAttrRef attrref; /* Objid for the object */
pwr_tClassId class; /* Class of object */ pwr_tClassId cid; /* Class of object */
pwr_tBoolean valid; /* Validity flag */ pwr_tBoolean valid; /* Validity flag */
pwr_tBoolean dynamic; /* Dynamic object */ pwr_tBoolean dynamic; /* Dynamic object */
pwr_tInt16 namesize; /* Name of attribute [.attribute] */ pwr_tInt16 namesize; /* Name of attribute [.attribute] */
...@@ -134,7 +134,7 @@ typedef struct { ...@@ -134,7 +134,7 @@ typedef struct {
typedef struct { typedef struct {
pwr_tObjid objid; /* Objid for the object */ pwr_tObjid objid; /* Objid for the object */
pwr_tClassId class; /* Class of object */ pwr_tClassId cid; /* Class of object */
pwr_tBoolean valid; /* Validity flag */ pwr_tBoolean valid; /* Validity flag */
pwr_tBoolean dynamic; /* Dynamic object */ pwr_tBoolean dynamic; /* Dynamic object */
pwr_tInt16 namesize; /* Size of name of attribute [.attribute] */ pwr_tInt16 namesize; /* Size of name of attribute [.attribute] */
......
...@@ -154,3 +154,4 @@ numaref <Attribute referens in numeric format> /info ...@@ -154,3 +154,4 @@ numaref <Attribute referens in numeric format> /info
numobjid <Objid in numeric format> /info numobjid <Objid in numeric format> /info
volversion <Volume version mismatch> /error volversion <Volume version mismatch> /error
volerr <Volume check errors> /error volerr <Volume check errors> /error
bckversion <Backup version mismatch> /error
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
/* wb_bckw_gtk.cpp -- Backupfile display window */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include "co_cdh.h"
#include "co_time.h"
#include "co_dcli.h"
#include "co_lng.h"
#include "cow_xhelp.h"
#include "wb_ldh.h"
#include "wb_bckw_gtk.h"
#include "wb_bckwnav_gtk.h"
#include "cow_wow_gtk.h"
static gint delete_event( GtkWidget *w, GdkEvent *event, gpointer bckw)
{
WbBckWGtk::activate_exit(w, bckw);
return TRUE;
}
static void destroy_event( GtkWidget *w, gpointer data)
{
}
WbBckWGtk::WbBckWGtk (
void *bckw_parent_ctx,
GtkWidget *bckw_parent_wid,
ldh_tSession bckw_ldhses,
const char *bckw_name,
wb_bck_list *l_list,
int l_editmode,
pwr_tStatus *status) :
WbBckW( bckw_parent_ctx, bckw_ldhses, bckw_name, l_list, l_editmode, status), parent_wid(bckw_parent_wid)
{
const int window_width = 1100;
const int window_height = 600;
toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW,
"default-height", window_height,
"default-width", window_width,
"title", bckw_name,
NULL);
g_signal_connect( toplevel, "delete_event", G_CALLBACK(delete_event), this);
g_signal_connect( toplevel, "destroy", G_CALLBACK(destroy_event), this);
g_signal_connect( toplevel, "focus-in-event", G_CALLBACK(WbBckWGtk::action_inputfocus), this);
CoWowGtk::SetWindowIcon( toplevel);
GtkAccelGroup *accel_g = (GtkAccelGroup *) g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_g);
GtkMenuBar *menu_bar = (GtkMenuBar *) g_object_new(GTK_TYPE_MENU_BAR, NULL);
// File Entry
GtkWidget *file_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g);
g_signal_connect(file_close, "activate", G_CALLBACK(WbBckWGtk::activate_exit), this);
GtkWidget *file_print = gtk_image_menu_item_new_from_stock(GTK_STOCK_PRINT, accel_g);
g_signal_connect(file_print, "activate", G_CALLBACK(WbBckWGtk::activate_print), this);
file_transfer_wb = gtk_menu_item_new_with_mnemonic( "_Transfer to database");
g_signal_connect(file_transfer_wb, "activate", G_CALLBACK(WbBckWGtk::activate_transfer_wb), this);
GtkWidget *file_filter = gtk_menu_item_new_with_mnemonic( "_Filter");
g_signal_connect(file_filter, "activate", G_CALLBACK(WbBckWGtk::activate_filter), this);
GtkWidget *file_open = gtk_menu_item_new_with_mnemonic( "_Open");
g_signal_connect(file_open, "activate", G_CALLBACK(WbBckWGtk::activate_open), this);
GtkWidget *file_diff = gtk_menu_item_new_with_mnemonic( "_Compare Backup File");
g_signal_connect(file_diff, "activate", G_CALLBACK(WbBckWGtk::activate_diff), this);
GtkWidget *file_diff_wb = gtk_menu_item_new_with_mnemonic( "C_ompare Database");
g_signal_connect(file_diff_wb, "activate", G_CALLBACK(WbBckWGtk::activate_diff_wb), this);
GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_open);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_diff);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_diff_wb);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_transfer_wb);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_filter);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);
GtkWidget *file = gtk_menu_item_new_with_mnemonic("_File");
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu));
// Edit menu
edit_check_all = gtk_menu_item_new_with_mnemonic( "_Check all");
g_signal_connect(edit_check_all, "activate", G_CALLBACK(WbBckWGtk::activate_check_all), this);
edit_check_clear = gtk_menu_item_new_with_mnemonic( "_Check clear");
g_signal_connect(edit_check_clear, "activate", G_CALLBACK(WbBckWGtk::activate_check_clear), this);
GtkMenu *edit_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_check_all);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_check_clear);
GtkWidget *edit = gtk_menu_item_new_with_mnemonic("_Edit");
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), edit);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(edit), GTK_WIDGET(edit_menu));
// View menu
GtkWidget *view_zoom_in = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN, NULL);
g_signal_connect(view_zoom_in, "activate", G_CALLBACK(WbBckWGtk::activate_zoom_in), this);
gtk_widget_add_accelerator( view_zoom_in, "activate", accel_g,
'i', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
GtkWidget *view_zoom_out = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT, NULL);
g_signal_connect(view_zoom_out, "activate", G_CALLBACK(WbBckWGtk::activate_zoom_out), this);
gtk_widget_add_accelerator( view_zoom_out, "activate", accel_g,
'o', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
GtkWidget *view_zoom_reset = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100, NULL);
g_signal_connect(view_zoom_reset, "activate", G_CALLBACK(WbBckWGtk::activate_zoom_reset), this);
GtkMenu *view_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_in);
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_out);
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_reset);
GtkWidget *view = gtk_menu_item_new_with_mnemonic("_View");
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), view);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(view), GTK_WIDGET(view_menu));
form = gtk_vbox_new( FALSE, 0);
// Create bckwnav
bckwnav = new WbBckWNavGtk( this, form, bckw_ldhses, l_list, l_editmode, &nav_widget);
gtk_box_pack_start( GTK_BOX(form), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
gtk_box_pack_start( GTK_BOX(form), GTK_WIDGET(nav_widget), TRUE, TRUE, 0);
gtk_container_add( GTK_CONTAINER(toplevel), form);
gtk_widget_show_all( toplevel);
wow = new CoWowGtk( toplevel);
show();
if ( list && list->type() != bck_eType_WbDiff) {
g_object_set( file_transfer_wb, "visible", FALSE, NULL);
g_object_set( edit_check_all, "visible", FALSE, NULL);
g_object_set( edit_check_clear, "visible", FALSE, NULL);
}
}
//
// Delete window
//
WbBckWGtk::~WbBckWGtk()
{
if ( bckwnav)
delete bckwnav;
if ( toplevel)
gtk_widget_destroy( toplevel);
}
void WbBckWGtk::print()
{
pwr_tStatus sts;
CoWowGtk::CreateBrowPrintDialogGtk( name, bckwnav->brow->ctx, flow_eOrientation_Portrait, 1.0,
(void *)toplevel, &sts);
}
gboolean WbBckWGtk::action_inputfocus( GtkWidget *w, GdkEvent *event, gpointer data)
{
WbBckWGtk *bckw = (WbBckWGtk *)data;
if ( bckw) {
if ( bckw->focustimer.disabled())
return FALSE;
bckw->bckwnav->set_input_focus();
bckw->focustimer.disable( 400);
}
return FALSE;
}
void WbBckWGtk::set_title( char *title)
{
char *titleutf8 = g_convert( title, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);
gtk_window_set_title( GTK_WINDOW(toplevel), titleutf8);
g_free( titleutf8);
}
void WbBckWGtk::activate_exit( GtkWidget *w, gpointer data)
{
WbBckWGtk *bckw = (WbBckWGtk *)data;
delete bckw;
}
void WbBckWGtk::activate_print( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_print();
}
void WbBckWGtk::activate_open( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_open();
}
void WbBckWGtk::activate_diff( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_diff();
}
void WbBckWGtk::activate_diff_wb( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_diff_wb();
}
void WbBckWGtk::activate_transfer_wb( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_transfer_wb();
}
void WbBckWGtk::activate_filter( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_filter();
}
void WbBckWGtk::activate_check_all( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_check_all();
}
void WbBckWGtk::activate_check_clear( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->activate_check_clear();
}
void WbBckWGtk::activate_zoom_in( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->bckwnav->zoom( 1.2);
}
void WbBckWGtk::activate_zoom_out( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->bckwnav->zoom( 5.0/6);
}
void WbBckWGtk::activate_zoom_reset( GtkWidget *w, gpointer data)
{
WbBckW *bckw = (WbBckW *)data;
bckw->bckwnav->unzoom();
}
void WbBckWGtk::activate_help( GtkWidget *w, gpointer data)
{
CoXHelp::dhelp( "messagewindow_refman", 0, navh_eHelpFile_Other, "$pwr_lang/man_dg.dat",
true);
}
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#ifndef wb_bckw_gtk_h
#define wb_bckw_gtk_h
/* wb_bckw_gtk.h -- Backupfile display window */
#ifndef wb_bckw_h
# include "wb_bckw.h"
#endif
#ifndef cow_wow_gtk_h
# include "cow_wow_gtk.h"
#endif
#include <gtk/gtk.h>
class WbBckWGtk : public WbBckW {
public:
WbBckWGtk(
void *l_parent_ctx,
GtkWidget *l_parent_wid,
ldh_tSession l_ldhses,
const char *l_name,
wb_bck_list *l_list,
int l_editmode,
pwr_tStatus *status);
~WbBckWGtk();
GtkWidget *parent_wid;
GtkWidget *toplevel;
GtkWidget *form;
GtkWidget *nav_widget;
GtkWidget *file_transfer_wb;
GtkWidget *edit_check_all;
GtkWidget *edit_check_clear;
CoWowFocusTimerGtk focustimer;
CoWowFocusTimerGtk maptimer;
void print();
void set_title( char *title);
static gboolean action_inputfocus( GtkWidget *w, GdkEvent *event, gpointer data);
static void activate_exit( GtkWidget *w, gpointer data);
static void activate_print( GtkWidget *w, gpointer data);
static void activate_open( GtkWidget *w, gpointer data);
static void activate_diff( GtkWidget *w, gpointer data);
static void activate_diff_wb( GtkWidget *w, gpointer data);
static void activate_transfer_wb( GtkWidget *w, gpointer data);
static void activate_filter( GtkWidget *w, gpointer data);
static void activate_check_all( GtkWidget *w, gpointer data);
static void activate_check_clear( GtkWidget *w, gpointer data);
static void activate_zoom_in( GtkWidget *w, gpointer data);
static void activate_zoom_out( GtkWidget *w, gpointer data);
static void activate_zoom_reset( GtkWidget *w, gpointer data);
static void activate_help( GtkWidget *w, gpointer data);
};
#endif
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
/* wb_bckwnav_gtk.cpp -- Backupfile display window */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include "co_cdh.h"
#include "co_time.h"
#include "co_dcli.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_browwidget_gtk.h"
#include "wb_ldh.h"
#include "wb_bckwnav_gtk.h"
WbBckWNavGtk::WbBckWNavGtk (
void *l_parent_ctx,
GtkWidget *l_parent_wid,
ldh_tSession l_ldhses,
wb_bck_list *l_list,
int l_editmode,
GtkWidget **w) :
WbBckWNav( l_parent_ctx, l_ldhses, l_list, l_editmode), parent_wid(l_parent_wid)
{
form_widget = scrolledbrowwidgetgtk_new(
WbBckWNav::init_brow_cb, this, &brow_widget);
gtk_widget_show_all( brow_widget);
// Create the root item
*w = form_widget;
}
//
// Delete ev
//
WbBckWNavGtk::~WbBckWNavGtk()
{
delete brow;
gtk_widget_destroy( form_widget);
}
void WbBckWNavGtk::set_input_focus()
{
gtk_widget_grab_focus( brow_widget);
}
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#ifndef wb_bckwnav_gtk_h
#define wb_bckwnav_gtk_h
/* wb_bckwnav_gtk.h -- Backup display window */
#ifndef wb_bckwnav_h
# include "wb_bckwnav.h"
#endif
class WbBckWNavGtk : public WbBckWNav {
public:
WbBckWNavGtk(
void *bckw_parent_ctx,
GtkWidget *bckw_parent_wid,
ldh_tSession bckw_ldhses,
wb_bck_list *l_list,
int l_editmode,
GtkWidget **w);
~WbBckWNavGtk();
GtkWidget *parent_wid;
GtkWidget *brow_widget;
GtkWidget *form_widget;
GtkWidget *toplevel;
void set_input_focus();
};
#endif
...@@ -71,6 +71,7 @@ extern "C" { ...@@ -71,6 +71,7 @@ extern "C" {
#include "wb_foe_gtk.h" #include "wb_foe_gtk.h"
#include "wb_utl_gtk.h" #include "wb_utl_gtk.h"
#include "wb_xcrr_gtk.h" #include "wb_xcrr_gtk.h"
#include "wb_bckw_gtk.h"
#define max(Dragon,Eagle) ((Dragon) > (Eagle) ? (Dragon) : (Eagle)) #define max(Dragon,Eagle) ((Dragon) > (Eagle) ? (Dragon) : (Eagle))
#define min(Dragon,Eagle) ((Dragon) < (Eagle) ? (Dragon) : (Eagle)) #define min(Dragon,Eagle) ((Dragon) < (Eagle) ? (Dragon) : (Eagle))
...@@ -463,6 +464,11 @@ WCrr *WNavGtk::wcrr_new( pwr_tAttrRef *aref, pwr_tStatus *status) ...@@ -463,6 +464,11 @@ WCrr *WNavGtk::wcrr_new( pwr_tAttrRef *aref, pwr_tStatus *status)
return new WCrrGtk( parent_wid, this, ldhses, aref, gbl.advanced_user, status); return new WCrrGtk( parent_wid, this, ldhses, aref, gbl.advanced_user, status);
} }
WbBckW *WNavGtk::bckw_new( char *name, wb_bck_list *list, pwr_tStatus *status)
{
return new WbBckWGtk( this, parent_wid, ldhses, name, list, editmode, status);
}
void WNavGtk::wge_subwindow_loop( WGe *wge) void WNavGtk::wge_subwindow_loop( WGe *wge)
{ {
gtk_main(); gtk_main();
......
...@@ -96,6 +96,7 @@ class WNavGtk : public WNav { ...@@ -96,6 +96,7 @@ class WNavGtk : public WNav {
CoLogin *login_new( const char *name, const char *groupname, CoLogin *login_new( const char *name, const char *groupname,
void (* bc_success)( void *), void (* bc_cancel)( void *), pwr_tStatus *status); void (* bc_success)( void *), void (* bc_cancel)( void *), pwr_tStatus *status);
WCrr *wcrr_new( pwr_tAttrRef *aref, pwr_tStatus *status); WCrr *wcrr_new( pwr_tAttrRef *aref, pwr_tStatus *status);
WbBckW *bckw_new( char *name, wb_bck_list *list, pwr_tStatus *status);
static void trace_scan( WNavGtk *wnav); static void trace_scan( WNavGtk *wnav);
static void sel_lose_cb( GtkWidget *w, GdkEventSelection *event, static void sel_lose_cb( GtkWidget *w, GdkEventSelection *event,
......
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pwr.h"
#include "pwr_class.h"
#include "pwr_baseclasses.h"
#include "co_dcli.h"
#include "co_time.h"
#include "rt_gdh.h"
#include "rt_bckdef.h"
#include "wb_ldh.h"
#include "wb_bck.h"
#include "wb_ldh_msg.h"
wb_bck_list::~wb_bck_list()
{
bck_sItem *ip;
bck_sItem *next = m_first;
while ( next) {
ip = next;
next = ip->next;
free( ip->valuep);
free( ip);
}
}
void wb_bck_list::add( pwr_tAttrRef *arp, void *value, unsigned int size)
{
bck_sItem *ip = (bck_sItem *)malloc( sizeof(bck_sItem));
ip->aref = *arp;
ip->size = size;
ip->valuep = malloc(size);
memcpy( ip->valuep, value, size);
ip->value2p = 0;
ip->hide = 0;
ip->next = 0;
if ( !m_first)
m_first = ip;
else
m_last->next = ip;
m_last = ip;
}
void wb_bck_list::add( bck_sItem *xp, void *value2)
{
bck_sItem *ip = (bck_sItem *)malloc( sizeof(bck_sItem));
ip->aref = xp->aref;
ip->size = xp->size;
ip->valuep = malloc(ip->size);
memcpy( ip->valuep, xp->valuep, ip->size);
if ( value2) {
ip->value2p = malloc(ip->size);
memcpy( ip->value2p, value2, ip->size);
}
else
ip->value2p = 0;
ip->hide = 0;
ip->next = 0;
if ( !m_first)
m_first = ip;
else
m_last->next = ip;
m_last = ip;
}
pwr_tStatus wb_bck_list::print( char *outfile)
{
pwr_tFileName fname;
FILE *fout;
pwr_tStatus sts;
dcli_translate_filename( fname, outfile);
fout = fopen( fname, "w");
if ( !fout)
return LDH__NOSUCHFILE;
bck_sItem *ip = m_first;
while (ip) {
char str[1024];
pwr_eType atype;
int printed = 0;
char *anamep;
int size;
sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size);
if ( EVEN(sts)) return sts;
fprintf( fout, "%s", anamep);
sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype);
if ( ODD(sts)) {
sts = cdh_AttrValueToString( atype, ip->valuep, str, sizeof(str));
if ( ODD(sts)) {
fprintf( fout, "\n %s\n", str);
printed = 1;
}
}
if ( !printed) {
// Print as hex code
unsigned char *p = (unsigned char *)ip->valuep;
for ( int i = 0; i < (int)ip->size; i++, p++) {
if ((i % 16) == 0) fprintf( fout, "\n ");
fprintf( fout, "%02x ", *p);
}
fprintf( fout, "\n");
}
ip = ip->next;
}
fclose( fout);
return LDH__SUCCESS;
}
pwr_tStatus wb_bck_list::read_db( wb_bck_list *lp)
{
pwr_eType atype;
char *anamep;
int size;
void *valuep;
pwr_tAName aname;
pwr_tAttrRef aref;
pwr_tCid cid;
char *s;
pwr_tStatus sts;
m_type = bck_eType_Wb;
bck_sItem *ip = lp->m_first;
while (ip) {
sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size);
if ( EVEN(sts)) return sts;
sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype);
if ( ODD(sts)) {
// Read value from database
strncpy( aname, anamep, sizeof(aname));
if ( (s = strrchr( aname, '.')) && strcmp( s, ".ActualValue") == 0) {
*s = 0;
sts = ldh_NameToAttrRef( m_ldhses, aname, &aref);
if ( EVEN(sts)) return sts;
sts = ldh_GetAttrRefTid( m_ldhses, &aref, &cid);
if ( EVEN(sts)) return sts;
switch ( cid) {
case pwr_cClass_Ao:
case pwr_cClass_Do:
case pwr_cClass_Io:
case pwr_cClass_Av:
case pwr_cClass_Dv:
case pwr_cClass_Iv:
// Read InitValue instead of ActualValue
strcat( aname, ".InitialValue");
sts = ldh_NameToAttrRef( m_ldhses, aname, &aref);
if ( EVEN(sts)) return sts;
valuep = malloc(ip->size);
sts = ldh_ReadAttribute( m_ldhses, &aref, valuep, ip->size);
break;
default:
valuep = malloc(ip->size);
sts = ldh_ReadAttribute( m_ldhses, &ip->aref, valuep, ip->size);
}
}
else {
valuep = malloc(ip->size);
sts = ldh_ReadAttribute( m_ldhses, &ip->aref, valuep, ip->size);
}
}
add( &ip->aref, valuep, ip->size);
free( valuep);
ip = ip->next;
}
return LDH__SUCCESS;
}
pwr_tStatus wb_bck_list::diff( wb_bck_list *lp, char *outfile)
{
pwr_tFileName fname;
FILE *fout;
pwr_tStatus sts;
int diff_cnt = 0;
dcli_translate_filename( fname, outfile);
fout = fopen( fname, "w");
if ( !fout)
return LDH__NOSUCHFILE;
if ( lp)
fprintf( fout, "Backup difference: 1: %s, 2: %s\n", m_filename, lp->m_filename);
else
fprintf( fout, "Backup difference: 1: %s, 2: Workbench\n", m_filename);
bck_sItem *ip = m_first;
while (ip) {
char str[1024];
char str2[1024];
pwr_eType atype;
char *anamep;
int size;
sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size);
if ( EVEN(sts)) return sts;
sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype);
if ( ODD(sts)) {
void *value2p;
bck_sItem *ip2 = lp->find( &ip->aref);
if ( ip2) {
value2p = ip2->valuep;
int is_equal = 0;
switch ( atype) {
case pwr_eType_String:
case pwr_eType_Text:
is_equal = strcmp( (const char *)value2p, (const char *)ip->valuep) == 0 ? 1 : 0;
break;
default:
is_equal = memcmp( value2p, ip->valuep, ip->size) == 0 ? 1 : 0;
}
if ( is_equal) {
ip = ip->next;
continue;
}
sts = cdh_AttrValueToString( atype, value2p, str2, sizeof(str2));
if ( EVEN(sts))
strcpy( str2, "-");
}
else
strcpy( str2, "-");
sts = cdh_AttrValueToString( atype, ip->valuep, str, sizeof(str));
if ( EVEN(sts))
strcpy( str, "-");
fprintf( fout, "%s\n", anamep);
fprintf( fout, "1> %s\n", str);
fprintf( fout, "2> %s\n", str2);
diff_cnt++;
}
ip = ip->next;
}
if ( diff_cnt)
fprintf( fout, "%d differences found\n", diff_cnt);
else
fprintf( fout, "No differences found\n");
fclose( fout);
return LDH__SUCCESS;
}
pwr_tStatus wb_bck_list::diff( wb_bck_list *lp, wb_bck_list *outlp)
{
pwr_tStatus sts;
int diff_cnt = 0;
if ( lp->m_type == bck_eType_Wb)
outlp->m_type = bck_eType_WbDiff;
else
outlp->m_type = bck_eType_FileDiff;
bck_sItem *ip = m_first;
while (ip) {
pwr_eType atype;
char *anamep;
int size;
sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size);
if ( EVEN(sts)) return sts;
sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype);
if ( ODD(sts)) {
void *value2p;
bck_sItem *ip2 = lp->find( &ip->aref);
if ( ip2) {
value2p = ip2->valuep;
int is_equal = 0;
switch ( atype) {
case pwr_eType_String:
case pwr_eType_Text:
is_equal = strcmp( (const char *)value2p, (const char *)ip->valuep) == 0 ? 1 : 0;
break;
default:
is_equal = memcmp( value2p, ip->valuep, ip->size) == 0 ? 1 : 0;
}
if ( is_equal) {
ip = ip->next;
continue;
}
}
else
value2p = 0;
outlp->add( ip, value2p);
diff_cnt++;
}
ip = ip->next;
}
return LDH__SUCCESS;
}
bck_sItem *wb_bck_list::find( pwr_tAttrRef *arp)
{
for ( bck_sItem *ip = m_first; ip; ip = ip->next) {
if ( cdh_ObjidIsEqual( arp->Objid, ip->aref.Objid) && arp->Offset == ip->aref.Offset &&
arp->Size == ip->aref.Size) {
return ip;
}
}
return 0;
}
pwr_tStatus wb_bck_list::read() {
FILE *f;
BCK_FILEHEAD_STRUCT fh;
bck_t_cycleheader ch;
bck_t_writeheader dh;
int c, d;
unsigned char *datap;
pwr_tStatus sts;
int csts;
char *namep;
pwr_tAName aname;
int size;
m_type = bck_eType_File;
// Open file
f = fopen( m_filename, "rb");
if ( !f)
return LDH__NOSUCHFILE;
// Read header
fseek (f, 0, 0);
fread (&fh, sizeof fh, 1, f);
if (fh.version != BCK_FILE_VERSION) {
printf ("This program is built with header version %d\n", BCK_FILE_VERSION);
return LDH__BCKVERSION;
}
for (c=0; c<2; c++) {
fseek(f, fh.curdata [c], 0);
fread(&ch, sizeof ch, 1, f);
/* Work thru the data segments */
for ( d = 0; d < (int)ch.segments; d++) {
csts = fread(&dh, sizeof dh, 1, f);
if (csts != 0) {
if (dh.namesize > 0) {
namep = (char *)malloc(dh.namesize + 1);
csts = fread(namep, dh.namesize + 1, 1, f);
} else
namep = NULL;
datap = (unsigned char *)malloc(dh.size);
csts = fread(datap, dh.size, 1, f);
}
if (csts == 0) {
printf( "** Read error\n");
break;
}
if (dh.valid) {
sts = ldh_ObjidToName( m_ldhses, dh.objid, cdh_mName_volumeStrict, aname, sizeof(aname), &size);
if ( EVEN(sts)) {
printf( "** Error, %s%s not found in this environment",
cdh_ObjidToString(0, dh.objid, 1), aname);
}
else {
strncat( aname, namep, sizeof(aname));
pwr_tAttrRef aref;
sts = ldh_NameToAttrRef( m_ldhses, aname, &aref);
if ( EVEN(sts))
printf("**Error, %s, no such attribute\n", aname);
else
add( &aref, datap, dh.size);
}
}
free(datap);
free(namep);
}
}
fclose (f);
return LDH__SUCCESS;
}
pwr_tStatus bck_dump( ldh_tSession ldhses, char *filename, char *out)
{
pwr_tFileName fname;
FILE *f, *fout;
BCK_FILEHEAD_STRUCT fh;
bck_t_cycleheader ch;
bck_t_writeheader dh;
char timstr [24];
int c, d;
unsigned char *datap, *p;
int i;
pwr_tStatus sts;
int csts;
char *namep;
pwr_tAName aname;
int size;
int dump = 0;
// Open file
dcli_translate_filename( fname, filename);
f = fopen( fname, "rb");
if ( !f)
return LDH__NOSUCHFILE;
dcli_translate_filename( fname, out);
fout = fopen( fname, "w");
if ( !fout)
return LDH__NOSUCHFILE;
// Read header and print it
fseek (f, 0, 0);
fread (&fh, sizeof fh, 1, f);
fprintf( fout, "Layout version: %d\n", fh.version);
if (fh.version != BCK_FILE_VERSION) {
printf ("This program is built with header version %d\n", BCK_FILE_VERSION);
return LDH__BCKVERSION;
}
time_AtoAscii(&fh.creationtime, time_eFormat_DateAndTime, timstr, sizeof(timstr));
fprintf( fout, "Created: %s\n", timstr);
for (c=0; c<2; c++) {
fseek(f, fh.curdata [c], 0);
fread(&ch, sizeof ch, 1, f);
/* Work thru the data segments */
for ( d = 0; d < (int)ch.segments; d++) {
csts = fread(&dh, sizeof dh, 1, f);
if (csts != 0) {
if (dh.namesize > 0) {
namep = (char *)malloc(dh.namesize + 1);
csts = fread(namep, dh.namesize + 1, 1, f);
} else
namep = NULL;
datap = (unsigned char *)malloc(dh.size);
csts = fread(datap, dh.size, 1, f);
}
if (csts == 0) {
fprintf( fout, "Read error\n");
break;
}
if (dh.valid) {
if ( dump) {
fprintf( fout, "%s%s", cdh_ObjidToString(0, dh.objid, 1), namep);
p = datap;
for ( i = 0; i < (int)dh.size; i++, p++) {
if ((i % 16) == 0) fprintf( fout, "\n ");
fprintf( fout, "%02x ", *p);
}
fprintf( fout, "\n");
}
else {
sts = ldh_ObjidToName( ldhses, dh.objid, cdh_mName_volumeStrict, aname, sizeof(aname), &size);
if ( EVEN(sts))
strcpy( aname, cdh_ObjidToString(0, dh.objid, 1));
strncat( aname, namep, sizeof(aname));
fprintf( fout, "%s", aname);
char str[1024];
pwr_tAttrRef aref;
pwr_eType atype;
int printed = 0;
sts = ldh_NameToAttrRef( ldhses, aname, &aref);
if ( ODD(sts)) {
sts = ldh_GetAttrRefType( ldhses, &aref, &atype);
if ( ODD(sts)) {
sts = cdh_AttrValueToString( atype, datap, str, sizeof(str));
if ( ODD(sts)) {
fprintf( fout, "\n %s\n", str);
printed = 1;
}
}
}
if ( !printed) {
// Print as hex code
p = datap;
for ( i = 0; i < (int)dh.size; i++, p++) {
if ((i % 16) == 0) fprintf( fout, "\n ");
fprintf( fout, "%02x ", *p);
}
fprintf( fout, "\n");
}
}
}
free(datap);
free(namep);
}
}
fclose (f);
fclose (fout);
return LDH__SUCCESS;
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#ifndef wb_bck_h
#define wb_bck_h
typedef enum {
bck_eType_,
bck_eType_WbDiff,
bck_eType_FileDiff,
bck_eType_Wb,
bck_eType_File
} bck_eType;
typedef struct sBckItem {
pwr_tAttrRef aref;
unsigned int size;
void *valuep;
void *value2p;
int hide;
struct sBckItem *next;
} bck_sItem;
class wb_bck_list {
private:
bck_sItem *m_first;
bck_sItem *m_last;
pwr_tFileName m_filename;
ldh_tSession m_ldhses;
bck_eType m_type;
void add( pwr_tAttrRef *arp, void *value, unsigned int size);
void add( bck_sItem *xp, void *value2);
bck_sItem *find( pwr_tAttrRef *arp);
public:
wb_bck_list( ldh_tSession ldhses, char *filename) : m_first(0), m_last(0), m_ldhses(ldhses), m_type(bck_eType_) {
dcli_translate_filename( m_filename, filename);
}
~wb_bck_list();
bck_eType type() { return m_type;}
pwr_tStatus read();
pwr_tStatus read_db( wb_bck_list *lp);
pwr_tStatus print( char *outfile);
pwr_tStatus diff( wb_bck_list *lp, char *outfile);
pwr_tStatus diff( wb_bck_list *lp, wb_bck_list *outlp);
bck_sItem *first() { return m_first;}
bck_sItem *next( bck_sItem *item) { return item->next;}
};
pwr_tStatus bck_dump( ldh_tSession ldhses, char *filename, char *out);
#endif
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
/* wb_bckw.cpp -- Backupfile display window */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include "co_cdh.h"
#include "co_time.h"
#include "co_dcli.h"
#include "co_lng.h"
#include "cow_xhelp.h"
#include "cow_wow.h"
#include "wb_ldh.h"
#include "wb_bckw.h"
WbBckW::WbBckW(
void *l_parent_ctx,
ldh_tSesContext l_ldhses,
const char *bckw_name,
wb_bck_list *l_list,
int l_editmode,
pwr_tStatus *status) :
parent_ctx(l_parent_ctx), ldhses(l_ldhses), bckwnav(NULL),
size(0), max_size(500), list(l_list), editmode(l_editmode), wow(0)
{
*status = 1;
strcpy( name, bckw_name);
}
WbBckW::~WbBckW() {
if ( list)
delete list;
}
void WbBckW::show()
{
bckwnav->show();
}
void WbBckW::activate_transfer_wb()
{
wow->DisplayQuestion( this, "Transfer to database",
"Do you want to transfer the marked values to database",
transfer_wb_ok, 0, 0);
}
void WbBckW::transfer_wb_ok( void *ctx, void *data)
{
WbBckW *bckw = (WbBckW *)ctx;
bckw->bckwnav->transfer_wb();
}
void WbBckW::activate_filter()
{
wow->CreateInputDialog( this, "Filter", "Enter hierarchy",
filter_cb, 0, 40, 0, 0);
}
void WbBckW::filter_cb( void *ctx, void *data, char *text)
{
WbBckW *bckw = (WbBckW *)ctx;
pwr_tStatus sts;
sts = bckw->bckwnav->filter( text);
if ( EVEN(sts))
bckw->wow->DisplayError( "Error Message", "Hierarchy not found");
}
void WbBckW::activate_open()
{
wow->CreateFileSelDia( "Backup File Selection", (void *)this,
file_selected_cb, wow_eFileSelType_Backup);
}
void WbBckW::file_selected_cb( void *ctx, char *filename, wow_eFileSelType file_type)
{
WbBckW *bckw = (WbBckW *)ctx;
pwr_tStatus sts;
printf( "File : %s\n", filename);
wb_bck_list *slist = new wb_bck_list( bckw->ldhses, filename);
sts = slist->read();
if ( EVEN(sts)) {
return;
}
bckw->bckwnav->clear();
if ( bckw->list)
delete bckw->list;
bckw->list = bckw->bckwnav->list = slist;
bckw->bckwnav->show();
bckw->set_title( filename);
}
void WbBckW::activate_diff()
{
if ( !list)
return;
wow->CreateFileSelDia( "Backup File Selection", (void *)this,
diff_file_selected_cb, wow_eFileSelType_Backup);
}
void WbBckW::diff_file_selected_cb( void *ctx, char *filename, wow_eFileSelType file_type)
{
WbBckW *bckw = (WbBckW *)ctx;
pwr_tStatus sts;
printf( "File : %s\n", filename);
if ( !bckw->list)
return;
wb_bck_list *dlist = new wb_bck_list( bckw->ldhses, filename);
sts = dlist->read();
if ( EVEN(sts)) {
bckw->wow->DisplayError( "Error Message", "Read error");
return;
}
wb_bck_list *outlist = new wb_bck_list( bckw->ldhses, (char *)"Difference list");
sts = bckw->list->diff( dlist, outlist);
bckw->bckwnav->clear();
delete bckw->list;
delete dlist;
bckw->list = bckw->bckwnav->list = outlist;
bckw->bckwnav->show();
bckw->set_title( (char *)"File Difference");
}
void WbBckW::activate_diff_wb()
{
pwr_tStatus sts;
if ( !list)
return;
wb_bck_list *listdb = new wb_bck_list( ldhses, (char *)"Workbench");
sts = listdb->read_db( list);
if ( EVEN(sts)) {
bckw->wow->DisplayError( "Error Message", "Read error");
return;
}
wb_bck_list *outlist = new wb_bck_list( ldhses, (char *)"Difference list");
sts = list->diff( listdb, outlist);
bckwnav->clear();
delete list;
delete listdb;
list = bckwnav->list = outlist;
bckwnav->show();
set_title( (char *)"Database Difference");
}
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#ifndef wb_bckw_h
#define wb_bckw_h
/* wb_bckw.h -- Backupfile display window */
#ifndef pwr_h
# include "pwr.h"
#endif
#ifndef wb_bck_h
# include "wb_bck.h"
#endif
#ifndef wb_bckwnav_h
# include "wb_bckwnav.h"
#endif
class CoWow;
class CoWowFocusTimer;
#include "cow_wow.h"
class WbBckW {
public:
WbBckW(
void *l_parent_ctx,
ldh_tSesContext l_ldhses,
const char *bckw_name,
wb_bck_list *l_list,
int l_editmode,
pwr_tStatus *status);
~WbBckW();
virtual void print() {}
virtual void set_title( char *title) {}
void show();
void activate_print() {print();}
void activate_transfer_wb();
void activate_filter();
void activate_open();
void activate_diff();
void activate_diff_wb();
void activate_check_all() { bckwnav->check_all();}
void activate_check_clear() { bckwnav->check_clear();}
static void transfer_wb_ok( void *ctx, void *data);
static void filter_cb( void *ctx, void *data, char *text);
static void file_selected_cb( void *ctx, char *filename, wow_eFileSelType file_type);
static void diff_file_selected_cb( void *ctx, char *filename, wow_eFileSelType file_type);
void *parent_ctx;
ldh_tSesContext ldhses;
char name[80];
WbBckWNav *bckwnav;
int size;
int max_size;
wb_bck_list *list;
int editmode;
CoWow *wow;
};
#endif
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
/* wb_logwnav.cpp -- Backupfile display window */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include "co_cdh.h"
#include "co_time.h"
#include "co_dcli.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "xnav_bitmap_save12.h"
#include "xnav_bitmap_build12.h"
#include "xnav_bitmap_package12.h"
#include "xnav_bitmap_copy12.h"
#include "xnav_bitmap_export12.h"
#include "xnav_bitmap_clone12.h"
#include "wb_ldh.h"
#include "wb_bckwnav.h"
#include "pwr_baseclasses.h"
#include "wb_ldh_msg.h"
//
// Free pixmaps
//
void WbBckWNavBrow::free_pixmaps()
{
brow_FreeAnnotPixmap( ctx, pixmap_save);
brow_FreeAnnotPixmap( ctx, pixmap_build);
brow_FreeAnnotPixmap( ctx, pixmap_package);
brow_FreeAnnotPixmap( ctx, pixmap_copy);
brow_FreeAnnotPixmap( ctx, pixmap_export);
brow_FreeAnnotPixmap( ctx, pixmap_clone);
}
//
// Create pixmaps for leaf, closed map and open map
//
void WbBckWNavBrow::allocate_pixmaps()
{
flow_sPixmapData pixmap_data;
int i;
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_save12_width;
pixmap_data[i].height =xnav_bitmap_save12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_save12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_save);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_build12_width;
pixmap_data[i].height =xnav_bitmap_build12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_build12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_build);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_package12_width;
pixmap_data[i].height =xnav_bitmap_package12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_package12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_package);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_copy12_width;
pixmap_data[i].height =xnav_bitmap_copy12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_copy12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_copy);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_export12_width;
pixmap_data[i].height =xnav_bitmap_export12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_export12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_export);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_clone12_width;
pixmap_data[i].height =xnav_bitmap_clone12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_clone12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_clone);
}
//
// Create nodeclasses
//
void WbBckWNavBrow::create_nodeclasses()
{
allocate_pixmaps();
// Create common-class
brow_CreateNodeClass( ctx, "LogDefault",
flow_eNodeGroup_Common, &nc_bck);
brow_AddAnnotPixmap( nc_bck, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
brow_AddAnnot( nc_bck, 2.8, 0.6, 0,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_bck, 35, 0.6, 1,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_bck, 45, 0.6, 2,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddFrame( nc_bck, 0, 0, 35, 0.83, flow_eDrawType_LineGray, -1, 1);
// Create common-class with radiobutton
brow_CreateNodeClass( ctx, "LogDefault",
flow_eNodeGroup_Common, &nc_wbbck);
brow_AddAnnotPixmap( nc_wbbck, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
brow_AddRadiobutton( nc_wbbck, 1.4, 0.03, 0.7, 0.7, 0, flow_eDrawType_Line, 1);
brow_AddAnnot( nc_wbbck, 2.8, 0.6, 0,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_wbbck, 35, 0.6, 1,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_wbbck, 45, 0.6, 2,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddFrame( nc_wbbck, 0, 0, 35, 0.83, flow_eDrawType_LineGray, -1, 1);
}
void WbBckWNavBrow::brow_setup()
{
brow_sAttributes brow_attr;
unsigned long mask;
mask = 0;
mask |= brow_eAttr_indentation;
brow_attr.indentation = 0.5;
mask |= brow_eAttr_annotation_space;
brow_attr.annotation_space = 0.5;
brow_SetAttributes( ctx, &brow_attr, mask);
brow_SetCtxUserData( ctx, bckwnav);
brow_EnableEvent( ctx, flow_eEvent_MB1Click, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_MB1DoubleClick, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_MB3Press, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_MB3Down, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_SelectClear, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ObjectDeleted, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Up, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Down, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PF3, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PageUp, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PageDown, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ScrollUp, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ScrollDown, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Radiobutton, flow_eEventType_CallBack,
WbBckWNav::brow_cb);
}
//
// Backcall routine called at creation of the brow widget
// Enable event, create nodeclasses and insert the root objects.
//
int WbBckWNav::init_brow_cb( FlowCtx *fctx, void *client_data)
{
WbBckWNav *bckwnav = (WbBckWNav *) client_data;
BrowCtx *ctx = (BrowCtx *)fctx;
bckwnav->brow = new WbBckWNavBrow( ctx, (void *)bckwnav);
bckwnav->brow->brow_setup();
bckwnav->brow->create_nodeclasses();
return 1;
}
WbBckWNav::WbBckWNav( void *l_parent_ctx, ldh_tSesContext l_ldhses, wb_bck_list *l_list, int l_editmode) :
parent_ctx(l_parent_ctx), ldhses(l_ldhses), list(l_list), editmode(l_editmode)
{
}
//
// Delete ev
//
WbBckWNav::~WbBckWNav()
{
}
WbBckWNavBrow::~WbBckWNavBrow()
{
free_pixmaps();
}
//
// Zoom
//
void WbBckWNav::zoom( double zoom_factor)
{
brow_Zoom( brow->ctx, zoom_factor);
}
//
// Return to base zoom factor
//
void WbBckWNav::unzoom()
{
brow_UnZoom( brow->ctx);
}
//
// Callbacks from brow
//
int WbBckWNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
{
WbBckWNav *bckwnav;
ItemBck *item;
if ( event->event == flow_eEvent_ObjectDeleted)
{
brow_GetUserData( event->object.object, (void **)&item);
delete item;
return 1;
}
brow_GetCtxUserData( (BrowCtx *)ctx, (void **) &bckwnav);
switch ( event->event)
{
case flow_eEvent_Key_Up:
{
brow_tNode *node_list;
int node_count;
brow_tObject object;
int sts;
brow_GetSelectedNodes( bckwnav->brow->ctx, &node_list, &node_count);
if ( !node_count) {
sts = brow_GetLastVisible( bckwnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
if ( !brow_IsVisible( bckwnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
sts = brow_GetLastVisible( bckwnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
sts = brow_GetPrevious( bckwnav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
if ( node_count)
free( node_list);
return 1;
}
}
}
brow_SelectClear( bckwnav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( bckwnav->brow->ctx, object);
if ( !brow_IsVisible( bckwnav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( bckwnav->brow->ctx, object, 0.25);
if ( node_count)
free( node_list);
break;
}
case flow_eEvent_Key_Down:
{
brow_tNode *node_list;
int node_count;
brow_tObject object;
int sts;
brow_GetSelectedNodes( bckwnav->brow->ctx, &node_list, &node_count);
if ( !node_count) {
sts = brow_GetFirstVisible( bckwnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
if ( !brow_IsVisible( bckwnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
sts = brow_GetFirstVisible( bckwnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
sts = brow_GetNext( bckwnav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
if ( node_count)
free( node_list);
return 1;
}
}
}
brow_SelectClear( bckwnav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( bckwnav->brow->ctx, object);
if ( !brow_IsVisible( bckwnav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( bckwnav->brow->ctx, object, 0.75);
if ( node_count)
free( node_list);
break;
}
case flow_eEvent_SelectClear:
brow_ResetSelectInverse( bckwnav->brow->ctx);
break;
case flow_eEvent_MB1Click:
// Select
double ll_x, ll_y, ur_x, ur_y;
int sts;
switch ( event->object.object_type)
{
case flow_eObjectType_Node:
brow_MeasureNode( event->object.object, &ll_x, &ll_y,
&ur_x, &ur_y);
if ( event->object.x < ll_x + 1.0)
{
// Simulate doubleclick
flow_tEvent doubleclick_event;
doubleclick_event = (flow_tEvent) calloc( 1, sizeof(*doubleclick_event));
memcpy( doubleclick_event, event, sizeof(*doubleclick_event));
doubleclick_event->event = flow_eEvent_MB1DoubleClick;
sts = WbBckWNav::brow_cb( ctx, doubleclick_event);
free( (char *) doubleclick_event);
return sts;
}
if ( brow_FindSelectedObject( bckwnav->brow->ctx, event->object.object))
{
brow_SelectClear( bckwnav->brow->ctx);
}
else
{
brow_SelectClear( bckwnav->brow->ctx);
brow_SetInverse( event->object.object, 1);
brow_SelectInsert( bckwnav->brow->ctx, event->object.object);
}
break;
default:
brow_SelectClear( bckwnav->brow->ctx);
}
break;
case flow_eEvent_Key_PageDown: {
brow_Page( bckwnav->brow->ctx, 0.95);
break;
}
case flow_eEvent_Key_PageUp: {
brow_Page( bckwnav->brow->ctx, -0.95);
break;
}
case flow_eEvent_ScrollDown: {
brow_Page( bckwnav->brow->ctx, 0.10);
break;
}
case flow_eEvent_ScrollUp: {
brow_Page( bckwnav->brow->ctx, -0.10);
break;
}
case flow_eEvent_MB1DoubleClick:
break;
case flow_eEvent_Radiobutton: {
switch ( event->object.object_type) {
case flow_eObjectType_Node:
brow_GetUserData( event->object.object, (void **)&item);
switch( item->type) {
case bckwitem_eItemType_Bck:
((ItemBck *)item)->set( !event->radiobutton.value);
break;
default:
;
}
break;
default:
;
}
break;
}
default:
;
}
return 1;
}
void WbBckWNav::show()
{
if ( !list)
return;
brow_SetNodraw( brow->ctx);
for ( bck_sItem *ip = list->first(); ip; ip = list->next( ip)) {
if ( !ip->hide)
new ItemBck( this, ip, 0, flow_eDest_IntoLast);
}
brow_ResetNodraw( brow->ctx);
brow_Redraw( brow->ctx, 0);
}
void WbBckWNav::clear()
{
brow_DeleteAll( brow->ctx);
}
pwr_tStatus WbBckWNav::transfer_wb()
{
int sts;
brow_tNode node;
int rval;
ItemBck *item;
char *anamep;
int size;
pwr_tAttrRef aref;
pwr_tCid cid;
char *s;
pwr_tAName aname;
for ( sts = brow_GetFirst( brow->ctx, &node); ODD(sts); sts = brow_GetNext( brow->ctx, node, &node)) {
brow_GetRadiobutton( node, 0, &rval);
if ( rval) {
brow_GetUserData( node, (void **)&item);
bck_sItem *ip = item->bck_item;
sts = ldh_AttrRefToName( ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size);
if ( EVEN(sts)) return sts;
strncpy( aname, anamep, sizeof(aname));
if ( (s = strrchr( aname, '.')) && strcmp( s, ".ActualValue") == 0) {
*s = 0;
sts = ldh_NameToAttrRef( ldhses, aname, &aref);
if ( EVEN(sts)) return sts;
sts = ldh_GetAttrRefTid( ldhses, &aref, &cid);
if ( EVEN(sts)) return sts;
switch ( cid) {
case pwr_cClass_Ao:
case pwr_cClass_Do:
case pwr_cClass_Io:
case pwr_cClass_Av:
case pwr_cClass_Dv:
case pwr_cClass_Iv:
// Write InitValue instead of ActualValue
strcat( aname, ".InitialValue");
sts = ldh_NameToAttrRef( ldhses, aname, &aref);
if ( EVEN(sts)) return sts;
sts = ldh_WriteAttribute( ldhses, &aref, ip->valuep, ip->size);
break;
default:
sts = ldh_WriteAttribute( ldhses, &ip->aref, ip->valuep, ip->size);
}
}
else
sts = ldh_WriteAttribute( ldhses, &ip->aref, ip->valuep, ip->size);
if ( ODD(sts)) {
memcpy( ip->value2p, ip->valuep, ip->size);
item->update();
}
else
printf("** ldh_WriteAttribute error, %s\n", anamep);
}
}
return LDH__SUCCESS;
}
pwr_tStatus WbBckWNav::filter( char *hierarchy)
{
pwr_tStatus sts;
pwr_tOid oid;
pwr_tOid p;
int found;
sts = ldh_NameToObjid( ldhses, &oid, hierarchy);
if ( EVEN(sts)) return sts;
for ( bck_sItem *ip = list->first(); ip; ip = list->next( ip)) {
sts = 1;
found = 0;
for ( p = ip->aref.Objid; ODD(sts); sts = ldh_GetParent( ldhses, p, &p)) {
if ( cdh_ObjidIsEqual( p, oid)) {
found = 1;
break;
}
}
ip->hide = !found;
}
clear();
show();
return LDH__SUCCESS;
}
void WbBckWNav::check_all()
{
int sts;
brow_tNode node;
for ( sts = brow_GetFirst( brow->ctx, &node); ODD(sts); sts = brow_GetNext( brow->ctx, node, &node))
brow_SetRadiobutton( node, 0, 1);
}
void WbBckWNav::check_clear()
{
int sts;
brow_tNode node;
for ( sts = brow_GetFirst( brow->ctx, &node); ODD(sts); sts = brow_GetNext( brow->ctx, node, &node))
brow_SetRadiobutton( node, 0, 0);
}
ItemBck::ItemBck( WbBckWNav *item_bckwnav, bck_sItem *item_bck_item,
brow_tNode dest, flow_eDest dest_code):
bckwnav(item_bckwnav), bck_item(item_bck_item)
{
char str[1024];
char *anamep;
int size;
pwr_tStatus sts;
type = bckwitem_eItemType_Bck;
sts = ldh_AttrRefToName( bckwnav->ldhses, &bck_item->aref, cdh_mName_volumeStrict, &anamep, &size);
if ( EVEN(sts)) return;
sts = ldh_GetAttrRefType( bckwnav->ldhses, &bck_item->aref, &atype);
if ( EVEN(sts)) return;
sts = cdh_AttrValueToString( atype, bck_item->valuep, str, sizeof(str));
if ( EVEN(sts))
strcpy( str, "-");
if ( bckwnav->editmode && bckwnav->list->type() == bck_eType_WbDiff)
brow_CreateNode( bckwnav->brow->ctx, (char *)"Bck", bckwnav->brow->nc_wbbck,
dest, dest_code, (void *) this, 1, &node);
else
brow_CreateNode( bckwnav->brow->ctx, (char *)"Bck", bckwnav->brow->nc_bck,
dest, dest_code, (void *) this, 1, &node);
int annot = 0;
brow_SetAnnotation( node, annot++, anamep, strlen(anamep));
brow_SetAnnotation( node, annot++, str, strlen(str));
if ( bck_item->value2p) {
sts = cdh_AttrValueToString( atype, bck_item->value2p, str, sizeof(str));
if ( EVEN(sts))
strcpy( str, "-");
brow_SetAnnotation( node, annot++, str, strlen(str));
}
brow_SetAnnotPixmap( node, 0, bckwnav->brow->pixmap_save);
}
void ItemBck::update()
{
char str[1024];
pwr_tStatus sts;
sts = cdh_AttrValueToString( atype, bck_item->valuep, str, sizeof(str));
if ( EVEN(sts))
strcpy( str, "-");
brow_SetAnnotation( node, 1, str, strlen(str));
if ( bck_item->value2p) {
sts = cdh_AttrValueToString( atype, bck_item->value2p, str, sizeof(str));
if ( EVEN(sts))
strcpy( str, "-");
brow_SetAnnotation( node, 2, str, strlen(str));
}
}
void ItemBck::set( int value)
{
brow_SetRadiobutton( node, 0, value);
}
/**
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
**/
#ifndef wb_bckwnav_h
#define wb_bckwnav_h
/* wb_bckwnav.h -- Backupfile display window */
#ifndef pwr_h
# include "pwr.h"
#endif
#ifndef flow_h
#include "flow.h"
#endif
#ifndef flow_browctx_h
#include "flow_browctx.h"
#endif
#ifndef flow_browapi_h
#include "flow_browapi.h"
#endif
#ifndef wb_bck_h
#include "wb_bck.h"
#endif
typedef enum {
bckwitem_eItemType_Bck
} bckwitem_eItemType;
class WbBckWNavBrow {
public:
WbBckWNavBrow( BrowCtx *brow_ctx, void *lwnav) : ctx(brow_ctx), bckwnav(lwnav) {};
~WbBckWNavBrow();
BrowCtx *ctx;
void *bckwnav;
brow_tNodeClass nc_bck;
brow_tNodeClass nc_wbbck;
flow_sAnnotPixmap *pixmap_save;
flow_sAnnotPixmap *pixmap_build;
flow_sAnnotPixmap *pixmap_package;
flow_sAnnotPixmap *pixmap_copy;
flow_sAnnotPixmap *pixmap_export;
flow_sAnnotPixmap *pixmap_clone;
void free_pixmaps();
void allocate_pixmaps();
void create_nodeclasses();
void brow_setup();
};
class WbBckWNav {
public:
WbBckWNav( void *l_parent_ctx, ldh_tSesContext l_ldhses, wb_bck_list *l_list, int l_editmode);
virtual ~WbBckWNav();
void *parent_ctx;
ldh_tSesContext ldhses;
WbBckWNavBrow *brow;
wb_bck_list *list;
int editmode;
virtual void set_input_focus() {}
void show();
void clear();
void zoom( double zoom_factor);
void unzoom();
pwr_tStatus transfer_wb();
pwr_tStatus filter( char *hierarchy);
void check_all();
void check_clear();
static int init_brow_cb( FlowCtx *fctx, void *client_data);
static int brow_cb( FlowCtx *ctx, flow_tEvent event);
};
class ItemBck {
public:
ItemBck( WbBckWNav *bckwnav, bck_sItem *item_bck_item,
brow_tNode dest, flow_eDest dest_code);
bckwitem_eItemType type;
WbBckWNav *bckwnav;
brow_tNode node;
bck_sItem *bck_item;
pwr_eType atype;
void set( int value);
void update();
virtual ~ItemBck() {}
};
#endif
...@@ -1954,7 +1954,7 @@ int WNav::brow_cb( FlowCtx *ctx, flow_tEvent event) ...@@ -1954,7 +1954,7 @@ int WNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
((WItemEnum *)item)->set(); ((WItemEnum *)item)->set();
break; break;
case wnav_eItemType_Mask: case wnav_eItemType_Mask:
((WItemMask *)item)->set( !event->radiobutton.value); ((WItemMask *)item)->set( event->radiobutton.value);
break; break;
default: default:
; ;
......
...@@ -87,6 +87,10 @@ ...@@ -87,6 +87,10 @@
#include "wb_log.h" #include "wb_log.h"
#endif #endif
#ifndef wb_bckw_h
#include "wb_bckw.h"
#endif
#define wnav_cVersion "X3.3a" #define wnav_cVersion "X3.3a"
#define wnav_cScriptDescKey "!** Description" #define wnav_cScriptDescKey "!** Description"
...@@ -342,6 +346,7 @@ class WNav : public WUtility{ ...@@ -342,6 +346,7 @@ class WNav : public WUtility{
void (* bc_success)( void *), void (* bc_cancel)( void *), void (* bc_success)( void *), void (* bc_cancel)( void *),
pwr_tStatus *status) { return 0;} pwr_tStatus *status) { return 0;}
virtual WCrr *wcrr_new( pwr_tAttrRef *aref, pwr_tStatus *status) { return 0;} virtual WCrr *wcrr_new( pwr_tAttrRef *aref, pwr_tStatus *status) { return 0;}
virtual WbBckW *bckw_new( char *name, wb_bck_list *list, pwr_tStatus *status) { return 0;}
static int brow_cb( FlowCtx *ctx, flow_tEvent event); static int brow_cb( FlowCtx *ctx, flow_tEvent event);
static int init_brow_base_cb( FlowCtx *fctx, void *client_data); static int init_brow_base_cb( FlowCtx *fctx, void *client_data);
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
#include "wb_xcrr.h" #include "wb_xcrr.h"
#include "ge.h" #include "ge.h"
#include "wb_utl.h" #include "wb_utl.h"
#include "wb_bck.h"
#define WNAV_MENU_CREATE 0 #define WNAV_MENU_CREATE 0
#define WNAV_MENU_ADD 1 #define WNAV_MENU_ADD 1
...@@ -192,6 +193,8 @@ static int wnav_update_func( void *client_data, ...@@ -192,6 +193,8 @@ static int wnav_update_func( void *client_data,
void *client_flag); void *client_flag);
static int wnav_clone_func( void *client_data, static int wnav_clone_func( void *client_data,
void *client_flag); void *client_flag);
static int wnav_backup_func( void *client_data,
void *client_flag);
dcli_tCmdTable wnav_command_table[] = { dcli_tCmdTable wnav_command_table[] = {
{ {
...@@ -466,6 +469,12 @@ dcli_tCmdTable wnav_command_table[] = { ...@@ -466,6 +469,12 @@ dcli_tCmdTable wnav_command_table[] = {
&wnav_clone_func, &wnav_clone_func,
{ "dcli_arg1", "/NAME", "/VID", ""} { "dcli_arg1", "/NAME", "/VID", ""}
}, },
{
"BACKUP",
&wnav_backup_func,
{ "dcli_arg1", "dcli_arg2", "dcli_arg13", "/FILE", "/FILE1", "/FILE2", "/OUT",
"/WINDOW", ""}
},
{"",}}; {"",}};
...@@ -5253,6 +5262,237 @@ static int wnav_update_func( void *client_data, ...@@ -5253,6 +5262,237 @@ static int wnav_update_func( void *client_data,
return 1; return 1;
} }
static int wnav_backup_func( void *client_data,
void *client_flag)
{
WNav *wnav = (WNav *)client_data;
char arg1_str[80];
pwr_tStatus sts;
sts = dcli_get_qualifier( "dcli_arg1", arg1_str, sizeof(arg1_str));
if ( EVEN(sts)) {
wnav->message('E', "Syntax error");
return WNAV__SYNTAX;
}
if ( cdh_NoCaseStrncmp( arg1_str, "DUMP", strlen( arg1_str)) == 0) {
pwr_tFileName filestr;
pwr_tFileName outstr;
pwr_tStatus sts;
// command is "BACKUP DUMP"
sts = wnav_wccm_get_ldhsession_cb( wnav, &wnav->ldhses);
if ( EVEN(sts)) return sts;
if ( EVEN( dcli_get_qualifier( "dcli_arg2", filestr, sizeof(filestr)))) {
if ( EVEN( dcli_get_qualifier( "/FILE" , filestr, sizeof(filestr)))) {
wnav->message('E', "Enter file");
return WNAV__QUAL;
}
}
if ( EVEN( dcli_get_qualifier( "dcli_arg3", outstr, sizeof(outstr)))) {
if ( EVEN( dcli_get_qualifier( "/OUT" , outstr, sizeof(outstr)))) {
wnav->message('E', "Enter out file");
return WNAV__QUAL;
}
}
sts = bck_dump( wnav->ldhses, filestr, outstr);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
}
else if ( cdh_NoCaseStrncmp( arg1_str, "SHOW", strlen( arg1_str)) == 0) {
pwr_tFileName filestr;
char *filep = filestr;
pwr_tFileName outstr;
char *outp = outstr;
pwr_tStatus sts;
// command is "BACKUP SHOW"
sts = wnav_wccm_get_ldhsession_cb( wnav, &wnav->ldhses);
if ( EVEN(sts)) return sts;
if ( EVEN( dcli_get_qualifier( "dcli_arg2", filestr, sizeof(filestr)))) {
if ( EVEN( dcli_get_qualifier( "/FILE" , filestr, sizeof(filestr)))) {
filep = 0;
}
}
if ( EVEN( dcli_get_qualifier( "dcli_arg3", outstr, sizeof(outstr)))) {
if ( EVEN( dcli_get_qualifier( "/OUT" , outstr, sizeof(outstr)))) {
outp = 0;
}
}
if ( filep == 0) {
wnav->bckw_new( (char *)"Backup file", 0, &sts);
}
else if ( outp == 0) {
wb_bck_list *list = new wb_bck_list( wnav->ldhses, filestr);
sts = list->read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
wnav->bckw_new( (char *)"Backup file", list, &sts);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
}
else {
wb_bck_list list( wnav->ldhses, filestr);
sts = list.read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = list.print( outstr);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
}
}
else if ( cdh_NoCaseStrncmp( arg1_str, "DIFFERENCE", strlen( arg1_str)) == 0) {
pwr_tFileName file1str;
pwr_tFileName file2str;
char *file2p = file2str;
pwr_tFileName outstr;
char *outp = outstr;
pwr_tStatus sts;
// command is "BACKUP DIFFERENCE"
sts = wnav_wccm_get_ldhsession_cb( wnav, &wnav->ldhses);
if ( EVEN(sts)) return sts;
if ( EVEN( dcli_get_qualifier( "dcli_arg2", file1str, sizeof(file1str)))) {
if ( EVEN( dcli_get_qualifier( "/FILE1" , file1str, sizeof(file1str)))) {
wnav->message('E', "Enter file");
return WNAV__QUAL;
}
}
if ( EVEN( dcli_get_qualifier( "dcli_arg3", file2str, sizeof(file2str)))) {
if ( EVEN( dcli_get_qualifier( "/FILE2" , file2str, sizeof(file2str)))) {
file2p = 0;
}
}
if ( EVEN( dcli_get_qualifier( "/OUT" , outstr, sizeof(outstr)))) {
outp = 0;
}
if ( outp) {
if ( file2p) {
// Compare two files
wb_bck_list list1( wnav->ldhses, file1str);
wb_bck_list list2( wnav->ldhses, file2str);
sts = list1.read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = list2.read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = list1.diff( &list2, outstr);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
}
else {
// Compare file with database
wb_bck_list list1( wnav->ldhses, file1str);
wb_bck_list listdb( wnav->ldhses, (char *)"Workbench");
sts = list1.read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = listdb.read_db( &list1);
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = list1.diff( &listdb, outstr);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
}
}
else {
if ( file2p) {
// Compare two files
wb_bck_list list1( wnav->ldhses, file1str);
wb_bck_list list2( wnav->ldhses, file2str);
wb_bck_list *outlist = new wb_bck_list( wnav->ldhses, (char *)"Difference list");
sts = list1.read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = list2.read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = list1.diff( &list2, outlist);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
wnav->bckw_new( (char *)"Difference list", outlist, &sts);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
}
else {
// Compare file with database
wb_bck_list list1( wnav->ldhses, file1str);
wb_bck_list listdb( wnav->ldhses, (char *)"Workbench");
wb_bck_list *outlist = new wb_bck_list( wnav->ldhses, (char *)"Difference list");
sts = list1.read();
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = listdb.read_db( &list1);
if ( EVEN(sts)) {
wnav->message(' ', wnav_get_message(sts));
return sts;
}
sts = list1.diff( &listdb, outlist);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
wnav->bckw_new( (char *)"Difference list", outlist, &sts);
if ( EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
}
}
}
else {
wnav->message('E', "Syntax error");
return WNAV__SYNTAX;
}
return 1;
}
static void wnav_clone_volume_cb( void *ctx, char *text) static void wnav_clone_volume_cb( void *ctx, char *text)
{ {
WNav *wnav = (WNav *)ctx; WNav *wnav = (WNav *)ctx;
......
...@@ -906,6 +906,21 @@ void CoWowGtk::CreateFileSelDia( const char *title, void *parent_ctx, ...@@ -906,6 +906,21 @@ void CoWowGtk::CreateFileSelDia( const char *title, void *parent_ctx,
gtk_file_filter_add_pattern( filter, "*"); gtk_file_filter_add_pattern( filter, "*");
gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter); gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter);
} }
else if ( file_type == wow_eFileSelType_Backup) {
pwr_tFileName folder;
dcli_translate_filename( folder, "$pwrp_load");
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(dialog), folder);
GtkFileFilter *filter = gtk_file_filter_new();
gtk_file_filter_set_name( filter, "*.bck");
gtk_file_filter_add_pattern( filter, "*.bck");
gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter);
filter = gtk_file_filter_new();
gtk_file_filter_set_name( filter, "All Files");
gtk_file_filter_add_pattern( filter, "*");
gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter);
}
if ( gtk_dialog_run( GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { if ( gtk_dialog_run( GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char *filename; char *filename;
......
...@@ -51,6 +51,7 @@ typedef enum { ...@@ -51,6 +51,7 @@ typedef enum {
wow_eFileSelType_Graph, wow_eFileSelType_Graph,
wow_eFileSelType_Image, wow_eFileSelType_Image,
wow_eFileSelType_History, wow_eFileSelType_History,
wow_eFileSelType_Backup,
wow_eFileSelType__ wow_eFileSelType__
} wow_eFileSelType; } wow_eFileSelType;
......
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