private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // init library
            activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib();
            activeVisualObjectLib.LoadStatic(null);

            // find file, remember Submodel element for it, find filename
            // (ConceptDescription)(no-local)[IRI]http://www.admin-shell.io/mtp/v1/MTPSUCLib/ModuleTypePackage
            var simIdFn = new AdminShell.Key("ConceptDescription", false,
                                             "IRI", "http://www.admin-shell.io/mtp/v1/MTPSUCLib/ModuleTypePackage");

            this.activeMtpFileElem = theSubmodel?.submodelElements?.FindFirstSemanticIdAs <AdminShell.File>(simIdFn);
            var inputFn = this.activeMtpFileElem?.value;

            if (inputFn == null)
            {
                return;
            }

            // access file
            if (CheckIfPackageFile(inputFn))
            {
                inputFn = thePackage.MakePackageFileAvailableAsTempFile(inputFn);
            }

            // load file
            LoadFile(inputFn);

            // fit it
            this.mtpVisu.ZoomToFitCanvas();

            // double click handler
            this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // start
            SetMessage("Application started.");

            // initialize symbol library
            this.theSymbolLib = new MtpSymbolLib();

            var ISO10628 = new ResourceDictionary();

            ISO10628.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_DIN_EN_ISO_10628.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_ISO10628", ISO10628);

            var FESTO = new ResourceDictionary();

            FESTO.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_Festo.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_Festo", FESTO);

            // initialize visual object libraries
            activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib();
            activeVisualObjectLib.LoadStatic(this.theSymbolLib);

            // to find options
            this.theOptions = AasxPluginOptionsBase.LoadDefaultOptionsFromAssemblyDir <MtpViewerStandaloneOptions>(
                "WpfMtpVisuViewer", Assembly.GetExecutingAssembly());
            if (this.theOptions != null && this.theOptions.SymbolMappings != null)
            {
                activeVisualObjectLib.LoadFromSymbolMappings(this.theSymbolLib, this.theOptions.SymbolMappings);
                SetMessage("Options loaded.");
            }

            // load file
            try
            {
                //// LoadFile("Dosing.mtp");
                //// LoadFile("Manifest_PxC_Dosing.aml");
                LoadFile("Manifest_V18.10.31_3_better_name_win3.aml");
                //// LoadFile("Manifest_Sten1.aml");
                //// LoadFile("Manifest_ChemiReaktor_MIHO.aml");

                SetMessage("MTP file loaded.");
            }
            catch (Exception ex)
            {
                SetMessage("Exception: {0}", ex.Message);
            }

            // fit it
            this.mtpVisu.ZoomToFitCanvas();

            // double click handler
            this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick;
        }
Ejemplo n.º 3
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // initialize symbol library
            this.theSymbolLib = new MtpSymbolLib();

            var ISO10628 = new ResourceDictionary();

            ISO10628.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_DIN_EN_ISO_10628.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_ISO10628", ISO10628);

            var FESTO = new ResourceDictionary();

            FESTO.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_Festo.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_Festo", FESTO);

            // initialize visual object libraries
            activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib();
            activeVisualObjectLib.LoadStatic(this.theSymbolLib);

            // gather infos
            var ok = GatherMtpInfos(this.thePreLoadInfo);

            if (ok && this.activeMtpFileFn != null)
            {
                // access file
                var inputFn = this.activeMtpFileFn;
                if (CheckIfPackageFile(inputFn))
                {
                    inputFn = thePackage.MakePackageFileAvailableAsTempFile(inputFn);
                }

                // load file
                LoadFile(inputFn);

                // fit it
                this.mtpVisu.ZoomToFitCanvas();

                // double click handler
                this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick;
            }

            // Timer for status
            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            // ReSharper disable once RedundantDelegateCreation
            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            dispatcherTimer.Start();
        }
Ejemplo n.º 4
0
        public void LoadAmlOrMtp(
            MtpVisualObjectLib objectLib, IMtpDataSourceFactoryOpcUa dataSourceFactory,
            MtpDataSourceOpcUaPreLoadInfo preLoadInfo,
            MtpDataSourceSubscriber subscriber, string fn,
            MtpSymbolMapRecordList makeUpConfigRecs = null)
        {
            // check
            if (fn == null)
            {
                return;
            }

            // check if we have a mtp-file, which needs to be unzipped
            bool unzip = fn.ToLower().EndsWith(".mtp") || fn.ToLower().EndsWith(".zip");

            // easy?
            if (!unzip)
            {
                using (var stream = File.OpenRead(fn))
                {
                    LoadStream(objectLib, dataSourceFactory, preLoadInfo, subscriber, stream, makeUpConfigRecs);
                }
                return;
            }

            // not easy ..
            using (var file = File.OpenRead(fn))
                using (var zip = new ZipArchive(file, ZipArchiveMode.Read))
                {
                    // simply take the first .aml file
                    foreach (var entry in zip.Entries)
                    {
                        // take the 1st *.anl file; should be only one on the root level, even for MultiFileMTP
                        if (entry.FullName.ToLower().EndsWith(".aml"))
                        {
                            using (var stream = entry.Open())
                            {
                                LoadStream(objectLib, dataSourceFactory, preLoadInfo, subscriber, stream, makeUpConfigRecs);
                            }
                            break;
                        }
                    }
                }
        }
Ejemplo n.º 5
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // initialize symbol library
            this.theSymbolLib = new MtpSymbolLib();

            var ISO10628 = new ResourceDictionary();

            ISO10628.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_DIN_EN_ISO_10628.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_ISO10628", ISO10628);

            var FESTO = new ResourceDictionary();

            FESTO.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_Festo.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_Festo", FESTO);

            // initialize visual object libraries
            activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib();
            activeVisualObjectLib.LoadStatic(this.theSymbolLib);

            // gather infos
            var ok = GatherMtpInfos();

            if (ok && this.activeMtpFileFn != null)
            {
                // access file
                var inputFn = this.activeMtpFileFn;
                if (CheckIfPackageFile(inputFn))
                {
                    inputFn = thePackage.MakePackageFileAvailableAsTempFile(inputFn);
                }

                // load file
                LoadFile(inputFn);

                // fit it
                this.mtpVisu.ZoomToFitCanvas();

                // double click handler
                this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick;
            }
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }
Ejemplo n.º 7
0
            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);
            }