@@ -3113,6 +3113,8 @@ private void AddAttributeData( AttributeFamilyType attribute, UANode uaNode )
31133113
31143114 AddEnumerationFieldDefinition ( attribute , uaNode ) ;
31153115
3116+ AddOptionSetFieldDefintion ( attribute , uaNode ) ;
3117+
31163118 AttributeType nodeIdAttribute = AddModifyAttribute ( attribute . Attribute , "NodeId" , "NodeId" ,
31173119 new Variant ( uaNode . DecodedNodeId ) ) ;
31183120
@@ -3211,32 +3213,16 @@ private void AddStructureFieldDefinition( AttributeFamilyType attribute, UANode
32113213 RemoveUnwantedAttribute ( structureFieldAttribute , "MaxStringLength" ) ;
32123214 }
32133215
3214- if ( field . Description != null && field . Description . Length > 0 )
3215- {
3216- List < Variant > localizedTextList = new List < Variant > ( field . Description . Length ) ;
3217- foreach ( NodeSet . LocalizedText description in field . Description )
3218- {
3219- localizedTextList . Add (
3220- new Variant (
3221- new LocalizedText ( description . Locale , description . Value ) ) ) ;
3222- }
3223- Variant localizedTextArray = new Variant ( localizedTextList ) ;
3216+ AttributeType descriptionCreated = AddLocalizedTextArrayAttribute (
3217+ structureFieldAttribute ,
3218+ "Description" ,
3219+ field . Description ) ;
32243220
3225- LocalizedText localizedText = new LocalizedText (
3226- field . Description [ 0 ] . Locale , field . Description [ 0 ] . Value ) ;
3227- AddModifyAttribute ( structureFieldAttribute . Attribute ,
3228- "Description" , "LocalizedText" , localizedTextArray ,
3229- bListOf : true ) ;
3230- RemoveUnwantedAttribute ( structureFieldAttribute . Attribute [ "Description" ] ,
3231- "StructureFieldDefinition" ) ;
3232- }
3233- else if ( structureFieldAttribute . Attribute [ "Description" ] != null )
3221+ if ( descriptionCreated != null )
32343222 {
3235- RemoveUnwantedAttribute ( structureFieldAttribute , "Description ") ;
3223+ RemoveUnwantedAttribute ( descriptionCreated , "StructureFieldDefinition ") ;
32363224 }
32373225
3238-
3239-
32403226 // Remove the NodeId from the structure Field
32413227 AttributeType nodeIdAttribute = structureFieldAttribute . Attribute [ "DataType" ] ;
32423228 if ( nodeIdAttribute != null )
@@ -3297,8 +3283,27 @@ private void AddEnumerationFieldDefinition(AttributeFamilyType attribute, UANode
32973283 enumValues . DecodedValue , bListOf : true ) ;
32983284 if ( added != null )
32993285 {
3286+ // Remove empty values
33003287 RemoveNodeIdsFromDefinition ( added ) ;
33013288
3289+ foreach ( AttributeType arrayElement in added . Attribute )
3290+ {
3291+ List < string > toBeRemoved = new List < string > ( ) ;
3292+
3293+ foreach ( AttributeType parameter in arrayElement . Attribute )
3294+ {
3295+ if ( string . IsNullOrEmpty ( parameter . Value ) )
3296+ {
3297+ toBeRemoved . Add ( parameter . Name ) ;
3298+ }
3299+ }
3300+
3301+ foreach ( string removeAttribute in toBeRemoved )
3302+ {
3303+ RemoveUnwantedAttribute ( arrayElement , removeAttribute ) ;
3304+ }
3305+ }
3306+
33023307 AttributeType nodeIdAttribute = AddModifyAttribute ( added . Attribute ,
33033308 "NodeId" , "NodeId" , new Variant ( EnumValuesPropertyId ) ) ;
33043309
@@ -3327,30 +3332,14 @@ private void AddEnumerationFieldDefinition(AttributeFamilyType attribute, UANode
33273332 fieldAttribute . RecreateAttributeInstance ( enumFieldSource ) ;
33283333 fieldAttribute . Name = fieldDefinition . Name ;
33293334
3330- AddModifyAttribute ( fieldAttribute . Attribute ,
3331- "Name" , "String" , new Variant ( fieldDefinition . Name ) ) ;
3335+ // Remove the Name
3336+ RemoveUnwantedAttribute ( fieldAttribute , "Name" ) ;
33323337
3333- LocalizedText descriptionLocalizedText = new LocalizedText ( "" ) ;
3338+ // Description is an array of LocalizedText
33343339
3335- if ( fieldDefinition . Description != null && fieldDefinition . Description . Length > 0 )
3336- {
3337- descriptionLocalizedText = new LocalizedText (
3338- fieldDefinition . Description [ 0 ] . Locale , fieldDefinition . Description [ 0 ] . Value ) ;
3339- }
3340+ AddLocalizedTextArrayAttribute ( fieldAttribute , "Description" , fieldDefinition . Description ) ;
33403341
3341- AddModifyAttribute ( fieldAttribute . Attribute , "Description" , "LocalizedText" ,
3342- new Variant ( descriptionLocalizedText ) ) ;
3343-
3344- LocalizedText displayNameLocalizedText = new LocalizedText ( "" ) ;
3345-
3346- if ( fieldDefinition . DisplayName != null && fieldDefinition . DisplayName . Length > 0 )
3347- {
3348- displayNameLocalizedText = new LocalizedText (
3349- fieldDefinition . DisplayName [ 0 ] . Locale , fieldDefinition . DisplayName [ 0 ] . Value ) ;
3350- }
3351-
3352- AddModifyAttribute ( fieldAttribute . Attribute , "DisplayName" , "LocalizedText" ,
3353- new Variant ( displayNameLocalizedText ) ) ;
3342+ AddLocalizedTextArrayAttribute ( fieldAttribute , "DisplayName" , fieldDefinition . DisplayName ) ;
33543343
33553344 AddModifyAttribute ( fieldAttribute . Attribute ,
33563345 "Value" , "Int32" , new Variant ( fieldDefinition . Value ) ) ;
@@ -3366,6 +3355,56 @@ private void AddEnumerationFieldDefinition(AttributeFamilyType attribute, UANode
33663355 }
33673356 }
33683357
3358+ private void AddOptionSetFieldDefintion ( AttributeFamilyType attribute , UANode uaNode )
3359+ {
3360+ UADataType optionSetNode = uaNode as UADataType ;
3361+ if ( optionSetNode != null &&
3362+ optionSetNode . Definition != null &&
3363+ optionSetNode . Definition . IsOptionSet == true )
3364+ {
3365+ if ( optionSetNode . Definition . Field != null &&
3366+ optionSetNode . Definition . Field . Length > 0 )
3367+ {
3368+ string path = BuildLibraryReference ( ATLPrefix , Opc . Ua . Namespaces . OpcUa , "ListOfOptionSet" ) ;
3369+ AttributeFamilyType optionSetFieldDefinition = m_cAEXDocument . FindByPath ( path ) as AttributeFamilyType ;
3370+
3371+ AttributeType optionSetFields = new AttributeType (
3372+ new System . Xml . Linq . XElement ( defaultNS + "Attribute" ) ) ;
3373+
3374+ optionSetFields . RecreateAttributeInstance ( optionSetFieldDefinition as AttributeFamilyType ) ;
3375+ optionSetFields . Name = "OptionSetFieldDefinition" ;
3376+ optionSetFields . AdditionalInformation . Append ( OpcUaTypeOnly ) ;
3377+
3378+ string optionSetPath = BuildLibraryReference ( ATLPrefix , Opc . Ua . Namespaces . OpcUa , "OptionSet" ) ;
3379+ AttributeFamilyType optionSetSource = m_cAEXDocument . FindByPath ( optionSetPath ) as AttributeFamilyType ;
3380+
3381+ foreach ( DataTypeField fieldDefinition in optionSetNode . Definition . Field )
3382+ {
3383+ AttributeType fieldAttribute = new AttributeType ( new System . Xml . Linq . XElement ( defaultNS + "Attribute" ) ) ;
3384+
3385+ fieldAttribute . RecreateAttributeInstance ( optionSetSource ) ;
3386+ fieldAttribute . Name = fieldDefinition . Name ;
3387+
3388+ AttributeType valueAttribute = AddModifyAttribute ( fieldAttribute . Attribute ,
3389+ "Value" , "Int32" , new Variant ( fieldDefinition . Value ) ) ;
3390+
3391+ RemoveUnwantedAttribute ( valueAttribute , "NodeId" ) ;
3392+ RemoveUnwantedAttribute ( fieldAttribute , "ValidBits" ) ;
3393+ RemoveUnwantedAttribute ( fieldAttribute , "NodeId" ) ;
3394+
3395+ optionSetFields . Attribute . Insert ( fieldAttribute , false , true ) ;
3396+ }
3397+
3398+ attribute . Attribute . Insert ( optionSetFields , false , true ) ;
3399+ }
3400+ else
3401+ {
3402+ bool unexpected = true ;
3403+ }
3404+ }
3405+ }
3406+
3407+
33693408 private AttributeFamilyType ProcessDataType ( NodeSet . UANode node )
33703409 {
33713410 var typeNode = node as MarkdownProcessor . NodeSet . UADataType ;
@@ -3400,6 +3439,49 @@ private AttributeFamilyType ProcessDataType(NodeSet.UANode node)
34003439
34013440 return added ;
34023441 }
3442+
3443+ private AttributeType AddLocalizedTextArrayAttribute ( AttributeType attribute ,
3444+ string name , NodeSet . LocalizedText [ ] texts )
3445+ {
3446+ AttributeType created = null ;
3447+
3448+ // Currently for Field Definitions
3449+ Variant localizedTextArray = LocalizedTextArrayAsVariant ( texts ) ;
3450+ if ( localizedTextArray . TypeInfo != null &&
3451+ localizedTextArray . TypeInfo . BuiltInType != null &&
3452+ localizedTextArray . TypeInfo . BuiltInType == BuiltInType . Variant )
3453+ {
3454+ created = AddModifyAttribute ( attribute . Attribute , name , "LocalizedText" ,
3455+ localizedTextArray , bListOf : true ) ;
3456+ }
3457+ else
3458+ {
3459+ RemoveUnwantedAttribute ( attribute , name ) ;
3460+ }
3461+
3462+ return created ;
3463+ }
3464+
3465+ private Variant LocalizedTextArrayAsVariant ( NodeSet . LocalizedText [ ] array )
3466+ {
3467+ Variant localizedTextArray = new Variant ( ) ;
3468+
3469+ if ( array != null && array . Length >= 0 )
3470+ {
3471+ List < Variant > localizedTextList = new List < Variant > ( array . Length ) ;
3472+ foreach ( NodeSet . LocalizedText text in array )
3473+ {
3474+ localizedTextList . Add (
3475+ new Variant (
3476+ new LocalizedText ( text . Locale , text . Value ) ) ) ;
3477+ }
3478+
3479+ localizedTextArray = new Variant ( localizedTextList ) ;
3480+ }
3481+
3482+ return localizedTextArray ;
3483+ }
3484+
34033485 #endregion
34043486
34053487 #region INSTANCE
0 commit comments