Commit 2657bab8 authored by claes's avatar claes

Extern function to format selection

parent 7a35af90
#include <string.h>
#include "wb_wnav_selformat.h"
typedef struct {char *TypeStr;
pwr_eType Type;
pwr_tInt16 Size;
} wnav_sTypeStr;
static int wnav_type_to_string(
pwr_eType type,
char *type_buf,
int *size)
{
int i;
static const wnav_sTypeStr type_table[] = {
{"Boolean", pwr_eType_Boolean, sizeof(pwr_tBoolean)},
{"Float32", pwr_eType_Float32, sizeof(pwr_tFloat32)},
{"Float64", pwr_eType_Float64, sizeof(pwr_tFloat64)},
{"Char", pwr_eType_Char, sizeof(pwr_tChar)},
{"Int8", pwr_eType_Int8, sizeof(pwr_tInt8)},
{"Int16", pwr_eType_Int16, sizeof(pwr_tInt16)},
{"Int32", pwr_eType_Int32, sizeof(pwr_tInt32)},
{"UInt8", pwr_eType_UInt8, sizeof(pwr_tUInt8)},
{"UInt16", pwr_eType_UInt16, sizeof(pwr_tUInt16)},
{"UInt32", pwr_eType_UInt32, sizeof(pwr_tUInt32)},
{"Objid", pwr_eType_Objid, sizeof(pwr_tObjid)},
{"Time", pwr_eType_Time, sizeof(pwr_tTime)},
{"DeltaTime", pwr_eType_DeltaTime, sizeof(pwr_tDeltaTime)},
{"AttrRef", pwr_eType_AttrRef, sizeof(pwr_sAttrRef)}
};
for (i = 0; i < int(sizeof(type_table)/sizeof(type_table[0])); i++)
{
if ( type_table[i].Type == type)
{
strcpy(type_buf, type_table[i].TypeStr);
if (size)
*size = type_table[i].Size;
return 1;
}
}
if (type == pwr_eType_String)
{
strcpy(type_buf, "String");
if (size)
*size = 1; /* This is not the real size */
return 1;
}
return 0;
}
pwr_tBoolean wnav_format_selection( ldh_tSesContext ldhses, pwr_sAttrRef attrref,
pwr_tBoolean is_class, pwr_tBoolean is_attr,
int select_syntax, int select_volume,
int select_attr, int select_type, char *buff)
{
pwr_sAttrRef attr_ref;
int ret_len, i, j, size, sts;
char name[256];
char attr_name[128], type_buff[80];
pwr_tClassId classid, body_class;
pwr_sGraphPlcNode *graph_body;
ldh_sParDef attr_def;
char *p1, *p2;
char hyphen[8], dot[8], colon[8];
char *name_ptr;
pwr_tObjid object = attrref.Objid;
char *s;
if ( select_syntax == wnav_eSelectionMode_Extern && !select_attr) {
sts = ldh_ObjidToName( ldhses, object, ldh_eName_Objid,
name, sizeof(name), &ret_len);
if (EVEN(sts)) return FALSE;
strcpy( buff, name);
return TRUE;
}
else if ( select_syntax == wnav_eSelectionMode_Extern && select_attr) {
sts = ldh_ObjidToName( ldhses, object, ldh_eName_Default,
name, sizeof(name), &ret_len);
if (EVEN(sts)) return FALSE;
}
else if ( select_volume) {
sts = ldh_ObjidToName(ldhses, object, ldh_eName_VolPath,
name, sizeof(name), &ret_len);
if (EVEN(sts)) return FALSE;
}
else {
sts = ldh_ObjidToName(ldhses, object, ldh_eName_Hierarchy,
name, sizeof(name), &ret_len);
if (EVEN(sts)) return FALSE;
}
if (select_syntax == wnav_eSelectionMode_GMS) {
strcpy(hyphen, "\\-");
strcpy(dot, "\\.");
strcpy(colon, "\\:");
}
else {
strcpy(hyphen, "-");
strcpy(dot, ".");
strcpy(colon, ":");
}
for (i = 0, j = 0; i < ret_len + 1; i++) {
if (name[i] == '-') {
strcpy( &buff[j], hyphen);
j += strlen(hyphen);
}
else if (name[i] == ':') {
strcpy( &buff[j], colon);
j += strlen(colon);
}
else {
buff[j] = name[i];
j++;
}
}
// Fetch and add attribute name if necessary
if (select_attr && !is_class) {
sts = ldh_GetObjectClass(ldhses, object, &classid);
if ( EVEN(sts)) return FALSE;
if ( ! is_attr) {
// Get the debugparameter if there is one, else add ActualValue
sts = ldh_GetClassBody(ldhses, classid,
"GraphPlcNode", &body_class, (char **)&graph_body, &size);
if ( ODD(sts) )
strcpy(attr_name, graph_body->debugpar);
else
strcpy(attr_name, "ActualValue");
strcat(name, ".");
strcat(name, attr_name);
// Check if attribute exists
sts = ldh_NameToAttrRef(ldhses, name, &attr_ref);
if (ODD(sts)) {
if (select_syntax == wnav_eSelectionMode_Extern && select_attr) {
sts = ldh_AttrRefToName(ldhses, &attr_ref,
ldh_eName_ArefExport,
&name_ptr, &ret_len);
if (EVEN(sts)) return FALSE;
strcpy( buff, name_ptr);
return TRUE;
}
}
}
else {
sts = ldh_AttrRefToName(ldhses, &attrref,
ldh_eName_Aref,
&name_ptr, &ret_len);
if ( EVEN(sts)) return FALSE;
if ( (s = strrchr( name_ptr, '.')))
strcpy( attr_name, s + 1);
else
strcpy( attr_name, "");
}
strcat(buff, dot);
strcat(buff, attr_name);
if (select_type) {
// If attribute is an array element
// Get attribute definition for the array.
if ( (p1 = strstr(attr_name, "[")))
*p1 = '\0';
sts = ldh_GetAttrDef(ldhses, classid, "RtBody",
attr_name, &attr_def);
if (EVEN(sts))
sts = ldh_GetAttrDef(ldhses, classid, "SysBody",
attr_name, &attr_def);
if ( ODD(sts) &&
wnav_type_to_string( attr_def.Par->Input.Info.Type, type_buff, NULL)) {
char num[8];
if ( (p2 = strstr(buff, "[")))
*p2 = '\0';
if (attr_def.Par->Input.Info.Type == pwr_eType_String) {
sprintf(num, "%d", attr_def.Par->Input.Info.Size/attr_def.Par->Input.Info.Elements);
strcat(type_buff, num);
}
strcat(buff, "##");
strcat(buff, type_buff);
// Check if array
if (p1) {
sprintf(&buff[strlen(buff)], "#%d",
attr_def.Par->Input.Info.Elements);
*p1 = '[';
strcat(buff, p1);
}
else if ( attr_def.Par->Input.Info.Elements > 1) {
sprintf(&buff[strlen(buff)], "#%d",
attr_def.Par->Input.Info.Elements);
}
}
}
}
if ( select_syntax == wnav_eSelectionMode_Extern && select_attr) {
sts = ldh_NameToAttrRef(ldhses, buff, &attr_ref);
if (EVEN(sts)) return FALSE;
sts = ldh_AttrRefToName( ldhses, &attr_ref,
ldh_eName_ArefExport, &p1, &size);
if (EVEN(sts)) return FALSE;
strcpy( buff, p1);
}
return TRUE;
}
#ifndef wb_wnav_selformat_h
#define wb_wnav_selformat_h
/* wb_wtt.h -- Simple navigator
PROVIEW/R
Copyright (C) 1996 by Comator Process AB.
<Description>. */
#if defined __cplusplus
extern "C" {
#endif
#ifndef pwr_h
# include "pwr.h"
#endif
#ifndef wb_ldh_h
# include "wb_ldh.h"
#endif
// Defines for primary selection mode
typedef enum {
wnav_eSelectionMode_GMS,
wnav_eSelectionMode_Normal,
wnav_eSelectionMode_Extern
} wnav_eSelectionMode;
pwr_tBoolean wnav_format_selection( ldh_tSesContext ldhses, pwr_sAttrRef attrref,
pwr_tBoolean is_class, pwr_tBoolean is_attr,
int select_syntax, int select_volume,
int select_attr, int select_type, char *buff);
#if defined __cplusplus
}
#endif
#endif
...@@ -64,6 +64,7 @@ extern "C" { ...@@ -64,6 +64,7 @@ extern "C" {
#include "wb_env.h" #include "wb_env.h"
#include "wb_wpkg.h" #include "wb_wpkg.h"
#include "co_msgwindow.h" #include "co_msgwindow.h"
#include "wb_wnav_selformat.h"
#define MESSAGE_RETURN_STS(sts)\ #define MESSAGE_RETURN_STS(sts)\
...@@ -82,12 +83,6 @@ extern "C" { ...@@ -82,12 +83,6 @@ extern "C" {
// //
// //
//
typedef struct {char *TypeStr;
pwr_eType Type;
pwr_tInt16 Size;
} wtt_sTypeStr;
static int wtt_get_wbctx( void *ctx, ldh_tWBContext *wbctx); static int wtt_get_wbctx( void *ctx, ldh_tWBContext *wbctx);
static int wtt_set_focus_cb( void *ctx, void *comp); static int wtt_set_focus_cb( void *ctx, void *comp);
...@@ -2683,7 +2678,7 @@ static void wtt_activate_selmode( Widget w, Wtt *wtt, ...@@ -2683,7 +2678,7 @@ static void wtt_activate_selmode( Widget w, Wtt *wtt,
XmToggleButtonSetState( wtt->copy_mode.add_type, 0, 0); XmToggleButtonSetState( wtt->copy_mode.add_type, 0, 0);
wtt->select_type = 0; wtt->select_type = 0;
XtSetSensitive( wtt->copy_mode.add_volume, 1); XtSetSensitive( wtt->copy_mode.add_volume, 1);
wtt->select_syntax = wtt_eSelectionMode_Normal; wtt->select_syntax = wnav_eSelectionMode_Normal;
} }
else if (!strcmp(name,"gmsSyntax")) else if (!strcmp(name,"gmsSyntax"))
{ {
...@@ -2696,7 +2691,7 @@ static void wtt_activate_selmode( Widget w, Wtt *wtt, ...@@ -2696,7 +2691,7 @@ static void wtt_activate_selmode( Widget w, Wtt *wtt,
XmToggleButtonSetState( wtt->copy_mode.extern_syntax, 0, 0); XmToggleButtonSetState( wtt->copy_mode.extern_syntax, 0, 0);
XtSetSensitive( wtt->copy_mode.add_type, 1); XtSetSensitive( wtt->copy_mode.add_type, 1);
XtSetSensitive( wtt->copy_mode.add_volume, 1); XtSetSensitive( wtt->copy_mode.add_volume, 1);
wtt->select_syntax = wtt_eSelectionMode_GMS; wtt->select_syntax = wnav_eSelectionMode_GMS;
} }
else if (!strcmp(name,"externSyntax")) else if (!strcmp(name,"externSyntax"))
{ {
...@@ -2712,7 +2707,7 @@ static void wtt_activate_selmode( Widget w, Wtt *wtt, ...@@ -2712,7 +2707,7 @@ static void wtt_activate_selmode( Widget w, Wtt *wtt,
XtSetSensitive( wtt->copy_mode.add_volume, 0); XtSetSensitive( wtt->copy_mode.add_volume, 0);
wtt->select_type = 0; wtt->select_type = 0;
XmToggleButtonSetState( wtt->copy_mode.add_volume, 0, 0); XmToggleButtonSetState( wtt->copy_mode.add_volume, 0, 0);
wtt->select_syntax = wtt_eSelectionMode_Extern; wtt->select_syntax = wnav_eSelectionMode_Extern;
wtt->select_volume = 0; wtt->select_volume = 0;
} }
else if (!strcmp(name,"addVolume")) else if (!strcmp(name,"addVolume"))
...@@ -3118,51 +3113,6 @@ void wtt_options_hier_tog_cr( Widget w, Wtt *wtt) ...@@ -3118,51 +3113,6 @@ void wtt_options_hier_tog_cr( Widget w, Wtt *wtt)
} /* wtt_options_hier_tog_cr */ } /* wtt_options_hier_tog_cr */
static int wtt_type_to_string(
pwr_eType type,
char *type_buf,
int *size)
{
int i;
static const wtt_sTypeStr type_table[] = {
{"Boolean", pwr_eType_Boolean, sizeof(pwr_tBoolean)},
{"Float32", pwr_eType_Float32, sizeof(pwr_tFloat32)},
{"Float64", pwr_eType_Float64, sizeof(pwr_tFloat64)},
{"Char", pwr_eType_Char, sizeof(pwr_tChar)},
{"Int8", pwr_eType_Int8, sizeof(pwr_tInt8)},
{"Int16", pwr_eType_Int16, sizeof(pwr_tInt16)},
{"Int32", pwr_eType_Int32, sizeof(pwr_tInt32)},
{"UInt8", pwr_eType_UInt8, sizeof(pwr_tUInt8)},
{"UInt16", pwr_eType_UInt16, sizeof(pwr_tUInt16)},
{"UInt32", pwr_eType_UInt32, sizeof(pwr_tUInt32)},
{"Objid", pwr_eType_Objid, sizeof(pwr_tObjid)},
{"Time", pwr_eType_Time, sizeof(pwr_tTime)},
{"DeltaTime", pwr_eType_DeltaTime, sizeof(pwr_tDeltaTime)},
{"AttrRef", pwr_eType_AttrRef, sizeof(pwr_sAttrRef)}
};
for (i = 0; i < int(sizeof(type_table)/sizeof(type_table[0])); i++)
{
if ( type_table[i].Type == type)
{
strcpy(type_buf, type_table[i].TypeStr);
if (size)
*size = type_table[i].Size;
return 1;
}
}
if (type == pwr_eType_String)
{
strcpy(type_buf, "String");
if (size)
*size = 1; /* This is not the real size */
return 1;
}
return 0;
}
static pwr_tBoolean wtt_format_selection( static pwr_tBoolean wtt_format_selection(
void *ctx, void *ctx,
pwr_sAttrRef attrref, pwr_sAttrRef attrref,
...@@ -3173,19 +3123,8 @@ static pwr_tBoolean wtt_format_selection( ...@@ -3173,19 +3123,8 @@ static pwr_tBoolean wtt_format_selection(
wnav_eSelectionFormat format wnav_eSelectionFormat format
) )
{ {
int ret_len, i, j, size, sts; char buff[256];
char name[256];
char buff[256], attr_name[128], type_buff[80];
pwr_tClassId classid, body_class;
pwr_sGraphPlcNode *graph_body;
pwr_sAttrRef attr_ref;
ldh_sParDef attr_def;
char *p1, *p2;
char hyphen[8], dot[8], colon[8];
char *name_ptr;
Wtt *wtt = (Wtt *) ctx; Wtt *wtt = (Wtt *) ctx;
pwr_tObjid object = attrref.Objid;
char *s;
int select_syntax; int select_syntax;
int select_volume, select_attr, select_type; int select_volume, select_attr, select_type;
...@@ -3197,174 +3136,32 @@ static pwr_tBoolean wtt_format_selection( ...@@ -3197,174 +3136,32 @@ static pwr_tBoolean wtt_format_selection(
select_type = wtt->select_type; select_type = wtt->select_type;
break; break;
case wnav_eSelectionFormat_Graph: case wnav_eSelectionFormat_Graph:
select_syntax = wtt_eSelectionMode_Normal; select_syntax = wnav_eSelectionMode_Normal;
select_volume = 0; select_volume = 0;
select_attr = 1; select_attr = 1;
select_type = 1; select_type = 1;
break; break;
case wnav_eSelectionFormat_Objid: case wnav_eSelectionFormat_Objid:
select_syntax = wtt_eSelectionMode_Normal; select_syntax = wnav_eSelectionMode_Normal;
select_volume = 1; select_volume = 1;
select_attr = 0; select_attr = 0;
select_type = 0; select_type = 0;
break; break;
case wnav_eSelectionFormat_Attrref: case wnav_eSelectionFormat_Attrref:
select_syntax = wtt_eSelectionMode_Normal; select_syntax = wnav_eSelectionMode_Normal;
select_volume = 1; select_volume = 1;
select_attr = 1; select_attr = 1;
select_type = 0; select_type = 0;
break; break;
} }
if ( wnav_format_selection( wtt->ldhses, attrref, is_class, is_attr, select_syntax,
if ( select_syntax == wtt_eSelectionMode_Extern && !select_attr) { select_volume, select_attr, select_type, buff)) {
sts = ldh_ObjidToName( wtt->ldhses, object, ldh_eName_Objid, *value_return = XtNewString(buff);
name, sizeof(name), &ret_len); *length_return = strlen(buff) + 1;
if (EVEN(sts)) return FALSE;
*value_return = XtNewString(name);
*length_return = strlen(name) + 1;
return TRUE; return TRUE;
} }
else if ( select_syntax == wtt_eSelectionMode_Extern && select_attr) { return FALSE;
sts = ldh_ObjidToName( wtt->ldhses, object, ldh_eName_Default,
name, sizeof(name), &ret_len);
if (EVEN(sts)) return FALSE;
}
else if ( select_volume) {
sts = ldh_ObjidToName(wtt->ldhses, object, ldh_eName_VolPath,
name, sizeof(name), &ret_len);
if (EVEN(sts)) return FALSE;
}
else {
sts = ldh_ObjidToName(wtt->ldhses, object, ldh_eName_Hierarchy,
name, sizeof(name), &ret_len);
if (EVEN(sts)) return FALSE;
}
if (select_syntax == wtt_eSelectionMode_GMS) {
strcpy(hyphen, "\\-");
strcpy(dot, "\\.");
strcpy(colon, "\\:");
}
else {
strcpy(hyphen, "-");
strcpy(dot, ".");
strcpy(colon, ":");
}
for (i = 0, j = 0; i < ret_len + 1; i++) {
if (name[i] == '-') {
strcpy( &buff[j], hyphen);
j += strlen(hyphen);
}
else if (name[i] == ':') {
strcpy( &buff[j], colon);
j += strlen(colon);
}
else {
buff[j] = name[i];
j++;
}
}
// Fetch and add attribute name if necessary
if (select_attr && !is_class) {
sts = ldh_GetObjectClass(wtt->ldhses, object, &classid);
if ( EVEN(sts)) return FALSE;
if ( ! is_attr) {
// Get the debugparameter if there is one, else add ActualValue
sts = ldh_GetClassBody(wtt->ldhses, classid,
"GraphPlcNode", &body_class, (char **)&graph_body, &size);
if ( ODD(sts) )
strcpy(attr_name, graph_body->debugpar);
else
strcpy(attr_name, "ActualValue");
strcat(name, ".");
strcat(name, attr_name);
// Check if attribute exists
sts = ldh_NameToAttrRef(wtt->ldhses, name, &attr_ref);
if (ODD(sts)) {
if (select_syntax == wtt_eSelectionMode_Extern && select_attr) {
sts = ldh_AttrRefToName(wtt->ldhses, &attr_ref,
ldh_eName_ArefExport,
&name_ptr, &ret_len);
if (EVEN(sts)) return FALSE;
*value_return = XtNewString(name_ptr);
*length_return = strlen(name_ptr) + 1;
return TRUE;
}
}
}
else {
sts = ldh_AttrRefToName(wtt->ldhses, &attrref,
ldh_eName_Aref,
&name_ptr, &ret_len);
if ( EVEN(sts)) return FALSE;
if ( (s = strrchr( name_ptr, '.')))
strcpy( attr_name, s + 1);
else
strcpy( attr_name, "");
}
strcat(buff, dot);
strcat(buff, attr_name);
if (select_type) {
// If attribute is an array element
// Get attribute definition for the array.
if ( (p1 = strstr(attr_name, "[")))
*p1 = '\0';
sts = ldh_GetAttrDef(wtt->ldhses, classid, "RtBody",
attr_name, &attr_def);
if (EVEN(sts))
sts = ldh_GetAttrDef(wtt->ldhses, classid, "SysBody",
attr_name, &attr_def);
if ( ODD(sts) &&
wtt_type_to_string( attr_def.Par->Input.Info.Type, type_buff, NULL)) {
char num[8];
if ( (p2 = strstr(buff, "[")))
*p2 = '\0';
if (attr_def.Par->Input.Info.Type == pwr_eType_String) {
sprintf(num, "%d", attr_def.Par->Input.Info.Size/attr_def.Par->Input.Info.Elements);
strcat(type_buff, num);
}
strcat(buff, "##");
strcat(buff, type_buff);
// Check if array
if (p1) {
sprintf(&buff[strlen(buff)], "#%d",
attr_def.Par->Input.Info.Elements);
*p1 = '[';
strcat(buff, p1);
}
else if ( attr_def.Par->Input.Info.Elements > 1) {
sprintf(&buff[strlen(buff)], "#%d",
attr_def.Par->Input.Info.Elements);
}
}
}
}
if ( select_syntax == wtt_eSelectionMode_Extern && select_attr) {
sts = ldh_NameToAttrRef(wtt->ldhses, buff, &attr_ref);
if (EVEN(sts)) return False;
sts = ldh_AttrRefToName( wtt->ldhses, &attr_ref,
ldh_eName_ArefExport, &p1, &size);
if (EVEN(sts)) return False;
strcpy( buff, p1);
}
*value_return = XtNewString(buff);
*length_return = strlen(buff) + 1;
return TRUE;
} }
int Wtt::get_select_first( pwr_sAttrRef *attrref, int *is_attr) int Wtt::get_select_first( pwr_sAttrRef *attrref, int *is_attr)
......
...@@ -16,6 +16,7 @@ extern "C" { ...@@ -16,6 +16,7 @@ extern "C" {
# include "pwr.h" # include "pwr.h"
#endif #endif
#ifndef flow_std_h #ifndef flow_std_h
#include "flow_std.h" #include "flow_std.h"
#endif #endif
...@@ -70,13 +71,6 @@ typedef enum { ...@@ -70,13 +71,6 @@ typedef enum {
} wtt_eInputMode; } wtt_eInputMode;
// Defines for primary selection mode
typedef enum {
wtt_eSelectionMode_GMS,
wtt_eSelectionMode_Normal,
wtt_eSelectionMode_Extern
} wtt_eSelectionMode;
class WttApplListElem { class WttApplListElem {
public: public:
WttApplListElem( wb_eUtility al_type, void *al_ctx, pwr_tObjid al_objid, WttApplListElem( wb_eUtility al_type, void *al_ctx, pwr_tObjid al_objid,
......
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