Ejemplo n.º 1
0
        private void Traverse(Port srcPort_obj, Tonka.DesignElement parent, Tonka.Port port, Dictionary <string, object> visited)
        {
            Logger.WriteDebug("Traverse Port: port {0}",
                              port.Path);

            if (visited.ContainsKey(port.ID))
            {
                Logger.WriteWarning("Traverse Port Revisit: {0}", port.Path);
                return;
            }
            visited.Add(port.ID, port);

            // continue traversal
            var remotes = port.DstConnections.PortCompositionCollection.Select(p => p.DstEnd).Union(
                port.SrcConnections.PortCompositionCollection.Select(p => p.SrcEnd));

            foreach (var remote in remotes)
            {
                if (visited.ContainsKey(remote.ID))
                {
                    continue;                                      // already visited continue
                }
                if (remote.ParentContainer is Tonka.DesignElement) // remote is contained in a Component or ComponentAssembly
                {
                    srcPort_obj.connectedPorts[remote.Impl.AbsPath] = remote;
                    Traverse(srcPort_obj,
                             remote.ParentContainer as Tonka.DesignElement,
                             remote as Tonka.Port,
                             visited);
                }
                else if (remote.ParentContainer is Tonka.Connector) // remote is contained in a Connector
                {
                    srcPort_obj.connectedPorts[remote.Impl.AbsPath] = remote;
                    Traverse(remote.Name,
                             srcPort_obj,
                             remote.ParentContainer.ParentContainer as Tonka.DesignElement,
                             remote.ParentContainer as Tonka.Connector,
                             visited);
                }
                else if (portHasCorrectParentType(remote) && // remote is contained in a SchematicModel
                         CyPhyBuildVisitor.Ports.ContainsKey(remote.ID))
                {
                    ConnectPorts(srcPort_obj, CyPhyBuildVisitor.Ports[remote.ID]);
                }
            }
        }
Ejemplo n.º 2
0
        private static String GetIDOfDesignSpaceSourceObject(CyPhy.DesignElement de)
        {
            // Look for a DesignEntityRef, within a CWC, that points to this.
            foreach (CyPhy.DesignEntityRef der in de.ReferencedBy.DesignEntityRef)
            {
                // Get the Built connection and then the BuildDesignEntityRef.
                // The BuildDesignEntityRef will point to our source object.
                foreach (CyPhy.Built b in der.DstConnections.BuiltCollection)
                {
                    ISIS.GME.Common.Interfaces.FCO fco = b.SrcEnd;
                    if (fco is CyPhy.BuiltDesignEntityRef)
                    {
                        return(GetOrSetID((fco as CyPhy.BuiltDesignEntityRef).Referred.DesignEntity));
                    }
                }
            }

            return("");
        }
Ejemplo n.º 3
0
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            this.Logger.WriteInfo("Running Component Authoring interpreter.");

            /*if (currentobj != null &&
             *  currentobj.Meta.Name == typeof(CyPhy.ComponentAssembly).Name)
             * {
             *  CyPhy.ComponentAssembly ca = CyPhyClasses.ComponentAssembly.Cast(currentobj);
             *  string fileName = null;
             *  DialogResult dr;
             *  using (OpenFileDialog ofd = new OpenFileDialog())
             *  {
             *      ofd.CheckFileExists = true;
             *      ofd.Multiselect = false;
             *      ofd.Filter = "SVG files (*.svg)|*.svg*|All files (*.*)|*.*";
             *      ofd.AutoUpgradeEnabled = true;
             *      dr = ofd.ShowDialog();
             *      if (dr == DialogResult.OK)
             *      {
             *          fileName = ofd.FileName;
             *      }
             *  }
             *  if (fileName == null)
             *  {
             *      this.Logger.WriteError("No file was selected.  Add Custom Icon will not complete.");
             *      return;
             *  }
             *
             *  string IconFileDestPath = META.ComponentLibraryManager.EnsureComponentAssemblyFolder(ca);
             *  IconFileDestPath = ca.GetDirectoryPath(META.ComponentLibraryManager.PathConvention.ABSOLUTE);
             *
             *  System.IO.File.Copy(fileName, System.IO.Path.Combine(IconFileDestPath, "icon.svg"), true);
             *  this.Logger.WriteInfo("Successfully added icon.svg to " + currentobj.Name);
             *  return;
             * }*/
            // verify we are running in a component and that it is not an instance or library
            string return_msg;

            if (!CheckPreConditions(currentobj, out return_msg))
            {
                this.Logger.WriteFailed(return_msg);
                return;
            }

            // assuming a component is open
            // stash off the project, currentobj and CurrentComponent parameters for use in the event handlers
            StashProject    = project;
            StashCurrentObj = currentobj;

            if (currentobj.Meta.Name == typeof(CyPhy.Component).Name)
            {
                StashCurrentComponent = CyPhyClasses.Component.Cast(currentobj);
            }
            else if (currentobj.Meta.Name == typeof(CyPhy.ComponentAssembly).Name)
            {
                StashCurrentComponent = CyPhyClasses.ComponentAssembly.Cast(currentobj);
            }
            else
            {
                throw new ArgumentException("Invalid design element passed to authoring tool");
            }


            SupportedDesignEntityType designElementType;

            if (StashCurrentComponent is CyPhy.Component)
            {
                designElementType = SupportedDesignEntityType.Component;
            }
            else if (StashCurrentComponent is CyPhy.ComponentAssembly)
            {
                designElementType = SupportedDesignEntityType.ComponentAssembly;
            }
            else
            {
                throw new ArgumentException("Invalid design element passed to authoring tool");
            }

            // use reflection to populate the dialog box objects
            PopulateDialogBox(designElementType);

            // 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);
        }
Ejemplo n.º 4
0
 public void SetCurrentDesignElement(CyPhy.DesignElement comp)
 {
     CurrentDesignElement = comp;
 }
Ejemplo n.º 5
0
        private void Traverse(string srcConnectorName, Port srcPort_obj, Tonka.DesignElement parent, Tonka.Connector connector, Dictionary <string, object> visited)
        {
            // XXX this is dead code; the elaborator removes Connectors
            Logger.WriteDebug("Traverse Connector: {0}, Mapped-Pin: {1}",
                              connector.Path,
                              srcConnectorName);
            if (visited.ContainsKey(connector.ID))
            {
                Logger.WriteWarning("Traverse Connector Revisit: {0}, Mapped-Pin: {1}", connector.Path, srcConnectorName);
                return;
            }
            visited.Add(connector.ID, connector);

            // continue traversal as connector
            var remotes = connector.DstConnections.ConnectorCompositionCollection.Select(p => p.DstEnd).Union(
                connector.SrcConnections.ConnectorCompositionCollection.Select(p => p.SrcEnd));

            foreach (var remote in remotes)
            {
                if (visited.ContainsKey(remote.ID)) // already visited
                {
                    continue;
                }
                if (remote.ParentContainer is Tonka.DesignElement)
                {
                    Traverse(srcConnectorName, srcPort_obj, remote.ParentContainer as Tonka.DesignElement, remote as Tonka.Connector, visited);
                }
            }

            // continue traversal through named port
            // XXX FIXME p.Name.Equals(srcConnectorName) is a bug (why should it matter what the names are)
            var mappedPorts = connector.Children.SchematicModelPortCollection.Where(p => p.Name.Equals(srcConnectorName));

            foreach (var mappedPort in mappedPorts)
            {
                var remotePorts = mappedPort.DstConnections.PortCompositionCollection.Select(p => p.DstEnd).Union(
                    mappedPort.SrcConnections.PortCompositionCollection.Select(p => p.SrcEnd));
                foreach (var remotePort in remotePorts)
                {
                    if (visited.ContainsKey(remotePort.ID)) // already visited
                    {
                        continue;
                    }
                    if (remotePort.ParentContainer is Tonka.Connector &&
                        !visited.ContainsKey(remotePort.ParentContainer.ID))
                    // traverse connector chain, carry port name in srcConnector
                    {
                        Traverse(remotePort.Name, srcPort_obj,
                                 remotePort.ParentContainer.ParentContainer as Tonka.DesignElement,
                                 remotePort.ParentContainer as Tonka.Connector, visited);
                    }
                    else if (remotePort.ParentContainer is Tonka.DesignElement)
                    {
                        Traverse(srcPort_obj, remotePort.ParentContainer as Tonka.DesignElement, remotePort as Tonka.Port, visited);
                    }
                    else if (portHasCorrectParentType(remotePort) &&
                             CyPhyBuildVisitor.Ports.ContainsKey(remotePort.ID))
                    {
                        ConnectPorts(srcPort_obj, CyPhyBuildVisitor.Ports[remotePort.ID]);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static XElement CreateForAssembly(CyPhy.DesignElement system, Dictionary <XElement, CyPhy.SPICEModel> map = null)
        {
            Action <XElement, IEnumerable <CyPhy.SPICEModel> > addSpiceModels = (parentElement, models) =>
            {
                foreach (var model in models.OrderBy(sm => sm.Name))
                {
                    var spiceElement = new XElement("SpiceModel");
                    parentElement.Add(spiceElement);
                    spiceElement.SetAttributeValue("Name", model.Name);
                    // spiceElement.SetAttributeValue("Fidelity"
                    if (map != null)
                    {
                        map.Add(spiceElement, model);
                    }
                }
            };

            Queue <Tuple <XElement, CyPhy.DesignEntity> > containers = new Queue <Tuple <XElement, CyPhy.DesignEntity> >();

            containers.Enqueue(new Tuple <XElement, CyPhy.DesignEntity>(null, system));
            XElement root = null;

            while (containers.Count > 0)
            {
                var      tuple     = containers.Dequeue();
                var      parent    = tuple.Item1;
                var      container = tuple.Item2;
                XElement element   = new XElement(container.Impl.MetaBase.Name);
                element.SetAttributeValue("Name", container.Name);
                if (parent == null)
                {
                    root = element;
                }
                else
                {
                    parent.Add(element);
                }
                IEnumerable <CyPhy.Component>    childComponents    = new CyPhy.Component[] { };
                IEnumerable <CyPhy.ComponentRef> childComponentRefs = new CyPhy.ComponentRef[] { };
                if (container is CyPhy.DesignContainer)
                {
                    foreach (var child in (container as CyPhy.DesignContainer).Children.DesignContainerCollection)
                    {
                        containers.Enqueue(new Tuple <XElement, CyPhy.DesignEntity>(element, child));
                    }
                    childComponents    = (container as CyPhy.DesignContainer).Children.ComponentCollection;
                    childComponentRefs = (container as CyPhy.DesignContainer).Children.ComponentRefCollection;
                    // TODO addSpiceModels(element, (container as CyPhy.DesignContainer).Children.SPICEModelCollection);
                }
                else if (container is CyPhy.ComponentAssembly)
                {
                    foreach (var child in (container as CyPhy.ComponentAssembly).Children.ComponentAssemblyCollection)
                    {
                        containers.Enqueue(new Tuple <XElement, CyPhy.DesignEntity>(element, child));
                    }
                    childComponents    = (container as CyPhy.ComponentAssembly).Children.ComponentCollection;
                    childComponentRefs = (container as CyPhy.ComponentAssembly).Children.ComponentRefCollection;
                    element.SetAttributeValue("Classifications", (container as CyPhy.ComponentAssembly).Attributes.Classifications.Replace("\n", ";"));
                    addSpiceModels(element, (container as CyPhy.ComponentAssembly).Children.SPICEModelCollection);
                }
                foreach (var childComponent in childComponents)
                {
                    var childElement = new XElement("Component");
                    childElement.SetAttributeValue("Name", childComponent.Name);
                    childElement.SetAttributeValue("Classifications", childComponent.Attributes.Classifications.Replace("\n", ";"));
                    element.Add(childElement);
                    addSpiceModels(childElement, childComponent.Children.SPICEModelCollection);
                }
                foreach (var childComponentRef in childComponentRefs)
                {
                    if (childComponentRef.AllReferred.Impl.MetaBase.Name == "ComponentAssembly")
                    {
                        containers.Enqueue(new Tuple <XElement, CyPhy.DesignEntity>(element, childComponentRef.Referred.ComponentAssembly));
                        continue;
                    }
                    var childElement = new XElement("Component");
                    childElement.SetAttributeValue("Name", childComponentRef.Name);
                    childElement.SetAttributeValue("Classifications", childComponentRef.Referred.Component.Attributes.Classifications.Replace("\n", ";"));
                    element.Add(childElement);
                    addSpiceModels(childElement, childComponentRef.Referred.Component.Children.SPICEModelCollection);
                }
                // children.Sort((a, b) => a.name.CompareTo(b.name));
            }

            return(root);
        }