-
Notifications
You must be signed in to change notification settings - Fork 1
/
Diagram.go
1338 lines (1201 loc) · 59.6 KB
/
Diagram.go
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
// Package crldiagramdomain defines the Diagram domain. This is a pre-defined domain that is, itself,
// represented as a CRLElement and identified with the CrlDiagramDomainURI. This concept space contains the prototypes of all Elements used to construct CrlDiagrams.
// Included are:
//
// CrlDiagram: the diagram itself
// CrlDiagramNode: a node in the diagram
// CrlDiagramLink: a link in the diagram
// CrlDiagramPointer: a pointer shown as a link in the diagram
// CrlDiagramAnchoredText: stand-alone text anchored to a reference point in the diagram
//
// These classes are intended to hold all of the information about the diagram that is not specific to the rendering engine.
//
// Intended Usage
// CRL Elements, in general, can have functions associated with them. When refinements of the elements are created, modified, or deleted, these functions are
// called. The strategy used for diagrams is to place all rendering-specific code in functions associated with the deining concepts.
// This is accomplished using the FunctionCallManager.AddFunctionCall() method. Note that this registration is NOT done in the core diagram package, but
// rather in the package providing the rendering engine linkage.
//
// Instances of the prototpes can be conveniently instantiated using the supplied New<type>() functions. This creates a refinement of the type and
// adds the appropriate children, with each child being a refinement of its defining type.
package crldiagramdomain
import (
"log"
"math"
"strconv"
"github.com/pkg/errors"
"golang.org/x/image/math/fixed"
"github.com/golang/freetype/truetype"
"github.com/pbrown12303/activeCRL/core"
"github.com/pbrown12303/activeCRL/crldatatypesdomain"
mapset "github.com/deckarep/golang-set"
"golang.org/x/image/font"
"golang.org/x/image/font/gofont/gobold"
"golang.org/x/image/font/gofont/goitalic"
"golang.org/x/image/font/gofont/goregular"
)
// IconSize defines the height and width of icons
const IconSize = 16.0
// NodeLineWidth is the width of the line bordering the node image
const NodeLineWidth = 2.0
// NodePadWidth is the width of the padding surrounding the icon, displayLabel, and abstractionDisplayLabel
const NodePadWidth = 1.0
var goRegularFont *truetype.Font
var goBoldFont *truetype.Font
var go12PtRegularFace font.Face
var go12PtBoldFace font.Face
var go10PtRegularFace font.Face
var go10PtItalicFace font.Face
// CrlDiagramPrefix is the prefix for all URIs related to CrlDiagram
var CrlDiagramPrefix = "http://activeCrl.com"
// CrlDiagramDomainURI identifies concept space containing all concepts related to the CrlDiagram
var CrlDiagramDomainURI = CrlDiagramPrefix + "/CrlDiagramDomain"
// CrlDiagramURI identifies the CrlDiagram concept
var CrlDiagramURI = CrlDiagramDomainURI + "/" + "CrlDiagram"
// CrlDiagramWidthURI identifies the CrlDiagramWidth concept
var CrlDiagramWidthURI = CrlDiagramURI + "/" + "Width"
// CrlDiagramHeightURI identifies the CrlDiagramHeight concept
var CrlDiagramHeightURI = CrlDiagramURI + "/" + "Height"
// Diagram Anchored Text
// CrlDiagramAnchoredTextURI identifies the concept of an Anchored Text
var CrlDiagramAnchoredTextURI = CrlDiagramDomainURI + "/" + "AnchoredText"
// CrlDiagramAnchoredTextAnchorXURI identifies the x coordinate of the anchored text anchor point
var CrlDiagramAnchoredTextAnchorXURI = CrlDiagramAnchoredTextURI + "/" + "AnchorX"
// CrlDiagramAnchoredTextAnchorYURI identifies the y coordinate of the anchored text anchor point
var CrlDiagramAnchoredTextAnchorYURI = CrlDiagramAnchoredTextURI + "/" + "AnchorY"
// CrlDiagramAnchoredTextOffsetXURI identifies the x offset of the anchored text anchor point
var CrlDiagramAnchoredTextOffsetXURI = CrlDiagramAnchoredTextURI + "/" + "OffsetX"
// CrlDiagramAnchoredTextOffsetYURI identifies the y offset of the anchored text anchor point
var CrlDiagramAnchoredTextOffsetYURI = CrlDiagramAnchoredTextURI + "/" + "OffsetY"
// CrlDiagramAnchoredTextVisibleURI identifies the boolean indicating whether the anchored text is presently viewable
var CrlDiagramAnchoredTextVisibleURI = CrlDiagramAnchoredTextURI + "/" + "Visible"
// Diagram Element
// CrlDiagramElementURI identifies the CrlDiagramElement concept
var CrlDiagramElementURI = CrlDiagramDomainURI + "/" + "CrlDiagramElement"
// CrlDiagramElementModelReferenceURI identifies the reference to the model element represented by the element
var CrlDiagramElementModelReferenceURI = CrlDiagramElementURI + "/" + "ModelReference"
// CrlDiagramElementDisplayLabelURI identifies the display label concept to be used when displaying the element
var CrlDiagramElementDisplayLabelURI = CrlDiagramElementURI + "/" + "DisplayLabel"
// CrlDiagramElementAbstractionDisplayLabelURI identifies the abstraction display label concept to be used when displaying the element
var CrlDiagramElementAbstractionDisplayLabelURI = CrlDiagramElementURI + "/" + "AbstractionDisplayLabel"
// CrlDiagramElementLineColorURI identifies the line color to be used when displaying the element
var CrlDiagramElementLineColorURI = CrlDiagramElementURI + "/" + "LineColor"
// CrlDiagramElementBGColorURI identifies the background color to be used when displaying the element
var CrlDiagramElementBGColorURI = CrlDiagramElementURI + "/" + "BGColor"
// Diagram Node
// CrlDiagramNodeURI identifies the CrlDiagramNode concept
var CrlDiagramNodeURI = CrlDiagramDomainURI + "/" + "CrlDiagramNode"
// CrlDiagramNodeAbstractionDisplayLabelURI identifies the abstraction display label concept to be used when displaying the element
var CrlDiagramNodeAbstractionDisplayLabelURI = CrlDiagramElementURI + "/" + "AbstractionDisplayLabel"
// CrlDiagramNodeXURI identifies the X coordinate of the node
var CrlDiagramNodeXURI = CrlDiagramNodeURI + "/" + "X"
// CrlDiagramNodeYURI identifies the Y coordinate of the node
var CrlDiagramNodeYURI = CrlDiagramNodeURI + "/" + "Y"
// CrlDiagramNodeHeightURI identifies the height of the node
var CrlDiagramNodeHeightURI = CrlDiagramNodeURI + "/" + "Height"
// CrlDiagramNodeWidthURI identifies the width of the node
var CrlDiagramNodeWidthURI = CrlDiagramNodeURI + "/" + "Width"
// CrlDiagramNodeDisplayLabelYOffsetURI identifies the Y offset for the display label within the node
var CrlDiagramNodeDisplayLabelYOffsetURI = CrlDiagramNodeURI + "/" + "DisplayLabelYOffset"
// Diagram Link
// CrlDiagramLinkURI identifies the CrlDiagramLink concept
var CrlDiagramLinkURI = CrlDiagramDomainURI + "/" + "CrlDiagramLink"
// CrlDiagramLinkSourceURI identifies the concept that is the source of the link
var CrlDiagramLinkSourceURI = CrlDiagramLinkURI + "/" + "Source"
// CrlDiagramLinkTargetURI identifies the concept that is the target of the link
var CrlDiagramLinkTargetURI = CrlDiagramLinkURI + "/" + "Target"
// CrlDiagramLinkDisplayLabelURI identifies the anchored text being used as the display label on a link
var CrlDiagramLinkDisplayLabelURI = CrlDiagramLinkURI + "/" + "DisplayLabel"
// CrlDiagramLinkAbstractionDisplayLabelURI identifies the anchored text used as the abstraction label on a link
var CrlDiagramLinkAbstractionDisplayLabelURI = CrlDiagramLinkURI + "/" + "AbstractionDisplayLabel"
// CrlDiagramLinkMultiplicityURI identifies the anchored text used to display multiplicity
var CrlDiagramLinkMultiplicityURI = CrlDiagramLinkURI + "/" + "Multiplicity"
// Diagram Pointer
// CrlDiagramPointerURI identifies a pointer represented as a link
var CrlDiagramPointerURI = CrlDiagramDomainURI + "/" + "Pointer"
// CrlDiagramAbstractPointerURI identifies the Abstract of an Element represented as a link
var CrlDiagramAbstractPointerURI = CrlDiagramDomainURI + "/" + "AbstractPointer"
// CrlDiagramElementPointerURI identifies the element pointer of a Reference represented as a link
var CrlDiagramElementPointerURI = CrlDiagramDomainURI + "/" + "ElementPointer"
// CrlDiagramOwnerPointerURI identifies the owner of an Element represented as a link
var CrlDiagramOwnerPointerURI = CrlDiagramDomainURI + "/" + "OwnerPointer"
// CrlDiagramRefinedPointerURI identifies the refined element of a Refinement represented as a link
var CrlDiagramRefinedPointerURI = CrlDiagramDomainURI + "/" + "RefinedPointer"
// CrlDiagramReferenceLinkURI identifies the Reference represented as a link in the diagram
var CrlDiagramReferenceLinkURI = CrlDiagramDomainURI + "/" + "ReferenceLink"
// CrlDiagramRefinementLinkURI identifies the Refinement represented as a link in the diagram
var CrlDiagramRefinementLinkURI = CrlDiagramDomainURI + "/" + "RefinementLink"
func addAnchoredTextConcepts(anchoredText core.Concept, trans *core.Transaction) {
uOfD := trans.GetUniverseOfDiscourse()
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramAnchoredTextAnchorXURI, anchoredText, "AnchorX", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramAnchoredTextAnchorYURI, anchoredText, "AnchorY", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramAnchoredTextOffsetXURI, anchoredText, "OffsetX", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramAnchoredTextOffsetYURI, anchoredText, "OffsetY", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramAnchoredTextVisibleURI, anchoredText, "Visible", trans)
}
func addDiagramElementConcepts(newElement core.Concept, trans *core.Transaction) {
uOfD := trans.GetUniverseOfDiscourse()
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramElementModelReferenceURI, newElement, "Model Reference", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramElementLineColorURI, newElement, "Line Color", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramElementBGColorURI, newElement, "BG Color", trans)
}
func addDiagramLinkConcepts(newLink core.Concept, trans *core.Transaction) {
uOfD := trans.GetUniverseOfDiscourse()
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramLinkSourceURI, newLink, "Source", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramLinkTargetURI, newLink, "Target", trans)
displayLabel, _ := uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramLinkDisplayLabelURI, newLink, "DisplayLabel", trans)
addAnchoredTextConcepts(displayLabel, trans)
abstractionDisplayLabel, _ := uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramLinkAbstractionDisplayLabelURI, newLink, "AbstractionDisplayLabel", trans)
addAnchoredTextConcepts(abstractionDisplayLabel, trans)
}
func addDiagramNodeConcepts(newNode core.Concept, trans *core.Transaction) {
uOfD := trans.GetUniverseOfDiscourse()
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramNodeXURI, newNode, "X", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramNodeYURI, newNode, "Y", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramNodeHeightURI, newNode, "Height", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramNodeWidthURI, newNode, "Width", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramElementDisplayLabelURI, newNode, "DisplayLabel", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramElementAbstractionDisplayLabelURI, newNode, "AbstractionDisplayLabel", trans)
}
// GetAbstractionDisplayLabel is a convenience function for getting the AbstractionDisplayLabel value for a DiagramElement
func GetAbstractionDisplayLabel(diagramElement core.Concept, trans *core.Transaction) string {
if diagramElement == nil {
return ""
}
abstractionDisplayLabelLiteral := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementAbstractionDisplayLabelURI, trans)
if abstractionDisplayLabelLiteral != nil {
return abstractionDisplayLabelLiteral.GetLiteralValue(trans)
}
return ""
}
// GetBGColor is a convenience function for getting the backgound color value of a DiagramElement
func GetBGColor(diagramElement core.Concept, trans *core.Transaction) string {
if diagramElement == nil {
return ""
}
BGColorLiteral := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementBGColorURI, trans)
if BGColorLiteral != nil {
return BGColorLiteral.GetLiteralValue(trans)
}
return ""
}
// GetDisplayLabel is a convenience function for getting the DisplayLabel value of a DiagramElement
func GetDisplayLabel(diagramElement core.Concept, trans *core.Transaction) string {
if diagramElement == nil {
return ""
}
displayLabelLiteral := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementDisplayLabelURI, trans)
if displayLabelLiteral != nil {
return displayLabelLiteral.GetLiteralValue(trans)
}
return ""
}
// GetFirstElementRepresentingConcept returns the first diagram element that represents the indicated concept
func GetFirstElementRepresentingConcept(diagram core.Concept, concept core.Concept, trans *core.Transaction) core.Concept {
if diagram == nil || !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConcept called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramElementURI, trans) {
if GetReferencedModelConcept(el, trans) == concept && !el.IsRefinementOfURI(CrlDiagramPointerURI, trans) {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptID returns the first diagram element that represents the indicated concept
func GetFirstElementRepresentingConceptID(diagram core.Concept, conceptID string, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptID called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramElementURI, trans) {
if GetReferencedModelConcept(el, trans).GetConceptID(trans) == conceptID && !el.IsRefinementOfURI(CrlDiagramPointerURI, trans) {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptOwnerPointer returns the first diagram element that represents the indicated concept's OwnerPointer
func GetFirstElementRepresentingConceptOwnerPointer(diagram core.Concept, concept core.Concept, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptOwnerPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramOwnerPointerURI, trans) {
if GetReferencedModelConcept(el, trans) == concept {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptIDOwnerPointer returns the first diagram element that represents the indicated concept's OwnerPointer
func GetFirstElementRepresentingConceptIDOwnerPointer(diagram core.Concept, conceptID string, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptIDOwnerPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramOwnerPointerURI, trans) {
if GetReferencedModelConcept(el, trans).GetConceptID(trans) == conceptID {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptElementPointer returns the first diagram element that represents the indicated concept's ElementPointer
func GetFirstElementRepresentingConceptElementPointer(diagram core.Concept, concept core.Concept, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptElementPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramElementPointerURI, trans) {
if GetReferencedModelConcept(el, trans) == concept {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptIDElementPointer returns the first diagram element that represents the indicated concept's ElementPointer
func GetFirstElementRepresentingConceptIDElementPointer(diagram core.Concept, conceptID string, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptIDElementPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramElementPointerURI, trans) {
if GetReferencedModelConcept(el, trans).GetConceptID(trans) == conceptID {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptAbstractPointer returns the first diagram element that represents the indicated concept's AbstractPointer
func GetFirstElementRepresentingConceptAbstractPointer(diagram core.Concept, concept core.Concept, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptAbstractPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramAbstractPointerURI, trans) {
if GetReferencedModelConcept(el, trans) == concept {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptIDAbstractPointer returns the first diagram element that represents the indicated concept's AbstractPointer
func GetFirstElementRepresentingConceptIDAbstractPointer(diagram core.Concept, conceptID string, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptIDAbstractPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramAbstractPointerURI, trans) {
if GetReferencedModelConcept(el, trans).GetConceptID(trans) == conceptID {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptRefinedPointer returns the first diagram element that represents the indicated concept's RefinedPointer
func GetFirstElementRepresentingConceptRefinedPointer(diagram core.Concept, concept core.Concept, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptRefinedPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramRefinedPointerURI, trans) {
if GetReferencedModelConcept(el, trans) == concept {
return el
}
}
return nil
}
// GetFirstElementRepresentingConceptIDRefinedPointer returns the first diagram element that represents the indicated concept's RefinedPointer
func GetFirstElementRepresentingConceptIDRefinedPointer(diagram core.Concept, conceptID string, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetFirstElementRepresentingConceptIDRefinedPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramRefinedPointerURI, trans) {
if GetReferencedModelConcept(el, trans).GetConceptID(trans) == conceptID {
return el
}
}
return nil
}
// GetLineColor is a convenience function for getting the LineColor value of a DiagramElement
func GetLineColor(diagramElement core.Concept, trans *core.Transaction) string {
if diagramElement == nil {
return ""
}
lineColorLiteral := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementLineColorURI, trans)
if lineColorLiteral != nil {
return lineColorLiteral.GetLiteralValue(trans)
}
return ""
}
// GetLinkSource is a convenience function for getting the source concept of a link
func GetLinkSource(diagramLink core.Concept, trans *core.Transaction) core.Concept {
if diagramLink == nil {
return nil
}
sourceReference := diagramLink.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramLinkSourceURI, trans)
if sourceReference != nil {
return sourceReference.GetReferencedConcept(trans)
}
return nil
}
// GetLinkSourceReference is a convenience function for getting the source reference of a link
func GetLinkSourceReference(diagramLink core.Concept, trans *core.Transaction) core.Concept {
if diagramLink == nil {
return nil
}
return diagramLink.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramLinkSourceURI, trans)
}
// GetLinkTarget is a convenience function for getting the target concept of a link
func GetLinkTarget(diagramLink core.Concept, trans *core.Transaction) core.Concept {
if diagramLink == nil {
return nil
}
targetReference := diagramLink.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramLinkTargetURI, trans)
if targetReference != nil {
return targetReference.GetReferencedConcept(trans)
}
return nil
}
// GetLinkTargetReference is a convenience function for getting the target reference of a link
func GetLinkTargetReference(diagramLink core.Concept, trans *core.Transaction) core.Concept {
if diagramLink == nil {
return nil
}
return diagramLink.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramLinkTargetURI, trans)
}
// GetNodeHeight is a convenience function for getting the Height value of a node's position
func GetNodeHeight(diagramNode core.Concept, trans *core.Transaction) float64 {
if diagramNode == nil {
return 0.0
}
heightLiteral := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeHeightURI, trans)
if heightLiteral != nil {
value := heightLiteral.GetLiteralValue(trans)
numericValue, err := strconv.ParseFloat(value, 64)
if err == nil {
return numericValue
}
}
return 0.0
}
// GetNodeWidth is a convenience function for getting the Width value of a node's position
func GetNodeWidth(diagramNode core.Concept, trans *core.Transaction) float64 {
if diagramNode == nil {
return 0.0
}
widthLiteral := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeWidthURI, trans)
if widthLiteral != nil {
value := widthLiteral.GetLiteralValue(trans)
numericValue, err := strconv.ParseFloat(value, 64)
if err == nil {
return numericValue
}
}
return 0.0
}
// GetNodeX is a convenience function for getting the X value of a node's position
func GetNodeX(diagramNode core.Concept, trans *core.Transaction) float64 {
if diagramNode == nil {
return 0.0
}
xLiteral := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeXURI, trans)
if xLiteral != nil {
value := xLiteral.GetLiteralValue(trans)
numericValue, err := strconv.ParseFloat(value, 64)
if err == nil {
return numericValue
}
}
return 0.0
}
// GetNodeY is a convenience function for getting the X value of a node's position
func GetNodeY(diagramNode core.Concept, trans *core.Transaction) float64 {
if diagramNode == nil {
return 0.0
}
yLiteral := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeYURI, trans)
if yLiteral != nil {
value := yLiteral.GetLiteralValue(trans)
numericValue, err := strconv.ParseFloat(value, 64)
if err == nil {
return numericValue
}
}
return 0.0
}
// GetOwnerPointer returns the ownerPointer for the concept if one exists
func GetOwnerPointer(diagram core.Concept, concept core.Concept, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetOwnerPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramOwnerPointerURI, trans) {
if GetReferencedModelConcept(el, trans) == concept {
return el
}
}
return nil
}
// GetElementPointer returns the elementPointer for the concept if one exists
func GetElementPointer(diagram core.Concept, concept core.Concept, trans *core.Transaction) core.Concept {
if !diagram.IsRefinementOfURI(CrlDiagramURI, trans) {
log.Printf("GetElementPointer called with diagram of incorrect type")
return nil
}
for _, el := range diagram.GetOwnedConceptsRefinedFromURI(CrlDiagramElementPointerURI, trans) {
if GetReferencedModelConcept(el, trans) == concept {
return el
}
}
return nil
}
// GetReferencedModelConcept is a function on a CrlDiagramNode that returns the model element represented by the
// diagram node
func GetReferencedModelConcept(diagramElement core.Concept, trans *core.Transaction) core.Concept {
if diagramElement == nil {
return nil
}
reference := diagramElement.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramElementModelReferenceURI, trans)
if reference != nil {
return reference.GetReferencedConcept(trans)
}
return nil
}
func init() {
var err error
// Set up fonts and faces
goRegularFont, err = truetype.Parse(goregular.TTF)
if err != nil {
log.Print(err.Error())
}
goBoldFont, err = truetype.Parse(gobold.TTF)
if err != nil {
log.Print(err.Error())
}
goItalicFont, err := truetype.Parse(goitalic.TTF)
if err != nil {
log.Print(err.Error())
}
options12Pt := truetype.Options{Size: 12.0}
go12PtRegularFace = truetype.NewFace(goRegularFont, &options12Pt)
go12PtBoldFace = truetype.NewFace(goBoldFont, &options12Pt)
options10Pt := truetype.Options{Size: 10.0}
go10PtRegularFace = truetype.NewFace(goRegularFont, &options10Pt)
go10PtItalicFace = truetype.NewFace(goItalicFont, &options10Pt)
}
// Int26_6ToFloat converts a fixed point 26_6 integer to a floating point number
func Int26_6ToFloat(val fixed.Int26_6) float64 {
return float64(val) / 64.0
}
// IsDiagram returns true if the supplied element is a CrlDiagram
func IsDiagram(el core.Concept, trans *core.Transaction) bool {
switch el.(type) {
case core.Concept:
return el.IsRefinementOfURI(CrlDiagramURI, trans)
}
return false
}
// IsDiagramAbstractPointer returns true if the supplied element is a CrlDiagramAbstractPointer
func IsDiagramAbstractPointer(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramAbstractPointerURI, trans)
}
// IsDiagramElement returns true if the supplied element is a CrlDiagramElement
func IsDiagramElement(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramElementURI, trans)
}
// IsDiagramElementPointer returns true if the supplied element is a CrlDiagramElementPointer
func IsDiagramElementPointer(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramElementPointerURI, trans)
}
// IsDiagramLink returns true if the supplied element is a CrlDiagramLink
func IsDiagramLink(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramLinkURI, trans)
}
// IsDiagramNode returns true if the supplied element is a CrlDiagramNode
func IsDiagramNode(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramNodeURI, trans)
}
// IsDiagramOwnerPointer returns true if the supplied element is a CrlDiagramOwnerPointer
func IsDiagramOwnerPointer(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramOwnerPointerURI, trans)
}
// IsDiagramPointer returns true if the supplied element is a CrlDiagramPointer
func IsDiagramPointer(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramPointerURI, trans)
}
// IsDiagramRefinedPointer returns true if the supplied element is a CrlDiagramRefinedPointer
func IsDiagramRefinedPointer(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramRefinedPointerURI, trans)
}
// IsDiagramReferenceLink returns true if the supplied element is a CrlDiagramReferenceLink
func IsDiagramReferenceLink(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramReferenceLinkURI, trans)
}
// IsDiagramRefinementLink returns true if the supplied element is a CrlDiagramRefinementLink
func IsDiagramRefinementLink(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramRefinementLinkURI, trans)
}
// IsModelReference returns true if the supplied element is a ModelReference
func IsModelReference(el core.Concept, trans *core.Transaction) bool {
return el.IsRefinementOfURI(CrlDiagramElementModelReferenceURI, trans)
}
// IsDisplayLabel returns true if the supplied Literal is the DisplayLabel
func IsDisplayLabel(el core.Concept, trans *core.Transaction) bool {
if el == nil {
return false
}
return el.IsRefinementOfURI(CrlDiagramElementDisplayLabelURI, trans)
}
// NewDiagram creates a new diagram
func NewDiagram(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newDiagram, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramURI, "New Diagram", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramWidthURI, newDiagram, "Width", trans)
uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramHeightURI, newDiagram, "Height", trans)
return newDiagram, nil
}
// NewDiagramNode creates a new diagram node
func NewDiagramNode(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newNode, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramNodeURI, "New Node", trans)
addDiagramElementConcepts(newNode, trans)
addDiagramNodeConcepts(newNode, trans)
SetLineColor(newNode, "#00000000", trans)
return newNode, nil
}
// NewDiagramReferenceLink creates a new diagram link to represent a reference
func NewDiagramReferenceLink(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newLink, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramReferenceLinkURI, "ReferenceLink", trans)
addDiagramElementConcepts(newLink, trans)
addDiagramLinkConcepts(newLink, trans)
multiplicity, _ := uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramLinkMultiplicityURI, newLink, "Multiplicity", trans)
addAnchoredTextConcepts(multiplicity, trans)
return newLink, nil
}
// NewDiagramRefinementLink creates a new diagram link
func NewDiagramRefinementLink(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newLink, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramRefinementLinkURI, "RefinementLink", trans)
addDiagramElementConcepts(newLink, trans)
addDiagramLinkConcepts(newLink, trans)
return newLink, nil
}
// NewDiagramOwnerPointer creates a new DiagramOwnerPointer
func NewDiagramOwnerPointer(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newPointer, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramOwnerPointerURI, "OwnerPointer", trans)
addDiagramElementConcepts(newPointer, trans)
addDiagramLinkConcepts(newPointer, trans)
multiplicity, _ := uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramLinkMultiplicityURI, newPointer, "Multiplicity", trans)
addAnchoredTextConcepts(multiplicity, trans)
return newPointer, nil
}
// NewDiagramElementPointer creates a new DiagramElementPointer
func NewDiagramElementPointer(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newPointer, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramElementPointerURI, "ElementPointer", trans)
addDiagramElementConcepts(newPointer, trans)
addDiagramLinkConcepts(newPointer, trans)
return newPointer, nil
}
// NewDiagramAbstractPointer creates a new DiagramAbstractPointer
func NewDiagramAbstractPointer(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newPointer, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramAbstractPointerURI, "AbstractPointer", trans)
addDiagramElementConcepts(newPointer, trans)
addDiagramLinkConcepts(newPointer, trans)
return newPointer, nil
}
// NewDiagramRefinedPointer creates a new DiagramRefinedPointer
func NewDiagramRefinedPointer(trans *core.Transaction) (core.Concept, error) {
uOfD := trans.GetUniverseOfDiscourse()
newPointer, _ := uOfD.CreateRefinementOfConceptURI(CrlDiagramRefinedPointerURI, "RefinedPointer", trans)
addDiagramElementConcepts(newPointer, trans)
addDiagramLinkConcepts(newPointer, trans)
return newPointer, nil
}
// SetAbstractionDisplayLabel is a function on a CrlDiagramNode that sets the abstraction display label of the diagram node
func SetAbstractionDisplayLabel(diagramElement core.Concept, value string, trans *core.Transaction) {
if diagramElement == nil {
return
}
literal := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementAbstractionDisplayLabelURI, trans)
if literal == nil {
return
}
literal.SetLiteralValue(value, trans)
updateNodeSize(diagramElement, trans)
}
// SetDisplayLabel is a function on a CrlDiagramNode that sets the display label of the diagram element.
// If the diagram element is a pointer, the value is ignored and the label is set to the empty string
func SetDisplayLabel(diagramElement core.Concept, value string, trans *core.Transaction) {
if diagramElement == nil {
return
}
literal := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementDisplayLabelURI, trans)
if literal == nil {
return
}
if IsDiagramPointer(diagramElement, trans) {
literal.SetLiteralValue("", trans)
} else {
literal.SetLiteralValue(value, trans)
}
updateNodeSize(diagramElement, trans)
}
// SetLineColor is a function on a CrlDiagramElement that sets the line color for the diagram element.
func SetLineColor(diagramElement core.Concept, value string, trans *core.Transaction) {
if diagramElement == nil {
return
}
literal := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementLineColorURI, trans)
if literal == nil {
// This is remedial code: the literal should already be there
uOfD := trans.GetUniverseOfDiscourse()
literal, _ = uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramElementLineColorURI, diagramElement, "Line Color", trans)
}
literal.SetLiteralValue(value, trans)
}
// SetBGColor is a function on a CrlDiagramNode that sets the background color for the diagram element.
// If the diagram element is a pointer, the value is ignored and the label is set to the empty string
func SetBGColor(diagramElement core.Concept, value string, trans *core.Transaction) {
if diagramElement == nil {
return
}
literal := diagramElement.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramElementBGColorURI, trans)
if literal == nil {
// This is remedial code: the literal should already be there
uOfD := trans.GetUniverseOfDiscourse()
literal, _ = uOfD.CreateOwnedRefinementOfConceptURI(CrlDiagramElementBGColorURI, diagramElement, "Background Color", trans)
}
if IsDiagramPointer(diagramElement, trans) {
literal.SetLiteralValue("", trans)
} else {
literal.SetLiteralValue(value, trans)
}
}
// SetLinkSource is a convenience function for setting the source concept of a link
func SetLinkSource(diagramLink core.Concept, source core.Concept, trans *core.Transaction) {
if diagramLink == nil {
return
}
sourceReference := diagramLink.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramLinkSourceURI, trans)
if sourceReference != nil {
sourceReference.SetReferencedConcept(source, core.NoAttribute, trans)
}
}
// SetLinkTarget is a convenience function for setting the target concept of a link
func SetLinkTarget(diagramLink core.Concept, target core.Concept, trans *core.Transaction) {
if diagramLink == nil {
return
}
targetReference := diagramLink.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramLinkTargetURI, trans)
if targetReference != nil {
targetReference.SetReferencedConcept(target, core.NoAttribute, trans)
}
}
// SetNodeHeight is a function on a CrlDiagramNode that sets the height of the diagram node
func SetNodeHeight(diagramNode core.Concept, value float64, trans *core.Transaction) {
if diagramNode == nil {
return
}
literal := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeHeightURI, trans)
if literal == nil {
return
}
literal.SetLiteralValue(strconv.FormatFloat(value, 'f', -1, 64), trans)
}
// SetNodeWidth is a function on a CrlDiagramNode that sets the width of the diagram node
func SetNodeWidth(diagramNode core.Concept, value float64, trans *core.Transaction) {
if diagramNode == nil {
return
}
literal := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeWidthURI, trans)
if literal == nil {
return
}
literal.SetLiteralValue(strconv.FormatFloat(value, 'f', -1, 64), trans)
}
// SetNodeX is a function on a CrlDiagramNode that sets the x of the diagram node
func SetNodeX(diagramNode core.Concept, value float64, trans *core.Transaction) {
if diagramNode == nil {
return
}
literal := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeXURI, trans)
if literal == nil {
return
}
literal.SetLiteralValue(strconv.FormatFloat(value, 'f', -1, 64), trans)
}
// SetNodeY is a function on a CrlDiagramNode that sets the y of the diagram node
func SetNodeY(diagramNode core.Concept, value float64, trans *core.Transaction) {
if diagramNode == nil {
return
}
literal := diagramNode.GetFirstOwnedLiteralRefinementOfURI(CrlDiagramNodeYURI, trans)
if literal == nil {
return
}
literal.SetLiteralValue(strconv.FormatFloat(value, 'f', -1, 64), trans)
}
// SetReferencedModelConcept is a function on a CrlDiagramNode that sets the model element represented by the
// diagram node
func SetReferencedModelConcept(diagramElement core.Concept, el core.Concept, trans *core.Transaction) {
if diagramElement == nil {
return
}
reference := diagramElement.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramElementModelReferenceURI, trans)
if reference == nil {
return
}
reference.SetReferencedConcept(el, core.NoAttribute, trans)
updateDiagramElementForModelElementChange(diagramElement, el, trans)
}
// BuildCrlDiagramDomain builds the CrlDiagram concept space and adds it to the uOfD
func BuildCrlDiagramDomain(uOfD *core.UniverseOfDiscourse, trans *core.Transaction) core.Concept {
if uOfD.GetElementWithURI(crldatatypesdomain.CrlDataTypesDomainURI) == nil {
crldatatypesdomain.BuildCrlDataTypesDomain(uOfD, trans)
}
// CrlDiagramDomain
crlDiagramDomain, _ := uOfD.NewElement(trans, CrlDiagramDomainURI)
crlDiagramDomain.SetLabel("CrlDiagramDomain", trans)
//
// CrlDiagram
//
crlDiagram, _ := uOfD.NewOwnedElement(crlDiagramDomain, "CrlDiagram", trans, CrlDiagramURI)
uOfD.NewOwnedLiteral(crlDiagram, "Width", trans, CrlDiagramWidthURI)
uOfD.NewOwnedLiteral(crlDiagram, "Height", trans, CrlDiagramHeightURI)
// Diagram Anchored Text
crlDiagramAnchoredText, _ := uOfD.NewOwnedLiteral(crlDiagramDomain, "AnchoredText", trans, CrlDiagramAnchoredTextURI)
uOfD.NewOwnedLiteral(crlDiagramAnchoredText, "AnchorX", trans, CrlDiagramAnchoredTextAnchorXURI)
uOfD.NewOwnedLiteral(crlDiagramAnchoredText, "AnchorY", trans, CrlDiagramAnchoredTextAnchorYURI)
uOfD.NewOwnedLiteral(crlDiagramAnchoredText, "OffsetX", trans, CrlDiagramAnchoredTextOffsetXURI)
uOfD.NewOwnedLiteral(crlDiagramAnchoredText, "OffsetY", trans, CrlDiagramAnchoredTextOffsetYURI)
crldatatypesdomain.NewOwnedBoolean(crlDiagramAnchoredText, "Visible", trans, CrlDiagramAnchoredTextVisibleURI)
// Multiplicity
uOfD.CreateOwnedRefinementOfConcept(crlDiagramAnchoredText, crlDiagramDomain, "Multiplicity", trans, CrlDiagramLinkMultiplicityURI)
//
// CrlDiagramElement
//
crlDiagramElement, _ := uOfD.NewOwnedElement(crlDiagramDomain, "CrlDiagramElement", trans, CrlDiagramElementURI)
uOfD.NewOwnedReference(crlDiagramElement, "ModelReference", trans, CrlDiagramElementModelReferenceURI)
crlDisplayLabel, _ := uOfD.NewOwnedLiteral(crlDiagramElement, "DisplayLabel", trans, CrlDiagramElementDisplayLabelURI)
crlAbstractionDisplayLabel, _ := uOfD.NewOwnedLiteral(crlDiagramElement, "AbstractionDisplayLabel", trans, CrlDiagramElementAbstractionDisplayLabelURI)
uOfD.NewOwnedLiteral(crlDiagramElement, "LineColor", trans, CrlDiagramElementLineColorURI)
uOfD.NewOwnedLiteral(crlDiagramElement, "BGColor", trans, CrlDiagramElementBGColorURI)
//
// CrlDiagramNode
//
crlDiagramNode, _ := uOfD.CreateOwnedRefinementOfConcept(crlDiagramElement, crlDiagramDomain, "CrlDiagramNode", trans, CrlDiagramNodeURI)
uOfD.NewOwnedLiteral(crlDiagramNode, "X", trans, CrlDiagramNodeXURI)
uOfD.NewOwnedLiteral(crlDiagramNode, "Y", trans, CrlDiagramNodeYURI)
uOfD.NewOwnedLiteral(crlDiagramNode, "Height", trans, CrlDiagramNodeHeightURI)
uOfD.NewOwnedLiteral(crlDiagramNode, "Width", trans, CrlDiagramNodeWidthURI)
uOfD.NewOwnedLiteral(crlDiagramNode, "DisplayLabelYOffset", trans, CrlDiagramNodeDisplayLabelYOffsetURI)
//
// CrlDiagramLink
//
crlDiagramLink, _ := uOfD.CreateOwnedRefinementOfConcept(crlDiagramElement, crlDiagramDomain, "CrlDiagramLink", trans, CrlDiagramLinkURI)
uOfD.NewOwnedReference(crlDiagramLink, "Source", trans, CrlDiagramLinkSourceURI)
uOfD.NewOwnedReference(crlDiagramLink, "Target", trans, CrlDiagramLinkTargetURI)
floatingDisplayLabel, _ := uOfD.CreateOwnedRefinementOfConcept(crlDiagramAnchoredText, crlDiagramLink, "DisplayLabel", trans, CrlDiagramLinkDisplayLabelURI)
uOfD.AddAbstractionToConcept(floatingDisplayLabel, crlDisplayLabel, trans)
floatingAbstractionDisplayLabel, _ := uOfD.CreateOwnedRefinementOfConcept(crlDiagramAnchoredText, crlDiagramLink, "DisplayLabel", trans, CrlDiagramLinkAbstractionDisplayLabelURI)
uOfD.AddAbstractionToConcept(floatingAbstractionDisplayLabel, crlAbstractionDisplayLabel, trans)
uOfD.CreateOwnedRefinementOfConcept(crlDiagramLink, crlDiagramDomain, "ReferenceLink", trans, CrlDiagramReferenceLinkURI)
uOfD.CreateOwnedRefinementOfConcept(crlDiagramLink, crlDiagramDomain, "RefinementLink", trans, CrlDiagramRefinementLinkURI)
//
// Pointers
//
crlDiagramPointer, _ := uOfD.CreateOwnedRefinementOfConcept(crlDiagramLink, crlDiagramDomain, "Pointer", trans, CrlDiagramPointerURI)
uOfD.CreateOwnedRefinementOfConcept(crlDiagramPointer, crlDiagramDomain, "AbstractPointer", trans, CrlDiagramAbstractPointerURI)
uOfD.CreateOwnedRefinementOfConcept(crlDiagramPointer, crlDiagramDomain, "ElementPointer", trans, CrlDiagramElementPointerURI)
uOfD.CreateOwnedRefinementOfConcept(crlDiagramPointer, crlDiagramDomain, "OwnerPointer", trans, CrlDiagramOwnerPointerURI)
uOfD.CreateOwnedRefinementOfConcept(crlDiagramPointer, crlDiagramDomain, "RefinedPointer", trans, CrlDiagramRefinedPointerURI)
uOfD.AddFunction(CrlDiagramElementURI, updateDiagramElement)
uOfD.AddFunction(CrlDiagramOwnerPointerURI, updateDiagramOwnerPointer)
crlDiagramDomain.SetIsCoreRecursively(trans)
return crlDiagramDomain
}
// updateDiagramElement updates the diagram element
func updateDiagramElement(diagramElement core.Concept, notification *core.ChangeNotification, trans *core.Transaction) error {
uOfD := trans.GetUniverseOfDiscourse()
trans.WriteLockElement(diagramElement)
// core Elements should always be ignored
if diagramElement.GetIsCore(trans) {
return nil
}
diagram := diagramElement.GetOwningConcept(trans)
if diagram == nil {
// There is nothing to do
return nil
}
// Suppress circular notifications
underlyingChange := notification.GetUnderlyingChange()
if underlyingChange != nil && underlyingChange.IsReferenced(diagramElement) {
return nil
}
// There are several notifications of interest here:
// - the deletion of the referenced model element
// - the label of the referenced model element
// - the list of immediate abstractions of the referenced model element.
// First, determine whether it is the referenced model element that has changed
diagramElementModelReference := diagramElement.GetFirstOwnedReferenceRefinedFromURI(CrlDiagramElementModelReferenceURI, trans)
if diagramElementModelReference == nil {
// Without a model reference, there is nothing to do. This scenario can occur during diagramElement deletion.
return nil
}
modelElement := GetReferencedModelConcept(diagramElement, trans)
switch notification.GetNatureOfChange() {
case core.OwnedConceptChanged:
switch underlyingChange.GetNatureOfChange() {
case core.ConceptChanged:
if underlyingChange.GetReportingElementID() == diagramElementModelReference.GetConceptID(trans) {
// The underlying change is from the model reference
updateDiagramElementForModelElementChange(diagramElement, modelElement, trans)
}
case core.ReferencedConceptChanged:
underlyingReportingElementID := underlyingChange.GetReportingElementID()
if underlyingReportingElementID == diagramElementModelReference.GetConceptID(trans) {
// The underlying change is from the model reference
if IsDiagramNode(diagramElement, trans) {