/// <summary> /// Runs the Component Assembly exporter. Exports CWC configurations into Component Assemblies. /// </summary> /// <param name="cwcs">Set of CWCs to export.</param> /// <returns>Exported Component Assembly references.</returns> public IEnumerable <MgaReference> RunCAExporter(IEnumerable <MgaFCO> cwcs) { if (cwcs == null) { throw new ArgumentNullException("cwcs"); } List <MgaReference> exportedConfigurations = new List <MgaReference>(); if (cwcs.Any()) { IMgaComponentEx componentAssemblyExporter = (IMgaComponentEx)Activator.CreateInstance(Type.GetTypeFromProgID("MGA.Interpreter.CyPhyCAExporter")); MgaFCOs selected = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); foreach (MgaFCO cwc in cwcs) { selected.Append(cwc); } componentAssemblyExporter.Initialize(cwcs.First().Project); componentAssemblyExporter.InvokeEx(cwcs.First().Project, cwcs.First().ParentModel as MgaFCO, selected, 128); var traceability = (CyPhyCOMInterfaces.IMgaTraceability)componentAssemblyExporter.ComponentParameter["traceability"]; traceability.CopyTo(Traceability); foreach (MgaFCO cwc in cwcs) { foreach (MgaConnPoint cp in cwc.PartOfConns) { MgaSimpleConnection configuration2ComponentAssembly = cp.Owner as MgaSimpleConnection; exportedConfigurations.Add(configuration2ComponentAssembly.Dst as MgaReference); } } } return(exportedConfigurations); }
public static void RunDSRefactorer(MgaFCO currentobj, List <MgaFCO> selected, String refactoredType) { // create interpreter type Type typeInterpreter = Type.GetTypeFromProgID("MGA.Interpreter.CyphyDesignSpaceRefactor"); IMgaComponentEx dsRefactorInterpreter = Activator.CreateInstance(typeInterpreter) as IMgaComponentEx; // empty selected object set Type typeMgaFCOs = Type.GetTypeFromProgID("Mga.MgaFCOs"); MgaFCOs selectedObjs = Activator.CreateInstance(typeMgaFCOs) as MgaFCOs; foreach (MgaFCO fco in selected) { selectedObjs.Append(fco); } // initialize interpreter dsRefactorInterpreter.Initialize(currentobj.Project); // automation means no UI element shall be shown by the interpreter dsRefactorInterpreter.ComponentParameter["automation"] = "true"; dsRefactorInterpreter.ComponentParameter["refactored_type_or_action"] = refactoredType; // do not write to the console dsRefactorInterpreter.ComponentParameter["console_messages"] = "off"; // do not expand nor collapse the model dsRefactorInterpreter.ComponentParameter["expanded"] = "true"; // call the formula evaluator and update all parameters starting from the current object dsRefactorInterpreter.InvokeEx(currentobj.Project, currentobj, selectedObjs, 16); }
public void DesertTestBase(MgaProject project, string dsPath, Action <IEnumerable <Configurations> > helperTest, Action <Configurations> exporterTest) { var gateway = new MgaGateway(project); Type desertType = Type.GetTypeFromProgID("MGA.Interpreter.DesignSpaceHelper"); var desert = (IMgaComponentEx)Activator.CreateInstance(desertType); MgaFCO currentobj = null; gateway.PerformInTransaction(() => { currentobj = (MgaFCO)project.RootFolder.ObjectByPath[dsPath]; var configurations = ISIS.GME.Dsml.CyPhyML.Classes.DesignContainer.Cast(currentobj).Children.ConfigurationsCollection; foreach (var configuration in configurations) { configuration.Delete(); } }, abort: false); Xunit.Assert.True(currentobj != null, string.Format("'{0}' does not exist in model", dsPath)); desert.Initialize(project); desert.InvokeEx(project, currentobj, null, 128); Configurations configs = null; gateway.PerformInTransaction(() => { var configurations = ISIS.GME.Dsml.CyPhyML.Classes.DesignContainer.Cast(currentobj).Children.ConfigurationsCollection; configs = configurations.First(); helperTest(configurations); }); if (exporterTest != null) { Type caExporterType = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyCAExporter"); var caExporter = (IMgaComponentEx)Activator.CreateInstance(caExporterType); gateway.PerformInTransaction(() => { MgaFCOs selected = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); foreach (MgaFCO cwc in configs.Children.CWCCollection.Select(x => (MgaFCO)x.Impl)) { selected.Append(cwc); } caExporter.Initialize(project); caExporter.InvokeEx(project, selected[1].ParentModel as MgaFCO, selected, 128); exporterTest(configs); }); } }
void referenceConnectionCopy() { foreach (IMgaConnection otherIMgaConnection in _iMgaConnectionSet) { IMgaModel otherIMgaConnectionParent = otherIMgaConnection.ParentModel; IMgaModel newIMgaConnectionParent = getCorrespondingIMgaFCO(otherIMgaConnectionParent) as IMgaModel; if (newIMgaConnectionParent == null) { Dictionary <string, IMgaFCO> nameTargetMap = new Dictionary <string, IMgaFCO>(); foreach (IMgaConnPoint otherIMgaConnPoint in otherIMgaConnection.ConnPoints) { nameTargetMap[otherIMgaConnPoint.ConnRole] = otherIMgaConnPoint.Target; } gmeConsole.Error.Write("Could not make connection between "); bool first = true; foreach (string key in nameTargetMap.Keys) { if (first) { first = false; } else { gmeConsole.Error.Write(", "); } gmeConsole.Error.Write("\"" + key + "\"=\"" + nameTargetMap[key].AbsPath + "\""); } gmeConsole.Error.Write(" in main model: Could not access parent (path: \"" + otherIMgaConnectionParent.AbsPath + "\")"); _exitStatus |= Errors.PathError; continue; } IMgaConnection newIMgaConnection = newIMgaConnectionParent.CreateChildObject(otherIMgaConnection.MetaRole) as IMgaConnection; foreach (IMgaConnPoint otherIMgaConnPointToCopy in otherIMgaConnection.ConnPoints) { IMgaFCO otherTarget = otherIMgaConnPointToCopy.Target; MgaFCO newTarget = getCorrespondingIMgaFCO(otherTarget) as MgaFCO; if (newTarget == null) { gmeConsole.Error.WriteLine("Could not find connection target of path \"" + otherTarget.AbsPath + "\" and role \"" + otherIMgaConnPointToCopy.ConnRole + "\" for connection of path \"" + newIMgaConnection.AbsPath + "\""); newIMgaConnection.DestroyObject(); newIMgaConnection = null; _exitStatus |= Errors.PathError; break; } MgaFCOs newMgaFCOs = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); bool referenceError = false; foreach (IMgaFCO otherReferenceIMgaFCO in otherIMgaConnPointToCopy.References) { IMgaFCO newReferenceIMgaFCO = getCorrespondingIMgaFCO(otherReferenceIMgaFCO); if (newReferenceIMgaFCO == null) { gmeConsole.Error.WriteLine("Could not make connection reference \"" + otherReferenceIMgaFCO.AbsPath + "\" for connection \"" + newIMgaConnection.AbsPath + "\", role \"" + otherIMgaConnPointToCopy.ConnRole + "\"."); newIMgaConnection.DestroyObject(); newIMgaConnection = null; referenceError = true; _exitStatus |= Errors.PathError; break; } newMgaFCOs.Append(newReferenceIMgaFCO as MgaFCO); } if (referenceError) { break; } MgaConnPoint newMgaConnPoint = null; newIMgaConnection.AddConnPoint(otherIMgaConnPointToCopy.ConnRole, 1, newTarget, newMgaFCOs, out newMgaConnPoint); } if (newIMgaConnection != null) { attributesAndRegistryCopy(newIMgaConnection, otherIMgaConnection); } } }
public void connectionCopy() { HashSet <IMgaConnection> otherIMgaConnectionSet = new HashSet <IMgaConnection>(); foreach (IMgaFCO otherIMgaFCO in _hasConnectionList) { IEnumerable <IMgaConnPoint> otherIMgaConnPoints = otherIMgaFCO.PartOfConns.Cast <IMgaConnPoint>(); if (otherIMgaFCO is IMgaReference) { otherIMgaConnPoints = otherIMgaConnPoints.Concat(((IMgaReference)otherIMgaFCO).UsedByConns .Cast <IMgaConnPoint>().Where(cp => cp.References[1] == otherIMgaFCO)); } IMgaFCO newIMgaFCO = getCorrespondingIMgaFCO(otherIMgaFCO); if (newIMgaFCO == null) { gmeConsole.Error.WriteLine("Could not make any connections to \"" + otherIMgaFCO.AbsPath + "\" in main model during merge: FCO not found."); _exitStatus |= Errors.PathError; continue; } // AT THIS POINT, NO CONNECTIONS SHOULD EXIST EXCEPT FOR CONNECTIONS THAT ARE INSTANCE/SUBTYPES foreach (IMgaConnPoint otherIMgaConnPoint in otherIMgaConnPoints) { if (otherIMgaConnPoint.References.Count > 0) { if (!_fcoMap.ContainsKey(otherIMgaConnPoint.References[1])) { continue; } } // GET ACTUAL CONNECTION IMgaConnection otherIMgaConnection = otherIMgaConnPoint.Owner; // ANY CONNECTIONS THAT ARE INSTANCES/SUBTYPES IN THE "OTHER" MODEL (I.E. ORIGINAL MODEL IN THE OTHER FILE) // MUST BE INSTANCES/SUBTYPES IN "NEW" MODEL. I.E. THEY ALREADY EXIST IN THE "NEW" MODEL, SO SKIP if (otherIMgaConnection.ArcheType != null) { continue; } // IF CONNECTION ALREADY PROCESSED, SKIP if (otherIMgaConnectionSet.Contains(otherIMgaConnection)) { continue; } otherIMgaConnectionSet.Add(otherIMgaConnection); _iMgaConnectionSet.Remove(otherIMgaConnection); IMgaModel otherIMgaConnectionParent = otherIMgaConnection.ParentModel; IMgaModel newIMgaConnectionParent = getCorrespondingIMgaFCO(otherIMgaConnectionParent) as IMgaModel; if (newIMgaConnectionParent == null) { gmeConsole.Error.WriteLine("Could not make connection to \"" + otherIMgaFCO.AbsPath + "\" in main model: Could not access parent (path: \"" + otherIMgaConnectionParent.AbsPath + "\")."); _exitStatus |= Errors.PathError; continue; } IMgaConnection newIMgaConnection = newIMgaConnectionParent.CreateChildObject(otherIMgaConnection.MetaRole) as IMgaConnection; foreach (IMgaConnPoint otherIMgaConnPointToCopy in otherIMgaConnection.ConnPoints) { IMgaFCO otherTarget = otherIMgaConnPointToCopy.Target; MgaFCO newTarget = getCorrespondingIMgaFCO(otherTarget) as MgaFCO; if (newTarget == null) { gmeConsole.Error.WriteLine("Could not find connection target of path \"" + otherTarget.AbsPath + "\" and role \"" + otherIMgaConnPointToCopy.ConnRole + "\" for connection of path \"" + newIMgaConnection.AbsPath + "\""); newIMgaConnection.DestroyObject(); newIMgaConnection = null; _exitStatus |= Errors.PathError; break; } MgaFCOs newMgaFCOs = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); bool referenceError = false; foreach (IMgaFCO otherReferenceIMgaFCO in otherIMgaConnPointToCopy.References) { IMgaFCO newReferenceIMgaFCO = getCorrespondingIMgaFCO(otherReferenceIMgaFCO); if (newReferenceIMgaFCO == null) { gmeConsole.Error.WriteLine("Could not make connection reference \"" + otherReferenceIMgaFCO.AbsPath + "\" for connection \"" + newIMgaConnection.AbsPath + "\", role \"" + otherIMgaConnPointToCopy.ConnRole + "\"."); newIMgaConnection.DestroyObject(); newIMgaConnection = null; referenceError = true; _exitStatus |= Errors.PathError; break; } newMgaFCOs.Append(newReferenceIMgaFCO as MgaFCO); } if (referenceError) { break; } MgaConnPoint newMgaConnPoint = null; newIMgaConnection.AddConnPoint(otherIMgaConnPointToCopy.ConnRole, 1, newTarget, newMgaFCOs, out newMgaConnPoint); } if (newIMgaConnection != null) { attributesAndRegistryCopy(newIMgaConnection, otherIMgaConnection); } } } }
//for any objects dependant on other objects //creates new connections and redirects src and dst //redirects references //redirects attachments for instances/subtypes private void directFCOs() { foreach (MgaFCO entry in oldSubsAndInstances) { //attach masters/slaves that changed parents MgaFCO arch = entry.ArcheType; if (oldToNewFCO.ContainsKey(entry.ArcheType)) { arch = oldToNewFCO[entry.ArcheType]; } if (oldToNewFCO.ContainsKey(entry)) { oldToNewFCO[entry].AttachToArcheType(arch, entry.IsInstance); } else { bool tmp = entry.IsInstance; entry.DetachFromArcheType(); entry.AttachToArcheType(arch, tmp); } //TODO: some recursive action with children, replace instanceSoln if (entry.IsInstance) { directInstance(entry); } } foreach (MgaFCO entry in oldConnsAndRefs) { MgaFCO curr = entry; if (entry is MgaConnection) { bool replaceConn = false; MgaModel parent = entry.ParentModel; MgaFCO src = (entry as IMgaSimpleConnection).Src; MgaFCO dst = (entry as IMgaSimpleConnection).Dst; MgaFCOs srcRefs = (entry as IMgaSimpleConnection).SrcReferences; MgaFCOs dstRefs = (entry as IMgaSimpleConnection).DstReferences; string role = entry.MetaRole.Name; //instanceSoln(parent as MgaFCO); //instanceSoln(src); //instanceSoln(dst); if (oldToNewFCO.ContainsKey(entry.ParentModel as MgaFCO)) { parent = oldToNewFCO[entry.ParentModel as MgaFCO] as MgaModel; replaceConn = true; } if (oldToNewFCO.ContainsKey((entry as IMgaSimpleConnection).Src)) { src = oldToNewFCO[(entry as IMgaSimpleConnection).Src]; replaceConn = true; } if (oldToNewFCO.ContainsKey((entry as IMgaSimpleConnection).Dst)) { dst = oldToNewFCO[(entry as IMgaSimpleConnection).Dst]; replaceConn = true; } if (srcRefs != null) { List <int> temp = new List <int>(); for (int i = srcRefs.Count; i > 0; --i) { //instanceSoln(srcRefs[i]); if (oldToNewFCO.ContainsKey(srcRefs[i])) { temp.Add(i); replaceConn = true; } } foreach (int i in temp) { srcRefs.Append(oldToNewFCO[srcRefs[i]]); } foreach (int i in temp) { srcRefs.Remove(i); } } if (dstRefs != null) { List <int> temp = new List <int>(); for (int i = dstRefs.Count; i > 0; --i) { //instanceSoln(dstRefs[i]); if (oldToNewFCO.ContainsKey(dstRefs[i])) { temp.Add(i); replaceConn = true; } } foreach (int i in temp) { dstRefs.Append(oldToNewFCO[dstRefs[i]]); } foreach (int i in temp) { dstRefs.Remove(i); } } if (oldToNewRole.ContainsKey(entry.MetaRole.Name)) { role = oldToNewRole[entry.MetaRole.Name]; replaceConn = true; } //special case (featuremap): if (entry.MetaRole.Name == "FeatureMap") { if (((entry as IMgaSimpleConnection).Src.ParentModel.MetaRole.Name == "CADModel" && (entry as IMgaSimpleConnection).Src.MetaRole.Name == "SurfaceGeometry" && (entry as IMgaSimpleConnection).Src.get_StrAttrByName("Orientation") != "SIDE_A") || ((entry as IMgaSimpleConnection).Dst.ParentModel.MetaRole.Name == "CADModel" && (entry as IMgaSimpleConnection).Dst.MetaRole.Name == "SurfaceGeometry" && (entry as IMgaSimpleConnection).Dst.get_StrAttrByName("Orientation") != "SIDE_A")) { role = "SurfaceReverseMap"; replaceConn = true; } } if (replaceConn) { try{ MgaFCO newConn = makeConn(parent, src, dst, role, srcRefs, dstRefs); oldToNewFCO.Add(entry, newConn); if (entry.Name != entry.MetaRole.Name && entry.Name != entry.Meta.Name && entry.Name != entry.Meta.DisplayedName) //name default?? { newConn.Name = entry.Name; } copyFCO(entry, newConn); } catch (Exception ex) { GMEConsole.Error.WriteLine( "Exception creating connection in <a href=\"mga:{0}\">{1}</a> between <a href=\"mga:{2}\">{3}</a> and <a href=\"mga:{4}\">{5}</a>: {6}", parent.ID, parent.Name, src.ID, src.Name, dst.ID, dst.Name, ex.Message ); } } } else if (entry is MgaReference) { if (oldToNewFCO.ContainsKey(entry)) { curr = oldToNewFCO[entry]; (curr as MgaReference).Referred = (entry as MgaReference).Referred; } if ((entry as MgaReference).Referred != null && oldToNewFCO.ContainsKey((entry as MgaReference).Referred)) { (curr as MgaReference).Referred = oldToNewFCO[(entry as MgaReference).Referred]; } } } }