static pwr_tStatus ConnectAttribute ( ldh_sMenuCall *ip ) { pwr_tStatus sts; pwr_sMenuButton mb; pwr_sAttrRef PattrRef; sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject, "SysBody", &mb, sizeof(pwr_sMenuButton)); if (EVEN(sts)) return sts; // Assume RtBody or SysBody char *aname_p; pwr_tAName aname; int size; sts = ldh_AttrRefToName( ip->PointedSession, &ip->Pointed, ldh_eName_ArefVol, &aname_p, &size); if ( EVEN(sts)) return 0; strncpy( aname, aname_p, sizeof(aname)); strncat( aname, ".", sizeof(aname)); strncat( aname, mb.MethodArguments[0], sizeof(aname)); sts = ldh_NameToAttrRef( ip->PointedSession, aname, &PattrRef); if (ODD(sts)) sts = ldh_WriteAttribute(ip->PointedSession, &PattrRef, &ip->Selected[0], sizeof(pwr_tAttrRef)); if ( ip->message_cb) { char msg[200]; if ( ODD(sts)) { pwr_tOName name; sts = ldh_AttrRefToName( ip->PointedSession, &ip->Selected[0], ldh_eName_Hierarchy, &aname_p, &size); if ( ODD(sts)) strncpy( name, aname_p, sizeof(name)); else cdh_ObjidToString( name, ip->Selected[0].Objid, 1); snprintf( msg, sizeof(msg), "%s connected to: %s", mb.MethodArguments[0], name); ip->wtt->message( 'I', msg); } else { msg_GetMsg( sts, msg, sizeof(msg)); ip->wtt->message( 'E', msg); } } return LDH__SUCCESS; }
pwr_tStatus wb_bck_list::diff( wb_bck_list *lp, wb_bck_list *outlp) { pwr_tStatus sts; int diff_cnt = 0; if ( lp->m_type == bck_eType_Wb) outlp->m_type = bck_eType_WbDiff; else outlp->m_type = bck_eType_FileDiff; bck_sItem *ip = m_first; while (ip) { pwr_eType atype; char *anamep; int size; sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size); if ( EVEN(sts)) return sts; sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype); if ( ODD(sts)) { void *value2p; bck_sItem *ip2 = lp->find( &ip->aref); if ( ip2) { value2p = ip2->valuep; int is_equal = 0; switch ( atype) { case pwr_eType_String: case pwr_eType_Text: is_equal = strcmp( (const char *)value2p, (const char *)ip->valuep) == 0 ? 1 : 0; break; default: is_equal = memcmp( value2p, ip->valuep, ip->size) == 0 ? 1 : 0; } if ( is_equal) { ip = ip->next; continue; } } else value2p = 0; outlp->add( ip, value2p); diff_cnt++; } ip = ip->next; } return LDH__SUCCESS; }
static pwr_tStatus trace_get_attr_m5( WGre *gre, vldh_t_node node, char *debug_par, char *object_str, char *attr_str, flow_eTraceType *trace_type, int *inverted) { pwr_tAName aname; pwr_tStatus sts; int size; pwr_sAttrRef *objarp; pwr_sAttrRef objar, disar; char *np, *s; ldh_sAttrRefInfo info; *inverted = 0; /* Get the attrref stored in the attribute Object */ sts = ldh_GetObjectPar( node->hn.wind->hw.ldhses, node->ln.oid, "DevBody", "Object", (char **)&objarp, &size); if ( EVEN(sts)) return sts; objar = *objarp; free((char *) objarp); sts = ldh_GetAttrRefInfo( node->hn.wind->hw.ldhses, &objar, &info); if( EVEN(sts)) return sts; if ( !info.flags & PWR_MASK_DISABLEATTR) return TRA__NOPAR; disar = cdh_ArefToDisableAref( &objar); /* Get the name of the node */ sts = ldh_AttrRefToName( node->hn.wind->hw.ldhses, &disar, cdh_mNName, &np, &size); if( EVEN(sts)) return sts; strcpy( aname, np); s = strrchr( aname, '.'); if ( !s) return TRA__NOPAR; strcpy( attr_str, s + 1); *s = 0; strcpy( object_str, aname); *trace_type = flow_eTraceType_Boolean; return TRA__SUCCESS; }
void WAtt::activate_print() { char *namep; pwr_tStatus sts; int size; pwr_tAName aname; sts = ldh_AttrRefToName( ldhses, &aref, ldh_eName_VolPath, &namep, &size); if ( EVEN(sts)) return; strcpy( aname, namep); print( aname); }
void WCrrGtk::print() { pwr_tStatus sts; char *namep; int size; pwr_tAName title; sts = ldh_AttrRefToName( ldhses, &objar, cdh_mNName, &namep, &size); if ( EVEN(sts)) return; strncpy( title, namep, sizeof(title)); CoWowGtk::CreateBrowPrintDialogGtk( title, xcrrnav->brow->ctx, flow_eOrientation_Portrait, 1.0, (void *)toplevel, &sts); }
pwr_tStatus wb_bck_list::print( char *outfile) { pwr_tFileName fname; FILE *fout; pwr_tStatus sts; dcli_translate_filename( fname, outfile); fout = fopen( fname, "w"); if ( !fout) return LDH__NOSUCHFILE; bck_sItem *ip = m_first; while (ip) { char str[1024]; pwr_eType atype; int printed = 0; char *anamep; int size; sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size); if ( EVEN(sts)) return sts; fprintf( fout, "%s", anamep); sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype); if ( ODD(sts)) { sts = cdh_AttrValueToString( atype, ip->valuep, str, sizeof(str)); if ( ODD(sts)) { fprintf( fout, "\n %s\n", str); printed = 1; } } if ( !printed) { // Print as hex code unsigned char *p = (unsigned char *)ip->valuep; for ( int i = 0; i < (int)ip->size; i++, p++) { if ((i % 16) == 0) fprintf( fout, "\n "); fprintf( fout, "%02x ", *p); } fprintf( fout, "\n"); } ip = ip->next; } fclose( fout); return LDH__SUCCESS; }
// // Crossreferences // static pwr_tStatus Crossreferences( ldh_sMenuCall *ip) { pwr_tStatus sts; int size; char *namep; char cmd[600]; sts = ldh_AttrRefToName( ip->PointedSession, &ip->Pointed, cdh_mNName, &namep, &size); if ( EVEN(sts)) return sts; snprintf( cmd, sizeof(cmd), "cross/wind/name=%s", namep); ip->wnav->command( cmd); return 1; }
pwr_tStatus wsx_error_msg( ldh_tSesContext sesctx, pwr_tStatus sts, pwr_tAttrRef aref, int *errorcount, int *warningcount ) { static char msg[256]; int status, size; pwr_tAName name; char *namep; FILE *logfile; logfile = NULL; if (EVEN(sts)) { msg_GetMsg( sts, msg, sizeof(msg)); if (logfile != NULL) fprintf(logfile, "%s\n", msg); else printf("%s\n", msg); if ( cdh_ObjidIsNull( aref.Objid)) MsgWindow::message( co_error(sts), 0, 0); else { /* Get the full hierarchy name for the node */ status = ldh_AttrRefToName( sesctx, &aref, cdh_mNName, &namep, &size); if( EVEN(status)) return status; strncpy( name, namep, sizeof(name)); if (logfile != NULL) fprintf(logfile, " in object %s\n", name); else printf(" in object %s\n", name); MsgWindow::message( co_error(sts), " in object", name, aref.Objid); } if ( (sts & 2) && !(sts & 1)) (*errorcount)++; else if ( !(sts & 2) && !(sts & 1)) (*warningcount)++; } return WSX__SUCCESS; }
pwr_tStatus wsx_error_msg_str( ldh_tSesContext sesctx, const char *str, pwr_tAttrRef aref, int severity, int *errorcount, int *warningcount ) { int status, size; pwr_tAName name; char *namep; FILE *logfile; char msg[200]; logfile = NULL; snprintf( msg, sizeof(msg), "%%WSX-%c-MSG, %s", severity, str); if (logfile != NULL) fprintf(logfile, "%s\n", msg); else printf("%s\n", msg); if ( cdh_ObjidIsNull( aref.Objid)) MsgWindow::message( severity, msg, "", 0); else { /* Get the full hierarchy name for the node */ status = ldh_AttrRefToName( sesctx, &aref, cdh_mNName, &namep, &size); if( EVEN(status)) return status; strncpy( name, namep, sizeof(name)); if (logfile != NULL) fprintf(logfile, " in object %s\n", name); else printf(" in object %s\n", name); MsgWindow::message( severity, msg, " in object", name, aref.Objid); } if ( severity == 'E' || severity == 'F') (*errorcount)++; else if ( severity == 'W') (*warningcount)++; return WSX__SUCCESS; }
static pwr_tStatus Connect ( ldh_sMenuCall *ip ) { pwr_tStatus sts; pwr_sMenuButton mb; pwr_sAttrRef PattrRef; pwr_sAttrRef aref = ip->Selected[0]; sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject, "SysBody", &mb, sizeof(pwr_sMenuButton)); if (EVEN(sts)) return sts; if ( strcmp( mb.MethodArguments[1], "") != 0) { char arg_cid_str[20][32]; int arg_cid_cnt; int i; int cid_ok = 0; pwr_tCid cid; pwr_tCid arg_cid; // arg 1 holds the allowed class or classes to connect to arg_cid_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *) arg_cid_str, sizeof( arg_cid_str) / sizeof( arg_cid_str[0]), sizeof( arg_cid_str[0]), 0); sts = ldh_GetAttrRefTid( ip->PointedSession, &ip->Selected[0], &cid); if ( EVEN(sts)) return 0; for ( i = 0; i < arg_cid_cnt; i++) { sts = ldh_ClassNameToId( ip->PointedSession, &arg_cid, arg_cid_str[i]); if ( EVEN(sts)) return 0; if ( cid == arg_cid) { cid_ok = 1; break; } } if ( !cid_ok) return 0; } if ( strcmp( mb.MethodArguments[2], "") != 0) // Body in MethodArguments 2, probably DevBody sts = ldh_SetObjectPar( ip->PointedSession, ip->Pointed.Objid, mb.MethodArguments[2], mb.MethodArguments[0], (char *) &ip->Selected[0], sizeof(ip->Selected[0])); else { char *name_p; pwr_tAName name; int size; pwr_tCid cid; // If Selected is a Template object in a classvolume, replace with // symbol $IoConnect if ( cdh_IsClassVolume( aref.Objid.vid)) { sts = ldh_ObjidToName( ip->PointedSession, aref.Objid, ldh_eName_Object, name, sizeof(name), &size); if ( ODD(sts) && strcmp( name, "Template") == 0) { sts = ldh_GetObjectClass( ip->PointedSession, aref.Objid, &cid); if ( EVEN(sts)) return sts; aref.Objid.vid = ldh_cIoConnectVolume; aref.Objid.oix = cid; } } // Assume RtBody or SysBody sts = ldh_AttrRefToName(ip->PointedSession, &ip->Pointed, ldh_eName_VolPath, &name_p, &size); if ( ODD(sts)) { strcpy( name, name_p); strcat( name, "."); strcat( name, mb.MethodArguments[0]); sts = ldh_NameToAttrRef( ip->PointedSession, name, &PattrRef); if (ODD(sts)) sts = ldh_WriteAttribute(ip->PointedSession, &PattrRef, &aref, sizeof(aref)); } } char msg[500]; if ( ODD(sts)) { pwr_tAName name; char *name_p; int len; sts = ldh_AttrRefToName( ip->PointedSession, &aref, ldh_eName_Hierarchy, &name_p, &len); if ( EVEN(sts)) cdh_ObjidToString( name, aref.Objid, 1); else strcpy( name, name_p); sprintf( msg, "%s connected to: %s", mb.MethodArguments[0], name); ip->wtt->message( 'I', msg); } else { msg_GetMsg( sts, msg, sizeof(msg)); ip->wtt->message( 'E', msg); } return PWRS__SUCCESS; }
static pwr_tStatus IoConnect ( ldh_sMenuCall *ip ) { pwr_tStatus sts; pwr_sMenuButton mb; pwr_sAttrRef aref = ip->Selected[0]; pwr_sAttrRef PattrRef; char *name_p; pwr_tAName name; int size; sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject, "SysBody", &mb, sizeof(pwr_sMenuButton)); if (EVEN(sts)) return sts; if ( strcmp( mb.MethodArguments[0], "") != 0) { char arg_cid_str[20][32]; int arg_cid_cnt; int i; int cid_ok = 0; pwr_tCid cid; pwr_tCid arg_cid; // arg 0 holds the allowed class or classes to connect to arg_cid_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *) arg_cid_str, sizeof( arg_cid_str) / sizeof( arg_cid_str[0]), sizeof( arg_cid_str[0]), 0); sts = ldh_GetAttrRefTid( ip->PointedSession, &ip->Selected[0], &cid); if ( EVEN(sts)) return 0; for ( i = 0; i < arg_cid_cnt; i++) { sts = ldh_ClassNameToId( ip->PointedSession, &arg_cid, arg_cid_str[i]); if ( EVEN(sts)) return 0; if ( cid == arg_cid) { cid_ok = 1; break; } } if ( !cid_ok) return 0; } #if 0 printf( "Here in IoConnect\n"); wb_session *sp = (wb_session *)ip->PointedSession; wb_object o = sp->object( ip->Pointed.Objid); if ( !o) return o.sts(); wb_attribute oa = sp->attribute( &ip->Pointed); if ( !oa) return oa.sts(); replaceClass( sp, oa, &ip->Selected[0]); #endif sts = ldh_AttrRefToName(ip->PointedSession, &ip->Pointed, ldh_eName_VolPath, &name_p, &size); if ( ODD(sts)) { strcpy( name, name_p); strcat( name, ".IoConnect"); sts = ldh_NameToAttrRef( ip->PointedSession, name, &PattrRef); if (ODD(sts)) sts = ldh_WriteAttribute(ip->PointedSession, &PattrRef, &aref, sizeof(aref)); } char msg[500]; if ( ODD(sts)) { pwr_tAName name; char *name_p; int len; sts = ldh_AttrRefToName( ip->PointedSession, &aref, ldh_eName_Hierarchy, &name_p, &len); if ( EVEN(sts)) cdh_ObjidToString( name, aref.Objid, 1); else strcpy( name, name_p); sprintf( msg, "Io connected to: %s", name); ip->wtt->message( 'I', msg); } else { msg_GetMsg( sts, msg, sizeof(msg)); ip->wtt->message( 'E', msg); } return PWRS__SUCCESS; }
static pwr_tStatus trace_get_attr_m4( WGre *gre, vldh_t_node node, char *debug_par, char *object_str, char *attr_str, flow_eTraceType *trace_type, int *inverted) { pwr_tAName aname; pwr_tStatus sts; int size; pwr_sAttrRef *objarp; pwr_sAttrRef objar; char parname[120]; pwr_sTypeDef *tdef; pwr_tTid tid; char *np, *s; *inverted = 0; /* Get the objdid stored in the parameter Object */ switch ( node->ln.cid) { case pwr_cClass_GetAp: strcpy( parname, "ApObject"); break; case pwr_cClass_GetDp: strcpy( parname, "DpObject"); break; default: strcpy( parname, "Object"); } sts = ldh_GetObjectPar( node->hn.wind->hw.ldhses, node->ln.oid, "DevBody", parname, (char **)&objarp, &size); if ( EVEN(sts)) return sts; objar = *objarp; free((char *) objarp); sts = ldh_GetAttrRefTid( node->hn.wind->hw.ldhses, &objar, &tid); if( EVEN(sts) ) return sts; if ( cdh_tidIsCid( tid)) return TRA__NOPAR; /* Get the name of the node */ sts = ldh_AttrRefToName( node->hn.wind->hw.ldhses, &objar, cdh_mNName, &np, &size); if( EVEN(sts)) return sts; strcpy( aname, np); s = strrchr( aname, '.'); if ( !s) return TRA__NOPAR; strcpy( attr_str, s + 1); *s = 0; strcpy( object_str, aname); sts = ldh_GetObjectBody( node->hn.wind->hw.ldhses, cdh_TypeIdToObjid(tid), "SysBody", (void **)&tdef, &size); if ( EVEN(sts)) return sts; switch( tdef->Type) { case pwr_eType_Boolean: *trace_type = flow_eTraceType_Boolean; break; case pwr_eType_Int32: *trace_type = flow_eTraceType_Int32; break; case pwr_eType_Float32: *trace_type = flow_eTraceType_Float32; break; default: *trace_type = flow_eTraceType_Int32; break; } free((char *) tdef); return TRA__SUCCESS; }
WCrrGtk::WCrrGtk( GtkWidget *xa_parent_wid, void *xa_parent_ctx, ldh_tSesContext xa_ldhses, pwr_sAttrRef *xa_objar, int xa_advanced_user, int *xa_sts) : WCrr( xa_parent_ctx, xa_ldhses, xa_objar, xa_advanced_user, xa_sts), parent_wid(xa_parent_wid) { int sts; char *namep; int size; pwr_tAName title; *xa_sts = ldh_AttrRefToName( xa_ldhses, &objar, cdh_mNName, &namep, &size); if ( EVEN(*xa_sts)) return; strncpy( title, namep, sizeof(title)); toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, "default-height", 420, "default-width", 600, "title", CoWowGtk::convert_utf8(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(action_inputfocus), 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_from_stock(GTK_STOCK_PRINT, accel_g); 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_exit), 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(CoWowGtk::translate_utf8("_File")); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file); gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu)); // Functions entry GtkWidget *functions_open_plc = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("Open _Program")); g_signal_connect( functions_open_plc, "activate", G_CALLBACK(activate_openplc), this); gtk_widget_add_accelerator( functions_open_plc, "activate", accel_g, 'l', GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE); GtkMenu *func_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), functions_open_plc); GtkWidget *functions = gtk_menu_item_new_with_mnemonic(CoWowGtk::translate_utf8("_Functions")); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions); gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(func_menu)); // Help entry GtkWidget *help_help = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP, accel_g); g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this); GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help); 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)); xcrrnav = new WAttNavGtk( (void *)this, wattnav_eType_CrossRef, vbox, "Plant", xa_ldhses, objar, 0, xa_advanced_user, 1, wb_eUtility_AttributeEditor, &brow_widget, &sts); // xcrrnav->popup_menu_cb = &xcrr_popup_menu_cb; // xcrrnav->start_trace_cb = &xcrr_start_trace_cb; // xcrrnav->close_cb = &xcrr_close_cb; gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0); gtk_box_pack_end( GTK_BOX(vbox), GTK_WIDGET(brow_widget), TRUE, TRUE, 0); gtk_container_add( GTK_CONTAINER(toplevel), vbox); gtk_widget_show_all( toplevel); *xa_sts = XATT__SUCCESS; }
pwr_tStatus wb_bck_list::diff( wb_bck_list *lp, char *outfile) { pwr_tFileName fname; FILE *fout; pwr_tStatus sts; int diff_cnt = 0; dcli_translate_filename( fname, outfile); fout = fopen( fname, "w"); if ( !fout) return LDH__NOSUCHFILE; if ( lp) fprintf( fout, "Backup difference: 1: %s, 2: %s\n", m_filename, lp->m_filename); else fprintf( fout, "Backup difference: 1: %s, 2: Workbench\n", m_filename); bck_sItem *ip = m_first; while (ip) { char str[1024]; char str2[1024]; pwr_eType atype; char *anamep; int size; sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size); if ( EVEN(sts)) return sts; sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype); if ( ODD(sts)) { void *value2p; bck_sItem *ip2 = lp->find( &ip->aref); if ( ip2) { value2p = ip2->valuep; int is_equal = 0; switch ( atype) { case pwr_eType_String: case pwr_eType_Text: is_equal = strcmp( (const char *)value2p, (const char *)ip->valuep) == 0 ? 1 : 0; break; default: is_equal = memcmp( value2p, ip->valuep, ip->size) == 0 ? 1 : 0; } if ( is_equal) { ip = ip->next; continue; } sts = cdh_AttrValueToString( atype, value2p, str2, sizeof(str2)); if ( EVEN(sts)) strcpy( str2, "-"); } else strcpy( str2, "-"); sts = cdh_AttrValueToString( atype, ip->valuep, str, sizeof(str)); if ( EVEN(sts)) strcpy( str, "-"); fprintf( fout, "%s\n", anamep); fprintf( fout, "1> %s\n", str); fprintf( fout, "2> %s\n", str2); diff_cnt++; } ip = ip->next; } if ( diff_cnt) fprintf( fout, "%d differences found\n", diff_cnt); else fprintf( fout, "No differences found\n"); fclose( fout); return LDH__SUCCESS; }
pwr_tStatus wb_bck_list::read_db( wb_bck_list *lp) { pwr_eType atype; char *anamep; int size; void *valuep; pwr_tAName aname; pwr_tAttrRef aref; pwr_tCid cid; char *s; pwr_tStatus sts; m_type = bck_eType_Wb; bck_sItem *ip = lp->m_first; while (ip) { sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size); if ( EVEN(sts)) return sts; sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype); if ( ODD(sts)) { // Read value from database strncpy( aname, anamep, sizeof(aname)); if ( (s = strrchr( aname, '.')) && strcmp( s, ".ActualValue") == 0) { *s = 0; sts = ldh_NameToAttrRef( m_ldhses, aname, &aref); if ( EVEN(sts)) return sts; sts = ldh_GetAttrRefTid( m_ldhses, &aref, &cid); if ( EVEN(sts)) return sts; switch ( cid) { case pwr_cClass_Ao: case pwr_cClass_Do: case pwr_cClass_Io: case pwr_cClass_Av: case pwr_cClass_Dv: case pwr_cClass_Iv: // Read InitValue instead of ActualValue strcat( aname, ".InitialValue"); sts = ldh_NameToAttrRef( m_ldhses, aname, &aref); if ( EVEN(sts)) return sts; valuep = malloc(ip->size); sts = ldh_ReadAttribute( m_ldhses, &aref, valuep, ip->size); break; default: valuep = malloc(ip->size); sts = ldh_ReadAttribute( m_ldhses, &ip->aref, valuep, ip->size); } } else { valuep = malloc(ip->size); sts = ldh_ReadAttribute( m_ldhses, &ip->aref, valuep, ip->size); } } add( &ip->aref, valuep, ip->size); free( valuep); ip = ip->next; } return LDH__SUCCESS; }
WAttTextGtk::WAttTextGtk(GtkWidget* wa_parent_wid, void* wa_parent_ctx, ldh_tSesContext wa_ldhses, pwr_sAttrRef wa_aref, int wa_editmode, pwr_tStatus* status) : WAttText(wa_parent_ctx, wa_ldhses, wa_aref, wa_editmode, status), parent_wid(wa_parent_wid), toplevel(0), init(1) { int sts; int size; char* namep; if (EVEN(*status)) return; sts = ldh_AttrRefToName(ldhses, &aref, ldh_eName_Hierarchy, &namep, &size); if (EVEN(sts)) { *status = sts; return; } toplevel = (GtkWidget*)g_object_new(GTK_TYPE_WINDOW, "default-height", 700, "default-width", 800, "title", CoWowGtk::convert_utf8(namep), 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(action_inputfocus), this); CoWowGtk::SetWindowIcon(toplevel); // 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_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g); g_signal_connect(file_close, "activate", G_CALLBACK(activate_exit), this); GtkWidget* file_save = gtk_image_menu_item_new_from_stock(GTK_STOCK_SAVE, accel_g); g_signal_connect(file_save, "activate", G_CALLBACK(activate_save), this); GtkWidget* file_saveandclose = gtk_menu_item_new_with_mnemonic("S_ave and close"); g_signal_connect( file_saveandclose, "activate", G_CALLBACK(activate_saveandclose), this); gtk_widget_add_accelerator(file_saveandclose, "activate", accel_g, 't', GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE); GtkMenu* file_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_save); gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_saveandclose); gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close); GtkWidget* file = gtk_menu_item_new_with_mnemonic("_File"); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file); gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu)); // Edit entry GtkWidget* edit_copy = gtk_image_menu_item_new_from_stock(GTK_STOCK_COPY, accel_g); g_signal_connect(edit_copy, "activate", G_CALLBACK(activate_copy), this); GtkWidget* edit_cut = gtk_image_menu_item_new_from_stock(GTK_STOCK_CUT, accel_g); g_signal_connect(edit_cut, "activate", G_CALLBACK(activate_cut), this); GtkWidget* edit_paste = gtk_image_menu_item_new_from_stock(GTK_STOCK_PASTE, accel_g); g_signal_connect(edit_paste, "activate", G_CALLBACK(activate_paste), this); GtkMenu* edit_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_copy); gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_cut); gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_paste); GtkWidget* edit = gtk_menu_item_new_with_mnemonic("_Edit"); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), edit); gtk_menu_item_set_submenu(GTK_MENU_ITEM(edit), GTK_WIDGET(edit_menu)); // Help entry GtkWidget* help_help = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP, accel_g); g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this); GtkMenu* help_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help); GtkWidget* help = gtk_menu_item_new_with_mnemonic("_Help"); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help); gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu)); if (((WUtility*)parent_ctx)->utype == wb_eUtility_WNav) parent_ctx = ((WNav*)parent_ctx)->parent_ctx; utility = ((WUtility*)parent_ctx)->utype; textbuffer = gtk_text_buffer_new(NULL); g_signal_connect_after( textbuffer, "insert-text", G_CALLBACK(action_text_inserted), this); g_signal_connect_after( textbuffer, "changed", G_CALLBACK(action_text_changed), this); textview = gtk_text_view_new_with_buffer(textbuffer); GtkWidget* viewport = gtk_viewport_new(NULL, NULL); GtkWidget* scrolledwindow = gtk_scrolled_window_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(viewport), textview); gtk_container_add(GTK_CONTAINER(scrolledwindow), viewport); button_ok = gtk_button_new_with_label("Ok"); gtk_widget_set_size_request(button_ok, 70, 25); g_signal_connect(button_ok, "clicked", G_CALLBACK(activate_ok), this); button_apply = gtk_button_new_with_label("Apply"); gtk_widget_set_size_request(button_apply, 70, 25); g_signal_connect(button_apply, "clicked", G_CALLBACK(activate_apply), this); button_cancel = gtk_button_new_with_label("Cancel"); gtk_widget_set_size_request(button_cancel, 70, 25); g_signal_connect(button_cancel, "clicked", G_CALLBACK(activate_cancel), this); GtkWidget* hboxbuttons = gtk_hbox_new(TRUE, 40); gtk_box_pack_start(GTK_BOX(hboxbuttons), button_ok, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hboxbuttons), button_apply, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(hboxbuttons), button_cancel, FALSE, FALSE, 0); msg_label = gtk_label_new(""); gtk_widget_set_size_request(msg_label, -1, 25); vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), scrolledwindow, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), hboxbuttons, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox), msg_label, FALSE, FALSE, 5); gtk_container_add(GTK_CONTAINER(toplevel), vbox); gtk_widget_show_all(toplevel); if (utility == wb_eUtility_Wtt) { ((Wtt*)parent_ctx) ->register_utility((void*)this, wb_eUtility_AttrTextEditor); } char* value; ldh_sAttrRefInfo ainfo; sts = ldh_GetAttrRefInfo(ldhses, &aref, &ainfo); if (EVEN(sts)) { *status = sts; return; } char* s = strchr(namep, '.'); if (!s) return; strncpy(aname, s + 1, sizeof(aname)); sts = ldh_GetObjectPar( ldhses, aref.Objid, "DevBody", aname, (char**)&value, &size); if (EVEN(sts)) { *status = sts; return; } input_max_length = ainfo.size - 1; GtkTextIter start_iter, end_iter; gtk_text_buffer_get_start_iter(textbuffer, &start_iter); gtk_text_buffer_get_end_iter(textbuffer, &end_iter); gtk_text_buffer_delete(textbuffer, &start_iter, &end_iter); gtk_text_buffer_get_start_iter(textbuffer, &start_iter); char* textutf8 = g_convert(value, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL); gtk_text_buffer_insert(textbuffer, &start_iter, textutf8, -1); g_free(textutf8); free(value); if (!editmode) { gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview), FALSE); } wow = new CoWowGtk(toplevel); init = 0; }
WAttGtk::WAttGtk( GtkWidget *wa_parent_wid, void *wa_parent_ctx, ldh_tSesContext wa_ldhses, pwr_sAttrRef wa_aref, int wa_editmode, int wa_advanced_user, int wa_display_objectname) : WAtt(wa_parent_ctx,wa_ldhses,wa_aref,wa_editmode,wa_advanced_user, wa_display_objectname), parent_wid(wa_parent_wid) { int sts; int size; char *namep; sts = ldh_AttrRefToName( ldhses, &aref, ldh_eName_Hierarchy, &namep, &size); if ( EVEN(sts)) return; toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, "default-height", 570, "default-width", 410, "title", CoWowGtk::convert_utf8(namep), 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(action_inputfocus), 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_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g); g_signal_connect(file_close, "activate", G_CALLBACK(activate_exit), this); GtkWidget *file_print = gtk_image_menu_item_new_from_stock(GTK_STOCK_PRINT, accel_g); g_signal_connect(file_print, "activate", G_CALLBACK(activate_print), 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)); // Functions entry GtkWidget *func_changevalue = gtk_menu_item_new_with_mnemonic( "_Change Value"); g_signal_connect( func_changevalue, "activate", G_CALLBACK(activate_change_value), this); gtk_widget_add_accelerator( func_changevalue, "activate", accel_g, 'q', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); GtkWidget *func_close_changeval = gtk_menu_item_new_with_mnemonic( "C_lose Change Value"); g_signal_connect( func_close_changeval, "activate", G_CALLBACK(activate_close_changeval), this); gtk_widget_add_accelerator( func_close_changeval, "activate", accel_g, 't', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); GtkMenu *func_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_changevalue); gtk_menu_shell_append(GTK_MENU_SHELL(func_menu), func_close_changeval); GtkWidget *functions = gtk_menu_item_new_with_mnemonic("_Functions"); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions); gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(func_menu)); // Help entry GtkWidget *help_help = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP, accel_g); g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this); GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help); GtkWidget *help = gtk_menu_item_new_with_mnemonic("_Help"); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help); gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu)); pane = gtk_vpaned_new(); if ( ((WUtility *)parent_ctx)->utype == wb_eUtility_WNav) parent_ctx = ((WNav *)parent_ctx)->parent_ctx; utility = ((WUtility *)parent_ctx)->utype; wattnav = new WAttNavGtk( (void *)this, wattnav_eType_Object, pane, "Plant", ldhses, aref, wa_editmode, wa_advanced_user, wa_display_objectname, utility, &brow_widget, &sts); ((WAttNav *)wattnav)->message_cb = &WAtt::message_cb; ((WAttNav *)wattnav)->change_value_cb = &WAtt::change_value_cb; GtkWidget *statusbar = gtk_hbox_new( FALSE, 0); msg_label = gtk_label_new( ""); gtk_widget_set_size_request( msg_label, -1, 25); cmd_prompt = gtk_label_new( "value > "); gtk_widget_set_size_request( cmd_prompt, -1, 25); cmd_entry = new CoWowEntryGtk( &value_recall); cmd_entry->set_hide_on_esc(true); cmd_input = cmd_entry->widget(); gtk_widget_set_size_request( cmd_input, -1, 25); g_signal_connect( cmd_input, "activate", G_CALLBACK(activate_cmd_input), this); g_signal_connect( cmd_input, "hide", G_CALLBACK(hide_cmd_input), this); gtk_box_pack_start( GTK_BOX(statusbar), msg_label, FALSE, FALSE, 0); gtk_box_pack_start( GTK_BOX(statusbar), cmd_prompt, FALSE, FALSE, 0); gtk_box_pack_start( GTK_BOX(statusbar), cmd_input, TRUE, TRUE, 0); gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0); gtk_box_pack_end( GTK_BOX(vbox), GTK_WIDGET(pane), TRUE, TRUE, 0); gtk_paned_pack1( GTK_PANED(pane), GTK_WIDGET(brow_widget), TRUE, TRUE); gtk_paned_pack2( GTK_PANED(pane), GTK_WIDGET(statusbar), FALSE, TRUE); gtk_container_add( GTK_CONTAINER(toplevel), vbox); cmd_scrolled_buffer = gtk_text_buffer_new( NULL); g_signal_connect_after( cmd_scrolled_buffer, "insert-text", G_CALLBACK(action_text_inserted), this); cmd_scrolledtextview = gtk_text_view_new_with_buffer( cmd_scrolled_buffer); GtkWidget *viewport = gtk_viewport_new( NULL, NULL); GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL); gtk_container_add( GTK_CONTAINER(viewport), cmd_scrolledtextview); gtk_container_add( GTK_CONTAINER(scrolledwindow), viewport); cmd_scrolled_ok = gtk_button_new_with_label( "Ok"); gtk_widget_set_size_request( cmd_scrolled_ok, 70, 25); g_signal_connect( cmd_scrolled_ok, "clicked", G_CALLBACK(activate_cmd_scrolled_ok), this); cmd_scrolled_ca = gtk_button_new_with_label( "Cancel"); gtk_widget_set_size_request( cmd_scrolled_ca, 70, 25); g_signal_connect( cmd_scrolled_ca, "clicked", G_CALLBACK(activate_cmd_scrolled_ca), this); GtkWidget *hboxbuttons = gtk_hbox_new( TRUE, 40); gtk_box_pack_start( GTK_BOX(hboxbuttons), cmd_scrolled_ok, FALSE, FALSE, 0); gtk_box_pack_end( GTK_BOX(hboxbuttons), cmd_scrolled_ca, FALSE, FALSE, 0); cmd_scrolledinput = gtk_vbox_new( FALSE, 0); gtk_box_pack_start( GTK_BOX(cmd_scrolledinput), scrolledwindow, TRUE, TRUE, 0); gtk_box_pack_start( GTK_BOX(cmd_scrolledinput), hboxbuttons, FALSE, FALSE, 5); gtk_box_pack_start( GTK_BOX(statusbar), cmd_scrolledinput, TRUE, TRUE, 0); gtk_widget_show_all( toplevel); g_object_set( cmd_prompt, "visible", FALSE, NULL); g_object_set( cmd_input, "visible", FALSE, NULL); g_object_set( cmd_scrolledinput, "visible", FALSE, NULL); int w, h; gdk_drawable_get_size( pane->window, &w, &h); gtk_paned_set_position( GTK_PANED(pane), h - 50); if ( utility == wb_eUtility_Wtt) { ((Wtt *)parent_ctx)->register_utility( (void *) this, wb_eUtility_AttributeEditor); } }