source: Sophya/trunk/Poubelle/PI/piimage.cc@ 222

Last change on this file since 222 was 222, checked in by ansari, 26 years ago

Creation module DPC/PI Reza 09/04/99

File size: 23.9 KB
Line 
1// Module PI : Peida Interactive PIImage
2// Affichage d'image R. Ansari 05/95
3// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
4// Refonte Reza 10/95
5
6
7#include <stdlib.h>
8#include <stdio.h>
9#include <string.h>
10
11#include "piimage.h"
12#include "piimgtools.h"
13#include "pidrwtools.h"
14#include PIAPP_H
15
16//++
17// Class PIImage
18// Lib PI
19// include piimage.h
20//
21// Classe pour la l'affichage et la manipulation d'images.
22// Peut contrôler un PIPixmap pour l'affichage d'une zone
23// agrandie (zoom) et un PIPixmap pour l'affichage de toute
24// l'image (réduite).
25// Utilise les adaptateur de tableaux 2D manipuler le
26// contenu des images ("P2DArrayAdapter").
27//
28// * Bouton-1 : Envoie le message "PIMsg_Active" et affiche
29// les coordonnées courantes et la valeur du pixel,
30// et positionne le pavé.
31// * Bouton-2 : Permet de définir une zone de l'image et repositionne le pavé.
32// * Bouton-3 : Permet de déplacer l'image dans la fenêtre
33//
34// Gestion du clavier :
35// * <Alt>O : Affichage de la fenêtre de contrôle des paramètres de visualisation.
36// * <Alt>G : Affichage de la fenêtre de changement des attributs graphiques
37// * <Alt>R : Rafraîchit l'affichage.
38// * <Alt>V : Copier/*Coller* Ajout du texte du buffer copier/coller
39// sur l'objet à la position courante.
40// * <Alt>C : *Copier*/Coller Permet de copier le contenu de la zone sélectionnée
41// de l'image sous forme texte.
42// * <Alt>Z : Supprime les textes et signes ajoutés au dessin.
43// * Touches Curseurs : déplace la pavé.
44//--
45//++
46// Links Parents
47// PIPixmap
48//--
49
50//++
51// Titre Constructeurs, méthodes
52//--
53//++
54// PIImage(PIContainerGen *par, char *nom=NULL, int sx=0, int sy=0, int px=0, int py=0)
55// Créateur
56//
57//--
58
59// --------------------------------------------------------------------------------
60// ----------------------------- Classe PIImage -----------------------------------
61// --------------------------------------------------------------------------------
62// Variable globale pour la gestion de l'image courante
63PIImage* PIImage::cur_piimage = NULL;
64/* --Methode-- */
65PIImage* PIImage::CurrentPIImage()
66{
67return(cur_piimage);
68}
69
70/* --Methode-- */
71void PIImage::SetCurrentPIImage(PIImage* curimg)
72{
73cur_piimage = curimg;
74}
75
76/* --Methode-- */
77PIImage::PIImage(PIContainerGen *par, char *nom,
78 int sx, int sy, int px, int py) :
79 PIPixmap(par, nom, sx, sy, px, py)
80{
81
82img = NULL;
83aisup = false;
84curshow = true;
85winovis = true; // $CHECK$ Reza A enlever si possible 17/6/96
86
87
88zow = NULL; // Widget zoom
89gvw = NULL; // widget vue globale
90cmvw = NULL; // widget ColorMapView
91// Fenetre transient et Label pour affichage de l'info (texte PixVal)
92int tx, ty;
93PIApplicationPrefCompSize(tx, ty);
94tx *= 5; ty = (int)(ty*0.8);
95trtw = new PIWindow(this, "PixVal", PIWK_transient, tx, ty, 0, 0);
96trtw->SetAutoDelChilds(true);
97trtlb = new PILabel(trtw, "PixVal", tx, ty, 0, 0);
98trtlb->SetBinding(PIBK_fixed,PIBK_fixed, PIBK_fixed,PIBK_fixed);
99ustrtw = atrtw = false;
100if ((sx < 300) || (sy < 150) ) atrtw = true;
101showinfo = false;
102
103gpixm = zpixm = pixm = NULL;
104xsgpxm = xszpxm = xspxm = 0;
105ysgpxm = yszpxm = yspxm = 0;
106lut = NULL;
107offx = offy = 0;
108xpav = ypav = 0;
109xpv0 = ypv0 = 0;
110xszpav = yszpav = 1;
111xmv0 = ymv0 = -1;
112dxmv = dymv = 0;
113xcurs = ycurs = -1;
114zoom = 1;
115zmgv = 1;
116
117mdrw = new PIElDrawer();
118gvdrw = new PIElDrawer();
119AddDrawer(mdrw, true, false, false);
120
121SetLut(0., 32000., kLutType_Lin, 0, false);
122SetColMapId(CMAP_COLRJ32);
123// pour le copier-coller
124cpbuffer = NULL;
125cpbuflen = 0;
126
127SetBackgroundColor(PI_Black);
128
129ActivateKeyboard();
130ActivateButton(1);
131ActivateMove(1);
132ActivateButton(2);
133ActivateMove(2);
134ActivateButton(3);
135ActivateMove(3);
136
137cur_piimage = this;
138}
139
140/* --Methode-- */
141PIImage::~PIImage()
142{
143if (pixm) delete pixm;
144if (zpixm) delete zpixm;
145if (zow)
146 {
147 zow->SetPixmap(NULL,0,0);
148 zow->EraseWindow();
149 }
150if (gpixm) delete gpixm;
151if (gvw)
152 {
153 gvw->SetPixmap(NULL,0,0);
154 gvw->EraseWindow();
155 gvw->SetMsg(0); gvw->SetMsgParent(NULL);
156 gvw->SetUserData(NULL, 0);
157 }
158if (cmvw) cmvw->SetColMap(NULL, 1., -1., true);
159if (lut) delete lut;
160delete mdrw;
161delete gvdrw;
162if (aisup && img) delete img; // Suppression automatique d'image
163delete trtw;
164if (cpbuffer) delete[] cpbuffer;
165if (this == cur_piimage) cur_piimage = NULL;
166}
167
168/* --Methode-- */
169void PIImage::Process(PIMessage msg, PIMsgHandler* sender, void* data)
170{
171if (UserMsg(msg) == (Msg()+626))
172 {
173 if (ModMsg(msg) == PIMsg_Click)
174 { int* pxy=(int *)data; SetPave(pxy[0]*zmgv, pxy[1]*zmgv); }
175 if (ModMsg(msg) == PIMsg_Resize)
176 { ComputeGloVPixmap(); SetGloVPixmap(); }
177 }
178else ReSend(msg, sender, data);
179return;
180}
181
182/* --Methode-- */
183void PIImage::SetImage(P2DArrayAdapter *pim, bool ad, bool refr)
184{
185
186offx = offy = 0;
187xpav = ypav = 0;
188xszpav = yszpav = 1;
189img = pim;
190if (gpixm) delete gpixm;
191gpixm = NULL;
192xsgpxm = ysgpxm = 0;
193zmgv = 1;
194
195if (img) {
196// SetSize(img->XSize(), img->YSize());
197 CenterPave();
198 double min=1., max=-1., moy, sig;
199 int nbnul, nbsat;
200 img->CheckDyn(min, max, moy, sig, nbnul, nbsat);
201 SetLut(min, max, kLutType_Lin, 1, refr);
202 aisup = ad;
203 }
204else aisup = false;
205return;
206}
207
208/* --Methode-- */
209void PIImage::ChangeAxesConfiguration(bool ix, bool iy, bool xy, bool refr)
210{
211if (!img) return;
212bool invx, invy, exy;
213img->GetAxesConfiguration(invx, invy, exy);
214if (ix) invx = !invx;
215if (iy) invy = !invy;
216if (xy) exy = !exy;
217img->ConfigureAxes(invx, invy, exy);
218ComputeGloVPixmap();
219if (refr) Apply();
220}
221
222/* --Methode-- */
223void PIImage::SetZoomWin(PIPixmap * zw, bool refr)
224{
225zow = zw;
226if (zow && refr && img)
227 ComputeZoomPixmap();
228return;
229}
230
231/* --Methode-- */
232void PIImage::SetGloVWin(PIPixmap * zw, bool refr)
233{
234gvw = zw;
235if (gvw && img)
236 { ComputeGloVPixmap();
237 if (refr) SetGloVPixmap(); }
238return;
239}
240
241/* --Methode-- */
242void PIImage::SetCMapWin(PICMapView * cw, bool refr)
243{
244cmvw = cw;
245if (cmvw && refr) cmvw->SetColMap(cmap, Lut()->Min(), Lut()->Max(), true);
246}
247
248
249/* --Methode-- */
250void PIImage::UseInfoWin(bool trw)
251{
252ustrtw = trw;
253}
254
255/* --Methode-- */
256void PIImage::ShowInfo(bool si)
257{
258if (showinfo == si) return;
259showinfo = si;
260if (showinfo && img) {
261 char buff[256];
262 double x,y;
263 img->XYCoord(xpav, ypav, x, y);
264 sprintf(buff," X= %g , Y= %g Pix= %g (%d,%d) ",
265 x, y , (*img)(xpav, ypav), xpav, ypav );
266 DrawInfo(mWGrC, buff);
267 }
268else DrawInfo(mWGrC, NULL);
269}
270
271/* --Methode-- */
272void PIImage::ShowCursor(bool sc)
273{
274if (curshow == sc) return;
275curshow = sc;
276if (curshow) DrawCursor(mWGrC);
277else DrawCursor(mWGrC, -1, -1);
278return;
279}
280
281/* --Methode-- */
282void PIImage::SetLut(double min, double max, int typlut, int lauto, bool refr)
283{
284if (lut) delete(lut);
285if (lauto && img)
286 {
287 int nbsig = lauto;
288 double fracmax = 1. - 0.05*nbsig;
289 img->ComputeLut_PicHisto(min, max, nbsig, fracmax);
290 }
291
292lut = new LUT(min, max, NbCol(), typlut);
293
294ComputeGloVPixmap();
295if (refr) Apply();
296return;
297}
298
299
300/* --Methode-- */
301void PIImage::SetLut(LUT *clut, bool refr)
302{
303LUT * olut = lut;
304lut = new LUT(clut->Min(), clut->Max(), NbCol(), clut->Type());
305if (olut) delete olut;
306
307ComputeGloVPixmap();
308if (refr) Apply();
309return;
310}
311
312/* --Methode-- */
313void PIImage::SetZoomF(float fzm, bool refr)
314{
315int zm;
316
317if (fzm < 0.01) return;
318if (fzm < 1.) zm = (int)(-(1./fzm));
319else zm = (int)(fzm+0.25);
320SetZoom(zm, refr);
321return;
322}
323
324/* --Methode-- */
325void PIImage::SetZoom(int zm, bool refr)
326{
327if ((zm == 0) || (zm == -1) ) zoom = 1;
328else if (zm > 20) zoom = 20;
329else if (zm < -20) zoom = -20;
330else zoom = zm;
331if (img)
332 { SetOffsetFromPave();
333 if (refr) Apply(); }
334return;
335}
336
337/* --Methode-- */
338float PIImage::GetZoomF()
339{
340if (zoom >= 1) return((float)zoom);
341else return(-1./(float)zoom);
342}
343
344
345/* --Methode-- */
346void PIImage::SetOffset(int ox, int oy, bool refr)
347{
348if (img == NULL) {offx = offy = 0; return; }
349if (ox < 0) ox = 0;
350if (ox >= (img->XSize()-1)) ox = img->XSize()-2;
351if (oy < 0) oy = 0;
352if (oy >= (img->YSize()-1)) oy = img->YSize()-2;
353offx = ox; offy = oy;
354CenterPave();
355if (refr) Apply();
356return;
357}
358
359
360/* --Methode-- */
361void PIImage::SetPave(int x, int y, bool refr, bool cent)
362{
363int xc, yc;
364
365if (img == NULL)
366 { offx = offy = 0;
367 xpav = ypav = 0;
368 return; }
369
370if ( (x >= (img->XSize()-1)) || ( x < 0) ||
371 (y >= (img->YSize()-1)) || ( y < 0) ) return;
372
373if ( (x == xpav) && (y == ypav) ) return;
374xpav = x; ypav = y;
375
376if ( PosImg2W(xpav,ypav,&xc, &yc) || cent) // Il faut recenter l'image
377 { SetOffsetFromPave();
378 if (refr) Apply(true); }
379else if (refr)
380 { Apply(false); if (curshow) DrawCursor(mWGrC); }
381
382return;
383}
384
385/* --Methode-- */
386void PIImage::SetColMap(PIColorMap* cmp, bool refr)
387{
388if (!cmp) return;
389int cmapid = cmp->Type();
390if ( (cmapid == CMAP_GREY32) || (cmapid == CMAP_GREYINV32) ||
391 (cmapid == CMAP_GREY128) || (cmapid == CMAP_GREYINV128)) mdrw->SetColAtt(PI_Red);
392else mdrw->SetColAtt(PI_White);
393PIPixmap::SetColMap(cmp, refr);
394if (zow) zow->SetColMap(cmp, refr);
395if (gvw) gvw->SetColMap(cmp, refr);
396if (cmvw) cmvw->SetColMap(cmap, Lut()->Min(), Lut()->Max(), refr);
397return;
398}
399
400/* --Methode-- */
401void PIImage::SetColMapId(CMapId cmapid, bool refr)
402{
403if ( (cmapid == CMAP_GREY32) || (cmapid == CMAP_GREYINV32) ||
404 (cmapid == CMAP_GREY128) || (cmapid == CMAP_GREYINV128)) mdrw->SetColAtt(PI_Red);
405else mdrw->SetColAtt(PI_White);
406PIPixmap::SetColMapId(cmapid, refr);
407if (zow) zow->SetColMapId(cmapid, refr);
408if (gvw) gvw->SetColMapId(cmapid, refr);
409if (cmvw) cmvw->SetColMapId(cmapid, Lut()->Min(), Lut()->Max(), refr);
410return;
411}
412
413
414/* --Methode-- */
415void PIImage::Apply(bool mw)
416{
417if (img == NULL) return;
418if (mw) {
419 ComputePixmap();
420 Send(Msg(), PIMsg_Active);
421 cur_piimage = this;
422 PIDrwTools::SetCurrentBaseWdg(this);
423 }
424else {
425 char buff[256];
426 double x,y;
427 img->XYCoord(xpav, ypav, x, y);
428 sprintf(buff," X= %g , Y= %g Pix= %g (%d,%d) ",
429 x, y , (*img)(xpav, ypav), xpav, ypav );
430 if (ustrtw || atrtw) trtlb->SetLabel((string)buff);
431 else DrawInfo(mWGrC, buff);
432 }
433if (zow != NULL) ComputeZoomPixmap();
434if (gvw != NULL)
435 if ( (gvw->UserData() != this) || (mw) ) SetGloVPixmap();
436if (cmvw) cmvw->SetColMap(cmap, Lut()->Min(), Lut()->Max(), true);
437
438return;
439}
440
441/* --Methode-- */
442void PIImage::Resize()
443{
444// printf("PIImage::Resize\n");
445// On bascule sur la fenetre transient pour l'affichage des valeurs si fenetre trop petite
446if ((XSize() < 300) || (YSize() < 150) ) atrtw = true;
447else atrtw = false;
448PIPixmap::Resize();
449CenterPave();
450Apply();
451return;
452}
453
454/* --Methode-- */
455void PIImage::Draw(PIGraphic* g, int x0, int y0, int dx, int dy)
456{
457PIPixmap::Draw(g, x0, y0, dx, dy);
458winovis = false; // $CHECK$ Reza A enlever si possible 17/6/96
459if (curshow) {
460 int xc,yc;
461 PosImg2W(xpav, ypav, &xc, &yc);
462 if ((xc >= x0) && (xc < x0+dx) &&
463 (yc >= y0) && (yc < y0+dy) ) DrawCursor(g, xc, yc);
464 }
465
466if (showinfo && img) {
467 char buff[256];
468 double x,y;
469 img->XYCoord(xpav, ypav, x, y);
470 sprintf(buff," X= %g , Y= %g Pix= %g (%d,%d) ",
471 x, y , (*img)(xpav, ypav), xpav, ypav );
472 DrawInfo(mWGrC, buff);
473 }
474
475return;
476}
477
478/* --Methode-- */
479void PIImage::Keyboard(int key, PIKeyModifier kmod)
480{
481cur_piimage = this;
482if (kmod == PIKM_Alt) {
483 if (key == 'R' || key == 'r') Apply(true); // Pour tout rafraichir
484 else if (key == 'V' || key == 'v') RequestSelection(); // Pour coller (copier/coller)
485 else if (key == 'Z' || key == 'z') { mdrw->ElDelAll(); Refresh(); } // Pour supprimer tous les signes
486 else if (key == 'O' || key == 'o') PIImgTools::ShowPIImgTools(); // Fentre LUT et options
487 else if (key == 'G' || key == 'g') { // Fentre attributs graphiques
488 PIDrwTools::SetCurrentBaseWdg(this);
489 PIDrwTools::ShowPIDrwTools(); // Fentre axes et options de trace
490 }
491// ---- Le copier ----
492 else if ((key == 'C' || key == 'c') && img) {
493 // On limite la taille a 48x48
494 int i1 = XPave();
495 int i2 = ( XSzPave() < 48 ) ? i1+XSzPave() : i1+48;
496 int j1 = YPave();
497 int j2 = ( YSzPave() < 48 ) ? j1+YSzPave() : i1+48;
498 if ( ( (i2-i1) < 1 ) || ((j2-j1) < 1) ) return;
499 if (!ClaimSelection()) return; // On n'a pas pu prendre possession de la zone d'echange
500 if (cpbuffer) delete[] cpbuffer;
501 cpbuflen = (j2-j1)*(i2-i1+2)*12+(j2-j1)+128;
502 cpbuffer = new char[cpbuflen];
503 sprintf(cpbuffer,"PIImage: Pave(%dx%d) en (%d, %d) MaxCopie= 48x48 \n",
504 XSzPave(), YSzPave(), i1, j1);
505 int i,j;
506 int l = strlen(cpbuffer);
507 for(j=j1; j<j2; j++) {
508 sprintf(cpbuffer+l,"L %3d:",j);
509 l += 6;
510 for(i=i1; i<i2; i++) { sprintf(cpbuffer+l," %10g", (*img)(i, j)); l += 11; }
511 cpbuffer[l] = '\n'; l++;
512 }
513 cpbuffer[l] = '\0';
514 cpbuflen = l+1;
515 }
516 }
517
518
519else if (kmod == PIKM_Blank) {
520 switch (key) {
521 case PIK_Up :
522 SetPave(xpav, ypav-1, true, false);
523 break;
524 case PIK_Down :
525 SetPave(xpav, ypav+1, true, false);
526 break;
527 case PIK_Left :
528 SetPave(xpav-1, ypav, true, false);
529 break;
530 case PIK_Right :
531 SetPave(xpav+1, ypav, true, false);
532 break;
533 default :
534 break;
535 }
536}
537
538}
539
540
541/* --Methode-- */
542void PIImage::But1Press(int x, int y)
543{
544int xp, yp;
545
546Send(Msg(), PIMsg_Active);
547cur_piimage = this;
548PIDrwTools::SetCurrentBaseWdg(this);
549if (img == NULL) return;
550if ( PosW2Img(x, y, &xp, &yp) ) return;
551SelPointerShape(PI_CrossPointer);
552xpav = xp; ypav = yp;
553if (ustrtw || atrtw) ShowTrTxW();
554Apply(false);
555if (curshow) DrawCursor(mWGrC, -1,-1);
556return;
557}
558
559
560/* --Methode-- */
561void PIImage::Ptr1Move(int x, int y)
562{
563int xp, yp;
564if (img == NULL) return;
565if ( PosW2Img(x, y, &xp, &yp) ) return;
566xpav = xp; ypav = yp;
567Apply(false);
568return;
569}
570
571
572/* --Methode-- */
573void PIImage::But1Release(int /*x*/, int /*y*/)
574{
575SelPointerShape(PI_ArrowPointer);
576if (curshow) DrawCursor(mWGrC);
577if (ustrtw || atrtw) trtw->Hide();
578else if (!showinfo) DrawInfo(mWGrC, NULL);
579return;
580}
581
582
583/* --Methode-- */
584void PIImage::But2Press(int x, int y)
585{
586
587Send(Msg(), PIMsg_Active);
588cur_piimage = this;
589PIDrwTools::SetCurrentBaseWdg(this);
590if (img == NULL) return;
591if ( PosW2Img(x, y, &xpv0, &ypv0) ) { xmv0 = -1; return; }
592xmv0 = x; ymv0 = y; dxmv = dymv = 0;
593if (curshow) DrawCursor(mWGrC,-1,-1);
594mWGrC->SelGOMode(PI_GOXOR);
595if (GetColMapId() == CMAP_COLRJ32)
596mWGrC->SelForeground(PI_Yellow);
597else mWGrC->SelForeground(PI_Magenta);
598mWGrC->SelLine(PI_NormalLine);
599if (ustrtw || atrtw) ShowTrTxW();
600return;
601}
602
603/* --Methode-- */
604void PIImage::Ptr2Move(int x, int y)
605{
606int xp, yp;
607if (img == NULL) return;
608if (xmv0 < 0) return;
609if ( PosW2Img(x, y, &xp, &yp) ) return;
610mWGrC->DrawBox(xmv0, ymv0, dxmv, dymv);
611dxmv = x-xmv0; dymv = y-ymv0;
612mWGrC->DrawBox(xmv0, ymv0, dxmv, dymv);
613
614 {
615 char buff[256];
616 double x,y;
617 img->XYCoord(xp, yp, x, y);
618 sprintf(buff," X= %g , Y= %g Pix= %g (C= %d,%d) ",
619 x, y , (*img)(xp, yp), (xp+xpv0)/2, (yp+ypv0)/2 );
620 if (ustrtw || atrtw) trtlb->SetLabel((string)buff);
621 else DrawInfo(mWGrC, buff);
622 }
623
624return;
625}
626
627/* --Methode-- */
628void PIImage::But2Release(int x, int y)
629{
630int xp2, yp2;
631
632if (img == NULL) return;
633if (xmv0 < 0) return;
634mWGrC->DrawBox(xmv0, ymv0, dxmv, dymv);
635mWGrC->SelGOMode(PI_GOCopy);
636mWGrC->SelForeground(PI_White);
637if ( PosW2Img(x, y, &xp2, &yp2) )
638 PosW2Img(xmv0+dxmv, ymv0+dymv, &xp2, &yp2);
639xpav = (xpv0+xp2)/2;
640ypav = (ypv0+yp2)/2;
641xszpav = ((xp2-xpv0) > 0) ? (xp2-xpv0) : 1;
642yszpav = ((yp2-ypv0) > 0) ? (yp2-ypv0) : 1;
643
644Apply(false);
645if (curshow) DrawCursor(mWGrC);
646if (ustrtw || atrtw) trtw->Hide();
647else if (!showinfo) DrawInfo(mWGrC, NULL);
648return;
649}
650
651
652/* --Methode-- */
653void PIImage::But3Press(int x, int y)
654{
655int xp, yp;
656
657Send(Msg(), PIMsg_Active);
658cur_piimage = this;
659PIDrwTools::SetCurrentBaseWdg(this);
660if (img == NULL) return;
661if ( PosW2Img(x, y, &xp, &yp) ) { xmv0 = -1; return; }
662if (curshow) DrawCursor(mWGrC,-1,-1);
663if (ustrtw || atrtw) ShowTrTxW();
664SelPointerShape(PI_TDLRArrowPointer);
665xmv0 = xp;
666ymv0 = yp;
667return;
668}
669
670
671/* --Methode-- */
672void PIImage::Ptr3Move(int x, int y)
673{
674int xp, yp;
675if (img == NULL) return;
676if (xmv0 < 0) return;
677if ( PosW2Img(x, y, &xp, &yp) ) return;
678
679char buff[256];
680sprintf(buff," DelX= %d , DelY= %d ", xp-xmv0, yp-ymv0);
681if (ustrtw || atrtw) trtlb->SetLabel((string)buff);
682else DrawInfo(mWGrC, buff);
683}
684
685/* --Methode-- */
686void PIImage::But3Release(int x, int y)
687{
688int xp, yp;
689
690SelPointerShape(PI_ArrowPointer);
691if (ustrtw || atrtw) trtw->Hide();
692if (img == NULL) return;
693if (xmv0 < 0) return;
694if ( PosW2Img(x, y, &xp, &yp) ) return;
695
696offx -= (xp-xmv0);
697offy -= (yp-ymv0);
698
699if (offx < 0) offx = 0;
700if (offy < 0) offy = 0;
701if (offx >= img->XSize()) offx = img->XSize();
702if (offy >= img->YSize()) offy = img->YSize();
703xpav = xmv0; ypav = ymv0;
704xmv0 = ymv0 = -1;
705Apply();
706return;
707}
708
709
710/* --Methode-- */
711void PIImage::PasteSelection(unsigned int typ, void *pdata, unsigned int l)
712{
713if (!img) return;
714if (typ != PICP_string) return;
715int ll = (l<256) ? l+1 : 256;
716char pc[256];
717strncpy(pc, (char*)pdata, ll-1); pc[ll-1] = '\0';
718double fx, fy;
719img->Coord(xpav, ypav, fx, fy);
720mdrw->ElAddText(fx, fy, pc );
721mdrw->Refresh();
722}
723
724/* --Methode-- */
725void * PIImage::ProvideSelection(unsigned int& typ, unsigned int& len)
726{
727typ = PICP_string;
728len = cpbuflen;
729return(cpbuffer);
730}
731
732/* --Methode-- */
733void PIImage::SelectionLost()
734{
735if (cpbuffer) delete[] cpbuffer;
736cpbuffer = NULL;
737cpbuflen = 0;
738return;
739}
740
741
742
743/* --Methode-- */
744void PIImage::ComputePixmap()
745{
746unsigned int xwsz, ywsz;
747
748if (img == NULL) return;
749xwsz = XSize();
750ywsz = YSize();
751
752pixm = img->ComputePixmap(lut, offx, offy, zoom, xwsz, ywsz, pixm, &xspxm, &yspxm);
753int xw1, yw1, xw2, yw2;
754xw1 = (xwsz-xspxm)/2;
755if (xw1 < 0) xw1 = 0;
756yw1 = (ywsz-yspxm)/2;
757if (yw1 < 0) yw1 = 0;
758xw2 = xspxm+xw1;
759yw2 = yspxm+yw1;
760SetDefaultDrawRectangle(xw1, yw1, xw2, yw2, false);
761// printf("--DBG-- ComputePixmap() %d %d $ %d %d :: %d %d , %d %d \n", xwsz, ywsz, xspxm, yspxm, xw1, yw1, xw2, yw2);
762int x1,y1, x2,y2;
763ofx = xw1; ofy = yw1;
764PosW2Img(xw1, yw1, &x1, &y1);
765PosW2Img(xw2, yw2, &x2, &y2);
766double fx1,fy1, fx2, fy2;
767img->Coord(x1,y1, fx1, fy2); // fy1 et fy2 echange expres pour utiliser kAxeDirAuto
768img->Coord(x2,y2, fx2, fy1); // En effet Image de haut vers bas, Axes de bas vers haut par defaut
769SetDefaultDrawerLimits(fx1, fx2, fy1, fy2, kAxeDirAuto, kAxeDirAuto);
770// printf("--DBG2-- ComputePixmap() %g %g %g %g \n", fx1, fx2, fy1, fy2);
771xcurs = ycurs = -1;
772SetPixmap(pixm, xspxm, yspxm, true, xw1, yw1);
773// Refresh();
774return;
775}
776
777
778/* --Methode-- */
779void PIImage::ComputeZoomPixmap()
780{
781unsigned int xwsz, ywsz;
782int lofx, lofy;
783int zm;
784
785if (zow == NULL) return;
786if (img == NULL) return;
787
788xwsz = zow->XSize();
789ywsz = zow->YSize();
790
791zm = zoom+4;
792if ( (zm==-1) || (zm == 0) ) zm = 1;
793if (zm > 0)
794 {
795 lofx = xpav-(xwsz/2/zm);
796 lofy = ypav-(ywsz/2/zm);
797 }
798else
799 {
800 lofx = xpav+(xwsz*zm/2);
801 lofy = ypav+(ywsz*zm/2);
802 }
803if (lofx < 0) lofx = 0;
804if (lofy < 0) lofy = 0;
805
806zpixm = img->ComputePixmap(lut, lofx, lofy, zm, xwsz, ywsz, zpixm, &xszpxm, &yszpxm);
807zow->SetColMap(cmap, false);
808zow->SetPixmap(zpixm, xszpxm, yszpxm);
809zow->SetUserData((void *)this, 0);
810// zow->Refresh();
811return;
812
813}
814
815
816/* --Methode-- */
817void PIImage::ComputeGloVPixmap()
818{
819unsigned int xwsz, ywsz;
820int zmx,zmy;
821
822if (gvw == NULL) return;
823if (img == NULL) return;
824
825xwsz = gvw->XSize();
826ywsz = gvw->YSize();
827
828zmx = img->XSize()/xwsz;
829zmy = img->YSize()/ywsz;
830
831if (zmx < zmy) zmx = zmy;
832if (zmx < 1) zmx = 1;
833zmgv = zmx;
834if (zmx > 1) zmx = -zmx;
835gpixm = img->ComputePixmap(lut, 0, 0, zmx, xwsz, ywsz, gpixm, &xsgpxm, &ysgpxm);
836// printf("DEBUG-ComputeGloVPixmap() %d-%d , (%d,%d) , %d-%d \n", xwsz, ywsz, zmx, zmy, xsgpxm, ysgpxm);
837return;
838}
839
840/* --Methode-- */
841void PIImage::SetGloVPixmap()
842{
843float zm;
844int x,y, dx,dy;
845
846int xw1, yw1, xw2, yw2;
847xw1 = (gvw->XSize()-xsgpxm)/2;
848if (xw1 < 0) xw1 = 0;
849yw1 = (gvw->YSize()-ysgpxm)/2;
850if (yw1 < 0) yw1 = 0;
851xw2 = xsgpxm+xw1;
852yw2 = ysgpxm+yw1;
853
854if (zoom > 0) zm = zmgv*zoom;
855else zm = (float)zmgv/(float)(-zoom);
856x = offx/zmgv+1+xw1;
857y = offy/zmgv+1+yw1;
858dx = (int) ( (float)XSize()/zm-1. );
859dy = (int) ( (float)YSize()/zm-1. );
860
861gvw->DeleteDrawers();
862gvdrw->ElDelAll();
863gvdrw->SetLimits(xw1, xw2, yw1, yw2, kAxeDirLtoR, kAxeDirUpDown);
864int cmapid = cmap->Type();
865if ( (cmapid == CMAP_GREY32) || (cmapid == CMAP_GREYINV32) ||
866 (cmapid == CMAP_GREY128) || (cmapid == CMAP_GREYINV128)) gvdrw->SetColAtt(PI_Red);
867else gvdrw->SetColAtt(PI_Yellow);
868gvdrw->SetLineAtt(PI_NormalLine);
869gvdrw->ElAddRect(x,y,dx,dy);
870gvw->AddDrawer(gvdrw, xw1, yw1, xw2, yw2, false);
871gvw->SetColMap(cmap, false);
872gvw->SetPixmap(gpixm, xsgpxm, ysgpxm, true, xw1, yw1);
873gvw->SetUserData((void *)this, 0);
874gvw->SetMsg(Msg()+626);
875gvw->SetMsgParent(this);
876
877return;
878}
879
880/* --Methode-- */
881void PIImage::DrawCursor(PIGraphic* g)
882{
883int xc, yc;
884if (PosImg2W(xpav, ypav, &xc, &yc)) DrawCursor(g, -1, -1);
885else DrawCursor(g, xc, yc);
886return;
887}
888
889#define CURSHSIZE 25
890
891/* --Methode-- */
892void PIImage::DrawCursor(PIGraphic* g, int xc, int yc)
893{
894
895if (winovis) return; // $CHECK$ Reza A enlever si possible 17/6/96
896
897g->SelGOMode(PI_GOCopy);
898if ( (GetColMapId() == CMAP_GREY32) || (GetColMapId() == CMAP_GREYINV32) ||
899 (GetColMapId() == CMAP_GREY128) || (GetColMapId() == CMAP_GREYINV128) ) g->SelForeground(PI_Red);
900else g->SelForeground(PI_White);
901
902if (zoom < 3) g->SelLine(PI_NormalLine);
903else g->SelLine(PI_ThickLine);
904
905if ((xcurs>=0) && (ycurs>=0) && (g->kind() != PI_PSFileGraphics ) ) {
906 PIPixmap::Draw(g, xcurs-3, ycurs-CURSHSIZE, 6, CURSHSIZE*2);
907 PIPixmap::Draw(g, xcurs-CURSHSIZE, ycurs-3, CURSHSIZE*2, 6);
908}
909if ((xc >= 0) && (yc >= 0))
910 {
911 xcurs = xc; ycurs = yc;
912 g->DrawLine(xcurs-CURSHSIZE, ycurs, xcurs-4, ycurs);
913 g->DrawLine(xcurs+4, ycurs, xcurs+CURSHSIZE, ycurs);
914 g->DrawLine(xcurs, ycurs-CURSHSIZE, xcurs, ycurs-4);
915 g->DrawLine(xcurs, ycurs+4, xcurs, ycurs+CURSHSIZE);
916 }
917else { xcurs = ycurs = -1; }
918
919g->SelGOMode(PI_GOCopy);
920g->SelLine(PI_NormalLine);
921g->SelForeground(PI_White);
922return;
923}
924
925
926/* --Methode-- */
927void PIImage::DrawInfo(PIGraphic* g, char* txt)
928{
929g->SelFont(PI_NormalSizeFont, PI_RomanFont);
930if (txt) {
931 PIColors fgc = g->GetForeground();
932 PIGOMode gm = g->GetGOMode();
933 g->SelGOMode(PI_GOCopy);
934 g->SelForeground(PI_White);
935 g->SelBackground(PI_Black);
936 g->DrawOpaqueString(20, YSize()-5, txt);
937 g->SelGOMode(gm);
938 g->SelForeground(fgc);
939 }
940else {
941 int a,d,h;
942 h = g->GetFontHeight(a, d);
943 if (g->kind() != PI_PSFileGraphics ) PIPixmap::Draw(g, 0, YSize()-10-h, XSize(), h+10);
944 }
945return;
946}
947
948/* --Methode-- */
949void PIImage::ShowTrTxW()
950{
951if (trtw)
952 {
953 int tpx, tpy;
954 GetScreenPos(tpx, tpy);
955 tpy -= (trtw->YSize()+5);
956 if (tpy < 0) tpy = 0;
957 trtw->SetPos(tpx, tpy);
958 trtw->Show();
959 }
960
961return;
962}
963
964/* --Methode-- */
965int PIImage::PosW2Img(int xiw, int yiw, int * xp, int * yp)
966{
967if (!img) { *xp = *yp = 0; return(1); }
968xiw -= ofx; yiw -= ofy; // Offset d'affichage du pixmap
969if (zoom > 0)
970 {
971 *xp = xiw/zoom+offx;
972 *yp = yiw/zoom+offy;
973 }
974else
975 {
976 *xp = offx-xiw*zoom;
977 *yp = offy-yiw*zoom;
978 }
979
980if ( (*xp >= 0) && (*xp < img->XSize() ) &&
981 (*yp >= 0) && (*yp < img->YSize() ) ) return(0);
982else return(1);
983}
984
985
986/* --Methode-- */
987int PIImage::PosImg2W(int xp, int yp, int * xiw, int * yiw)
988{
989if (!img) { *xiw = *yiw = -1; return(1); }
990if (zoom > 0)
991 {
992 *xiw = (xp-offx)*zoom+(zoom/2);
993 *yiw = (yp-offy)*zoom+(zoom/2);
994 }
995else
996 {
997 *xiw = (offx-xp)/zoom;
998 *yiw = (offy-yp)/zoom;
999 }
1000
1001*xiw += ofx; *yiw += ofy; // Offset d'affichage du pixmap
1002if (*xiw > XSize()) *xiw = -1;
1003if (*yiw > YSize()) *yiw = -1;
1004
1005if ((*xiw < 0) || (*yiw < 0)) return(1);
1006else return(0);
1007}
1008
1009
1010/* --Methode-- */
1011void PIImage::SetOffsetFromPave()
1012{
1013if (!img) { offx = offy = 0; return; }
1014if (zoom > 0)
1015 {
1016 offx = xpav-XSize()/2/zoom;
1017 offy = ypav-YSize()/2/zoom;
1018 }
1019else
1020 {
1021 offx = xpav+XSize()/2*zoom;
1022 offy = ypav+YSize()/2*zoom;
1023 }
1024
1025if (offx < 0) offx = 0;
1026if (offx >= (img->XSize()-1)) offx = img->XSize()-2;
1027if (offy < 0) offy = 0;
1028if (offy >= (img->YSize()-1)) offy = img->YSize()-2;
1029
1030return;
1031}
1032
1033/* --Methode-- */
1034void PIImage::CenterPave()
1035{
1036int xwsz, ywsz;
1037
1038if (zoom > 0)
1039 { xwsz = XSize()/zoom;
1040 ywsz = YSize()/zoom; }
1041else
1042 { xwsz = -(XSize()*zoom);
1043 ywsz = -(YSize()*zoom); }
1044
1045if (img) {
1046 if (xwsz > (img->XSize()-offx)) xwsz = (img->XSize()-offx);
1047 if (ywsz > (img->YSize()-offy)) ywsz = (img->YSize()-offy);
1048 }
1049xpav = offx+xwsz/2;
1050ypav = offx+ywsz/2;
1051xszpav = ((xwsz+ywsz)/20) ;
1052if (xszpav < 1) xszpav = 1;
1053yszpav = xszpav;
1054
1055return;
1056}
Note: See TracBrowser for help on using the repository browser.