blob: 2f07ce04fb1fb2870c486df8d290d56df3ee2ecf [file] [log] [blame]
tkuhn1l6e4eb4cd2019-05-16 11:06:07 +02001using Logging;
2using System;
3using System.Collections.Generic;
4using System.Collections.ObjectModel;
5using System.ComponentModel;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Media;
10
11using AdminShellNS;
12
13/* Copyright (c) 2018-2019 Festo AG & Co. KG <https://www.festo.com/net/de_de/Forms/web/contact_international>, author: Michael Hoffmeister
14This software is licensed under the Eclipse Public License - v 2.0 (EPL-2.0) (see https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt).
15The browser functionality is under the cefSharp license (see https://raw.githubusercontent.com/cefsharp/CefSharp/master/LICENSE).
16The JSON serialization is under the MIT license (see https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md). */
17
18namespace AasxPackageExplorer
19{
20 public class TreeViewLineCache
21 {
22 public Dictionary<object, bool> IsExpanded = new Dictionary<object, bool>();
23 }
24
25 public class VisualElementGeneric : INotifyPropertyChanged
26 {
27 // bi-directional tree
28 public VisualElementGeneric Parent = null;
29 public ObservableCollection<VisualElementGeneric> Members { get; set; }
30
31 // cache for expanded states
32 public TreeViewLineCache Cache = null;
33
34 // members (some dedicated for list / tree like visualisation
35 private bool _isExpanded = false;
36 private bool _isExpandedTouched = false;
37 private bool _isSelected = false;
38 public string TagString { get; set; }
39 public string Caption { get; set; }
40 public string Info { get; set; }
41 public string Value { get; set; }
42 public string ValueInfo { get; set; }
43 public Brush Background { get; set; }
44 public Brush Border { get; set; }
45 public Brush TagFg { get; set; }
46 public Brush TagBg { get; set; }
47 public bool IsTopLevel = false;
48
49 public VisualElementGeneric()
50 {
51 this.Members = new ObservableCollection<VisualElementGeneric>();
52 }
53
54 /// <summary>
55 /// Get the main (business) data object, e.g. a submodel
56 /// </summary>
57 /// <returns></returns>
58 public virtual object GetMainDataObject()
59 {
60 return null;
61 }
62
63 /// <summary>
64 /// Restores the state of the IsExpanded from an cache. The cache associates with the MainDataObject and therefore survives, even if the the TreeViewLines are completely rebuilt.
65 /// </summary>
66 public void RestoreFromCache()
67 {
68 var o = this.GetMainDataObject();
69 if (o != null && Cache != null && Cache.IsExpanded.ContainsKey(o))
70 {
71 this._isExpanded = Cache.IsExpanded[o];
72 this._isExpandedTouched = true;
73 }
74 }
75
76 /// <summary>
77 /// For each different sub-class type of TreeViewLineGeneric, this methods refreshes attributes such as Caption and Info. Required, if updates to the MainDataObject shall be reflected on the UI.
78 /// </summary>
79 public virtual void RefreshFromMainData()
80 {
81 // to be overloaded for sub-classes!
82 }
83
84 /// <summary>
85 /// Gets/sets whether the TreeViewItem
86 /// associated with this object is expanded.
87 /// </summary>
88 public bool IsExpanded
89 {
90 get { return _isExpanded; }
91 set
92 {
93 if (value != _isExpanded)
94 {
95 _isExpanded = value;
96 this.OnPropertyChanged("IsExpanded");
97 }
98
99 // store in cache
100 var o = this.GetMainDataObject();
101 if (o != null && Cache != null)
102 Cache.IsExpanded[o] = value;
103
104 _isExpandedTouched = true;
105 }
106 }
107
108 public void SetIsExpandedIfNotTouched(bool isExpanded)
109 {
110 if (!_isExpandedTouched)
111 _isExpanded = isExpanded;
112 }
113
114 /// <summary>
115 /// Gets/sets whether the TreeViewItem
116 /// associated with this object is selected.
117 /// </summary>
118 public bool IsSelected
119 {
120 get { return _isSelected; }
121 set
122 {
123 if (value != _isSelected)
124 {
125 _isSelected = value;
126 this.OnPropertyChanged("IsSelected");
127 }
128 }
129 }
130
131 public event PropertyChangedEventHandler PropertyChanged;
132
133 protected virtual void OnPropertyChanged(string propertyName)
134 {
135 if (this.PropertyChanged != null)
136 this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
137 }
138
139 //
140 //
141 //
142
143 private bool SearchForDescendentAndCallIfFound(VisualElementGeneric descendent, Action<VisualElementGeneric> lambda)
144 {
145 var res = false;
146 if (this == descendent)
147 {
148 if (lambda != null)
149 lambda(this);
150 res = true; // meaning: in this sub-tree, descendent was found!
151 }
152 if (this.Members != null)
153 foreach (var mem in this.Members)
154 res = res || mem.SearchForDescendentAndCallIfFound(descendent, lambda);
155 return res;
156 }
157
158 public void ForAllDescendents(Action<VisualElementGeneric> lambda)
159 {
160 if (lambda != null)
161 lambda(this);
162 if (this.Members != null)
163 foreach (var mem in this.Members)
164 mem.ForAllDescendents(lambda);
165 }
166
167 public void CollectListOfTopLevelNodes(List<VisualElementGeneric> list)
168 {
169 if (list == null)
170 return;
171 if (this.IsTopLevel)
172 {
173 list.Add(this);
174 if (this.Members != null)
175 foreach (var mem in this.Members)
176 mem.CollectListOfTopLevelNodes(list);
177 }
178 }
179
180 public bool CheckIfDescendent(VisualElementGeneric descendent)
181 {
182 if (descendent == null)
183 return false;
184 if (this == descendent)
185 return true;
186 var res = false;
187 if (this.Members != null)
188 foreach (var mem in this.Members)
189 res = res || mem.CheckIfDescendent(descendent);
190 return res;
191 }
192 }
193
194 public class VisualElementEnvironmentItem : VisualElementGeneric
195 {
196 public enum ItemType { Env = 0, Shells, Assets, ConceptDescriptions, Package, SupplFiles, EmptySet };
197 public static string[] ItemTypeNames = new string[] { "Environment", "AdministrationShells", "Assets", "ConceptDescriptions", "Package", "Supplementary files", "Empty" };
198
199 public AdminShell.PackageEnv thePackage = null;
200 public AdminShell.AdministrationShellEnv theEnv = null;
201 public ItemType theItemType = ItemType.Env;
202
203 public VisualElementEnvironmentItem(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.PackageEnv package, AdminShell.AdministrationShellEnv env, ItemType itemType)
204 : base()
205 {
206 this.Parent = parent;
207 this.Cache = cache;
208 this.thePackage = package;
209 this.theEnv = env;
210 this.theItemType = itemType;
211 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#B0B0B0"));
212 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#404040"));
213 this.Caption = $"\"{ItemTypeNames[(int)itemType]}\"";
214 this.Info = "";
215 this.IsTopLevel = true;
216 this.TagString = "Env";
217 if (theItemType == ItemType.EmptySet)
218 {
219 this.TagString = "\u2205";
220 this.Caption = "No information available";
221 }
222 if (theItemType == ItemType.Package && thePackage != null)
223 {
224 this.TagString = "\u25a2";
225 this.Info += "" + thePackage.Filename;
226 }
227 this.TagBg = this.Border;
228 this.TagFg = Brushes.White;
229 RestoreFromCache();
230 }
231
232 public static object GiveDataObject(ItemType t)
233 {
234 return ItemTypeNames[(int)t];
235 }
236
237 public override object GetMainDataObject()
238 {
239 return GiveDataObject(theItemType);
240 }
241
242 public override void RefreshFromMainData()
243 {
244 }
245
246 }
247
248 public class VisualElementAdminShell : VisualElementGeneric
249 {
250 public AdminShell.AdministrationShellEnv theEnv = null;
251 public AdminShell.AdministrationShell theAas = null;
252
253 public VisualElementAdminShell(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.AdministrationShell aas)
254 : base()
255 {
256 this.Parent = parent;
257 this.Cache = cache;
258 this.theEnv = env;
259 this.theAas = aas;
260 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#88A6D2"));
261 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#4370B3"));
262 this.TagString = "AAS";
263 this.TagBg = this.Border;
264 this.TagFg = Brushes.White;
265 RefreshFromMainData();
266 RestoreFromCache();
267 }
268
269 public override object GetMainDataObject()
270 {
271 return theAas;
272 }
273
274 public override void RefreshFromMainData()
275 {
276 if (theAas != null)
277 {
278 var ci = theAas.ToCaptionInfo();
279 this.Caption = ci.Item1;
280 this.Info = ci.Item2;
281 var asset = theEnv.FindAsset(theAas.assetRef);
282 if (asset != null)
283 this.Info += $" of [{asset.identification.idType}, {asset.identification.id}, {asset.kind.kind}]";
284 }
285 }
286 }
287
288 public class VisualElementAsset : VisualElementGeneric
289 {
290 public AdminShell.AdministrationShellEnv theEnv = null;
291 public AdminShell.Asset theAsset = null;
292
293 public VisualElementAsset(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.Asset asset)
294 : base()
295 {
296 this.Parent = parent;
297 this.Cache = cache;
298 this.theEnv = env;
299 this.theAsset = asset;
300 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#B0B0B0"));
301 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#404040"));
302 this.TagString = "Asset";
303 this.TagBg = this.Border;
304 this.TagFg = Brushes.White;
305 RefreshFromMainData();
306 RestoreFromCache();
307 }
308
309 public override object GetMainDataObject()
310 {
311 return theAsset;
312 }
313
314 public override void RefreshFromMainData()
315 {
316 if (theAsset != null)
317 {
318 var ci = theAsset.ToCaptionInfo();
319 this.Caption = "" + ci.Item1;
320 this.Info = ci.Item2;
321 }
322 }
323 }
324
325 public class VisualElementSubmodelRef : VisualElementGeneric
326 {
327 public AdminShell.AdministrationShellEnv theEnv = null;
328 public AdminShell.SubmodelRef theSubmodelRef = null;
329 public AdminShell.Submodel theSubmodel = null;
330
331 public VisualElementSubmodelRef(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.SubmodelRef smr, AdminShell.Submodel sm)
332 : base()
333 {
334 this.Parent = parent;
335 this.Cache = cache;
336 this.theEnv = env;
337 this.theSubmodelRef = smr;
338 this.theSubmodel = sm;
339 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#CBD8EB"));
340 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#4370B3"));
341 this.TagString = "Sub";
342 this.TagBg = this.Border;
343 this.TagFg = Brushes.White;
344 RefreshFromMainData();
345 RestoreFromCache();
346 }
347
348 public override object GetMainDataObject()
349 {
350 return theSubmodelRef;
351 }
352
353 public override void RefreshFromMainData()
354 {
355 if (theSubmodel != null)
356 {
357 var ci = theSubmodel.ToCaptionInfo();
358 this.Caption = "" + ci.Item1;
359 this.Info = ci.Item2;
360 }
361 }
362
363 }
364
365 public class VisualElementView : VisualElementGeneric
366 {
367 public AdminShell.AdministrationShellEnv theEnv = null;
368 public AdminShell.View theView = null;
369
370 public VisualElementView(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.View vw)
371 : base()
372 {
373 this.Parent = parent;
374 this.Cache = cache;
375 this.theEnv = env;
376 this.theView = vw;
377 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#C0C0C0"));
378 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#404040"));
379 this.TagString = "View";
380 this.TagBg = this.Border;
381 this.TagFg = Brushes.White;
382 RefreshFromMainData();
383 RestoreFromCache();
384 }
385
386 public override object GetMainDataObject()
387 {
388 return theView;
389 }
390
391 public override void RefreshFromMainData()
392 {
393 if (theView != null)
394 {
395 var ci = theView.ToCaptionInfo();
396 this.Caption = "" + ci.Item1;
397 this.Info = ci.Item2;
398 }
399 }
400
401 }
402
403 public class VisualElementReference : VisualElementGeneric
404 {
405 public AdminShell.AdministrationShellEnv theEnv = null;
406 public AdminShell.Reference theReference = null;
407
408 public VisualElementReference(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.Reference rf)
409 : base()
410 {
411 this.Parent = parent;
412 this.Cache = cache;
413 this.theEnv = env;
414 this.theReference = rf;
415 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#D0D0D0"));
416 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#606060"));
417 this.TagString = "\u2b95";
418 this.TagBg = this.Border;
419 this.TagFg = Brushes.White;
420 RefreshFromMainData();
421 RestoreFromCache();
422 }
423
424 public override object GetMainDataObject()
425 {
426 return theReference;
427 }
428
429 public override void RefreshFromMainData()
430 {
431 if (theReference != null && theReference.Keys != null)
432 {
433 this.Caption = "";
434 this.Info = "";
435 foreach (var x in theReference.Keys)
436 {
437 if (x == null)
438 continue;
439 if (this.Info != "") this.Info += "/ ";
440 this.Info += x.value;
441 }
442 }
443 }
444
445 }
446
447 public class VisualElementSubmodelElement : VisualElementGeneric
448 {
449 public AdminShell.AdministrationShellEnv theEnv = null;
450 public AdminShell.Referable theContainer = null;
451 public AdminShell.SubmodelElementWrapper theWrapper = null;
452
453 private AdminShell.ConceptDescription cachedCD = null;
454
455 public VisualElementSubmodelElement(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.Referable parentContainer, AdminShell.SubmodelElementWrapper wrap)
456 : base()
457 {
458 this.Parent = parent;
459 this.Cache = cache;
460 this.theEnv = env;
461 this.theContainer = parentContainer;
462 this.theWrapper = wrap;
463 this.Background = Brushes.White;
464 this.Border = Brushes.White;
465
466 this.TagString = "Elem";
467 if (wrap != null && wrap.submodelElement != null)
468 {
469 if (wrap.submodelElement is AdminShell.Property) this.TagString = "Prop";
470 if (wrap.submodelElement is AdminShell.File) this.TagString = "File";
471 if (wrap.submodelElement is AdminShell.Blob) this.TagString = "Blob";
472 if (wrap.submodelElement is AdminShell.ReferenceElement) this.TagString = "Ref";
473 if (wrap.submodelElement is AdminShell.RelationshipElement) this.TagString = "Rel";
474 if (wrap.submodelElement is AdminShell.SubmodelElementCollection) this.TagString = "Coll";
475 }
476
477 this.TagBg = (SolidColorBrush)(new BrushConverter().ConvertFrom("#707070")); ;
478 this.TagFg = Brushes.White;
479 RefreshFromMainData();
480 RestoreFromCache();
481 }
482
483 public override object GetMainDataObject()
484 {
485 return theWrapper.submodelElement;
486 }
487
488 public override void RefreshFromMainData()
489 {
490 if (theWrapper != null)
491 {
492 var sme = theWrapper.submodelElement;
493 var ci = sme.ToCaptionInfo();
494 this.Caption = "" + ci.Item1;
495 this.Info = ci.Item2;
496
497 if (sme is AdminShell.Property)
498 {
499 var smep = sme as AdminShell.Property;
500 if (smep.value != null && smep.value != "")
501 this.Info += "= " + smep.value;
502 else if (smep.valueId != null && !smep.valueId.IsEmpty)
503 this.Info += "<= " + smep.valueId.ToString();
504
505 // cache ConceptDescription?
506 if (sme.semanticId != null && sme.semanticId.Keys != null)
507 {
508 if (this.cachedCD == null)
509 this.cachedCD = this.theEnv.FindConceptDescription(sme.semanticId.Keys);
510 if (this.cachedCD != null && this.cachedCD.embeddedDataSpecification != null
511 && this.cachedCD.embeddedDataSpecification.dataSpecificationContent != null
512 && this.cachedCD.embeddedDataSpecification.dataSpecificationContent.dataSpecificationIEC61360 != null)
513 {
514 var iecprop = this.cachedCD.embeddedDataSpecification.dataSpecificationContent.dataSpecificationIEC61360;
515 if (iecprop.unit != null && iecprop.unit != "")
516 this.Info += " [" + iecprop.unit + "]";
517 }
518 }
519 }
520
521 if (sme is AdminShell.File)
522 {
523 var smef = sme as AdminShell.File;
524 if (smef.value != null && smef.value != "")
525 this.Info += "-> " + smef.value;
526 }
527
528 if (sme is AdminShell.ReferenceElement)
529 {
530 var smere = sme as AdminShell.ReferenceElement;
531 if (smere.value != null && !smere.value.IsEmpty)
532 this.Info += "~> " + smere.value.ToString();
533 }
534
535 if (sme is AdminShell.SubmodelElementCollection)
536 {
537 var smesec = sme as AdminShell.SubmodelElementCollection;
538 if (smesec.value != null)
539 this.Info += "(" + smesec.value.Count + " elements)";
540 }
541 }
542 }
543
544 }
545
546 public class VisualElementConceptDescription : VisualElementGeneric
547 {
548 public AdminShell.AdministrationShellEnv theEnv = null;
549 public AdminShell.ConceptDescription theCD = null;
550
551 public VisualElementConceptDescription(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.ConceptDescription cd)
552 : base()
553 {
554 this.Parent = parent;
555 this.Cache = cache;
556 this.theEnv = env;
557 this.theCD = cd;
558 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#D0D0D0"));
559 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#606060"));
560 this.TagString = "CD";
561 this.TagBg = (SolidColorBrush)(new BrushConverter().ConvertFrom("#707070")); ;
562 this.TagFg = Brushes.White;
563 RefreshFromMainData();
564 RestoreFromCache();
565 }
566
567 public override object GetMainDataObject()
568 {
569 return theCD;
570 }
571
572 public override void RefreshFromMainData()
573 {
574 if (theCD != null)
575 {
576 var ci = theCD.ToCaptionInfo();
577 this.Caption = "" + ci.Item1 + " ";
578 this.Info = ci.Item2;
579 }
580 }
581
582 }
583
584 public class VisualElementSupplementalFile : VisualElementGeneric
585 {
586 public AdminShell.PackageEnv thePackage = null;
587 public AdminShell.PackageSupplementaryFile theFile = null;
588
589 public VisualElementSupplementalFile(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.PackageEnv package, AdminShell.PackageSupplementaryFile sf)
590 : base()
591 {
592 this.Parent = parent;
593 this.Cache = cache;
594 this.thePackage = package;
595 this.theFile = sf;
596 this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#D0D0D0"));
597 this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#606060"));
598 this.TagString = "\u25a4";
599 this.TagBg = (SolidColorBrush)(new BrushConverter().ConvertFrom("#707070")); ;
600 this.TagFg = Brushes.White;
601 RefreshFromMainData();
602 RestoreFromCache();
603 }
604
605 public override object GetMainDataObject()
606 {
607 return theFile;
608 }
609
610 public override void RefreshFromMainData()
611 {
612 if (theFile != null)
613 {
614 this.Caption = "" + theFile.uri.ToString();
615 this.Info = "";
616
617 if (theFile.location == AdminShell.PackageSupplementaryFile.LocationType.AddPending)
618 this.Info += "(add pending) ";
619 if (theFile.location == AdminShell.PackageSupplementaryFile.LocationType.DeletePending)
620 this.Info += "(delete pending) ";
621 if (theFile.sourcePath != null)
622 this.Info += "\u2b60 " + theFile.sourcePath;
623
624 if (theFile.specialHandling == AdminShell.PackageSupplementaryFile.SpecialHandlingType.EmbedAsThumbnail)
625 this.Info += " [Thumbnail]";
626 }
627 }
628
629 }
630
631 //
632 // Generators
633 //
634
635 public class Generators
636 {
637 public static void GenerateVisualElementsFromShellEnvAddElements(TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, VisualElementGeneric parent, AdminShell.Referable parentContainer, AdminShell.SubmodelElementWrapper el)
638 {
639 var ti = new VisualElementSubmodelElement(parent, cache, env, parentContainer, el);
640 parent.Members.Add(ti);
641 var elc = el.submodelElement as AdminShell.SubmodelElementCollection;
642 if (elc != null)
643 foreach (var elcc in elc.value)
644 GenerateVisualElementsFromShellEnvAddElements(cache, env, ti, elc, elcc);
645 }
646
647 public static List<VisualElementGeneric> GenerateVisualElementsFromShellEnv(TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.PackageEnv package = null, bool editMode = false, int expandMode = 0)
648 {
649 // clear tree
650 var res = new List<VisualElementGeneric>();
651 // valid?
652 if (env == null)
653 return res;
654
655 // need some attach points
656 VisualElementEnvironmentItem tiPackage = null, tiEnv = null, tiShells = null, tiAssets = null, tiCDs = null;
657
658 // many operytions -> make it bulletproof
659 try
660 {
661
662 if (editMode)
663 {
664 // package
665 tiPackage = new VisualElementEnvironmentItem(null /* Parent */, cache, package, env, VisualElementEnvironmentItem.ItemType.Package);
666 tiPackage.SetIsExpandedIfNotTouched(true);
667 res.Add(tiPackage);
668
669 // env
670 tiEnv = new VisualElementEnvironmentItem(tiPackage, cache, package, env, VisualElementEnvironmentItem.ItemType.Env);
671 tiEnv.SetIsExpandedIfNotTouched(expandMode > 0);
672 tiPackage.Members.Add(tiEnv);
673
674 // shells
675 tiShells = new VisualElementEnvironmentItem(tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.Shells);
676 tiShells.SetIsExpandedIfNotTouched(expandMode > 0);
677 tiEnv.Members.Add(tiShells);
678
679 // assets
680 tiAssets = new VisualElementEnvironmentItem(tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.Assets);
681 tiAssets.SetIsExpandedIfNotTouched(expandMode > 0);
682 tiEnv.Members.Add(tiAssets);
683
684 // concept descriptions
685 tiCDs = new VisualElementEnvironmentItem(tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.ConceptDescriptions);
686 tiCDs.SetIsExpandedIfNotTouched(expandMode > 0);
687 tiEnv.Members.Add(tiCDs);
688 }
689
690 // over all Admin shells
691 foreach (var aas in env.AdministrationShells)
692 {
693 // item
694 var tiAas = new VisualElementAdminShell(null, cache, env, aas);
695 tiAas.SetIsExpandedIfNotTouched(expandMode > 0);
696
697 // add item
698 if (editMode)
699 {
700 tiAas.Parent = tiShells;
701 tiShells.Members.Add(tiAas);
702 }
703 else
704 {
705 res.Add(tiAas);
706 }
707
708 // have submodels?
709 if (aas.submodelRefs != null)
710 foreach (var smr in aas.submodelRefs)
711 {
712 var sm = env.FindSubmodel(smr);
713 if (sm == null)
714 {
715 Log.Error("Cannot find some submodel!");
716 continue;
717 }
718 // item
719 var tiSm = new VisualElementSubmodelRef(tiAas, cache, env, smr, sm);
720 tiSm.SetIsExpandedIfNotTouched(expandMode > 1);
721 // recursively into the submodel elements
722 if (sm.submodelElements != null)
723 foreach (var sme in sm.submodelElements)
724 GenerateVisualElementsFromShellEnvAddElements(cache, env, tiSm, sm, sme);
725 // add
726 tiAas.Members.Add(tiSm);
727 }
728
729 // have views?
730 if (aas.views != null && aas.views.views != null)
731 foreach (var vw in aas.views.views)
732 {
733 // item
734 var tiVw = new VisualElementView(tiAas, cache, env, vw);
735 tiVw.SetIsExpandedIfNotTouched(expandMode > 1);
736 // recursion -> submodel elements
737 if (vw.containedElements != null && vw.containedElements.reference != null)
738 foreach (var ce in vw.containedElements.reference)
739 {
740 var tiRf = new VisualElementReference(tiVw, cache, env, ce);
741 tiVw.Members.Add(tiRf);
742 }
743 // add
744 tiAas.Members.Add(tiVw);
745 }
746 }
747
748 // if edit mode, then display further ..
749 if (editMode)
750 {
751 // over all assets
752 foreach (var asset in env.Assets)
753 {
754 // item
755 var tiAsset = new VisualElementAsset(tiAssets, cache, env, asset);
756 tiAssets.Members.Add(tiAsset);
757 }
758
759 // over all concept descriptions
760 foreach (var cd in env.ConceptDescriptions)
761 {
762 // item
763 var tiCD = new VisualElementConceptDescription(tiCDs, cache, env, cd);
764 tiCDs.Members.Add(tiCD);
765 }
766 }
767
768 // package as well?
769 if (editMode && package != null && tiPackage != null)
770 {
771 // file folder
772 var tiFiles = new VisualElementEnvironmentItem(tiPackage, cache, package, env, VisualElementEnvironmentItem.ItemType.SupplFiles);
773 tiFiles.SetIsExpandedIfNotTouched(expandMode > 0);
774 tiPackage.Members.Add(tiFiles);
775
776 // single files
777 var files = package.GetListOfSupplementaryFiles();
778 foreach (var fi in files)
779 tiFiles.Members.Add(new VisualElementSupplementalFile(tiFiles, cache, package, fi));
780 }
781
782 } catch (Exception ex)
783 {
784 Log.Error(ex, "Generating tree of visual elements");
785 }
786
787 // end
788 return res;
789
790 }
791
792 }
793
794 }