1 | // Module PI : Peida Interactive PIBaseWdg |
---|
2 | // Classe de base pour nouvelles composantes graphiques 96 |
---|
3 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA |
---|
4 | |
---|
5 | #include <stdio.h> |
---|
6 | |
---|
7 | #include "sopnamsp.h" |
---|
8 | #include "pibwdggen.h" |
---|
9 | #include "pidrawer.h" |
---|
10 | #include "pigraphps.h" |
---|
11 | #include "pidrwtools.h" |
---|
12 | |
---|
13 | static inline void dbl_swap(double& a, double& b) { double tmp = a; a = b; b = tmp; } |
---|
14 | |
---|
15 | //++ |
---|
16 | // Class PIBaseWdg |
---|
17 | // Lib PI |
---|
18 | // include pibwdggen.h |
---|
19 | // |
---|
20 | // Classe de base pour la création de nouvelles composantes graphiques. |
---|
21 | // Le traitement des événements liés à l'écran, clavier, souris se fait |
---|
22 | // à travers des méthodes de cette classe : "Resize()", "But1Press()", ... |
---|
23 | // La classe "PIBaseWdg" supporte en outre un mécanisme permettant |
---|
24 | // d'associer un ou plusieurs objets traceur (*Drawer*) capables |
---|
25 | // de se dessiner dans la fenêtre associée à l'objet. |
---|
26 | // La classe "PIBaseWdgGen" définit l'interface et ne peut pas être instanciée |
---|
27 | // directement (Méthodes virtuelles pures). Les objets instanciés sont de la |
---|
28 | // classe "PIBaseWdg" et le fichier entête correspondant est "PIBWDG_H" |
---|
29 | // défini dans "pisysdep.h". |
---|
30 | //-- |
---|
31 | //++ |
---|
32 | // Links Parents |
---|
33 | // PIWdg |
---|
34 | //-- |
---|
35 | //++ |
---|
36 | // Links Voir aussi |
---|
37 | // PIGraphic |
---|
38 | // PIDrawer |
---|
39 | //-- |
---|
40 | |
---|
41 | // ---------- Les methodes de la classe PIBWdgGen ------------ |
---|
42 | |
---|
43 | //++ |
---|
44 | // Titre Constructeur |
---|
45 | //-- |
---|
46 | //++ |
---|
47 | // PIBaseWdgGen(PIContainerGen *par, const char *nom, int sx=10, int sy=10, int px=0, int py=0) |
---|
48 | // Création d'un objet contenu dans l'objet *PIContainer* "par", de |
---|
49 | // taille "sx,sy", se trouvant à la position "px,py" avec le nom "nom" |
---|
50 | //-- |
---|
51 | |
---|
52 | //++ |
---|
53 | // Titre Méthodes |
---|
54 | //-- |
---|
55 | //++ |
---|
56 | // void SelPointerShape(PIPointer ptr=PI_ArrowPointer) |
---|
57 | // Choix de la forme du pointeur (souris) pour la fenêtre |
---|
58 | // associée à l'objet. |
---|
59 | //| PI_ArrowPointer, PI_CrossPointer, PI_HandPointer, PI_TDLRArrowPointer |
---|
60 | // PIPointer GetPointerShape() |
---|
61 | // Renvoie la forme du pointeur |
---|
62 | //-- |
---|
63 | |
---|
64 | //++ |
---|
65 | // Titre Activation du traitement des événements |
---|
66 | //-- |
---|
67 | //++ |
---|
68 | // void ActivatePtrCross() |
---|
69 | // Active l'appel aux méthodes "Enter()" et "Leave()" lorsque la souris |
---|
70 | // rentre ou sort de la fenêtre correspondante à l'objet |
---|
71 | // void ActivateButton(int b) |
---|
72 | // Active l'appel aux méthodes "ButbPress()" et "ButxRelease()" pour |
---|
73 | // le bouton "b" de la souris ("b=1,2,3") |
---|
74 | // void ActivateMove(int b) |
---|
75 | // Active l'appel aux méthodes "PtrbMove()" lors des mouvements de |
---|
76 | // la souris avec le bouton "b" enfoncé ("b=1,2,3") |
---|
77 | // L'appel avec "bid=0" active l'appel à la méthode "PtrMove()" |
---|
78 | // Lors des mouvements de souris sans bouton enfoncé. |
---|
79 | // void ActivateKeyboard() |
---|
80 | // Active l'appel à la méthode "Keyboard()" lors de l'appui sur les |
---|
81 | // touches du clavier. |
---|
82 | //-- |
---|
83 | |
---|
84 | |
---|
85 | /* --Methode-- */ |
---|
86 | PIBaseWdgGen::PIBaseWdgGen(PIContainerGen *par, const char *nom, |
---|
87 | int sx, int sy, int px, int py) : |
---|
88 | PIWdg(par, nom, sx, sy, px, py) |
---|
89 | { |
---|
90 | mDrwId=0; // Compteur des numeros sequentiel des PIDrawer |
---|
91 | mActDrwId = -1; // Identificateur du drawer actif |
---|
92 | mAdfg=false; // Pour controle d'appel de RemoveDrawer() |
---|
93 | mWGrC = NULL; // PIGraphic (Contexte graphique) associe a la fenetre} |
---|
94 | // Doit etre cree par PIBaseWdgX/Mac/... |
---|
95 | SetDefaultDrawRectangle(0., 0., 1., 1., true); |
---|
96 | SetDefaultDrawerLimits(0., 1., 0., 1., kAxeDirLtoR, kAxeDirUpDown); |
---|
97 | SetDefaultDrawerLogScale(false, false); |
---|
98 | } |
---|
99 | |
---|
100 | /* --Methode-- */ |
---|
101 | PIBaseWdgGen::~PIBaseWdgGen() |
---|
102 | { |
---|
103 | delete mWGrC; |
---|
104 | if (PIDrwTools::GetCurrentBaseWdg() == this) |
---|
105 | PIDrwTools::SetCurrentBaseWdg(NULL); |
---|
106 | DeleteDrawers(); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | /* --Methode-- |
---|
111 | void PIBaseWdgGen::Refresh() |
---|
112 | { |
---|
113 | if ( IsVisible() ) { |
---|
114 | Draw(mWGrC, 0, 0, XSize(), YSize()); |
---|
115 | CallDrawers(mWGrC); |
---|
116 | } |
---|
117 | return; |
---|
118 | } |
---|
119 | */ |
---|
120 | |
---|
121 | //++ |
---|
122 | // Titre Gestion des événements |
---|
123 | //-- |
---|
124 | //++ |
---|
125 | // void Draw(PIGraphic* g, int x0, int y0, int dx, int dy) |
---|
126 | // Méthode appelée lorsqu'il faut redessiner tout ou partie de |
---|
127 | // la fenêtre. La zone a rafraîchir est determinée par |
---|
128 | // "(x0,y0)", "dx,dy" et "g" est l'objet "PIGraphic" |
---|
129 | // qui doit être utilisé. |
---|
130 | // Cette méthode ne doit pas être appelé directement. |
---|
131 | // Pour rafraîchir le contenu de la fenêtre, il faut appeler |
---|
132 | // la méthode "Refresh()" |
---|
133 | // void Resize() |
---|
134 | // Méthode appelée lorsque la taille de l'objet est modifiée. |
---|
135 | // "XSize()", "YSize()" fournissent la nouvelle taille de l'objet. |
---|
136 | // void Enter() |
---|
137 | // Méthode appelée lorsque le pointeur rentre dans la fenêtre |
---|
138 | // (Si "ActivatePtrCross()" a été appelé ) |
---|
139 | // void Leave() |
---|
140 | // Méthode appelée lorsque le pointeur quitte la fenêtre |
---|
141 | // (Si "ActivatePtrCross()" a été appelé ) |
---|
142 | // void ButbPress(int x, int y) (b=1,2,3) |
---|
143 | // Méthode appelée lorsque le bouton "b=1,2,3" de la souris est enfoncé. |
---|
144 | // "x,y" : Position de la souris |
---|
145 | // (Si "ActivateButton(b)" a été appelé ) |
---|
146 | // void ButbRelease(int x, int y) (b=1,2,3) |
---|
147 | // Méthode appelée lorsque le bouton "b=1,2,3" de la souris est relaché. |
---|
148 | // "x,y" : Position de la souris |
---|
149 | // (Si "ActivateButton(b)" a été appelé ) |
---|
150 | // void PtrMove(int x, int y) |
---|
151 | // Méthode appelée lors des mouvements de la souris. "x,y" : Position de la souris |
---|
152 | // (Si "ActivateMove(0)" a été appelé ) |
---|
153 | // void PtrbMove(int x, int y) (b=1,2,3) |
---|
154 | // Méthode appelée lors des mouvements de la souris, avec le |
---|
155 | // bouton "b=1,2,3" appuyé. "x,y" : Position de la souris |
---|
156 | // (Si "ActivateMove(b)" a été appelé ) |
---|
157 | // void Keyboard(int key, PIKeyModifier kmod) |
---|
158 | // Méthode appelée en réponse à des actions sur le clavier. |
---|
159 | // "key" est le code ASCII de la touche enfoncé - "kmod" indique |
---|
160 | // si des touches speciaux étaient enfoncés en même temps. |
---|
161 | //| kmod = PIKM_Blank | PIKM_Shift | PIKM_Alt | PIKM_Cntl |
---|
162 | // Des constantes ont été définis pour certaines touches particulières |
---|
163 | //| PIK_Return , PIK_Enter , PIK_BackSpace, PIK_Delete |
---|
164 | //| PIK_Tab , PIK_Escape , PIK_Up , PIK_Down, |
---|
165 | //| PIK_Right , PIK_Left , PIK_Previous , PIK_Next |
---|
166 | //-- |
---|
167 | |
---|
168 | /* --Methode-- */ |
---|
169 | void PIBaseWdgGen::Draw(PIGraphic* g, int x0, int y0, int dx, int dy) |
---|
170 | { |
---|
171 | #ifdef DEBUG_RZXB |
---|
172 | puts("Debug_PIBaseWdgGen::Draw() Efface la fenetre par defaut ! "); |
---|
173 | #endif |
---|
174 | if (g->kind() != PI_PSFileGraphics) EraseWindow(x0, y0, dx, dy); |
---|
175 | return; |
---|
176 | } |
---|
177 | |
---|
178 | /* --Methode-- */ |
---|
179 | void PIBaseWdgGen::Resize() |
---|
180 | { |
---|
181 | #ifdef DEBUG_RZXB |
---|
182 | puts("Debug_PIBaseWdgGen::Resize() resize notify "); |
---|
183 | #endif |
---|
184 | return; |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | /* --Methode-- */ |
---|
189 | void PIBaseWdgGen::Enter() |
---|
190 | { |
---|
191 | #ifdef DEBUG_RZXB |
---|
192 | puts("Debug_PIBaseWdgGen::Enter() enter notify "); |
---|
193 | #endif |
---|
194 | return; |
---|
195 | } |
---|
196 | |
---|
197 | /* --Methode-- */ |
---|
198 | void PIBaseWdgGen::Leave() |
---|
199 | { |
---|
200 | #ifdef DEBUG_RZXB |
---|
201 | puts("Debug_PIBaseWdgGen::Leave() leave notify "); |
---|
202 | #endif |
---|
203 | return; |
---|
204 | } |
---|
205 | |
---|
206 | |
---|
207 | /* --Methode-- */ |
---|
208 | void PIBaseWdgGen::But1Press(int /*x*/, int /*y*/) |
---|
209 | { |
---|
210 | Send(Msg(), PIMsg_Active); |
---|
211 | #ifdef DEBUG_RZXB |
---|
212 | printf ("PIBaseWdgGen::But1Press PosX,Y= %d %d \n", x, y); |
---|
213 | #endif |
---|
214 | return; |
---|
215 | } |
---|
216 | |
---|
217 | /* --Methode-- */ |
---|
218 | void PIBaseWdgGen::But1Release(int /*x*/, int /*y*/) |
---|
219 | { |
---|
220 | #ifdef DEBUG_RZXB |
---|
221 | printf ("PIBaseWdgGen::ButReleasePosX,Y= %d %d \n", x, y); |
---|
222 | #endif |
---|
223 | return; |
---|
224 | } |
---|
225 | |
---|
226 | /* --Methode-- */ |
---|
227 | void PIBaseWdgGen::But2Press(int /*x*/, int /*y*/) |
---|
228 | { |
---|
229 | return; |
---|
230 | } |
---|
231 | |
---|
232 | /* --Methode-- */ |
---|
233 | void PIBaseWdgGen::But2Release(int /*x*/, int /*y*/) |
---|
234 | { |
---|
235 | return; |
---|
236 | } |
---|
237 | |
---|
238 | /* --Methode-- */ |
---|
239 | void PIBaseWdgGen::But3Press(int /*x*/, int /*y*/) |
---|
240 | { |
---|
241 | return; |
---|
242 | } |
---|
243 | |
---|
244 | /* --Methode-- */ |
---|
245 | void PIBaseWdgGen::But3Release(int /*x*/, int /*y*/) |
---|
246 | { |
---|
247 | return; |
---|
248 | } |
---|
249 | |
---|
250 | /* --Methode-- */ |
---|
251 | void PIBaseWdgGen::PtrMove(int /*x*/, int /*y*/) |
---|
252 | { |
---|
253 | #ifdef DEBUG_RZXB |
---|
254 | printf ("Debug_PIBaseWdgGen::PtrMove PosX,Y= %d %d \n", x, y); |
---|
255 | #endif |
---|
256 | return; |
---|
257 | } |
---|
258 | |
---|
259 | /* --Methode-- */ |
---|
260 | void PIBaseWdgGen::Ptr1Move(int /*x*/, int /*y*/) |
---|
261 | { |
---|
262 | #ifdef DEBUG_RZXB |
---|
263 | printf ("Debug_PIBaseWdgGen::Ptr1Move PosX,Y= %d %d \n", x, y); |
---|
264 | #endif |
---|
265 | return; |
---|
266 | } |
---|
267 | |
---|
268 | /* --Methode-- */ |
---|
269 | void PIBaseWdgGen::Ptr2Move(int /*x*/, int /*y*/) |
---|
270 | { |
---|
271 | return; |
---|
272 | } |
---|
273 | |
---|
274 | |
---|
275 | /* --Methode-- */ |
---|
276 | void PIBaseWdgGen::Ptr3Move(int /*x*/, int /*y*/) |
---|
277 | { |
---|
278 | return; |
---|
279 | } |
---|
280 | |
---|
281 | /* --Methode-- */ |
---|
282 | void PIBaseWdgGen::Keyboard(int /*key*/, PIKeyModifier /*kmod*/) |
---|
283 | { |
---|
284 | #ifdef DEBUG_RZXB |
---|
285 | printf("PIBaseWdgGen::Keyboard: Key= %d (%c) Mod= %d \n", key, (char)key, (int)kmod); |
---|
286 | #endif |
---|
287 | return; |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | /* --Methode-- */ |
---|
292 | void PIBaseWdgGen::PSPrint(PSFile * psf, int ofx, int ofy, double scale_x, double scale_y) |
---|
293 | { |
---|
294 | if (!psf) return; |
---|
295 | PIGraphicPS grpsf(psf, (PIWdg *)this, ofx, ofy, scale_x, scale_y); |
---|
296 | Draw(&grpsf, 0, 0, XSize(), YSize()); |
---|
297 | CallDrawers(&grpsf); |
---|
298 | return; |
---|
299 | } |
---|
300 | |
---|
301 | //++ |
---|
302 | // Titre Gestion des traceurs (PIDrawer) |
---|
303 | // Un même "PIDrawer" peut être attaché simultanement à plusieurs "PIBaseWdg", ainsi |
---|
304 | // que plusieurs fois au même "PIBaseWdg", avec des identificateurs différents. |
---|
305 | // Un des traceurs, par défaur le dernier ajouté est considéré comme le traceur |
---|
306 | // actif ou sélectionné (voir "SetActiveDrawer" ...). |
---|
307 | //-- |
---|
308 | //++ |
---|
309 | // void SetDefaultDrawRectangle(PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2, bool elastic=true) |
---|
310 | // Définition du rectangle d'attachement par défaut. "(x1,y1)" et "(x2,y2)" determinent |
---|
311 | // les positions des deux coins opposés. |
---|
312 | // si "elastic=true", les coordonnées sont supposées être des facteurs multiplicatifs |
---|
313 | // des dimensions de l'objet. |
---|
314 | // void GetDefaultDrawRectangle(PIGrCoord& x1, PIGrCoord& y1, PIGrCoord& x2, PIGrCoord& y2, bool& elastic) |
---|
315 | // Retourne le rectangle d'attachement par défaut. "(x1,y1)" et "(x2,y2)" determinent |
---|
316 | // les positions des deux coins opposés."elastic=true": Pos/Taille spécifiées en fraction |
---|
317 | // de la taille du PIBaseWdg. |
---|
318 | // void SetDefaultDrawerLimits(double xmin, double xmax, double ymin, double ymax, - |
---|
319 | // int axrl=kAxeDirSame, int ayud=kAxeDirSame) |
---|
320 | // Définition du système de coordonnées par défaut d'un drawer attaché |
---|
321 | // en "autolim=true" |
---|
322 | // void SetDefaultDrawerLogScale(bool logx, bool logy) |
---|
323 | // Définition d'échelle logarithmique pour le système de coordonnées par défaut |
---|
324 | // d'un drawer attaché en "autolim=true". |
---|
325 | // |
---|
326 | //-- |
---|
327 | |
---|
328 | /* --Methode-- */ |
---|
329 | void PIBaseWdgGen::SetDefaultDrawRectangle(PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2, bool elastic) |
---|
330 | { |
---|
331 | mDrX1 = x1; mDrY1 = y1; |
---|
332 | mDrX2 = x2; mDrY2 = y2; mDrElastic = elastic; |
---|
333 | } |
---|
334 | |
---|
335 | /* --Methode-- */ |
---|
336 | void PIBaseWdgGen::GetDefaultDrawRectangle(PIGrCoord& x1, PIGrCoord& y1, PIGrCoord& x2, PIGrCoord& y2, bool& elastic) |
---|
337 | { |
---|
338 | x1 = mDrX1; y1 = mDrY1; |
---|
339 | x2 = mDrX2; y2 = mDrY2; elastic = mDrElastic; |
---|
340 | } |
---|
341 | |
---|
342 | /* --Methode-- */ |
---|
343 | void PIBaseWdgGen::SetDefaultDrawerLimits(double xmin, double xmax, double ymin, double ymax, |
---|
344 | int axrl, int ayud) |
---|
345 | { |
---|
346 | mDrXmin = xmin; mDrXmax = xmax; |
---|
347 | mDrYmin = ymin; mDrYmax = ymax; |
---|
348 | if (axrl != kAxeDirSame) mDXdir = axrl; |
---|
349 | if (ayud != kAxeDirSame) mDYdir = ayud; |
---|
350 | } |
---|
351 | |
---|
352 | /* --Methode-- */ |
---|
353 | void PIBaseWdgGen::SetDefaultDrawerLogScale(bool logx, bool logy) |
---|
354 | { |
---|
355 | mDXlog = logx; |
---|
356 | mDYlog = logy; |
---|
357 | } |
---|
358 | |
---|
359 | //++ |
---|
360 | // int AddDrawer(PIDrawer* drw, PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2, - |
---|
361 | // bool psz=true, bool clip=true, bool ad=false, bool lock=false) |
---|
362 | // Attachement d'un "PIDrawer" au rectangle défini les coordonnées des deux coins opposés. |
---|
363 | // si "psz=true", les coordonnées sont supposées être des facteurs multiplicatifs |
---|
364 | // des dimensions de l'objet. |
---|
365 | // si "clip=true", "PIDrawer* drw" ne peut dessiner en dehors de son rectangle |
---|
366 | // d'attachement. |
---|
367 | // si "ad=true", le "PIDrawer* drw" est détruit lors de la destruction de l'objet PIBaseWdg. |
---|
368 | // si "lock=true", le drawer ne peut être détaché suite à une requête interactive. |
---|
369 | // La méthode retourne l'identificateur du drawer attaché. |
---|
370 | // int AddDrawer(PIDrawer* drw, bool autolim=false, bool clip=true, bool ad=false, bool lock=false) |
---|
371 | // Ajout d'un "PIDrawer" au rectangle d'attachement par défaut. |
---|
372 | // Si "autolim=true", l'objet "PIBaseWdg" impose l'espace de coordonnées utilisateur |
---|
373 | // à l'aide des valeurs définies par "SetDefaultDrawerLimits()". |
---|
374 | // Si ""clip=true", "PIDrawer* drw" ne peut dessiner en dehors de son rectangle |
---|
375 | // d'attachement. |
---|
376 | // si "ad=true", le "PIDrawer* drw" est détruit lors de la destruction de l'objet PIBaseWdg. |
---|
377 | // si "lock=true", le drawer ne peut être détaché suite à une requête interactive. |
---|
378 | // La méthode retourne l'identificateur du drawer attaché. |
---|
379 | //-- |
---|
380 | |
---|
381 | /* --Methode-- */ |
---|
382 | int PIBaseWdgGen::AddDrawer(PIDrawer* drw, PIGrCoord x1, PIGrCoord y1, |
---|
383 | PIGrCoord x2, PIGrCoord y2, bool psz, bool clip, bool ad, bool lock) |
---|
384 | { |
---|
385 | if (drw == NULL) return(0); |
---|
386 | mDrwId++; |
---|
387 | BWDrwId did; |
---|
388 | did.x1 = x1; did.y1 = y1; |
---|
389 | did.x2 = x2; did.y2 = y2; |
---|
390 | did.autoszp = did.autolim = false; |
---|
391 | did.elastic = psz; did.clip = clip; |
---|
392 | did.id = mDrwId; did.ad = ad; |
---|
393 | did.lock = lock; |
---|
394 | did.drw = drw; |
---|
395 | mDrwList.push_back(did); |
---|
396 | drw->Attach(this, mDrwId); |
---|
397 | mActDrwId = mDrwId; // Le dernier drawer ajoute devient le drawer actif par defaut |
---|
398 | return(mDrwId); |
---|
399 | } |
---|
400 | |
---|
401 | /* --Methode-- */ |
---|
402 | int PIBaseWdgGen::AddDrawer(PIDrawer* drw, bool autolim, bool clip, bool ad, bool lock) |
---|
403 | { |
---|
404 | if (drw == NULL) return(0); |
---|
405 | mDrwId++; |
---|
406 | BWDrwId did; |
---|
407 | did.x1 = 0.; did.y1 = 0.; |
---|
408 | did.x2 = 1.; did.y2 = 1.; |
---|
409 | did.autoszp = true; did.autolim = autolim; |
---|
410 | did.elastic = false; did.clip = clip; |
---|
411 | did.id = mDrwId; did.ad = ad; |
---|
412 | did.lock = lock; |
---|
413 | did.drw = drw; |
---|
414 | mDrwList.push_back(did); |
---|
415 | drw->Attach(this, mDrwId); |
---|
416 | mActDrwId = mDrwId; // Le dernier drawer ajoute devient le drawer actif par defaut |
---|
417 | return(mDrwId); |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | //++ |
---|
422 | // void MoveResizeDrawer(int id, PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2, bool elastic=true) |
---|
423 | // Modification du rectangle d'attachement du PIDrawer avec l'identificateur "id" , retourné |
---|
424 | // par "AddDrawer()". Si "elatic=true", taille/pos spécifiée en fraction de la taille du PIBaseWdg. |
---|
425 | // void RemoveDrawer(int id) |
---|
426 | // Ote le drawer "id" de la liste des drawers du PIBaseWdg. |
---|
427 | // void DeleteDrawers() |
---|
428 | // Ote tous les drawers de la liste. Détruit ceux ajoutés avec l'option "ad=true" |
---|
429 | //-- |
---|
430 | |
---|
431 | /* --Methode-- */ |
---|
432 | void PIBaseWdgGen::MoveResizeDrawer(int id, PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2, bool elastic) |
---|
433 | { |
---|
434 | vector<BWDrwId>::iterator it; |
---|
435 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
436 | if ((*it).id == id) { |
---|
437 | (*it).x1 = x1; (*it).y1 = y1; |
---|
438 | (*it).x2 = x2; (*it).y2 = y2; |
---|
439 | (*it).elastic = elastic; |
---|
440 | break; |
---|
441 | } |
---|
442 | return; |
---|
443 | } |
---|
444 | |
---|
445 | /* --Methode-- */ |
---|
446 | void PIBaseWdgGen::RemoveDrawer(int id) |
---|
447 | { |
---|
448 | if (mAdfg) return; |
---|
449 | vector<BWDrwId>::iterator it; |
---|
450 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
451 | if ((*it).id == id) { |
---|
452 | (*it).drw->Detach(this, id); mDrwList.erase(it); |
---|
453 | if (id == mActDrwId) { |
---|
454 | if (NbDrawers() > 0) mActDrwId = (*(mDrwList.end()-1)).id; |
---|
455 | else mActDrwId = -1; |
---|
456 | } |
---|
457 | |
---|
458 | break; |
---|
459 | } |
---|
460 | return; |
---|
461 | } |
---|
462 | |
---|
463 | /* --Methode-- */ |
---|
464 | void PIBaseWdgGen::DeleteDrawers() |
---|
465 | { |
---|
466 | mAdfg = true; |
---|
467 | mActDrwId = -1; |
---|
468 | vector<BWDrwId>::iterator it; |
---|
469 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
470 | if ((*it).ad) delete (*it).drw; |
---|
471 | mDrwList.erase(mDrwList.begin(), mDrwList.end() ); |
---|
472 | mAdfg = false; |
---|
473 | return; |
---|
474 | } |
---|
475 | |
---|
476 | //++ |
---|
477 | // int NbDrawers() |
---|
478 | // Retourne le nombre de PIDrawer attachés |
---|
479 | // PIDrawer* GetDrawerId(int id) |
---|
480 | // Retourne le PIDrawer avec l'identificateur "id". |
---|
481 | // PIDrawer* GetDrawer(int n) |
---|
482 | // Retourne le PIDrawer "n=0..NbDrawers()-1" de la liste |
---|
483 | // int GetDrawerIdFromNum(int n) |
---|
484 | // Retourne l'identificateur du drawer numero "n=0..NbDrawers()-1". |
---|
485 | // bool IsDrawerLockedId(int id) |
---|
486 | // Retourne le flag "lock" pour le PIDrawer avec l'identificateur "id". |
---|
487 | // si "true", le drawer ne doit être détaché suite à une requête interactive. |
---|
488 | // bool IsDrawerAutoSizePos(int id) |
---|
489 | // Retourne "true" si le PIDrawer (Identificateur= "id") est positionné |
---|
490 | // dans le rectangle par défaut. |
---|
491 | // void GetDrawerPosition(int id, PIGrCoord& x1, PIGrCoord& y1, PIGrCoord& x2, PIGrCoord& y2, bool& elastic) |
---|
492 | // Retourne le rectangle d'attachement du PIDrawer avec l'identificateur "id". |
---|
493 | // "elastic=true": position et taille spécifiées en fraction de la taille du PIBaseWdg. |
---|
494 | //-- |
---|
495 | |
---|
496 | /* --Methode-- */ |
---|
497 | int PIBaseWdgGen::GetDrawerIdFromNum(int n) |
---|
498 | { |
---|
499 | if ( (n < 0) || (n >= mDrwList.size()) ) return(-1); |
---|
500 | return(mDrwList[n].id); |
---|
501 | } |
---|
502 | |
---|
503 | |
---|
504 | /* --Methode-- */ |
---|
505 | PIDrawer* PIBaseWdgGen::GetDrawer(int n) |
---|
506 | { |
---|
507 | if ( (n < 0) || (n >= mDrwList.size()) ) return(NULL); |
---|
508 | return(mDrwList[n].drw); |
---|
509 | } |
---|
510 | |
---|
511 | /* --Methode-- */ |
---|
512 | PIDrawer* PIBaseWdgGen::GetDrawerId(int id) |
---|
513 | { |
---|
514 | vector<BWDrwId>::iterator it; |
---|
515 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
516 | if ((*it).id == id) return((*it).drw); |
---|
517 | return(NULL); |
---|
518 | } |
---|
519 | |
---|
520 | /* --Methode-- */ |
---|
521 | bool PIBaseWdgGen::IsDrawerLockedId(int id) |
---|
522 | { |
---|
523 | vector<BWDrwId>::iterator it; |
---|
524 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
525 | if ((*it).id == id) return((*it).lock); |
---|
526 | return true; |
---|
527 | } |
---|
528 | |
---|
529 | /* --Methode-- */ |
---|
530 | bool PIBaseWdgGen::IsDrawerAutoSizePos(int id) |
---|
531 | { |
---|
532 | vector<BWDrwId>::iterator it; |
---|
533 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
534 | if ((*it).id == id) return( (*it).autoszp ); |
---|
535 | return false; |
---|
536 | } |
---|
537 | |
---|
538 | /* --Methode-- */ |
---|
539 | void PIBaseWdgGen::GetDrawerPosition(int id, PIGrCoord& x1, PIGrCoord& y1, |
---|
540 | PIGrCoord& x2, PIGrCoord& y2, bool& elastic) |
---|
541 | { |
---|
542 | x1 = y1 = x2 = y2 = 0; |
---|
543 | elastic = false; |
---|
544 | vector<BWDrwId>::iterator it; |
---|
545 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
546 | if ((*it).id == id) { |
---|
547 | x1 = (*it).x1; y1 = (*it).y1; |
---|
548 | x2 = (*it).x2; y2 = (*it).y2; |
---|
549 | elastic = (*it).elastic; |
---|
550 | break; |
---|
551 | } |
---|
552 | return; |
---|
553 | } |
---|
554 | |
---|
555 | //++ |
---|
556 | // void SetActiveDrawerId(int id) |
---|
557 | // Sélectionne le traceur (PIDrawer) avec l'identificateur "id" comme traceur actif. |
---|
558 | // void SetActiveDrawer(int n) |
---|
559 | // Sélectionne le traceur numéro "n" de la liste comme traceur actif. |
---|
560 | // int GetActiveDrawerId() |
---|
561 | // Retourne l'identificateur du traceur actif (-1 si pas de traceur actif). |
---|
562 | // int GetActiveDrawerNum() |
---|
563 | // Retourne le numéro du traceur actif dans la liste (index dans le vecteur de traceurs - |
---|
564 | // -1 si pas de traceur actif). |
---|
565 | // PIDrawer* GetActiveDrawer() |
---|
566 | // Retourne le pointeur sur le traceur actif (NULL si pas de traceur actif). |
---|
567 | // int FindNearestDrawerId(int x, int y) |
---|
568 | // Retourne le numéro du traceur le plus proche au point "(x,y)" de l'objet PIBaseWdg. |
---|
569 | // -1 si pas de traceur. |
---|
570 | //-- |
---|
571 | |
---|
572 | /* --Methode-- */ |
---|
573 | void PIBaseWdgGen::SetActiveDrawerId(int id) |
---|
574 | { |
---|
575 | vector<BWDrwId>::iterator it; |
---|
576 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
577 | if ((*it).id == id) { mActDrwId = id; break; } |
---|
578 | return; |
---|
579 | } |
---|
580 | |
---|
581 | /* --Methode-- */ |
---|
582 | void PIBaseWdgGen::SetActiveDrawer(int n) |
---|
583 | { |
---|
584 | if ( (n >= 0) && (n < mDrwList.size()) ) mActDrwId = mDrwList[n].id; |
---|
585 | return; |
---|
586 | } |
---|
587 | |
---|
588 | /* --Methode-- */ |
---|
589 | int PIBaseWdgGen::GetActiveDrawerId() |
---|
590 | { |
---|
591 | return(mActDrwId); |
---|
592 | } |
---|
593 | |
---|
594 | /* --Methode-- */ |
---|
595 | int PIBaseWdgGen::GetActiveDrawerNum() |
---|
596 | { |
---|
597 | if (mActDrwId < 0) return(-1); |
---|
598 | for(int i=0; i<mDrwList.size(); i++) |
---|
599 | if (mDrwList[i].id == mActDrwId) return(i); |
---|
600 | return(-1); |
---|
601 | } |
---|
602 | |
---|
603 | /* --Methode-- */ |
---|
604 | PIDrawer* PIBaseWdgGen::GetActiveDrawer() |
---|
605 | { |
---|
606 | if (mActDrwId < 0) return(NULL); |
---|
607 | else return(GetDrawerId(mActDrwId)); |
---|
608 | } |
---|
609 | |
---|
610 | /* --Methode-- */ |
---|
611 | int PIBaseWdgGen::FindNearestDrawerId(int xp, int yp) |
---|
612 | { |
---|
613 | if (mDrwList.size() < 1) return -1; |
---|
614 | double xmin,ymin, xmax, ymax; |
---|
615 | int drx0, dry0, drdx, drdy; |
---|
616 | int ddrx0, ddry0, ddrdx, ddrdy; |
---|
617 | |
---|
618 | if (mDrElastic) { |
---|
619 | ddrx0 = (int)((double) mDrX1 * (double)XSize()); |
---|
620 | ddry0 = (int)((double) mDrY1 * (double)YSize()); |
---|
621 | ddrdx = (int)((double) mDrX2 * (double)XSize()) - ddrx0 ; |
---|
622 | ddrdy = (int)((double) mDrY2 * (double)YSize()) - ddry0 ; |
---|
623 | } |
---|
624 | else { |
---|
625 | ddrx0 = (int)mDrX1; ddry0 = (int)mDrY1; |
---|
626 | ddrdx = (int)mDrX2-ddrx0; ddrdy = (int)mDrY2-ddry0; |
---|
627 | } |
---|
628 | |
---|
629 | int nid = -1; |
---|
630 | double neardist = 9.e39; |
---|
631 | bool fgido = false; |
---|
632 | |
---|
633 | vector<BWDrwId>::iterator it; |
---|
634 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) { |
---|
635 | if ( (*it).autoszp ) // Taille/position par defaut impose par PIBaseWdg |
---|
636 | { drx0 = ddrx0; dry0 = ddry0; drdx = ddrdx; drdy = ddrdy; } |
---|
637 | else { |
---|
638 | if ( (*it).elastic ) { // Taille/position defin en fraction de la taille du PIBaseWdg |
---|
639 | drx0 = (int)((double)(*it).x1 * (double)XSize()); |
---|
640 | dry0 = (int)((double)(*it).y1 * (double)YSize()); |
---|
641 | drdx = (int)((double)(*it).x2 * (double)XSize()) - drx0 ; |
---|
642 | drdy = (int)((double)(*it).y2 * (double)YSize()) - dry0 ; |
---|
643 | } |
---|
644 | else { |
---|
645 | drx0 = (int)(*it).x1 ; dry0 = (int)(*it).y1 ; |
---|
646 | drdx = (int)(*it).x2-drx0 ; drdy = (int)(*it).y2-dry0 ; |
---|
647 | } |
---|
648 | } |
---|
649 | // L'ordre des operations ici est importante |
---|
650 | if ( (*it).autolim ) { |
---|
651 | (*it).drw->SetLimits(mDrXmin, mDrXmax, mDrYmin, mDrYmax, mDXdir, mDYdir); |
---|
652 | (*it).drw->SetLogScale(mDXlog, mDYlog); |
---|
653 | } |
---|
654 | double xu, yu; |
---|
655 | (*it).drw->WdgCoord2DrwCoord(xp, yp, xu, yu, drx0, dry0, drdx, drdy); |
---|
656 | double curd = (*it).drw->GetDistanceToPoint(xu, yu); |
---|
657 | if (!fgido || (curd < neardist)) { |
---|
658 | neardist = curd; nid = (*it).id; fgido = true; |
---|
659 | } |
---|
660 | } |
---|
661 | return nid; |
---|
662 | } |
---|
663 | |
---|
664 | //++ |
---|
665 | // void CallDrawers(PIGraphic* g, int x0=0, int y0=0, int dx=0, int dy=0) |
---|
666 | // Appel de la méthode de tracé pour tous les Drawers |
---|
667 | // void CallDrawer(int id); |
---|
668 | // Appel de la méthode de tracé pour le drawer avec l'identificateur "id" |
---|
669 | //-- |
---|
670 | |
---|
671 | /* --Methode-- */ |
---|
672 | void PIBaseWdgGen::CallDrawers(PIGraphic* g, int x0, int y0, int dx, int dy) |
---|
673 | { |
---|
674 | double xmin,ymin, xmax, ymax; |
---|
675 | PIGraphicUC* guc; |
---|
676 | int drx0, dry0, drdx, drdy; |
---|
677 | int ddrx0, ddry0, ddrdx, ddrdy; |
---|
678 | |
---|
679 | if (mDrElastic) { |
---|
680 | ddrx0 = (int)((double) mDrX1 * (double)XSize()); |
---|
681 | ddry0 = (int)((double) mDrY1 * (double)YSize()); |
---|
682 | ddrdx = (int)((double) mDrX2 * (double)XSize()) - ddrx0 ; |
---|
683 | ddrdy = (int)((double) mDrY2 * (double)YSize()) - ddry0 ; |
---|
684 | } |
---|
685 | else { |
---|
686 | ddrx0 = (int)mDrX1; ddry0 = (int)mDrY1; |
---|
687 | ddrdx = (int)mDrX2-ddrx0; ddrdy = (int)mDrY2-ddry0; |
---|
688 | } |
---|
689 | |
---|
690 | bool sxy = false; |
---|
691 | if ((dx > 0) && (dy > 0)) sxy = true; |
---|
692 | |
---|
693 | vector<BWDrwId>::iterator it; |
---|
694 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) { |
---|
695 | g->SaveGraphicAtt(); |
---|
696 | if ( (*it).autoszp ) // Taille/position par defaut impose par PIBaseWdg |
---|
697 | { drx0 = ddrx0; dry0 = ddry0; drdx = ddrdx; drdy = ddrdy; } |
---|
698 | else { |
---|
699 | if ( (*it).elastic ) { // Taille/position defin en fraction de la taille du PIBaseWdg |
---|
700 | drx0 = (int)((double)(*it).x1 * (double)XSize()); |
---|
701 | dry0 = (int)((double)(*it).y1 * (double)YSize()); |
---|
702 | drdx = (int)((double)(*it).x2 * (double)XSize()) - drx0 ; |
---|
703 | drdy = (int)((double)(*it).y2 * (double)YSize()) - dry0 ; |
---|
704 | } |
---|
705 | else { |
---|
706 | drx0 = (int)(*it).x1 ; dry0 = (int)(*it).y1 ; |
---|
707 | drdx = (int)(*it).x2-drx0 ; drdy = (int)(*it).y2-dry0 ; |
---|
708 | } |
---|
709 | } |
---|
710 | // L'ordre des operations ici est importante |
---|
711 | if ( (*it).autolim ) { |
---|
712 | (*it).drw->SetLimits(mDrXmin, mDrXmax, mDrYmin, mDrYmax, mDXdir, mDYdir); |
---|
713 | (*it).drw->SetLogScale(mDXlog, mDYlog); |
---|
714 | } |
---|
715 | guc = (*it).drw->SetDrwWdg(this, drx0, dry0, drdx, drdy, g); |
---|
716 | if ((*it).clip) g->SetClipRectangle(drx0, dry0, drdx , drdy); |
---|
717 | (*it).drw->SelGraAtt(guc); |
---|
718 | if (sxy) { |
---|
719 | guc->GrC2UC(x0, y0, xmin, ymin); |
---|
720 | guc->GrC2UC(x0+dx, y0+dy, xmax, ymax); |
---|
721 | } |
---|
722 | else { |
---|
723 | guc->GrC2UC(0, 0, xmin, ymin); |
---|
724 | guc->GrC2UC(XSize(), YSize(), xmax, ymax); |
---|
725 | } |
---|
726 | if (xmin > xmax) dbl_swap(xmin,xmax); |
---|
727 | if (ymin > ymax) dbl_swap(ymin,ymax); |
---|
728 | (*it).drw->Draw(guc, xmin, ymin, xmax, ymax); |
---|
729 | g->RestoreGraphicAtt(); |
---|
730 | if ((*it).clip) g->ClearClipRectangle(); |
---|
731 | } |
---|
732 | |
---|
733 | return; |
---|
734 | } |
---|
735 | |
---|
736 | /* --Methode-- */ |
---|
737 | void PIBaseWdgGen::CallDrawer(int id) |
---|
738 | { |
---|
739 | double xmin,ymin, xmax, ymax; |
---|
740 | PIGraphicUC* guc; |
---|
741 | int drx0, dry0, drdx, drdy; |
---|
742 | int ddrx0, ddry0, ddrdx, ddrdy; |
---|
743 | |
---|
744 | PIGraphic* g = WindowGraphic(); |
---|
745 | g->SaveGraphicAtt(); |
---|
746 | |
---|
747 | if (mDrElastic) { |
---|
748 | ddrx0 = (int)((double) mDrX1 * (double)XSize()); |
---|
749 | ddry0 = (int)((double) mDrY1 * (double)YSize()); |
---|
750 | ddrdx = (int)((double) mDrX2 * (double)XSize()) - ddrx0 ; |
---|
751 | ddrdy = (int)((double) mDrY2 * (double)YSize()) - ddry0 ; |
---|
752 | } |
---|
753 | else { |
---|
754 | ddrx0 = (int)mDrX1; ddry0 = (int)mDrY1; |
---|
755 | ddrdx = (int)mDrX2-ddrx0; ddrdy = (int)mDrY2-ddry0; |
---|
756 | } |
---|
757 | vector<BWDrwId>::iterator it; |
---|
758 | for(it = mDrwList.begin(); it != mDrwList.end(); it++) |
---|
759 | if ((*it).id == id) { |
---|
760 | g->SaveGraphicAtt(); |
---|
761 | if ( (*it).autoszp ) // Taille/position par defaut impose par PIBaseWdg |
---|
762 | { drx0 = ddrx0; dry0 = ddry0; drdx = ddrdx; drdy = ddrdy; } |
---|
763 | else { |
---|
764 | if ( (*it).elastic ) { // Taille/position defin en fraction de la taille du PIBaseWdg |
---|
765 | drx0 = (int)((double)(*it).x1 * (double)XSize()); |
---|
766 | dry0 = (int)((double)(*it).y1 * (double)YSize()); |
---|
767 | drdx = (int)((double)(*it).x2 * (double)XSize()) - drx0 ; |
---|
768 | drdy = (int)((double)(*it).y2 * (double)YSize()) - dry0 ; |
---|
769 | } |
---|
770 | else { |
---|
771 | drx0 = (int)(*it).x1 ; dry0 = (int)(*it).y1 ; |
---|
772 | drdx = (int)(*it).x2-drx0 ; drdy = (int)(*it).y2-dry0 ; |
---|
773 | } |
---|
774 | } |
---|
775 | // L'ordre des operations ici est importante |
---|
776 | if ( (*it).autolim ) { |
---|
777 | (*it).drw->SetLimits(mDrXmin, mDrXmax, mDrYmin, mDrYmax, mDXdir, mDYdir); |
---|
778 | (*it).drw->SetLogScale(mDXlog, mDYlog); |
---|
779 | } |
---|
780 | guc = (*it).drw->SetDrwWdg(this, drx0, dry0, drdx, drdy, g); |
---|
781 | if ((*it).clip) g->SetClipRectangle(drx0, dry0, drdx , drdy); |
---|
782 | (*it).drw->SelGraAtt(guc); |
---|
783 | guc->GrC2UC(0, 0, xmin, ymin); |
---|
784 | guc->GrC2UC(XSize(), YSize(), xmax, ymax); |
---|
785 | if (xmin > xmax) dbl_swap(xmin,xmax); |
---|
786 | if (ymin > ymax) dbl_swap(ymin,ymax); |
---|
787 | (*it).drw->Draw(guc, xmin, ymin, xmax, ymax); |
---|
788 | g->RestoreGraphicAtt(); |
---|
789 | if ((*it).clip) g->ClearClipRectangle(); |
---|
790 | break; |
---|
791 | } |
---|
792 | g->RestoreGraphicAtt(); |
---|
793 | return; |
---|
794 | } |
---|
795 | |
---|
796 | |
---|
797 | /* --Methode-- */ |
---|
798 | PIGraphic* PIBaseWdgGen::WindowGraphic() |
---|
799 | { |
---|
800 | return(mWGrC); |
---|
801 | } |
---|