/// <summary>
        /// Creates the Structur to reference a picture and set the correct value <paramref name="pic"/>.
        /// If the structur is already there, it will only update the value.
        /// </summary>
        /// <param name="pic">the absolut path to the picture</param>
        /// <param name="pictype">Picturetyp like 'DevicePicture' or 'DeviceIcon'</param>
        /// <param name="externalname">The name of the externalElement</param>
        /// <param name="systemUnitClass">the systemUnitClass to insert the structure into</param>
        /// <returns></returns>
        public Uri createPictureRef(string pic, string pictype, string externalname, SystemUnitClassType systemUnitClass)
        {
            // create the package paths
            FileInfo pictureInfo = new FileInfo(pic);
            Uri      picturePath = new Uri(pictureInfo.Name, UriKind.Relative);
            Uri      picturePart = PackUriHelper.CreatePartUri(picturePath);

            // Create the InternalElement which refers to the picture
            InternalElementType pictureIE = null;

            foreach (var internalElement in systemUnitClass.InternalElement)
            {
                if (internalElement.Name.Equals(pictype))
                {
                    pictureIE = internalElement;
                    break;
                }
            }
            if (pictureIE == null)
            {
                pictureIE = systemUnitClass.InternalElement.Append(pictype);
            }

            // create the externalelement
            ExternalInterfaceType pictureEI = null;

            foreach (var externalinterface in pictureIE.ExternalInterface)
            {
                if (externalinterface.Name.Equals(externalname))
                {
                    pictureEI = externalinterface;
                    break;
                }
            }
            if (pictureEI == null)
            {
                pictureEI = pictureIE.ExternalInterface.Append(externalname);
            }

            pictureEI.RefBaseClassPath = AutomationMLInterfaceClassLib.ExternalDataConnector;

            // create the refURI Attribute with the value of the path

            AttributeType pictureAtt = null;

            if (pictureEI.Attribute.GetCAEXAttribute("refURI") == null)
            {
                pictureAtt = pictureEI.Attribute.Append("refURI");
            }
            pictureAtt.AttributeDataType = "xs:anyURI";
            pictureAtt.Value             = picturePart.ToString();


            return(picturePart);
        }
        public static bool CheckForRoleClassOrRoleRequirements(SystemUnitClassType ie, string classPath)
        {
            // HACK (MIHO, 2020-08-03): see equivalent function in AmlImport.cs; may be re-use
            if (ie is InternalElementType)
            {
                if (CheckForRole((ie as InternalElementType).RoleRequirements, classPath))
                {
                    return(true);
                }
            }

            return
                (CheckForRole(ie.SupportedRoleClass, classPath));
        }
        /// <summary>
        /// Takes the url of the picture and setup in the value attribute of the corresponding internal element <paramref name="pic"/>.
        /// </summary>
        /// <param name="url">the absolut path to the picture or document in the internet</param>
        /// <param name="urltype">Picturetyp like 'DevicePicture' or 'DeviceIcon' and document type like "Short guide" or "Bill of materials" etc</param>
        /// <param name="externalname">The name of the externalElement</param>
        /// <param name="systemUnitClass">the systemUnitClass to insert the structure into</param>
        /// <returns></returns>
        public void interneturl(string url, string urltype, string externalname, SystemUnitClassType systemUnitClass)
        {
            // Create the InternalElement which refers to the picture
            InternalElementType urlIE = null;

            foreach (var internalElement in systemUnitClass.InternalElement)
            {
                if (internalElement.Name.Equals(urltype))
                {
                    urlIE = internalElement;
                    break;
                }
            }
            if (urlIE == null)
            {
                urlIE = systemUnitClass.InternalElement.Append(urltype);
            }

            // create the externalelement
            ExternalInterfaceType urlEI = null;

            foreach (var externalinterface in urlIE.ExternalInterface)
            {
                if (externalinterface.Name.Equals(externalname))
                {
                    urlEI = externalinterface;
                    break;
                }
            }
            if (urlEI == null)
            {
                urlEI = urlIE.ExternalInterface.Append(externalname);
            }

            urlEI.RefBaseClassPath = AutomationMLInterfaceClassLib.ExternalDataConnector;

            // create the refURI Attribute with the value of the path

            AttributeType urlAtt = null;

            if (urlEI.Attribute.GetCAEXAttribute("refURI") == null)
            {
                urlAtt = urlEI.Attribute.Append("refURI");
            }
            urlAtt.AttributeDataType = "xs:anyURI";
            urlAtt.Value             = url.ToString();
        }
示例#4
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);
            }