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.");
        }
Exemplo n.º 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.");
        }