Changeset 2503 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Mar 9, 2004, 7:21:48 PM (22 years ago)
Author:
ansari
Message:

1) Ajout methodes PIDrawer::OptionToString(()
PIGraphicAtt::AttToStrings(() et PIWdgGen::OptionToString() pour
transformer les options graphiques en chaine (texte)
2) Prise en charge de OptionToString() ds PIDrwOptionStringWindow.
3) Ajout methodes PIDrawer::GetDistanceToPoint() et

PIBaseWdgGen::FindNearestDrawerId() afin de permettre la selection

des drawers avec la souris.

Reza 09 Mars 2003

Location:
trunk/SophyaPI/PI
Files:
14 edited

Legend:

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

    r2301 r2503  
    502502// PIDrawer*  GetActiveDrawer()
    503503//      Retourne le pointeur sur le traceur actif (NULL si pas de traceur actif).
     504// int   FindNearestDrawerId(int x, int y)
     505//      Retourne le numéro du traceur le plus proche au point "(x,y)" de l'objet PIBaseWdg.
     506//      -1 si pas de traceur.
    504507//--
    505508
     
    540543  if (mActDrwId < 0) return(NULL);
    541544  else return(GetDrawerId(mActDrwId));
     545}
     546
     547/* --Methode-- */
     548int PIBaseWdgGen::FindNearestDrawerId(int xp, int yp)
     549{
     550  if (mDrwList.size() < 1)  return -1;
     551  double xmin,ymin, xmax, ymax;
     552  int drx0, dry0, drdx, drdy;
     553  int ddrx0, ddry0, ddrdx, ddrdy;
     554
     555  if (mDrElastic) {
     556    ddrx0 = (int)((double) mDrX1 * (double)XSize());
     557    ddry0 = (int)((double) mDrY1 * (double)YSize());
     558    ddrdx = (int)((double) mDrX2 * (double)XSize()) - ddrx0 ;
     559    ddrdy = (int)((double) mDrY2 * (double)YSize()) - ddry0 ;
     560  }
     561  else {
     562    ddrx0 = (int)mDrX1;   ddry0 = (int)mDrY1; 
     563    ddrdx = (int)mDrX2-ddrx0;   ddrdy = (int)mDrY2-ddry0; 
     564  }
     565 
     566  int nid = -1;
     567  double neardist = 9.e39;
     568  bool fgido = false;
     569 
     570  vector<BWDrwId>::iterator it;
     571  for(it = mDrwList.begin(); it != mDrwList.end(); it++) {
     572    if ( (*it).autoszp )   // Taille/position  par defaut impose par PIBaseWdg
     573      { drx0 = ddrx0;  dry0 = ddry0;   drdx = ddrdx;  drdy = ddrdy; }
     574    else {
     575      if ( (*it).elastic  ) {   // Taille/position defin en fraction de la taille du PIBaseWdg
     576        drx0 = (int)((double)(*it).x1 * (double)XSize());
     577        dry0 = (int)((double)(*it).y1 * (double)YSize());
     578        drdx = (int)((double)(*it).x2 * (double)XSize()) - drx0 ;
     579        drdy = (int)((double)(*it).y2 * (double)YSize()) - dry0 ;
     580      }
     581      else {
     582        drx0 = (int)(*it).x1 ;  dry0 = (int)(*it).y1 ;
     583        drdx = (int)(*it).x2-drx0 ;  drdy = (int)(*it).y2-dry0 ;
     584      }
     585    }
     586    // L'ordre des operations ici est importante
     587    if ( (*it).autolim ) {
     588      (*it).drw->SetLimits(mDrXmin, mDrXmax, mDrYmin, mDrYmax, mDXdir, mDYdir);     
     589      (*it).drw->SetLogScale(mDXlog, mDYlog);
     590    }
     591    double xu, yu;
     592    (*it).drw->WdgCoord2DrwCoord(xp, yp, xu, yu, drx0, dry0, drdx, drdy);
     593    double curd = (*it).drw->GetDistanceToPoint(xu, yu);
     594    if (!fgido || (curd < neardist)) {
     595      neardist = curd;  nid = (*it).id;  fgido = true;
     596    }
     597  }
     598return nid; 
    542599}
    543600
  • trunk/SophyaPI/PI/pibwdggen.h

    r1827 r2503  
    104104  virtual int        GetActiveDrawerId();   
    105105  virtual int        GetActiveDrawerNum();   
     106
    106107  virtual PIDrawer*  GetActiveDrawer();   
     108
     109// Recherche du plus proche Drawer
     110  virtual int        FindNearestDrawerId(int x, int y);
    107111
    108112//  Trace des Drawers ...         
  • trunk/SophyaPI/PI/pidrawer.cc

    r2394 r2503  
    374374//      L'implémentation par défaut effectue le décodage des attributs graphiques en
    375375//      utilisant la méthode *PIGraphicAtt::DecodeAttStrings()*
     376// int  OptionToString(vector<string> & opt) const
     377//      Méthode virtuelle qui peut être redéfinie dans les classes filles,
     378//      pour fournir des chaines de caracteres décodable par *DecodeOptionString()* .
     379//      Renvoie le nombre d'éléments ajoutés.
     380//      L'implémentation par défaut effectue le décodage des attributs graphiques en
     381//      utilisant la méthode *PIGraphicAtt::AttToStrings()*
    376382// void  GetOptionsHelpInfo(string& info)
    377383//      Ajoute au bout de la chaine "info" l'aide concernant le décodage des options du traceur.
     
    385391  UpdateGraphicAtt(gratt);
    386392  return(ndec);
     393}
     394
     395int
     396PIDrawer::OptionToString(vector<string> & opt) const
     397{
     398  return mGrAtt.AttToStrings(opt);
    387399}
    388400
     
    438450  xW0 = x0;   yW0 = y0;
    439451  xWd = dx;   yWd = dy;
     452  if (!limitsFixed) UpdateLimits();
    440453  if (mGrUC)  delete mGrUC;
    441454  mGrUC = new PIGraphicUC(g, x0, y0, dx, dy);
     
    452465
    453466void
     467PIDrawer::WdgCoord2DrwCoord(int x, int y, double& xu, double& yu,
     468                            int x0, int y0, int dx, int dy)
     469{
     470  if (!limitsFixed) UpdateLimits();
     471  PIGraphicUC guc(NULL, x0, y0, dx, dy);
     472  guc.SetUCS(xMin, xMax, yMin, yMax, aXFlg, aYFlg);
     473  if (aXlog || aYlog) guc.SetLogScale(aXlog, aYlog);
     474  guc.GrC2UC(x,y,xu,yu);
     475  return;
     476}
     477
     478void
    454479PIDrawer::SetAxesFlags(unsigned int flags)
    455480{
     
    496521//      rectangulaire "(xmin,ymin) -- (xmax,ymax)".
    497522//      L'implémentation par défaut ne fait rien.
     523// double  GetDistanceToPoint(double x, double y)
     524//      Fournit une distance au point "x,y". Valeur entre 0 et 1 au bord xmin/max,ymin/max. 
     525//      L'implémentation par défaut retourne la distance normalisée au point
     526//      ((xmin+xmax)/2,(ymin+ymax)/2)
    498527//--
    499528
     
    508537{
    509538}
     539
     540double
     541PIDrawer::GetDistanceToPoint(double x, double y)
     542{
     543  double xc = 0.5*(XMin()+XMax());
     544  double yc = 0.5*(YMin()+YMax());
     545  double delx = (x-xc)/(0.5*(XMax()-XMin()));
     546  double dely = (y-yc)/(0.5*(YMax()-YMin())); 
     547  return sqrt((delx*delx+dely*dely)/2.);
     548}
  • trunk/SophyaPI/PI/pidrawer.h

    r2301 r2503  
    4242  virtual void       GetClickInfo(string& info,double x,double y
    4343                                 ,double x0=0.,double y0=0.,bool fgdiff=false);
     44// Renvoie une distance au point x,y
     45// 0: au(x) point(s) le(s) plus proche(s) ... 1  au bord xmin/xmax , ymin/ymax
     46// La methode par defaut calcule la distance normalisee au point ((xmin+xmax)/2,(ymin+ymax)/2)
     47  virtual double     GetDistanceToPoint(double x, double y);
    4448
    4549  virtual void       Refresh();      // Recalcule les limites et reaffiche
     
    8387//   Methode permettant de decoder des options a partir de chaines
    8488  virtual int        DecodeOptionString(vector<string> & opt, bool rmdecopt=true);
     89//   Methode retournant un vecteur de string a partir des options
     90  virtual int        OptionToString(vector<string> & opt) const;
     91
    8592//   Texte d'aide des options disponibles
    8693  virtual void       GetOptionsHelpInfo(string& info);
     
    94101//  Pb avec acces depuis PIBaseWdgGen (Reza 11/07/97)
    95102  virtual  PIGraphicUC*  SetDrwWdg(PIBaseWdgGen* drw, int x0, int y0, int dx, int dy, PIGraphicGen* g);
     103//  Transformation coordonnees fenetre en coordonnees drawer
     104  virtual  void      WdgCoord2DrwCoord(int x, int y, double& xu, double& yu,
     105                                       int x0, int y0, int dx, int dy);
    96106
    97107//  Je declare en public a cause de cxx - Reza 11/07/97
  • trunk/SophyaPI/PI/pidrwtools.cc

    r2394 r2503  
    773773  mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    774774  mLab->SetLabel("");
    775   cpx += 2.6*bsx;
    776   mBut[0] = new PIButton(this, "SetOption", 555, bsx*1.5, bsy, cpx, cpy);
     775  cpx += 2.3*bsx;
     776  mBut[0] = new PIButton(this, "SetOption", 555, bsx*1.2, bsy, cpx, cpy);
    777777  mBut[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    778   cpx += 1.8*bsx;
    779   mBut[1] = new PIButton(this, "Dimiss", 777, bsx*1.5, bsy, cpx, cpy);
     778  cpx += 1.25*bsx;
     779  mBut[1] = new PIButton(this, "GetOption", 666, bsx*1.2, bsy, cpx, cpy);
    780780  mBut[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
     781  cpx += 1.25*bsx;
     782  mBut[2] = new PIButton(this, "Dimiss", 777, bsx*1.2, bsy, cpx, cpy);
     783  mBut[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    781784}
    782785
     
    789792  delete mBut[0];
    790793  delete mBut[1];
     794  delete mBut[2];
    791795}
    792796/* --Methode-- */
     
    842846      mDrw->Refresh();
    843847    }
     848    break;
     849  case 666:
     850    if (mDrw) {
     851      vector<string> vops;
     852      mDrw->OptionToString(vops);
     853      string ops;
     854      for(int kk=0; kk<vops.size(); kk++) {
     855        ops += vops[kk]; ops += ' ';
     856      }
     857      mTxt[1]->SetText(ops);
     858    }
     859    break;
    844860  default :
    845861    break;
  • trunk/SophyaPI/PI/pidrwtools.h

    r2387 r2503  
    7676  PIText* mTxt[2];
    7777  PILabel* mLab;
    78   PIButton* mBut[2];
     78  PIButton* mBut[3];
    7979  PIDrawer* mDrw;
    8080};
  • trunk/SophyaPI/PI/pieldrw.cc

    r2394 r2503  
    675675}
    676676
     677/* --Methode-- */
     678double  PIElDrawer::GetDistanceToPoint(double x, double y)
     679{
     680  double dist,disty,distx,d1,d2;
     681  bool fgokx, fgoky;
     682  d1 = fabs(x-XMin());
     683  d2 = fabs(x-XMax());
     684  if ((y<YMax()) && (y>YMin()))  {
     685    distx = (d1 < d2) ? d1 : d2;
     686    distx /= 0.5*(XMax()-XMin());
     687    fgokx = true;
     688  }
     689  else fgokx = false;
     690  d1 = fabs(y-YMin());
     691  d2 = fabs(y-YMax());
     692  if ((x<XMax()) && (x>XMin()))  {
     693    disty = (d1 < d2) ? d1 : d2;
     694    disty /= 0.5*(YMax()-YMin());
     695    fgoky = true;
     696  }
     697  else fgoky = false;
     698  if (!fgokx  && !fgoky)  return PIDrawer::GetDistanceToPoint(x,y);
     699  else {
     700    if (fgokx && fgoky) dist = (distx<disty) ? distx : disty;
     701    else if (fgokx) dist = distx;
     702    else dist = disty;
     703  }
     704  return dist;
     705}
  • trunk/SophyaPI/PI/pieldrw.h

    r2387 r2503  
    224224  virtual void       Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
    225225
     226// Renvoie une distance au point x,y
     227// 0: au(x) point(s) le(s) plus proche(s) ... 1  au bord xmin/xmax , ymin/ymax
     228// La methode par defaut calcule la distance normalisee au point ((xmin+xmax)/2,(ymin+ymax)/2)
     229  virtual double     GetDistanceToPoint(double x, double y);
     230
    226231  inline void        ConfigureAxeTicks(int ntickx=0, int nticky=0,
    227232                                       double majtl=0., double mintl=0.)
  • trunk/SophyaPI/PI/pigratt.cc

    r2401 r2503  
    8787//      Si "rmdecatt == true", les attributs décodés sont supprimés du
    8888//      vecteur de départ.
     89// int  AttToStrings(vector<string> & att) const
     90//      Renvoie dans "att" les attributs sous forme de string Décodeable
     91//      par *DecodeAttStrings()* . Retourne le nombre d'éléments ajoutés.
    8992// unsigned long DecodeTextPosDirAtt(vector<string> & att, bool rmdecatt=true)
    9093//      Décode les attributs de direction et de positionnement de tracé de texte
     
    654657}
    655658
     659int PIGraphicAtt::AttToStrings(vector<string> & att) const
     660{
     661  // A FAIRE - Reza->CMV  Mars 2004
     662  // On ne vide pas (ne met pas a zero) att, mais on ajoute derriere.
     663  att.push_back("A FAIRE - Reza->CMV  Mars 2004");
     664  return 1;
     665}
     666
    656667int PIGraphicAtt::DecodeTextPosDirAtt(vector<string> & att, unsigned long& tdirpos,
    657668                                   bool rmdecatt)
  • trunk/SophyaPI/PI/pigratt.h

    r2242 r2503  
    3333  virtual void   UpdateFrom(PIGraphicAtt const & att);
    3434  virtual int    DecodeAttStrings(vector<string> & att, bool rmdecatt=true);
     35  virtual int    AttToStrings(vector<string> & att) const;
    3536  // decodage des attributs de positions et direction de trace de texte
    3637  static  int    DecodeTextPosDirAtt(vector<string> & att, unsigned long& tdirpos,
  • trunk/SophyaPI/PI/piscdrawwdg.cc

    r2349 r2503  
    8080{
    8181  mFgReticule = false;
     82  mFgShiftBut = false;
    8283  mCPosX = mCPosY = 0;
    8384  mPPos[0] = mPPos[1] = 0.;
     
    408409PIScDrawWdg::But1Press(int x, int y)
    409410{
     411  PIKeyModifier kmod;
     412  unsigned long tm;
     413  GetLastEventInfo(kmod, tm);
     414  if (kmod == PIKM_Shift) {   //SetActive Drawer on Shift-Button-1
     415    mFgShiftBut = true;
     416    int nid = FindNearestDrawerId(x,y);
     417    SetActiveDrawerId(nid);
     418    PIDrawer*  actdr = GetActiveDrawer();
     419    if (actdr) {
     420      actdr->HighLight(true);
     421    }
     422    return;
     423  }
    410424  UpdateText(x, y);
    411425  if (mTrW)
     
    438452PIScDrawWdg::Ptr1Move(int x, int y)
    439453{
     454  if (mFgShiftBut) return;  //SetActive Drawer on Shift-Button-1
    440455  UpdateText(x, y);  // Met a jour mPPos
    441456  if (mFgReticule)  DrawReticule(x,y,1);
     
    445460PIScDrawWdg::But1Release(int x, int y)
    446461{
     462  if (mFgShiftBut) {  //SetActive Drawer on Shift-Button-1
     463    mFgShiftBut = false;
     464    PIDrawer*  actdr = GetActiveDrawer();
     465    if (actdr) {
     466      actdr->HighLight(false);
     467    }
     468    return;
     469  }
     470 
    447471  UpdateText(x, y);
    448472  if (mFgReticule)  DrawReticule(x,y,2);
  • trunk/SophyaPI/PI/piscdrawwdg.h

    r2349 r2503  
    101101  int mPosFDX, mPosFDY;       // Position (coord fenetre memorise)
    102102  bool mFgReticule;       // Controle l'affiche d'une réticule (Bouton-1)
     103  bool mFgShiftBut;       // true -> shift-Button
    103104  string mFormatOpt[2];   // Format optimal d'impression des textes
    104105
  • trunk/SophyaPI/PI/piwdggen.cc

    r1914 r2503  
    7979//      pour decoder des options a partir de chaines de caracteres.
    8080//      Renvoie le nombre d'options decodees.
     81// int  OptionToString(vector<string> & opt) const
     82//      Méthode virtuelle qui peut être redéfinie dans les classes filles,
     83//      pour fournir des chaines de caracteres décodable par *DecodeOptionString()* .
     84//      Renvoie le nombre d'éléments ajoutés.
    8185//--
    8286
     
    8488{
    8589  return(0);
     90}
     91int PIWdgGen::OptionToString(vector<string> & opt) const
     92{
     93  return(0);
    8694}
    8795
  • trunk/SophyaPI/PI/piwdggen.h

    r1914 r2503  
    7373  virtual int            DecodeOptionString(vector<string> & opt,
    7474                                            bool rmdecopt=true);
     75//   Remplissage de chaine decodable par DecodeOptionString() a partir des options
     76  virtual int            OptionToString(vector<string> & opt) const;
    7577
    7678//  Gestion des accrochages (binding) aux containers
Note: See TracChangeset for help on using the changeset viewer.