예제 #1
0
        public void InitPlugin(string[] args)
        {
            // start ..
            Log.Info("InitPlugin() called with args = {0}", (args == null) ? "" : string.Join(", ", args));

            // .. with built-in options
            options = AasxPluginImageMap.ImageMapOptions.CreateDefault();

            // try load defaults options from assy directory
            try
            {
                var newOpt =
                    AasxPluginOptionsBase.LoadDefaultOptionsFromAssemblyDir <AasxPluginImageMap.ImageMapOptions>(
                        this.GetPluginName(), Assembly.GetExecutingAssembly());
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception when reading default options {1}");
            }
        }
예제 #2
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            // for speed reasons, have the most often used at top!
            if (action == "call-check-visual-extension")
            {
                // arguments
                if (args.Length < 1)
                {
                    return(null);
                }

                // looking only for Submodels
                var sm = args[0] as AdminShell.Submodel;
                if (sm == null)
                {
                    return(null);
                }

                // check for a record in options, that matches Submodel
                var found = false;
                if (this.options != null && this.options.Records != null)
                {
                    foreach (var rec in this.options.Records)
                    {
                        if (rec.AllowSubmodelSemanticId != null)
                        {
                            foreach (var x in rec.AllowSubmodelSemanticId)
                            {
                                if (sm.semanticId != null && sm.semanticId.Matches(x))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!found)
                {
                    return(null);
                }

                // success prepare record
                var cve = new AasxPluginResultVisualExtension("IMG", "Image Map");

                // ok
                return(cve);
            }

            // rest follows

            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt = JsonConvert.DeserializeObject <AasxPluginImageMap.ImageMapOptions>(args[0] as string);
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = JsonConvert.SerializeObject(this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense      = "";
                lic.longLicense       = "";
                lic.isStandardLicense = true;

                return(lic);
            }

            if (action == "get-events" && this.eventStack != null)
            {
                // try access
                return(this.eventStack.PopEvent());
            }

            if (action == "get-check-visual-extension")
            {
                var cve = new AasxPluginResultBaseObject();
                cve.strType = "True";
                cve.obj     = true;
                return(cve);
            }

            if (action == "fill-panel-visual-extension" && this.viewerControl != null)
            {
                // arguments
                if (args?.Length < 3)
                {
                    return(null);
                }

                // call
                var resobj = AasxPluginImageMap.ImageMapControl.FillWithWpfControls(Log, args?[0], args?[1],
                                                                                    this.options, this.eventStack, args?[2]);

                // give object back
                var res = new AasxPluginResultBaseObject();
                res.obj = resobj;
                return(res);
            }

            if (action == "get-list-new-submodel")
            {
                // prepare list
                var list = new List <string>();
                list.Add("ImageMap");

                // make result
                var res = new AasxPluginResultBaseObject();
                res.obj = list;
                return(res);
            }

            if (action == "generate-submodel" && args != null && args.Length >= 1 && args[0] is string)
            {
                // get arguments
                var smName = args[0] as string;
                if (smName == null)
                {
                    return(null);
                }

                // generate (by hand)
                var sm = new AdminShell.Submodel();
                sm.semanticId = new AdminShell.SemanticId(AasxPredefinedConcepts.ImageMap.Static.SEM_ImageMapSubmodel);
                sm.idShort    = "ImageMap";

                sm.SmeForWrite.CreateSMEForCD <AdminShell.File>(AasxPredefinedConcepts.ImageMap.Static.CD_ImageFile,
                                                                idShort: "ImageFile", addSme: true);

                var ent = sm.SmeForWrite.CreateSMEForCD <AdminShell.Entity>(
                    AasxPredefinedConcepts.ImageMap.Static.CD_EntityOfImageMap,
                    idShort: "Entity00", addSme: true);

                ent.statements.CreateSMEForCD <AdminShell.Property>(
                    AasxPredefinedConcepts.ImageMap.Static.CD_RegionRect,
                    idShort: "RegionRect", addSme: true)?.Set("string", "[ 10, 10, 30, 30 ]");

                ent.statements.CreateSMEForCD <AdminShell.Property>(
                    AasxPredefinedConcepts.ImageMap.Static.CD_RegionCircle,
                    idShort: "RegionCircle", addSme: true)?.Set("string", "[ 40, 40, 10 ]");

                ent.statements.CreateSMEForCD <AdminShell.Property>(
                    AasxPredefinedConcepts.ImageMap.Static.CD_RegionPolygon,
                    idShort: "RegionPolygon", addSme: true)?.Set("string", "[ 20, 20, 50, 20, 40, 30 ]");

                ent.statements.CreateSMEForCD <AdminShell.ReferenceElement>(
                    AasxPredefinedConcepts.ImageMap.Static.CD_NavigateTo,
                    idShort: "NavigateTo", addSme: true);

                // make result
                var res = new AasxPluginResultBaseObject();
                res.strType = "OK";
                res.obj     = sm;
                return(res);
            }

            // default
            return(null);
        }