-
Notifications
You must be signed in to change notification settings - Fork 9
/
LinkedScale.cs
739 lines (623 loc) · 25.2 KB
/
LinkedScale.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
#region Copyright
/////////////////////////////////////////////////////////////////////////////
// Altaxo: a data processing and data plotting program
// Copyright (C) 2002-2011 Dr. Dirk Lellinger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
/////////////////////////////////////////////////////////////////////////////
#endregion Copyright
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Altaxo.Data;
using Altaxo.Graph.Scales.Boundaries;
using Altaxo.Main;
namespace Altaxo.Graph.Scales
{
[Serializable]
public class LinkedScale : Scale
{
/// <summary>
/// The (real) scale which is behind this fassade. Can not be another linked scale.
/// It is recommended that the type of this scale matches the type of the scale linked to.
/// In some rather rare cases the type of this scale may be different than the type of the scale linked to.
/// </summary>
private Scale _scaleWrapped;
/// <summary>
/// The _scale linked to. This scale normally is located in a sibling layer.
/// </summary>
private RelDocNodeProxy? _scaleLinkedToProxy;
/// <summary>
/// Store the reference of the resolved scale linked to in order to detect when a new scale is resolved. If this is the case, the new scale must be tested for circular dependencies.
/// </summary>
private WeakReference _cachedResolvedScaleLinkedToWeak = new WeakReference(new object());
/// <summary>
/// Flag that indicated whether the latest resolved scaleLinkedTo was circular dependent on this scale. In this case the case is treated as if no Scale could be resolved.
/// </summary>
private bool _isScaleCircularDependend;
private LinkedScaleParameters _linkParameters;
/// <summary>
/// If true, the type of wrapped scale is the same as the type of the scale linked to
/// </summary>
protected bool _linkScaleType;
/// <summary>
/// If true, the tick spacing is used from the scale linked to 1:1
/// </summary>
protected bool _linkTickSpacing;
/// <summary>
/// The cached update sequence number of the TickSpacing of the scale linked to.
/// </summary>
protected int _cachedUSNOfScaleLinkedToTickSpacing;
#region Serialization
[Obsolete]
private int? _linkedScaleIndex;
[Obsolete]
private int? _linkedLayerIndex;
[Altaxo.Serialization.Xml.XmlSerializationSurrogateFor("AltaxoBase", "Altaxo.Graph.Scales.LinkedScale", 2)]
private class XmlSerializationSurrogate2 : Altaxo.Serialization.Xml.IXmlSerializationSurrogate
{
public virtual void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
{
throw new InvalidOperationException("Serialization of old versions not supported.");
/*
LinkedScale s = (LinkedScale)obj;
info.AddValue("ScaleWrapped", s._scaleWrapped);
info.AddValue("LinkParameters", s._linkParameters);
info.AddValue("LinkedScaleIndex", s._linkedScaleIndex);
*/
}
public object Deserialize(object? o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object? parent)
{
var s = SDeserialize(o, info, parent);
return s;
}
protected virtual LinkedScale SDeserialize(object? o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object? parent)
{
var s = (LinkedScale?)o ?? new LinkedScale(info);
s.WrappedScale = (Scale)info.GetValue("ScaleWrapped", s);
s._linkParameters = (LinkedScaleParameters)info.GetValue("LinkParameters", s);
if (s._linkParameters is not null)
s._linkParameters.ParentObject = s;
#pragma warning disable CS0612 // Type or member is obsolete
s._linkedScaleIndex = info.GetInt32("LinkedScaleIndex");
#pragma warning restore CS0612 // Type or member is obsolete
return s;
}
}
[Obsolete]
public void SetLinkedLayerIndex(int linkedLayerIndex, Altaxo.Serialization.Xml.IXmlDeserializationInfo info)
{
_linkedLayerIndex = linkedLayerIndex;
info.DeserializationFinished += EhXmlDeserializationFinished_UseLinkedScaleAndLayerIndex;
}
[Obsolete]
private void EhXmlDeserializationFinished_UseLinkedScaleAndLayerIndex(Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object documentRoot, bool isFinallyCall)
{
if (_linkedScaleIndex is not null && _linkedLayerIndex is not null)
{
int linkedScaleIndex = _linkedScaleIndex.Value;
int linkedLayerIndex = _linkedLayerIndex.Value;
// Retrieve the document
Scale? scale = null;
var layer = AbsoluteDocumentPath.GetRootNodeImplementing<Altaxo.Graph.Gdi.HostLayer>(this);
if (layer is not null)
{
var parentLayer = layer.ParentLayer;
if (parentLayer is not null)
{
var sibling = parentLayer.Layers[linkedLayerIndex] as Altaxo.Graph.Gdi.XYPlotLayer;
if (sibling is not null)
{
scale = sibling.Scales[linkedScaleIndex];
}
}
}
if (scale is not null)
ScaleLinkedTo = scale;
}
if (ScaleLinkedTo is not null || isFinallyCall)
info.DeserializationFinished -= EhXmlDeserializationFinished_UseLinkedScaleAndLayerIndex;
}
/// <summary>
/// 2013-09-26 LinkedLayerIndex added, thus scale is now directly linked
/// </summary>
[Altaxo.Serialization.Xml.XmlSerializationSurrogateFor("AltaxoBase", "Altaxo.Graph.Scales.LinkedScale", 3)]
private class XmlSerializationSurrogate3 : Altaxo.Serialization.Xml.IXmlSerializationSurrogate
{
/// <summary>Index of linked scale in the layer where the linked scale is located.</summary>
private int _linkedScaleIndex;
/// <summary>
/// Number of the layer where the linked scale can be located. Note that the linked layer must have the same parent layer that the layer this scale belongs to.
/// </summary>
private int _linkedLayerIndex;
private LinkedScale? _instance;
public virtual void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
{
throw new InvalidOperationException("Serialization of old versions not supported.");
/*
LinkedScale s = (LinkedScale)obj;
info.AddValue("ScaleWrapped", s._scaleWrapped);
info.AddValue("LinkParameters", s._linkParameters);
info.AddValue("LinkedScaleIndex", s._linkedScaleIndex);
info.AddValue("LinkedLayerIndex", s._linkedLayerIndex);
*/
}
public object Deserialize(object? o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object? parent)
{
var s = SDeserialize(o, info, parent);
return s;
}
protected virtual LinkedScale SDeserialize(object? o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object? parent)
{
var s = (LinkedScale?)o ?? new LinkedScale(info);
s.WrappedScale = (Scale)info.GetValue("ScaleWrapped", s);
s.LinkParameters = (LinkedScaleParameters)info.GetValue("LinkParameters", s);
var surr = new XmlSerializationSurrogate3
{
_linkedScaleIndex = info.GetInt32("LinkedScaleIndex"),
_linkedLayerIndex = info.GetInt32("LinkedLayerIndex"),
_instance = s
};
// create a callback to resolve the instance as early as possible
info.DeserializationFinished += surr.EhXmlDeserializationFinished;
return s;
}
private void EhXmlDeserializationFinished(Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object documentRoot, bool isFinallyCall)
{
if (_instance is null)
return;
// Retrieve the document
Scale? scale = null;
var layer = AbsoluteDocumentPath.GetRootNodeImplementing<Altaxo.Graph.Gdi.HostLayer>(_instance);
if (layer is not null)
{
var parentLayer = layer.ParentLayer;
if (parentLayer is not null)
{
var sibling = parentLayer.Layers[_linkedLayerIndex] as Altaxo.Graph.Gdi.XYPlotLayer;
if (sibling is not null)
{
scale = sibling.Scales[_linkedScaleIndex];
}
}
}
if (scale is not null || isFinallyCall)
{
if (scale is not null)
_instance.ScaleLinkedTo = scale;
info.DeserializationFinished -= EhXmlDeserializationFinished;
}
}
}
/// <summary>
/// 2014-01-01 LinkedScale is now saved as a RelDocNodeProxy
/// </summary>
[Altaxo.Serialization.Xml.XmlSerializationSurrogateFor("AltaxoBase", "Altaxo.Graph.Scales.LinkedScale", 4)]
private class XmlSerializationSurrogate4 : Altaxo.Serialization.Xml.IXmlSerializationSurrogate
{
public virtual void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
{
var s = (LinkedScale)obj;
info.AddValue("ScaleWrapped", s._scaleWrapped);
info.AddValueOrNull("ScaleLinkedTo", s._scaleLinkedToProxy);
info.AddValue("LinkParameters", s._linkParameters);
}
public object Deserialize(object? o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object? parent)
{
var s = (LinkedScale?)o ?? new LinkedScale(info);
s.WrappedScale = (Scale)info.GetValue("ScaleWrapped", s);
s.ChildSetMember(ref s._scaleLinkedToProxy, info.GetValueOrNull<Main.RelDocNodeProxy>("ScaleLinkedTo", s));
s.LinkParameters = (LinkedScaleParameters)info.GetValue("LinkParameters", s);
return s;
}
}
/// <summary>
/// 2015-02-13 added parameters _linkScaleType and _linkTickSpacing
/// </summary>
[Altaxo.Serialization.Xml.XmlSerializationSurrogateFor(typeof(LinkedScale), 5)]
private class XmlSerializationSurrogate5 : Altaxo.Serialization.Xml.IXmlSerializationSurrogate
{
public virtual void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
{
var s = (LinkedScale)obj;
info.AddValue("ScaleWrapped", s._scaleWrapped);
info.AddValueOrNull("ScaleLinkedTo", s._scaleLinkedToProxy);
info.AddValue("LinkParameters", s._linkParameters);
info.AddValue("LinkScaleType", s._linkScaleType);
info.AddValue("LinkTickSpacing", s._linkTickSpacing);
}
public object Deserialize(object? o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object? parent)
{
var s = (LinkedScale?)o ?? new LinkedScale(info);
s.WrappedScale = (Scale)info.GetValue("ScaleWrapped", s);
s.ChildSetMember(ref s._scaleLinkedToProxy, info.GetValueOrNull<Main.RelDocNodeProxy>("ScaleLinkedTo", s));
s.LinkParameters = (LinkedScaleParameters)info.GetValue("LinkParameters", s);
s._linkScaleType = info.GetBoolean("LinkScaleType");
s._linkTickSpacing = info.GetBoolean("LinkTickSpacing");
return s;
}
}
#endregion Serialization
#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
private LinkedScale(Altaxo.Serialization.Xml.IXmlDeserializationInfo info)
{
}
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
public LinkedScale(Scale scaleToWrap)
{
_linkParameters = new LinkedScaleParameters() { ParentObject = this };
WrappedScale = scaleToWrap;
}
[Obsolete("Only for old deserialization purposes")]
public LinkedScale(Scale scaleToWrap, int scaleNumberLinkedTo)
{
_linkParameters = new LinkedScaleParameters() { ParentObject = this };
WrappedScale = scaleToWrap;
_linkedScaleIndex = scaleNumberLinkedTo;
}
public LinkedScale(LinkedScale from)
{
CopyFrom(from);
}
[MemberNotNull(nameof(_linkParameters), nameof(_scaleWrapped))]
protected void CopyFrom(LinkedScale from)
{
using (var suspendToken = SuspendGetToken())
{
ChildCopyToMember(ref _linkParameters, from._linkParameters);
ChildCopyToMember(ref _scaleWrapped, from._scaleWrapped);
ChildSetMember(ref _scaleLinkedToProxy, from._scaleLinkedToProxy is null ? null : new RelDocNodeProxy(from._scaleLinkedToProxy, true, this));
_linkScaleType = from._linkScaleType;
_linkTickSpacing = from._linkTickSpacing;
_cachedResolvedScaleLinkedToWeak.Target = from._cachedResolvedScaleLinkedToWeak.Target;
EhSelfChanged(EventArgs.Empty);
suspendToken.Resume();
}
}
public override bool CopyFrom(object obj)
{
if (ReferenceEquals(this, obj))
return true;
if (obj is LinkedScale from)
{
CopyFrom(from);
return true;
}
return false;
}
protected override System.Collections.Generic.IEnumerable<Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName()
{
if (_scaleWrapped is not null)
yield return new Main.DocumentNodeAndName(_scaleWrapped, () => _scaleWrapped = null!, "ScaleWrapped");
if (_linkParameters is not null)
yield return new Main.DocumentNodeAndName(_linkParameters, () => _linkParameters = null!, "LinkParameters");
if (_scaleLinkedToProxy is not null)
yield return new Main.DocumentNodeAndName(_scaleLinkedToProxy, () => _scaleLinkedToProxy = null!, "ScaleLinkedTo");
}
public override object Clone()
{
return new LinkedScale(this);
}
[MaybeNull]
public Scale ScaleLinkedTo
{
get
{
var scaleLinkedTo = _scaleLinkedToProxy is not null ? (_scaleLinkedToProxy.Document as Scale) : null;
if (scaleLinkedTo is not null && !object.ReferenceEquals(scaleLinkedTo, _cachedResolvedScaleLinkedToWeak.Target)) // seems to be a newly resolved instance
{
// then we have to test whether this instance is circular dependent
_cachedResolvedScaleLinkedToWeak = new WeakReference(scaleLinkedTo);
// Test for circular references
_isScaleCircularDependend = IsScaleDependentOnMe(scaleLinkedTo);
}
return _isScaleCircularDependend ? null : scaleLinkedTo; // if it is circular dependent, return null
}
set
{
if (object.ReferenceEquals(value, _scaleLinkedToProxy is not null ? (_scaleLinkedToProxy.Document as Scale) : null))
return;
if (ChildSetMember(ref _scaleLinkedToProxy, new RelDocNodeProxy(value, this)))
{
OnLinkPropertiesChanged(); // calculated the bounds of the wrapped scale
}
}
}
/// <summary>
/// Checks if the scale in the argument is dependend on this Scale. This would mean a circular dependency, which should be avoided.
/// </summary>
/// <param name="scaleToTest">The scale to check.</param>
/// <returns>True if the provided scale or one of its linked scales is dependend on this scale.</returns>
public bool IsScaleDependentOnMe(Scale scaleToTest)
{
return WouldScaleBeDependentOnMe(this, scaleToTest);
}
/// <summary>
/// Checks if the scale in the argument is dependend on this Scale. This would mean a circular dependency, which should be avoided.
/// </summary>
/// <param name="scaleThatWouldBecomeALinkedScale">Scale that is a linked scale or that would become a linked scale.</param>
/// <param name="scaleToTest">The scale to check.</param>
/// <returns>True if the provided scale or one of its linked scales is dependend on this scale.</returns>
public static bool WouldScaleBeDependentOnMe(Scale scaleThatWouldBecomeALinkedScale, Scale scaleToTest)
{
if (object.ReferenceEquals(scaleThatWouldBecomeALinkedScale, scaleToTest))
return true; // Scale are identical, thus they are really dependent on each other
var linkedScale = scaleToTest as LinkedScale;
while (linkedScale is not null)
{
if (object.ReferenceEquals(scaleThatWouldBecomeALinkedScale, linkedScale))
return true; // this means a direct circular dependency (we are at the original scale), so return true
if (object.ReferenceEquals(scaleThatWouldBecomeALinkedScale, linkedScale.ScaleLinkedTo))
return true; // That would mean a circular dependency also, thus also return true;
linkedScale = linkedScale.ScaleLinkedTo as LinkedScale;
}
return false; // no dependency detected
}
/// <summary>
/// If true, the type of wrapped scale is the same as the type of the scale linked to
/// </summary>
public bool LinkScaleType
{
get
{
return _linkScaleType;
}
set
{
var oldValue = _linkScaleType;
_linkScaleType = value;
if (value != oldValue)
{
OnLinkPropertiesChanged();
EhSelfChanged(EventArgs.Empty);
}
}
}
/// <summary>
/// If true, the tick spacing is used from the scale linked to 1:1
/// </summary>
public bool LinkTickSpacing
{
get
{
return _linkTickSpacing;
}
set
{
var oldValue = _linkTickSpacing;
_linkTickSpacing = value;
if (value != oldValue)
{
OnLinkPropertiesChanged();
EhSelfChanged(EventArgs.Empty);
}
}
}
public bool IsStraightLink
{
get
{
return _linkParameters.IsStraightLink;
}
}
/// <summary>
/// Set all parameters of the axis link by once.
/// </summary>
/// <param name="orgA">The value a of x-axis link for link of axis origin: org' = a + b*org.</param>
/// <param name="orgB">The value b of x-axis link for link of axis origin: org' = a + b*org.</param>
/// <param name="endA">The value a of x-axis link for link of axis end: end' = a + b*end.</param>
/// <param name="endB">The value b of x-axis link for link of axis end: end' = a + b*end.</param>
public void SetLinkParameter(double orgA, double orgB, double endA, double endB)
{
_linkParameters.SetTo(orgA, orgB, endA, endB);
}
public void SetLinkParameterToStraightLink()
{
_linkParameters.SetToStraightLink();
}
public LinkedScaleParameters LinkParameters
{
get
{
return _linkParameters;
}
set
{
if (ChildSetMember(ref _linkParameters, value ?? new LinkedScaleParameters()))
EhSelfChanged(EventArgs.Empty);
}
}
public double LinkOrgA
{
get { return _linkParameters.OrgA; }
set
{
_linkParameters.OrgA = value;
}
}
public double LinkOrgB
{
get { return _linkParameters.OrgB; }
set
{
_linkParameters.OrgB = value;
}
}
public double LinkEndA
{
get { return _linkParameters.EndA; }
set
{
_linkParameters.EndA = value;
}
}
public double LinkEndB
{
get { return _linkParameters.EndB; }
set
{
_linkParameters.EndB = value;
OnLinkPropertiesChanged();
}
}
public Scale WrappedScale
{
get
{
return _scaleWrapped;
}
[MemberNotNull(nameof(_scaleWrapped))]
set
{
if (value is null)
throw new ArgumentNullException(nameof(WrappedScale));
if (ChildSetMember(ref _scaleWrapped, value))
{
OnLinkPropertiesChanged();
EhSelfChanged(EventArgs.Empty);
}
}
}
public override Ticks.TickSpacing TickSpacing
{
get
{
return WrappedScale.TickSpacing;
}
set
{
WrappedScale.TickSpacing = value;
}
}
public override double PhysicalVariantToNormal(Altaxo.Data.AltaxoVariant x)
{
return _scaleWrapped.PhysicalVariantToNormal(x);
}
public override Altaxo.Data.AltaxoVariant NormalToPhysicalVariant(double x)
{
return _scaleWrapped.NormalToPhysicalVariant(x);
}
public override Rescaling.IScaleRescaleConditions? RescalingObject
{
get { return _scaleWrapped.RescalingObject; }
}
public override IPhysicalBoundaries DataBoundsObject
{
get
{
var scaleLinkedTo = ScaleLinkedTo;
if (ReferenceEquals(this, scaleLinkedTo))
throw new InvalidProgramException("_scaleLinkedTo is reference equal to this scale. Please report this error to the forum");
// it is not possible for a this scale to act back to the scale which is linked
// 2015-07-06 dont give the databounds object of the linked scale, because the following will happen:
// when the user pressed rescale or the data changed in the layer with this scale, the data of this layer where given to the linked scale
// but this will not take the data of the layer where the linked scale resides into account, thus avoid this
return _scaleWrapped.DataBoundsObject;
}
}
public override Altaxo.Data.AltaxoVariant OrgAsVariant
{
get
{
return _scaleWrapped.OrgAsVariant;
}
}
public override Altaxo.Data.AltaxoVariant EndAsVariant
{
get
{
return _scaleWrapped.EndAsVariant;
}
}
public override void OnUserRescaled()
{
var scaleLinkedTo = ScaleLinkedTo;
if (scaleLinkedTo is not null)
scaleLinkedTo.OnUserRescaled();
}
public override void OnUserZoomed(AltaxoVariant newZoomOrg, AltaxoVariant newZoomEnd)
{
// ignore this - we are linked
}
protected override string? SetScaleOrgEnd(Altaxo.Data.AltaxoVariant org, Altaxo.Data.AltaxoVariant end)
{
var scaleLinkedTo = ScaleLinkedTo;
if (scaleLinkedTo is not null)
{
if (!IsStraightLink)
{
org = (org - LinkOrgA) / LinkOrgB;
end = (end - LinkEndA) / LinkEndB;
}
throw new NotImplementedException("What should we do here?");
//return scaleLinkedTo.SetScaleOrgEnd(org, end);
}
return null;
}
#region Changed event handling
protected override bool HandleHighPriorityChildChangeCases(object? sender, ref EventArgs e)
{
if (object.ReferenceEquals(sender, _linkParameters))
{
OnLinkPropertiesChanged();
}
else if (object.ReferenceEquals(sender, _scaleLinkedToProxy))
{
OnLinkPropertiesChanged();
}
return base.HandleHighPriorityChildChangeCases(sender, ref e);
}
private void EhLinkedScaleChanged(object? sender, EventArgs e)
{
OnLinkPropertiesChanged();
}
protected virtual void OnLinkPropertiesChanged()
{
// calculate the new bounds
var scaleLinkedTo = ScaleLinkedTo;
if (scaleLinkedTo is not null)
{
// Test if the type of wrapped scale matches
if (_linkScaleType && scaleLinkedTo.GetType() != WrappedScale.GetType())
{
WrappedScale = (Scale)scaleLinkedTo.Clone();
}
if (_linkTickSpacing)
{
if (scaleLinkedTo.TickSpacing.GetType() != _scaleWrapped.TickSpacing.GetType())
{
_scaleWrapped.TickSpacing = (Ticks.TickSpacing)scaleLinkedTo.TickSpacing.Clone();
}
else if (scaleLinkedTo.TickSpacing.UpdateSequenceNumber != _cachedUSNOfScaleLinkedToTickSpacing)
{
_scaleWrapped.TickSpacing.CopyFrom(scaleLinkedTo.TickSpacing);
_cachedUSNOfScaleLinkedToTickSpacing = scaleLinkedTo.TickSpacing.UpdateSequenceNumber;
}
}
AltaxoVariant org = scaleLinkedTo.OrgAsVariant;
AltaxoVariant end = scaleLinkedTo.EndAsVariant;
if (!IsStraightLink)
{
org = org * LinkOrgB + LinkOrgA;
end = end * LinkEndB + LinkEndA;
}
if (_scaleWrapped.RescalingObject is Rescaling.IUnboundNumericScaleRescaleConditions unbound)
unbound.SetUserParameters(Rescaling.BoundaryRescaling.Fixed, Rescaling.BoundariesRelativeTo.Absolute, org, Rescaling.BoundaryRescaling.Fixed, Rescaling.BoundariesRelativeTo.Absolute, end);
}
}
#endregion Changed event handling
}
}