@@ -152,6 +152,7 @@ public void CreateAML(string modelPath, string modelName = null )
152152 AutomationMLBaseRoleClassLibType . RoleClassLib ( m_cAEXDocument ) ;
153153 AutomationMLBaseAttributeTypeLibType . AttributeTypeLib ( m_cAEXDocument ) ;
154154 AutomationMLBaseAttributeTypeLibType . AttributeTypeLib ( cAEXDocumentTemp ) ;
155+ AutomationMLInterfaceClassLibType . InterfaceClassLib ( cAEXDocumentTemp ) ;
155156
156157 // process each model in order (with the base UA Model first )
157158
@@ -179,8 +180,10 @@ public void CreateAML(string modelPath, string modelName = null )
179180
180181 AddLibaryHeaderInfo ( m_atl_temp as CAEXBasicObject , modelInfo ) ;
181182
183+ // create the InterfaceClassLibrary
184+ var icl_temp = cAEXDocumentTemp . CAEXFile . InterfaceClassLib . Append ( ICLPrefix + modelInfo . NamespaceUri ) ;
185+ AddLibaryHeaderInfo ( icl_temp as CAEXBasicObject , modelInfo ) ;
182186
183-
184187 // Create the RoleClassLibrary
185188 var rcl_temp = cAEXDocumentTemp . CAEXFile . RoleClassLib . Append ( RCLPrefix + modelInfo . NamespaceUri ) ;
186189 // var rcl_temp = m_cAEXDocument.CAEXFile.RoleClassLib.Append(RCLPrefix + modelInfo.NamespaceUri);
@@ -238,17 +241,34 @@ public void CreateAML(string modelPath, string modelName = null )
238241 atl . AttributeType . Insert ( CreateListOf ( dicEntry . Value ) , false ) ; // insert into the AML document in alpha order
239242 }
240243
244+ foreach ( var refType in SortedReferenceTypes )
245+ {
246+ ProcessReferenceType ( ref icl_temp , refType . Value ) ;
247+ }
248+
249+ // reorder icl_temp an put in the real icl in alpha order
250+
241251 foreach ( var refType in SortedReferenceTypes )
242252 {
243- if ( icl == null )
253+ string iclpath = BuildLibraryReference ( ICLPrefix , modelInfo . NamespaceUri , refType . Key ) ;
254+ InterfaceClassType ict = icl_temp . CAEXDocument . FindByPath ( iclpath ) as InterfaceClassType ;
255+
256+ if ( ict != null )
244257 {
245- // Create the InterfaceClassLibrary
246- icl = m_cAEXDocument . CAEXFile . InterfaceClassLib . Append ( ICLPrefix + modelInfo . NamespaceUri ) ;
247- AddLibaryHeaderInfo ( icl as CAEXBasicObject , modelInfo ) ;
258+
259+ if ( icl == null )
260+ {
261+ // Create the InterfaceClassLibrary
262+ icl = m_cAEXDocument . CAEXFile . InterfaceClassLib . Append ( ICLPrefix + modelInfo . NamespaceUri ) ;
263+ AddLibaryHeaderInfo ( icl as CAEXBasicObject , modelInfo ) ;
264+ }
265+ icl . Insert ( ict , false ) ;
248266 }
249- ProcesReferenceType ( ref icl , refType . Value ) ;
267+
250268 }
251269
270+
271+
252272 foreach ( var obType in SortedObjectTypes )
253273 {
254274 FindOrAddSUC ( ref scl_temp , ref rcl_temp , obType . Value ) ;
@@ -417,22 +437,22 @@ private void AddMetaModelLibraries( CAEXDocument doc)
417437
418438
419439
420- private void AddBaseNodeClassAttributes ( AttributeSequence seq , bool isAbstract )
440+ private void AddBaseNodeClassAttributes ( IClassWithBaseClassReference owner , bool isAbstract )
421441 {
422- AddModifyAttribute ( true , seq , "BrowseName" , "QualifiedName" , Variant . Null ) ;
423- AddModifyAttribute ( true , seq , "DisplayName" , "LocalizedText" , Variant . Null ) ;
442+ AddModifyAttribute ( owner . Attribute , "BrowseName" , "QualifiedName" , Variant . Null ) ;
443+ AddModifyAttribute ( owner . Attribute , "DisplayName" , "LocalizedText" , Variant . Null ) ;
424444
425- var abs = AddModifyAttribute ( true , seq , "IsAbstract" , "Boolean" , Variant . Null ) ;
426- abs . Value = isAbstract ? "true" : "false" ;
445+ var abs = AddModifyAttribute ( owner . Attribute , "IsAbstract" , "Boolean" , isAbstract ) ;
446+ // abs.Value = isAbstract ? "true" : "false";
427447
428- AddModifyAttribute ( true , seq , "Description" , "LocalizedText" , Variant . Null ) ;
429- AddModifyAttribute ( true , seq , "WriteMask" , "AttributeWriteMask" , Variant . Null ) ;
430- AddModifyAttribute ( true , seq , "RolePermissions" , "ListOfRolePermissionType" , Variant . Null ) ;
431- AddModifyAttribute ( true , seq , "AccessRestrictions" , "AccessRestrictionType" , Variant . Null ) ;
448+ AddModifyAttribute ( owner . Attribute , "Description" , "LocalizedText" , Variant . Null ) ;
449+ AddModifyAttribute ( owner . Attribute , "WriteMask" , "AttributeWriteMask" , Variant . Null ) ;
450+ AddModifyAttribute ( owner . Attribute , "RolePermissions" , "ListOfRolePermissionType" , Variant . Null ) ;
451+ AddModifyAttribute ( owner . Attribute , "AccessRestrictions" , "AccessRestrictionType" , Variant . Null ) ;
432452 }
433453
434454
435- private AttributeType AddModifyAttribute ( bool bAdd , AttributeSequence seq , string name , string refDataType , Variant val , bool bListOf = false , string sURI = uaNamespaceURI )
455+ private AttributeType AddModifyAttribute ( AttributeSequence seq , string name , string refDataType , Variant val , bool bListOf = false , string sURI = uaNamespaceURI )
436456 {
437457 string sUADataType = refDataType ;
438458
@@ -450,15 +470,13 @@ private AttributeType AddModifyAttribute(bool bAdd, AttributeSequence seq, strin
450470 var ob = m_cAEXDocument . FindByPath ( path ) ;
451471 var at = ob as AttributeFamilyType ;
452472 AttributeType a ;
453- if ( bAdd == true )
454- a = seq . Append ( name ) ;
455- else
456- a = seq [ name ] ;
457-
473+
474+ a = seq . Append ( name ) ;
475+
458476 a . RecreateAttributeInstance ( at ) ;
459- if ( bListOf == false && val . TypeInfo != null )
477+ if ( bListOf == false && val . TypeInfo != null )
460478 {
461- switch ( val . TypeInfo . BuiltInType ) // TODO -- consider supporting setting values for more complicated types (enums, structures, Qualified Names ...) and arrays
479+ switch ( val . TypeInfo . BuiltInType ) // TODO -- consider supporting setting values for more complicated types (enums, structures, Qualified Names ...) and arrays
462480 {
463481 case BuiltInType . Boolean :
464482 case BuiltInType . Byte :
@@ -477,33 +495,34 @@ private AttributeType AddModifyAttribute(bool bAdd, AttributeSequence seq, strin
477495 case BuiltInType . UInt32 :
478496 case BuiltInType . UInt64 :
479497 case BuiltInType . UInteger :
480- a . Value = val . ToString ( ) ;
481- a . DefaultValue = a . Value ;
498+ a . DefaultAttributeValue = a . AttributeValue = val ;
482499 break ;
483- }
500+ }
484501 }
485-
502+
486503 return a ;
487504 }
488505
489- private AttributeType AddModifyAttribute ( bool bAdd , AttributeSequence seq , string name , NodeId refDataType , Variant val , bool bListOf = false )
506+
507+
508+ private AttributeType AddModifyAttribute ( AttributeSequence seq , string name , NodeId refDataType , Variant val , bool bListOf = false )
490509 {
491510 var DataTypeNode = m_modelManager . FindNode < UANode > ( refDataType ) ;
492511 var sUADataType = DataTypeNode . DecodedBrowseName . Name ;
493512 var sURI = m_modelManager . FindModelUri ( DataTypeNode . DecodedNodeId ) ;
494- return AddModifyAttribute ( bAdd , seq , name , sUADataType , val , bListOf , sURI ) ;
513+ return AddModifyAttribute ( seq , name , sUADataType , val , bListOf , sURI ) ;
495514 }
496515
497- private AttributeType AddModifyAttribute ( bool bAdd , AttributeSequence seq , string name , NodeId refDataType )
516+
517+ private AttributeType AddModifyAttribute ( AttributeSequence seq , string name , NodeId refDataType )
498518 {
499- return AddModifyAttribute ( bAdd , seq , name , refDataType , Variant . Null ) ;
519+ return AddModifyAttribute ( seq , name , refDataType , Variant . Null ) ;
500520 }
501521
502522
503523 private void OverrideBooleanAttribute ( AttributeSequence seq , string AttributeName , Boolean value )
504524 {
505- var at = AddModifyAttribute ( true , seq , AttributeName , "Boolean" , Variant . Null ) ;
506- at . DefaultValue = at . Value = value ? "true" : "false" ;
525+ var at = AddModifyAttribute ( seq , AttributeName , "Boolean" , value ) ;
507526 }
508527
509528
@@ -686,11 +705,11 @@ SystemUnitFamilyType FindOrAddSUC(ref SystemUnitClassLibType scl, ref RoleClassL
686705 var basevar = basenode as NodeSet . UAVariableType ;
687706
688707 if ( varnode . ValueRank != basevar . ValueRank )
689- AddModifyAttribute ( true , rtn . Attribute , "ValueRank" , "Int32" , varnode . ValueRank ) ;
708+ AddModifyAttribute ( rtn . Attribute , "ValueRank" , "Int32" , varnode . ValueRank ) ;
690709 if ( basevar . IsAbstract != varnode . IsAbstract )
691710 OverrideBooleanAttribute ( rtn . Attribute , "IsAbstract" , varnode . IsAbstract ) ;
692711 if ( basevar . DataType != varnode . DataType )
693- AddModifyAttribute ( true , rtn . Attribute , "Value" , varnode . DecodedDataType ) ;
712+ AddModifyAttribute ( rtn . Attribute , "Value" , varnode . DecodedDataType ) ;
694713 break ;
695714
696715 }
@@ -701,21 +720,21 @@ SystemUnitFamilyType FindOrAddSUC(ref SystemUnitClassLibType scl, ref RoleClassL
701720 switch ( refnode . NodeClass )
702721 {
703722 case NodeClass . ObjectType :
704- AddBaseNodeClassAttributes ( rtn . Attribute , false ) ;
705- AddModifyAttribute ( true , rtn . Attribute , "EventNotifier" , "EventNotifierType" , Variant . Null ) ;
723+ AddBaseNodeClassAttributes ( rtn , false ) ;
724+ AddModifyAttribute ( rtn . Attribute , "EventNotifier" , "EventNotifierType" , Variant . Null ) ;
706725 break ;
707726 case NodeClass . VariableType :
708- AddBaseNodeClassAttributes ( rtn . Attribute , true ) ;
709- AddModifyAttribute ( true , rtn . Attribute , "ArrayDimensions" , "ListOfUInt32" , Variant . Null ) ;
710- AddModifyAttribute ( true , rtn . Attribute , "ValueRank" , "Int32" , - 2 ) ;
711- AddModifyAttribute ( true , rtn . Attribute , "Value" , "BaseDataType" , Variant . Null ) ;
712- AddModifyAttribute ( true , rtn . Attribute , "AccessLevel" , "AccessLevelType" , Variant . Null ) ;
713- AddModifyAttribute ( true , rtn . Attribute , "MinimumSamplingInterval" , "Duration" , Variant . Null ) ;
727+ AddBaseNodeClassAttributes ( rtn , true ) ;
728+ AddModifyAttribute ( rtn . Attribute , "ArrayDimensions" , "ListOfUInt32" , Variant . Null ) ;
729+ AddModifyAttribute ( rtn . Attribute , "ValueRank" , "Int32" , - 2 ) ;
730+ AddModifyAttribute ( rtn . Attribute , "Value" , "BaseDataType" , Variant . Null ) ;
731+ AddModifyAttribute ( rtn . Attribute , "AccessLevel" , "AccessLevelType" , Variant . Null ) ;
732+ AddModifyAttribute ( rtn . Attribute , "MinimumSamplingInterval" , "Duration" , Variant . Null ) ;
714733 break ;
715734 case NodeClass . Method :
716- AddBaseNodeClassAttributes ( rtn . Attribute , false ) ;
717- AddModifyAttribute ( true , rtn . Attribute , "Executable" , "Boolean" , true ) ;
718- AddModifyAttribute ( true , rtn . Attribute , "UserExecutable" , "Boolean" , true ) ;
735+ AddBaseNodeClassAttributes ( rtn , false ) ;
736+ AddModifyAttribute ( rtn . Attribute , "Executable" , "Boolean" , true ) ;
737+ AddModifyAttribute ( rtn . Attribute , "UserExecutable" , "Boolean" , true ) ;
719738
720739 break ;
721740 }
@@ -750,7 +769,7 @@ SystemUnitFamilyType FindOrAddSUC(ref SystemUnitClassLibType scl, ref RoleClassL
750769 var varnode = targetNode as NodeSet . UAVariable ;
751770 bool bListOf = ( varnode . ValueRank == 1 ) ; // use ListOf when its a UA array
752771
753- AddModifyAttribute ( false , ie . Attribute , "Value" , varnode . DecodedDataType , varnode . DecodedValue , bListOf ) ;
772+ AddModifyAttribute ( ie . Attribute , "Value" , varnode . DecodedDataType , varnode . DecodedValue , bListOf ) ;
754773 ie . SetAttributeValue ( "ValueRank" , varnode . ValueRank ) ;
755774 ie . SetAttributeValue ( "ArrayDimensions" , varnode . ArrayDimensions ) ;
756775
@@ -824,14 +843,17 @@ private void OverrideAttribute(IClassWithBaseClassReference owner, string Name,
824843
825844 }
826845
827- private void ProcesReferenceType ( ref InterfaceClassLibType icl , NodeId nodeId )
846+ private void ProcessReferenceType ( ref InterfaceClassLibType icl , NodeId nodeId )
828847 {
829848 var refnode = m_modelManager . FindNode < NodeSet . UAReferenceType > ( nodeId ) ;
830849 var added = icl . InterfaceClass . Append ( refnode . DecodedBrowseName . Name ) ;
831850 NodeId BaseNodeId = m_modelManager . FindFirstTarget ( refnode . DecodedNodeId , HasSubTypeNodeId , false ) ;
832851 if ( BaseNodeId != null )
833852 {
834853 added . RefBaseClassPath = BaseRefFromNodeId ( BaseNodeId , ICLPrefix ) ;
854+ InterfaceClassType ict = icl . CAEXDocument . FindByPath ( added . RefBaseClassPath ) as InterfaceClassType ;
855+ if ( ict == null )
856+ ProcessReferenceType ( ref icl , BaseNodeId ) ;
835857 }
836858 else
837859 {
@@ -840,10 +862,11 @@ private void ProcesReferenceType(ref InterfaceClassLibType icl, NodeId nodeId)
840862 // AddBaseNodeClassAttributes(added.Attribute, true);
841863
842864
843- AddModifyAttribute ( true , added . Attribute , "InverseName" , "LocalizedText" , Variant . Null ) ;
844- AddModifyAttribute ( true , added . Attribute , "ModellingRule" , "ModellingRuleType" , Variant . Null , false , MetaModelName ) ;
845- var sym = AddModifyAttribute ( true , added . Attribute , "Symmetric" , "Boolean" , Variant . Null ) ;
846- sym . Value = "true" ;
865+ AddModifyAttribute ( added . Attribute , "InverseName" , "LocalizedText" , Variant . Null ) ;
866+ AddModifyAttribute ( added . Attribute , "ModellingRule" , "ModellingRuleType" , Variant . Null , false , MetaModelName ) ;
867+ OverrideBooleanAttribute ( added . Attribute , "Symmetric" , true ) ;
868+ OverrideBooleanAttribute ( added . Attribute , "IsAbstract" , true ) ;
869+
847870 }
848871 // look for inverse name
849872 InterfaceFamilyType inverseAdded = null ;
@@ -869,7 +892,7 @@ private void ProcesReferenceType(ref InterfaceClassLibType icl, NodeId nodeId)
869892 OverrideBooleanAttribute ( added . Attribute , "Symmetric" , refnode . Symmetric ) ;
870893
871894 if ( refnode . InverseName != null )
872- AddModifyAttribute ( true , added . Attribute , "InverseName" , "LocalizedText" , refnode . InverseName [ 0 ] . Value ) ;
895+ AddModifyAttribute ( added . Attribute , "InverseName" , "LocalizedText" , refnode . InverseName [ 0 ] . Value ) ;
873896
874897 OverrideAttribute ( added , IsSource , "xs:boolean" , true ) ;
875898 OverrideAttribute ( added , RefClassConnectsToPath , "xs:string" , ( inverseAdded != null ? inverseAdded . CAEXPath ( ) : added . CAEXPath ( ) ) ) ;
@@ -884,8 +907,8 @@ private void ProcesReferenceType(ref InterfaceClassLibType icl, NodeId nodeId)
884907 OverrideBooleanAttribute ( inverseAdded . Attribute , "IsAbstract" , refnode . IsAbstract ) ;
885908 if ( basenode . Symmetric != refnode . Symmetric )
886909 OverrideBooleanAttribute ( inverseAdded . Attribute , "Symmetric" , refnode . Symmetric ) ;
887- AddModifyAttribute ( true , inverseAdded . Attribute , "InverseName" , "LocalizedText" , refnode . DecodedBrowseName . Name ) ;
888- // OverrideBooleanAttribute(inverseAdded.Attribute, "IsSource", false);
910+ AddModifyAttribute ( inverseAdded . Attribute , "InverseName" , "LocalizedText" , refnode . DecodedBrowseName . Name ) ;
911+
889912 OverrideAttribute ( inverseAdded , IsSource , "xs:boolean" , false ) ;
890913 OverrideAttribute ( inverseAdded , RefClassConnectsToPath , "xs:string" , added . CAEXPath ( ) ) ;
891914
0 commit comments