Commit fc0de9ca authored by Claes Sjofors's avatar Claes Sjofors

Xtt tree window to view specific classes added

parent cba719f0
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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.
**/
/* cow_tree_gtk.cpp -- Tree viewer */
#include <fstream>
#include <vector>
#include "glow_std.h"
#include "co_cdh.h"
#include "co_time.h"
#include "co_dcli.h"
#include "cow_wow_gtk.h"
#include "cow_xhelp_gtk.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_browwidget_gtk.h"
#include "glow.h"
#include "glow_curvectx.h"
#include "flow_msg.h"
#include "cow_tree_gtk.h"
#include "cow_treenav_gtk.h"
void CowTreeGtk::message( char severity, const char *message)
{
gtk_label_set_text( GTK_LABEL(msg_label), message);
}
static gint delete_event( GtkWidget *w, GdkEvent *event, gpointer data)
{
CowTreeGtk *cowtree = (CowTreeGtk *)data;
if ( cowtree->close_cb)
(cowtree->close_cb)( cowtree->parent_ctx);
else
delete cowtree;
return FALSE;
}
static void destroy_event( GtkWidget *w, gpointer data)
{
// CowTreeGtk *cowtree = (CowTreeGtk *)data;
// delete cowtree;
}
static gboolean cowtree_focus_in_event( GtkWidget *w, GdkEvent *event, gpointer data)
{
CowTreeGtk *cowtree = (CowTreeGtk *)data;
if ( cowtree->treenav)
cowtree->treenav->set_inputfocus();
return FALSE;
}
void CowTreeGtk::activate_print( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
cowtree->activate_print();
}
void CowTreeGtk::activate_close( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
if ( cowtree->close_cb)
(cowtree->close_cb)( cowtree);
else
delete cowtree;
}
void CowTreeGtk::activate_zoom_in( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
cowtree->activate_zoom_in();
}
void CowTreeGtk::activate_zoom_out( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
cowtree->activate_zoom_out();
}
void CowTreeGtk::activate_zoom_reset( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
cowtree->activate_zoom_reset();
}
void CowTreeGtk::activate_help( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
cowtree->activate_help();
}
void CowTreeGtk::activate_tree_layout( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
cowtree->treenav->show_tree();
}
void CowTreeGtk::activate_list_layout( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
cowtree->treenav->show_list();
}
void CowTreeGtk::activate_button_ok( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
pwr_tStatus sts;
sts = cowtree->activate_button_ok();
if ( ODD(sts)) {
if ( cowtree->close_cb)
(cowtree->close_cb)( cowtree->parent_ctx);
else
delete cowtree;
}
}
void CowTreeGtk::activate_button_apply( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
pwr_tStatus sts;
sts = cowtree->activate_button_ok();
}
void CowTreeGtk::activate_button_cancel( GtkWidget *w, gpointer data)
{
CowTree *cowtree = (CowTree *)data;
if ( cowtree->close_cb)
(cowtree->close_cb)( cowtree->parent_ctx);
else
delete cowtree;
}
void CowTreeGtk::pop()
{
gtk_window_present( GTK_WINDOW(toplevel));
}
CowTreeGtk::CowTreeGtk( GtkWidget *a_parent_wid,
void *a_parent_ctx,
const char *title,
pwr_tAttrRef *itemlist,
int item_cnt,
unsigned int options,
pwr_tStatus (*get_object_info)( void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*get_node_info)( void *, char *, char *, int),
pwr_tStatus (*action)( void *, pwr_tAttrRef *)) :
CowTree( a_parent_ctx, itemlist, item_cnt, options, get_object_info, get_node_info, action),
parent_wid(a_parent_wid)
{
int sts;
pwr_tFileName fname;
toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW,
"default-height", 400,
"default-width", 600,
"title", title,
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(cowtree_focus_in_event), this);
CoWowGtk::SetWindowIcon( toplevel);
GtkWidget *vbox = gtk_vbox_new( FALSE, 0);
// Menu
// Accelerators
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_print = gtk_image_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Print"));
gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(file_print),
gtk_image_new_from_stock( "gtk-print", GTK_ICON_SIZE_MENU));
g_signal_connect(file_print, "activate", G_CALLBACK(activate_print), this);
GtkWidget *file_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g);
g_signal_connect(file_close, "activate", G_CALLBACK(activate_close), this);
GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
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));
// View menu
GtkWidget *view_tree_layout = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Tree Layout"));
g_signal_connect(view_tree_layout, "activate", G_CALLBACK(activate_tree_layout), this);
GtkWidget *view_list_layout = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_List Layout"));
g_signal_connect(view_list_layout, "activate", G_CALLBACK(activate_list_layout), this);
GtkWidget *view_zoom_in = gtk_image_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("Zoom _In"));
gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(view_zoom_in),
gtk_image_new_from_stock( "gtk-zoom-in", GTK_ICON_SIZE_MENU));
g_signal_connect(view_zoom_in, "activate", G_CALLBACK(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_with_mnemonic(CoWowGtk::translate_utf8("Zoom _Out"));
gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(view_zoom_out),
gtk_image_new_from_stock( "gtk-zoom-out", GTK_ICON_SIZE_MENU));
g_signal_connect(view_zoom_out, "activate", G_CALLBACK(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_with_mnemonic(CoWowGtk::translate_utf8("Zoom _Reset"));
gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(view_zoom_reset),
gtk_image_new_from_stock( "gtk-zoom-100", GTK_ICON_SIZE_MENU));
g_signal_connect(view_zoom_reset, "activate", G_CALLBACK(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_tree_layout);
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_list_layout);
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(CoWowGtk::translate_utf8("_View"));
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), view);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(view), GTK_WIDGET(view_menu));
// Help entry
GtkWidget *help_overview = gtk_image_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Overview"));
gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(help_overview),
gtk_image_new_from_stock( "gtk-help", GTK_ICON_SIZE_MENU));
g_signal_connect(help_overview, "activate", G_CALLBACK(activate_help), this);
gtk_widget_add_accelerator( help_overview, "activate", accel_g,
'h', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_overview);
GtkWidget *help = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Help"));
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu));
// Toolbar
GtkToolbar *tools = (GtkToolbar *) g_object_new(GTK_TYPE_TOOLBAR, NULL);
GtkWidget *tools_zoom_in = gtk_button_new();
dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_in.png");
gtk_container_add( GTK_CONTAINER(tools_zoom_in),
gtk_image_new_from_file( fname));
g_signal_connect(tools_zoom_in, "clicked", G_CALLBACK(activate_zoom_in), this);
g_object_set( tools_zoom_in, "can-focus", FALSE, NULL);
gtk_toolbar_append_widget( tools, tools_zoom_in,CoWowGtk::translate_utf8("Zoom in"), "");
GtkWidget *tools_zoom_out = gtk_button_new();
dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_out.png");
gtk_container_add( GTK_CONTAINER(tools_zoom_out),
gtk_image_new_from_file( fname));
g_signal_connect(tools_zoom_out, "clicked", G_CALLBACK(activate_zoom_out), this);
g_object_set( tools_zoom_out, "can-focus", FALSE, NULL);
gtk_toolbar_append_widget( tools, tools_zoom_out,CoWowGtk::translate_utf8("Zoom out"), "");
GtkWidget *tools_zoom_reset = gtk_button_new();
dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_reset.png");
gtk_container_add( GTK_CONTAINER(tools_zoom_reset),
gtk_image_new_from_file( fname));
g_signal_connect(tools_zoom_reset, "clicked", G_CALLBACK(activate_zoom_reset), this);
g_object_set( tools_zoom_reset, "can-focus", FALSE, NULL);
gtk_toolbar_append_widget( tools, tools_zoom_reset,CoWowGtk::translate_utf8("Zoom reset"), "");
// Ok can Cancel buttons
GtkWidget *button_box = gtk_hbox_new( FALSE, 0);
button_ok = gtk_button_new_with_label( CoWowGtk::translate_utf8("Ok"));
g_object_set( button_ok, "can-focus", FALSE, NULL);
gtk_widget_set_size_request( button_ok, 110, 25);
g_signal_connect(button_ok, "clicked", G_CALLBACK(activate_button_ok), this);
button_apply = gtk_button_new_with_label( CoWowGtk::translate_utf8("Apply"));
g_object_set( button_apply, "can-focus", FALSE, NULL);
gtk_widget_set_size_request( button_apply, 110, 25);
g_signal_connect(button_apply, "clicked", G_CALLBACK(activate_button_apply), this);
button_cancel = gtk_button_new_with_label( CoWowGtk::translate_utf8("Cancel"));
g_object_set( button_cancel, "can-focus", FALSE, NULL);
gtk_widget_set_size_request( button_cancel, 110, 25);
g_signal_connect(button_cancel, "clicked", G_CALLBACK(activate_button_cancel), this);
gtk_box_pack_start( GTK_BOX(button_box), button_ok, FALSE, FALSE, 20);
gtk_box_pack_start( GTK_BOX(button_box), button_apply, FALSE, FALSE, 40);
gtk_box_pack_end( GTK_BOX(button_box), button_cancel, FALSE, FALSE, 20);
// Statusbar
GtkWidget *statusbar = gtk_hbox_new( FALSE, 0);
msg_label = gtk_label_new( "");
gtk_widget_set_size_request( msg_label, -1, 25);
gtk_box_pack_start( GTK_BOX(statusbar), msg_label, FALSE, FALSE, 20);
gtk_widget_show_all( statusbar);
treenav = new TreeNavGtk( this, toplevel,
itemlist, item_cnt, options,
get_object_info, get_node_info, &brow_widget, &sts);
treenav->message_cb = &CowTree::message;
gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(tools), FALSE, FALSE, 0);
gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(brow_widget), TRUE, TRUE, 0);
gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(button_box), FALSE, FALSE, 20);
gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(statusbar), FALSE, FALSE, 3);
gtk_container_add( GTK_CONTAINER(toplevel), vbox);
gtk_widget_show_all( toplevel);
wow = new CoWowGtk( toplevel);
}
CowTreeGtk::~CowTreeGtk()
{
delete (TreeNavGtk *)treenav;
gtk_widget_destroy( toplevel);
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 cow_tree_gtk_h
#define cow_tree_gtk_h
#include "cow_tree.h"
#include "cow_treenav.h"
#include "cow_wow_gtk.h"
/* cow_tree.h -- Tree viewer */
class CoWowRecall;
class CoWowEntryGtk;
class CowTreeNavGtk;
class CowTreeGtk : public CowTree {
public:
CowTreeGtk(
GtkWidget *a_parent_wid,
void *a_parent_ctx,
const char *title,
pwr_tAttrRef *itemlist,
int item_cnt,
unsigned int options,
pwr_tStatus (*get_object_info)( void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*get_node_info)( void *, char *, char *, int),
pwr_tStatus (*action)( void *, pwr_tAttrRef *));
GtkWidget *parent_wid;
GtkWidget *brow_widget;
GtkWidget *form_widget;
GtkWidget *toplevel;
GtkWidget *msg_label;
GtkWidget *button_ok;
GtkWidget *button_apply;
GtkWidget *button_cancel;
GtkWidget *pane;
void message( char severity, const char *message);
void pop();
static void activate_print( GtkWidget *w, gpointer data);
static void activate_close( GtkWidget *w, gpointer data);
static void activate_tree_layout( GtkWidget *w, gpointer data);
static void activate_list_layout( 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);
static void activate_button_ok( GtkWidget *w, gpointer data);
static void activate_button_apply( GtkWidget *w, gpointer data);
static void activate_button_cancel( GtkWidget *w, gpointer data);
~CowTreeGtk();
};
#endif
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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.
**/
/* cow_treenav.cpp -- Tree viewer */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "co_cdh.h"
#include "co_time.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_browwidget_gtk.h"
#include "flow_msg.h"
#include "glow.h"
#include "glow_growctx.h"
#include "glow_growapi.h"
#include "glow_growwidget_gtk.h"
#include "cow_tree_gtk.h"
#include "cow_treenav_gtk.h"
//
// Create the navigator widget
//
TreeNavGtk::TreeNavGtk(
void *xn_parent_ctx,
GtkWidget *xn_parent_wid,
pwr_tAttrRef *xn_itemlist,
int xn_item_cnt,
unsigned int xn_options,
pwr_tStatus (*xn_get_object_info)(void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*xn_get_node_info)(void *, char *, char *, int),
GtkWidget **w,
pwr_tStatus *status) :
TreeNav( xn_parent_ctx, xn_itemlist, xn_item_cnt, xn_options, xn_get_object_info, xn_get_node_info, status),
parent_wid(xn_parent_wid)
{
form_widget = scrolledbrowwidgetgtk_new(
TreeNav::init_brow_cb, this, &brow_widget);
gtk_widget_show_all( brow_widget);
// Create the root item
*w = form_widget;
*status = 1;
}
//
// Delete a nav context
//
TreeNavGtk::~TreeNavGtk()
{
delete brow;
gtk_widget_destroy( form_widget);
}
void TreeNavGtk::set_inputfocus()
{
gtk_widget_grab_focus( brow_widget);
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 cow_treenav_gtk_h
#define cow_treenav_gtk_h
/* cow_treenav_gtk.h -- Tree viewer */
#include <gtk/gtk.h>
#ifndef cow_treenav_h
# include "cow_treenav.h"
#endif
//! The navigation area of the attribute editor.
class TreeNavGtk : public TreeNav {
public:
TreeNavGtk(
void *xn_parent_ctx,
GtkWidget *xn_parent_wid,
pwr_tAttrRef *xn_itemlist,
int xn_item_cnt,
unsigned int xn_options,
pwr_tStatus (*xn_get_object_info)(void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*xn_get_node_info)(void *, char *, char *, int),
GtkWidget **w,
pwr_tStatus *status);
~TreeNavGtk();
GtkWidget *parent_wid;
GtkWidget *brow_widget;
GtkWidget *form_widget;
GtkWidget *toplevel;
void set_inputfocus();
};
#endif
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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.
**/
/* xtt_tbl.cpp -- Display object attributes */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "co_cdh.h"
#include "co_time.h"
#include "cow_xhelp.h"
#include "co_dcli.h"
#include "cow_wow.h"
#include "co_cnf.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "glow.h"
#include "glow_growctx.h"
#include "glow_growapi.h"
#include "flow_msg.h"
#include "glow_curvectx.h"
#include "cow_tree.h"
#include "cow_treenav.h"
CowTree::~CowTree()
{
}
CowTree::CowTree( void *xn_parent_ctx, pwr_tAttrRef *xn_itemlist, int xn_item_cnt, unsigned int xn_options,
pwr_tStatus (*xn_get_object_info_cb)( void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*xn_get_node_info_cb)( void *, char *, char *, int),
pwr_tStatus (*xn_action_cb)( void *, pwr_tAttrRef *)) :
parent_ctx(xn_parent_ctx), close_cb(0), wow(0)
{
get_object_info_cb = xn_get_object_info_cb;
get_node_info_cb = xn_get_node_info_cb;
action_cb = xn_action_cb;
}
void CowTree::message( void *cowtree, char severity, const char *message)
{
((CowTree *)cowtree)->message( severity, message);
}
void CowTree::activate_print()
{
pwr_tFileName filename;
pwr_tCmd cmd;
dcli_translate_filename( filename, "$pwrp_tmp/cow_tree.ps");
treenav->print( filename);
sprintf( cmd, "$pwr_exe/rt_print.sh %s", filename);
system(cmd);
}
void CowTree::activate_zoom_in()
{
double zoom_factor;
treenav->get_zoom( &zoom_factor);
if ( zoom_factor > 40)
return;
treenav->zoom( 1.18);
}
void CowTree::activate_zoom_out()
{
double zoom_factor;
treenav->get_zoom( &zoom_factor);
if ( zoom_factor < 15)
return;
treenav->zoom( 1.0 / 1.18);
}
void CowTree::activate_zoom_reset()
{
treenav->unzoom();
}
void CowTree::activate_help()
{
CoXHelp::dhelp("overview", "", navh_eHelpFile_Base, NULL, 0);
}
int CowTree::activate_button_ok()
{
TrItemBase *item;
pwr_tAttrRef aref;
pwr_tStatus sts;
if ( !treenav->get_select( &item)) {
message( 'E', "Select an object");
return 0;
}
switch ( item->type) {
case treenav_eItemType_Object:
case treenav_eItemType_TreeObject: {
TreeNav_object *hi = &((TrItemObject *)item)->item;
aref = hi->aref;
break;
}
default:
message( 'E', "Select an object");
return 0;
}
if ( action_cb)
sts = (action_cb)( parent_ctx, &aref);
return sts;
}
int CowTree::get_select_cb( void *ctx, pwr_tAttrRef *aref)
{
CowTree *cowtree = (CowTree *) ctx;
TrItemBase *item;
if ( !cowtree->treenav->get_select( &item)) {
cowtree->message( 'E', "Select an storage item");
return 0;
}
switch ( item->type) {
case treenav_eItemType_Object:
case treenav_eItemType_TreeObject: {
TreeNav_object *hi = &((TrItemObject *)item)->item;
*aref = hi->aref;
break;
}
default:
return 0;
}
return 1;
}
pwr_tStatus CowTree::get_object_info(void *ctx, pwr_tAttrRef *aref, char *name, int nsize, char *cname,
char *descr, int dsize)
{
CowTree *cowtree = (CowTree *)ctx;
return (cowtree->get_object_info_cb)( cowtree->parent_ctx, aref, name, nsize, cname, descr, dsize);
}
pwr_tStatus CowTree::get_node_info(void *ctx, char *name, char *descr, int dsize)
{
CowTree *cowtree = (CowTree *)ctx;
return (cowtree->get_node_info_cb)( cowtree->parent_ctx, name, descr, dsize);
}
pwr_tStatus CowTree::action(void *ctx, pwr_tAttrRef *aref)
{
CowTree *cowtree = (CowTree *)ctx;
return (cowtree->action_cb)( cowtree->parent_ctx, aref);
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 cow_tree_h
#define cow_tree_h
#ifndef pwr_privilege_h
#include "pwr_privilege.h"
#endif
#include "glow.h"
/* cow_tree.h -- Tree viewer */
typedef enum {
tree_mOptions_LayoutList = 1 << 0,
tree_mOptions_LayoutTree = 1 << 1,
tree_mOptions_AlphaOrder = 1 << 2
} tree_mOptions;
class TreeNav;
class CoWow;
class CowTree {
public:
CowTree( void *xn_parent_ctx, pwr_tAttrRef *xn_itemlist, int xn_item_cnt, unsigned int xn_options,
pwr_tStatus (*get_object_info)( void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*get_node_info)( void *, char *, char *, int),
pwr_tStatus (*action)( void *, pwr_tAttrRef *));
void *parent_ctx;
char name[80];
TreeNav *treenav;
void (*close_cb)( void *);
void (*object_info_cb)( void *, pwr_tAttrRef, char *, char *);
pwr_tStatus (*get_object_info_cb)( void *, pwr_tAttrRef *, char *, int, char *, char *, int);
pwr_tStatus (*get_node_info_cb)( void *, char *, char *, int);
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *);
CoWow *wow;
void activate_print();
void activate_zoom_in();
void activate_zoom_out();
void activate_zoom_reset();
void activate_help();
int activate_button_ok();
virtual void message( char sev, const char *text) {}
virtual void pop() {}
static void message( void *attr, char severity, const char *message);
static int cowtree_get_select_cb( void *ctx, pwr_tOid *oid, char *aname, char *oname);
static void cowtree_help_cb( void *ctx, const char *key);
static int get_select_cb( void *ctx, pwr_tAttrRef *aref);
static pwr_tStatus get_object_info(void *ctx, pwr_tAttrRef *aref, char *name, int nsize, char *cname,
char *descr, int dsize);
static pwr_tStatus get_node_info(void *ctx, char *name, char *descr, int dsize);
static pwr_tStatus action(void *ctx, pwr_tAttrRef *aref);
virtual ~CowTree();
};
#endif
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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.
**/
/* cow_treenav.cpp -- Tree viewer */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "pwr.h"
#include "pwr_baseclasses.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_msg.h"
#include "cow_treenav.h"
#include "cow_tree.h"
#include "rt_gdh.h"
#include "xnav_bitmap_leaf8.h"
#include "xnav_bitmap_leaf10.h"
#include "xnav_bitmap_leaf12.h"
#include "xnav_bitmap_leaf14.h"
#include "xnav_bitmap_leaf16.h"
#include "xnav_bitmap_leaf18.h"
#include "xnav_bitmap_leaf20.h"
#include "xnav_bitmap_leaf24.h"
#include "xnav_bitmap_map8.h"
#include "xnav_bitmap_map10.h"
#include "xnav_bitmap_map12.h"
#include "xnav_bitmap_map14.h"
#include "xnav_bitmap_map16.h"
#include "xnav_bitmap_map18.h"
#include "xnav_bitmap_map20.h"
#include "xnav_bitmap_map24.h"
#include "xnav_bitmap_openmap8.h"
#include "xnav_bitmap_openmap10.h"
#include "xnav_bitmap_openmap12.h"
#include "xnav_bitmap_openmap14.h"
#include "xnav_bitmap_openmap16.h"
#include "xnav_bitmap_openmap18.h"
#include "xnav_bitmap_openmap20.h"
#include "xnav_bitmap_openmap24.h"
void TreeNav::message( char sev, const char *text)
{
(message_cb)( parent_ctx, sev, text);
}
void TreeNav::print( char *filename)
{
brow_Print( brow->ctx, filename);
}
//
// Free pixmaps
//
void TreeNavBrow::free_pixmaps()
{
brow_FreeAnnotPixmap( ctx, pixmap_leaf);
brow_FreeAnnotPixmap( ctx, pixmap_map);
brow_FreeAnnotPixmap( ctx, pixmap_openmap);
}
//
// Create pixmaps for leaf, closed map and open map
//
void TreeNavBrow::allocate_pixmaps()
{
flow_sPixmapData pixmap_data;
int i;
i = 0;
pixmap_data[i].width =xnav_bitmap_leaf8_width;
pixmap_data[i].height =xnav_bitmap_leaf8_height;
pixmap_data[i++].bits = xnav_bitmap_leaf8_bits;
pixmap_data[i].width =xnav_bitmap_leaf10_width;
pixmap_data[i].height =xnav_bitmap_leaf10_height;
pixmap_data[i++].bits = xnav_bitmap_leaf10_bits;
pixmap_data[i].width =xnav_bitmap_leaf12_width;
pixmap_data[i].height =xnav_bitmap_leaf12_height;
pixmap_data[i++].bits = xnav_bitmap_leaf12_bits;
pixmap_data[i].width =xnav_bitmap_leaf14_width;
pixmap_data[i].height =xnav_bitmap_leaf14_height;
pixmap_data[i++].bits = xnav_bitmap_leaf14_bits;
pixmap_data[i].width =xnav_bitmap_leaf16_width;
pixmap_data[i].height =xnav_bitmap_leaf16_height;
pixmap_data[i++].bits = xnav_bitmap_leaf16_bits;
pixmap_data[i].width =xnav_bitmap_leaf18_width;
pixmap_data[i].height =xnav_bitmap_leaf18_height;
pixmap_data[i++].bits = xnav_bitmap_leaf18_bits;
pixmap_data[i].width =xnav_bitmap_leaf20_width;
pixmap_data[i].height =xnav_bitmap_leaf20_height;
pixmap_data[i++].bits = xnav_bitmap_leaf20_bits;
pixmap_data[i].width =xnav_bitmap_leaf20_width;
pixmap_data[i].height =xnav_bitmap_leaf20_height;
pixmap_data[i++].bits = xnav_bitmap_leaf20_bits;
pixmap_data[i].width =xnav_bitmap_leaf24_width;
pixmap_data[i].height =xnav_bitmap_leaf24_height;
pixmap_data[i++].bits = xnav_bitmap_leaf24_bits;
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_leaf);
i = 0;
pixmap_data[i].width =xnav_bitmap_map8_width;
pixmap_data[i].height =xnav_bitmap_map8_height;
pixmap_data[i++].bits = xnav_bitmap_map8_bits;
pixmap_data[i].width =xnav_bitmap_map10_width;
pixmap_data[i].height =xnav_bitmap_map10_height;
pixmap_data[i++].bits = xnav_bitmap_map10_bits;
pixmap_data[i].width =xnav_bitmap_map12_width;
pixmap_data[i].height =xnav_bitmap_map12_height;
pixmap_data[i++].bits = xnav_bitmap_map12_bits;
pixmap_data[i].width =xnav_bitmap_map14_width;
pixmap_data[i].height =xnav_bitmap_map14_height;
pixmap_data[i++].bits = xnav_bitmap_map14_bits;
pixmap_data[i].width =xnav_bitmap_map16_width;
pixmap_data[i].height =xnav_bitmap_map16_height;
pixmap_data[i++].bits = xnav_bitmap_map16_bits;
pixmap_data[i].width =xnav_bitmap_map18_width;
pixmap_data[i].height =xnav_bitmap_map18_height;
pixmap_data[i++].bits = xnav_bitmap_map18_bits;
pixmap_data[i].width =xnav_bitmap_map20_width;
pixmap_data[i].height =xnav_bitmap_map20_height;
pixmap_data[i++].bits = xnav_bitmap_map20_bits;
pixmap_data[i].width =xnav_bitmap_map20_width;
pixmap_data[i].height =xnav_bitmap_map20_height;
pixmap_data[i++].bits = xnav_bitmap_map20_bits;
pixmap_data[i].width =xnav_bitmap_map24_width;
pixmap_data[i].height =xnav_bitmap_map24_height;
pixmap_data[i++].bits = xnav_bitmap_map24_bits;
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_map);
i = 0;
pixmap_data[i].width =xnav_bitmap_openmap8_width;
pixmap_data[i].height =xnav_bitmap_openmap8_height;
pixmap_data[i++].bits = xnav_bitmap_openmap8_bits;
pixmap_data[i].width =xnav_bitmap_openmap10_width;
pixmap_data[i].height =xnav_bitmap_openmap10_height;
pixmap_data[i++].bits = xnav_bitmap_openmap10_bits;
pixmap_data[i].width =xnav_bitmap_openmap12_width;
pixmap_data[i].height =xnav_bitmap_openmap12_height;
pixmap_data[i++].bits = xnav_bitmap_openmap12_bits;
pixmap_data[i].width =xnav_bitmap_openmap14_width;
pixmap_data[i].height =xnav_bitmap_openmap14_height;
pixmap_data[i++].bits = xnav_bitmap_openmap14_bits;
pixmap_data[i].width =xnav_bitmap_openmap16_width;
pixmap_data[i].height =xnav_bitmap_openmap16_height;
pixmap_data[i++].bits = xnav_bitmap_openmap16_bits;
pixmap_data[i].width =xnav_bitmap_openmap18_width;
pixmap_data[i].height =xnav_bitmap_openmap18_height;
pixmap_data[i++].bits = xnav_bitmap_openmap18_bits;
pixmap_data[i].width =xnav_bitmap_openmap20_width;
pixmap_data[i].height =xnav_bitmap_openmap20_height;
pixmap_data[i++].bits = xnav_bitmap_openmap20_bits;
pixmap_data[i].width =xnav_bitmap_openmap20_width;
pixmap_data[i].height =xnav_bitmap_openmap20_height;
pixmap_data[i++].bits = xnav_bitmap_openmap20_bits;
pixmap_data[i].width =xnav_bitmap_openmap24_width;
pixmap_data[i].height =xnav_bitmap_openmap24_height;
pixmap_data[i++].bits = xnav_bitmap_openmap24_bits;
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_openmap);
}
//
// Create the navigator widget
//
TreeNav::TreeNav(
void *xn_parent_ctx,
pwr_tAttrRef *xn_itemlist,
int xn_item_cnt,
unsigned int xn_options,
pwr_tStatus (*xn_get_object_info)(void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*xn_get_node_info)(void *, char *, char *, int),
pwr_tStatus *status) :
parent_ctx(xn_parent_ctx),
itemlist(xn_itemlist),item_cnt(xn_item_cnt),
message_cb(NULL), options(xn_options)
{
get_object_info = xn_get_object_info;
get_node_info = xn_get_node_info;
create_objectlist(xn_itemlist, xn_item_cnt, status);
*status = 1;
}
//
// Delete a nav context
//
TreeNav::~TreeNav()
{
}
TreeNavBrow::~TreeNavBrow()
{
free_pixmaps();
}
//
// Callbacks from brow
//
static int treenav_brow_cb( FlowCtx *ctx, flow_tEvent event)
{
TreeNav *treenav;
TrItemBase *item;
if ( event->event == flow_eEvent_ObjectDeleted) {
brow_GetUserData( event->object.object, (void **)&item);
delete item;
return 1;
}
brow_GetCtxUserData( (BrowCtx *)ctx, (void **) &treenav);
treenav->message( ' ', "");
switch ( event->event) {
case flow_eEvent_Key_PageDown: {
brow_Page( treenav->brow->ctx, 0.8);
break;
}
case flow_eEvent_Key_PageUp: {
brow_Page( treenav->brow->ctx, -0.8);
break;
}
case flow_eEvent_ScrollDown: {
brow_Page( treenav->brow->ctx, 0.1);
break;
}
case flow_eEvent_ScrollUp: {
brow_Page( treenav->brow->ctx, -0.1);
break;
}
case flow_eEvent_Key_Up: {
brow_tNode *node_list;
int node_count;
brow_tObject object;
int sts;
brow_GetSelectedNodes( treenav->brow->ctx, &node_list, &node_count);
if ( !node_count) {
sts = brow_GetLastVisible( treenav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
if ( !brow_IsVisible( treenav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
sts = brow_GetLastVisible( treenav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
sts = brow_GetPrevious( treenav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
if ( node_count)
free( node_list);
return 1;
}
}
}
brow_SelectClear( treenav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( treenav->brow->ctx, object);
if ( !brow_IsVisible( treenav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( treenav->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( treenav->brow->ctx, &node_list, &node_count);
if ( !node_count) {
sts = brow_GetFirstVisible( treenav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
if ( !brow_IsVisible( treenav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
sts = brow_GetFirstVisible( treenav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
sts = brow_GetNext( treenav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
if ( node_count)
free( node_list);
return 1;
}
}
}
brow_SelectClear( treenav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( treenav->brow->ctx, object);
if ( !brow_IsVisible( treenav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( treenav->brow->ctx, object, 0.75);
if ( node_count)
free( node_list);
break;
}
case flow_eEvent_SelectClear:
brow_ResetSelectInverse( treenav->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 = treenav_brow_cb( ctx, doubleclick_event);
free( (char *) doubleclick_event);
return sts;
}
if ( brow_FindSelectedObject( treenav->brow->ctx, event->object.object)) {
brow_SelectClear( treenav->brow->ctx);
}
else {
brow_SelectClear( treenav->brow->ctx);
brow_SetInverse( event->object.object, 1);
brow_SelectInsert( treenav->brow->ctx, event->object.object);
}
break;
default:
brow_SelectClear( treenav->brow->ctx);
}
break;
}
case flow_eEvent_Key_Left: {
brow_tNode *node_list;
int node_count;
brow_tObject object;
int sts;
brow_GetSelectedNodes( treenav->brow->ctx, &node_list, &node_count);
if ( !node_count)
return 1;
if ( brow_IsOpen( node_list[0]))
// Close this node
object = node_list[0];
else {
// Close parent
sts = brow_GetParent( treenav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
free( node_list);
return 1;
}
}
brow_GetUserData( object, (void **)&item);
item->close( treenav, 0, 0);
brow_SelectClear( treenav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( treenav->brow->ctx, object);
if ( !brow_IsVisible( treenav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( treenav->brow->ctx, object, 0.25);
free( node_list);
break;
}
case flow_eEvent_Key_Right: {
brow_tNode *node_list;
int node_count;
brow_GetSelectedNodes( treenav->brow->ctx, &node_list, &node_count);
if ( !node_count)
return 1;
brow_GetUserData( node_list[0], (void **)&item);
switch( item->type) {
case treenav_eItemType_TreeNode:
((TrItemNode *)item)->open_children( treenav, 0, 0);
break;
default:
;
}
}
case flow_eEvent_MB1DoubleClick:
switch ( event->object.object_type) {
case flow_eObjectType_Node:
brow_GetUserData( event->object.object, (void **)&item);
switch( item->type) {
case treenav_eItemType_TreeNode:
((TrItemNode *)item)->open_children( treenav,
event->object.x, event->object.y);
break;
default:
;
}
break;
default:
;
}
break;
default:
;
}
return 1;
}
//
// Create nodeclasses
//
void TreeNavBrow::create_nodeclasses()
{
allocate_pixmaps();
// Create common-class
brow_CreateNodeClass( ctx, "NavigatorDefault",
flow_eNodeGroup_Common, &nc_object);
brow_AddAnnotPixmap( nc_object, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
brow_AddAnnot( nc_object, 2, 0.6, 0,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_object, 12, 0.6, 1,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
1);
brow_AddAnnot( nc_object, 15, 0.6, 2,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
1);
brow_AddFrame( nc_object, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);
// Create attribute nodeclass
brow_CreateNodeClass( ctx, "NavigatorAttr",
flow_eNodeGroup_Common, &nc_node);
brow_AddAnnotPixmap( nc_node, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
brow_AddAnnot( nc_node, 2, 0.6, 0,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_node, 8, 0.6, 1,
flow_eDrawType_TextHelvetica, 2, flow_eAnnotType_OneLine,
1);
brow_AddFrame( nc_node, 0, 0, 20, 0.83, flow_eDrawType_LineGray, -1, 1);
}
void TreeNav::show_list()
{
options |= tree_mOptions_LayoutList;
options &= ~tree_mOptions_LayoutTree;
brow_DeleteAll( brow->ctx);
create_items();
}
void TreeNav::show_tree()
{
options |= tree_mOptions_LayoutTree;
options &= ~tree_mOptions_LayoutList;
brow_DeleteAll( brow->ctx);
create_items();
}
int TreeNav::create_items()
{
int i;
brow_SetNodraw( brow->ctx);
if ( options & tree_mOptions_LayoutList) {
for ( i = 0; i < (int)objectlist.size(); i++) {
new TrItemObject( this, &objectlist[i], NULL, flow_eDest_IntoLast);
}
}
else {
for ( int idx = 1; idx; idx = tree[idx].fws) {
if ( tree[idx].type == treenav_eTreeItemType_Object)
new TrItemTreeObject( this, &objectlist[tree[idx].idx], idx, NULL,
flow_eDest_IntoLast);
else
new TrItemNode( this, tree[idx].sname, tree[idx].descr, idx, NULL, flow_eDest_IntoLast);
}
}
brow_ResetNodraw( brow->ctx);
brow_Redraw( brow->ctx, 0);
return 1;
}
void TreeNavBrow::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, treenav);
brow_EnableEvent( ctx, flow_eEvent_MB1Click, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_MB1DoubleClick, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_SelectClear, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ObjectDeleted, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Up, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Down, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Right, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Left, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PF3, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Radiobutton, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PageUp, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PageDown, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ScrollUp, flow_eEventType_CallBack,
treenav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ScrollDown, flow_eEventType_CallBack,
treenav_brow_cb);
}
//
// Backcall routine called at creation of the brow widget
// Enable event, create nodeclasses and insert the root objects.
//
int TreeNav::init_brow_cb( FlowCtx *fctx, void *client_data)
{
TreeNav *treenav = (TreeNav *) client_data;
BrowCtx *ctx = (BrowCtx *)fctx;
treenav->brow = new TreeNavBrow( ctx, (void *)treenav);
treenav->brow->brow_setup();
treenav->brow->create_nodeclasses();
treenav->build_tree();
// Create the root items
treenav->create_items();
return 1;
}
int TreeNav::get_select( TrItemBase **item)
{
brow_tNode *node_list;
int node_count;
brow_GetSelectedNodes( brow->ctx, &node_list, &node_count);
if ( !node_count)
return 0;
brow_GetUserData( node_list[0], (void **)item);
return 1;
}
int TreeNav::get_item( char *name, TreeNav_object **hi)
{
for ( int i = 0; i < (int)objectlist.size(); i++) {
if ( cdh_NoCaseStrcmp( objectlist[i].name, name) == 0) {
*hi = &objectlist[i];
return 1;
}
}
return 0;
}
//
// Get zoom
//
void TreeNav::get_zoom( double *zoom_factor)
{
brow_GetZoom( brow->ctx, zoom_factor);
}
//
// Zoom
//
void TreeNav::zoom( double zoom_factor)
{
brow_Zoom( brow->ctx, zoom_factor);
}
//
// Return to base zoom factor
//
void TreeNav::unzoom()
{
brow_UnZoom( brow->ctx);
}
TrItemObject::TrItemObject( TreeNav *treenav, TreeNav_object *xitem,
brow_tNode dest, flow_eDest dest_code) :
TrItemBase( treenav_eItemType_Object), item(*xitem)
{
type = treenav_eItemType_Object;
pwr_tAName aname;
brow_CreateNode( treenav->brow->ctx, "LocalItem", treenav->brow->nc_object,
dest, dest_code, (void *) this, 1, &node);
brow_SetAnnotPixmap( node, 0, treenav->brow->pixmap_leaf);
strcpy( aname, item.name);
brow_SetAnnotation( node, 0, aname, strlen(aname));
brow_SetAnnotation( node, 1, item.cname, strlen(item.cname));
brow_SetAnnotation( node, 2, item.description, strlen(item.description));
}
int TrItemObject::close( TreeNav *treenav, double x, double y)
{
double node_x, node_y;
brow_GetNodePosition( node, &node_x, &node_y);
if ( brow_IsOpen( node)) {
// Close
brow_SetNodraw( treenav->brow->ctx);
brow_CloseNode( treenav->brow->ctx, node);
brow_SetAnnotPixmap( node, 0, treenav->brow->pixmap_leaf);
brow_ResetOpen( node, treenav_mOpen_All);
brow_ResetNodraw( treenav->brow->ctx);
brow_Redraw( treenav->brow->ctx, node_y);
}
return 1;
}
TrItemTreeObject::TrItemTreeObject( TreeNav *treenav, TreeNav_object *xitem, int index,
brow_tNode dest, flow_eDest dest_code) :
TrItemObject(treenav, xitem, dest, dest_code), idx(index)
{
pwr_tAName aname;
char *s;
type = treenav_eItemType_TreeObject;
if ((s = strrchr( item.name, '.')) || (s = strrchr( item.name, '-')))
strcpy( aname, s+1);
else
strcpy( aname, item.name);
brow_SetAnnotation( node, 0, aname, strlen(aname));
}
TrItemNode::TrItemNode( TreeNav *treenav, char *name, char *descr, int index,
brow_tNode dest, flow_eDest dest_code) :
TrItemBase(treenav_eItemType_TreeNode), idx(index)
{
brow_CreateNode( treenav->brow->ctx, "TreeNode", treenav->brow->nc_node,
dest, dest_code, (void *) this, 1, &node);
if ( treenav->tree[idx].fch)
brow_SetAnnotPixmap( node, 0, treenav->brow->pixmap_map);
else
brow_SetAnnotPixmap( node, 0, treenav->brow->pixmap_leaf);
brow_SetAnnotation( node, 0, name, strlen(name));
if ( descr)
brow_SetAnnotation( node, 1, descr, strlen(descr));
}
int TrItemNode::open_children( TreeNav *treenav, double x, double y)
{
double node_x, node_y;
brow_GetNodePosition( node, &node_x, &node_y);
if ( brow_IsOpen( node) & treenav_mOpen_Children) {
// Attributes is open, close
brow_SetNodraw( treenav->brow->ctx);
brow_CloseNode( treenav->brow->ctx, node);
brow_ResetOpen( node, treenav_mOpen_Children);
brow_SetAnnotPixmap( node, 0, treenav->brow->pixmap_map);
// brow_RemoveAnnotPixmap( node, 1);
brow_ResetNodraw( treenav->brow->ctx);
brow_Redraw( treenav->brow->ctx, node_y);
}
else {
brow_SetNodraw( treenav->brow->ctx);
for ( int i = treenav->tree[idx].fch; i; i = treenav->tree[i].fws) {
if ( treenav->tree[i].deleted)
continue;
if ( treenav->tree[i].type == treenav_eTreeItemType_Object)
new TrItemTreeObject( treenav, &treenav->objectlist[treenav->tree[i].idx], i, node,
flow_eDest_IntoLast);
else
new TrItemNode( treenav, treenav->tree[i].sname, treenav->tree[i].descr, i, node, flow_eDest_IntoLast);
}
brow_SetOpen( node, treenav_mOpen_Children);
brow_SetAnnotPixmap( node, 0, treenav->brow->pixmap_openmap);
brow_ResetNodraw( treenav->brow->ctx);
brow_Redraw( treenav->brow->ctx, node_y);
}
return 1;
}
int TrItemNode::close( TreeNav *treenav, double x, double y)
{
double node_x, node_y;
if ( brow_IsOpen( node) & treenav_mOpen_Children) {
// Children is open, close
brow_GetNodePosition( node, &node_x, &node_y);
brow_SetNodraw( treenav->brow->ctx);
brow_CloseNode( treenav->brow->ctx, node);
brow_ResetOpen( node, treenav_mOpen_All);
brow_SetAnnotPixmap( node, 0, treenav->brow->pixmap_map);
brow_ResetNodraw( treenav->brow->ctx);
brow_Redraw( treenav->brow->ctx, node_y);
}
return 1;
}
void TreeNav::build_tree()
{
pwr_tAName aname;
for ( int i = 0; i < (int)objectlist.size(); i++) {
TreeNode n;
strcpy( aname, objectlist[i].name);
tree_add( aname, i, treenav_eTreeItemType_Object);
}
}
void TreeNav::tree_add( char *name, int list_index, treenav_eTreeItemType type)
{
pwr_tObjName name_array[24];
int seg;
seg = dcli_parse( name, "-.", "",
(char *) name_array, sizeof( name_array)/sizeof( name_array[0]),
sizeof( name_array[0]), 0);
if ( tree.size() == 0) {
// First item
TreeNode n0;
strcpy( n0.sname, "nonode");
tree.push_back(n0);
for ( int j = 0; j < seg; j++) {
TreeNode n;
n.fth = j;
tree[j].fch = j + 1;
strcpy( n.sname, name_array[j]);
get_descr( name, seg, j, n.descr);
if ( j == seg -1) {
n.idx = list_index;
n.type = type;
}
tree.push_back(n);
}
}
else {
int idx = 1;
int last = idx;
for ( int j = 0; j < seg; j++) {
int found = 0;
while ( idx) {
last = idx;
if ( strcmp( tree[idx].sname, name_array[j]) == 0) {
found = 1;
break;
}
idx = tree[idx].fws;
}
if ( !found) {
TreeNode n;
strcpy( n.sname, name_array[j]);
get_descr( name, seg, j, n.descr);
n.fth = tree[last].fth;
n.bws = last;
tree[last].fws = tree.size();
if ( j == seg - 1) {
n.idx = list_index;
n.type = type;
}
tree.push_back(n);
for ( int k = j + 1; k < seg; k++) {
TreeNode n;
n.fth = tree.size() - 1;
if ( tree[n.fth].fch == 0)
tree[n.fth].fch = tree.size();
strcpy( n.sname, name_array[k]);
get_descr( name, seg, k, n.descr);
if ( k == seg - 1) {
n.idx = list_index;
n.type = type;
}
tree.push_back(n);
}
break;
}
if ( tree[idx].fch == 0) {
TreeNode n;
strcpy( n.sname, name_array[j]);
n.fth = tree[last].fth;
n.bws = last;
tree[last].fws = tree.size();
if ( j == seg - 1) {
n.idx = list_index;
n.type = type;
}
tree.push_back(n);
for ( int k = j + 1; k < seg; k++) {
TreeNode n;
n.fth = tree.size() - 1;
if ( tree[n.fth].fch == 0)
tree[n.fth].fch = tree.size();
strcpy( n.sname, name_array[k]);
get_descr( name, seg, k, n.descr);
if ( k == seg - 1) {
n.idx = list_index;
n.type = type;
}
tree.push_back(n);
}
break;
}
idx = tree[idx].fch;
last = idx;
}
}
}
void TreeNav::create_objectlist( pwr_tAttrRef *xn_itemlist,
int xn_item_cnt,
pwr_tStatus *status)
{
for ( int i = 0; i < xn_item_cnt; i++) {
TreeNav_object object;
pwr_tStatus sts;
object.aref = xn_itemlist[i];
sts = (get_object_info)(parent_ctx, &object.aref, object.name, sizeof(object.name), object.cname,
object.description, sizeof(object.description));
if (EVEN(sts)) continue;
objectlist.push_back(object);
}
// Sort
if ( options & tree_mOptions_AlphaOrder) {
TreeNav_object tmp;
for ( unsigned int i = objectlist.size() - 1; i > 0; i--) {
for ( unsigned int j = 0; j < i; j++) {
if ( strcmp(objectlist[j].name, objectlist[j+1].name) > 0) {
tmp = objectlist[j+1];
objectlist[j+1] = objectlist[j];
objectlist[j] = tmp;
}
}
}
}
}
int TreeNav::get_descr( char *name, int seg, int idx, char *descr)
{
pwr_tAName n;
char *s, *s1;
pwr_tStatus sts;
pwr_tString80 description;
strncpy( n, name, sizeof(n));
s = n;
for ( int m = 0; m <= idx; m++) {
if ( (s1 = strchr( s, '-')) || (s1 = strchr( s, '.'))) {
if ( m == idx)
*s1 = 0;
else
s1++;
s = s1;
}
else
break;
}
sts = (get_node_info)( parent_ctx, n, description, sizeof(description));
strcpy( descr, description);
return sts;
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 cow_treenav_h
#define cow_treenav_h
/* cow_treenav.h -- Table Viewer */
#include <fstream>
#include <vector>
#ifndef pwr_h
# include "pwr.h"
#endif
#ifndef flow_h
#include "flow.h"
#endif
#ifndef flow_browctx_h
#include "flow_browapi.h"
#endif
#ifndef rt_qcom_h
#include "rt_qcom.h"
#endif
class TrItemBase;
typedef enum {
treenav_eItemType_Object,
treenav_eItemType_TreeObject,
treenav_eItemType_TreeNode,
} treenav_eItemType;
typedef enum {
treenav_mOpen_All = ~0,
treenav_mOpen_Children = 1 << 0
} treenav_mOpen;
class TreeNav_object {
public:
pwr_tAttrRef aref;
pwr_tAName name;
pwr_tObjName cname;
pwr_tString80 description;
TreeNav_object() {
memset( &aref, 0, sizeof(aref)); strcpy(name, ""); strcpy(cname, ""); strcpy(description, "");
}
TreeNav_object( const TreeNav_object& x) : aref(x.aref) {
strcpy( name, x.name);
strcpy( cname, x.cname);
strcpy( description, x.description);
}
};
typedef enum {
treenav_eTreeItemType_No,
treenav_eTreeItemType_Object,
treenav_eTreeItemType_ObjectAttr
} treenav_eTreeItemType;
class TreeNode {
public:
TreeNode() : fth(0), fch(0), fws(0), bws(0), type(treenav_eTreeItemType_No), idx(0), deleted(0)
{ strcpy( sname, ""); strcpy( descr, "");}
int fth;
int fch;
int fws;
int bws;
char sname[80];
pwr_tString80 descr;
treenav_eTreeItemType type;
int idx;
int deleted;
};
//! Class for handling of brow.
class TreeNavBrow {
public:
TreeNavBrow( BrowCtx *brow_ctx, void *xn) : ctx(brow_ctx), treenav(xn) {};
~TreeNavBrow();
BrowCtx *ctx;
void *treenav;
brow_tNodeClass nc_object;
brow_tNodeClass nc_node;
flow_sAnnotPixmap *pixmap_leaf;
flow_sAnnotPixmap *pixmap_map;
flow_sAnnotPixmap *pixmap_openmap;
void free_pixmaps();
void allocate_pixmaps();
void create_nodeclasses();
void brow_setup();
};
//! The navigation area of the attribute editor.
class TreeNav {
public:
TreeNav( void *xn_parent_ctx,
pwr_tAttrRef *xn_itemlist,
int xn_item_cnt,
unsigned int xn_options,
pwr_tStatus (*xn_get_object_info)(void *, pwr_tAttrRef *, char *, int, char *, char *, int),
pwr_tStatus (*xn_get_node_info)(void *, char *, char *, int),
pwr_tStatus *status);
virtual ~TreeNav();
void *parent_ctx;
TreeNavBrow *brow;
pwr_tAttrRef *itemlist;
vector<TreeNav_object> objectlist;
int item_cnt;
void (*message_cb)( void *, char, const char *);
vector<TreeNode> tree;
unsigned int options;
pwr_tStatus (*get_object_info)(void *, pwr_tAttrRef *, char *, int, char *, char *, int);
pwr_tStatus (*get_node_info)(void *, char *, char *, int);
void print( char *filename);
int create_items();
void build_tree();
void tree_add( char *name, int list_index, treenav_eTreeItemType type);
int get_select( TrItemBase **item);
int get_item( char *oname, TreeNav_object **hi);
void get_zoom( double *zoom_factor);
void zoom( double zoom_factor);
void unzoom();
void show_tree();
void show_list();
void delete_item( TreeNav_object *hi);
void create_objectlist( pwr_tAttrRef *xn_itemlist,
int xn_item_cnt,
pwr_tStatus *status);
void add_item_command( char *name, char *command);
int get_descr( char *name, int seg, int idx, char *descr);
virtual void message( char sev, const char *text);
virtual void set_inputfocus() {}
static int init_brow_cb( FlowCtx *fctx, void *client_data);
};
class TrItemBase {
public:
TrItemBase( treenav_eItemType t) : type(t) {}
virtual ~TrItemBase() {}
treenav_eItemType type;
virtual int close( TreeNav *treenav, double x, double y) {return 1;}
};
//! Item for an object in list layout.
class TrItemObject : public TrItemBase {
public:
TrItemObject( TreeNav *treenav, TreeNav_object *item, brow_tNode dest, flow_eDest dest_code);
virtual ~TrItemObject() {}
TreeNav_object item;
brow_tNode node;
int close( TreeNav *treenav, double x, double y);
};
//! Item for an object in tree layout.
class TrItemTreeObject : public TrItemObject {
public:
TrItemTreeObject( TreeNav *treenav, TreeNav_object *item, int index, brow_tNode dest, flow_eDest dest_code);
virtual ~TrItemTreeObject() {}
int idx;
};
//! Item for a tree node.
class TrItemNode : public TrItemBase {
public:
TrItemNode( TreeNav *treenav, char *name, char *descr, int index, brow_tNode dest, flow_eDest dest_code);
virtual ~TrItemNode() {}
brow_tNode node;
int idx;
int open_children( TreeNav *treenav, double x, double y);
int close( TreeNav *treenav, double x, double y);
};
#endif
......@@ -133,11 +133,13 @@ XttFastGtk::XttFastGtk( void *parent_ctx,
XttFastGtk::~XttFastGtk()
{
if ( timerid)
timerid->remove();
for ( int i = 0; i < fast_cnt; i++) {
gdh_UnrefObjectInfo( new_subid);
}
if ( curve)
delete curve;
if ( gcd)
delete gcd;
......
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 "pwr.h"
#include "rt_gdh.h"
#include "xtt_otree_gtk.h"
#include "cow_tree_gtk.h"
/* xtt_otree_gtk.cpp -- Object tree viewer */
XttOTreeGtk::XttOTreeGtk( GtkWidget *parent_wid, void *xn_parent_ctx, const char *title, pwr_tAttrRef *xn_itemlist,
int xn_item_cnt, unsigned int xn_options,
pwr_tStatus (*xn_action_cb)( void *, pwr_tAttrRef *)) :
XttOTree( xn_parent_ctx, xn_itemlist, xn_item_cnt, xn_options, xn_action_cb)
{
cowtree = new CowTreeGtk( parent_wid, this, title, xn_itemlist, xn_item_cnt, xn_options, &get_object_info,
&get_node_info, &action);
cowtree->close_cb = close;
}
XttOTreeGtk::~XttOTreeGtk()
{
delete cowtree;
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 xtt_otree_gtk_h
#define xtt_otree_gtk_h
#include <gtk/gtk.h>
#ifndef xtt_otree_h
#include "xtt_otree.h"
#endif
/* xtt_otree.h -- Object tree viewer */
class XttOTreeGtk : public XttOTree {
public:
XttOTreeGtk( GtkWidget *parent_wid, void *xn_parent_ctx, const char *title, pwr_tAttrRef *xn_itemlist,
int xn_item_cnt, unsigned int xn_options,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *));
virtual ~XttOTreeGtk();
};
#endif
......@@ -146,6 +146,8 @@ XttSevHistGtk::XttSevHistGtk( void *parent_ctx,
XttSevHistGtk::~XttSevHistGtk()
{
if ( otree)
delete otree;
if ( timerid)
timerid->remove();
if ( curve)
......@@ -156,6 +158,11 @@ XttSevHistGtk::~XttSevHistGtk()
delete wow;
}
XttOTree *XttSevHistGtk::tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int layout,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *))
{
return new XttOTreeGtk( parent_widget, this, title, itemlist, itemcnt, layout, action_cb);
}
......
......@@ -42,6 +42,7 @@
#ifndef xtt_sevhist_h
# include "xtt_sevhist.h"
#endif
#include "xtt_otree_gtk.h"
class XttSevHistGtk : public XttSevHist {
public:
......@@ -71,6 +72,9 @@ class XttSevHistGtk : public XttSevHist {
void *basewidget,
int *sts);
~XttSevHistGtk();
XttOTree *tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int layout,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *));
};
#endif
......
......@@ -59,6 +59,7 @@
#include "xtt_xnav.h"
#include "xtt_trend_gtk.h"
#include "ge_curve_gtk.h"
#include "xtt_otree_gtk.h"
XttTrendGtk::XttTrendGtk( void *parent_ctx,
GtkWidget *parent_wid,
......@@ -101,6 +102,7 @@ XttTrendGtk::XttTrendGtk( void *parent_ctx,
XttTrendGtk::~XttTrendGtk()
{
if ( timerid)
timerid->remove();
for ( int i = 0; i < trend_cnt; i++) {
......@@ -109,9 +111,17 @@ XttTrendGtk::~XttTrendGtk()
delete curve;
if ( gcd)
delete gcd;
if ( otree)
delete otree;
delete wow;
}
XttOTree *XttTrendGtk::tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int layout,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *))
{
return new XttOTreeGtk( parent_widget, this, title, itemlist, itemcnt, layout, action_cb);
}
......
......@@ -59,6 +59,8 @@ class XttTrendGtk : public XttTrend {
int x_color_theme,
void *basewidget,
int *sts);
XttOTree *tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int layout,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *));
~XttTrendGtk();
};
......
......@@ -91,6 +91,7 @@ typedef void *Widget;
#include "ge_curve_gtk.h"
#include "xtt_fileview_gtk.h"
#include "xtt_keyboard_gtk.h"
#include "xtt_otree_gtk.h"
#define max(Dragon,Eagle) ((Dragon) > (Eagle) ? (Dragon) : (Eagle))
#define min(Dragon,Eagle) ((Dragon) < (Eagle) ? (Dragon) : (Eagle))
......@@ -328,6 +329,12 @@ CLog *XNavGtk::clog_new( const char *name, pwr_tStatus *sts)
return new CLogGtk( this, parent_wid, name, sts);
}
XttOTree *XNavGtk::tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int options,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *))
{
return new XttOTreeGtk( parent_wid, this, title, itemlist, itemcnt, options, action_cb);
}
XttGe *XNavGtk::xnav_ge_new( const char *name, const char *filename, int scrollbar, int menu,
int navigator, int width, int height, int x, int y,
double scan_time, const char *object_name,
......
......@@ -121,6 +121,8 @@ class XNavGtk : public XNav {
pwr_tStatus *status);
XttKeyboard *keyboard_new( const char *name, keyboard_eKeymap keymap, keyboard_eType type,
int color_theme, pwr_tStatus *status);
XttOTree *tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int options,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *));
void bell( int time);
void get_popup_menu( pwr_sAttrRef attrref,
xmenu_eItemType item_type,
......
......@@ -69,7 +69,7 @@ XttFast::XttFast( void *parent_ctx,
pwr_sAttrRef *fast_arp,
int xn_color_theme,
int *sts) :
xnav(parent_ctx), fast_cnt(0), timerid(0), close_cb(0), help_cb(0), first_scan(1),
xnav(parent_ctx), fast_cnt(0), gcd(0), curve(0), timerid(0), close_cb(0), help_cb(0), first_scan(1),
axis_configured(false), color_theme(xn_color_theme)
{
pwr_sAttrRef aref = pwr_cNAttrRef;
......
......@@ -181,7 +181,7 @@ void Op::activate_blocklist()
void Op::activate_trend()
{
char cmd[200] = "show objectlist/class=dstrend,dstrendcurve/title=\"Trend List\"/sort";
char cmd[200] = "show objecttree/class=dstrend,dstrendcurve/title=\"Trend List\"/alpha/global";
if ( command_cb)
command_cb( parent_ctx, cmd);
......@@ -189,7 +189,7 @@ void Op::activate_trend()
void Op::activate_fast()
{
char cmd[200] = "show objectlist/class=dsfastcurve/title=\"Fast Curve List\"";
char cmd[200] = "show objecttree/class=dsfastcurve/title=\"Fast Curve List\"/alpha/global";
if ( command_cb)
command_cb( parent_ctx, cmd);
......@@ -197,14 +197,14 @@ void Op::activate_fast()
void Op::activate_history()
{
char cmd[200] = "show objectlist/class=sevhist,sevhistobject/title=\"Process History List\"/sort";
char cmd[200] = "show objecttree/class=sevhist,sevhistobject/title=\"Process History List\"/alpha/global";
if ( command_cb)
command_cb( parent_ctx, cmd);
}
void Op::activate_graph()
{
char cmd[200] = "show objectlist/class=xttgraph/title=\"Process Graphic List\"";
char cmd[200] = "show objecttree/class=xttgraph/title=\"Process Graphic List\"";
if ( command_cb)
command_cb( parent_ctx, cmd);
......
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 "pwr.h"
#include "rt_gdh.h"
#include "co_cdh.h"
#include "xtt_otree.h"
/* xtt_otree.h -- Object tree viewer */
XttOTree::XttOTree( void *xn_parent_ctx, pwr_tAttrRef *xn_itemlist, int xn_item_cnt, unsigned int xn_options,
pwr_tStatus (*xn_action_cb)( void *, pwr_tAttrRef *)) :
parent_ctx(xn_parent_ctx), close_cb(0)
{
action_cb = xn_action_cb;
// cowtree = new CowTree( this, xn_itemlist, xn_item_cnt, xn_layout, get_object_info, get_node_info);
}
void XttOTree::pop()
{
cowtree->pop();
}
pwr_tStatus XttOTree::get_object_info( void *ctx, pwr_tAttrRef *aref, char *name, int nsize, char *cname,
char *descr, int dsize)
{
pwr_tStatus sts;
pwr_tAttrRef daref;
pwr_tCid cid;
sts = gdh_AttrrefToName( aref, name, nsize, cdh_mNName);
if ( EVEN(sts)) return sts;
sts = gdh_GetAttrRefTid( aref, &cid);
if ( EVEN(sts)) return sts;
sts = gdh_ObjidToName( cdh_ClassIdToObjid(cid), cname, sizeof(pwr_tObjName), cdh_mName_object);
if ( EVEN(sts)) return sts;
sts = gdh_ArefANameToAref( aref, "Description", &daref);
if ( ODD(sts)) {
sts = gdh_GetObjectInfoAttrref( &daref, descr, dsize);
}
if ( EVEN(sts))
strcpy( descr, "");
return 1;
}
pwr_tStatus XttOTree::get_node_info( void *ctx, char *name, char *descr, int dsize)
{
pwr_tStatus sts;
pwr_tAName dname;
strncpy( dname, name, sizeof(dname));
strncat( dname, ".Description", sizeof(dname));
sts = gdh_GetObjectInfo( dname, descr, dsize);
if ( EVEN(sts))
strcpy( descr, "");
return sts;
}
pwr_tStatus XttOTree::action( void *ctx, pwr_tAttrRef *aref)
{
XttOTree *otree = (XttOTree *)ctx;
if ( otree->action_cb)
return (otree->action_cb)( otree->parent_ctx, aref);
return 0;
}
void XttOTree::close( void *ctx)
{
XttOTree *otree = (XttOTree *)ctx;
if ( otree->close_cb)
(otree->close_cb)( otree->parent_ctx);
else
delete otree;
}
XttOTree::~XttOTree() {
}
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2016 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 xtt_otree_h
#define xtt_otree_h
#ifndef cow_tree_h
#include "cow_tree.h"
#endif
/* xtt_otree.h -- Object tree viewer */
class XttOTree {
protected:
void *parent_ctx;
CowTree *cowtree;
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *);
public:
XttOTree( void *xn_parent_ctx, pwr_tAttrRef *xn_itemlist, int xn_item_cnt, unsigned int xn_options,
pwr_tStatus (*xn_action_cb)( void *, pwr_tAttrRef *));
void pop();
void (*close_cb)( void *);
static pwr_tStatus get_object_info( void *ctx, pwr_tAttrRef *aref, char *name, int nsize, char *cname,
char *descr, int dsize);
static pwr_tStatus get_node_info( void *ctx, char *name, char *descr, int dsize);
static pwr_tStatus action( void *ctx, pwr_tAttrRef *aref);
static void close( void *ctx);
virtual ~XttOTree();
};
#endif
......@@ -74,7 +74,7 @@ XttSevHist::XttSevHist( void *parent_ctx,
int *sts) :
xnav(parent_ctx), gcd(0), curve(0), rows(0), vsize(0), timerid(0), close_cb(0), help_cb(0),
get_select_cb(0), first_scan(1), scctx(xn_scctx), wow(0), time_low_old(0), time_high_old(0),
initial_period(time_ePeriod_), color_theme(xn_color_theme)
initial_period(time_ePeriod_), color_theme(xn_color_theme), otree(0)
{
pwr_tTime from, to;
......@@ -888,6 +888,35 @@ void XttSevHist::sevhist_next_period_cb( void *ctx)
void XttSevHist::sevhist_add_cb( void *ctx)
{
XttSevHist *sevhist = (XttSevHist *) ctx;
if ( !sevhist->get_select_cb) {
if ( sevhist->otree)
sevhist->otree->pop();
else {
pwr_tAttrRef *list;
int listcnt;
pwr_tCid cid[2] = {pwr_cClass_SevHist, pwr_cClass_SevHistObject};
int options = 0;
pwr_tStatus sts;
sts = gdh_GetGlobalClassList( 2, cid, 1, &list, &listcnt);
if ( EVEN(sts)) return;
if ( !listcnt)
return;
if ( listcnt > 20)
options |= tree_mOptions_LayoutTree;
else
options |= tree_mOptions_LayoutList;
options |= tree_mOptions_AlphaOrder;
sevhist->otree = sevhist->tree_new( "Add attribute", list, listcnt, options, sevhist_otree_action_cb);
sevhist->otree->close_cb = sevhist_otree_close_cb;
free( (char *)list);
}
}
else {
pwr_tOid oid;
pwr_tOName aname, oname;
int sts;
......@@ -899,11 +928,56 @@ void XttSevHist::sevhist_add_cb( void *ctx)
if ( EVEN(sts)) return;
sevhist->curve_add( oid, aname, oname, false);
}
}
pwr_tStatus XttSevHist::sevhist_otree_action_cb( void *ctx, pwr_tAttrRef *aref)
{
XttSevHist *sevhist = (XttSevHist *)ctx;
pwr_tStatus sts;
pwr_tAttrRef aaref;
pwr_tAName oname;
pwr_tAName aname;
char *s;
pwr_tCid cid;
sts = gdh_GetAttrRefTid( aref, &cid);
if ( EVEN(sts)) return sts;
sts = gdh_ArefANameToAref( aref, "Attribute", &aaref);
if ( EVEN(sts)) return sts;
sts = gdh_GetObjectInfoAttrref( &aaref, &aaref, sizeof(pwr_tAttrRef));
if ( EVEN(sts)) return sts;
sts = gdh_AttrrefToName( &aaref, oname, sizeof(oname), cdh_mNName);
if ( EVEN(sts)) return sts;
s = strrchr( oname, '.');
if ( s) {
*s = 0;
strncpy( aname, s+1, sizeof(aname));
}
sevhist->curve_add( aaref.Objid, aname, oname, cid == pwr_cClass_SevHistObject);
if ( EVEN(sts))
printf( "SevHist add failure\n");
return sts;
}
void XttSevHist::sevhist_otree_close_cb( void *ctx)
{
XttSevHist *sevhist = (XttSevHist *)ctx;
if ( sevhist->otree) {
delete sevhist->otree;
sevhist->otree = 0;
}
}
void XttSevHist::sevhist_remove_cb( void *ctx)
{
// Do do
// To do
}
int XttSevHist::sevhist_export_cb( void *ctx, pwr_tTime *from, pwr_tTime *to, int rows, int idx,
......
......@@ -96,6 +96,7 @@ class XttSevHist {
bool sevhistobjectv[XTT_SEVHIST_MAX]; //!< Indicates that it is a SevHistObject
time_ePeriod initial_period;
int color_theme;
XttOTree *otree;
//! Constructor
XttSevHist( void *xn_parent_ctx,
......@@ -127,6 +128,11 @@ class XttSevHist {
void setup();
void update_color_theme( int ct) { curve->update_color_theme(ct);}
virtual XttOTree *tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int layout,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *)) {return 0;}
static pwr_tStatus sevhist_otree_action_cb( void *ctx, pwr_tAttrRef *aref);
static void sevhist_otree_close_cb( void *ctx);
static void sevhist_close_cb( void *ctx);
static void sevhist_increase_period_cb( void *ctx);
static void sevhist_decrease_period_cb( void *ctx);
......
......@@ -60,6 +60,7 @@
#include "xtt_xnav.h"
#include "xtt_trend.h"
#include "xtt_otree.h"
#include "ge_curve.h"
......@@ -70,8 +71,9 @@ XttTrend::XttTrend( void *parent_ctx,
unsigned int x_options,
int xn_color_theme,
int *sts) :
xnav(parent_ctx), trend_cnt(0), update_time(1000), options(x_options),
close_cb(0), help_cb(0), command_cb(0), get_select_cb(0), color_theme(xn_color_theme)
xnav(parent_ctx), trend_cnt(0), gcd(0), curve(0), update_time(1000), options(x_options), timerid(0),
close_cb(0), help_cb(0), command_cb(0), get_select_cb(0), color_theme(xn_color_theme),
otree(0)
{
pwr_sAttrRef *aref_list;
pwr_sAttrRef *aref_p;
......@@ -501,6 +503,9 @@ void XttTrend::pop()
void XttTrend::setup()
{
if ( !curve)
return;
if ( trend_tid == pwr_cClass_DsTrendCurve)
curve->setup( curve_mEnable_Snapshot | curve_mEnable_Add);
else
......@@ -528,160 +533,63 @@ void XttTrend::trend_snapshot_cb( void *ctx)
(trend->command_cb)( trend->xnav, cmd);
}
class AttrList {
public:
AttrList( char *a, char *t) : attr(a), trend(t) {}
string attr;
string trend;
};
class AttrListCtx {
public:
AttrListCtx( XttTrend *t) : trend(t) {}
XttTrend *trend;
vector<AttrList> v;
};
static void add_objectlist_cb( void *ctx, char *text, int ok_pressed)
void XttTrend::trend_madd_cb( void *ctx)
{
printf( "%s\n", text);
XttTrend *trend = (XttTrend *) ctx;
if ( trend->otree)
trend->otree->pop();
else {
pwr_tAttrRef *list;
int listcnt;
pwr_tCid cid[2] = {pwr_cClass_DsTrend, pwr_cClass_DsTrendCurve};
int options = 0;
pwr_tStatus sts;
pwr_tAttrRef trend_aref, attr_aref;
AttrListCtx *vctx = (AttrListCtx *)ctx;
unsigned int i;
int found = 0;
for ( i = 0; i < vctx->v.size(); i++) {
if ( strcmp( vctx->v[i].attr.c_str(), text) == 0) {
found = 1;
break;
}
}
if ( !found)
return;
sts = gdh_NameToAttrref( pwr_cNOid, vctx->v[i].attr.c_str(), &attr_aref);
sts = gdh_GetGlobalClassList( 2, cid, 1, &list, &listcnt);
if ( EVEN(sts)) return;
sts = gdh_NameToAttrref( pwr_cNOid, vctx->v[i].trend.c_str(), &trend_aref);
if ( EVEN(sts)) return;
if ( !listcnt)
return;
vctx->trend->curve_add( &attr_aref, &trend_aref, &sts);
if ( EVEN(sts))
printf( "Trend add failure\n");
if ( listcnt > 20)
options |= tree_mOptions_LayoutTree;
else
options |= tree_mOptions_LayoutList;
options |= tree_mOptions_AlphaOrder;
delete vctx;
}
trend->otree = trend->tree_new( "Add attribute", list, listcnt, options, trend_otree_action_cb);
trend->otree->close_cb = trend_otree_close_cb;
static void add_objectlist_cancel_cb( void *ctx)
{
delete (AttrListCtx *)ctx;
free( (char *)list);
}
}
void XttTrend::trend_madd_cb( void *ctx)
pwr_tStatus XttTrend::trend_otree_action_cb( void *ctx, pwr_tAttrRef *aref)
{
XttTrend *trend = (XttTrend *) ctx;
pwr_tAttrRef trend_aref, attr_aref;
pwr_tAName trend_name, attr_name;
XttTrend *trend = (XttTrend *)ctx;
pwr_tStatus sts;
pwr_tAName *names;
printf( "Madd\n");
AttrListCtx *vctx = new AttrListCtx(trend);
for ( sts = gdh_GetClassListAttrRef( trend->trend_tid, &trend_aref);
ODD(sts);
sts = gdh_GetNextAttrRef( trend->trend_tid, &trend_aref, &trend_aref)) {
switch ( trend->trend_tid) {
case pwr_cClass_DsTrend: {
pwr_tAttrRef dataname_aref;
sts = gdh_ArefANameToAref( &trend_aref, "DataName", &dataname_aref);
if ( EVEN(sts)) return;
sts = gdh_GetObjectInfoAttrref( &dataname_aref, &attr_aref, sizeof(attr_aref));
if ( EVEN(sts)) return;
sts = gdh_AttrrefToName( &attr_aref, attr_name, sizeof(attr_name),
cdh_mNName);
if ( EVEN(sts)) continue;
sts = gdh_AttrrefToName( &trend_aref, trend_name, sizeof(trend_name),
cdh_mNName);
if ( EVEN(sts)) continue;
AttrList l( attr_name, trend_name);
vctx->v.push_back(l);
break;
}
case pwr_cClass_DsTrendCurve: {
pwr_sClass_DsTrendCurve tp;
unsigned int asize = sizeof(tp.Attribute)/sizeof(tp.Attribute[0]);
sts = gdh_GetObjectInfoAttrref( &trend_aref, &tp, sizeof(tp));
if ( EVEN(sts)) return;
sts = gdh_AttrrefToName( &trend_aref, trend_name, sizeof(trend_name),
cdh_mNName);
if ( EVEN(sts)) continue;
for ( unsigned int j = 0; j < asize; j++) {
if ( cdh_ObjidIsNull(tp.Attribute[j].Objid))
break;
sts = gdh_AttrrefToName( &tp.Attribute[j], attr_name, sizeof(attr_name),
cdh_mNName);
if (EVEN(sts)) continue;
AttrList l( attr_name, trend_name);
vctx->v.push_back(l);
}
break;
}
default: ;
}
}
trend->curve_add( aref, 0, &sts);
if ( EVEN(sts))
printf( "Trend add failure\n");
return sts;
}
names = (pwr_tAName *)calloc( vctx->v.size() + 1, sizeof(pwr_tAName));
for ( unsigned int i = 0; i < vctx->v.size(); i++) {
strcpy( names[i], vctx->v[i].attr.c_str());
}
void XttTrend::trend_otree_close_cb( void *ctx)
{
XttTrend *trend = (XttTrend *)ctx;
// Sort
pwr_tAName tmp;
for ( unsigned int i = vctx->v.size() - 1; i > 0; i--) {
for ( unsigned int j = 0; j < i; j++) {
if ( strcmp(names[j], names[j+1]) > 0) {
strcpy( tmp, names[j+1]);
strcpy( names[j+1], names[j]);
strcpy( names[j], tmp);
}
}
if ( trend->otree) {
delete trend->otree;
trend->otree = 0;
}
trend->wow->CreateList( "Add attribute", (char *)names, sizeof(names[0]),
add_objectlist_cb, add_objectlist_cancel_cb, vctx);
free( names);
}
void XttTrend::trend_add_cb( void *ctx)
{
XttTrend *trend = (XttTrend *) ctx;
pwr_tAttrRef aref;
int is_attr;
pwr_tStatus sts;
if ( !trend->get_select_cb)
return;
sts = trend->get_select_cb( trend->xnav, &aref, &is_attr);
if ( EVEN(sts)) return;
trend->curve_add( &aref, 0, &sts);
if ( EVEN(sts))
printf( "Trend add failure\n");
trend_madd_cb( ctx);
}
void XttTrend::trend_help_cb( void *ctx)
......
......@@ -85,6 +85,7 @@ class XttTrend {
int (*get_select_cb)( void *, pwr_tAttrRef *, int *); //!< Get selected trend object.
CoWow *wow;
int color_theme;
XttOTree *otree;
XttTrend( void *xn_parent_ctx,
char *xn_name,
......@@ -98,7 +99,11 @@ class XttTrend {
void setup();
void curve_add( pwr_tAttrRef *arp, pwr_tAttrRef *trend_arp, pwr_tStatus *sts);
void update_color_theme( int ct) { curve->update_color_theme(ct);}
virtual XttOTree *tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int layout,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *)) {return 0;}
static pwr_tStatus trend_otree_action_cb( void *ctx, pwr_tAttrRef *aref);
static void trend_otree_close_cb( void *ctx);
static void trend_close_cb( void *ctx);
static void trend_help_cb( void *ctx);
static void trend_snapshot_cb( void *ctx);
......
......@@ -115,6 +115,10 @@ extern "C" {
#include "xtt_keyboard.h"
#endif
#ifndef xtt_otree_h
#include "xtt_otree.h"
#endif
#define xnav_cVersion "X3.0b"
#define XNAV_BROW_MAX 25
#define XNAV_LOGG_MAX 10
......@@ -411,6 +415,8 @@ class XNav {
pwr_tStatus *status) { return 0;}
virtual XttKeyboard *keyboard_new( const char *name, keyboard_eKeymap keymap, keyboard_eType type,
int color_theme, pwr_tStatus *status) {return 0;}
virtual XttOTree *tree_new( const char *title, pwr_tAttrRef *itemlist, int itemcnt, unsigned int options,
pwr_tStatus (*action_cb)( void *, pwr_tAttrRef *)) {return 0;}
virtual void bell( int time) {}
virtual int confirm_dialog( char *title, char *text) { return 0; }
virtual void set_clock_cursor() {}
......
......@@ -100,6 +100,7 @@
#include "xtt_fileview.h"
#include "xtt_log.h"
#include "xtt_stream.h"
#include "xtt_otree.h"
class xnav_file {
public:
......@@ -200,6 +201,7 @@ static void xnav_colortheme_selector_ok_cb( void *ctx, char *text, int ok_presse
static void xnav_keyboard_key_pressed_cb( void *, int);
static void xnav_keyboard_close_cb( void *);
static int xnav_replace_node_str( char *out, char *object_str);
static pwr_tStatus xnav_otree_action_cb( void *xnav, pwr_tAttrRef *aref);
static int xnav_help_func( void *client_data,
void *client_flag);
......@@ -273,7 +275,7 @@ dcli_tCmdTable xnav_command_table[] = {
"/OPTION", "/ENTRY", "/NEW", "/TITLE", "/WINDOW",
"/ALARMVIEW", "/WIDTH", "/HEIGHT", "/XPOSITION", "/YPOSITION",
"/FULLSCREEN", "/MAXIMIZE", "/FULLMAXIMIZE",
"/SORT", "/TEXT", ""}
"/SORT", "/TEXT", "/LAYOUT", "/GLOBAL", "/ALPHAORDER", ""}
},
{
"OPEN",
......@@ -2702,6 +2704,87 @@ static int xnav_show_func( void *client_data,
xnav_show_objectlist_cancel_cb, ctx);
free( names);
}
else if ( cdh_NoCaseStrncmp( arg1_str, "OBJECTTREE", strlen( arg1_str)) == 0)
{
char class_str[80];
// Command is "SHOW OBJECTTREE"
if ( ODD( dcli_get_qualifier( "/CLASS", class_str, sizeof(class_str)))) {
pwr_tCid cid[20];
pwr_tObjName class_array[20];
int class_num;
pwr_tAttrRef *list;
int listcnt;
unsigned int options = 0;
char layout_str[40];
int i;
int global;
int alphaorder;
global = ODD( dcli_get_qualifier( "/GLOBAL", 0, 0));
alphaorder = ODD( dcli_get_qualifier( "/ALPHAORDER", 0, 0));
// The class string can contain several classes separated by ','
class_num = dcli_parse( class_str, ",", "",
(char *) class_array, sizeof( class_array)/sizeof( class_array[0]),
sizeof( class_array[0]), 0);
for ( i = 0; i < class_num; i++) {
sts = gdh_ClassNameToId( class_array[i], &cid[i]);
if ( EVEN(sts)) {
xnav->message('E', "Unknown class");
return XNAV__HOLDCOMMAND;
}
}
if ( global)
sts = gdh_GetGlobalClassList( class_num, cid, 1, &list, &listcnt);
else
sts = gdh_GetLocalClassList( class_num, cid, 1, &list, &listcnt);
if ( EVEN(sts)) {
xnav->message('E', "Class list error");
return XNAV__HOLDCOMMAND;
}
if ( listcnt == 0) {
xnav->message('E', "No objects found");
return XNAV__HOLDCOMMAND;
}
if ( ODD( dcli_get_qualifier( "/LAYOUT", layout_str, sizeof(layout_str)))) {
if ( cdh_NoCaseStrcmp( layout_str, "list") == 0)
options |= tree_mOptions_LayoutList;
else if ( cdh_NoCaseStrcmp( layout_str, "tree") == 0)
options |= tree_mOptions_LayoutTree;
else if ( cdh_NoCaseStrcmp( layout_str, "default") == 0) {
if ( listcnt > 20)
options |= tree_mOptions_LayoutTree;
else
options |= tree_mOptions_LayoutList;
}
else {
xnav->message('E', "No such layout");
return XNAV__HOLDCOMMAND;
}
}
else {
if ( listcnt > 20)
options |= tree_mOptions_LayoutTree;
else
options |= tree_mOptions_LayoutList;
}
if ( alphaorder)
options |= tree_mOptions_AlphaOrder;
xnav->tree_new( "Objects", list, listcnt, options, xnav_otree_action_cb);
free( (char *)list);
return XNAV__SUCCESS;
}
else {
xnav->message('E', "Syntax error");
return XNAV__HOLDCOMMAND;
}
}
else
{
/* This might be a system picture */
......@@ -4513,7 +4596,7 @@ static int xnav_open_func( void *client_data,
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->close_cb = xnav_sevhist_close_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
// hist->get_select_cb = xnav_sevhist_get_select_cb;
xnav->appl.insert( applist_eType_SevHist, (void *)hist, pwr_cNOid, "",
NULL);
}
......@@ -4768,7 +4851,7 @@ static int xnav_open_func( void *client_data,
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->close_cb = xnav_sevhist_close_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
//hist->get_select_cb = xnav_sevhist_get_select_cb;
xnav->appl.insert( applist_eType_SevHist, (void *)hist, oidv[0], "",
NULL);
}
......@@ -4780,7 +4863,7 @@ static int xnav_open_func( void *client_data,
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->close_cb = xnav_sevhist_close_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
//hist->get_select_cb = xnav_sevhist_get_select_cb;
xnav->appl.insert( applist_eType_SevHist, (void *)hist, oidv[0], "",
NULL);
}
......@@ -4792,7 +4875,7 @@ static int xnav_open_func( void *client_data,
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->close_cb = xnav_sevhist_close_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
//hist->get_select_cb = xnav_sevhist_get_select_cb;
xnav->appl.insert( applist_eType_SevHist, (void *)hist, oidv[0], "",
NULL);
}
......@@ -9635,7 +9718,6 @@ int XNav::show_symbols()
return XNAV__SUCCESS;
}
void xnav_popup_menu_cb( void *xnav, pwr_sAttrRef attrref,
unsigned long item_type,
unsigned long utility, char *arg, int x, int y)
......@@ -9662,6 +9744,7 @@ void xnav_start_trace_cb( void *xnav, pwr_tObjid objid, char *name)
((XNav *)xnav)->start_trace( objid, name);
}
static void xnav_clog_close_cb( void *ctx)
{
XNav *xnav = (XNav *)ctx;
......@@ -9845,6 +9928,44 @@ static void xnav_keyboard_close_cb( void *ctx)
xnav->close_keyboard( keyboard_mAction_Close | keyboard_mAction_ResetInput);
}
static pwr_tStatus xnav_otree_action_cb( void *ctx, pwr_tAttrRef *aref)
{
XNav *xnav = (XNav *)ctx;
pwr_tStatus sts;
pwr_tAName aname;
pwr_tCmd cmd;
pwr_tCid cid;
sts = gdh_GetAttrRefTid( aref, &cid);
if ( EVEN(sts)) return sts;
sts = gdh_AttrrefToName( aref, aname, sizeof(aname), cdh_mNName);
if ( EVEN(sts)) return sts;
switch ( cid) {
case pwr_cClass_DsTrend:
case pwr_cClass_DsTrendCurve:
sprintf( cmd, "open trend/name=%s/title=\"%s\"", aname, aname);
break;
case pwr_cClass_DsFastCurve:
sprintf( cmd, "open fast/name=%s/title=\"%s\"", aname, aname);
break;
case pwr_cClass_SevHist:
case pwr_cClass_SevHistObject:
sprintf( cmd, "open history/name=%s/title=\"%s\"", aname, aname);
break;
case pwr_cClass_XttGraph:
sprintf( cmd, "open graph/object=%s", aname);
break;
default:
sprintf( cmd, "open graph/class/inst=%s", aname);
}
xnav->command( cmd);
return 1;
}
void XNav::open_graph( const char *name, const char *filename, int scrollbar, int menu,
int navigator, int width, int height, int x, int y,
const char *object_name, const char *focus_name, int input_focus_empty,
......
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