/* * private void FindMatchingSolidModelingFeatures(CyPhy.CADDatum datum, * CyPhy.CADModel acadmodel) * { * // META-947: Creates a virtual connector * * Dictionary<string, DataRep.Datum> featuremap = new Dictionary<string, DataRep.Datum>(); * FindMatchingDatums(datum, * acadmodel, * featuremap); * * if (featuremap.Count > 0) * { * // virtual connector * DataRep.StructuralInterfaceConstraint sirep = new StructuralInterfaceConstraint(datum, this.Id); * sirep.DatumList = featuremap; * sirep.DegreeFreedom = sirep.GetDegreesOfFreedom(); * StructuralInterfaceNodes[datum.ID] = sirep; * } * } * * private void FindMatchingSolidModelingFeatures(CyPhy.Connector a, * CyPhy.CADModel acadmodel) * { * // META-947: Connector instead of StructuralInterface * // [1] Connectors can be nested so find all cad datums within a connector recursively * // [2] Find connected datums * // Skip Connector without any Datum Ports * * List<CyPhy.CADDatum> CadDatum_List = new List<CyPhy.CADDatum>(); * FindCadDatumsInConnector(a, CadDatum_List); * * Dictionary<string, DataRep.Datum> featuremap = new Dictionary<string, DataRep.Datum>(); * * if (CadDatum_List.Count() > 0) * { * foreach (CyPhy.CADDatum item in CadDatum_List) * { * FindMatchingDatums(item, * acadmodel, * featuremap); * } * * } * * if (featuremap.Count > 0) * { * DataRep.StructuralInterfaceConstraint sirep = new StructuralInterfaceConstraint(a, this.Id); * sirep.DatumList = featuremap; * sirep.DegreeFreedom = sirep.GetDegreesOfFreedom(); * StructuralInterfaceNodes[a.ID] = sirep; * } * } * * * private void FindMatchingDatums(CyPhy.CADDatum datum, * CyPhy.CADModel cadmodel, * Dictionary<string, DataRep.Datum> featuremap) * { * string cadmodel_id = cadmodel.ID; * string alignment = "ALIGN"; * string orientation = "NONE"; * * * if (datum.Kind == "Surface") * { * alignment = (datum as CyPhy.Surface).Attributes.Alignment.ToString(); * } * * CadDatumTraversal traversal = new CadDatumTraversal(datum, * cadmodel_id); * * if (traversal.datumFound.Count > 0) * { * if (traversal.datumFound.Count > 1) * { * Logger.Instance.AddLogMessage("Connector datum connected to multiple datums in the same CADModel [" + datum.Path + "]", Severity.Error); * return; * } * * CyPhy2CAD_CSharp.DataRep.Datum datumRep = new DataRep.Datum(traversal.datumFound.First().Attributes.DatumName, * datum.Kind, * this.DisplayID); * if (datum.Kind == "Surface") * { * if (traversal.ReverseMap) * orientation = "SIDE_B"; * else * orientation = "SIDE_A"; * } * * if (datum.Kind == "CoordinateSystem") * { * alignment = "CSYS"; * } * * datumRep.Alignment = alignment; * datumRep.Orientation = orientation; * * if (!featuremap.ContainsKey(datum.Name)) * { * featuremap[datum.Name] = datumRep; * } * } * } * * // Connectors can be nested! * private void FindCadDatumsInConnector(CyPhy.Connector connector, * List<CyPhy.CADDatum> caddatum_list) * { * caddatum_list.AddRange(connector.Children.CADDatumCollection); * * //foreach (CyPhy.Connector conn in connector.Children.ConnectorCollection) * //{ * // FindCadDatumsInConnector(conn, caddatum_list); * //} * * } */ public CAD.CADComponentType ToCADXMLOutput(string representation) { CAD.CADComponentType cadoutput = new CAD.CADComponentType(); cadoutput._id = UtilityHelpers.MakeUdmID(); cadoutput.Type = ModelType.ToUpper(); cadoutput.Standalone = false; cadoutput.SpecialInstruction = Size2Fit ? "SIZE_TO_FIT" : ""; if (!String.IsNullOrEmpty(SpecialInstructions)) { cadoutput.SpecialInstruction += (cadoutput.SpecialInstruction.Length != 0 ? "," : "") + SpecialInstructions; } cadoutput.Name = String.IsNullOrEmpty(ModelName) ? "" : ModelName; cadoutput.DisplayName = Name; cadoutput.MaterialID = MaterialName; cadoutput.ComponentID = DisplayID; cadoutput.Classification = Classification; if (CadParameters.Any()) { CAD.ParametricParametersType parameterRoot = new CAD.ParametricParametersType(); parameterRoot._id = UtilityHelpers.MakeUdmID(); List <CAD.CADParameterType> paramarray = new List <CAD.CADParameterType>(); foreach (var item in CadParameters) { CAD.CADParameterType parameter = new CAD.CADParameterType(); parameter._id = UtilityHelpers.MakeUdmID(); parameter.Type = item.Type; parameter.Name = item.Name; parameter.Value = item.Value; parameter.Units = new CAD.UnitsType(); parameter.Units._id = UtilityHelpers.MakeUdmID(); parameter.Units.Value = item.Unit; paramarray.Add(parameter); } parameterRoot.CADParameter = paramarray.ToArray(); cadoutput.ParametricParameters = parameterRoot; } if (ManufacturingParameters != null && ManufacturingParameters.Count != 0) { cadoutput.ManufacturingParameter = new CAD.ManufacturingParameterType[ManufacturingParameters.Count]; int i = 0; foreach (var param in ManufacturingParameters) { cadoutput.ManufacturingParameter[i++] = new CAD.ManufacturingParameterType() { Name = param.Key, Value = param.Value }; } } if (MetaData != null && MetaData.Count != 0) { cadoutput.MetaData = new CAD.MetaDataType[MetaData.Count]; int i = 0; foreach (var param in MetaData) { cadoutput.MetaData[i++] = new CAD.MetaDataType() { Key = param.Key, Value = param.Value }; } } cadoutput.Representation = representation; if (this.CadElementsList.Count > 0) { cadoutput.Elements = new CAD.ElementsType() { _id = UtilityHelpers.MakeUdmID() }; cadoutput.Elements.Element = this.CadElementsList.ToArray(); } return(cadoutput); }
private void CreateStructuralInterfaceEquivalent(CyPhy.Component cyphycomp) { CyPhy.CADModel cadmodel = cyphycomp.Children.CADModelCollection.FirstOrDefault(x => x.Attributes.FileFormat.ToString() == "Creo"); if (cadmodel != null) { string uri; cadmodel.TryGetResourcePath(out uri); char[] start = new char[] { '/', '\\' }; if (!String.IsNullOrEmpty(uri)) { uri = uri.TrimStart(start); string absPath; cadmodel.TryGetResourcePath(out absPath, ComponentLibraryManager.PathConvention.ABSOLUTE); var hyperlink = cyphycomp.ToHyperLink(Traceability); missingFile = Task.Run(() => CheckFileExists(hyperlink, uri, absPath)); // META-1382 //ModelName = UtilityHelpers.CleanString2(Path.GetFileNameWithoutExtension(uri)); ModelName = Path.GetFileName(uri); List <string> tokens_2 = ModelName.Split('.').ToList <string>(); int index = tokens_2.FindIndex(x => x.ToUpper() == "PRT"); if (index != -1) { ModelType = "Part"; ModelName = string.Join("", tokens_2.GetRange(0, index).ToArray()); } else { index = tokens_2.FindIndex(x => x.ToUpper() == "ASM"); if (index != -1) { ModelType = "Assembly"; ModelName = string.Join("", tokens_2.GetRange(0, index).ToArray()); } } // It shouldn't be an empty string if (ModelType.Length == 0) { ModelType = "Part"; } } else { Logger.Instance.AddLogMessage("CADModel Resource Path information unavailable for component [" + cyphycomp.Path + "," + DisplayID + "]!", Severity.Warning); } ModelURI = uri.Length > 0 ? Path.GetDirectoryName(uri) : ""; //ModelType = cadmodel.Attributes.FileType.ToString(); foreach (var param in cadmodel.Children.CADParameterCollection) { CADParameter acadparam = new CADParameter(param); CadParameters.Add(acadparam); } // META-947: Connector replaced StructuralInterface // Not dealing with nested Connectors right now. // foreach (var item in cyphycomp.Children.StructuralInterfaceCollection) foreach (CyPhy.Connector item in cyphycomp.Children.ConnectorCollection) { FindMatchingSolidModelingFeatures(item, cadmodel); } foreach (CyPhy.CADDatum item in cyphycomp.Children.CADDatumCollection) { // only Coordinate System is supported if (item is CyPhy.CoordinateSystem) { FindMatchingSolidModelingFeatures(item, cadmodel); } //else // Logger.Instance.AddLogMessage("Only CoordinateSystem datums outside of a Connector are supported, other datum types not supported.", Severity.Warning); } // Materials if (cyphycomp.Children.MaterialRefCollection.Any()) { CyPhy.MaterialRef matRef = cyphycomp.Children.MaterialRefCollection.First(); CyPhy.Material material = matRef.Referred.Material; if (material != null) { this.MaterialName = material.Attributes.Name; } } } }