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); } } }
private void Viewer_MouseDown(object sender, Microsoft.Msagl.Drawing.MsaglMouseEventArgs e) { if (e != null && e.Clicks > 1 && e.LeftButtonIsPressed && theViewer != null && this.eventStack != null) { // double-click detected, can access the viewer? try { var x = theViewer.ObjectUnderMouseCursor; if (x != null && x.DrawingObject != null && x.DrawingObject.UserData != null) { var us = x.DrawingObject.UserData; if (us is AdminShell.Referable) { // make event var refs = new List <AdminShell.Key>(); (us as AdminShell.Referable).CollectReferencesByParent(refs); // ok? if (refs.Count > 0) { var evt = new AasxPluginResultEventNavigateToReference(); evt.targetReference = AdminShell.Reference.CreateNew(refs); this.eventStack.PushEvent(evt); } } if (us is AdminShell.Reference) { var evt = new AasxPluginResultEventNavigateToReference(); evt.targetReference = (us as AdminShell.Reference); this.eventStack.PushEvent(evt); } } } catch (Exception ex) { AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex); } } }
private void Viewer_MouseDown(object sender, Microsoft.Msagl.Drawing.MsaglMouseEventArgs e) { if (e != null && e.Clicks > 1 && e.LeftButtonIsPressed && theViewer != null && this.eventStack != null) { // double-click detected, can access the viewer? // ReSharper disable EmptyGeneralCatchClause try { var x = theViewer.ObjectUnderMouseCursor; if (x != null && x.DrawingObject != null && x.DrawingObject.UserData != null) { var us = x.DrawingObject.UserData; if (us is AdminShell.Referable) { // make event var refs = new List<AdminShell.Key>(); (us as AdminShell.Referable).CollectReferencesByParent(refs); // ok? if (refs.Count > 0) { var evt = new AasxPluginResultEventNavigateToReference(); evt.targetReference = AdminShell.Reference.CreateNew(refs); this.eventStack.PushEvent(evt); } } if (us is AdminShell.Reference) { var evt = new AasxPluginResultEventNavigateToReference(); evt.targetReference = (us as AdminShell.Reference); this.eventStack.PushEvent(evt); } } } catch { } // ReSharper enable EmptyGeneralCatchClause } }
private void DocumentEntity_MenuClick(DocumentEntity e, string menuItemHeader, object tag) { // first check if (e == null || menuItemHeader == null) { return; } // what to do? if (tag == null && menuItemHeader == "Edit" && e.SourceElementsDocument != null && e.SourceElementsDocumentVersion != null) { // show the edit panel OuterTabControl.SelectedItem = TabPanelEdit; ButtonAddUpdateDoc.Content = "Update"; // make a template description for the content (remeber it) formInUpdateMode = true; updateSourceElements = e.SourceElementsDocument; var desc = theOptions.FormVdi2770; if (desc == null) { desc = DocumentShelfOptions.CreateVdi2770TemplateDesc(theOptions); } // latest version (from resources) if (e.SmVersion == DocumentEntity.SubmodelVersion.V11) { desc = DocumentShelfOptions.CreateVdi2770v11TemplateDesc(); } this.currentFormDescription = desc; // take over existing data this.currentFormInst = new FormInstanceSubmodelElementCollection(null, currentFormDescription); this.currentFormInst.PresetInstancesBasedOnSource(updateSourceElements); this.currentFormInst.outerEventStack = theEventStack; // bring it to the panel var elementsCntl = new FormListOfDifferentControl(); elementsCntl.ShowHeader = false; elementsCntl.DataContext = this.currentFormInst; ScrollViewerForm.Content = elementsCntl; #if not_yet this.currentTemplateDescription = new AasTemplateDescListOfElement(desc); this.currentTemplateDescription.ClearDynamicData(); this.currentTemplateDescription.PresetInstancesBasedOnSource(updateSourceElements); // bring it to the panel var elementsCntl = new AasTemplateListOfElementControl(); elementsCntl.DataContext = this.currentTemplateDescription; ScrollViewerForm.Content = elementsCntl; #endif // OK return; } if (tag == null && menuItemHeader == "Delete" && e.SourceElementsDocument != null && e.SourceElementsDocumentVersion != null && theSubmodel?.submodelElements != null && theOptions != null) { // the source elements need to match a Document foreach (var smcDoc in theSubmodel.submodelElements.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( theOptions?.SemIdDocument)) { if (smcDoc?.value == e.SourceElementsDocument) { // identify as well the DocumentVersion // (convert to List() because of Count() below) var allVers = e.SourceElementsDocument.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( theOptions?.SemIdDocumentVersion).ToList(); foreach (var smcVer in allVers) { if (smcVer?.value == e.SourceElementsDocumentVersion) { // access if (smcVer == null || smcVer.value == null || smcDoc == null || smcDoc.value == null) { continue; } // ask back .. the old-fashioned way! if (MessageBoxResult.Yes != MessageBox.Show( "Delete Document?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning)) { return; } // confirmed! -> delete if (allVers.Count < 2) { // remove the whole document! theSubmodel.submodelElements.Remove(smcDoc); } else { // remove only the document version e.SourceElementsDocument.Remove(smcVer); } // switch back to docs // change back OuterTabControl.SelectedItem = TabPanelList; // re-display ParseSubmodelToListItems( this.theSubmodel, this.theOptions, theViewModel.TheSelectedDocClass, theViewModel.TheSelectedLanguage, theViewModel.TheSelectedListType); // re-display also in Explorer var evt = new AasxPluginResultEventRedrawAllElements(); if (theEventStack != null) { theEventStack.PushEvent(evt); } // OK return; } } // ReSharper enable PossibleMultipleEnumeration } } } // check for a document reference if (tag != null && tag is Tuple <DocumentEntity.DocRelationType, AdminShell.Reference> reltup && reltup.Item2 != null && reltup.Item2.Count > 0) { var evt = new AasxPluginResultEventNavigateToReference(); evt.targetReference = new AdminShell.Reference(reltup.Item2); this.theEventStack.PushEvent(evt); } }
private void DocumentEntity_MenuClick(DocumentEntity e, string menuItemHeader, object tag) { // first check if (e == null || menuItemHeader == null) { return; } // what to do? if (tag == null && menuItemHeader == "Edit" && e.SourceElementsDocument != null && e.SourceElementsDocumentVersion != null) { // show the edit panel OuterTabControl.SelectedItem = TabPanelEdit; ButtonAddUpdateDoc.Content = "Update"; // make a template description for the content (remeber it) formInUpdateMode = true; updateSourceElements = e.SourceElementsDocument; var desc = DocuShelfSemanticConfig.CreateVdi2770TemplateDesc(theOptions); // latest version (from resources) if (e.SmVersion == DocumentEntity.SubmodelVersion.V11) { desc = DocuShelfSemanticConfig.CreateVdi2770v11TemplateDesc(); } this.currentFormDescription = desc; // take over existing data this.currentFormInst = new FormInstanceSubmodelElementCollection(null, currentFormDescription); this.currentFormInst.PresetInstancesBasedOnSource(updateSourceElements); this.currentFormInst.outerEventStack = theEventStack; // bring it to the panel var elementsCntl = new FormListOfDifferentControl(); elementsCntl.ShowHeader = false; elementsCntl.DataContext = this.currentFormInst; ScrollViewerForm.Content = elementsCntl; // OK return; } if (tag == null && menuItemHeader == "Delete" && e.SourceElementsDocument != null && e.SourceElementsDocumentVersion != null && theSubmodel?.submodelElements != null && theOptions != null) { // the source elements need to match a Document foreach (var smcDoc in theSubmodel.submodelElements.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( _semConfig.SemIdDocument)) { if (smcDoc?.value == e.SourceElementsDocument) { // identify as well the DocumentVersion // (convert to List() because of Count() below) var allVers = e.SourceElementsDocument.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( _semConfig.SemIdDocumentVersion).ToList(); foreach (var smcVer in allVers) { if (smcVer?.value == e.SourceElementsDocumentVersion) { // access if (smcVer == null || smcVer.value == null || smcDoc == null || smcDoc.value == null) { continue; } // ask back .. the old-fashioned way! if (MessageBoxResult.Yes != MessageBox.Show( "Delete Document?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning)) { return; } // confirmed! -> delete if (allVers.Count < 2) { // remove the whole document! theSubmodel.submodelElements.Remove(smcDoc); } else { // remove only the document version e.SourceElementsDocument.Remove(smcVer); } // switch back to docs // change back OuterTabControl.SelectedItem = TabPanelList; // re-display ParseSubmodelToListItems( this.theSubmodel, this.theOptions, theViewModel.TheSelectedDocClass, theViewModel.TheSelectedLanguage, theViewModel.TheSelectedListType); // re-display also in Explorer var evt = new AasxPluginResultEventRedrawAllElements(); if (theEventStack != null) { theEventStack.PushEvent(evt); } // OK return; } } // ReSharper enable PossibleMultipleEnumeration } } } // save digital file if (tag == null && menuItemHeader == "Save file .." && e.DigitalFile?.Path.HasContent() == true) { // make a file available var inputFn = e.DigitalFile.Path; if (CheckIfPackageFile(inputFn)) { inputFn = thePackage.MakePackageFileAvailableAsTempFile(e.DigitalFile.Path); } if (!inputFn.HasContent()) { Log.Error("Error making digital file available. Aborting!"); return; } // ask for a file name var dlg = new Microsoft.Win32.SaveFileDialog(); dlg.Title = "Save digital file as .."; dlg.FileName = System.IO.Path.GetFileName(e.DigitalFile.Path); dlg.DefaultExt = "*" + System.IO.Path.GetExtension(e.DigitalFile.Path); dlg.Filter = "All files (*.*)|*.*"; if (true != dlg.ShowDialog()) { return; } // save try { File.Copy(inputFn, dlg.FileName); } catch (Exception ex) { Log.Error(ex, "while saveing digital file to user specified loacation"); } } // check for a document reference if (tag != null && tag is Tuple <DocumentEntity.DocRelationType, AdminShell.Reference> reltup && reltup.Item2 != null && reltup.Item2.Count > 0) { var evt = new AasxPluginResultEventNavigateToReference(); evt.targetReference = new AdminShell.Reference(reltup.Item2); this.theEventStack.PushEvent(evt); } }