public static HashSet<Cyber.ModelicaComponent> getCyberComponentSet(Cyber.RootFolder CyberRootFolder)
        {

            HashSet<Cyber.ModelicaComponent> CyberComponentSet = new HashSet<Cyber.ModelicaComponent>();

            foreach (Cyber.LibraryFolder childLibraryFolder in CyberRootFolder.Children.LibraryFolderCollection)
            {
                CyberComponentSet.UnionWith(getCyberComponentSet(childLibraryFolder));
            }

            foreach (Cyber.Components childComponentFolder in CyberRootFolder.Children.ComponentsCollection)
            {
                CyberComponentSet.UnionWith(getCyberComponentSet(childComponentFolder));
            }

            return CyberComponentSet;

        }
        public static HashSet<Cyber.ModelicaComponent> getCyberComponentSet(Cyber.LibraryFolder CyberLibraryFolder)
        {

            HashSet<Cyber.ModelicaComponent> CyberComponentSet = new HashSet<Cyber.ModelicaComponent>();

            // A LibraryFolder has self-containment relationship
            foreach (Cyber.LibraryFolder libFolder in CyberLibraryFolder.Children.LibraryFolderCollection)
            {
                CyberComponentSet.UnionWith(getCyberComponentSet(libFolder));
            }

            foreach (Cyber.ModelicaComponent component in CyberLibraryFolder.Children.ModelicaComponentCollection)
            {
                CyberComponentSet.Add(component);
            }

            return CyberComponentSet;
        }
 public static HashSet<Cyber.ModelicaComponent> getCyberComponentSet(Cyber.ModelicaComponent CyberComponent)
 {
     HashSet<Cyber.ModelicaComponent> CyberComponentSet = new HashSet<Cyber.ModelicaComponent>();
     CyberComponentSet.Add(CyberComponent);
     return CyberComponentSet;
 }
        public static HashSet<Cyber.ModelicaComponent> getCyberComponentSet(Cyber.Components CyberComponents)
        {

            HashSet<Cyber.ModelicaComponent> CyberComponentSet = new HashSet<Cyber.ModelicaComponent>();

            foreach (Cyber.ModelicaComponent childComponent in CyberComponents.Children.ModelicaComponentCollection)
            {
                CyberComponentSet.Add(childComponent);
            }

            return CyberComponentSet;
        }
        private void createAVMCyberParameter(List<avm.modelica.Parameter> avmCyberModelParameterList, Cyber.ParameterRef cyberModelParameterRef)
        {
            string idString = "ID" + _idCounter;
            _idCounter++;

            // Initialize a avmCyber Parameter
            avm.modelica.Parameter avmCyberParameter = new avm.modelica.Parameter();
            
            ////
            // Set avm cyber parameter Value
            avmCyberParameter.Value = new avm.Value();
            
            // Assign ValueExpressionType for avm Value
            avm.DerivedValue avmDerivedValue = new avm.DerivedValue();
            avmDerivedValue.ValueSource = idString;
            avmCyberParameter.Value.ValueExpression = avmDerivedValue;    

            // Assign ID attr content
            avmCyberParameter.Value.ID = META2AVM_Util.UtilFuncs.ensureMetaIDAttribute(cyberModelParameterRef);
            ////
            
            // Assign Locator relative to the parent cyberModel
            avmCyberParameter.Locator = cyberModelParameterRef.Name;

            /// Now do the outer representation
            avm.PrimitiveProperty avmProperty = new avm.PrimitiveProperty();
            avmProperty.Name = avmCyberParameter.Locator;
            avmProperty.ID = "property." + idString;
            avmProperty.Notes = avmCyberParameter.Notes;

            avmProperty.Value = new avm.Value();
            avmProperty.Value.ID = idString;
            
            
            // Three cases for getting the data type and/or value of the parameter object
            //  TODO: JEP The Simulink case is extremely messy - assume that the value is a real-type scalar for now, and we'll take care of it later
            avmProperty.Value.DimensionType = DimensionTypeEnum.Scalar;
            avmProperty.Value.DataType = DataTypeEnum.Real;
            avm.ParametricValue avmParametricValue = new avm.ParametricValue();
            
            //avm.FixedValue maxVal = new avm.FixedValue();
            //maxVal.Value = "1.0e10";
    
            //avmParametricValue.Maximum = maxVal;
            //avm.FixedValue minVal = new avm.FixedValue();
            //minVal.Value = "-1.0e10";
            //avmParametricValue.Minimum = minVal;
            //avm.FixedValue avmFixedValue = new avm.FixedValue();
            //avmFixedValue.Value = "0";
            /* Cyber.ParameterBase pbase = cyberModelParamterRef.Referred as Cyber.ParameterBase;
            if (pbase.Kind == "VFL_Parameter")
            {
                Simulink.SF_Parameter sfparam = pbase as Simulink.SF_Parameter;

            }
            else if (pbase.Kind == "Data")
            {

            }
            else if (pbase.Kind == "SFData")
            {

            } */
            avmProperty.Value.ValueExpression = avmParametricValue;
            

            // Add avm param to the given List
            avmCyberModelParameterList.Add(avmCyberParameter);
            _avmComponent.Property.Add(avmProperty);
        }
        public void createAVMCyberModel(Cyber.ModelicaComponent cyberModel, string filename)
        {
            // Initialize new AVM cyber model
            avm.cyber.CyberModel avmCyberModel = new avm.cyber.CyberModel();

            // Set Class
            avmCyberModel.Class = cyberModel.Attributes.Class;

            // Set Name
            _avmComponent.Name = cyberModel.Name;
            avmCyberModel.Name = cyberModel.Name;

            _avmComponent.ID = META2AVM_Util.UtilFuncs.ensureMetaIDAttribute();

            _avmComponent.SchemaVersion = "2.5";
            avmCyberModel.Notes = "";
            avmCyberModel.UsesResource = "cyber.path";

            // Create locator string
            string[] path_parts = filename.Split('\\');
            string[] filename_parts = path_parts[path_parts.Length - 1].Split('.');
            avmCyberModel.Locator = cyberModel.Path.Replace('/', '.');

            avm.Resource res = new avm.Resource();
            res.Path = "Cyber\\" + path_parts[path_parts.Length - 1];
            res.Name = "CyberModel";
            res.ID = "cyber.path";
            
            _avmComponent.ResourceDependency.Add(res);

            avm.Resource res2 = new avm.Resource();
            res2.Path = "Cyber\\" + filename_parts[0] + ".xml";
            res2.Name = "CyberXML";
            res2.ID = "cyberxml.path";

            _avmComponent.ResourceDependency.Add(res2);

            // Set Type
            GMEConsole.Out.WriteLine(cyberModel.GetType().Name);
            if (cyberModel.Impl.MetaBase.Name == "SimulinkWrapper")
            {
               avmCyberModel.Type = avm.cyber.ModelType.Simulink;
            }
            else //(cyberModel.Impl.MetaBase.Name == "SignalFlowWrapper")
            {
               avmCyberModel.Type = avm.cyber.ModelType.SignalFlow;
            }
            //else
            //{
                // Other ModelicaComponent types not handled for now
            //    return;
            //}

            // for every InputSignalInterface in the ModelicaComponent create avm.modelica.Connector.
            // Note: Connector in AVM Cyber Model in a copy of AVM ModelicaModel
            foreach (Cyber.InputSignalInterface cyberInputSignalInterface in cyberModel.Children.InputSignalInterfaceCollection)
            {
                createAVMCyberConnector(avmCyberModel.Connector, cyberInputSignalInterface);
            }

            // for every OutputSignalInterface in the ModelicaComponent create avm.modelica.connector
            foreach (Cyber.OutputSignalInterface cyberOutputSignalInterface in cyberModel.Children.OutputSignalInterfaceCollection)
            {
                createAVMCyberConnector(avmCyberModel.Connector, cyberOutputSignalInterface);
            }

            // for every BusInterface in the ModelicaComponent create avm.modelica.connector
            // FIX: may require fix. Not sure!
            foreach (Cyber.BusInterface cyberBusInterface in cyberModel.Children.BusInterfaceCollection)
            {
                createAVMCyberConnector(avmCyberModel.Connector, cyberBusInterface);
            }

            // for every ParameterRef in the ModelicaComponent create avm.modelica.parameter
            foreach (Cyber.ParameterRef cyberParameterRef in cyberModel.Children.ParameterRefCollection)
            {
                createAVMCyberParameter(avmCyberModel.Parameter, cyberParameterRef);
            }
            
            // Add it to _avmComponent's DomainModel List
            _avmComponent.DomainModel.Add(avmCyberModel);
            // 
        }