Changeset 1631 in Sophya
- Timestamp:
- Aug 8, 2001, 6:51:43 PM (24 years ago)
- Location:
- trunk/SophyaPI/PI
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PI/pidrawer.cc
r1618 r1631 616 616 617 617 /* --Methode-Static-- */ 618 int PIDrawer::BonFormatAxes(double xmin,double xmax,double dx,string& format )618 int PIDrawer::BonFormatAxes(double xmin,double xmax,double dx,string& format, int add_digit) 619 619 // Calcul format optimal pour ecrire les axes 620 // double = 17 digits : +d.(16digits)e+ddd -> e25.18 est large! 620 // double = 17 digits : +d.(17digits)e+ddd -> min 25%17e -> securite 26%18e 621 // ** add_digit nombre de digit a ajouter au nombre de digit minimum. 621 622 { 622 623 format = "%-6g"; // format par default … … 659 660 ndig -= 2; // +1 - 3 (car par ex:"+9.") 660 661 662 // on ajoute des digits au cas ou on veut plus que le minimum requis 663 ndig += add_digit; 664 661 665 // Si peu de digits on reste avec le format par defaut 662 666 // Attention: %6g arrondi le 6ieme digit -> ndig<5 ! 663 667 if(ndig<6) return ndig; 664 668 669 // Calcule du nombre nn devant le format %nn.ddde 670 // +a.<---ddd--->e+123 671 // nndig = ddd + 8 672 int nndig = ndig + 8; if(nndig<=0) nndig = 26; 673 665 674 // On evite d'ecrire d.ddde+00 -> format %f 666 675 if( (xmin>=1. && xmin<10. && xmax>=1. && xmax<10.) 667 676 || (xmin>-10. && xmin<=-1. && xmax>-10. && xmax<=-1.) ) { 668 sprintf(str,"%%- 26.%df",ndig);677 sprintf(str,"%%-%d.%df",nndig,ndig); 669 678 } else { 670 sprintf(str,"%%- 26.%de",ndig);679 sprintf(str,"%%-%d.%de",nndig,ndig); 671 680 } 672 681 format = str; -
trunk/SophyaPI/PI/pidrawer.h
r1618 r1631 94 94 static void BestTicks(double rmin,double rmax,int nticks,double& majt); 95 95 // Calcul du format optimal pour les axes 96 static int BonFormatAxes(double xmin,double xmax,double dx,string& format );96 static int BonFormatAxes(double xmin,double xmax,double dx,string& format, int add_digit=0); 97 97 98 98 // Les objets/methodes suivants devraient etre protected -
trunk/SophyaPI/PI/piscdrawwdg.cc
r1589 r1631 77 77 mPPos[0] = mPPos[1] = 0.; 78 78 mPSz[0] = mPSz[1] = 0.; 79 mFormatOpt[0] = "%-g"; mFormatOpt[1] = "%-g"; 79 80 80 81 mBDrw = new PIElDrawer; … … 173 174 yMaxS = ymax; 174 175 } 176 mFormatOpt[0] = SetFormatOpt(xmin,xmax); 177 mFormatOpt[1] = SetFormatOpt(ymin,ymax); 175 178 } 176 179 … … 229 232 { 230 233 char buff[128]; 231 sprintf(buff, "X= %g Y= %g", x, y); 232 // sprintf(buff, "%.3f,%.3f ", x, y); 234 string format = "X= "; format += mFormatOpt[0].c_str(); 235 format += " Y= "; format += mFormatOpt[1].c_str(); 236 sprintf(buff,format.c_str(),x,y); 233 237 return((string)buff); 234 238 } … … 296 300 PIScDrawWdg::But1Press(int x, int y) 297 301 { 302 int pos = (x>XSize()/2) ? PI_HorizontalRight: PI_HorizontalLeft; 298 303 UpdateText(x, y); 299 304 if (mTrW) … … 316 321 mWGrC->DrawLine(0, y, XSize(), y); 317 322 mCPosX = x; mCPosY = y; 318 char buff[64]; 319 sprintf(buff,"%g , %g", mPPos[0], mPPos[1]); 323 char buff[128]; 324 string format1 = "X= "; format1 += mFormatOpt[0].c_str(); 325 string format2 = "Y= "; format2 += mFormatOpt[1].c_str(); 326 sprintf(buff,format1.c_str(), mPPos[0], pos); 320 327 mWGrC->DrawString(x+10, y-10, buff); 328 sprintf(buff,format2.c_str(), mPPos[1], pos); 329 mWGrC->DrawString(x+10, y+20, buff); 321 330 } 322 331 else SelPointerShape(PI_CrossPointer); … … 330 339 PIScDrawWdg::Ptr1Move(int x, int y) 331 340 { 332 char buff[64]; 341 int pos = (x>XSize()/2) ? PI_HorizontalRight: PI_HorizontalLeft; 342 char buff[128]; 343 string format1 = "X= "; format1 += mFormatOpt[0].c_str(); 344 string format2 = "Y= "; format2 += mFormatOpt[1].c_str(); 333 345 if (mFgReticule) { // On trace une reticule 334 346 mWGrC->DrawLine(mCPosX, 0, mCPosX, YSize()); 335 347 mWGrC->DrawLine(0, mCPosY, XSize(), mCPosY); 336 sprintf(buff,"%g , %g", mPPos[0], mPPos[1]); 337 mWGrC->DrawString(mCPosX+10, mCPosY-10, buff); 348 sprintf(buff,format1.c_str(), mPPos[0]); 349 mWGrC->DrawString(mCPosX+10, mCPosY-10, buff, pos); 350 sprintf(buff,format2.c_str(), mPPos[1]); 351 mWGrC->DrawString(mCPosX+10, mCPosY+20, buff, pos); 338 352 mWGrC->DrawLine(x, 0, x, YSize()); 339 353 mWGrC->DrawLine(0, y, XSize(), y); … … 342 356 UpdateText(x, y); // Met a jour mPPos 343 357 if (mFgReticule) { 344 sprintf(buff,"%g , %g", mPPos[0], mPPos[1]); 345 mWGrC->DrawString(x+10, y-10, buff); 358 sprintf(buff,format1.c_str(), mPPos[0]); 359 mWGrC->DrawString(mCPosX+10, mCPosY-10, buff, pos); 360 sprintf(buff,format2.c_str(), mPPos[1]); 361 mWGrC->DrawString(mCPosX+10, mCPosY+20, buff, pos); 346 362 } 347 363 } … … 350 366 PIScDrawWdg::But1Release(int x, int y) 351 367 { 368 int pos = (x>XSize()/2) ? PI_HorizontalRight: PI_HorizontalLeft; 352 369 UpdateText(x, y); 353 370 if (mFgReticule) { // On efface la reticule 354 371 mWGrC->DrawLine(mCPosX, 0, mCPosX, YSize()); 355 372 mWGrC->DrawLine(0, mCPosY, XSize(), mCPosY); 356 char buff[64]; 357 sprintf(buff,"%g , %g", mPPos[0], mPPos[1]); 358 mWGrC->DrawString(mCPosX+10, mCPosY-10, buff); 373 char buff[128]; 374 string format1 = "X= "; format1 += mFormatOpt[0].c_str(); 375 string format2 = "Y= "; format2 += mFormatOpt[1].c_str(); 376 sprintf(buff,format1.c_str(), mPPos[0]); 377 mWGrC->DrawString(mCPosX+10, mCPosY-10, buff, pos); 378 sprintf(buff,format2.c_str(), mPPos[1]); 379 mWGrC->DrawString(mCPosX+10, mCPosY+20, buff, pos); 359 380 mWGrC->SelForeground(cForCol); 360 381 mWGrC->SelGOMode(cGOmod); … … 502 523 } 503 524 525 string 526 PIScDrawWdg::SetFormatOpt(double xmin,double xmax) 527 { 528 string format = "%-g"; 529 //PIDrawer::BonFormatAxes(xmin,xmax,(xmax-xmin)*0.9999,format,2); 530 double xm = (fabs(xmax)>fabs(xmin)) ? fabs(xmax): fabs(xmin); 531 double dx = fabs(xmax-xmin)/500.; 532 PIDrawer::BonFormatAxes(xm,xm+dx,dx*0.9999,format,0); 533 return format; 534 } 504 535 505 536 // -------------------------------------------------------------------------- -
trunk/SophyaPI/PI/piscdrawwdg.h
r505 r1631 67 67 // concernant le petit pave autour de la pos. courante 68 68 69 void SetTextWin(PILabel * tw, bool trw=true, int tx= 300, int ty=30);69 void SetTextWin(PILabel * tw, bool trw=true, int tx=500, int ty=30); 70 70 71 71 virtual void But1Press(int x, int y); … … 83 83 virtual void Keyboard(int key, PIKeyModifier kmod); 84 84 virtual void PasteSelection(unsigned int typ, void *pdata, unsigned int l); 85 86 static string SetFormatOpt(double xmin,double xmax); 85 87 86 88 protected: 87 89 double xMinS, xMaxS, yMinS, yMaxS; // Sauvegarde pour zoom 88 double mPPos[2]; // Position courante (user coordinates) 89 double mPSz[2]; // Taille courant du pave info 90 int mCPosX, mCPosY; // Position click souris X,Y 91 bool mFgReticule; // Controle l'affiche d'une réticule (Bouton-1) 90 double mPPos[2]; // Position courante (user coordinates) 91 double mPSz[2]; // Taille courant du pave info 92 int mCPosX, mCPosY; // Position click souris X,Y 93 bool mFgReticule; // Controle l'affiche d'une réticule (Bouton-1) 94 string mFormatOpt[2]; // Format optimal d'impression des textes 92 95 93 96 PIElDrawer* mBDrw; … … 106 109 PIWindow * mInfoW; 107 110 PIText * mInfoTxt; 108 109 111 110 112 private:
Note:
See TracChangeset
for help on using the changeset viewer.