source: Sophya/trunk/SophyaPI/PI/pibwdggen.cc @ 2780

Last change on this file since 2780 was 2780, checked in by ansari, 19 years ago

1/ Suite corrections liees a l'appel de FinishCreate() (la bonne methode et au bon moment) dans les PIContainer (picontainergen/xx.cc)
2/ Corrections diverses liees au trace des axes / titre (piaxes.h pieldrw.cc)
3/ Ajout possibilite de faire Refresh() du widget a partir du drawer et bouton Refresh ds PIDrwOptionStringWindow - (pidrawer.h .cc pidrwtools.h .cc)
4/ Petites corrections de gestions des attributs graphiques (pigratt.cc piyfxdrw.cc ...)
5/ Amelioration/corrections PIBarGraph et PITextDrawer

Reza 30 Mai 2005

File size: 24.1 KB
Line 
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
13static 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-- */
86PIBaseWdgGen::PIBaseWdgGen(PIContainerGen *par, const char *nom,
87                       int sx, int sy, int px, int py) :
88PIWdg(par, nom, sx, sy, px, py)
89{
90mDrwId=0;   // Compteur des numeros sequentiel des PIDrawer
91mActDrwId = -1;  // Identificateur du drawer actif
92mAdfg=false;    // Pour controle d'appel de RemoveDrawer()
93mWGrC = NULL;   // PIGraphic (Contexte graphique) associe a la fenetre}
94                // Doit etre cree par PIBaseWdgX/Mac/...
95SetDefaultDrawRectangle(0., 0., 1., 1., true);
96SetDefaultDrawerLimits(0., 1., 0., 1., kAxeDirLtoR, kAxeDirUpDown);
97SetDefaultDrawerLogScale(false, false);
98}
99
100/* --Methode-- */
101PIBaseWdgGen::~PIBaseWdgGen()
102{
103delete mWGrC;
104if (PIDrwTools::GetCurrentBaseWdg() == this) 
105  PIDrwTools::SetCurrentBaseWdg(NULL);
106DeleteDrawers();
107}
108 
109
110/* --Methode--
111void PIBaseWdgGen::Refresh()
112{
113if ( IsVisible() )  {
114  Draw(mWGrC, 0, 0, XSize(), YSize());
115  CallDrawers(mWGrC);
116}
117return;
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-- */
169void PIBaseWdgGen::Draw(PIGraphic* g, int x0, int y0, int dx, int dy)
170{
171#ifdef DEBUG_RZXB
172puts("Debug_PIBaseWdgGen::Draw() Efface la fenetre par defaut ! ");
173#endif
174if (g->kind() != PI_PSFileGraphics) EraseWindow(x0, y0, dx, dy);
175return;
176}
177
178/* --Methode-- */
179void PIBaseWdgGen::Resize()
180{
181#ifdef DEBUG_RZXB
182puts("Debug_PIBaseWdgGen::Resize()  resize notify ");
183#endif
184return;
185}
186
187
188/* --Methode-- */
189void PIBaseWdgGen::Enter()
190{
191#ifdef DEBUG_RZXB
192puts("Debug_PIBaseWdgGen::Enter() enter notify ");
193#endif
194return;
195}
196
197/* --Methode-- */
198void PIBaseWdgGen::Leave()
199{
200#ifdef DEBUG_RZXB
201puts("Debug_PIBaseWdgGen::Leave() leave notify ");
202#endif
203return;
204}
205
206
207/* --Methode-- */
208void PIBaseWdgGen::But1Press(int /*x*/, int /*y*/)
209{
210Send(Msg(), PIMsg_Active);
211#ifdef DEBUG_RZXB
212printf ("PIBaseWdgGen::But1Press PosX,Y= %d %d \n", x, y);
213#endif
214return;
215}
216
217/* --Methode-- */
218void PIBaseWdgGen::But1Release(int /*x*/, int /*y*/)
219{
220#ifdef DEBUG_RZXB
221printf ("PIBaseWdgGen::ButReleasePosX,Y= %d %d \n", x, y);
222#endif
223return;
224}
225
226/* --Methode-- */
227void PIBaseWdgGen::But2Press(int /*x*/, int /*y*/)
228{
229return;
230}
231
232/* --Methode-- */
233void PIBaseWdgGen::But2Release(int /*x*/, int /*y*/)
234{
235return;
236}
237
238/* --Methode-- */
239void PIBaseWdgGen::But3Press(int /*x*/, int /*y*/)
240{
241return;
242}
243
244/* --Methode-- */
245void PIBaseWdgGen::But3Release(int /*x*/, int /*y*/)
246{
247return;
248}
249
250/* --Methode-- */
251void PIBaseWdgGen::PtrMove(int /*x*/, int /*y*/)
252{
253#ifdef DEBUG_RZXB
254printf ("Debug_PIBaseWdgGen::PtrMove PosX,Y= %d %d \n", x, y);
255#endif
256return;
257}
258
259/* --Methode-- */
260void PIBaseWdgGen::Ptr1Move(int /*x*/, int /*y*/)
261{
262#ifdef DEBUG_RZXB
263printf ("Debug_PIBaseWdgGen::Ptr1Move PosX,Y= %d %d \n", x, y);
264#endif
265return;
266}
267
268/* --Methode-- */
269void PIBaseWdgGen::Ptr2Move(int /*x*/, int /*y*/)
270{
271return;
272}
273
274
275/* --Methode-- */
276void PIBaseWdgGen::Ptr3Move(int /*x*/, int /*y*/)
277{
278return;
279}
280
281/* --Methode-- */
282void PIBaseWdgGen::Keyboard(int /*key*/, PIKeyModifier /*kmod*/)
283{
284#ifdef DEBUG_RZXB
285printf("PIBaseWdgGen::Keyboard: Key= %d (%c)  Mod= %d \n", key, (char)key, (int)kmod); 
286#endif
287return;
288}
289
290
291/* --Methode-- */
292void PIBaseWdgGen::PSPrint(PSFile * psf, int ofx, int ofy, double scale_x, double scale_y)
293{
294if (!psf) return;
295PIGraphicPS grpsf(psf, (PIWdg *)this, ofx, ofy, scale_x, scale_y);
296Draw(&grpsf, 0, 0, XSize(), YSize());
297CallDrawers(&grpsf); 
298return;
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-- */
329void PIBaseWdgGen::SetDefaultDrawRectangle(PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2, bool elastic)
330{
331mDrX1 = x1;  mDrY1 = y1;
332mDrX2 = x2;  mDrY2 = y2;   mDrElastic = elastic;
333}
334
335/* --Methode-- */
336void PIBaseWdgGen::GetDefaultDrawRectangle(PIGrCoord& x1, PIGrCoord& y1, PIGrCoord& x2, PIGrCoord& y2, bool& elastic)
337{
338x1 = mDrX1;  y1 = mDrY1;
339x2 = mDrX2;  y2 = mDrY2;   elastic = mDrElastic;
340}
341
342/* --Methode-- */
343void PIBaseWdgGen::SetDefaultDrawerLimits(double xmin, double xmax, double ymin, double ymax,
344                                          int axrl, int ayud)
345{
346mDrXmin = xmin;   mDrXmax = xmax; 
347mDrYmin = ymin;   mDrYmax = ymax; 
348if (axrl != kAxeDirSame)   mDXdir = axrl;   
349if (ayud != kAxeDirSame)   mDYdir = ayud;
350}
351
352/* --Methode-- */
353void PIBaseWdgGen::SetDefaultDrawerLogScale(bool logx, bool logy)
354{
355mDXlog = logx; 
356mDYlog = 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-- */
382int PIBaseWdgGen::AddDrawer(PIDrawer* drw, PIGrCoord x1, PIGrCoord y1, 
383                            PIGrCoord x2, PIGrCoord y2, bool psz, bool clip, bool ad, bool lock)
384{
385if (drw == NULL)   return(0);
386mDrwId++;
387BWDrwId did;
388did.x1 = x1;  did.y1 = y1;
389did.x2 = x2;  did.y2 = y2;
390did.autoszp = did.autolim = false;   
391did.elastic = psz;  did.clip = clip;
392did.id = mDrwId;  did.ad = ad; 
393did.lock = lock;
394did.drw = drw;
395mDrwList.push_back(did);
396drw->Attach(this, mDrwId);
397mActDrwId = mDrwId;   // Le dernier drawer ajoute devient le drawer actif par defaut
398return(mDrwId);
399}
400
401/* --Methode-- */
402int PIBaseWdgGen::AddDrawer(PIDrawer* drw, bool autolim, bool clip, bool ad, bool lock)
403{
404if (drw == NULL)   return(0);
405mDrwId++;
406BWDrwId did;
407did.x1 = 0.;  did.y1 = 0.;
408did.x2 = 1.;  did.y2 = 1.;
409did.autoszp = true;   did.autolim = autolim;   
410did.elastic = false;   did.clip = clip;
411did.id = mDrwId;  did.ad = ad;
412did.lock = lock; 
413did.drw = drw;
414mDrwList.push_back(did);
415drw->Attach(this, mDrwId);
416mActDrwId = mDrwId;   // Le dernier drawer ajoute devient le drawer actif par defaut
417return(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-- */
432void PIBaseWdgGen::MoveResizeDrawer(int id,  PIGrCoord x1, PIGrCoord y1,  PIGrCoord x2, PIGrCoord y2, bool elastic)
433{
434vector<BWDrwId>::iterator it;
435for(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  }
442return;
443}
444
445/* --Methode-- */
446void PIBaseWdgGen::RemoveDrawer(int id)
447{
448if (mAdfg)  return;
449vector<BWDrwId>::iterator it;
450for(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  }
460return;
461}
462
463/* --Methode-- */
464void PIBaseWdgGen::DeleteDrawers()
465{
466mAdfg = true;
467mActDrwId = -1;
468vector<BWDrwId>::iterator it;
469for(it = mDrwList.begin(); it != mDrwList.end(); it++) 
470  if ((*it).ad)  delete (*it).drw;
471mDrwList.erase(mDrwList.begin(), mDrwList.end() );
472mAdfg = false;
473return;
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-- */
497int PIBaseWdgGen::GetDrawerIdFromNum(int n)
498{
499if ( (n < 0) || (n >= mDrwList.size()) ) return(-1);
500return(mDrwList[n].id);
501}
502
503
504/* --Methode-- */
505PIDrawer* PIBaseWdgGen::GetDrawer(int n)
506{
507if ( (n < 0) || (n >= mDrwList.size()) ) return(NULL);
508return(mDrwList[n].drw);
509}
510
511/* --Methode-- */
512PIDrawer* PIBaseWdgGen::GetDrawerId(int id)
513{
514vector<BWDrwId>::iterator it;
515for(it = mDrwList.begin(); it != mDrwList.end(); it++) 
516  if ((*it).id == id)  return((*it).drw);
517return(NULL);
518}
519
520/* --Methode-- */
521bool PIBaseWdgGen::IsDrawerLockedId(int id)
522{
523vector<BWDrwId>::iterator it;
524for(it = mDrwList.begin(); it != mDrwList.end(); it++) 
525  if ((*it).id == id)  return((*it).lock);
526return true;
527}
528
529/* --Methode-- */
530bool PIBaseWdgGen::IsDrawerAutoSizePos(int id)
531{
532vector<BWDrwId>::iterator it;
533for(it = mDrwList.begin(); it != mDrwList.end(); it++) 
534  if ((*it).id == id)  return( (*it).autoszp );
535return false;
536}
537
538/* --Methode-- */
539void PIBaseWdgGen::GetDrawerPosition(int id, PIGrCoord& x1, PIGrCoord& y1, 
540                                     PIGrCoord& x2, PIGrCoord& y2, bool& elastic)
541{
542x1 = y1 = x2 = y2 = 0;
543elastic = false;
544vector<BWDrwId>::iterator it;
545for(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  }
552return;
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-- */
573void PIBaseWdgGen::SetActiveDrawerId(int id)
574{
575vector<BWDrwId>::iterator it;
576for(it = mDrwList.begin(); it != mDrwList.end(); it++) 
577  if ((*it).id == id) { mActDrwId = id; break; }
578return;
579}
580
581/* --Methode-- */
582void PIBaseWdgGen::SetActiveDrawer(int n)
583{
584if ( (n >= 0) && (n < mDrwList.size()) ) mActDrwId = mDrwList[n].id;
585return;
586}
587
588/* --Methode-- */
589int PIBaseWdgGen::GetActiveDrawerId()
590{
591  return(mActDrwId);
592}
593
594/* --Methode-- */
595int 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-- */
604PIDrawer*  PIBaseWdgGen::GetActiveDrawer()
605{
606  if (mActDrwId < 0) return(NULL); 
607  else return(GetDrawerId(mActDrwId));
608}
609
610/* --Methode-- */
611int 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  }
661return 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-- */
672void PIBaseWdgGen::CallDrawers(PIGraphic* g, int x0, int y0, int dx, int dy)
673{
674double xmin,ymin, xmax, ymax;
675PIGraphicUC* guc;
676int drx0, dry0, drdx, drdy;
677int ddrx0, ddry0, ddrdx, ddrdy;
678
679if (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  }
685else {
686  ddrx0 = (int)mDrX1;   ddry0 = (int)mDrY1; 
687  ddrdx = (int)mDrX2-ddrx0;   ddrdy = (int)mDrY2-ddry0; 
688  }
689
690bool sxy = false;
691if ((dx > 0) && (dy > 0))  sxy = true;
692
693vector<BWDrwId>::iterator it;
694for(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
733return;
734}
735
736/* --Methode-- */
737void PIBaseWdgGen::CallDrawer(int id)
738{
739double xmin,ymin, xmax, ymax;
740PIGraphicUC* guc;
741int drx0, dry0, drdx, drdy;
742int ddrx0, ddry0, ddrdx, ddrdy;
743
744PIGraphic* g = WindowGraphic();
745g->SaveGraphicAtt();
746
747if (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  }
753else {
754  ddrx0 = (int)mDrX1;   ddry0 = (int)mDrY1; 
755  ddrdx = (int)mDrX2-ddrx0;   ddrdy = (int)mDrY2-ddry0; 
756  }
757vector<BWDrwId>::iterator it;
758for(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  }
792g->RestoreGraphicAtt();
793return;
794}
795
796
797/* --Methode-- */
798PIGraphic* PIBaseWdgGen::WindowGraphic()
799{
800return(mWGrC);
801}
Note: See TracBrowser for help on using the repository browser.