~vbursian/research-assistant/intervers

« back to all changes in this revision

Viewing changes to RANet/Graphicals.h

  • Committer: Viktor Bursian
  • Date: 2013-06-06 15:10:08 UTC
  • Revision ID: vbursian@gmail.com-20130606151008-6641eh62f0lgx8jt
Tags: version_0.3.0
version 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
/*! @file Graphicals.h   Графические примитивы.
 
3
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
 
4
- Copyright(C) 2000-2010, Viktor E. Bursian, St.Petersburg, Russia.
 
5
                     Viktor.Bursian@mail.ioffe.ru
 
6
*///////////////////////////////////////////////////////////////////////////////
 
7
#ifndef Graphicals_H
 
8
#define Graphicals_H
 
9
#include "Storable.h"
 
10
#include "Color.h"
 
11
#include "PhysValue.h"
 
12
#include "Ranges.h"
 
13
namespace RA {
 
14
//------------------------------------------------------------------------------
 
15
 
 
16
ANNOUNCE_CLASS(sPoint)
 
17
ANNOUNCE_CLASS(sLineSegment)
 
18
ANNOUNCE_CLASS(sRectangle)
 
19
 
 
20
ANNOUNCE_CLASS(sPhysPair)
 
21
ANNOUNCE_CLASS(sBoundaries)
 
22
 
 
23
ANNOUNCE_CLASS(sIntPoint)
 
24
ANNOUNCE_CLASS(sScale)
 
25
ANNOUNCE_CLASS(sScales)
 
26
 
 
27
ANNOUNCE_CLASS(sAppearance)
 
28
ANNOUNCE_CLASS(sPointAppearance)
 
29
ANNOUNCE_CLASS(sLineAppearance)
 
30
 
 
31
ANNOUNCE_ABSTRACT_CLASS(sGraphObject)
 
32
 
 
33
//------------------------------------------------------------------- sPoint ---
 
34
 
 
35
class RANet_EXPORT  sPoint
 
36
{
 
37
  public:
 
38
                              sPoint ()
 
39
                                  :X(0.0),Y(0.0)
 
40
                                {};
 
41
                              sPoint (real  x ,real  y)
 
42
                                  :X(x),Y(y)
 
43
                                {};
 
44
                              sPoint (rcsPoint P)
 
45
                                  :X(P.X),Y(P.Y)
 
46
                                {};
 
47
    rsPoint                   operator = (rcsPoint P)
 
48
                                { X=P.X;  Y=P.Y; return *this; };
 
49
    rsPoint                   operator = (rcsIntPoint P);
 
50
//    bool                      operator == (rcsPoint P) const
 
51
//                                { return (X==P.X)&&(Y==P.Y); };
 
52
//    bool                      operator < (rcsPoint P) const
 
53
//                                { return (X<P.X)&&(Y<P.Y); };
 
54
    rsPoint                   operator += (rcsPoint P)
 
55
                                { X+=P.X;  Y+=P.Y; return *this; };
 
56
    rsPoint                   operator -= (rcsPoint P)
 
57
                                { X-=P.X;  Y-=P.Y; return *this; };
 
58
    sPoint                    operator + (rcsPoint P) const
 
59
                                { return sPoint( X+P.X , Y+P.Y ); };
 
60
    sPoint                    operator - (rcsPoint P) const
 
61
                                { return sPoint( X-P.X , Y-P.Y ); };
 
62
 
 
63
  public: //fields
 
64
    real                      X;
 
65
    real                      Y;
 
66
};
 
67
 
 
68
//------------------------------------------------------------- sLineSegment ---
 
69
 
 
70
class RANet_EXPORT  sLineSegment
 
71
{
 
72
  public: //fields
 
73
    sPoint                    Start;
 
74
    sPoint                    End;
 
75
};
 
76
 
 
77
//--------------------------------------------------------------- sRectangle ---
 
78
 
 
79
class RANet_EXPORT  sRectangle
 
80
{
 
81
  public:
 
82
                              sRectangle ()
 
83
                                {};
 
84
                              sRectangle (sRange x ,sRange y)
 
85
                                  :X(x),Y(y)
 
86
                                {};
 
87
                              sRectangle (rcsRectangle B)
 
88
                                  :X(B.X),Y(B.Y)
 
89
                                {};
 
90
    rsRectangle              operator = (rcsRectangle B)
 
91
                                { X=B.X; Y=B.Y; return *this; };
 
92
    bool                      operator == (rcsRectangle B) const
 
93
                                { return (X==B.X) && (Y==B.Y); };
 
94
//    rsRectangle              operator |= (rcsRectangle);
 
95
//    rsRectangle              operator |= (rcsPoint);
 
96
 
 
97
  public: //fields
 
98
    sRange                    X;
 
99
    sRange                    Y;
 
100
};
 
101
 
 
102
//---------------------------------------------------------------- sPhysPair ---
 
103
 
 
104
class RANet_EXPORT  sPhysPair : public virtual sStorable
 
105
{
 
106
  STORABLE(sPhysPair)
 
107
  public:
 
108
                              sPhysPair ()
 
109
                                  :X(),Y()
 
110
                                {};
 
111
                              sPhysPair (sPhysValue  x ,sPhysValue  y)
 
112
                                  :X(x),Y(y)
 
113
                                {};
 
114
                              sPhysPair (rcsPhysPair  P)
 
115
                                  :sStorable(),X(P.X),Y(P.Y)
 
116
                                {};
 
117
    rsPhysPair                operator = (rcsPhysPair  P)
 
118
                                { X=P.X;  Y=P.Y; return *this; };
 
119
    rsPhysPair                operator += (rcsPhysPair  P)
 
120
                                { X+=P.X;  Y+=P.Y; return *this; };
 
121
    rsPhysPair                operator -= (rcsPhysPair  P)
 
122
                                { X-=P.X;  Y-=P.Y; return *this; };
 
123
    sPhysPair                 operator + (rcsPhysPair  P) const
 
124
                                { return sPhysPair( X+P.X , Y+P.Y ); };
 
125
    sPhysPair                 operator - (rcsPhysPair  P) const
 
126
                                { return sPhysPair( X-P.X , Y-P.Y ); };
 
127
 
 
128
  public: //fields
 
129
    sPhysValue                X;
 
130
    sPhysValue                Y;
 
131
};
 
132
 
 
133
//-------------------------------------------------------------- sBoundaries ---
 
134
 
 
135
class RANet_EXPORT  sBoundaries : public virtual sStorable
 
136
{
 
137
  STORABLE(sBoundaries)
 
138
  public:
 
139
                              sBoundaries ()
 
140
                                {};
 
141
                              sBoundaries (sPhysRange  x ,sPhysRange  y)
 
142
                                  :X(x),Y(y)
 
143
                                {};
 
144
                              sBoundaries (rcsBoundaries B)
 
145
                                  :sStorable(),X(B.X),Y(B.Y)
 
146
                                {};
 
147
    rsBoundaries              operator = (rcsBoundaries B)
 
148
                                { X=B.X; Y=B.Y; return *this; };
 
149
    bool                      operator == (rcsBoundaries B) const
 
150
                                { return (X==B.X) && (Y==B.Y); };
 
151
//    rsBoundaries              operator |= (rcsBoundaries);
 
152
//    rsBoundaries              operator |= (rcsPhysPair);
 
153
 
 
154
  public: //fields
 
155
    sPhysRange                X;
 
156
    sPhysRange                Y;
 
157
};
 
158
 
 
159
//---------------------------------------------------------------- sIntPoint ---
 
160
 
 
161
class RANet_EXPORT  sIntPoint
 
162
{
 
163
  public:
 
164
                              sIntPoint ()
 
165
                                  :X(0.0),Y(0.0)
 
166
                                {};
 
167
                              sIntPoint (int  x ,int  y)
 
168
                                  :X(x),Y(y)
 
169
                                {};
 
170
                              sIntPoint (rcsIntPoint P)
 
171
                                  :X(P.X),Y(P.Y)
 
172
                                {};
 
173
    rsIntPoint                operator = (rcsIntPoint P)
 
174
                                { X=P.X;  Y=P.Y; return *this; };
 
175
    rsIntPoint                operator = (rcsPoint P)
 
176
                                { X=Round(P.X);  Y=Round(P.Y); return *this; };
 
177
    bool                      operator == (rcsIntPoint P) const
 
178
                                { return (X==P.X)&&(Y==P.Y); };
 
179
//    bool                      operator < (rcsIntPoint P) const
 
180
//                                { return (X<P.X)&&(Y<P.Y); };
 
181
    rsIntPoint                operator += (rcsIntPoint P)
 
182
                                { X+=P.X;  Y+=P.Y; return *this; };
 
183
    rsIntPoint                operator -= (rcsIntPoint P)
 
184
                                { X-=P.X;  Y-=P.Y; return *this; };
 
185
    sIntPoint                 operator + (rcsIntPoint P) const
 
186
                                { return sIntPoint( X+P.X , Y+P.Y ); };
 
187
    sIntPoint                 operator - (rcsIntPoint P) const
 
188
                                { return sIntPoint( X-P.X , Y-P.Y ); };
 
189
    int                       ManhattanLength () const
 
190
                                { return abs(X)+abs(Y); };
 
191
 
 
192
  public: //fields
 
193
    int                       X;
 
194
    int                       Y;
 
195
};
 
196
 
 
197
//---------------
 
198
 
 
199
inline  rsPoint   sPoint::operator = (rcsIntPoint P)
 
200
{
 
201
  X=P.X;  Y=P.Y;  return *this;
 
202
};
 
203
 
 
204
 
 
205
//------------------------------------------------------------------- sScale ---
 
206
 
 
207
class RANet_EXPORT  sScale
 
208
{
 
209
  public:
 
210
                              sScale (bool  upside_down);
 
211
                              sScale (rcsPhysValue  unit);
 
212
                              sScale (rcsScale  scale);
 
213
    rsScale                   operator = (rcsScale  scale);
 
214
    sPhysRange                PhysRange () const
 
215
                                {
 
216
                                  return sPhysRange
 
217
                                            (TheRange.From * TheUnit.ArbValue()
 
218
                                            ,TheRange.To * TheUnit.ArbValue()
 
219
                                            ,TheUnit.Units());
 
220
                                };
 
221
    sPhysValue                Unit () const
 
222
                                { return TheUnit; };
 
223
    sRange                    Range () const
 
224
                                { return TheRange; };
 
225
    virtual void              SetRange (sPhysRange);
 
226
    void                      SetRange (rcsRange);
 
227
    void                      SetRange (int  from ,int  to);
 
228
    void                      ShiftRange (int  shift);
 
229
    real                      PixelValue () const
 
230
                                { return (TheRange.To-TheRange.From)/TheSize; };
 
231
    int                       Size () const
 
232
                                { return TheSize; };
 
233
    virtual void              SetSize (int);
 
234
    int                       Tr (real) const;
 
235
    int                       Tr (sPhysValue) const;
 
236
    sPhysValue                Tr (int) const;
 
237
 
 
238
  protected:
 
239
    virtual void              SetOffset (int  offset)
 
240
                                { Offset = offset; };
 
241
  private: //fields
 
242
    sPhysValue                TheUnit;
 
243
    sRange                    TheRange;
 
244
    int                       TheSize;
 
245
    int                       Offset;  //!< shifts discrete coordinate system
 
246
                                       //!< (by halfwidth of the axis line)
 
247
    bool                      UpsideDown;
 
248
    bool                      NoTr;
 
249
};
 
250
 
 
251
//------------------------------------------------------------------ sScales ---
 
252
 
 
253
class RANet_EXPORT  sScales
 
254
{
 
255
  public:
 
256
//                              sScales ()
 
257
//                                  :X(),Y()
 
258
//                                {};
 
259
                              sScales (rcsScale  x ,rcsScale  y)
 
260
                                  :X(x),Y(y)
 
261
                                {};
 
262
                              sScales (rcsScales  S)
 
263
                                  :X(S.X),Y(S.Y)
 
264
                                {};
 
265
    rsScales                  operator = (rcsScales  S)
 
266
                                { X=S.X; Y=S.Y; return *this; };
 
267
    sIntPoint                 Tr (rcsPoint  P) const
 
268
                                { return sIntPoint(X.Tr(P.X),Y.Tr(P.Y)); };
 
269
    sIntPoint                 Tr (rcsPhysPair  P) const
 
270
                                { return sIntPoint(X.Tr(P.X),Y.Tr(P.Y)); };
 
271
    sPhysPair                 Tr (rcsIntPoint  P) const
 
272
                                { return sPhysPair(X.Tr(P.X),Y.Tr(P.Y)); };
 
273
 
 
274
  public: //fields
 
275
    sScale                    X;
 
276
    sScale                    Y;
 
277
};
 
278
 
 
279
//-------------------------------------------------------------- sAppearance ---
 
280
/*! Базовый класс для атрибутов внешнего вида узлов сети (цвета кривых и т.п.).
 
281
 
 
282
 
 
283
*/
 
284
class RANet_EXPORT  sAppearance : virtual public sStorable
 
285
{
 
286
  STORABLE(sAppearance)
 
287
  public:
 
288
                              sAppearance ();
 
289
  public: //fields
 
290
    sColor                    Color;
 
291
    bool                      Hidden;
 
292
};
 
293
 
 
294
//--------------------------------------------------------- sPointAppearance ---
 
295
 
 
296
class RANet_EXPORT  sPointAppearance : public sAppearance
 
297
{
 
298
  STORABLE(sPointAppearance)
 
299
  public:
 
300
    enum                      eStyle
 
301
                                {PointSolidCircle,PointOpenCircle};
 
302
    static const eStyle       DefaultStyle;
 
303
    static const int          DefaultSize;
 
304
  public:
 
305
                              sPointAppearance ();
 
306
  public: //fields
 
307
    int                       Size;
 
308
    eStyle                    Style;
 
309
};
 
310
 
 
311
//---------------------------------------------------------- sLineAppearance ---
 
312
 
 
313
class RANet_EXPORT  sLineAppearance : public sAppearance
 
314
{
 
315
  STORABLE(sLineAppearance)
 
316
  public:
 
317
    enum                      eStyle
 
318
                                {LineSolid,LineDotted,LineDashed};
 
319
    static const eStyle       DefaultStyle;
 
320
    static const int          DefaultThickness;
 
321
  public:
 
322
                              sLineAppearance ();
 
323
  public: //fields
 
324
    int                       Thickness;
 
325
    eStyle                    Style;
 
326
};
 
327
 
 
328
 
 
329
//------------------------------------------------------------- sGraphObject ---
 
330
 
 
331
class RANet_EXPORT  sGraphObject : virtual public sStorable
 
332
{
 
333
  ABSTRACT_STORABLE(sGraphObject)
 
334
  public:
 
335
    virtual sBoundaries       Boundaries ();
 
336
    virtual int               Distance (rcsIntPoint  position
 
337
                                       ,rcsScales    scales  );
 
338
    virtual sString           Hint () const =0;
 
339
    virtual void              SetColor (rcsColor);
 
340
 
 
341
  protected:
 
342
    explicit                  sGraphObject ()
 
343
                                  :sAdam(),sStorable(),Appearance(NULL)
 
344
                                {};
 
345
 
 
346
  public: //fields
 
347
    psAppearance              Appearance;
 
348
};
 
349
 
 
350
//------------------------------------------------------------------------------
 
351
}; //namespace RA
 
352
#endif
 
353