-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathDispEditHelperEntities.cs
5464 lines (4881 loc) · 271 KB
/
DispEditHelperEntities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2018-2023 Festo SE & Co. KG <https://www.festo.com/net/de_de/Forms/web/contact_international>
Author: Michael Hoffmeister
This source code is licensed under the Apache License 2.0 (see LICENSE.txt).
This source code may use other Open Source software components (see LICENSE.txt).
*/
using AasxIntegrationBase;
using AasxIntegrationBase.AdminShellEvents;
using AasxPackageLogic.PackageCentral;
using AdminShellNS;
using AnyUi;
using Extensions;
using System;
using System.IO;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Windows.Documents;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using Aas = AasCore.Aas3_0;
using AasCore.Samm2_2_0;
using static AasxPackageLogic.DispEditHelperBasics;
using System.Windows.Controls;
using AasxPackageExplorer;
using System.Threading.Tasks;
using static AasxPackageLogic.PackageCentral.PackageContainerHttpRepoSubset;
using VDS.Common.Filters;
namespace AasxPackageLogic
{
public class DispEditHelperEntities : DispEditHelperSammModules
{
static string PackageSourcePath = "";
static string PackageTargetFn = "";
static string PackageTargetDir = "/aasx";
static bool PackageEmbedAsThumbnail = false;
public DispEditHelperCopyPaste.CopyPasteBuffer theCopyPaste = new DispEditHelperCopyPaste.CopyPasteBuffer();
//
//
// --- AssetInformation
//
//
public void DisplayOrEditAasEntityAssetInformation(
PackageCentral.PackageCentral packages, Aas.IEnvironment env,
Aas.IAssetAdministrationShell aas, Aas.IAssetInformation asset,
object preferredNextFocus,
bool editMode, ModifyRepo repo, AnyUiStackPanel stack, bool embedded = false,
bool hintMode = false,
AasxMenu superMenu = null)
{
// Kind
this.DisplayOrEditEntityAssetKind(stack, asset.AssetKind,
(k) => { asset.AssetKind = k; }, relatedReferable: aas);
// Global Asset ID
this.AddHintBubble(stack, hintMode, new[] {
new HintCheck(
() => string.IsNullOrEmpty(asset.GlobalAssetId) == true,
"It is strongly encouraged to have the AAS associated with a global asset id from the " +
"very beginning. If the AAS describes a product, the individual asset id should be " +
"found on its name plate. " +
"This attribute is required as soon as the AAS is exchanged via partners in " +
"the life cycle of the asset.",
severityLevel: HintCheck.Severity.High),
new HintCheck(
() =>
{
int count = 0;
foreach(var aas in env.AllAssetAdministrationShells())
{
if(aas.AssetInformation.GlobalAssetId == asset.GlobalAssetId)
count++;
}
return (count>=2?true:false);
},
"It is not allowed to have duplicate GlobalAssetIds in the same file. This will break functionality and we strongly encoure to make the Id unique!",
severityLevel: HintCheck.Severity.High)
});
// Global Asset ID
this.AddGroup(stack, "globalAssetId:", this.levelColors.SubSection);
if (this.SafeguardAccess(
stack, repo, asset.GlobalAssetId, "globalAssetId:", "Create data element!",
v =>
{
asset.GlobalAssetId = "";
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionRedrawEntity();
}))
{
//TODO (jtikekar, 0000-00-00): check with Micha
this.AddKeyValueExRef(stack, "globalAssetId", asset, asset.GlobalAssetId, null, repo,
setValue: v =>
{
asset.GlobalAssetId = v as string;
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionNone();
},
auxButtonTitles: new[] { "Generate", "Input", "Rename", "Add existing", "Delete" },
auxButtonToolTips: new[] {
"Generate an id based on the customizable template option for asset ids.",
"Input the id, may be by the aid of barcode scanner",
"Rename the id and all occurences of the id in the AAS",
"Add id from existing element in main/ aux packages",
"Delete this entity"
},
auxButtonLambda: (i) =>
{
if (i == 0)
{
asset.GlobalAssetId = "" + AdminShellUtil.GenerateIdAccordingTemplate(
Options.Curr.TemplateIdAsset);
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionRedrawAllElements(nextFocus: preferredNextFocus);
}
if (i == 1)
{
var uc = new AnyUiDialogueDataTextBox(
"Global Asset ID:",
maxWidth: 1400,
symbol: AnyUiMessageBoxImage.Question,
options: AnyUiDialogueDataTextBox.DialogueOptions.FilterAllControlKeys,
text: "" + asset.GlobalAssetId);
if (this.context.StartFlyoverModal(uc))
{
asset.GlobalAssetId = "" + uc.Text;
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionRedrawAllElements(nextFocus: asset);
}
}
if (i == 2 && env != null)
{
var uc = new AnyUiDialogueDataTextBox(
"New Global Asset ID:",
symbol: AnyUiMessageBoxImage.Question,
maxWidth: 1400,
text: "" + asset.GlobalAssetId);
if (this.context.StartFlyoverModal(uc))
{
var res = false;
try
{
// rename
var lrf = env.RenameIdentifiable<Aas.AssetInformation>(
asset.GlobalAssetId,
uc.Text);
// use this information to emit events
if (lrf != null)
{
res = true;
foreach (var rf in lrf)
{
var rfi = rf.FindParentFirstIdentifiable();
if (rfi != null)
this.AddDiaryEntry(rfi, new DiaryEntryStructChange());
}
}
}
catch (Exception ex)
{
AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
}
if (!res)
this.context.MessageBoxFlyoutShow(
"The renaming of the Submodel or some referring elements " +
"has not performed successfully! Please review your inputs and " +
"the AAS structure for any inconsistencies.",
"Warning",
AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Warning);
return new AnyUiLambdaActionRedrawAllElements(asset);
}
}
if (i == 3)
{
var k2 = SmartSelectAasEntityKeys(packages,
PackageCentral.PackageCentral.Selector.MainAuxFileRepo, "All");
if (k2 != null && k2.Count >= 1)
{
asset.GlobalAssetId = "" + k2[0].Value;
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
}
return new AnyUiLambdaActionRedrawAllElements(nextFocus: asset);
}
if (i == 4)
{
if (AnyUiMessageBoxResult.Yes == this.context.MessageBoxFlyoutShow(
"Delete globalAssetId?",
"AssetInformation",
AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Warning))
{
asset.GlobalAssetId = null;
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
}
return new AnyUiLambdaActionRedrawAllElements(nextFocus: asset);
}
return new AnyUiLambdaActionNone();
});
// dead-csharp off
//this.AddKeyReference(
// stack, "globalAssetId", asset.GlobalAssetId, repo,
// packages, PackageCentral.PackageCentral.Selector.MainAux,
// showRefSemId: false,
// auxButtonTitles: new[] { "Generate", "Input", "Rename" },
// auxButtonToolTips: new[] {
// "Generate an id based on the customizable template option for asset ids.",
// "Input the id, may be by the aid of barcode scanner",
// "Rename the id and all occurences of the id in the AAS"
// },
// auxButtonLambda: (i) =>
// {
// if (i == 0)
// {
// asset.GlobalAssetId = "" + AdminShellUtil.GenerateIdAccordingTemplate(
// Options.Curr.TemplateIdAsset);
// this.AddDiaryEntry(aas, new DiaryEntryStructChange());
// return new AnyUiLambdaActionRedrawAllElements(nextFocus: preferredNextFocus);
// }
// if (i == 1)
// {
// var uc = new AnyUiDialogueDataTextBox(
// "Global Asset ID:",
// maxWidth: 1400,
// symbol: AnyUiMessageBoxImage.Question,
// options: AnyUiDialogueDataTextBox.DialogueOptions.FilterAllControlKeys,
// text: "" + asset.GlobalAssetId);
// if (this.context.StartFlyoverModal(uc))
// {
// asset.GlobalAssetId = "" + uc.Text;
// this.AddDiaryEntry(aas, new DiaryEntryStructChange());
// return new AnyUiLambdaActionRedrawAllElements(nextFocus: asset);
// }
// }
// if (i == 2 && env != null)
// {
// var uc = new AnyUiDialogueDataTextBox(
// "New Global Asset ID:",
// symbol: AnyUiMessageBoxImage.Question,
// maxWidth: 1400,
// text: "" + asset.GlobalAssetId);
// if (this.context.StartFlyoverModal(uc))
// {
// var res = false;
// try
// {
// // rename
// var lrf = env.RenameIdentifiable<Aas.AssetInformation>(
// asset.GlobalAssetId,
// uc.Text);
// // use this information to emit events
// if (lrf != null)
// {
// res = true;
// foreach (var rf in lrf)
// {
// var rfi = rf.FindParentFirstIdentifiable();
// if (rfi != null)
// this.AddDiaryEntry(rfi, new DiaryEntryStructChange());
// }
// }
// }
// catch (Exception ex)
// {
// AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
// }
// if (!res)
// this.context.MessageBoxFlyoutShow(
// "The renaming of the Submodel or some referring elements " +
// "has not performed successfully! Please review your inputs and " +
// "the AAS structure for any inconsistencies.",
// "Warning",
// AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Warning);
// return new AnyUiLambdaActionRedrawAllElements(asset);
// }
// }
// return new AnyUiLambdaActionNone();
// });
// dead-csharp on
// print code sheet
AddActionPanel(stack, "Actions:",
repo: repo,
superMenu: superMenu,
ticketMenu: new AasxMenu()
.AddAction("print-code-sheet", "Print asset code sheet ..",
"Prints an sheet with 2D codes for the asset id."),
ticketAction: (buttonNdx, ticket) =>
{
if (buttonNdx == 0)
{
if (context is AnyUiContextPlusDialogs cpd
&& cpd.HasCapability(AnyUiContextCapability.WPF))
{
var uc = new AnyUiDialogueDataEmpty();
this.context?.StartFlyover(uc);
try
{
if (string.IsNullOrEmpty(asset.GlobalAssetId) != true)
this.context?.PrintSingleAssetCodeSheet(
asset.GlobalAssetId, aas?.IdShort);
}
catch (Exception ex)
{
Log.Singleton.Error(ex, "When printing, an error occurred");
}
this.context?.CloseFlyover();
}
else
{
Log.Singleton.Error("Printing is only supported in the WPF version.");
}
}
return new AnyUiLambdaActionNone();
});
}
// Asset Type
this.AddGroup(stack, "assetType:", this.levelColors.SubSection);
if (this.SafeguardAccess(
stack, repo, asset.AssetType, "assetType:", "Create data element!",
v =>
{
asset.AssetType = "";
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionRedrawEntity();
}))
{
//TODO (jtikekar, 0000-00-00): check with Micha
this.AddKeyValueExRef(stack, "assetType", asset, asset.AssetType, null, repo,
setValue: v =>
{
asset.AssetType = v as string;
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionNone();
});
}
// Specific Asset IDs
// list of multiple key value pairs
this.DisplayOrEditEntityListOfSpecificAssetIds(stack, asset.SpecificAssetIds,
(ico) => { asset.SpecificAssetIds = ico; },
key: "specificAssetId",
relatedReferable: aas);
// Thumbnail: File [0..1]
this.AddGroup(stack, "DefaultThumbnail: Resource element", this.levelColors.SubSection,
requestAuxButton: repo != null,
auxButtonTitle: (asset.DefaultThumbnail == null) ? null : "Delete",
auxButtonLambda: (o) =>
{
if (AnyUiMessageBoxResult.Yes == this.context.MessageBoxFlyoutShow(
"Delete Resource element for thumbnail? This operation can not be reverted!",
"AssetInformation",
AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Warning))
{
asset.DefaultThumbnail = null;
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionRedrawEntity();
}
return new AnyUiLambdaActionNone();
});
if (this.SafeguardAccess(
stack, repo, asset.DefaultThumbnail, $"defaultThumbnail:", $"Create empty Resource element!",
v =>
{
asset.DefaultThumbnail = new Aas.Resource(""); //File replaced by resource in V3
this.AddDiaryEntry(aas, new DiaryEntryStructChange());
return new AnyUiLambdaActionRedrawEntity();
}))
{
var substack = AddSubStackPanel(stack, " "); // just a bit spacing to the left
// dead-csharp off
// Note: parentContainer = null effectively seems to disable "unwanted" functionality
// DisplayOrEditAasEntitySubmodelElement(
// packages: packages, env: env, parentContainer: null, wrapper: null,
// sme: (Aas.ISubmodelElement)asset.DefaultThumbnail,
// editMode: editMode, repo: repo, stack: substack, hintMode: hintMode);
// dead-csharp on
DisplayOrEditEntityFileResource(
substack, aas, repo, superMenu,
asset.DefaultThumbnail.Path, asset.DefaultThumbnail.ContentType,
(fn, ct) =>
{
asset.DefaultThumbnail.Path = fn;
asset.DefaultThumbnail.ContentType = ct;
},
relatedReferable: aas);
}
}
//
//
// --- AAS Env
//
//
public void DisplayOrEditAasEntityAasEnv(
PackageCentral.PackageCentral packages, Aas.IEnvironment env,
VisualElementEnvironmentItem ve, bool editMode, AnyUiStackPanel stack,
bool hintMode = false,
AasxMenu superMenu = null,
IMainWindow mainWindow = null)
{
this.AddGroup(stack, "Environment of AssetInformation Administration Shells", this.levelColors.MainSection);
if (env == null)
return;
if (editMode &&
(ve.theItemType == VisualElementEnvironmentItem.ItemType.Env
|| ve.theItemType == VisualElementEnvironmentItem.ItemType.Shells
|| ve.theItemType == VisualElementEnvironmentItem.ItemType.AllSubmodels
|| ve.theItemType == VisualElementEnvironmentItem.ItemType.AllConceptDescriptions))
{
// some hints
this.AddHintBubble(stack, hintMode, new[] {
new HintCheck(
() => { return env.AssetAdministrationShellCount() < 1; },
"There are no Administration Shells in this AAS environment. " +
(env.AssetAdministrationShells == null ? "List is null! " : "List is empty! ") +
"You should consider adding an Administration Shell by clicking 'Add AAS' " +
"on the edit panel below.",
breakIfTrue: true),
new HintCheck(
() => { return env.SubmodelCount() < 1; },
"There are no Submodels in this AAS environment. " +
(env.Submodels == null ? "List is null! " : "List is empty! ") +
"In this application, Submodels are " +
"created by adding them to associated to Administration Shells. " +
"Therefore, an Adminstration Shell shall exist before and shall be selected. " +
"You could then add Submodels by clicking " +
"'Create new Submodel of kind Type/Instance' on the edit panel. " +
"This step is typically done after creating asset and Administration Shell."),
new HintCheck(
() => { return env.ConceptDescriptionCount() < 1; },
"There are no ConceptDescriptions in this AAS environment. " +
(env.ConceptDescriptions == null ? "List is null! " : "List is empty! ") +
"Even if SubmodelElements can reference external concept descriptions, " +
"it is best practice to include (duplicates of the) concept descriptions " +
"inside the AAS environment. You should consider adding a ConceptDescription " +
"by clicking 'Add ConceptDescription' on the panel below or " +
"adding a SubmodelElement to a Submodel. This step is typically done after " +
"creating assets and Administration Shell and when creating SubmodelElements."),
});
// let the user control the number of entities
AddActionPanel(
stack, "Entities:",
repo: repo,
superMenu: superMenu,
ticketMenu: new AasxMenu()
.AddAction("add-aas", "Add AAS",
"Adds an AAS with blank information.")
.AddAction("add-cd", "Add ConceptDescription",
"Adds an ConceptDescription with blank information.")
.AddAction("add-sm-inst", "Add Submodel instance",
"Adds an Submodel instance without direct reference in AAS.",
conditional: ve.theItemType == VisualElementEnvironmentItem.ItemType.AllSubmodels)
.AddAction("add-sm-temp", "Add Submodel template",
"Adds an Submodel template without direct reference in AAS.",
conditional: ve.theItemType == VisualElementEnvironmentItem.ItemType.AllSubmodels),
ticketAction: (buttonNdx, ticket) =>
{
if (buttonNdx == 0)
{
// create TOGETHER with AssetInformation!!, as serialization might fail!
var aas = new Aas.AssetAdministrationShell("",
new Aas.AssetInformation(Aas.AssetKind.NotApplicable));
aas.Id = AdminShellUtil.GenerateIdAccordingTemplate(
Options.Curr.TemplateIdAas);
env.Add(aas);
this.AddDiaryEntry(aas, new DiaryEntryStructChange(
StructuralChangeReason.Create));
return new AnyUiLambdaActionRedrawAllElements(nextFocus: aas);
}
if (buttonNdx == 1)
{
var cd = new Aas.ConceptDescription("");
cd.Id = AdminShellUtil.GenerateIdAccordingTemplate(
Options.Curr.TemplateIdConceptDescription);
env.Add(cd);
this.AddDiaryEntry(cd, new DiaryEntryStructChange(
StructuralChangeReason.Create));
return new AnyUiLambdaActionRedrawAllElements(nextFocus: cd);
}
if (buttonNdx == 2 || buttonNdx == 3)
{
var sm = new Aas.Submodel("");
sm.Id = AdminShellUtil.GenerateIdAccordingTemplate(
(buttonNdx == 2) ? Options.Curr.TemplateIdSubmodelInstance
: Options.Curr.TemplateIdSubmodelTemplate);
if(buttonNdx == 2)
{
sm.Kind = ModellingKind.Instance;
}
else
{
sm.Kind = ModellingKind.Template;
}
env.Add(sm);
this.AddDiaryEntry(sm, new DiaryEntryStructChange(
StructuralChangeReason.Create));
return new AnyUiLambdaActionRedrawAllElements(nextFocus: sm);
}
return new AnyUiLambdaActionNone();
});
// Copy AAS
if (ve.theItemType == VisualElementEnvironmentItem.ItemType.Shells)
{
this.AddHintBubble(stack, hintMode, new[] {
new HintCheck(
() => { return this.packages.AuxAvailable; },
"You have opened an auxiliary AASX package. You can copy elements from it!",
severityLevel: HintCheck.Severity.Notice)
});
this.AddActionPanel(
stack, "Copy existing AAS:",
repo: repo,
superMenu: superMenu,
ticketMenu: new AasxMenu()
.AddAction("copy-single", "Copy single",
"Copy single selected entity from another AAS, caring for ConceptDescriptions.")
.AddAction("copy-recurse", "Copy recursively",
"Copy selected entity and children from another AAS, caring for ConceptDescriptions.")
.AddAction("copy-with-files", "Copy rec. w/ suppl. files",
"Copy selected entity and children from another AAS, caring for ConceptDescriptions " +
"and supplemental files."),
ticketAction: (buttonNdx, ticket) =>
{
if (buttonNdx == 0 || buttonNdx == 1 || buttonNdx == 2)
{
var rve = this.SmartSelectAasEntityVisualElement(
packages, PackageCentral.PackageCentral.Selector.MainAux,
Aas.Stringification.ToString(Aas.KeyTypes.AssetAdministrationShell)) as VisualElementAdminShell;
if (rve != null)
{
var copyRecursively = buttonNdx == 1 || buttonNdx == 2;
var createNewIds = env == rve.theEnv;
var copySupplFiles = buttonNdx == 2;
var potentialSupplFilesToCopy = new Dictionary<string, string>();
Aas.AssetAdministrationShell destAAS = null;
var mdo = rve.GetMainDataObject();
if (mdo != null && mdo is Aas.AssetAdministrationShell sourceAAS)
{
//
// copy AAS
//
try
{
// make a copy of the AAS itself
destAAS = (mdo as Aas.AssetAdministrationShell).Copy();
if (createNewIds)
{
destAAS.Id = AdminShellUtil.GenerateIdAccordingTemplate(
Options.Curr.TemplateIdAas);
if (destAAS.AssetInformation != null)
{
destAAS.AssetInformation.GlobalAssetId = AdminShellUtil.GenerateIdAccordingTemplate(
Options.Curr.TemplateIdAsset);
}
}
env.Add(destAAS);
this.AddDiaryEntry(destAAS, new DiaryEntryStructChange(
StructuralChangeReason.Create));
// clear, copy Submodels?
if (copyRecursively)
{
foreach (var smr in sourceAAS.AllSubmodels())
{
// need access to source submodel
var srcSub = rve.theEnv.FindSubmodel(smr);
if (srcSub == null)
continue;
// get hold of suppl file infos?
if (srcSub.SubmodelElements != null)
foreach (var f in
srcSub.SubmodelElements.FindDeep<Aas.File>())
{
if (f != null && f.Value != null &&
f.Value.StartsWith("/") &&
!potentialSupplFilesToCopy
.ContainsKey(f.Value.ToLower().Trim()))
potentialSupplFilesToCopy[
f.Value.ToLower().Trim()] =
f.Value.ToLower().Trim();
}
// complicated new ids?
if (!createNewIds)
{
// straightforward between environments
var destSMR = env.CopySubmodelRefAndCD(
rve.theEnv, smr, copySubmodel: true, copyCD: true,
shallowCopy: false);
if (destSMR != null)
{
destAAS.Add(destSMR);
}
}
else
{
// in the same environment?
// means: we have to generate a new submodel ref
// by using template mechanism
var tid = Options.Curr.TemplateIdSubmodelInstance;
if (srcSub.Kind != null && srcSub.Kind == Aas.ModellingKind.Template)
tid = Options.Curr.TemplateIdSubmodelTemplate;
// create Submodel as deep copy
// with new id from scratch
var dstSub = srcSub.Copy();
dstSub.Id = AdminShellUtil.GenerateIdAccordingTemplate(tid);
// make a new ref
var dstRef = dstSub.GetModelReference().Copy();
// formally add this to active environment and AAS
env.Add(dstSub);
destAAS.Add(dstRef);
this.AddDiaryEntry(dstSub, new DiaryEntryStructChange(
StructuralChangeReason.Create));
}
}
}
}
catch (Exception ex)
{
Log.Singleton.Error(ex, $"copying AAS");
}
//
// Copy suppl files
//
if (copySupplFiles && rve.thePackage != null && packages.Main != rve.thePackage)
{
// copy conditions met
foreach (var fn in potentialSupplFilesToCopy.Values)
{
try
{
// copy ONLY if not existing in destination
// rationale: do not potential harm the source content,
// even when voiding destination integrity
if (rve.thePackage.IsLocalFile(fn)
&& !packages.Main.IsLocalFile(fn))
{
var tmpFile =
rve.thePackage.MakePackageFileAvailableAsTempFile(fn);
var targetDir = System.IO.Path.GetDirectoryName(fn);
var targetFn = System.IO.Path.GetFileName(fn);
packages.Main.AddSupplementaryFileToStore(
tmpFile, targetDir, targetFn, false);
}
}
catch (Exception ex)
{
Log.Singleton.Error(
ex, $"copying supplemental file {fn}");
}
}
}
//
// Done
//
return new AnyUiLambdaActionRedrawAllElements(
nextFocus: destAAS, isExpanded: true);
}
}
}
return new AnyUiLambdaActionNone();
});
}
if (ve.theItemType == VisualElementEnvironmentItem.ItemType.Shells
|| ve.theItemType == VisualElementEnvironmentItem.ItemType.AllSubmodels
|| ve.theItemType == VisualElementEnvironmentItem.ItemType.AllConceptDescriptions)
{
// Cut, copy, paste within list of Assets
this.DispPlainListOfIdentifiablePasteHelper<Aas.IIdentifiable>(
stack, repo, this.theCopyPaste,
label: "Buffer:",
lambdaPasteInto: (cpi, del) =>
{
// access
if (cpi is CopyPasteItemIdentifiable cpiid)
{
// some pre-conditions not met?
if (cpiid?.entity == null || (del && cpiid?.parentContainer == null))
return null;
// divert
object res = null;
if (cpiid.entity is Aas.AssetAdministrationShell itaas)
{
// new
var aas = itaas.Copy();
env.Add(aas);
this.AddDiaryEntry(aas, new DiaryEntryStructChange(
StructuralChangeReason.Create));
res = aas;
// delete
if (del && cpiid.parentContainer is List<Aas.AssetAdministrationShell> aasold
&& aasold.Contains(itaas))
{
aasold.Remove(itaas);
this.AddDiaryEntry(itaas,
new DiaryEntryStructChange(StructuralChangeReason.Delete));
}
}
else
if (cpiid.entity is Aas.ConceptDescription itcd)
{
// new
var cd = itcd.Copy();
env.ConceptDescriptions ??= new List<IConceptDescription>();
env.ConceptDescriptions.Add(cd);
this.AddDiaryEntry(cd, new DiaryEntryStructChange(
StructuralChangeReason.Create));
res = cd;
// delete
if (del && cpiid.parentContainer is List<Aas.ConceptDescription> cdold
&& cdold.Contains(itcd))
{
cdold.Remove(itcd);
this.AddDiaryEntry(itcd,
new DiaryEntryStructChange(StructuralChangeReason.Delete));
}
}
// ok
return res;
}
if (cpi is CopyPasteItemSubmodel cpism)
{
// some pre-conditions not met?
if (cpism?.sm == null || (del && cpism?.parentContainer == null))
return null;
// divert
object res = null;
if (cpism.sm is Aas.Submodel itsm)
{
// new
var asset = itsm.Copy();
env.Submodels ??= new List<ISubmodel>();
env.Submodels.Add(itsm);
this.AddDiaryEntry(itsm, new DiaryEntryStructChange(
StructuralChangeReason.Create));
res = asset;
// delete
if (del && cpism.parentContainer is List<Aas.Submodel> smold
&& smold.Contains(itsm))
{
smold.Remove(itsm);
this.AddDiaryEntry(itsm,
new DiaryEntryStructChange(StructuralChangeReason.Delete));
}
}
// ok
return res;
}
// nok
return null;
});
}
//
// Concept Descriptions
//
if (ve.theItemType == VisualElementEnvironmentItem.ItemType.AllConceptDescriptions)
{
//
// Copy / import
//
this.AddGroup(stack, "Import of ConceptDescriptions", this.levelColors.MainSection);
// Copy
this.AddHintBubble(stack, hintMode, new[] {
new HintCheck(
() => { return this.packages.AuxAvailable; },
"You have opened an auxiliary AASX package. You can copy elements from it!",
severityLevel: HintCheck.Severity.Notice)
});
this.AddActionPanel(
stack, "Copy from existing ConceptDescription:",
repo: repo,
superMenu: superMenu,
ticketMenu: new AasxMenu()
.AddAction("copy-single", "Copy single",
"Copy single selected entity from another AAS."),
ticketAction: (buttonNdx, ticket) =>
{
if (buttonNdx == 0)
{
var rve = this.SmartSelectAasEntityVisualElement(
packages, PackageCentral.PackageCentral.Selector.MainAux,
"ConceptDescription") as VisualElementConceptDescription;
if (rve != null)
{
var mdo = rve.GetMainDataObject();
if (mdo != null && mdo is Aas.ConceptDescription)
{
var clone = (mdo as Aas.ConceptDescription).Copy();
this.MakeNewIdentifiableUnique(clone);
env.Add(clone);
this.AddDiaryEntry(clone,
new DiaryEntryStructChange(StructuralChangeReason.Create));
return new AnyUiLambdaActionRedrawAllElements(nextFocus: clone);
}
}
}
return new AnyUiLambdaActionNone();
});
//
// Dynamic rendering
//
this.AddGroup(stack, "Dynamic rendering of ConceptDescriptions", this.levelColors.MainSection);
var g1 = this.AddSubGrid(stack, "Dynamic order:", 1, 2, new[] { "#", "#" },
paddingCaption: new AnyUiThickness(5, 0, 0, 0),
minWidthFirstCol: GetWidth(FirstColumnWidth.Standard));
AnyUiComboBox cb1 = null;
cb1 = AnyUiUIElement.RegisterControl(
this.AddSmallComboBoxTo(g1, 0, 0,
margin: new AnyUiThickness(2, 2, 2, 2), padding: new AnyUiThickness(5, 0, 5, 0),
minWidth: 250,
items: new[] {
"List index", "idShort", "Identification", "By AasSubmodel",
"By SubmodelElements", "Structured"
}),
(o) =>
{
// resharper disable AccessToModifiedClosure
if (cb1?.SelectedIndex.HasValue == true)
{
ve.CdSortOrder = (VisualElementEnvironmentItem.ConceptDescSortOrder)
cb1.SelectedIndex.Value;
}
else
{
Log.Singleton.Error("ComboxBox Dynamic rendering of entities has no value");
}
// resharper enable AccessToModifiedClosure
return new AnyUiLambdaActionNone();
},
takeOverLambda: new AnyUiLambdaActionRedrawAllElements(
nextFocus: env?.ConceptDescriptions));
// set currently selected value
if (cb1 != null)
cb1.SelectedIndex = (int)ve.CdSortOrder;
//
// Static order
//
this.AddGroup(stack, "Static order of ConceptDescriptions", this.levelColors.MainSection);
this.AddHintBubble(stack, hintMode, new[] {
new HintCheck(
() => { return true; },
"The sort operation permanently changes the order of ConceptDescriptions in the " +
"environment. It cannot be reverted!",
severityLevel: HintCheck.Severity.Notice)
});
var g2 = this.AddSubGrid(stack, "Entities:", 1, 1, new[] { "#" },
paddingCaption: new AnyUiThickness(5, 0, 0, 0),
minWidthFirstCol: GetWidth(FirstColumnWidth.Standard));
AnyUiUIElement.RegisterControl(
this.AddSmallButtonTo(g2, 0, 0, content: "Sort according above order",
margin: new AnyUiThickness(2, 2, 2, 2), padding: new AnyUiThickness(5, 0, 5, 0)),
(o) =>
{
if (env.ConceptDescriptionCount() < 1)
{
Log.Singleton.Error("No ConceptDescriptions found for sorting. Aborting!");
return new AnyUiLambdaActionNone();
}
if (AnyUiMessageBoxResult.Yes == this.context.MessageBoxFlyoutShow(
"Perform sort operation? This operation can not be reverted!",
"ConceptDescriptions",
AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Warning))
{
var success = false;
if (ve.CdSortOrder == VisualElementEnvironmentItem.ConceptDescSortOrder.IdShort)
{
var x = env.ConceptDescriptions.ToList();
x.Sort(new ComparerIdShort());
env.ConceptDescriptions = x;
success = true;
}
if (ve.CdSortOrder == VisualElementEnvironmentItem.ConceptDescSortOrder.Id)
{
var x = env.ConceptDescriptions.ToList();
x.Sort(new ComparerIdentification());
env.ConceptDescriptions = x;
success = true;
}
if (ve.CdSortOrder == VisualElementEnvironmentItem.ConceptDescSortOrder.BySubmodel)
{
var cmp = env.CreateIndexedComparerCdsForSmUsage();
var x = env.ConceptDescriptions.ToList();
x.Sort(cmp);
env.ConceptDescriptions = x;
success = true;
}
if (success)
{
ve.CdSortOrder = VisualElementEnvironmentItem.ConceptDescSortOrder.None;
return new AnyUiLambdaActionRedrawAllElements(nextFocus: env?.ConceptDescriptions);
}
else
this.context.MessageBoxFlyoutShow(
"Cannot apply selected sort order!",
"ConceptDescriptions",
AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Warning);
}
return new AnyUiLambdaActionNone();
});
//
// various "repairs" of CDs
//
this.AddGroup(stack, "Maintenance of ConceptDescriptions (CDs)", this.levelColors.MainSection);
this.AddActionPanel(
stack, "Fix:",
repo: repo,
superMenu: superMenu,
ticketMenu: new AasxMenu()
.AddAction("fix-data-specs", "Fix data specs wrt. content",
"Auto-detect content of data specification and set References accordingly."),
ticketAction: (buttonNdx, ticket) =>
{
if (buttonNdx == 0)
{
if (AnyUi.AnyUiMessageBoxResult.Yes != this.context.MessageBoxFlyoutShow(