Exemple #1
0
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            // TODO: Add your interpreter code
            GMEConsole.Clear();
            GMEConsole.Out.WriteLine("Running interpreter...");

            // Get RootFolder
            IMgaFolder rootFolder = project.RootFolder;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Json Files (*.json)|*.json";

            var userClickedOK = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == System.Windows.Forms.DialogResult.OK)
            {
                string fileName = openFileDialog1.FileName;

                // parse Json
                if (File.Exists(fileName))
                {
                    List <string> materialKeys = new List <string>();
                    using (StreamReader reader = new StreamReader(fileName))
                    {
                        string  materialStr = reader.ReadToEnd();
                        JObject o           = JObject.Parse(materialStr);
                        JObject materialLib = o["Material library"].Value <JObject>();
                        if (materialLib != null)
                        {
                            materialKeys = materialLib.Properties().Select(p => p.Name).ToList();
                        }
                    }


                    // create material folders
                    if (materialKeys.Count() > 0)
                    {
                        int count = rootFolder.ChildFolders.OfType <GME.MGA.MgaFolder>().Where(f => f.MetaBase.Name == "MaterialsDefinition").Count();
                        if (count > 1)
                        {
                            GMEConsole.Error.WriteLine("There should only be 1 materials definition folder!");
                            return;
                        }
                        else if (count < 1)
                        {
                            var       role           = (rootFolder.MetaFolder as MgaMetaFolder).get_LegalChildFolderByName("MaterialsDefinition");
                            MgaFolder materialFolder = rootFolder.CreateFolder(role);
                            materialFolder.Name = "MaterialDefinitions";
                            CreateMaterialObjects(materialFolder,
                                                  materialKeys);
                        }
                        else
                        {
                            MgaFolder materialFolder = rootFolder.ChildFolders.OfType <GME.MGA.MgaFolder>().Where(f => f.MetaBase.Name == "MaterialsDefinition").First();
                            CreateMaterialObjects(materialFolder,
                                                  materialKeys);
                        }
                    }
                }
            }
            else
            {
                return;
            }

            // To use the domain-specific API:
            //  Create another project with the same name as the paradigm name
            //  Copy the paradigm .mga file to the directory containing the new project
            //  In the new project, install the GME DSMLGenerator NuGet package (search for DSMLGenerator)
            //  Add a Reference in this project to the other project
            //  Add "using [ParadigmName] = ISIS.GME.Dsml.[ParadigmName].Classes.Interfaces;" to the top of this file
            // if (currentobj.Meta.Name == "KindName")
            // [ParadigmName].[KindName] dsCurrentObj = ISIS.GME.Dsml.[ParadigmName].Classes.[KindName].Cast(currentobj);
        }
Exemple #2
0
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            GMEConsole.Clear();
            System.Windows.Forms.Application.DoEvents();

            IMgaFCO selectedObj = null;

            bool isContextValid = CheckForValidContext(currentobj);

            if (isContextValid == false)
            {
                return;
            }

            // get all the ComponentRefs in the DesignContainer
            var crefs = (currentobj as IMgaModel).
                        ChildFCOs.
                        Cast <IMgaFCO>().
                        Where(x => x.MetaBase.Name == "ComponentRef");

            // If there is exactly '1', select it
            if (crefs.Count() == 1)
            {
                selectedObj = crefs.FirstOrDefault();
            }

            if (selectedObj == null)
            {
                if (selectedobjs.Count != 1)
                {
                    GMEConsole.Error.WriteLine(SelectedObjErrorMessage);
                    return;
                }
                selectedObj = selectedobjs.Cast <IMgaFCO>().FirstOrDefault();
            }

            if (selectedObj == null)
            {
                GMEConsole.Error.WriteLine(SelectedObjErrorMessage);
                return;
            }

            if (selectedObj.MetaBase.Name != "ComponentRef")
            {
                GMEConsole.Error.WriteLine(SelectedObjErrorMessage);
                return;
            }

            if ((selectedObj as IMgaReference).Referred == null)
            {
                GMEConsole.Error.WriteLine("Selected ComponentRef is a null reference.");
                return;
            }

            GMEConsole.Info.WriteLine("Running CLM_light...");

            // everything is checked we can operate on the objects
            IMgaFCO   designContainer = currentobj;
            IMgaFCO   componentRef    = selectedObj;
            IMgaModel component       = (selectedObj as IMgaReference).Referred as IMgaModel;

            GMEConsole.Info.WriteLine("Discovering components.");

            //GMEConsole.Info.WriteLine("{0} components were found.", components.Count);

            // TODO: filter detected components if needed
            using (ComponentSelectionForm csf = new ComponentSelectionForm(component, currentobj as IMgaModel, GMEConsole.Error, GMEConsole.Info))
            {
                var dialogresult = csf.ShowDialog();

                if (dialogresult == System.Windows.Forms.DialogResult.OK)
                {
                    GMEConsole.Info.WriteLine("Inserting new components.");

                    List <IMgaFCO> components = new List <IMgaFCO>();

                    foreach (var item in csf.dgvSelector.SelectedRows)
                    {
                        var dgvr = item as System.Windows.Forms.DataGridViewRow;
                        var cli  = dgvr.DataBoundItem as ComponentListItem;
                        components.Add(cli.Fco);
                    }

                    GMEConsole.Info.WriteLine("{0} components were selected.", components.Count);

                    List <KeyValuePair <IMgaFCO, string> > messages = new List <KeyValuePair <IMgaFCO, string> >();

                    var insertedComponents = InsertComponents(designContainer, componentRef, components, messages);
                }
            }
            GMEConsole.Info.WriteLine("Done.");
        }