UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ZNaturalCoord.H
1 // ZNaturalCoord.H $Revision: 1.13 $ $Date: 2003/12/28 12:53:17 $
2 
3 #if !defined __ZNaturalCoord_H
4 
5 #define __ZNaturalCoord_H
6 
7 
8 #include <mix/SortedAr.H>
9 #include <zm/ZTypes.h>
10 
11 
12 /*************************************************************
13  * Natural hint of group
14  *************************************************************/
15 struct ZNOwnHint
16 {
17  ZGroupId id; /* group id */
18  float b[2]; /* bounds: b[0] <= b[1] */
19  Logic known; /* TRUE - known bounds, FALSE - unknown */
20 };
21 
22 struct ZNGroupHint : public ZNOwnHint
23 {
24  float c[2]; /* coords: c[0], c[1] any order */
25 
26  /* TRUE if group has been resized since last expose; FALSE --
27  coords may be changed without touching size */
28  Logic resized;
29 
30  /* TRUE if group has been moved since last expose; FALSE --
31  coords have the same value that have had after last expose */
32  Logic moved;
33 };
34 
35 
36 /*************************************************************
37  * Array of group hints
38  *************************************************************/
39 class ZNHintAr : public SortedAr
40 {
41 private:
42 
43  /* Returns index of group or -1 if is not found */
44  int group_index (ZGroupId gid) const;
45 
46 public:
47 
48  ZNHintAr (const ZNHintAr& hintar)
49  : SortedAr(hintar) {};
50  ZNHintAr (unsigned quant = DEFAULT_QUANT,
51  unsigned volume = START_VOLUME)
52  : SortedAr(sizeof(ZNGroupHint), quant, volume) {};
53 
54  /* Usual compare between two elements */
55  virtual Compar compare (const char* item1, const char* item2) const;
56 
57  /* Add one more group */
58  void add (const ZNGroupHint& item);
59 
60  /* Remove the group from hint array */
61  void remove_group (ZGroupId gid);
62 
63  /* Get reference at needed group */
64  ZNGroupHint& operator[] (ZGroupId gid) const
65  {return fetch(gid);}
66  ZNGroupHint& fetch (ZGroupId gid) const;
67 
68  /* Returns TRUE if group with gid is already exist */
69  Logic check (ZGroupId gid) const;
70 
71  /* Returns contents of group with index */
72  ZNGroupHint& group_body (unsigned index) const
73  {return *(ZNGroupHint*)item_ptr(index);}
74 
75  /* Print item for debug purpose */
76  virtual void print_item (unsigned i) const;
77 
78 };
79 
80 
81 /* Forward definition */
82 class ZNCoordMaster;
83 
84 
85 /*************************************************************
86  * Slave object with natural coord grid
87  *************************************************************/
89 {
90 private:
91 
92  ZNOwnHint bounds; /* own bounds of object and group id */
93 
94  ZNCoordMaster *master; /* pointer at own master */
95 
96 public:
97 
98  ZNCoordSlave (ZNCoordMaster *pMaster, ZGroupId gid);
99 
101  virtual~ZNCoordSlave ();
102 
103  /* Get group id */
104  ZGroupId group () const;
105 
106  /* Change group at new one */
107  void group (ZGroupId new_gid);
108 
109  /* Erase from group list -- before destructor */
110  void erase ();
111 
112  /* Get natural coords of group */
113  void get_nc (float nc[2]) const;
114  float get_nc1 () const;
115  float get_nc2 () const;
116  float get_nc_min () const;
117  float get_nc_max () const;
118  float get_nsize () const;
119 
120  /* Set natural coords of group */
121  void set_nc (float nc[2]);
122 
123  /* Set or clear knowledge of own bounds */
124  void set_bounds (float b[2]);
125  void clear_bounds ();
126 
127  /* Get own bounds or FALSE if they are unknown */
128  Logic own_bounds (float b[2]);
129 
130  /* Get group bounds or FALSE if they are unknown */
131  Logic group_bounds (float b[2]);
132 
133  /* Get group bounds or natural coords of group if bounds are unknown.
134  It's guaranteed that b[0]<b[1] if nc[0]<nc[1] and vise versa. */
135  void applied_bounds (float b[2]);
136 
137  /* Answers TRUE if group of object has been resized */
138  Logic is_resized () const;
139 
140  /* Answers TRUE if group of object has been moved */
141  Logic is_moved () const;
142 
143 };
144 
145 
146 #define PtrType ZNCoordSlave*
147 #define PtrAr ZNCSAr
148 #include <mix/PtrAr.H> /* ==> class ZNCSAr */
149 
150 
151 /*************************************************************
152  * Kinds of group bounds computation from many different own
153  * bounds:
154  * -- UnifyBounds -- OR-like operation;
155  * -- IntersectBounds -- AND-like operation;
156  *************************************************************/
157 enum ZBoundMode {UnifyBounds, IntersectBounds};
158 
159 
165 {
166 public:
167 
170  ZNCoordMaster (const char* szName = NULL);
171  virtual ~ZNCoordMaster ();
172 
173  /* Get natural coords of group */
174  void get_nc (ZGroupId gid, float nc[2]) const;
175  float get_nc1 (ZGroupId gid) const;
176  float get_nc2 (ZGroupId gid) const;
177  float get_nc_min (ZGroupId gid) const;
178  float get_nc_max (ZGroupId gid) const;
179  float get_nsize (ZGroupId gid) const;
180 
181  /* Set natural coords of group */
182  void set_nc (ZGroupId gid, float nc[2]);
183 
184  /* Add new slave into gid group */
185  void add_slave (ZNCoordSlave* pSlave);
186 
187  /* Add group if no such and do nothing if group exists */
188  void add_group (ZGroupId gid);
189 
190  /* Get count of slaves in group */
191  unsigned slaves_count (ZGroupId gid);
192 
193  /* Erase some slave from groups list */
194  void erase_slave (ZNCoordSlave* pSlave);
195 
196  /* Get group bounds or FALSE if they are unknown */
197  Logic group_bounds (ZGroupId gid, float b[2]);
198 
199  /* Get group bounds or natural coords of group if bounds are unknown.
200  It's guaranteed that b[0]<b[1] if nc[0]<nc[1] and vise versa. */
201  void applied_bounds (ZGroupId gid, float b[2]);
202 
203  /* Answers TRUE if group of object has been resized */
204  Logic is_resized (ZGroupId gid) const;
205 
206  /* Answers TRUE if group of object has been moved */
207  Logic is_moved (ZGroupId gid) const;
208 
209  /* Recompute all group bounds */
210  void rebounds (ZBoundMode mode);
211 
212  /* As if expose has been done */
213  void redrawn ();
214 
215 private:
216 
217  char *name;
218  char *spy_env;
219  Logic spy;
221  ZNHintAr *group;
222  ZNCSAr *slave;
224 };
225 
226 
227 #endif // ZNaturalCoord.H
Definition: ZNaturalCoord.H:39
Definition: SortedAr.H:14
Definition: ZNaturalCoord.H:22
ZNCoordMaster(const char *szName=NULL)
virtual ~ZNCoordSlave()
Definition: ZNaturalCoord.H:88
Definition: ZNaturalCoord.H:164
Definition: ZNaturalCoord.H:15