// Remove component from design void TestRemoveComponent() { SetupTest(); RunCyPhyMLSync( (project, propagate, interpreter) => { { MgaFCO assembly; project.BeginTransactionInNewTerr(); try { assembly = GetTestAssembly(project); } finally { project.AbortTransaction(); } interpreter.StartAssemblySync(project, assembly, 128); Application.DoEvents(); 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.REMOVE_CYPHY_DESIGN_COMPONENT, subjectID = testAssemblyId, payload = new Payload() }; action.payload.components.Add(new CADComponentType() { ComponentID = massInstanceGuid }); msg.actions.Add(action); propagate.EditMessageReceived(msg); Application.DoEvents(); } project.BeginTransactionInNewTerr(); try { var assembly = GetTestAssembly(project); var masscomp = assembly.ChildObjects.Cast <MgaFCO>().Where(fco => fco.Name.Equals(massName)); Xunit.Assert.Equal(0, masscomp.Count()); } finally { project.AbortTransaction(); } } ); }
private Edit CreateComponentEditMessage(string instanceId, CyPhyML.Component component, CyPhyML.CADModel cadModel) { string cadModelRelativePath = ""; if (false == cadModel.TryGetResourcePath(out cadModelRelativePath) || cadModelRelativePath == "") { // TODO log //return null; } var message = new Edit() { editMode = MetaLinkProtobuf.Edit.EditMode.POST, guid = Guid.NewGuid().ToString(), //sequence = 0, }; message.origin.Add(GMEOrigin); message.topic.Add(instanceId); edu.vanderbilt.isis.meta.Action action = new edu.vanderbilt.isis.meta.Action(); message.actions.Add(action); action.actionMode = MetaLinkProtobuf.Action.ActionMode.UPDATE_CAD_COMPONENT; action.subjectID = component.Attributes.AVMID; action.environment.Add(new edu.vanderbilt.isis.meta.Environment() { name = SearchPathStr, }); AddSearchPathToEnvironment(component, action.environment[0]); if (cadModelRelativePath.Length != 0) { action.payload = new Payload(); CADComponentType cadComponent = new CADComponentType() { AvmComponentID = component.Attributes.AVMID, CADModelID = CyphyMetaLinkUtils.GetResourceID(cadModel), // Using CADModelID to transport this information (the resource id) Name = Path.GetFileNameWithoutExtension(cadModelRelativePath), // the partial creo file name (less .prt or .asm) Type = (Path.GetExtension(cadModelRelativePath).EndsWith(".prt") || Path.GetExtension(cadModelRelativePath).EndsWith(".PRT")) ? "PART" : "ASSEMBLY" }; foreach (var connector in component.Children.ConnectorCollection) { cadComponent.Connectors.Add(new ConnectorType() { ID = connector.Guid.ToString(), DisplayName = connector.Name }); } foreach (var datum in cadModel.Children.CADDatumCollection) { cadComponent.Datums.Add(new ConnectorDatumType() { ID = datum.Attributes.DatumName, DisplayName = datum.Name }); } action.payload.components.Add(cadComponent); } return(message); }
// 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(); } } ); }
// Select component - only test that it won't fail void TestSelectComponent() { 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.SELECT_CYPHY_COMPONENT, payload = new Payload() }; action.payload.components.Add(new CADComponentType() { ComponentID = massInstanceGuid }); msg.actions.Add(action); propagate.EditMessageReceived(msg); Application.DoEvents(); } project.BeginTransactionInNewTerr(); try { // Nothing to check here } finally { project.AbortTransaction(); } } ); }
public void SendComponentManifest() { MetaLinkProtobuf.Edit manifestMessage = new MetaLinkProtobuf.Edit { editMode = Edit.EditMode.POST, }; manifestMessage.topic.Add(ComponentManifestTopic); var manifestAction = new MetaLinkProtobuf.Action(); manifestMessage.actions.Add(manifestAction); manifestAction.actionMode = MetaLinkProtobuf.Action.ActionMode.INSERT; var rf = CyPhyMLClasses.RootFolder.GetRootFolder(addon.Project); Queue<CyPhyML.Components> componentsQueue = new Queue<CyPhyML.Components>(); foreach (var childComponents in rf.Children.ComponentsCollection) { componentsQueue.Enqueue(childComponents); } while (componentsQueue.Count > 0) { var components = componentsQueue.Dequeue(); manifestAction.manifest.Add(new ComponentManifestNode() { nodeMode = ComponentManifestNode.NodeMode.FOLDER, guid = components.Guid.ToString("D"), name = components.Name }); foreach (var childComponents in components.Children.ComponentsCollection) { componentsQueue.Enqueue(childComponents); } foreach (var component in components.Children.ComponentCollection) { manifestAction.manifest.Add(new ComponentManifestNode() { nodeMode = ComponentManifestNode.NodeMode.COMPONENT, guid = component.Attributes.AVMID, cyphyParentId = components.Guid.ToString("D"), name = component.Name }); } } bridgeClient.SendToMetaLinkBridge(manifestMessage); }
//[Fact] void TestAssemblySyncConnect() { // TODO: this needs to be rewritten SetupTest(); SendInterest("0"); WaitToReceiveMessage(); RunCyPhyMLSync( (project, propagate, interpreter) => { MgaFCO CAD_debug; MgaFCO CAD_debug_copy; MgaFCO hierarchy_2; MgaFCO hookInstance; MgaFCO hookCopyInstance; MgaReference CAD_debug_ref; MgaReference hierarchy_1_ref; MgaReference hierarchy_1_ref_copy; project.BeginTransactionInNewTerr(); try { var filter = project.CreateFilter(); filter.Kind = "ComponentAssembly"; CAD_debug = project.AllFCOs(filter).Cast<MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyId).ToString("B")).First(); // FIXME this copy is no good, since CyPhyMetaLink can just create the connection in CAD_debug CAD_debug_copy = CAD_debug.ParentFolder.CopyFCODisp(CAD_debug); CAD_debug_copy.Name = CAD_debug.Name + "_copy"; hierarchy_2 = project.AllFCOs(filter).Cast<MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyHierarchy_2Id).ToString("B")).First(); //hullAndHookHookGuid = (string)((MgaModel)project.RootFolder.ObjectByPath[hullAndHookHookPath]).GetAttributeByNameDisp("AVMID"); hookInstance = CAD_debug.ChildObjects.Cast<MgaFCO>().Where(f => f.Name.Contains("drawbar")).First(); hierarchy_1_ref = (MgaReference)hierarchy_2.ChildObjectByRelID[1]; CAD_debug_ref = (MgaReference)((MgaModel)hierarchy_1_ref.Referred).ChildObjectByRelID[1]; hookCopyInstance = CAD_debug_copy.ChildObjects.Cast<MgaFCO>().Where(f => f.Name.Contains("drawbar")).First(); hierarchy_1_ref_copy = (MgaReference)((IMgaModel)hierarchy_2).CopyFCODisp((MgaFCO)hierarchy_1_ref, hierarchy_1_ref.MetaRole); hierarchy_1_ref_copy.Referred = CAD_debug_copy; } finally { project.CommitTransaction(); } Edit connectMsg; project.BeginTransactionInNewTerr(); try { string hookInstanceGuid; string hookCopyInstanceGuid; hookInstanceGuid = hookInstance.GetStrAttrByNameDisp("InstanceGUID"); hookCopyInstanceGuid = hookCopyInstance.GetStrAttrByNameDisp("InstanceGUID"); // CyPhyAddon should reassign this (during the last CommitTransaction) Xunit.Assert.NotEqual(hierarchy_1_ref.GetStrAttrByNameDisp("InstanceGUID"), hierarchy_1_ref_copy.GetStrAttrByNameDisp("InstanceGUID")); Xunit.Assert.NotEqual(hookInstanceGuid, hookCopyInstanceGuid); connectMsg = new Edit(); connectMsg.mode.Add(Edit.EditMode.POST); connectMsg.origin.Add(origin); connectMsg.topic.Add("0"); var action = new edu.vanderbilt.isis.meta.Action(); action.actionMode = edu.vanderbilt.isis.meta.Action.ActionMode.REMOVE_CYPHY_DESIGN_COMPONENT; action.payload = new Payload(); action.payload.components.Add(new CADComponentType() { ComponentID = Guid.Parse(hierarchy_2.GetGuidDisp()).ToString() }); action.payload.components.Add(new CADComponentType() { ComponentID = "2e1091d6-989e-4130-bfed-c046ef0f7011" + "_" + hierarchy_1_ref.GetStrAttrByNameDisp("InstanceGUID") + CAD_debug_ref.GetStrAttrByNameDisp("InstanceGUID") + hookInstanceGuid }); action.payload.components.Add(new CADComponentType() { ComponentID = "2e1091d6-989e-4130-bfed-c046ef0f7011" + "_" + hierarchy_1_ref_copy.GetStrAttrByNameDisp("InstanceGUID") + hookCopyInstanceGuid }); connectMsg.actions.Add(action); } finally { project.CommitTransaction(); } interpreter.StartAssemblySync(project, hierarchy_2, 128); Application.DoEvents(); SendToMetaLinkBridgeAndWaitForAddonToReceive(connectMsg); WaitForAllMetaLinkMessages(); Application.DoEvents(); Thread.Sleep(1000); // XXX don't race with propagate's send message thread WaitForAllMetaLinkMessages(); project.BeginTransactionInNewTerr(); try { Xunit.Assert.Equal((int)objectstatus_enum.OBJECT_DELETED, hookInstance.Status); } finally { project.AbortTransaction(); } } ); }
void TestAssemblySyncDiscardComponent() { SetupTest(); RunCyPhyMLSync( (project, propagate, interpreter) => { MgaFCO testAssembly; MgaFCO testAssemblyHierarchy_2; MgaFCO componentInstance; string componentInstanceGuid; string testHierarchy_1RefId; string testAssemblyRefId; project.BeginTransactionInNewTerr(); try { var filter = project.CreateFilter(); filter.Kind = "ComponentAssembly"; testAssembly = project.AllFCOs(filter).Cast<MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyId).ToString("B")).First(); testAssemblyHierarchy_2 = project.AllFCOs(filter).Cast<MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyHierarchy_2Id).ToString("B")).First(); //hullAndHookHookGuid = (string)((MgaModel)project.RootFolder.ObjectByPath[hullAndHookHookPath]).GetAttributeByNameDisp("AVMID"); componentInstance = testAssembly.ChildObjects.Cast<MgaFCO>().Where(f => f.Name.Contains("Damper")).First(); componentInstanceGuid = componentInstance.GetStrAttrByNameDisp("InstanceGUID"); MgaReference testHierarchy_1Ref = testAssemblyHierarchy_2.ChildObjects.Cast<MgaFCO>().OfType<MgaReference>().First(); testHierarchy_1RefId = new Guid(testHierarchy_1Ref.GetGuidDisp()).ToString("B"); MgaReference testAssemblyRef = ((MgaModel)testHierarchy_1Ref.Referred).ChildObjects.Cast<MgaFCO>().OfType<MgaReference>().First(); testAssemblyRefId = new Guid(testAssemblyRef.GetGuidDisp()).ToString("B"); } finally { project.AbortTransaction(); } interpreter.StartAssemblySync(project, testAssemblyHierarchy_2, 128); Application.DoEvents(); var msg = new Edit(); msg.mode.Add(Edit.EditMode.POST); msg.origin.Add(origin); msg.topic.Add((CyPhyMetaLinkAddon.IdCounter-1).ToString()); var action = new edu.vanderbilt.isis.meta.Action(); action.actionMode = edu.vanderbilt.isis.meta.Action.ActionMode.REMOVE_CYPHY_DESIGN_COMPONENT; action.subjectID = testAssemblyHierarchy_2Id; action.payload = new Payload(); action.payload.components.Add(new CADComponentType() { //ComponentID = hookInstanceGuid, ComponentID = testHierarchy_1RefId + testAssemblyRefId + componentInstanceGuid }); msg.actions.Add(action); SendToMetaLinkBridgeAndWaitForAddonToReceive(msg); WaitForAllMetaLinkMessages(); Application.DoEvents(); project.BeginTransactionInNewTerr(); try { Xunit.Assert.Equal((int)objectstatus_enum.OBJECT_DELETED, componentInstance.Status); } finally { project.AbortTransaction(); } } ); }
// Remove component from design void TestRemoveComponent() { 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(CyPhyMetaLink.CyPhyMetaLinkAddon.CadAssemblyTopic); msg.topic.Add(testAssemblyId); edu.vanderbilt.isis.meta.Action action = new edu.vanderbilt.isis.meta.Action() { actionMode = edu.vanderbilt.isis.meta.Action.ActionMode.DISCARD, payload = new Payload() }; action.payload.components.Add(new CADComponentType() { ComponentID = massInstanceGuid }); msg.actions.Add(action); propagate.EditMessageReceived(msg); Application.DoEvents(); } project.BeginTransactionInNewTerr(); try { var assembly = GetTestAssembly(project); var masscomp = assembly.ChildObjects.Cast<MgaFCO>().Where(fco => fco.Name.Equals(massName)); Xunit.Assert.Equal(0, masscomp.Count()); } finally { project.AbortTransaction(); } } ); }
public MetaLinkProtobuf.Edit UpdateComponentNameProtoBufMsg(CyPhyML.ComponentRef componentRef, string newName) { MetaLinkProtobuf.CADComponentType Component_msg = new MetaLinkProtobuf.CADComponentType { ComponentID = componentRef.Attributes.InstanceGUID, DisplayName = componentRef.Name }; MetaLinkProtobuf.Payload Payload_msg = new MetaLinkProtobuf.Payload(); Payload_msg.components.Add(Component_msg); MetaLinkProtobuf.Action Action_msg = new MetaLinkProtobuf.Action { actionMode = MetaLinkProtobuf.Action.ActionMode.UPDATE, payload = Payload_msg }; MetaLinkProtobuf.Edit Edit_msg = new MetaLinkProtobuf.Edit { editMode = MetaLinkProtobuf.Edit.EditMode.POST, guid = Guid.NewGuid().ToString(), sequence = 0, }; Edit_msg.origin.Add(GMEOrigin); Edit_msg.actions.Add(Action_msg); Edit_msg.topic.Add(CadAssemblyTopic); Edit_msg.topic.Add(AssemblyID); return Edit_msg; }
protected MetaLinkProtobuf.Edit CreateAddConstraintProtoBufMsg(string in_ComponentInstanceID, List<Tuple<CyPhy2CAD_CSharp.DataRep.Datum, CyPhy2CAD_CSharp.DataRep.Datum>> constraintPairs) { MetaLinkProtobuf.Payload Payload_msg = new MetaLinkProtobuf.Payload(); MetaLinkProtobuf.ConstraintType Constraint_msg = new MetaLinkProtobuf.ConstraintType() { ComponentID = in_ComponentInstanceID }; foreach (Tuple<CyPhy2CAD_CSharp.DataRep.Datum, CyPhy2CAD_CSharp.DataRep.Datum> element in constraintPairs) { MetaLinkProtobuf.PairType PairType_msg = new MetaLinkProtobuf.PairType { ConstraintFeatureA = new MetaLinkProtobuf.ConstraintFeatureType { ComponentID = element.Item1.ComponentID, FeatureName = element.Item1.DatumName, FeatureOrientationType = element.Item1.Orientation }, ConstraintFeatureB = new MetaLinkProtobuf.ConstraintFeatureType { ComponentID = element.Item2.ComponentID, FeatureName = element.Item2.DatumName, FeatureOrientationType = element.Item2.Orientation }, FeatureAlignmentType = element.Item1.Alignment, FeatureGeometryType = element.Item1.Type.ToString().ToUpper(), // need to add namespace to DatumType FeatureInterfaceType = "CAD_DATUM" }; Constraint_msg.Pair.Add(PairType_msg); } Payload_msg.constraints.Add(Constraint_msg); MetaLinkProtobuf.Action Action_msg = new MetaLinkProtobuf.Action { actionMode = MetaLinkProtobuf.Action.ActionMode.REPLACE, payload = Payload_msg }; MetaLinkProtobuf.Edit Edit_msg = new MetaLinkProtobuf.Edit { editMode = MetaLinkProtobuf.Edit.EditMode.POST, guid = Guid.NewGuid().ToString(), sequence = 0, }; Edit_msg.origin.Add(GMEOrigin); Edit_msg.actions.Add(Action_msg); Edit_msg.topic.Add(CadAssemblyTopic); Edit_msg.topic.Add(AssemblyID); return Edit_msg; }
private Edit CreateComponentEditMessage(string instanceId, CyPhyML.Component component, CyPhyML.CADModel cadModel) { string cadModelRelativePath = ""; if (false == cadModel.TryGetResourcePath(out cadModelRelativePath) || cadModelRelativePath == "") { // TODO log //return null; } var message = new Edit() { editMode = MetaLinkProtobuf.Edit.EditMode.POST, guid = Guid.NewGuid().ToString(), //sequence = 0, }; message.origin.Add(GMEOrigin); message.topic.Add(instanceId); edu.vanderbilt.isis.meta.Action action = new edu.vanderbilt.isis.meta.Action(); message.actions.Add(action); action.actionMode = MetaLinkProtobuf.Action.ActionMode.UPDATE_CAD_COMPONENT; action.subjectID = component.Attributes.AVMID; action.environment.Add(new edu.vanderbilt.isis.meta.Environment() { name = SearchPathStr, }); AddSearchPathToEnvironment(component, action.environment[0]); if (cadModelRelativePath.Length != 0) { action.payload = new Payload(); CADComponentType cadComponent = new CADComponentType() { AvmComponentID = component.Attributes.AVMID, CADModelID = CyphyMetaLinkUtils.GetResourceID(cadModel), // Using CADModelID to transport this information (the resource id) Name = Path.GetFileNameWithoutExtension(cadModelRelativePath), // the partial creo file name (less .prt or .asm) Type = (Path.GetExtension(cadModelRelativePath).EndsWith(".prt") || Path.GetExtension(cadModelRelativePath).EndsWith(".PRT")) ? "PART" : "ASSEMBLY" }; foreach (var connector in component.Children.ConnectorCollection) { cadComponent.Connectors.Add(new ConnectorType() { ID = connector.Guid.ToString(), DisplayName = connector.Name }); } foreach (var datum in cadModel.Children.CADDatumCollection) { cadComponent.Datums.Add(new ConnectorDatumType() { ID = datum.Attributes.DatumName, DisplayName = datum.Name }); } action.payload.components.Add(cadComponent); } return message; }
//[Fact] void TestAssemblySyncConnect() { // TODO: this needs to be rewritten SetupTest(); SendInterest("0"); WaitToReceiveMessage(); RunCyPhyMLSync( (project, propagate, interpreter) => { MgaFCO CAD_debug; MgaFCO CAD_debug_copy; MgaFCO hierarchy_2; MgaFCO hookInstance; MgaFCO hookCopyInstance; MgaReference CAD_debug_ref; MgaReference hierarchy_1_ref; MgaReference hierarchy_1_ref_copy; project.BeginTransactionInNewTerr(); try { var filter = project.CreateFilter(); filter.Kind = "ComponentAssembly"; CAD_debug = project.AllFCOs(filter).Cast <MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyId).ToString("B")).First(); // FIXME this copy is no good, since CyPhyMetaLink can just create the connection in CAD_debug CAD_debug_copy = CAD_debug.ParentFolder.CopyFCODisp(CAD_debug); CAD_debug_copy.Name = CAD_debug.Name + "_copy"; hierarchy_2 = project.AllFCOs(filter).Cast <MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyHierarchy_2Id).ToString("B")).First(); //hullAndHookHookGuid = (string)((MgaModel)project.RootFolder.ObjectByPath[hullAndHookHookPath]).GetAttributeByNameDisp("AVMID"); hookInstance = CAD_debug.ChildObjects.Cast <MgaFCO>().Where(f => f.Name.Contains("drawbar")).First(); hierarchy_1_ref = (MgaReference)hierarchy_2.ChildObjectByRelID[1]; CAD_debug_ref = (MgaReference)((MgaModel)hierarchy_1_ref.Referred).ChildObjectByRelID[1]; hookCopyInstance = CAD_debug_copy.ChildObjects.Cast <MgaFCO>().Where(f => f.Name.Contains("drawbar")).First(); hierarchy_1_ref_copy = (MgaReference)((IMgaModel)hierarchy_2).CopyFCODisp((MgaFCO)hierarchy_1_ref, hierarchy_1_ref.MetaRole); hierarchy_1_ref_copy.Referred = CAD_debug_copy; } finally { project.CommitTransaction(); } Edit connectMsg; project.BeginTransactionInNewTerr(); try { string hookInstanceGuid; string hookCopyInstanceGuid; hookInstanceGuid = hookInstance.GetStrAttrByNameDisp("InstanceGUID"); hookCopyInstanceGuid = hookCopyInstance.GetStrAttrByNameDisp("InstanceGUID"); // CyPhyAddon should reassign this (during the last CommitTransaction) Xunit.Assert.NotEqual(hierarchy_1_ref.GetStrAttrByNameDisp("InstanceGUID"), hierarchy_1_ref_copy.GetStrAttrByNameDisp("InstanceGUID")); Xunit.Assert.NotEqual(hookInstanceGuid, hookCopyInstanceGuid); connectMsg = new Edit(); connectMsg.mode.Add(Edit.EditMode.POST); connectMsg.origin.Add(origin); connectMsg.topic.Add("0"); var action = new edu.vanderbilt.isis.meta.Action(); action.actionMode = edu.vanderbilt.isis.meta.Action.ActionMode.REMOVE_CYPHY_DESIGN_COMPONENT; action.payload = new Payload(); action.payload.components.Add(new CADComponentType() { ComponentID = Guid.Parse(hierarchy_2.GetGuidDisp()).ToString() }); action.payload.components.Add(new CADComponentType() { ComponentID = "2e1091d6-989e-4130-bfed-c046ef0f7011" + "_" + hierarchy_1_ref.GetStrAttrByNameDisp("InstanceGUID") + CAD_debug_ref.GetStrAttrByNameDisp("InstanceGUID") + hookInstanceGuid }); action.payload.components.Add(new CADComponentType() { ComponentID = "2e1091d6-989e-4130-bfed-c046ef0f7011" + "_" + hierarchy_1_ref_copy.GetStrAttrByNameDisp("InstanceGUID") + hookCopyInstanceGuid }); connectMsg.actions.Add(action); } finally { project.CommitTransaction(); } interpreter.StartAssemblySync(project, hierarchy_2, 128); Application.DoEvents(); SendToMetaLinkBridgeAndWaitForAddonToReceive(connectMsg); WaitForAllMetaLinkMessages(); Application.DoEvents(); Thread.Sleep(1000); // XXX don't race with propagate's send message thread WaitForAllMetaLinkMessages(); project.BeginTransactionInNewTerr(); try { Xunit.Assert.Equal((int)objectstatus_enum.OBJECT_DELETED, hookInstance.Status); } finally { project.AbortTransaction(); } } ); }
void TestAssemblySyncDiscardComponent() { SetupTest(); RunCyPhyMLSync( (project, propagate, interpreter) => { MgaFCO testAssembly; MgaFCO testAssemblyHierarchy_2; MgaFCO componentInstance; string componentInstanceGuid; string testHierarchy_1RefId; string testAssemblyRefId; project.BeginTransactionInNewTerr(); try { var filter = project.CreateFilter(); filter.Kind = "ComponentAssembly"; testAssembly = project.AllFCOs(filter).Cast <MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyId).ToString("B")).First(); testAssemblyHierarchy_2 = project.AllFCOs(filter).Cast <MgaFCO>() .Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyHierarchy_2Id).ToString("B")).First(); //hullAndHookHookGuid = (string)((MgaModel)project.RootFolder.ObjectByPath[hullAndHookHookPath]).GetAttributeByNameDisp("AVMID"); componentInstance = testAssembly.ChildObjects.Cast <MgaFCO>().Where(f => f.Name.Contains("Damper")).First(); componentInstanceGuid = componentInstance.GetStrAttrByNameDisp("InstanceGUID"); MgaReference testHierarchy_1Ref = testAssemblyHierarchy_2.ChildObjects.Cast <MgaFCO>().OfType <MgaReference>().First(); testHierarchy_1RefId = new Guid(testHierarchy_1Ref.GetGuidDisp()).ToString("B"); MgaReference testAssemblyRef = ((MgaModel)testHierarchy_1Ref.Referred).ChildObjects.Cast <MgaFCO>().OfType <MgaReference>().First(); testAssemblyRefId = new Guid(testAssemblyRef.GetGuidDisp()).ToString("B"); } finally { project.AbortTransaction(); } interpreter.StartAssemblySync(project, testAssemblyHierarchy_2, 128); Application.DoEvents(); // wait for metalink bridge to record addon's interest in assembly while (true) { string line; if (metalinkOutput.TryTake(out line, 5000) == false) { throw new TimeoutException("Timed out waiting for metalink bridge to log 'interest recorded'"); } if (line.Contains("interest recorded")) { break; } } var msg = new Edit(); msg.mode.Add(Edit.EditMode.POST); msg.origin.Add(origin); msg.topic.Add((CyPhyMetaLinkAddon.IdCounter - 1).ToString()); var action = new edu.vanderbilt.isis.meta.Action(); action.actionMode = edu.vanderbilt.isis.meta.Action.ActionMode.REMOVE_CYPHY_DESIGN_COMPONENT; action.subjectID = testAssemblyHierarchy_2Id; action.payload = new Payload(); action.payload.components.Add(new CADComponentType() { //ComponentID = hookInstanceGuid, ComponentID = testHierarchy_1RefId + testAssemblyRefId + componentInstanceGuid }); msg.actions.Add(action); SendToMetaLinkBridgeAndWaitForAddonToReceive(msg); WaitForAllMetaLinkMessages(); Application.DoEvents(); project.BeginTransactionInNewTerr(); try { Xunit.Assert.Equal((int)objectstatus_enum.OBJECT_DELETED, componentInstance.Status); } finally { project.AbortTransaction(); } } ); }
public void SendCadAssemblyXml(string xml, string assemblyGuid, bool clear) { MetaLinkProtobuf.Edit message = new MetaLinkProtobuf.Edit { editMode = Edit.EditMode.POST, }; message.topic.Add(CadAssemblyTopic); message.topic.Add(assemblyGuid); if (clear) { message.actions.Add(new edu.vanderbilt.isis.meta.Action() { actionMode = MetaLinkProtobuf.Action.ActionMode.CLEAR }); } var action = new MetaLinkProtobuf.Action(); message.actions.Add(action); action.actionMode = MetaLinkProtobuf.Action.ActionMode.INSERT; MetaLinkProtobuf.Alien alien = new MetaLinkProtobuf.Alien(); action.alien = alien; alien.encoded = Encoding.UTF8.GetBytes(xml); alien.encodingMode = Alien.EncodingMode.XML; CyPhyML.ComponentAssembly targetAssembly = CyphyMetaLinkUtils.GetComponentAssemblyByGuid(addon.Project, assemblyGuid); if (targetAssembly != null) { var filter = targetAssembly.Impl.Project.CreateFilter(); filter.Kind = "ComponentRef"; try { var env = new MetaLinkProtobuf.Environment { name = SearchPathStr, }; foreach (var component in CyphyMetaLinkUtils.CollectComponentsRecursive(targetAssembly)) { if (component is CyPhyML.Component) AddSearchPathToEnvironment(component as CyPhyML.Component, env); } if (env.value.Count > 0) { action.environment.Add(env); } } catch (IOException) { // XXX } } bridgeClient.SendToMetaLinkBridge(message); }
// 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(); } } ); }
private void ProcessAVMComponentCreate(string component_xml, string topic) { try { File.WriteAllText(Path.Combine(Path.GetTempPath(), "CyPhyMetaLink_ComponentCreate.xml"), component_xml); } catch (IOException) { } XmlDocument doc = new XmlDocument(); doc.LoadXml(component_xml); XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable); manager.AddNamespace("avm", "avm"); manager.AddNamespace("cad", "cad"); avm.Component component = CyPhyComponentImporter.CyPhyComponentImporterInterpreter.DeserializeAvmComponentXml(new StringReader(doc.OuterXml)); addon.Project.BeginTransactionInNewTerr(); CyPhyML.Component createdComp = null; string createdavmid = null; try { var rf = CyPhyMLClasses.RootFolder.GetRootFolder(addon.Project); CyPhyML.Components importedComponents = CyphyMetaLinkUtils.GetImportedComponentsFolder(addon.Project); if (importedComponents == null) { importedComponents = CyPhyMLClasses.Components.Create(rf); importedComponents.Name = CyPhyComponentImporter.CyPhyComponentImporterInterpreter.ImportedComponentsFolderName; } var avmidComponentMap = CyPhyComponentImporter.CyPhyComponentImporterInterpreter.getCyPhyMLComponentDictionary_ByAVMID(rf); createdComp = CyPhy2ComponentModel.Convert.AVMComponent2CyPhyML(importedComponents, component, true, GMEConsole); // Ricardo requirement: Classification must not be empy if (createdComp.Attributes.Classifications.Length == 0) createdComp.Attributes.Classifications = "Unknown"; List<string> notcopied = new List<string>(); CopyResources(Path.Combine(GetProjectDir(), createdComp.GetDirectoryPath(), "CAD\\"), doc, manager, notcopied, false); CyPhyML.CADModel cadModel = createdComp.Children.CADModelCollection.First(); // Ricardo requirement: ID must be cad.path if (cadModel.SrcConnections.UsesResourceCollection.Any() && cadModel.SrcConnections.UsesResourceCollection.First().DstEnds.Resource != null) { cadModel.SrcConnections.UsesResourceCollection.First().DstEnds.Resource.Attributes.ID = "cad.path"; } else if (cadModel.DstConnections.UsesResourceCollection.Any() && cadModel.DstConnections.UsesResourceCollection.First().DstEnds.Resource != null) { cadModel.DstConnections.UsesResourceCollection.First().DstEnds.Resource.Attributes.ID = "cad.path"; } foreach (var res in createdComp.Children.ResourceCollection) { res.Attributes.Path = Path.Combine("CAD", res.Name); } CyphyMetaLinkUtils.SetCADModelTypesFromFilenames(createdComp); RefreshManufacturingResources(createdComp, Path.Combine(createdComp.GetDirectoryPath(), "Manufacturing")); createdavmid = createdComp.Attributes.AVMID; } finally { addon.Project.CommitTransaction(); } if (createdavmid != null && topic != null) { MetaLinkProtobuf.Edit Edit_msg = new MetaLinkProtobuf.Edit(){ editMode = Edit.EditMode.POST }; Edit_msg.topic.Add(CadPassiveTopic); Edit_msg.topic.Add(topic); MetaLinkProtobuf.Action action = new MetaLinkProtobuf.Action(){ actionMode = MetaLinkProtobuf.Action.ActionMode.SWITCH, interest = new Interest() }; action.interest.topic.Add(ComponentUpdateTopic); action.interest.uid.Add(createdavmid); Edit_msg.actions.Add(action); bridgeClient.SendToMetaLinkBridge(Edit_msg); SendInterest(null, ComponentUpdateTopic, createdavmid); } }
} // end function #region PROTOBUF protected MetaLinkProtobuf.Edit ModifyCADParameterProtoBufMsg(string in_ComponentInstanceID, CADParameter in_CADParameter) { MetaLinkProtobuf.ParametricParametersType ParametricParameters = new MetaLinkProtobuf.ParametricParametersType() { ComponentID = in_ComponentInstanceID }; MetaLinkProtobuf.CADParameterType CADParameter_msg = new MetaLinkProtobuf.CADParameterType { Name = in_CADParameter.Name, Type = in_CADParameter.Type, Value = in_CADParameter.Value }; ParametricParameters.CADParameter.Add(CADParameter_msg); MetaLinkProtobuf.Payload Payload_msg = new MetaLinkProtobuf.Payload(); Payload_msg.parameters.Add(ParametricParameters); MetaLinkProtobuf.Action Action_msg = new MetaLinkProtobuf.Action { actionMode = MetaLinkProtobuf.Action.ActionMode.REPLACE, payload = Payload_msg }; MetaLinkProtobuf.Edit Edit_msg = new MetaLinkProtobuf.Edit { editMode = MetaLinkProtobuf.Edit.EditMode.POST, guid = Guid.NewGuid().ToString(), sequence = 0, }; Edit_msg.origin.Add(GMEOrigin); Edit_msg.actions.Add(Action_msg); Edit_msg.topic.Add(CadAssemblyTopic); Edit_msg.topic.Add(AssemblyID); return Edit_msg; }
// Remove multiple components from design void TestRemoveComponents() { 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.REMOVE_CYPHY_DESIGN_COMPONENT, subjectID = testAssemblyId, payload = new Payload() }; action.payload.components.Add(new CADComponentType() { ComponentID = massInstanceGuid }); action.payload.components.Add(new CADComponentType() { ComponentID = springInstanceGuid }); msg.actions.Add(action); propagate.EditMessageReceived(msg); Application.DoEvents(); } project.BeginTransactionInNewTerr(); try { var assembly = GetTestAssembly(project); Xunit.Assert.Equal(1, assembly.ChildObjects.Cast<MgaFCO>().Where(fco => fco.MetaRole.Kind.Name=="ComponentRef").Count()); } finally { project.AbortTransaction(); } } ); }
public MetaLinkProtobuf.Edit AddComponentProtoBufMsg(CyPhyML.ComponentRef componentRef) { CyPhyML.Component component = componentRef.Referred.Component; CyPhyML.CADModel creocadmodel = null; string creomodelname = ""; string creomodeltype = ""; #if DEBUG GMEConsole.Info.WriteLine("AVM: " + component.Attributes.AVMID + " InstanceGUID: " + component.Attributes.InstanceGUID + " Rev: " + component.Attributes.Revision + " Ver: " + component.Attributes.Version); #endif creocadmodel = CyphyMetaLinkUtils.FindCADModelObject(component); if (creocadmodel == null) { GMEConsole.Warning.WriteLine("[" + component.Name + "] is missing a Creo CADModel object!"); return null; } // [1] List<CyPhyML.Resource> Resource_L = new List<CyPhyML.Resource>(); foreach (var item in creocadmodel.DstConnections.UsesResourceCollection) Resource_L.Add(item.DstEnds.Resource); foreach (var item in creocadmodel.SrcConnections.UsesResourceCollection) Resource_L.Add(item.SrcEnds.Resource); if (Resource_L.Count > 0) { creomodelname = Resource_L.First().Attributes.Path; } else { creomodelname = ""; #if DEBUG GMEConsole.Warning.WriteLine("[" + component.Name + "] is not connected to a Resource, therefore does not have a Creo model name."); #endif } if (creomodelname != "") creomodelname = Path.GetFileNameWithoutExtension(creomodelname); // [2] creomodeltype = creocadmodel.Attributes.FileType.ToString().ToUpper(); MetaLinkProtobuf.CADComponentType Component_msg = new MetaLinkProtobuf.CADComponentType { ComponentID = componentRef.Attributes.InstanceGUID, AvmComponentID = component.Attributes.AVMID, Type = creomodeltype, Name = creomodelname, ParametricParameters = new MetaLinkProtobuf.ParametricParametersType(), DisplayName = componentRef.Name }; // [4] InstanceIDToConstraint_Table[componentRef.Attributes.InstanceGUID] = 0; // [5] foreach (var param in creocadmodel.Children.CADParameterCollection) { MetaLinkProtobuf.CADParameterType CADParameter_msg = new MetaLinkProtobuf.CADParameterType { Name = (param.Attributes.ParameterName == "") ? param.Name : param.Attributes.ParameterName, Type = param.Attributes.CADParameterType.ToString(), Value = (param.Attributes.Value == "") ? (param.Attributes.DefaultValue == "") ? "0" : param.Attributes.DefaultValue : param.Attributes.Value }; Component_msg.ParametricParameters.CADParameter.Add(CADParameter_msg); } foreach (var connector in component.Children.ConnectorCollection) { Component_msg.Connectors.Add(new MetaLinkProtobuf.ConnectorType(){ ID = connector.Guid.ToString(), DisplayName = connector.Name }); } MetaLinkProtobuf.Payload Payload_msg = new MetaLinkProtobuf.Payload(); Payload_msg.components.Add(Component_msg); MetaLinkProtobuf.Action Action_msg = new MetaLinkProtobuf.Action { actionMode = MetaLinkProtobuf.Action.ActionMode.REPLACE, payload = Payload_msg }; MetaLinkProtobuf.Edit Edit_msg = new MetaLinkProtobuf.Edit { editMode = MetaLinkProtobuf.Edit.EditMode.POST, guid = Guid.NewGuid().ToString(), sequence = 0, }; Edit_msg.origin.Add(GMEOrigin); Edit_msg.actions.Add(Action_msg); Edit_msg.topic.Add(CadAssemblyTopic); Edit_msg.topic.Add(AssemblyID); return Edit_msg; }
public MetaLinkProtobuf.Edit UpdateComponentNameProtoBufMsg(CyPhyML.ComponentRef componentRef, string newName) { MetaLinkProtobuf.CADComponentType Component_msg = new MetaLinkProtobuf.CADComponentType { ComponentID = componentRef.Attributes.InstanceGUID, DisplayName = componentRef.Name }; MetaLinkProtobuf.Payload Payload_msg = new MetaLinkProtobuf.Payload(); Payload_msg.components.Add(Component_msg); MetaLinkProtobuf.Action Action_msg = new MetaLinkProtobuf.Action { actionMode = MetaLinkProtobuf.Action.ActionMode.UPDATE_CYPHY_DESIGN, payload = Payload_msg }; MetaLinkProtobuf.Edit Edit_msg = new MetaLinkProtobuf.Edit { editMode = MetaLinkProtobuf.Edit.EditMode.POST, guid = Guid.NewGuid().ToString(), sequence = 0, }; Edit_msg.origin.Add(GMEOrigin); Edit_msg.actions.Add(Action_msg); SyncedComponentData cdata = syncedComponents[componentRef.ParentContainer.Guid.ToString()]; Edit_msg.topic.Add(cdata.InstanceId); return Edit_msg; }