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
|
////////////////////////////////////////////////////////////////////////////////
/*! @file Graphicals.h Графические примитивы.
- Part of RANet - Research Assistant Net Library.
- Copyright(C) 2000-2015, Viktor E. Bursian, St.Petersburg, Russia.
Viktor_dot_Bursian_at_mail_dot_ioffe_dot_ru
*///////////////////////////////////////////////////////////////////////////////
#ifndef Graphicals_H
#define Graphicals_H
#include "Storable.h"
#include "Color.h"
#include "PhysValue.h"
#include "Ranges.h"
namespace RA {
//------------------------------------------------------------------------------
ANNOUNCE_CLASS(sPoint)
ANNOUNCE_CLASS(sLineSegment)
ANNOUNCE_CLASS(sRectangle)
ANNOUNCE_CLASS(sPhysPair)
ANNOUNCE_CLASS(sBoundaries)
ANNOUNCE_CLASS(sIntPoint)
ANNOUNCE_CLASS(sScale)
ANNOUNCE_CLASS(sScales)
ANNOUNCE_CLASS(sAppearance)
ANNOUNCE_CLASS(sLineAppearance)
ANNOUNCE_CLASS(sSpotAppearance)
ANNOUNCE_CLASS(sPointAppearance)
ANNOUNCE_ABSTRACT_CLASS(sGraphObject)
//------------------------------------------------------------------- sPoint ---
class RANet_EXPORT sPoint
{
public:
sPoint ()
:X(0.0),Y(0.0)
{}
sPoint (real x ,real y)
:X(x),Y(y)
{}
sPoint (rcsPoint P)
:X(P.X),Y(P.Y)
{}
rsPoint operator = (rcsPoint P)
{ X=P.X; Y=P.Y; return *this; }
rsPoint operator = (rcsIntPoint P);
// bool operator == (rcsPoint P) const
// { return (X==P.X)&&(Y==P.Y); }
// bool operator < (rcsPoint P) const
// { return (X<P.X)&&(Y<P.Y); }
rsPoint operator += (rcsPoint P)
{ X+=P.X; Y+=P.Y; return *this; }
rsPoint operator -= (rcsPoint P)
{ X-=P.X; Y-=P.Y; return *this; }
sPoint operator + (rcsPoint P) const
{ return sPoint( X+P.X , Y+P.Y ); }
sPoint operator - (rcsPoint P) const
{ return sPoint( X-P.X , Y-P.Y ); }
public: //fields
real X;
real Y;
};
//------------------------------------------------------------- sLineSegment ---
class RANet_EXPORT sLineSegment
{
public: //fields
sPoint Start;
sPoint End;
};
//--------------------------------------------------------------- sRectangle ---
class RANet_EXPORT sRectangle
{
public:
sRectangle ()
{}
sRectangle (sRange x ,sRange y)
:X(x),Y(y)
{}
sRectangle (rcsRectangle B)
:X(B.X),Y(B.Y)
{}
rsRectangle operator = (rcsRectangle B)
{ X=B.X; Y=B.Y; return *this; }
bool operator == (rcsRectangle B) const
{ return (X==B.X) && (Y==B.Y); }
// rsRectangle operator |= (rcsRectangle);
// rsRectangle operator |= (rcsPoint);
public: //fields
sRange X;
sRange Y;
};
//---------------------------------------------------------------- sPhysPair ---
class RANet_EXPORT sPhysPair : public virtual sStorable
{
STORABLE(sPhysPair)
public:
sPhysPair ()
:X(),Y()
{}
sPhysPair (sPhysValue x ,sPhysValue y)
:X(x),Y(y)
{}
sPhysPair (rcsPhysPair P)
:sStorable(),X(P.X),Y(P.Y)
{}
rsPhysPair operator = (rcsPhysPair P)
{ X=P.X; Y=P.Y; return *this; }
rsPhysPair operator += (rcsPhysPair P)
{ X+=P.X; Y+=P.Y; return *this; }
rsPhysPair operator -= (rcsPhysPair P)
{ X-=P.X; Y-=P.Y; return *this; }
sPhysPair operator + (rcsPhysPair P) const
{ return sPhysPair( X+P.X , Y+P.Y ); }
sPhysPair operator - (rcsPhysPair P) const
{ return sPhysPair( X-P.X , Y-P.Y ); }
public: //fields
sPhysValue X;
sPhysValue Y;
};
//-------------------------------------------------------------- sBoundaries ---
class RANet_EXPORT sBoundaries : public virtual sStorable
{
STORABLE(sBoundaries)
public:
sBoundaries ()
{}
sBoundaries (sPhysRange x ,sPhysRange y)
:X(x),Y(y)
{}
sBoundaries (rcsBoundaries B)
:sStorable(),X(B.X),Y(B.Y)
{}
public:
bool UnitsAreFixed () const
{
return X.UnitsAreFixed() && Y.UnitsAreFixed();
}
void FixTheUnits ()
{ X.FixTheUnits(); Y.FixTheUnits(); }
bool IsInf () const
{ return X.IsInf() || Y.IsInf(); }
bool IsNaN () const
{ return X.IsNaN() || Y.IsNaN(); }
public://operators
rsBoundaries operator = (rcsBoundaries B)
{ X=B.X; Y=B.Y; return *this; }
// bool operator == (rcsBoundaries B) const
// { return (X==B.X) && (Y==B.Y); }
rsBoundaries operator |= (rcsBoundaries);
//!< operator 'expand to contain both'
rsBoundaries operator |= (rcsPhysPair);
//!< operator 'expand to contain the point'
public: //fields
sPhysRange X;
sPhysRange Y;
};
//---------------------------------------------------------------- sIntPoint ---
class RANet_EXPORT sIntPoint
{
public:
sIntPoint ()
:X(0.0),Y(0.0)
{}
sIntPoint (int x ,int y)
:X(x),Y(y)
{}
sIntPoint (rcsIntPoint P)
:X(P.X),Y(P.Y)
{}
rsIntPoint operator = (rcsIntPoint P)
{ X=P.X; Y=P.Y; return *this; }
rsIntPoint operator = (rcsPoint P)
{ X=Round(P.X); Y=Round(P.Y); return *this; }
bool operator == (rcsIntPoint P) const
{ return (X==P.X)&&(Y==P.Y); }
// bool operator < (rcsIntPoint P) const
// { return (X<P.X)&&(Y<P.Y); };
rsIntPoint operator += (rcsIntPoint P)
{ X+=P.X; Y+=P.Y; return *this; }
rsIntPoint operator -= (rcsIntPoint P)
{ X-=P.X; Y-=P.Y; return *this; }
sIntPoint operator + (rcsIntPoint P) const
{ return sIntPoint( X+P.X , Y+P.Y ); }
sIntPoint operator - (rcsIntPoint P) const
{ return sIntPoint( X-P.X , Y-P.Y ); }
int ManhattanLength () const
{ return std::abs(X)+std::abs(Y); }
public: //fields
int X;
int Y;
};
//---------------
inline rsPoint sPoint::operator = (rcsIntPoint P)
{
X=P.X; Y=P.Y; return *this;
}
//------------------------------------------------------------------- sScale ---
class RANet_EXPORT sScale
{
public:
virtual ~sScale ()
{}
sScale (bool upside_down);
sScale (rcsPhysValue unit);
sScale (rcsScale scale);
rsScale operator = (rcsScale scale);
sPhysRange PhysRange () const
{
//! @test (real)(sPhysValue)
return sPhysRange(TheRange.From * TheUnit
,TheRange.To * TheUnit );
}
sPhysValue Unit () const
{ return TheUnit; }
sRange Range () const
{ return TheRange; }
virtual void SetRange (sPhysRange);
void SetRange (rcsRange);
void SetRange (int from ,int to);
void ShiftRange (int shift);
real PixelValue () const
{ return (TheRange.To-TheRange.From)/TheSize; }
int Size () const
{ return TheSize; }
virtual void SetSize (int);
int T (real) const;
int T (sPhysValue) const;
sPhysValue T (int) const;
real Tr2real (int) const;
real Tr2real (sPhysValue) const;
protected:
virtual void SetOffset (int offset)
{ Offset = offset; }
private: //fields
sPhysValue TheUnit;
sRange TheRange;
int TheSize;
int Offset; //!< shifts discrete coordinate system
//!< (by halfwidth of the axis line)
bool UpsideDown;
bool NoTr;
};
//------------------------------------------------------------------ sScales ---
class RANet_EXPORT sScales
{
public:
// sScales ()
// :X(),Y()
// {};
sScales (rcsScale x ,rcsScale y)
:X(x),Y(y)
{}
sScales (rcsScales S)
:X(S.X),Y(S.Y)
{}
rsScales operator = (rcsScales S)
{ X=S.X; Y=S.Y; return *this; }
sIntPoint T (rcsPoint P) const
{ return sIntPoint(X.T(P.X),Y.T(P.Y)); }
sIntPoint T (rcsPhysPair P) const
{ return sIntPoint(X.T(P.X),Y.T(P.Y)); }
sPhysPair T (rcsIntPoint P) const
{ return sPhysPair(X.T(P.X),Y.T(P.Y)); }
public: //fields
sScale X;
sScale Y;
};
//-------------------------------------------------------------- sAppearance ---
/*! Базовый класс для атрибутов внешнего вида узлов сети (цвета кривых и т.п.).
*/
class RANet_EXPORT sAppearance : virtual public sStorable
{
STORABLE(sAppearance)
public:
virtual ~sAppearance ();
explicit sAppearance (bool hidden = false);
// virtual psAppearance Replica () const;
// virtual psAppearance AssignFrom (pcsAppearance);
public: //fields
bool Hidden;
};
//---------------------------------------------------------- sLineAppearance ---
class RANet_EXPORT sLineAppearance : virtual public sAppearance
{
STORABLE(sLineAppearance)
public:
enum eLineStyle
{cLineSolid,cLineDotted,cLineDashed};
static const eLineStyle DefaultLineStyle;
static const byte DefaultLineThickness;
static const byte MinLineThickness;
static const byte MaxLineThickness;
public:
virtual ~sLineAppearance ();
sLineAppearance ();
explicit sLineAppearance (rcsColor color);
sLineAppearance (rcsColor color
,byte line_thickness
,eLineStyle line_style
= DefaultLineStyle);
// virtual psAppearance AssignFrom (pcsAppearance);
public: //fields
sColor LineColor;
byte LineThickness;
eLineStyle LineStyle;
};
//---------------------------------------------------------- sSpotAppearance ---
class RANet_EXPORT sSpotAppearance : virtual public sAppearance
{
STORABLE(sSpotAppearance)
public:
static const byte DefaultContourThickness;
static const byte MinContourThickness;
static const byte MaxContourThickness;
public:
sSpotAppearance ();
explicit sSpotAppearance (rcsColor);
// virtual psAppearance AssignFrom (pcsAppearance);
public: //fields
sColor FillColor;
sColor ContourColor;
bool Filled;
bool Contoured;
byte ContourThickness;
};
//--------------------------------------------------------- sPointAppearance ---
class RANet_EXPORT sPointAppearance : public sSpotAppearance
{
STORABLE(sPointAppearance)
public:
enum eShape
{cCircle,cSquare,cDiamond};
static const eShape DefaultShape;
static const byte DefaultSize;
static const byte MinSize;
static const byte MaxSize;
public:
sPointAppearance ();
explicit sPointAppearance (rcsColor);
sPointAppearance (rcsColor color
,byte point_size
,eShape point_shape);
// virtual psAppearance AssignFrom (pcsAppearance);
public: //fields
byte PointSize;
eShape PointShape;
};
//------------------------------------------------------------- sGraphObject ---
class RANet_EXPORT sGraphObject : virtual public sStorable
{
ABSTRACT_STORABLE(sGraphObject)
public:
virtual ~sGraphObject ();
public:
virtual pcsAppearance Appearance () const
{ return TheAppearance; }
virtual void SetAppearance (psAppearance);
virtual sBoundaries Boundaries ();
virtual sBoundaries Boundaries () const;
virtual int Distance (rcsIntPoint position
,rcsScales scales );
virtual sString Hint () =0;
protected:
explicit sGraphObject ()
:sAdam(),sStorable(),TheAppearance(NULL)
{}
protected: //fields
psAppearance TheAppearance;
};
//------------------------------------------------------------------------------
} //namespace RA
#endif
|