Changeset 1631 in Sophya for trunk


Ignore:
Timestamp:
Aug 8, 2001, 6:51:43 PM (24 years ago)
Author:
cmv
Message:

gestion du format pour l impression x=,y= avec curseur ou reticule cmv 8/8/01

Location:
trunk/SophyaPI/PI
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/pidrawer.cc

    r1618 r1631  
    616616
    617617/* --Methode-Static-- */
    618 int PIDrawer::BonFormatAxes(double xmin,double xmax,double dx,string& format)
     618int PIDrawer::BonFormatAxes(double xmin,double xmax,double dx,string& format, int add_digit)
    619619// 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.
    621622{
    622623 format = "%-6g";  // format par default
     
    659660 ndig -= 2;  // +1 - 3 (car par ex:"+9.")
    660661
     662 // on ajoute des digits au cas ou on veut plus que le minimum requis
     663 ndig += add_digit;
     664
    661665 // Si peu de digits on reste avec le format par defaut
    662666 // Attention: %6g arrondi le 6ieme digit -> ndig<5 !
    663667 if(ndig<6) return ndig;
    664668
     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
    665674 // On evite d'ecrire d.ddde+00   -> format %f
    666675 if(  (xmin>=1. && xmin<10. && xmax>=1. && xmax<10.)
    667676   || (xmin>-10. && xmin<=-1. && xmax>-10. && xmax<=-1.) ) {
    668    sprintf(str,"%%-26.%df",ndig);
     677   sprintf(str,"%%-%d.%df",nndig,ndig);
    669678 } else {
    670    sprintf(str,"%%-26.%de",ndig);
     679   sprintf(str,"%%-%d.%de",nndig,ndig);
    671680 }
    672681 format = str;
  • trunk/SophyaPI/PI/pidrawer.h

    r1618 r1631  
    9494  static void        BestTicks(double rmin,double rmax,int nticks,double& majt);
    9595//  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);
    9797
    9898//  Les objets/methodes suivants devraient etre protected     
  • trunk/SophyaPI/PI/piscdrawwdg.cc

    r1589 r1631  
    7777  mPPos[0] = mPPos[1] = 0.;
    7878  mPSz[0] = mPSz[1] = 0.;
     79  mFormatOpt[0] = "%-g"; mFormatOpt[1] = "%-g";
    7980
    8081  mBDrw = new PIElDrawer;
     
    173174    yMaxS = ymax;
    174175  }
     176  mFormatOpt[0] = SetFormatOpt(xmin,xmax);
     177  mFormatOpt[1] = SetFormatOpt(ymin,ymax);
    175178}
    176179 
     
    229232{
    230233  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);
    233237  return((string)buff);
    234238}
     
    296300PIScDrawWdg::But1Press(int x, int y)
    297301{
     302  int pos = (x>XSize()/2) ? PI_HorizontalRight: PI_HorizontalLeft;
    298303  UpdateText(x, y);
    299304  if (mTrW)
     
    316321    mWGrC->DrawLine(0, y, XSize(), y);
    317322    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);
    320327    mWGrC->DrawString(x+10, y-10, buff);
     328    sprintf(buff,format2.c_str(), mPPos[1], pos);
     329    mWGrC->DrawString(x+10, y+20, buff);
    321330    }
    322331  else SelPointerShape(PI_CrossPointer);
     
    330339PIScDrawWdg::Ptr1Move(int x, int y)
    331340{
    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();
    333345  if (mFgReticule) { // On trace une reticule
    334346    mWGrC->DrawLine(mCPosX, 0, mCPosX, YSize());
    335347    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);
    338352    mWGrC->DrawLine(x, 0, x, YSize());
    339353    mWGrC->DrawLine(0, y, XSize(), y);
     
    342356  UpdateText(x, y);  // Met a jour mPPos
    343357  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);
    346362    }
    347363}
     
    350366PIScDrawWdg::But1Release(int x, int y)
    351367{
     368  int pos = (x>XSize()/2) ? PI_HorizontalRight: PI_HorizontalLeft;
    352369  UpdateText(x, y);
    353370  if (mFgReticule) { // On efface la reticule
    354371    mWGrC->DrawLine(mCPosX, 0, mCPosX, YSize());
    355372    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);
    359380    mWGrC->SelForeground(cForCol);
    360381    mWGrC->SelGOMode(cGOmod);
     
    502523}
    503524
     525string
     526PIScDrawWdg::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}
    504535
    505536// --------------------------------------------------------------------------
  • trunk/SophyaPI/PI/piscdrawwdg.h

    r505 r1631  
    6767                                            // concernant le petit pave autour de la pos. courante
    6868
    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);
    7070
    7171  virtual void       But1Press(int x, int y);
     
    8383  virtual void       Keyboard(int key, PIKeyModifier kmod);
    8484  virtual void       PasteSelection(unsigned int typ, void *pdata, unsigned int l);
     85
     86  static  string     SetFormatOpt(double xmin,double xmax);
    8587 
    8688protected:
    8789  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
    9295
    9396  PIElDrawer* mBDrw;
     
    106109  PIWindow * mInfoW;
    107110  PIText * mInfoTxt;
    108 
    109111
    110112private:
Note: See TracChangeset for help on using the changeset viewer.