UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
zqb_natgroup.hpp
1 /* zqb_natgroup.hpp */
2 /* $Id: zqb_natgroup.hpp,v 1.12 2007/01/16 09:53:05 guser1 Exp $ */
3 #ifndef __zqb_natgroup_hpp
4 #define __zqb_natgroup_hpp
5 
6 #include <vector>
7 
8 #include "zqb_macros.h"
9 #include "zqb_autoname.hpp"
10 #include "zqb_pixgroup.hpp"
11 #include "zqb_natgrpmember.hpp"
12 
13 
35 class ZqbNatGroup : virtual public ZqbAutoName
36 {
37  friend class ZqbNatGrpMember;
38 
39 public:
40 
43  ZqbNatGroup (const char* szName = NULL);
44 
45 
46  /*
47  * Group service
48  */
49 
53  virtual void getCoords (double c[2]) const;
54 
63  virtual bool setCoords (double c[2], bool bForce = false);
64 
67  bool setCoordsSameOrder (double c[2],
68  bool bForce = false) {
69  double prev_c[2], new_c[2];
70  getCoords(prev_c);
71 
72  if(prev_c[0] < prev_c[1])
73  {
74  new_c[0] = ZqbMIN(c[0], c[1]);
75  new_c[1] = ZqbMAX(c[0], c[1]);
76  }
77  else /* prev_c[0] >= prev_c[1] */
78  {
79  new_c[0] = ZqbMAX(c[0], c[1]);
80  new_c[1] = ZqbMIN(c[0], c[1]);
81  }
82  return setCoords(new_c, bForce);
83  }
84 
94  bool setCoords (double c1, double c2,
95  bool bForce = false) {
96  double c[2];
97  c[0] = c1;
98  c[1] = c2;
99  return setCoords(c, bForce);
100  }
101 
104  bool setCoordsSameOrder (double c1, double c2,
105  bool bForce = false) {
106  double c[2];
107  c[0] = c1;
108  c[1] = c2;
109  return setCoordsSameOrder(c, bForce);
110  }
111 
113  bool isVisible (double c) const {
114  double range[2];
115  getCoords(range);
116  if(range[0] < range[1])
117  return range[0] <= c && c <= range[1];
118  /* else
119  range[0] >= range[1] */
120  return range[0] >= c && c >= range[1];
121  }
122 
123 
127  virtual void zoomAll ();
128 
129 
142  virtual void unifyBounds ();
143 
145  virtual void unsetBounds ();
146 
148  virtual void setBounds (double b[2]);
149 
151  void setBounds (double b1, double b2) {
152  double b[2];
153  b[0] = b1;
154  b[1] = b2;
155  setBounds(b);
156  }
157 
162  virtual bool getBounds (double b[2] = NULL) const;
163 
164 
165  /*
166  * Ticks service for scales and grids.
167  */
168 
170  virtual void setAutoTickMode (bool bAuto);
171 
173  virtual bool getAutoTickMode () const;
174 
175 
178  virtual void setMainTickStep (double fStep);
179 
181  virtual double getMainTickStep () const;
182 
186  virtual int getMainTickPrec () const;
187 
188 
190  virtual void setSubTickFreq (int nTicks);
191 
193  virtual int getSubTickFreq () const;
194 
195 
197  struct Tick {
198  double m_fCoord;
199  bool m_bMain;
201  Tick () : m_fCoord(0.0), m_bMain(false) {}
202  bool operator< (const Tick& t) const {
203  return m_fCoord < t.m_fCoord;
204  }
205  bool operator== (const Tick& t) const {
206  return m_fCoord == t.m_fCoord;
207  }
208  bool operator!= (const Tick& t) const {
209  return !operator==(t);
210  }
211  };
212 
214  typedef std::vector<Tick> Ticks;
215 
218  virtual void calcTicks (Ticks& ticks) const;
219 
222  virtual double calcMainTickStep (int* pMainTicksPrec = NULL) const;
223 
224 
225  /*
226  * Pixel vs. natural coordinate translation service.
227  */
228 
233  virtual bool n2p (ZqbPixGroup& pg, double nc, int& pc);
234 
239  virtual bool p2n (ZqbPixGroup& pg, int pc, double& nc);
240 
241 
242  /*
243  * Membership service
244  */
245 
247  virtual bool isEmpty ();
248 
249 protected:/* methods for ZqbNatGrpMember */
250 
253  virtual bool addMember (ZqbNatGrpMember* pMember);
254 
258  virtual bool removeMember (ZqbNatGrpMember* pMember);
259 
260 
261 protected:/* data */
262 
264  ZqbNatGrpMembers m_Members;
265 
269 
271  double m_fBounds[2];
272 
274  double m_fCoords[2];
275 
278 
282 
286 
291 
292 private:
293 
295  static int m_iNameCounter;
296 
297 };
298 
299 
300 #endif /* zqb_natgroup.hpp */
double m_fCoord
Definition: zqb_natgroup.hpp:198
virtual void getCoords(double c[2]) const
virtual double calcMainTickStep(int *pMainTicksPrec=NULL) const
virtual double getMainTickStep() const
virtual bool n2p(ZqbPixGroup &pg, double nc, int &pc)
virtual bool removeMember(ZqbNatGrpMember *pMember)
bool setCoordsSameOrder(double c[2], bool bForce=false)
Definition: zqb_natgroup.hpp:67
Definition: zqb_natgroup.hpp:35
bool m_bAutoCalcFreq
Definition: zqb_natgroup.hpp:277
virtual void unsetBounds()
double m_fMainTicksStep
Definition: zqb_natgroup.hpp:281
virtual void setAutoTickMode(bool bAuto)
virtual bool addMember(ZqbNatGrpMember *pMember)
virtual bool setCoords(double c[2], bool bForce=false)
double m_fBounds[2]
Definition: zqb_natgroup.hpp:271
virtual int getSubTickFreq() const
virtual void setMainTickStep(double fStep)
bool isVisible(double c) const
Definition: zqb_natgroup.hpp:113
virtual bool p2n(ZqbPixGroup &pg, int pc, double &nc)
Definition: zqb_autoname.hpp:18
virtual bool getBounds(double b[2]=NULL) const
bool m_bMain
Definition: zqb_natgroup.hpp:199
bool m_bKnownBounds
Definition: zqb_natgroup.hpp:268
virtual bool isEmpty()
std::vector< Tick > Ticks
Definition: zqb_natgroup.hpp:214
void setBounds(double b1, double b2)
Definition: zqb_natgroup.hpp:151
virtual void calcTicks(Ticks &ticks) const
bool setCoords(double c1, double c2, bool bForce=false)
Definition: zqb_natgroup.hpp:94
bool setCoordsSameOrder(double c1, double c2, bool bForce=false)
Definition: zqb_natgroup.hpp:104
virtual int getMainTickPrec() const
virtual void setSubTickFreq(int nTicks)
Definition: zqb_natgroup.hpp:197
int m_nMainTicksPrec
Definition: zqb_natgroup.hpp:285
Definition: zqb_natgrpmember.hpp:26
ZqbNatGrpMembers m_Members
Definition: zqb_natgroup.hpp:264
virtual void unifyBounds()
ZqbNatGroup(const char *szName=NULL)
double m_fCoords[2]
Definition: zqb_natgroup.hpp:274
int m_nSubTicks
Definition: zqb_natgroup.hpp:290
virtual void zoomAll()
virtual bool getAutoTickMode() const
Definition: zqb_pixgroup.hpp:34
virtual void setBounds(double b[2])