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; }
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; }
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; }
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; }