示例#1
0
 private static String GetDesignSpaceSourceObjectID(CyPhy.ComponentRef cr)
 {
     foreach (CyPhy.BuiltDesignEntityRef bdef in cr.ReferencedBy.BuiltDesignEntityRef)
     {
         foreach (CyPhy.Built built in bdef.SrcConnections.BuiltCollection)
         {
             CyPhy.DesignEntityRef der       = built.SrcEnds.DesignEntityRef;
             CyPhy.DesignEntity    de_Source = der.Referred.DesignEntity;
             return(de_Source.Guid.ToString());
         }
     }
     return("");
 }
示例#2
0
        // Insert an existing AVM component into a design
        void TestInsertComponentIntoDesign()
        {
            SetupTest();

            RunCyPhyMLSync(
                (project, propagate, interpreter) =>
            {
                {
                    Edit msg = new Edit()
                    {
                        editMode = Edit.EditMode.POST,
                    };
                    msg.mode.Add(Edit.EditMode.POST);
                    msg.origin.Add(origin);
                    msg.topic.Add("0");
                    edu.vanderbilt.isis.meta.Action action = new edu.vanderbilt.isis.meta.Action()
                    {
                        actionMode = edu.vanderbilt.isis.meta.Action.ActionMode.ADD_COMPONENT_TO_CYPHY_DESIGN,
                        subjectID  = testAssemblyId,
                        payload    = new Payload()
                    };
                    action.payload.components.Add(new CADComponentType()
                    {
                        Name           = "TestInsertComp",
                        AvmComponentID = testAVMId
                    });
                    msg.actions.Add(action);

                    propagate.EditMessageReceived(msg);
                    Application.DoEvents();
                }
                project.BeginTransactionInNewTerr();
                try
                {
                    var assembly   = GetTestAssembly(project);
                    var insertcomp = assembly.ChildObjects.Cast <MgaFCO>().Where(fco => fco.Name.Contains("TestInsertComp")).First();
                    Xunit.Assert.NotEqual(null, insertcomp);
                    CyPhyML.ComponentRef insertcompref = CyPhyMLClasses.ComponentRef.Cast(insertcomp);
                    Xunit.Assert.NotEqual(null, insertcompref.AllReferred);
                    Xunit.Assert.Equal(true, insertcompref.AllReferred is CyPhyML.Component);
                    Xunit.Assert.Equal(testAVMId, (insertcompref.AllReferred as CyPhyML.Component).Attributes.AVMID);
                }
                finally
                {
                    project.AbortTransaction();
                }
            }
                );
        }
示例#3
0
 public static CyPhyML.Connector FindConnector(CyPhyML.ComponentRef compref, string guid)
 {
     if (compref.Referred != null && compref.Referred.Component != null)
     {
         CyPhyML.Component comp = compref.Referred.Component;
         foreach (var connector in comp.Children.ConnectorCollection)
         {
             if (connector.Guid.ToString() == guid)
             {
                 return(connector);
             }
         }
     }
     return(null);
 }
示例#4
0
        public static HashSet <CyPhyML.Component> getCyPhyMLComponentSet(IMgaObject iMgaObject)
        {
            if (iMgaObject == null)
            {
                return(new HashSet <CyPhyML.Component>());
            }

            string metaName = iMgaObject.MetaBase.Name;

            HashSet <CyPhyML.Component> cyPhyMLComponentSet = null;

            if (metaName == "Component")
            {
                cyPhyMLComponentSet = new HashSet <CyPhyML.Component>();
                cyPhyMLComponentSet.Add(CyPhyMLClasses.Component.Cast(iMgaObject));
            }
            else if (metaName == "ComponentRef")
            {
                CyPhyML.ComponentRef cyPhyMLComponentRef = CyPhyMLClasses.ComponentRef.Cast(iMgaObject);
                cyPhyMLComponentSet = new HashSet <CyPhyML.Component>();
                cyPhyMLComponentSet.Add(cyPhyMLComponentRef.Referred as CyPhyML.Component);
            }
            else if (metaName == "ComponentAssembly")
            {
                cyPhyMLComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(CyPhyMLClasses.ComponentAssembly.Cast(iMgaObject));
            }
            else if (metaName == "ComponentAssemblyRef")
            {
                CyPhyML.ComponentAssemblyRef cyPhyMLComponentAssemblyRef = CyPhyMLClasses.ComponentAssemblyRef.Cast(iMgaObject);
                cyPhyMLComponentSet = new HashSet <CyPhyML.Component>();
                cyPhyMLComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(cyPhyMLComponentAssemblyRef.Referred as CyPhyML.ComponentAssembly);
            }
            else if (metaName == "TestBench")
            {
                cyPhyMLComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(CyPhyMLClasses.TestBench.Cast(iMgaObject));
            }
            else if (metaName == "RootFolder")
            {
                cyPhyMLComponentSet = CyPhy2ComponentModel.ComponentLister.getCyPhyMLComponentSet(CyPhyMLClasses.RootFolder.GetRootFolder(iMgaObject.Project));
            }
            else
            {
                cyPhyMLComponentSet = new HashSet <CyPhyML.Component>();
            }

            return(cyPhyMLComponentSet);
        }
示例#5
0
        public static CyPhyML.ComponentRef GetComponentRefInAssemblyById(CyPhyML.ComponentAssembly root, string amalgamatedId)
        {
            List <string> ids         = new List <string>();
            int           ind         = 0;
            int           guid_length = new Guid().ToString("B").Length;

            for (; ind < amalgamatedId.Length; ind += guid_length)
            {
                if (amalgamatedId.Length < ind + guid_length)
                {
                    return(null);
                }
                ids.Add(amalgamatedId.Substring(ind, guid_length));
            }
            CyPhyML.ComponentAssembly ca           = root;
            CyPhyML.ComponentRef      componentRef = null;
            foreach (string componentRefInstanceGuid in ids)
            {
                if (ca == null)
                {
                    return(null);
                }
                componentRef = GetComponentRefInAssemblyByIdWithoutFollowingReferences(ca, componentRefInstanceGuid);
                if (componentRef == null)
                {
                    return(null);
                }
                if (componentRef.AllReferred is CyPhyML.ComponentAssembly)
                {
                    ca = (CyPhyML.ComponentAssembly)componentRef.AllReferred;
                }
                else
                {
                    ca = null;
                }
            }
            return(componentRef);
        }
示例#6
0
        private void ImportComponentInstance(avm.ComponentInstance ad_componentinstance, CyPhy.ComponentRef cyphy_componentref)
        {
            AVM2CyPhyML.CyPhyMLComponentBuilder.SetLayoutData(ad_componentinstance, cyphy_componentref.Impl);

            ISIS.GME.Dsml.CyPhyML.Interfaces.Component component;
            if (avmidComponentMap.TryGetValue(ad_componentinstance.ComponentID, out component) == false)
            {
                throw new ApplicationException(String.Format("Cannot find Component with ID {0}. Has it been imported?", ad_componentinstance.ComponentID));
            }
            cyphy_componentref.Referred.Component = component;
            cyphy_componentref.Name = ad_componentinstance.Name;
            //cyphy_componentref.Attributes.ID = ad_componentinstance.ID;
            cyphy_componentref.Attributes.InstanceGUID        = ad_componentinstance.ID;
            idToComponentInstanceMap[ad_componentinstance.ID] = cyphy_componentref;

            foreach (var ad_propinstance in ad_componentinstance.PrimitivePropertyInstance)
            {
                Func <IMgaObject, string> getID = o =>
                {
                    var id = ((IMgaFCO)o).StrAttrByName["ID"];
                    if (id == "")
                    {
                        id = "id-" + Guid.Parse(((IMgaFCO)o).GetGuidDisp()).ToString("D");
                    }
                    return(id);
                };

                var cyphy_component = this.avmidComponentMap[ad_componentinstance.ComponentID];
                CyPhy.ValueFlowTarget cyphy_componentPort;
                try
                {
                    cyphy_componentPort = cyphy_component.AllChildren.OfType <CyPhy.ValueFlowTarget>()
                                          .Where(x => getID(x.Impl) == ad_propinstance.IDinComponentModel).SingleOrDefault();
                }
                catch (System.InvalidOperationException e)
                {
                    throw new ApplicationException(String.Format("Error: more than one PrimitivePropertyInstance with ID '{0}' in '{1}'. Run the ComponentExporter to fix.",
                                                                 ad_propinstance.IDinComponentModel, ad_componentinstance.Name));
                }
                if (cyphy_componentPort == null)
                {
                    throw new ApplicationException(String.Format("Cannot find {0} in {1}", ad_propinstance.IDinComponentModel, cyphy_component.Name));
                }

                _avmCyPhyMLObjectMap.Add(ad_propinstance, new KeyValuePair <ISIS.GME.Common.Interfaces.Reference, ISIS.GME.Common.Interfaces.FCO>(cyphy_componentref, cyphy_componentPort));
                registerValueNode(ad_propinstance.Value, ad_propinstance);
            }

            foreach (var ad_connectorInstance in ad_componentinstance.ConnectorInstance)
            {
                _idConnectorMap.Add(ad_connectorInstance.ID, ad_connectorInstance); // FIXME could be dup

                var             cyphy_component = this.avmidComponentMap[ad_componentinstance.ComponentID];
                CyPhy.Connector cyphy_componentConnector;
                try
                {
                    cyphy_componentConnector = cyphy_component.AllChildren.OfType <CyPhy.Connector>()
                                               .Where(x => ((MgaFCO)x.Impl).StrAttrByName["ID"] == ad_connectorInstance.IDinComponentModel).SingleOrDefault();
                }
                catch (System.InvalidOperationException e)
                {
                    throw new ApplicationException(String.Format("Error: more than one ConnectorInstance with ID '{0}' in '{1}'. Run the ComponentExporter to fix.",
                                                                 ad_connectorInstance.IDinComponentModel, ad_componentinstance.Name));
                }

                if (cyphy_componentConnector == null)
                {
                    throw new ApplicationException("adm error: component instance " + ad_componentinstance.ID + " has connector with IDinComponentModel "
                                                   + ad_connectorInstance.IDinComponentModel + " that has no matching Connector in the Component");
                }

                _avmCyPhyMLObjectMap.Add(ad_connectorInstance, new KeyValuePair <ISIS.GME.Common.Interfaces.Reference, ISIS.GME.Common.Interfaces.FCO>(cyphy_componentref, cyphy_componentConnector));
            }

            foreach (var ad_port in ad_componentinstance.PortInstance)
            {
                registerPort(ad_port);

                var cyphy_component          = this.avmidComponentMap[ad_componentinstance.ComponentID];
                var cyphy_componentConnector = cyphy_component.AllChildren.OfType <CyPhy.Port>()
                                               .Where(x => ((MgaFCO)x.Impl).StrAttrByName["ID"] == ad_port.IDinComponentModel).FirstOrDefault();
                if (cyphy_componentConnector == null)
                {
                    throw new ApplicationException("adm error: component instance " + ad_componentinstance.ID + " has connector with IDinComponentModel "
                                                   + ad_port.IDinComponentModel + " that has no matching Connector in the Component");
                }
                _avmCyPhyMLObjectMap.Add(ad_port, new KeyValuePair <ISIS.GME.Common.Interfaces.Reference, ISIS.GME.Common.Interfaces.FCO>(cyphy_componentref, cyphy_componentConnector));
            }
        }
示例#7
0
        private void ProcessContacts(CyPhy.KinematicTestBench testBench)
        {
            List <Multibody.ModelContact> contactlist = new List <Multibody.ModelContact>();
            string cyphyid1, cyphyid2;

            foreach (CyPhy.Contact contact in testBench.Children.ContactCollection)
            {
                CyPhy.ComponentRef terrain = null;
                var tip1 = contact.SrcEnds.TestInjectionPoint;
                if (tip1 == null)
                {
                    terrain = contact.SrcEnds.ComponentRef;
                }
                var tip2 = contact.DstEnds.TestInjectionPoint;
                if (tip2 == null)
                {
                    terrain = contact.SrcEnds.ComponentRef;
                }
                if (terrain != null)
                {
                    var tip = tip1 == null ? tip2 : tip1;
                    if (tip.AllReferred == null)
                    {
                        Logger.Instance.AddLogMessage("TIP doesn't refer anything: " + tip.Path, Severity.Error);
                        continue;
                    }
                    if (!(tip.AllReferred is CyPhy.Component))
                    {
                        Logger.Instance.AddLogMessage("TIPs participating in contacts can only refer components: " + tip.Path, Severity.Error);
                        continue;
                    }
                    cyphyid1 = (tip.AllReferred as CyPhy.Component).Attributes.InstanceGUID;
                    cyphyid2 = "TERRAIN";
                }
                else
                {
                    if (tip1.AllReferred == null)
                    {
                        Logger.Instance.AddLogMessage("TIP doesn't refer anything: " + tip1.Path, Severity.Error);
                        continue;
                    }
                    if (tip2.AllReferred == null)
                    {
                        Logger.Instance.AddLogMessage("TIP doesn't refer anything: " + tip2.Path, Severity.Error);
                        continue;
                    }
                    if (!(tip1.AllReferred is CyPhy.Component))
                    {
                        Logger.Instance.AddLogMessage("TIPs participating in contacts can only refer components: " + tip1.Path, Severity.Error);
                        continue;
                    }
                    if (!(tip2.AllReferred is CyPhy.Component))
                    {
                        Logger.Instance.AddLogMessage("TIPs participating in contacts can only refer components: " + tip2.Path, Severity.Error);
                        continue;
                    }
                    cyphyid1 = (tip1.AllReferred as CyPhy.Component).Attributes.InstanceGUID;
                    cyphyid2 = (tip2.AllReferred as CyPhy.Component).Attributes.InstanceGUID;
                }
                contactlist.Add(new Multibody.ModelContact()
                {
                    CyphyId1 = cyphyid1, CyphyId2 = cyphyid2
                });
            }
            if (contactlist.Count > 0)
            {
                ContactList = contactlist;
            }
        }
示例#8
0
        public void OutgoingValueFlowWithVariableName()
        {
            CyPhy.DesignContainer rootDC   = null;
            CyPhy.ComponentRef    comp1    = null;
            List <MgaFCO>         selected = new List <MgaFCO>();

            List <CyPhy.DesignContainer> childDCs = null;

            CyPhy.DesignContainer     childDC         = null;
            List <CyPhy.ComponentRef> childComponents = null;

            CyPhy.ComponentRef     childComp1      = null;
            List <CyPhy.ValueFlow> childValueFlows = null;

            CyPhy.ValueFlow childValueFlow = null;

            proj.PerformInTransaction(delegate
            {
                // Assuming test model has 1 and only 1 DesignContainer called "ValueFlowVariableName"
                rootDC = proj.GetDesignContainersByName("ValueFlowVariableName").First();
                comp1  = rootDC.Children
                         .ComponentRefCollection
                         .Where(x => x.Name == "C1")
                         .First();
                selected.Add(comp1.Impl as MgaFCO);
            });

            Utils.RunDSRefactorer(rootDC.Impl as MgaFCO, selected, "DesignContainer");

            proj.PerformInTransaction(delegate
            {
                // Assuming test model has 1 and only 1 DesignContainer called "ValueFlowVariableName"
                rootDC = proj.GetDesignContainersByName("ValueFlowVariableName").First();

                // Make sure only 1 child DesignContainer of name 'NewDC_C1' is found
                childDCs = rootDC.Children
                           .DesignContainerCollection
                           .Where(x => x.Name == "NewDC__C1").ToList();
                String countStr = "Count = " + childDCs.Count();
                Assert.True(childDCs.Count() == 1, "Expected to find exactly 1 DesignContainer named 'NewDC__C1', " + countStr);

                // Make sure only 1 child ComponentRef of name 'C1' is found
                childDC         = childDCs.First();
                childComponents = childDC.Children
                                  .ComponentRefCollection
                                  .Where(x => x.Name == "C1").ToList();
                Assert.True(childComponents.Count() == 1, "Expected to find exactly 1 ComponentRefs named 'C1' in DesignContainer 'NewDC__C1'");

                // Make sure only this ComponentRef and original ComponentRef point to the same component
                childComp1 = childComponents.First();
                Assert.True("C1" == childComp1.Referred.Component.Name, "Child ComponentRef and original ComponentRef points to different components!");

                // Make sure that the ValueFlow has the alias 'C1P1'
                childValueFlows = rootDC.Children
                                  .ValueFlowCollection
                                  .Where(x => x.SrcEnd.Name == "CustomFormula_C1" && x.DstEnd.Kind == "CustomFormula").ToList();
                Assert.True(childValueFlows.Count() == 1, "No ValueFlow found from 'CustomFormula_C1' property to the CustomFormula'");
                childValueFlow   = childValueFlows.First();
                string aliasName = childValueFlow.Attributes.FormulaVariableName;
                Assert.True("C1P1" == aliasName, "Alias found on ValueFlow from 'CustomFormula_C1' property to CustomFormula is not 'C1P1'");
            });
        }
示例#9
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);
        }