public void Push(VisualElementGeneric ve)
        {
            // access
            if (ve == null)
            {
                return;
            }

            // for ve, try to find the AAS (in the parent hierarchy)
            var veAas = ve.FindAllParents((v) => { return(v is VisualElementAdminShell); },
                                          includeThis: true).FirstOrDefault();

            // for ve, find the Referable to be ve or superordinate ..
            var veRef = ve.FindAllParents((v) =>
            {
                var derefdo = v?.GetDereferencedMainDataObject();
                // success implies AdminShell.IGetReference as well
                return(derefdo is AdminShell.Referable);
            }, includeThis: true).FirstOrDefault();

            // check, if ve can identify a Referable, to which a symbolic link can be done ..
            AdminShell.Identification aasid  = null;
            AdminShell.Reference      refref = null;

            if (veAas != null && veRef != null)
            {
                aasid = (veAas as VisualElementAdminShell)?.theAas?.identification;

                var derefdo = veRef.GetDereferencedMainDataObject();
                refref = (derefdo as AdminShell.IGetReference)?.GetReference();
            }

            // some more special cases
            if (refref == null && ve is VisualElementConceptDescription vecd)
            {
                refref = vecd.theCD?.GetReference();
            }

            // found some referable Reference?
            if (refref == null)
            {
                return;
            }

            // in case of plug in, make it more specific
            if (ve is VisualElementPluginExtension vepe && vepe.theExt?.Tag != null)
            {
                refref += new AdminShell.Key(AdminShell.Key.FragmentReference, false,
                                             AdminShell.Key.Custom, "Plugin:" + vepe.theExt.Tag);
            }

            // add, only if not already there
            if (history.Count < 1 || history[history.Count - 1].VisualElement != ve)
            {
                history.Add(new VisualElementHistoryItem(ve, aasid, refref));
            }

            // is enabled
            buttonBack.IsEnabled = true;
        }
        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;
        }
 public FormDescSubmodelElement(
     string formText, FormMultiplicity multiplicity, AdminShell.Key keySemanticId, string presetIdShort,
     string formInfo = null, bool isReadOnly = false)
     : base(formText, keySemanticId, presetIdShort, formInfo)
 {
     this.Multiplicity = multiplicity;
     this.IsReadOnly   = isReadOnly;
 }
 public FormDescReferable(
     string formText, AdminShell.Key keySemanticId, string presetIdShort, string formInfo = null)
     : base()
 {
     this.FormTitle     = formText;
     this.KeySemanticId = keySemanticId;
     this.PresetIdShort = presetIdShort;
     this.FormInfo      = formInfo;
 }
        private void MtpVisu_MtpObjectDoubleClick(MtpData.MtpBaseObject source)
        {
            // access
            if (source == null || this.activeMtpFileElem == null || this.theSubmodel?.submodelElements == null)
            {
                return;
            }

            // for the active file, find a Reference for it
            var mtpFileElemReference = this.activeMtpFileElem.GetReference();

            // inside the Submodel .. look out for Relations
            // (ConceptDescription)(no-local)[IRI]http://www.admin-shell.io/mtp/1/0/documentationReference
            var relKey = new AdminShell.Key("ConceptDescription", false,
                                            "IRI", "http://www.admin-shell.io/mtp/1/0/documentationReference");
            var searchRelation = this.theSubmodel?.submodelElements.FindDeep <AdminShell.RelationshipElement>(
                (candidate) =>
            {
                return(true == candidate?.semanticId?.MatchesExactlyOneKey(relKey, AdminShell.Key.MatchMode.Relaxed));
            });

            foreach (var rel in searchRelation)
            {
                // access
                if (rel.first == null || rel.second == null)
                {
                    continue;
                }

                // do some "math"
                var hit = false;
                if (source.Name != null)
                {
                    hit = rel.first.Matches(mtpFileElemReference
                                            + (new AdminShell.Key(
                                                   AdminShell.Key.GlobalReference, true, AdminShell.Key.Custom, source.Name)),
                                            AdminShell.Key.MatchMode.Relaxed);
                }
                if (source.RefID != null)
                {
                    hit = hit || rel.first.Matches(mtpFileElemReference
                                                   + (new AdminShell.Key(
                                                          AdminShell.Key.GlobalReference, true, AdminShell.Key.Custom, source.RefID)),
                                                   AdminShell.Key.MatchMode.Relaxed);
                }

                // yes?
                if (hit)
                {
                    var evt = new AasxPluginResultEventNavigateToReference();
                    evt.targetReference = new AdminShell.Reference(rel.second);
                    this.theEventStack.PushEvent(evt);
                }
            }
        }
        // Constructors
        //=============

        public FormDescReferenceElement(
            string formText, FormMultiplicity multiplicity, AdminShell.Key smeSemanticId,
            string presetIdShort, string formInfo = null, bool isReadOnly = false,
            string presetFilter = null)
            : base(formText, multiplicity, smeSemanticId, presetIdShort, formInfo, isReadOnly)
        {
            if (presetFilter != null)
            {
                this.presetFilter = presetFilter;
            }
        }
        // Constructors
        //=============

        public FormDescFile(
            string formText, FormMultiplicity multiplicity, AdminShell.Key smeSemanticId,
            string presetIdShort, string formInfo = null, bool isReadOnly = false,
            string presetMimeType = null)
            : base(formText, multiplicity, smeSemanticId, presetIdShort, formInfo, isReadOnly)
        {
            if (presetMimeType != null)
            {
                this.presetMimeType = presetMimeType;
            }
        }
 public FormDescReferable(FormDescReferable other)
     : base()
 {
     // this part == static, therefore only shallow copy
     this.FormTitle         = other.FormTitle;
     this.FormInfo          = other.FormInfo;
     this.KeySemanticId     = other.KeySemanticId;
     this.PresetIdShort     = other.PresetIdShort;
     this.PresetCategory    = other.PresetCategory;
     this.PresetDescription = other.PresetDescription;
 }
Beispiel #9
0
        public bool ContainsIndexKey(AdminShell.Key key)
        {
            // access
            var ndx = GenerateIndexKey(key);

            if (_recordLookup == null || !ndx.HasContent())
            {
                return(false);
            }

            return(_recordLookup.ContainsKey(ndx));
        }
Beispiel #10
0
        private string GenerateIndexKey(AdminShell.Key key)
        {
            if (key == null)
            {
                return(null);
            }
            // eliminate "local"
            var k = new AdminShell.Key(key)
            {
                local = false
            };
            var ndx = k?.ToString(format: 1);

            return(ndx);
        }
Beispiel #11
0
        public void IndexRecord(AdminShell.Key key, AasxPluginOptionsRecordBase rec)
        {
            if (_recordLookup == null)
            {
                _recordLookup = new MultiValueDictionary <string, AasxPluginOptionsRecordBase>();
            }

            var ndx = GenerateIndexKey(key);

            if (!ndx.HasContent())
            {
                return;
            }
            _recordLookup.Add(ndx, rec);
        }
 public FormDescProperty(
     string formText, FormMultiplicity multiplicity, AdminShell.Key smeSemanticId,
     string presetIdShort, string formInfo = null, bool isReadOnly = false, string valueType = null,
     string presetValue = null)
     : base(formText, multiplicity, smeSemanticId, presetIdShort, formInfo, isReadOnly)
 {
     // init
     if (valueType != null)
     {
         this.allowedValueTypes = new[] { valueType }
     }
     ;
     if (presetValue != null)
     {
         this.presetValue = presetValue;
     }
 }
Beispiel #13
0
        public IEnumerable <T> LookupAllIndexKey <T>(AdminShell.Key key)
            where T : AasxPluginOptionsRecordBase
        {
            // access
            var ndx = GenerateIndexKey(key);

            if (_recordLookup == null || !ndx.HasContent())
            {
                yield break;
            }

            if (!_recordLookup.ContainsKey(ndx))
            {
                yield break;
            }

            foreach (var r in _recordLookup[ndx])
            {
                if (r is T rr)
                {
                    yield return(rr);
                }
            }
        }
        // Constructors
        //=============

        public FormDescMultiLangProp(
            string formText, FormMultiplicity multiplicity, AdminShell.Key smeSemanticId, string presetIdShort,
            string formInfo = null, bool isReadOnly = false)
            : base(formText, multiplicity, smeSemanticId, presetIdShort, formInfo, isReadOnly)
        {
        }
 public FormDescSubmodelElementCollection(
     string formText, FormMultiplicity multiplicity, AdminShell.Key smeSemanticId, string presetIdShort,
     string formInfo = null)
     : base(formText, multiplicity, smeSemanticId, presetIdShort, formInfo)
 {
 }
 public FormDescSubmodel(
     string formText, AdminShell.Key keySemanticId, string presetIdShort, string formInfo = null)
     : base(formText, keySemanticId, presetIdShort, formInfo)
 {
 }
Beispiel #17
0
        public void AddKeyListKeys(
            StackPanel view, string key,
            List <AdminShell.Key> keys,
            ModifyRepo repo = null,
            AdminShell.PackageEnv package = null,
            string addExistingEntities    = null)
        {
            // sometimes needless to show
            if (repo == null && (keys == null || keys.Count < 1))
            {
                return;
            }
            int rows = 1; // default!

            if (keys != null && keys.Count > 1)
            {
                rows = keys.Count;
            }
            int rowOfs = 0;

            if (repo != null)
            {
                rowOfs = 1;
            }

            // Grid
            var g = new Grid();

            g.Margin = new Thickness(0, 0, 0, 0);

            // 0 key
            var gc = new ColumnDefinition();

            gc.Width = new GridLength(100);
            g.ColumnDefinitions.Add(gc);

            // 1 type
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 2 local
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 3 id type
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 4 value
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Star);
            g.ColumnDefinitions.Add(gc);

            // 5 buttons behind it
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // rows
            for (int r = 0; r < rows + rowOfs; r++)
            {
                var gr = new RowDefinition();
                gr.Height = new GridLength(1.0, GridUnitType.Auto);
                g.RowDefinitions.Add(gr);
            }

            // populate key
            AddSmallLabelTo(g, 0, 0, margin: new Thickness(5, 0, 0, 0), content: "" + key + ":");

            // populate [+] and [Select] buttons
            if (repo != null)
            {
                var g2 = AddSmallGrid(1, 3, new string[] { "*", "#", "#" });
                Grid.SetRow(g2, 0);
                Grid.SetColumn(g2, 1);
                Grid.SetColumnSpan(g2, 5);
                g.Children.Add(g2);

                if (addExistingEntities != null && package != null)
                {
                    repo.RegisterControl(AddSmallButtonTo(g2, 0, 1, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "Add existing"),
                                         (o) => {
                        var k2 = SmartSelectAasEntityKeys(package.AasEnv, addExistingEntities);
                        if (k2 != null)
                        {
                            keys.Clear();
                            keys.AddRange(k2);
                        }
                        return(new ModifyRepo.LambdaActionRedrawEntity());
                    });
                }

                repo.RegisterControl(AddSmallButtonTo(g2, 0, 2, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "Add blank"),
                                     (o) => {
                    var k = new AdminShell.Key();
                    keys.Add(k);
                    return(new ModifyRepo.LambdaActionRedrawEntity());
                });
            }

            // contents?
            if (keys != null)
            {
                for (int i = 0; i < keys.Count; i++)
                {
                    if (repo == null)
                    {
                        // lang
                        AddSmallLabelTo(g, 0 + i + rowOfs, 1, padding: new Thickness(2, 0, 0, 0), content: "(" + keys[i].type + ")");

                        // local
                        AddSmallLabelTo(g, 0 + i + rowOfs, 2, padding: new Thickness(2, 0, 0, 0), content: "" + ((keys[i].local) ? "(Local)" : "(no-Local)"));

                        // id type
                        AddSmallLabelTo(g, 0 + i + rowOfs, 3, padding: new Thickness(2, 0, 0, 0), content: "[" + keys[i].idType + "]");

                        // value
                        AddSmallLabelTo(g, 0 + i + rowOfs, 4, padding: new Thickness(2, 0, 0, 0), content: "" + keys[i].value);
                    }

                    else
                    {
                        // save in current context
                        var currentI = 0 + i;

                        // type
                        var cbType = repo.RegisterControl(
                            AddSmallComboBoxTo(g, 0 + i + rowOfs, 1, margin: new Thickness(2, 2, 2, 2), text: "" + keys[currentI].type,
                                               minWidth: 100, items: AdminShell.Key.KeyElements, isEditable: false),
                            (o) =>
                        {
                            keys[currentI].type = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        }) as ComboBox;
                        SmallComboBoxSelectNearestItem(cbType, cbType.Text);

                        // local
                        repo.RegisterControl(
                            AddSmallCheckBoxTo(g, 0 + i + rowOfs, 2, margin: new Thickness(2, 2, 2, 2), content: "local", isChecked: keys[currentI].local),
                            (o) =>
                        {
                            keys[currentI].local = (bool)o;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // id type
                        repo.RegisterControl(
                            AddSmallComboBoxTo(g, 0 + i + rowOfs, 3, margin: new Thickness(2, 2, 2, 2), text: "" + keys[currentI].idType,
                                               minWidth: 100, items: AdminShell.Key.IdentifierTypeNames, isEditable: false),
                            (o) =>
                        {
                            keys[currentI].idType = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // value
                        repo.RegisterControl(
                            AddSmallTextBoxTo(g, 0 + i + rowOfs, 4, margin: new Thickness(2, 2, 2, 2), text: "" + keys[currentI].value),
                            (o) =>
                        {
                            keys[currentI].value = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // button [-]
                        repo.RegisterControl(AddSmallButtonTo(g, 0 + i + rowOfs, 5, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "-"),
                                             (o) => {
                            keys.RemoveAt(currentI);
                            return(new ModifyRepo.LambdaActionRedrawEntity());
                        });
                    }
                }
            }

            // in total
            view.Children.Add(g);
        }
        public void ExportSingleSubmodel(
            AdminShellPackageEnv env, string path,
            AdminShell.Key smId,
            IEnumerable <AdminShell.Referable> cdReferables,
            CstIdObjectBase firstNodeId,
            CstIdObjectBase secondNodeId,
            CstIdObjectBase appClassId)
        {
            // access
            if (env?.AasEnv == null || path == null)
            {
                return;
            }
            _env = env;

            var sm = _env?.AasEnv.FindFirstSubmodelBySemanticId(smId);

            if (sm == null)
            {
                return;
            }

            // Step 1: copy all relevant CDs into the AAS
            if (cdReferables != null)
            {
                foreach (var rf in cdReferables)
                {
                    if (rf is AdminShell.ConceptDescription cd)
                    {
                        env?.AasEnv.ConceptDescriptions.AddIfNew(cd);
                    }
                }
            }

            // Step 2: make up a list of used semantic references and write to default file
            var tmpIdStore = new CstIdStore();

            tmpIdStore.CreateEmptyItemsFromSMEs(sm.submodelElements, omitIecEclass: true);
            tmpIdStore.WriteToFile(path + "_default_prop_refs.json");

            // Step 3: initialize node defs
            var nd1 = new CstNodeDef.NodeDefinition(firstNodeId);

            NodeDefRoot.Add(nd1);

            var nd2 = new CstNodeDef.NodeDefinition(secondNodeId);

            nd2.Parent           = nd1;
            nd2.ApplicationClass = new CstNodeDef.NodeDefinition(appClassId);
            NodeDefRoot.Add(nd2);

            // Step 4: start list of (later) lson entities
            // Note: already done by class init

            var lop = new CstPropertyRecord.ListOfProperty();

            PropertyRecs.Add(new CstPropertyRecord.PropertyRecord()
            {
                ID = "0815",
                ClassDefinition  = appClassId.ToRef(),
                ObjectType       = "PR",
                UnitSystem       = 1,
                Properties       = lop,
                ClassifiedObject = new CstPropertyRecord.ClassifiedObject()
                {
                    ObjectType       = "Item",
                    ClassifyRevision = true,
                    ID = new List <CstPropertyRecord.ID>(new[] { new CstPropertyRecord.ID()
                                                                 {
                                                                     PropertyName  = "item_id",
                                                                     PropertyValue = "000337"
                                                                 } }),
                    Properties = new CstPropertyRecord.ListOfProperty(new[] { new CstPropertyRecord.Property()
                                                                              {
                                                                                  PropertyName  = "object_name",
                                                                                  PropertyValue = "" + appClassId.Name
                                                                              } })
                }
            });

            // Step 4: recursively look at SME
            RecurseOnSme(sm.submodelElements, appClassId, "Application Class", lop);

            // Step 90: write class definitions
            var clsRoot = new CstClassDef.Root()
            {
                ClassDefinitions = ClassDefs
            };

            clsRoot.WriteToFile(path + "_classdefs.json");

            // Step 91: write node definitions
            NodeDefRoot.WriteToFile(path + "_nodedefs.json");

            // Step 92: write property definitions
            var prpRoot = new CstPropertyDef.Root()
            {
                PropertyDefinitions = PropertyDefs
            };

            prpRoot.WriteToFile(path + "_propdefs.json");

            // Step 93: write property definitions
            var recRoot = new CstPropertyRecord.Root()
            {
                PropertyRecords = PropertyRecs
            };

            recRoot.WriteToFile(path + "_proprecs.json");
        }