Beispiel #1
0
        void open_component_folder()
        {
            this.Logger = new CyPhyGUIs.GMELogger(CurrentProj, this.GetType().Name);

            CyPhy.Component comp    = GetCurrentComp();
            var             absPath = comp.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE);

            if (false == Directory.Exists(absPath))
            {
                Logger.WriteError("Component path does not exist: {0}", absPath);
                clean_up(false);
                return;
            }

            // META-2517 Explorer doesn't like paths with mixed seperators, make them all the same
            string uniformabspath = absPath.Replace("\\", "/");

            try
            {
                Process.Start(@uniformabspath);
            }
            catch (Exception ex)
            {
                Logger.WriteError("Error opening Windows Explorer: {0}", ex.Message);
                clean_up(false);
                return;
            }

            clean_up(true);
        }
        void open_component_folder()
        {
            this.Logger = new CyPhyGUIs.GMELogger(CurrentProj, this.GetType().Name);

            CyPhy.Component comp = GetCurrentComp();
            var absPath = comp.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE);

            if (false == Directory.Exists(absPath))
            {
                Logger.WriteError("Component path does not exist: {0}", absPath);
                clean_up(false);
                return;
            }

            // META-2517 Explorer doesn't like paths with mixed seperators, make them all the same
            string uniformabspath = absPath.Replace("\\", "/");
            try
            {
                Process.Start(@uniformabspath);
            }
            catch (Exception ex)
            {
                Logger.WriteError("Error opening Windows Explorer: {0}", ex.Message);
                clean_up(false);
                return;
            }

            clean_up(true);
        }
Beispiel #3
0
        private void Process(CyPhy.ComponentAssembly componentAssembly)
        {
            if (Logger == null)
            {
                Logger = new CyPhyGUIs.GMELogger(componentAssembly.Impl.Project, this.ComponentName);
            }

            if (String.IsNullOrWhiteSpace(componentAssembly.Attributes.Path))
            {
                componentAssembly.Attributes.Path = GetRandomComponentAssemblyDir();
            }
            else
            {
                string originalPath = Path.Combine(componentAssembly.Impl.Project.GetRootDirectoryPath(), componentAssembly.Attributes.Path);
                componentAssembly.Attributes.Path = GetRandomComponentAssemblyDir();
                if (Directory.Exists(originalPath))
                {
                    try
                    {
                        CopyDirectory(originalPath, Path.Combine(componentAssembly.Impl.Project.GetRootDirectoryPath(), componentAssembly.Attributes.Path));
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteError("Exception while copying to {0}: {1}", componentAssembly.Attributes.Path, ex);
                    }
                }
            }
        }
        public ConfigurationSelection GetConfigurationSelection(MgaProject project)
        {
            ConfigurationSelection config = new ConfigurationSelection()
            {
                PostToJobManager    = this.PostToJobManager,
                KeepTemporaryModels = this.KeepTemporaryModels
            };

            try
            {
                project.BeginTransactionInNewTerr();

                using (CyPhyGUIs.GMELogger logger = new CyPhyGUIs.GMELogger(project))
                {
                    config.Context = this.GetGMEObjectFromIdentification <MgaModel>(project, this.ContextId);

                    if (config.Context == null)
                    {
                        logger.WriteError("Context was not found based on this id '{0}'", this.ContextId);
                    }

                    config.SelectedConfigurations = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
                    foreach (var selectedId in this.SelectedConfigurationIds)
                    {
                        var selectedElement = this.GetGMEObjectFromIdentification <MgaFCO>(project, selectedId);

                        if (selectedElement != null)
                        {
                            // should be CWC or Component assembly
                            config.SelectedConfigurations.Append(selectedElement);
                        }
                        else
                        {
                            logger.WriteError("Configuration was not found based on this id '{0}'", selectedId);
                        }
                    }
                }
            }
            finally
            {
                project.AbortTransaction();
            }

            return(config);
        }
Beispiel #5
0
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            // This is the main ShowNet interpreter code
            Boolean ownLogger = false;

            if (Logger == null)
            {
                ownLogger = true;
                Logger    = new CyPhyGUIs.GMELogger(project, "ShowNet");
            }
            GMEConsole.Out.WriteLine("\n======================================================================================================================================\n");
            Logger.WriteInfo("Starting ShowNet.");

            // Get RootFolder
            IMgaFolder rootFolder = project.RootFolder;
            //GMEConsole.Out.WriteLine(rootFolder.Name);

            // 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
            bool done = false;

            if ((!done) && (null == currentobj))
            {
                done = true;
                Logger.WriteError("The current object is null.  Please select a ComponentAssembly or DesignContainer object.");
            }

            if ((!done) && (currentobj.Meta.Name != "ComponentAssembly" &&
                            currentobj.Meta.Name != "DesignContainer"))
            {
                done = true;
                Logger.WriteError("ShowNet only works on ComponentAssembly and DesignContainer objects.");
                Logger.WriteError("But, {1} is neither; it is a {0}.", currentobj.Meta.Name, currentobj.Name);
            }

            if (!done)
            {
                IEnumerable <CyPhy.PortComposition>      portCompositionChildren      = null;
                IEnumerable <CyPhy.ConnectorComposition> connectorCompositionChildren = null;

                if (currentobj.Meta.Name == "ComponentAssembly")
                {
                    var componentAssembly = ISIS.GME.Dsml.CyPhyML.Classes.ComponentAssembly.Cast(currentobj);
                    portCompositionChildren      = componentAssembly.Children.PortCompositionCollection;
                    connectorCompositionChildren = componentAssembly.Children.ConnectorCompositionCollection;
                }
                else if (currentobj.Meta.Name == "DesignContainer")
                {
                    var designContainer = ISIS.GME.Dsml.CyPhyML.Classes.DesignContainer.Cast(currentobj);
                    portCompositionChildren      = designContainer.Children.PortCompositionCollection;
                    connectorCompositionChildren = designContainer.Children.ConnectorCompositionCollection;
                }

                //=================================================================
                // Process the port connections
                //=================================================================

                NetworkManager portNetworkManager = new NetworkManager();

                foreach (CyPhy.PortComposition port in portCompositionChildren)
                {
                    Endpoint dstEndPoint = new Endpoint(port.DstEnd, port.GenericDstEndRef);
                    Endpoint srcEndPoint = new Endpoint(port.SrcEnd, port.GenericSrcEndRef);

                    //GMEConsole.Out.WriteLine("Found port: dst = '{0}' in the '{1}' {2}.",
                    //    dstEndPoint.Name,
                    //    dstEndPoint.ParentName,
                    //    dstEndPoint.ParentKind);

                    //GMEConsole.Out.WriteLine("            src = '{0}' in the '{1}' {2}.",
                    //    srcEndPoint.Name,
                    //    srcEndPoint.ParentName,
                    //    srcEndPoint.ParentKind);

                    // Create a network from the endpoints
                    List <Endpoint> nodes = new List <Endpoint>()
                    {
                        srcEndPoint, dstEndPoint
                    };
                    Network newNetwork = new Network(nodes);
                    portNetworkManager.Add(newNetwork);
                }

                //=================================================================
                // Process the connector connections
                //=================================================================

                NetworkManager connectorNetworkManager = new NetworkManager();

                foreach (CyPhy.ConnectorComposition connector in connectorCompositionChildren)
                {
                    Endpoint dstEndPoint = new Endpoint(connector.DstEnd, connector.GenericDstEndRef);
                    Endpoint srcEndPoint = new Endpoint(connector.SrcEnd, connector.GenericSrcEndRef);

                    // Create a network from the endpoints
                    List <Endpoint> nodes = new List <Endpoint>()
                    {
                        srcEndPoint, dstEndPoint
                    };
                    Network newNetwork = new Network(nodes);
                    connectorNetworkManager.Add(newNetwork);
                }

                // Make sure the network names are unique.
                NetworkNameChecker.Init();
                NetworkNameChecker.Update(ref portNetworkManager.NetworkList);
                NetworkNameChecker.Update(ref connectorNetworkManager.NetworkList);

                // Display all the networks.

                Logger.WriteInfo(string.Format("===== Found {0} port networks on {1}: =====\n",
                                               portNetworkManager.NetworkList.Count,
                                               currentobj.Name));

                foreach (Network mergedNet in portNetworkManager.NetworkList)
                {
                    using (StringReader sr = new StringReader(mergedNet.ToString()))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            GMEConsole.Out.WriteLine(line);
                        }
                    }
                }

                Logger.WriteInfo(string.Format("===== Found {0} connector networks on {1}: =====\n",
                                               connectorNetworkManager.NetworkList.Count,
                                               currentobj.Name));

                foreach (Network mergedNet in connectorNetworkManager.NetworkList)
                {
                    using (StringReader sr = new StringReader(mergedNet.ToString()))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            GMEConsole.Out.WriteLine(line);
                        }
                    }
                }
            }

            Logger.WriteInfo("The ShowNet interpreter has finished.");

            if (ownLogger)
            {
                Logger.Dispose();
                Logger = null;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Based on the selected objects, either adds connectors for ports/pins, or moves additional ports/pins into a connector.
        /// </summary>
        /// <param name="currentobj">The component model being modified.</param>
        /// <param name="selectedobjs">The selected ports/pins (and perhaps connector).</param>
        /// <seealso cref="https://metamorphsoftware.atlassian.net/browse/MOT-564"/>
        private void AddConnector(MgaFCO currentobj, MgaFCOs selectedobjs)
        {
            if (null == currentobj)
            {
                Logger.WriteError("The current object is null.  Please select a Component object.");
                return;
            }

            if (currentobj.Meta.Name != "Component")
            {
                Logger.WriteError("AddConnector only works on Component objects.");
                Logger.WriteError("But, {1} is neither; it is a {0}.", currentobj.Meta.Name, currentobj.Name);
                return;
            }

            // The current object is a component.
            // Check for selected objects.
            if (selectedobjs.Count < 1)
            {
                Logger.WriteError("At least one pin or port must be selected.");
                return;
            }

            // Make three lists classifying all the selected objects as either ports, connectors, or other,
            // so we can tell how many of each type have been selected.
            List <MgaFCO>          portList      = new List <MgaFCO>();
            List <CyPhy.Connector> connectorList = new List <CyPhy.Connector>();
            List <MgaFCO>          otherList     = new List <MgaFCO>();

            foreach (MgaFCO selectedObj in selectedobjs)
            {
                if (selectedObj.MetaRole.Name == "Connector")
                {
                    connectorList.Add(CyPhyClasses.Connector.Cast(selectedObj));
                }
                else if (IsPort(selectedObj))
                {
                    Logger.WriteDebug("Found port {0}.", selectedObj.Name);
                    portList.Add(selectedObj);
                }
                else
                {
                    otherList.Add(selectedObj);
                }
            }

            if (otherList.Count > 0)
            {
                if (otherList.Count == 1)
                {
                    Logger.WriteWarning("AddConnector only operates on pins, ports, and connectors; {0} was also selected but is being ignored.", otherList[0].MetaRole.Name);
                }
                else
                {
                    Logger.WriteWarning("AddConnector only operates on pins, ports, and connectors; {0} objects of other types are being ignored.", otherList.Count);
                }
            }

            if (portList.Count == 0 && connectorList.Count < 2)
            {
                Logger.WriteError("At least one pin/port object or more than one connector must be selected.");
                return;
            }

            Logger.WriteInfo("Found {0} ports, and {1} connectors OK.", portList.Count, connectorList.Count);

            // Choose the mode of operation based on how many connectors were selected.  See MOT-564.
            if (connectorList.Count == 0)
            {
                Logger.WriteInfo("About to create connectors for the selected ports.");
                HandleNoConnectorsSelected(currentobj, portList);
            }
            else if (connectorList.Count == 1)
            {
                Logger.WriteInfo("About to move selected ports into the selected connector.");
                HandleOneConnectorSelected(currentobj, portList, connectorList[0]);
            }
            else if (portList.Count == 0)
            {
                Logger.WriteInfo("About to combine selected connectors.");
                MergeMultipleConnectors(currentobj, connectorList);
            }
            else
            {
                Logger.WriteInfo("About to run in \"intelligent\" mode.");
                HandleMultipleConnectorsSelected(currentobj, portList, connectorList);
            }
        }