Commit 3c756ca1 authored by Claes Sjofors's avatar Claes Sjofors

Ge editor, check for unique object name, and name displayed in object edior

parent 11ef0ffc
......@@ -65,6 +65,7 @@
extern msg_sHead wbMsgHead;
extern msg_sHead geMsgHead;
extern msg_sHead flowMsgHead;
extern msg_sHead glowMsgHead;
extern msg_sHead pwrpMsgHead;
static const msg_sHead *heads[] = {
......@@ -76,6 +77,7 @@
&wbMsgHead,
&geMsgHead,
&flowMsgHead,
&glowMsgHead,
NULL
};
......
......@@ -44,6 +44,6 @@ noparent <There is no parent> /error
noconpoint <There is no such conpoint> /error
nochild <There is no child> /error
nonextsibling <There is no next sibling> /error
destroyed <Flow ctx is destoryed> /info
destroyed <Flow ctx is destroyed> /info
no_propagate <Don't propagate event handling> /info
fileopen <Unable to open file> /error
......@@ -52,3 +52,6 @@ noselect <Nothing is selected> /error
groupclass <Unable to group this kind of object> /error
terminated <Ctx is terminated> /info
subterminated <Subwindow is terminated> /info
name_long <Name is too long> /error
name_invchar <Invalid character for name> /error
name_alrexist <Name already exist> /error
......@@ -65,6 +65,25 @@ void AttrGtk::message( char severity, const char *message)
gtk_label_set_text( GTK_LABEL(msg_label), message);
}
void AttrGtk::message_popup( char severity, const char *message)
{
char title[40];
switch ( severity) {
case 'I':
strcpy( title, "Info message");
break;
case 'W':
strcpy( title, "Warning message");
break;
default:
strcpy( title, "Error message");
}
CoWowGtk wow( toplevel);
wow.DisplayError( title, message);
}
void AttrGtk::set_prompt( const char *prompt) {
if ( strcmp(prompt, "") == 0) {
g_object_set( cmd_prompt, "visible", FALSE, NULL);
......
......@@ -80,6 +80,7 @@ class AttrGtk : public Attr {
int input_max_length;
void message( char severity, const char *message);
void message_popup( char severity, const char *message);
void set_prompt( const char *prompt);
void change_value();
int reconfigure_attr();
......
......@@ -409,11 +409,6 @@ void GeGtk::activate_change_text(GtkWidget *w, gpointer gectx)
((Ge *)gectx)->activate_change_text();
}
void GeGtk::activate_change_name(GtkWidget *w, gpointer gectx)
{
((Ge *)gectx)->activate_change_name();
}
void GeGtk::activate_search_object(GtkWidget *w, gpointer gectx)
{
((Ge *)gectx)->activate_search_object();
......@@ -1876,10 +1871,6 @@ GeGtk::GeGtk( void *x_parent_ctx,
gtk_widget_add_accelerator( edit_change_text, "activate", accel_g,
't', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
GtkWidget *edit_change_name = gtk_menu_item_new_with_mnemonic( "Change _Name");
g_signal_connect( edit_change_name, "activate",
G_CALLBACK(activate_change_name), this);
GtkWidget *edit_search_object = gtk_menu_item_new_with_mnemonic( "_Search Object");
g_signal_connect( edit_search_object, "activate",
G_CALLBACK(activate_search_object), this);
......@@ -1913,7 +1904,6 @@ GeGtk::GeGtk( void *x_parent_ctx,
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_polyline);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_create_subgraph);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_change_text);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_change_name);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_search_object);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_objattr_store);
gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_objattr_recall);
......
......@@ -130,7 +130,6 @@ class GeGtk : public Ge {
static void activate_create_subgraph(GtkWidget *w, gpointer gectx);
static void activate_change_text( GtkWidget *w, gpointer gectx);
static void activate_change_name( GtkWidget *w, gpointer gectx);
static void activate_search_object( GtkWidget *w, gpointer gectx);
static void activate_preview_start( GtkWidget *w, gpointer gectx);
static void activate_preview_stop( GtkWidget *w, gpointer gectx);
......
......@@ -193,9 +193,12 @@ int Attr::reconfigure_attr_c( void *attr)
return ((Attr *)attr)->reconfigure_attr();
}
void Attr::message( void *attr, char severity, const char *message)
void Attr::message( void *attr, int popup, char severity, const char *message)
{
((Attr *)attr)->message( severity, message);
if ( popup)
((Attr *)attr)->message_popup( severity, message);
else
((Attr *)attr)->message( severity, message);
}
......@@ -58,6 +58,8 @@ typedef struct {
int noedit;
int multiline;
int mask;
int (*input_validation_cb)( void *ctx, void *value);
void *validation_ctx;
} attr_sItem;
class AttrNav;
......@@ -96,6 +98,7 @@ class Attr {
GeDyn *original_data;
virtual void message( char severity, const char *message) {}
virtual void message_popup( char severity, const char *msg) {message(severity,msg);}
virtual void set_prompt( const char *prompt) {}
virtual void change_value() {}
virtual int reconfigure_attr() {return 1;}
......@@ -113,7 +116,7 @@ class Attr {
attr_sItem **itemlist, int *item_cnt);
static void change_value_c( void *attr);
static int reconfigure_attr_c( void *attr);
static void message( void *attr, char severity, const char *message);
static void message( void *attr, int popup, char severity, const char *message);
virtual ~Attr();
};
......
......@@ -45,6 +45,7 @@
#include "co_cdh.h"
#include "co_time.h"
#include "co_dcli.h"
#include "co_msg.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
......@@ -1463,9 +1464,9 @@ void attrnav_attrvalue_to_string( int type_id, void *value_ptr,
}
}
void AttrNav::message( char sev, const char *text)
void AttrNav::message( int popup, char sev, const char *text)
{
(message_cb)( parent_ctx, sev, text);
(message_cb)( parent_ctx, popup, sev, text);
}
//
......@@ -1591,18 +1592,29 @@ int AttrNav::set_attr_value( char *value_str)
buffer, sizeof(buffer), item->size);
if ( EVEN(sts)) return sts;
if ( item->input_validation_cb) {
sts = (item->input_validation_cb)(item->validation_ctx, (void *)buffer);
if ( EVEN(sts)) {
char msg[200];
msg_GetMsg( sts, msg, sizeof(msg));
message( 1, 'E', msg);
return 0;
}
}
if ( item->max_limit != 0 || item->min_limit != 0) {
if ( item->type_id == glow_eType_Double ) {
if ( *(double *)&buffer < item->min_limit ||
*(double *)&buffer > item->max_limit) {
message( 'E', "Min or maxvalue exceeded");
message( 0, 'E', "Min or maxvalue exceeded");
return 0;
}
}
else if ( item->type_id == glow_eType_Int ) {
if ( *(int *)&buffer < item->min_limit ||
*(int *)&buffer > item->max_limit) {
message( 'E', "Min or maxvalue exceeded");
message( 0, 'E', "Min or maxvalue exceeded");
return 0;
}
}
......@@ -1691,7 +1703,7 @@ static int attrnav_brow_cb( FlowCtx *ctx, flow_tEvent event)
}
brow_GetCtxUserData( (BrowCtx *)ctx, (void **) &attrnav);
attrnav->message( ' ', null_str);
attrnav->message( 0, ' ', null_str);
switch ( event->event)
{
case flow_eEvent_Key_PageDown: {
......@@ -2367,9 +2379,10 @@ int AttrNav::object_attr()
for ( i = 0; i < item_cnt; i++)
{
new ItemLocal( this, item_p->name, "LocalAttr",
item_p->type, item_p->size, item_p->minlimit, item_p->maxlimit,
item_p->value, item_p->multiline, item_p->noedit, item_p->mask,
NULL, flow_eDest_IntoLast);
item_p->type, item_p->size, item_p->minlimit, item_p->maxlimit,
item_p->value, item_p->multiline, item_p->noedit, item_p->mask,
item_p->input_validation_cb, item_p->validation_ctx,
NULL, flow_eDest_IntoLast);
item_p++;
}
......@@ -2456,12 +2469,15 @@ ItemLocal::ItemLocal( AttrNav *attrnav, const char *item_name, const char *attr,
int attr_type, int attr_size, double attr_min_limit,
double attr_max_limit, void *attr_value_p, int attr_multiline,
int attr_noedit, int attr_mask,
int (*attr_input_validation_cb)( void *ctx, void *value),
void *attr_validation_ctx,
brow_tNode dest, flow_eDest dest_code) :
value_p(attr_value_p), first_scan(1),
type_id(attr_type), size(attr_size),
min_limit(attr_min_limit), max_limit(attr_max_limit),
multiline(attr_multiline), noedit(attr_noedit), mask(attr_mask), parent(0),
subgraph(0)
multiline(attr_multiline), noedit(attr_noedit), mask(attr_mask),
input_validation_cb(attr_input_validation_cb), validation_ctx(attr_validation_ctx),
parent(0), subgraph(0)
{
type = attrnav_eItemType_Local;
......@@ -2572,6 +2588,7 @@ int ItemLocal::open_children( AttrNav *attrnav, double x, double y)
new ItemLocal( attrnav, item_p->name, "LocalAttr",
item_p->type, item_p->size, item_p->minlimit, item_p->maxlimit,
item_p->value, item_p->multiline, item_p->noedit, item_p->mask,
item_p->input_validation_cb, item_p->validation_ctx,
node, flow_eDest_IntoLast);
item_p++;
}
......@@ -2657,6 +2674,7 @@ int ItemLocal::open_children( AttrNav *attrnav, double x, double y)
new ItemLocal( attrnav, item_p->name, "LocalAttr",
item_p->type, item_p->size, item_p->minlimit, item_p->maxlimit,
item_p->value, item_p->multiline, item_p->noedit, item_p->mask,
item_p->input_validation_cb, item_p->validation_ctx,
node, flow_eDest_IntoLast);
item_p++;
}
......
......@@ -151,7 +151,7 @@ class AttrNav {
attr_sItem *itemlist;
int item_cnt;
int trace_started;
void (*message_cb)( void *, char, const char *);
void (*message_cb)( void *, int, char, const char *);
void (*change_value_cb)( void *);
int (*get_subgraph_info_cb)( void *, char *, attr_sItem **, int *);
int (*get_dyn_info_cb)( void *, GeDyn *, attr_sItem **, int *);
......@@ -163,7 +163,7 @@ class AttrNav {
virtual int set_attr_value( char *value_str);
virtual int check_attr_value( int *multiline, int *size, char **value);
virtual void message( char sev, const char *text);
virtual void message( int popup, char sev, const char *text);
virtual void set_inputfocus() {}
virtual void force_trace_scan();
virtual int object_attr();
......@@ -180,7 +180,9 @@ class ItemLocal {
ItemLocal( AttrNav *attrnav, const char *item_name, const char *attr,
int attr_type, int attr_size, double attr_min_limit,
double attr_max_limit, void *attr_value_p, int attr_multiline,
int attr_noedit, int attr_mask,
int attr_noedit, int attr_mask,
int (*attr_input_validation_cb)( void *ctx, void *value),
void *attr_validation_ctx,
brow_tNode dest, flow_eDest dest_code);
attrnav_eItemType type;
brow_tNode node;
......@@ -195,6 +197,8 @@ class ItemLocal {
int multiline;
int noedit;
int mask;
int (*input_validation_cb)( void *ctx, void *value);
void *validation_ctx;
int parent;
int subgraph;
......
......@@ -4084,9 +4084,12 @@ int GeValue::connect( grow_tObject object, glow_sTraceData *trace_data)
else
annot_typeid = dyn_get_typeid( format);
if ( !check_format( format, annot_typeid))
printf( "** GeValue: Suspicious format \"%s\" (%s)\n", format, attribute);
if ( !check_format( format, annot_typeid)) {
char name[80];
grow_GetObjectName( object, name);
printf( "** GeValue: Suspicious format \"%s\" (%s, %s)\n", format, name, attribute);
}
break;
case graph_eDatabase_Local:
p = dyn->graph->localdb_ref_or_create( parsed_name, attr_type);
......@@ -14443,7 +14446,7 @@ int GeInputFocus::action( grow_tObject object, glow_tEvent event)
break;
case glow_eEvent_Key_Left:
if ( event->object.object_type != glow_eObjectType_NoObject) {
char name[40];
char name[80];
grow_tObject *objectlist, *object_p;
int object_cnt;
int i;
......@@ -14532,7 +14535,7 @@ int GeInputFocus::action( grow_tObject object, glow_tEvent event)
break;
case glow_eEvent_Key_Up:
if ( event->object.object_type != glow_eObjectType_NoObject) {
char name[40];
char name[80];
grow_tObject *objectlist, *object_p;
int object_cnt;
int i;
......
......@@ -1412,6 +1412,8 @@ int Graph::get_attr_items( grow_tObject object, attr_sItem **itemlist,
items[i].maxlimit = 0;
items[i].noedit = grow_info_p->no_edit;
items[i].multiline = grow_info_p->multiline;
items[i].input_validation_cb = grow_info_p->input_validation_cb;
items[i].validation_ctx = grow_info_p->validation_ctx;
grow_info_p++;
}
......@@ -1914,6 +1916,8 @@ int Graph::get_attr_items( grow_tObject object, attr_sItem **itemlist,
items[i].maxlimit = grow_info_p->maxlimit;
items[i].noedit = grow_info_p->no_edit;
items[i].multiline = grow_info_p->multiline;
items[i].input_validation_cb = grow_info_p->input_validation_cb;
items[i].validation_ctx = grow_info_p->validation_ctx;
grow_info_p++;
}
......@@ -2945,7 +2949,6 @@ static int graph_grow_cb( GlowCtx *ctx, glow_tEvent event)
grow_tObject *move_list;
int move_count;
int i;
char name[80];
grow_GetMoveList( graph->grow->ctx, &move_list, &move_count);
for ( i = 0; i < move_count; i++)
......@@ -2953,16 +2956,13 @@ static int graph_grow_cb( GlowCtx *ctx, glow_tEvent event)
switch ( grow_GetObjectType( move_list[i]))
{
case glow_eObjectType_Con:
sprintf( name, "C%d", grow_IncrNextObjectNameNumber( graph->grow->ctx));
grow_SetObjectName( move_list[i], name);
grow_SetObjectName( move_list[i], graph->get_next_object_name("C", ""));
break;
case glow_eObjectType_GrowGroup:
sprintf( name, "Grp%d_", grow_IncrNextObjectNameNumber( graph->grow->ctx));
grow_SetObjectName( move_list[i], name);
grow_SetObjectName( move_list[i], graph->get_next_object_name("Grp", "_"));
break;
default:
sprintf( name, "O%d", grow_IncrNextObjectNameNumber( graph->grow->ctx));
grow_SetObjectName( move_list[i], name);
grow_SetObjectName( move_list[i], graph->get_next_object_name("O", ""));
break;
}
}
......@@ -5106,7 +5106,7 @@ void Graph::create_trend( grow_tObject *object, double x, double y,
bcolor = glow_eDrawType_Color37;
}
grow_CreateGrowTrend( grow->ctx, "",
grow_CreateGrowTrend( grow->ctx, get_next_object_name("O",""),
x, y, width, height,
bcolor,
1, glow_mDisplayLevel_1, 1, 1,
......@@ -5152,7 +5152,7 @@ void Graph::create_xycurve( grow_tObject *object, double x, double y,
GeDyn *dyn;
glow_sTrendInfo info;
grow_CreateGrowXYCurve( grow->ctx, "",
grow_CreateGrowXYCurve( grow->ctx, get_next_object_name("O",""),
x, y, width, height,
glow_eDrawType_Color37,
1, glow_mDisplayLevel_1, 1, 1,
......@@ -5201,7 +5201,7 @@ void Graph::create_bar( grow_tObject *object, double x, double y, int colortheme
barbordercolor = glow_eDrawType_Color145;
}
grow_CreateGrowBar( grow->ctx, "",
grow_CreateGrowBar( grow->ctx, get_next_object_name("O",""),
x, y, width, height,
glow_eDrawType_Line,
1, glow_mDisplayLevel_1, 1, 1,
......@@ -5227,7 +5227,7 @@ void Graph::create_window( grow_tObject *object, double x, double y)
double height = 6;
GeDyn *dyn;
grow_CreateGrowWindow( grow->ctx, "",
grow_CreateGrowWindow( grow->ctx, get_next_object_name("O",""),
x, y, width, height,
glow_eDrawType_Line,
1, glow_mDisplayLevel_1, NULL,
......@@ -5245,7 +5245,7 @@ void Graph::create_table( grow_tObject *object, double x, double y)
double height = 6;
GeDyn *dyn;
grow_CreateGrowTable( grow->ctx, "",
grow_CreateGrowTable( grow->ctx, get_next_object_name("O",""),
x, y, width, height,
glow_eDrawType_Line,
1, 1, glow_eDrawType_Color33, glow_mDisplayLevel_1, NULL,
......@@ -5264,7 +5264,7 @@ void Graph::create_folder( grow_tObject *object, double x, double y)
double height = 6;
GeDyn *dyn;
grow_CreateGrowFolder( grow->ctx, "",
grow_CreateGrowFolder( grow->ctx, get_next_object_name("O",""),
x, y, width, height,
glow_eDrawType_Line, 1,
glow_eDrawType_Color22, glow_eDrawType_Color25,
......@@ -5306,7 +5306,7 @@ void Graph::create_axis( grow_tObject *object, double x, double y, int dynamic,
else
bcolor = glow_eDrawType_Line;
grow_CreateGrowAxis( grow->ctx, "",
grow_CreateGrowAxis( grow->ctx, get_next_object_name("O",""),
x, y, x + width, y + height,
bcolor, 1, 1,
glow_eDrawType_TextHelvetica, NULL, object);
......@@ -5349,7 +5349,7 @@ void Graph::create_axisarc( grow_tObject *object, double x, double y, int dynami
else
bcolor = glow_eDrawType_Line;
grow_CreateGrowAxisArc( grow->ctx, "",
grow_CreateGrowAxisArc( grow->ctx, get_next_object_name("O",""),
x, y, x + width, y + height, 0, 180,
bcolor, 1, 1,
glow_eDrawType_TextHelvetica, NULL, object);
......@@ -5397,7 +5397,7 @@ void Graph::create_pie( grow_tObject *object, double x, double y)
glow_eDrawType_Color225 };
double values[12] = { 8.333, 8.333, 8.333, 8.333, 8.333, 8.333, 8.333, 8.333, 8.333, 8.333, 8.333, 8.333};
grow_CreateGrowPie( grow->ctx, "",
grow_CreateGrowPie( grow->ctx, get_next_object_name("O",""),
x, y, x + width, y + height, 0, 360,
glow_eDrawType_Line, 1, 1, 0, glow_eDrawType_Color38,
NULL, object);
......@@ -5429,7 +5429,7 @@ void Graph::create_barchart( grow_tObject *object, double x, double y)
glow_eDrawType_Color195,
glow_eDrawType_Color225 };
grow_CreateGrowBarChart( grow->ctx, "",
grow_CreateGrowBarChart( grow->ctx, get_next_object_name("O",""),
x, y, width, height,
glow_eDrawType_Line, 1, 1, 0, glow_eDrawType_Color40,
NULL, object);
......@@ -5557,6 +5557,18 @@ int Graph::search_object( char *name)
return 1;
}
char *Graph::get_next_object_name( const char *prefix, const char *suffix)
{
static char name[32];
int sts = 0;
while ( EVEN(sts)) {
sprintf( name, "%s%d%s", prefix, grow_IncrNextObjectNameNumber( grow->ctx), suffix);
sts = grow_CheckObjectName( grow->ctx, name);
}
return name;
}
static void graph_free_dyn( grow_tObject object)
{
if ( grow_GetObjectType( object) == glow_eObjectType_GrowNode ||
......
......@@ -1390,6 +1390,8 @@ class Graph {
else return 1;
}
char *get_next_object_name( const char *prefix, const char *suffix);
static int get_colortheme_colors( char *file, double **colors, int *size);
//! Enable event logging
......
This diff is collapsed.
......@@ -92,6 +92,8 @@ extern "C" {
int no_edit;
double maxlimit;
double minlimit;
int (*input_validation_cb)( void *ctx, void *value);
void *validation_ctx;
} grow_sAttrInfo;
//! Structs to set attributes for the grow context.
......@@ -3132,6 +3134,7 @@ extern "C" {
void grow_SetObjectOriginalBackgroundColor( grow_tObject o, glow_eDrawType color);
void grow_ResetObjectBackgroundColor( grow_tObject object);
int grow_SetObjectClass( grow_tObject object, grow_tNodeClass nodeclass);
int grow_CheckObjectName( grow_tCtx ctx, char *name);
/*@}*/
......
......@@ -4728,3 +4728,35 @@ void GrowCtx::set_default_color_theme( char *theme)
{
strncpy( default_color_theme, theme, sizeof(default_color_theme));
}
int GrowCtx::check_object_name( char *name)
{
static const char ctab[257] =
"\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!0123456789!!!!!!\
!ABCDEFGHIJKLMNOPQRSTUVWXYZ!!!!_\
!^^^^^^^^^^^^^^^^^^^^^^^^^^!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
";
int len = strlen(name);
GlowArrayElem *e;
int sts;
if ( len >= 80)
return GLOW__NAME_LONG;
for ( int i = 0; i < len; i++) {
if ( ctab[(unsigned char)name[i]] == '!')
return GLOW__NAME_INVCHAR;
}
sts = a.find_by_name( name, &e);
if ( ODD(sts))
return GLOW__NAME_ALREXIST;
return GLOW__SUCCESS;
}
......@@ -881,6 +881,7 @@ class GrowCtx : public GlowCtx {
void reset_custom_colors();
int read_customcolor_file( char *name);
int write_customcolor_file( char *name);
int check_object_name( char *name);
static void set_default_color_theme( char *theme);
static int get_dimension( char *filename, int *width, int *heigth);
......
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