private bool portHasCorrectParentType(ISIS.GME.Common.Interfaces.FCO port) { ISIS.GME.Common.Interfaces.Container parent = port.ParentContainer; Type parentType = parent.GetType(); return(this.SchematicModelType.IsAssignableFrom(parentType)); }
public CyPhy.Parameter Create(ISIS.GME.Common.Interfaces.Container container) { CyPhy.Parameter result = ISIS.GME.Common.Utils.CreateObject <ISIS.GME.Dsml.CyPhyML.Classes.Parameter>(container, "" + ISIS.GME.Dsml.CyPhyML.Classes.Parameter.DefaultRole.Parameter.ToString()); result.Name = Name; result.Attributes.Value = DefaultValue; result.Attributes.DataType = Type; return(result); }
private bool IsParent(CyPhy.ConnectorComposition conn, CyPhy.ComponentAssembly topassembly) { GmeCommon.Interfaces.Container container = conn.ParentContainer; while (container != null) { if (container.Guid == topAssembly.Guid) { return(true); } container = container.ParentContainer; } return(false); }
public static T CreateObject <T>( ISIS.GME.Common.Interfaces.Container parent, string roleStr = null) where T : ISIS.GME.Common.Classes.Base, new() { Contract.Requires(parent != null); T result = new T(); string Kind = typeof(T).Name; if (parent.Impl is IMgaModel) { IMgaModel model = parent.Impl as IMgaModel; MgaMetaRole role = null; if (string.IsNullOrEmpty(roleStr)) { try { // try to use user defined role role = (model.MetaBase as IMgaMetaModel).RoleByName[Kind]; } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Role was not found in the container."); sb.AppendLine("Paradigm violation."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } else { try { // try to use user defined role role = (model.MetaBase as IMgaMetaModel).RoleByName[roleStr]; } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Role was not found in the container."); sb.AppendLine("Paradigm violation."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } try { MgaFCO fco = model.CreateChildObject(role); result.Impl = fco as IMgaObject; return(result); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("New element could not be created."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } else if (parent.Impl is MgaFolder) { if (string.IsNullOrEmpty(roleStr)) { MgaFolder folder = parent.Impl as MgaFolder; foreach (MgaMetaFolder item in folder.MetaFolder.LegalChildFolders) { if (item.Name == Kind) { MgaFolder f = folder.CreateFolder(item); result.Impl = f as IMgaObject; return(result); } } if (result.Impl == null) { foreach (MgaMetaFCO item in folder.MetaFolder.LegalRootObjects) { if (item.Name == Kind) { IMgaFCO fco = folder.CreateRootObject(item); result.Impl = fco as IMgaObject; return(result); } } } } else { MgaFolder folder = parent.Impl as MgaFolder; foreach (MgaMetaFolder item in folder.MetaFolder.LegalChildFolders) { if (item.Name == roleStr) { MgaFolder f = folder.CreateFolder(item); result.Impl = f as IMgaObject; return(result); } } if (result.Impl == null) { foreach (MgaMetaFCO item in folder.MetaFolder.LegalRootObjects) { if (item.Name == roleStr) { IMgaFCO fco = folder.CreateRootObject(item); result.Impl = fco as IMgaObject; return(result); } } } } } return(null); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parent"></param> /// <param name="metaRef">meta ref of the new object</param> /// <param name="roleMetaRef">meta ref of the role (if the parent is a model)</param> /// <returns></returns> public static T CreateObject <T>( ISIS.GME.Common.Interfaces.Container parent, int metaRef, int roleMetaRef = 0) where T : ISIS.GME.Common.Classes.Base, new() { Contract.Requires(parent != null); T result = new T(); if (parent.Impl is MgaModel) { MgaModel model = parent.Impl as MgaModel; MgaMetaRole role = null; try { // try to use user defined role role = (model.MetaBase as MgaMetaModel). Roles. Cast <MgaMetaRole>(). FirstOrDefault(x => x.MetaRef == roleMetaRef); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Role was not found in the container."); sb.AppendLine("Paradigm violation."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } try { IMgaFCO fco = model.CreateChildObject(role); result.Impl = fco as IMgaObject; return(result); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("New element could not be created."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } else if (parent.Impl is MgaFolder) { try { MgaFolder folder = parent.Impl as MgaFolder; MgaMetaFolder item = folder.MetaFolder. LegalChildFolders. Cast <MgaMetaFolder>(). FirstOrDefault(x => x.MetaRef == metaRef); if (item != null) { // create new folder MgaFolder f = folder.CreateFolder(item); result.Impl = f as IMgaObject; return(result); } else { MgaMetaFCO itemFco = folder.MetaFolder. LegalRootObjects. Cast <MgaMetaFCO>(). FirstOrDefault(x => x.MetaRef == metaRef); if (itemFco != null) { IMgaFCO f = folder.CreateRootObject(itemFco); result.Impl = f as IMgaObject; return(result); } } } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("New element could not be created in folder."); sb.AppendFormat("Container type: {0} Requested child type: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } return(null); }
public static List <CyPhy.JoinData> TransformJoinData(iFAB.assemblyDetail ad, ISIS.GME.Common.Interfaces.Container parent) { var rtn = new List <CyPhy.JoinData>(); foreach (var join in ad.Items) { CyPhy.JoinData jd = null; if (join is welded) { var w = join as welded; if (parent is CyPhy.Connector) { jd = CyPhyClasses.WeldedJoin.Create(parent as CyPhy.Connector); } else { jd = CyPhyClasses.WeldedJoin.CreateGeneric(parent) as CyPhy.WeldedJoin; } } else if (join is brazed) { var w = join as brazed; if (parent is CyPhy.Connector) { jd = CyPhyClasses.BrazedJoin.Create(parent as CyPhy.Connector); } else { jd = CyPhyClasses.BrazedJoin.CreateGeneric(parent) as CyPhy.BrazedJoin; } } else if (join is soldered) { var w = join as soldered; if (parent is CyPhy.Connector) { jd = CyPhyClasses.SolderedJoin.Create(parent as CyPhy.Connector); } else { jd = CyPhyClasses.SolderedJoin.CreateGeneric(parent) as CyPhy.SolderedJoin; } } else if (join is glued) { var w = join as glued; if (parent is CyPhy.Connector) { jd = CyPhyClasses.GluedJoin.Create(parent as CyPhy.Connector); } else { jd = CyPhyClasses.GluedJoin.CreateGeneric(parent) as CyPhy.GluedJoin; } } else if (join is mechanical) { var w = join as mechanical; if (parent is CyPhy.Connector) { jd = CyPhyClasses.MechanicalJoin.Create(parent as CyPhy.Connector); } else { jd = CyPhyClasses.MechanicalJoin.CreateGeneric(parent) as CyPhy.MechanicalJoin; } } else { continue; } jd.Attributes.Description = ad.id; rtn.Add(jd); } return(rtn); }