-
Notifications
You must be signed in to change notification settings - Fork 10
/
msInterfaces.pas
639 lines (537 loc) · 18.6 KB
/
msInterfaces.pas
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
unit msInterfaces;
interface
uses
System.Types,
System.Classes,
FMX.Graphics,
System.UITypes,
msSerializeInterfaces,
Generics.Collections,
FMX.Objects,
Data.DBXJSONReflect,
msLineF,
System.Math.Vectors,
FMX.Types
;
type
Pixel = msLineF.Pixel;
TTextAlign = FMX.Types.TTextAlign;
TPathData = FMX.Graphics.TPathData;
TPolygon = System.Math.Vectors.TPolygon;
ImsShape = interface;
TPointF = System.Types.TPointF;
ImsShapeByPt = interface
function ShapeByPt(const aPoint: TPointF): ImsShape;
end;//ImsShapeByPt
ImsShapesController = interface(ImsShapeByPt)
procedure RemoveShape(const aShape: ImsShape);
function AddShape(const aShape: ImsShape): ImsShape;
procedure Invalidate;
function ShapeCount: Integer;
end;//ImsShapesController
// - òóò áû èìåòü ÌÍÎÆÅÑÒÂÅÍÍÎÅ íàñëåäîâàíèå èíòåðôåéñîâ, íî Delphi åãî íå ïîääåðæèâàåò
// À âîò ñ UML - ìû åãî ÏÎÒÎÌ ÑÃÅÍÅÐÈÐÓÅÌ
TmsDrawContext = record
// [Ñîñòîÿíèå (øàáëîí ïðîåêòèðîâàíèÿ)|https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%81%D1%82%D0%BE%D1%8F%D0%BD%D0%B8%D0%B5_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)]
// Êîíòåêñò ðèñîâàíèÿ.
// "Ëèðèêà" - òóò - http://habrahabr.ru/post/170125/
// Íó è "ñâÿçàííîå" - https://ru.wikipedia.org/wiki/%D0%A1%D1%82%D1%80%D0%B0%D1%82%D0%B5%D0%B3%D0%B8%D1%8F_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)
//
// Çà÷åì æå ÍÀÌ íóæåí "êîíòåêñò"?
//
// Âñ¸ - ÁÀÍÀËÜÍÎ. ×òîáû ÍÅ ÒÐÎÃÀÒÜ ñèãíàòóðû ìåòîäîâ. Ìûñëü ïîíÿòíà?
public
rCanvas : TCanvas;
rMoving : Boolean; // - îïðåäåëÿåì, ÷òî òåêóùèé ðèñóåìûé ïðèìèòèâ - äâèãàåòñÿ
rOpacity: Single;
rLineOpacity: Single;
constructor Create(const aCanvas : TCanvas);
end;//TmsDrawContext
TAlphaColor = System.UITypes.TAlphaColor;
TAlphaColorRec = System.UITypes.TAlphaColorRec;
TStrokeDash = FMX.Graphics.TStrokeDash;
TmsColorRec = record
rIsSet : Boolean;
rValue : TAlphaColor;
class operator Implicit(aValue: TAlphaColor): TmsColorRec;
end;//TmsColorRec
TmsPixelRec = record
rIsSet : Boolean;
rValue : Pixel;
class operator Implicit(aValue: Pixel): TmsPixelRec;
end;//TmsPixelRec
TmsRadiusRec = record
rIsSet : Boolean;
rValue : Pixel;
class operator Implicit(aValue: Pixel): TmsRadiusRec;
end;//TmsRadiusRec
TmsStrokeDash = record
rIsSet : Boolean;
rValue : TStrokeDash;
class operator Implicit(aValue: TStrokeDash): TmsStrokeDash;
end;//TmsStrokeDash
TmsDrawOptionsContext = record
public
rFillColor: TAlphaColor;
rStrokeDash: TStrokeDash;
rStrokeColor: TAlphaColor;
rStrokeThickness: Single;
rOpacity: Single;
rLineOpacity: Single;
constructor Create(const aCtx: TmsDrawContext);
end;//TmsDrawOptionsContext
ImsDiagrammsHolder = interface;
TmsMakeShapeContext = record
public
rStartPoint: TPointF;
rShapesController: ImsShapesController;
rDiagrammsHolder: ImsDiagrammsHolder;
constructor Create(aStartPoint: TPointF; const aShapesController: ImsShapesController; const aDiagrammsHolder: ImsDiagrammsHolder);
end;//TmsMakeShapeContext
TmsEndShapeContext = TmsMakeShapeContext;
ImsDiagramm = interface;
TmsDiagrammsEnumerator = TEnumerator<ImsDiagramm>;
ImsShapesProvider = interface(ImsPersistent)
procedure ShapesForToolbarToList(aList: TStrings);
end;//ImsShapesProvider
ImsDiagrammsList = interface(ImsShapesProvider)
function GetEnumerator: TmsDiagrammsEnumerator;
function IndexOf(const anItem: ImsDiagramm): Integer;
function AddNewDiagramm: ImsDiagramm;
procedure Add(const aDiagramm: ImsDiagramm);
function SelectDiagramm(const aDiagrammName: String): ImsDiagramm;
function FirstDiagramm: ImsDiagramm;
procedure DiagrammsForToolbarToList(aList: TStrings);
function pm_GetCount: Integer;
property Count: Integer
read pm_GetCount;
end;//ImsDiagrammsList
ImsShapeClass = interface;
ImsShapeCreator = interface;
TmsClickContext = record
public
rShapeCreator: ImsShapeCreator;
rClickPoint: TPointF;
rDiagrammsHolder : ImsDiagrammsHolder;
rShift: TShiftState;
constructor Create(const aShapeCreator: ImsShapeCreator; const aClickPoint: TPointF; const aDiagrammsHolder : ImsDiagrammsHolder; const aShift: TShiftState);
end;//TmsClickContext
TmsMoveContext = record
public
rStartPoint: TPointF;
rDelta: TPointF;
rShapesController: ImsShapesController;
constructor Create(const aStartPoint: TPointF; const aDelta: TPointF; const aShapesController: ImsShapesController);
end;//TmsMoveContext
TRectF = System.Types.TRectF;
// TGUID.NewGUID - ÷òîáû íå çàáûòü
TmsUID = record
public
rLo: Int64;
rHi: Int64;
public
class operator Add(anUID: TmsUID; aDelta: Int64): TmsUID;
class operator Subtract(anUID: TmsUID; aDelta: Int64): TmsUID;
constructor Create(const aGUID: TGUID);
class function CreateNew: TmsUID; static;
function IsNull: Boolean;
end;//TmsUID
TmsShapeUID = record
public
rValue: TmsUID;
public
constructor Create(const aGUID: TGUID);
class function CreateNew: TmsShapeUID; static;
class operator Add(anUID: TmsShapeUID; aDelta: Int64): TmsShapeUID;
class operator Subtract(anUID: TmsShapeUID; aDelta: Int64): TmsShapeUID;
class operator Implicit(aValue: Int64): TmsShapeUID;
class operator Implicit(const aValue: TmsUID): TmsShapeUID;
function IsNull: Boolean;
end;//TmsShapeUID
ImsShapeView = interface
procedure DrawShape(const aCtx: TmsDrawContext; const aShape: ImsShape);
function ShapeContainsPt(const aShape: ImsShape; const aPoint: TPointF): Boolean;
end;//ImsShapeView
ImsShape = interface(ImsDiagrammsList)
['{70D5F6A0-1025-418B-959B-0CF524D8E394}']
procedure DrawTo(const aCtx: TmsDrawContext);
function IsNeedsSecondClick : Boolean;
function MouseUp(const aClickContext: TmsEndShapeContext): Boolean;
function EndTo(const aCtx: TmsEndShapeContext): Boolean;
function HitTest(const aPoint: TPointF; out theShape: ImsShape): Boolean;
procedure MoveBy(const aCtx: TmsMoveContext);
function NullClick(const aHolder: ImsDiagrammsHolder): Boolean;
function ClickInDiagramm: Boolean;
// - òêíóëè â ïðèìèòèâ âíóòðè äèàãðàììû
function DrawBounds: TRectF;
procedure MouseMove(const aClickContext: TmsEndShapeContext);
// - äåéñòâèòå íàæàòèè
function UID: TmsShapeUID;
function TransformFinishPoint(anAngle: Single): TPointF;
// - ýòî óæå íå ñîâñåì êîñòûëü
// - êîñòûëè ïîêà
function Polygon: TPolygon;
function pm_GetStartPoint: TPointF;
function pm_GetFinishPoint: TPointF;
function pm_GetShapeClass: ImsShapeClass;
property StartPoint: TPointF
read pm_GetStartPoint;
property FinishPoint: TPointF
read pm_GetFinishPoint;
property ShapeClass: ImsShapeClass
read pm_GetShapeClass;
function Name: String;
end;//ImsShape
TmsWeakRef<T> = record
// Ñëàáàÿ ññûëêà íà èíòåðôåéñ
private
type PT = ^T;
private
rRef : Pointer;
public
function AsRef: T; inline;
constructor Create(const aT: T);
class operator Equal(const A: TmsWeakRef<T>; const B: TmsWeakRef<T>): Boolean; inline;
class operator Equal(const A: TmsWeakRef<T>; const B: T): Boolean; inline;
class operator Implicit(const aValue: T): TmsWeakRef<T>; inline;
class operator Implicit(const aValue: TmsWeakRef<T>): T; inline;
end;//TmsWeakRef
TmsWeakShapeRef = TmsWeakRef<ImsShape>;
TmsShapesEnumerator = TEnumerator<ImsShape>;
ImsShapeCreator = interface
// [Ôàáðè÷íûé_ìåòîä_(øàáëîí_ïðîåêòèðîâàíèÿ)|https://ru.wikipedia.org/wiki/%D0%A4%D0%B0%D0%B1%D1%80%D0%B8%D1%87%D0%BD%D1%8B%D0%B9_%D0%BC%D0%B5%D1%82%D0%BE%D0%B4_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)]
function CreateShape(const aContext: TmsMakeShapeContext): ImsShape; overload;
function CreateShape(const aStartPoint: TPointF): ImsShape; overload;
end;//ImsShapeCreator
ImsShapeCreatorFriend = interface
// - Ýòî "çàòû÷êà", íî ïîêà òàê. ×òîáû íå òåðÿòü òåìï.
['{59C7ED7A-C4C7-4632-A59C-2CBF070FCA19}']
function ShapeClassForCreate: TClass;
end;//ImsShapeCreatorFriend
TmsJSONMarshal = TJSONMarshal;
TmsJSONUnMarshal = TJSONUnMarshal;
ImsDiagrammsHolder = interface
procedure UpToParent;
// - ñèãíàëèçèðóåì î òîì, ÷òî íàì íàäî ïåðåéòè ê ÐÎÄÈÒÅËÜÑÊÎÉ äèàãðàììå
procedure SwapParents;
// - ñèãíàëèçèðóåì î òîì, ÷òî íàäî ÏÎÌÅÍßÒÜ ìåñòàìè ÐÎÄÈÒÅËÜÑÊÈÅ äèàãðàììû
procedure Scroll(const aDirection: TPointF);
// ^ - íå ñòåñíÿéòåñü ñòàâèòü const ïåðåä çàïèñÿìè.
// Òî÷íåå ñòàâüòå ÎÁßÇÀÒÅËÜÍÎ !!!
// - ñêðîëëèíã äèàãðàììû íà äåëüòó
procedure ResetOrigin;
// - âîññòàíàâëèâàåì íà÷àëüíóþ ñèñòåìó êîîðäèíàò
function GenerateUID(const aShape: ImsShape): TmsShapeUID;
// - ñîçäà¸ò UID äëÿ ïðèìèòèâà aShape
function pm_GetCurrentDiagramms: ImsDiagrammsList;
procedure pm_SetCurrentDiagramms(const aValue: ImsDiagrammsList);
property CurrentDiagramms : ImsDiagrammsList
read pm_GetCurrentDiagramms
write pm_SetCurrentDiagramms;
end;//ImsDiagrammsHolder
TmsStereotypePlace = (
None,
Center,
Bottom,
OneThirty
);//TmsStereotypePlace
TmsAdditionalLineCoeff = array of Single;
ImsShapeClassTuner = interface
function AsMC: ImsShapeClass;
function SetFillColor(aColor: TAlphaColor): ImsShapeClassTuner;
function SetStrokeColor(aColor: TAlphaColor): ImsShapeClassTuner;
function SetInitialHeight(aValue: Pixel): ImsShapeClassTuner;
function SetInitialHeightScale(aValue: Single): ImsShapeClassTuner;
function SetCornerRadius(aValue: Single): ImsShapeClassTuner;
function SetStrokeThickness(aValue: Pixel): ImsShapeClassTuner;
function SetStrokeDash(aValue: TStrokeDash): ImsShapeClassTuner;
function SetInitialWidth(aValue: Pixel): ImsShapeClassTuner;
function SetIsForToolbar(aValue: Boolean): ImsShapeClassTuner;
function SetStereotypePlace(aValue: TmsStereotypePlace): ImsShapeClassTuner;
function SetSVGCode(const aValue: String): ImsShapeClassTuner;
function SetAdditionalLinesH(const aValue: TmsAdditionalLineCoeff): ImsShapeClassTuner;
function SetShapeView(const aValue: ImsShapeView): ImsShapeClassTuner;
function SetText(const aValue: String): ImsShapeClassTuner;
function SetArrowHeadShapeMC(const aValue: ImsShapeClass): ImsShapeClassTuner;
end;//ImsShapeClassTuner
TmsShapeClassName = record
rValue : String;
class operator Implicit(const aValue: String): TmsShapeClassName;
class operator Implicit(const aSelf: TmsShapeClassName): String;
class operator Equal(const A: TmsShapeClassName; const B: TmsShapeClassName): Boolean;
end;//TmsShapeClassName
TmsShapeStereotype = TmsShapeClassName;
ImsShapeClass = interface
function IsForToolbar: Boolean;
function IsTool: Boolean;
function IsLineLike: Boolean;
function IsConnectorLike: Boolean;
function Creator: ImsShapeCreator;
function Name: TmsShapeClassName;
procedure RegisterInMarshal(aMarshal: TmsJSONMarshal);
procedure RegisterInUnMarshal(aMarshal: TmsJSONUnMarshal);
function IsNullClick: Boolean;
function ButtonShape: ImsShape;
function IsOurInstance(const aShape: ImsShape): Boolean;
function NullClick(const aHolder: ImsDiagrammsHolder): Boolean;
function Stereotype: TmsShapeStereotype;
procedure TransformDrawOptionsContext(var theCtx: TmsDrawOptionsContext);
function InitialHeight: Pixel;
function InitialWidth: Pixel;
function CornerRadius: Pixel;
function ParentMC: ImsShapeClass;
function AsTuner: ImsShapeClassTuner;
function StereotypePlace: TmsStereotypePlace;
function SVGCode: String;
function AdditionalLinesH: TmsAdditionalLineCoeff;
function Specify(const aName: String): ImsShapeClassTuner;
function CreateShape(const aStartPoint: TPointF): ImsShape; overload;
function CreateShape(const aContext: TmsMakeShapeContext): ImsShape; overload;
function ShapeView: ImsShapeView;
function Text: String;
function ArrowHeadShapeMC: ImsShapeClass;
end;//ImsShapeClass
ImsDiagramm = interface(ImsShapesProvider)
['{59F2D068-F06F-4378-9ED4-888DFE8DFAF2}']
function Get_Name: String;
procedure Invalidate;
procedure MouseDown(const aClickContext: TmsClickContext);
procedure MouseUp(const aClickContex: TmsClickContext);
procedure MouseMove(const aClickContex: TmsClickContext);
procedure Clear;
procedure DrawTo(const aCanvas: TCanvas);
procedure SaveToPng(const aFileName: String);
function AddShape(const aShape: ImsShape): ImsShape;
procedure RemoveShape(const aShape: ImsShape);
function GetEnumerator: TmsShapesEnumerator;
function ItemsCount: Integer;
function FirstShape: ImsShape;
function ShapesController: ImsShapesController;
property Name: String
read Get_Name;
end;//ImsDiagramm
ImsDiagramms = interface(ImsDiagrammsList)
procedure Serialize;
procedure DeSerialize;
end;//ImsDiagramms
ImsInvalidator = interface
procedure InvalidateDiagramm(const aDiagramm: ImsDiagramm);
procedure DiagrammAdded(const aDiagramms: ImsDiagrammsList; const aDiagramm: ImsDiagramm);
end;//ImsInvalidator
ImsDiagrammsController = interface
procedure Clear;
procedure DrawTo(const aCanvas: TCanvas);
function As_ImsDiagrammsHolder: ImsDiagrammsHolder;
end;//ImsDiagrammsController
TmsWeakInvalidatorRef = TmsWeakRef<ImsInvalidator>;
TmsWeakShapeClassRef = TmsWeakRef<ImsShapeClass>;
implementation
uses
Math,
System.StrUtils,
System.SysUtils
;
// TmsDrawContext
constructor TmsDrawContext.Create(const aCanvas : TCanvas);
begin
rCanvas := aCanvas;
rMoving := false;
rOpacity := 0.5;
rLineOpacity := 1.0;
end;
// TmsMakeShapeContext
constructor TmsMakeShapeContext.Create(aStartPoint: TPointF; const aShapesController: ImsShapesController; const aDiagrammsHolder: ImsDiagrammsHolder);
begin
rStartPoint := aStartPoint;
rShapesController := aShapesController;
rDiagrammsHolder := aDiagrammsHolder;
end;
// TmsDrawOptionsContext
constructor TmsDrawOptionsContext.Create(const aCtx: TmsDrawContext);
begin
rFillColor := TAlphaColorRec.Null;
rOpacity := 0.5;
rLineOpacity := 1.0;
if aCtx.rMoving then
begin
rStrokeDash := TStrokeDash.DashDot;
rStrokeColor := TAlphaColors.Darkmagenta;
rStrokeThickness := 4;
end//aCtx.rMoving
else
begin
rStrokeDash := TStrokeDash.Solid;
rStrokeColor := TAlphaColorRec.Black;
rStrokeThickness := 1;
end;//aCtx.rMoving
end;
// TmsClickContext
constructor TmsClickContext.Create(const aShapeCreator: ImsShapeCreator; const aClickPoint: TPointF; const aDiagrammsHolder : ImsDiagrammsHolder; const aShift: TShiftState);
begin
rShapeCreator := aShapeCreator;
rClickPoint := aClickPoint;
rDiagrammsHolder := aDiagrammsHolder;
rShift := aShift;
end;
// TmsMoveContext
constructor TmsMoveContext.Create(const aStartPoint: TPointF; const aDelta: TPointF; const aShapesController: ImsShapesController);
begin
rStartPoint := aStartPoint;
rDelta := aDelta;
rShapesController := aShapesController;
end;
// TmsColorRec
class operator TmsColorRec.Implicit(aValue: TAlphaColor): TmsColorRec;
begin
Result.rIsSet := true;
Result.rValue := aValue;
end;
// TmsPixelRec
class operator TmsPixelRec.Implicit(aValue: Pixel): TmsPixelRec;
begin
if IsZero(aValue) OR (aValue < 0) then
Result.rIsSet := false
else
begin
Result.rIsSet := true;
Result.rValue := aValue;
end;//IsZero(aValue) OR (aValue < 0)
end;
// TmsRadiusRec
class operator TmsRadiusRec.Implicit(aValue: Pixel): TmsRadiusRec;
begin
if (aValue < 0) then
Result.rIsSet := false
else
begin
Result.rIsSet := true;
Result.rValue := aValue;
end;//(aValue < 0)
end;
// TmsStrokeDash
class operator TmsStrokeDash.Implicit(aValue: TStrokeDash): TmsStrokeDash;
begin
Result.rIsSet := true;
Result.rValue := aValue;
end;
// TmsShapeClassName
class operator TmsShapeClassName.Implicit(const aValue: String): TmsShapeClassName;
const
cPref = 'Tms';
begin
Result.rValue := aValue;
if ANSIStartsText(cPref, Result.rValue) then
Result.rValue := Copy(Result.rValue, Length(cPref) + 1, Length(Result.rValue) - Length(cPref));
end;
class operator TmsShapeClassName.Implicit(const aSelf: TmsShapeClassName): String;
begin
Result := aSelf.rValue;
end;
class operator TmsShapeClassName.Equal(const A: TmsShapeClassName; const B: TmsShapeClassName): Boolean;
begin
Result := (A.rValue = B.rValue);
end;
// TmsUID
class function TmsUID.CreateNew: TmsUID;
begin
Result := TmsUID.Create(TGUID.NewGUID);
end;
constructor TmsUID.Create(const aGUID: TGUID);
begin
Assert(SizeOf(Self) = SizeOf(aGUID));
Move(aGUID, Self, SizeOf(Self));
end;
class operator TmsUID.Add(anUID: TmsUID; aDelta: Int64): TmsUID;
begin
Result := anUID;
Assert(SizeOf(anUID) = SizeOf(TGUID));
Assert(aDelta >= 0);
if (aDelta > 0) then
begin
if (anUID.rLo - aDelta < High(anUID.rLo)) then
begin
Result.rLo := anUID.rLo + aDelta;
Result.rHi := 0;
end//anUID.rLo - aDelta < High(anUID.rLo)
else
begin
Assert(false, 'Íå ðåàëèçîâàíî');
Assert(anUID.rHi - aDelta < High(anUID.rHi), 'Íå ðåàëèçîâàíî');
Result.rHi := anUID.rHi + 1;
Result.rLo := 0;
Result := Result + (aDelta - 1);
end;//anUID.rLo - aDelta < High(anUID.rLo)
end;//aDelta > 0
end;
class operator TmsUID.Subtract(anUID: TmsUID; aDelta: Int64): TmsUID;
begin
Result := anUID;
Assert(aDelta >= 0);
if (aDelta > 0) then
begin
Assert(false, 'Íå ðåàëèçîâàíî');
end;//aDelta > 0
end;
function TmsUID.IsNull: Boolean;
begin
Result := (rLo = 0) AND (rHi = 0);
end;
// TmsShapeUID
constructor TmsShapeUID.Create(const aGUID: TGUID);
begin
rValue := TmsUID.Create(aGUID);
end;
class function TmsShapeUID.CreateNew: TmsShapeUID;
begin
Result.rValue := TmsUID.CreateNew;
end;
class operator TmsShapeUID.Add(anUID: TmsShapeUID; aDelta: Int64): TmsShapeUID;
begin
Result.rValue := anUID.rValue + aDelta;
end;
class operator TmsShapeUID.Subtract(anUID: TmsShapeUID; aDelta: Int64): TmsShapeUID;
begin
Result.rValue := anUID.rValue - aDelta;
end;
class operator TmsShapeUID.Implicit(aValue: Int64): TmsShapeUID;
begin
Result.rValue.rLo := aValue;
Result.rValue.rHi := 0;
end;
class operator TmsShapeUID.Implicit(const aValue: TmsUID): TmsShapeUID;
begin
Result.rValue := aValue;
end;
function TmsShapeUID.IsNull: Boolean;
begin
Result := rValue.IsNull;
end;
// TmsWeakRef<T>
constructor TmsWeakRef<T>.Create(const aT: T);
begin
Assert(SizeOf(aT) = SizeOf(Self.rRef));
Self.rRef := PPointer(@aT)^;
end;
function TmsWeakRef<T>.AsRef: T;
begin
Assert(SizeOf(Self.rRef) = SizeOf(Result));
Result := PT(@Self.rRef)^;
end;
class operator TmsWeakRef<T>.Implicit(const aValue: TmsWeakRef<T>): T;
begin
Result := aValue.AsRef;
end;
class operator TmsWeakRef<T>.Equal(const A: TmsWeakRef<T>; const B: TmsWeakRef<T>): Boolean;
begin
Result := (A.rRef = B.rRef);
end;
class operator TmsWeakRef<T>.Equal(const A: TmsWeakRef<T>; const B: T): Boolean;
begin
Assert(SizeOf(B) = SizeOf(A));
Result := (A.rRef = PPointer(@B)^);
end;
class operator TmsWeakRef<T>.Implicit(const aValue: T): TmsWeakRef<T>;
begin
Result := TmsWeakRef<T>.Create(aValue);
end;
end.