public void LoadStream( MtpVisualObjectLib objectLib, IMtpDataSourceFactoryOpcUa dataSourceFactory, MtpDataSourceOpcUaPreLoadInfo preLoadInfo, MtpDataSourceSubscriber subscriber, Stream stream, MtpSymbolMapRecordList makeUpConfigRecs = null) { // check if (stream == null) { return; } // try open file var doc = CAEXDocument.LoadFromStream(stream); if (doc == null) { return; } // load dynamic Instances var refIdToDynamicInstance = MtpAmlHelper.FindAllDynamicInstances(doc.CAEXFile); // load data sources if (dataSourceFactory != null) { MtpAmlHelper.CreateDataSources(dataSourceFactory, preLoadInfo, doc.CAEXFile); } // index pictures var pl = MtpAmlHelper.FindAllMtpPictures(doc.CAEXFile); foreach (var pi in pl) { var p = MtpPicture.ParsePicture(objectLib, subscriber, refIdToDynamicInstance, pi.Item2, makeUpConfigRecs); if (p != null) { this.PictureCollection.Add(pi.Item1, p); } } }
public static MtpPicture ParsePicture( MtpVisualObjectLib objectLib, MtpDataSourceSubscriber subscriber, Dictionary <string, SystemUnitClassType> refIdToDynamicInstance, SystemUnitClassType picture, MtpSymbolMapRecordList makeUpConfigRecs = null) { // result var res = new MtpPicture(); res.Picture = picture; // first, set up the canvas if (true) { var width = MtpAmlHelper.FindAttributeValueByNameFromDouble(picture.Attribute, "Width"); var height = MtpAmlHelper.FindAttributeValueByNameFromDouble(picture.Attribute, "Height"); if (width == null || height == null || width < 1 || height < 1) { return(null); } res.TotalSize = new Size(width.Value, height.Value); } // assume, that the elements below are in a list foreach (var ie in picture.InternalElement) { // the check described in VDI2658 rely on RefBaseSystemUnitPath if (ie == null || ie.Name == null || ie.RefBaseSystemUnitPath == null) { continue; } var refID = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "RefID"); // do a classification based on numbers to easily comapre var ec = 0; if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/Connection/Pipe") { ec = 100; } if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/Connection/FunctionLine") { ec = 101; } if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/Connection/MeasurementLine") { ec = 102; } if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/VisualObject") { ec = 200; } if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/TopologyObject/Termination/Nozzle") { ec = 300; } if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/TopologyObject/Termination/Source") { ec = 301; } if (ie.RefBaseSystemUnitPath.Trim() == "MTPHMISUCLib/TopologyObject/Termination/Sink") { ec = 302; } // // Pipe, FunctionLine, MeasurementLine // if (ec >= 100 && ec <= 199) { // access (still string) information var edgepath = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "Edgepath"); if (edgepath == null) { continue; } var points = MtpAmlHelper.PointCollectionFromString(edgepath); if (points == null || points.Count < 2) { continue; } var co = new MtpConnectionObject(); co.Name = ie.Name; co.RefID = refID; co.ObjClass = ec; co.points = points; res.Objects.Add(co); } // // Nozzle information? // var nozzlePoints = new PointCollection(); var measurementPoints = new PointCollection(); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (ec >= 200 && ec <= 399) { foreach (var ie2 in ie.InternalElement) { if (ie2 != null && ie2.RefBaseSystemUnitPath?.Trim() == "MTPHMISUCLib/PortObject/Nozzle") { // found nozzle with valid information? var nx = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie2.Attribute, "X"); var ny = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie2.Attribute, "Y"); if (nx != null && ny != null) { // add nozzlePoints.Add(new Point(nx.Value, ny.Value)); } } if (ie2 != null && ie2.RefBaseSystemUnitPath?.Trim() == "MTPHMISUCLib/PortObject/MeasurementPoint") { // found measurement point with valid information? var nx = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie2.Attribute, "X"); var ny = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie2.Attribute, "Y"); if (nx != null && ny != null) { // add measurementPoints.Add(new Point(nx.Value, ny.Value)); } } } } if (ie.Name == "V001") { ; } // // VisualObject // if (ec >= 200 && ec <= 299) { // create object and parse var vo = new MtpVisualObject(); vo.Name = ie.Name; vo.RefID = refID; vo.ObjClass = ec; vo.Parse(ie); if (!vo.IsValid()) { continue; } res.Objects.Add(vo); // add ports vo.logicalPorts = null; vo.measurementPoints = measurementPoints; vo.nozzlePoints = nozzlePoints; // try find an XAML object vo.visObj = objectLib.FindVisualObjectByClass(vo.eVer, vo.eClass, vo.eIrdi); // help improving this search if (makeUpConfigRecs != null) { makeUpConfigRecs.Add(new MtpSymbolMapRecord( vo.eVer, vo.eClass, vo.eIrdi, SymbolDefault: "{to be set}", Comment: "" + vo.Name + "," + vo.RefID)); } // try find dynamic instances if (vo.refID != null && refIdToDynamicInstance != null && refIdToDynamicInstance.ContainsKey(vo.refID)) { // try get the dynamic instance var ieDI = refIdToDynamicInstance[vo.refID] as InternalElementType; if (ieDI != null && ieDI.RefBaseSystemUnitPath != null && ieDI.RefBaseSystemUnitPath.Trim().Length > 0) { var bsup = ieDI.RefBaseSystemUnitPath.Trim(); if (bsup == "MTPDataObjectSUCLib/DataAssembly/AnaView" || bsup == "MTPDataObjectSUCLib/DataAssembly/IndicatorElement/AnaView") { vo.dynInstance = new MtpDiAnaView(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/AnaView/AnaMon" || bsup == "MTPDataObjectSUCLib/DataAssembly/IndicatorElement/AnaView/AnaMon") { vo.dynInstance = new MtpDiAnaMon(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/DIntiew" || bsup == "MTPDataObjectSUCLib/DataAssembly/IndicatorElement/DIntView") { vo.dynInstance = new MtpDiDIntView(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/AnaView/DIntMon" || bsup == "MTPDataObjectSUCLib/DataAssembly/IndicatorElement/AnaView/DIntMon") { vo.dynInstance = new MtpDiDIntMon(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/BinView" || bsup == "MTPDataObjectSUCLib/DataAssembly/IndicatorElement/BinView") { vo.dynInstance = new MtpDiBinView(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/BinMon" || bsup == "MTPDataObjectSUCLib/DataAssembly/IndicatorElement/BinMon") { vo.dynInstance = new MtpDiBinMon(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/BinVlv") { vo.dynInstance = new MtpDiBinValve(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/MonBinVlv") { vo.dynInstance = new MtpDiMonBinValve(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/BinDrv") { vo.dynInstance = new MtpDiBinDrive(); } if (bsup == "MTPDataObjectSUCLib/DataAssembly/ActiveElement/PIDCtrl") { vo.dynInstance = new MtpDiPIDCntl(); } } // found? if (vo.dynInstance != null) { vo.dynInstance.PopulateFromAml(ie.Name, ieDI, subscriber); } } } // // Topology Object // // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (ec >= 300 && ec <= 309) { // create object and parse var to = new MtpTopologyObject(); to.Name = ie.Name; to.RefID = refID; to.ObjClass = ec; to.Parse(ie); if (!to.IsValid()) { continue; } res.Objects.Add(to); // add ports to.logicalPorts = null; to.measurementPoints = measurementPoints; to.nozzlePoints = nozzlePoints; // draw source / sink? // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (ec >= 301 && ec <= 302) { // get visual object to.visObj = objectLib.FindVisualObjectByName( new[] { "Source_general", "Sink_general" }[ec - 301]); } } } // return picture return(res); }