PSQt/src/WdgGeo.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------
00002 // File and Version Information:
00003 //   $Id: WdgGeo.cpp 11039 2015-12-01 01:18:58Z dubrovin@SLAC.STANFORD.EDU $
00004 //
00005 // Author: Mikhail S. Dubrovin
00006 //---------------------------------------------------------------------
00007 
00008 //--------------------------
00009 
00010 #include "PSQt/WdgGeo.h"
00011 #include "PSQt/Logger.h"
00012 #include "AppUtils/AppDataPath.h"
00013 
00014 
00015 #include <iostream>  // std::cout
00016 #include <sstream>   // std::stringstream
00017 
00018 #include <QIntValidator>
00019 
00020 //using namespace std; // for cout without std::
00021 
00022 namespace PSQt {
00023 
00024 //--------------------------
00025 
00026 WdgGeo::WdgGeo( QWidget *parent, shpGO geo, const unsigned& pbits )
00027     : Frame(parent)
00028     , m_geo(geo)
00029     , m_pbits(pbits)
00030 {
00031   m_lab_geo    = new QLabel();
00032   m_lab_par    = new QLabel();
00033 
00034   AppUtils::AppDataPath adp_icon_add("PSQt/icons/list-add.png");
00035   AppUtils::AppDataPath adp_icon_sub("PSQt/icons/list-remove.png");
00036 
00037   m_but_add    = new QPushButton(); // "Add");
00038   m_but_sub    = new QPushButton(); // "Sub");
00039   m_but_add -> setIcon(QIcon(QString(adp_icon_add.path().c_str())));
00040   m_but_sub -> setIcon(QIcon(QString(adp_icon_sub.path().c_str())));
00041 
00042   m_but_gr     = new QButtonGroup();
00043   m_but_gr -> addButton(m_but_add);
00044   m_but_gr -> addButton(m_but_sub);
00045 
00046   m_edi_step   = new QLineEdit("100");
00047 
00048   m_edi_x0     = new QLineEdit();
00049   m_edi_y0     = new QLineEdit();
00050   m_edi_z0     = new QLineEdit();
00051   m_edi_rot_x  = new QLineEdit();
00052   m_edi_rot_y  = new QLineEdit();
00053   m_edi_rot_z  = new QLineEdit();
00054   m_edi_tilt_x = new QLineEdit();
00055   m_edi_tilt_y = new QLineEdit();
00056   m_edi_tilt_z = new QLineEdit();
00057 
00058   m_rad_x0     = new QRadioButton("x0:");
00059   m_rad_y0     = new QRadioButton("y0:");
00060   m_rad_z0     = new QRadioButton("z0:");
00061   m_rad_rot_x  = new QRadioButton("rot x:");
00062   m_rad_rot_y  = new QRadioButton("rot y:");
00063   m_rad_rot_z  = new QRadioButton("rot z:");
00064   m_rad_tilt_x = new QRadioButton("tilt x:");
00065   m_rad_tilt_y = new QRadioButton("tilt y:");
00066   m_rad_tilt_z = new QRadioButton("tilt z:");
00067 
00068   map_radio_to_edit[m_rad_x0    ] = m_edi_x0    ;
00069   map_radio_to_edit[m_rad_y0    ] = m_edi_y0    ;
00070   map_radio_to_edit[m_rad_z0    ] = m_edi_z0    ;
00071   map_radio_to_edit[m_rad_rot_x ] = m_edi_rot_x ;
00072   map_radio_to_edit[m_rad_rot_y ] = m_edi_rot_y ;
00073   map_radio_to_edit[m_rad_rot_z ] = m_edi_rot_z ;
00074   map_radio_to_edit[m_rad_tilt_x] = m_edi_tilt_x;
00075   map_radio_to_edit[m_rad_tilt_y] = m_edi_tilt_y;
00076   map_radio_to_edit[m_rad_tilt_z] = m_edi_tilt_z;
00077 
00078   m_rad_gr = new QButtonGroup();
00079 
00080   m_rad_gr->addButton(m_rad_x0);
00081   m_rad_gr->addButton(m_rad_y0);
00082   m_rad_gr->addButton(m_rad_z0);                                  
00083   m_rad_gr->addButton(m_rad_rot_x);
00084   m_rad_gr->addButton(m_rad_rot_y);
00085   m_rad_gr->addButton(m_rad_rot_z);                               
00086   m_rad_gr->addButton(m_rad_tilt_x);
00087   m_rad_gr->addButton(m_rad_tilt_y);
00088   m_rad_gr->addButton(m_rad_tilt_z);
00089 
00090   m_grid = new QGridLayout();
00091   m_grid -> addWidget(m_rad_x0,     0, 0);
00092   m_grid -> addWidget(m_rad_y0,     1, 0);
00093   m_grid -> addWidget(m_rad_z0,     2, 0);
00094   m_grid -> addWidget(m_rad_rot_x,  3, 0);
00095   m_grid -> addWidget(m_rad_rot_y,  4, 0);
00096   m_grid -> addWidget(m_rad_rot_z,  5, 0);                                
00097   m_grid -> addWidget(m_rad_tilt_x, 6, 0);
00098   m_grid -> addWidget(m_rad_tilt_y, 7, 0);
00099   m_grid -> addWidget(m_rad_tilt_z, 8, 0);
00100   
00101   m_grid -> addWidget(m_edi_x0,     0, 2);
00102   m_grid -> addWidget(m_edi_y0,     1, 2);
00103   m_grid -> addWidget(m_edi_z0,     2, 2);
00104   m_grid -> addWidget(m_edi_rot_x,  3, 2);
00105   m_grid -> addWidget(m_edi_rot_y,  4, 2);
00106   m_grid -> addWidget(m_edi_rot_z,  5, 2);                                
00107   m_grid -> addWidget(m_edi_tilt_x, 6, 2);
00108   m_grid -> addWidget(m_edi_tilt_y, 7, 2);
00109   m_grid -> addWidget(m_edi_tilt_z, 8, 2);
00110   
00111   m_cbox = new QHBoxLayout;
00112   m_cbox -> addStretch(1);
00113   m_cbox -> addWidget(m_but_sub);
00114   m_cbox -> addWidget(m_edi_step);
00115   m_cbox -> addWidget(m_but_add);
00116   m_cbox -> addStretch(1);
00117 
00118   m_box = new QVBoxLayout;
00119   m_box -> addWidget(m_lab_geo);
00120   m_box -> addWidget(m_lab_par);
00121   m_box -> addLayout(m_grid);
00122   m_box -> addLayout(m_cbox);
00123 
00124   this -> setLayout(m_box);
00125 
00126   this -> showTips();
00127   this -> setStyle();
00128   this -> updateGeoPars();
00129 
00130   //connect(m_rad_x0,  SIGNAL( clicked() ), this, SLOT( onRadioX()) );
00131   //connect(m_but_add, SIGNAL( clicked() ), this, SLOT(onButAddSub()) );
00132   connect(m_rad_gr, SIGNAL(buttonClicked(int)), this, SLOT(onRadioGroup()));
00133   connect(m_but_gr, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onButAddSub(QAbstractButton*)));
00134   connect(this, SIGNAL(geoIsChanged(shpGO&)), this, SLOT(testSignalGeoIsChanged(shpGO&)));
00135   connect(m_edi_step, SIGNAL(editingFinished()),  this, SLOT(onEdiStep())); 
00136 
00137   m_rad_x0->setChecked(true);
00138   this -> onRadioGroup();
00139   //this -> move(300,50);
00140 }
00141 
00142 //--------------------------
00143 
00144 void
00145 WdgGeo::showTips() 
00146 {
00147   std::string orig(" coordinate [um] of the object origin in parent frame");
00148   std::string rot (" axis rotation [degree] of the object in parent frame");
00149   std::string tilt(" axis tilt angle [degree] of the object in parent frame");
00150 
00151   m_rad_x0     -> setToolTip((std::string("x")+orig).c_str());
00152   m_rad_y0     -> setToolTip((std::string("y")+orig).c_str());     
00153   m_rad_z0     -> setToolTip((std::string("z")+orig).c_str());     
00154   m_rad_rot_x  -> setToolTip((std::string("x")+rot) .c_str());  
00155   m_rad_rot_y  -> setToolTip((std::string("y")+rot) .c_str()); 
00156   m_rad_rot_z  -> setToolTip((std::string("z")+rot) .c_str()); 
00157   m_rad_tilt_x -> setToolTip((std::string("x")+tilt).c_str()); 
00158   m_rad_tilt_y -> setToolTip((std::string("y")+tilt).c_str());  
00159   m_rad_tilt_z -> setToolTip((std::string("z")+tilt).c_str());  
00160 }
00161 
00162 //--------------------------
00163 
00164 void
00165 WdgGeo::setStyle() 
00166 {
00167   //this -> setWindowTitle(tr("WdgGeo"));
00168   //this -> setMinimumWidth(700);
00169   //this -> setFixedHeight(50);
00170   //this -> setFixedHeight( (m_show_frame)? 50 : 34);
00171 
00172   //if (! m_show_frame) this -> setContentsMargins(-9,-9,-9,-9);
00173 
00174   //this -> setContentsMargins(-9,-9,-9,-9);
00175   //this -> setContentsMargins(-5,-5,-5,-5);
00176 
00177   this -> setFixedWidth(220);
00178 
00179   unsigned width = 70;
00180   m_edi_x0    -> setFixedWidth(width);
00181   m_edi_y0    -> setFixedWidth(width);
00182   m_edi_z0    -> setFixedWidth(width);
00183   m_edi_rot_x -> setFixedWidth(width);
00184   m_edi_rot_y -> setFixedWidth(width);
00185   m_edi_rot_z -> setFixedWidth(width);
00186   m_edi_tilt_x-> setFixedWidth(width);
00187   m_edi_tilt_y-> setFixedWidth(width);
00188   m_edi_tilt_z-> setFixedWidth(width);
00189 
00190   m_edi_step  -> setFixedWidth(width);
00191   m_but_add   -> setFixedWidth(35);
00192   m_but_sub   -> setFixedWidth(35);
00193 
00194   m_edi_x0    -> setReadOnly(true);
00195   m_edi_y0    -> setReadOnly(true);
00196   m_edi_z0    -> setReadOnly(true);
00197   m_edi_rot_x -> setReadOnly(true);
00198   m_edi_rot_y -> setReadOnly(true);
00199   m_edi_rot_z -> setReadOnly(true);
00200   m_edi_tilt_x-> setReadOnly(true);
00201   m_edi_tilt_y-> setReadOnly(true);
00202   m_edi_tilt_z-> setReadOnly(true);
00203 }
00204 
00205 //--------------------------
00206 
00207 void 
00208 WdgGeo::resizeEvent(QResizeEvent *event)
00209 {
00210   stringstream ss; ss << "w:" << event->size().width() << " h:" <<  event->size().height();
00211   setWindowTitle(ss.str().c_str());
00212 }
00213 
00214 //--------------------------
00215 
00216 void
00217 WdgGeo::moveEvent(QMoveEvent *event)
00218 {
00219   stringstream ss; ss << "x:" << event->pos().x() << " y:" << event->pos().y();
00220   setWindowTitle(ss.str().c_str());
00221 }
00222 
00223 //--------------------------
00224 
00225 void 
00226 WdgGeo::closeEvent(QCloseEvent *event)
00227 {
00228   QWidget::closeEvent(event);
00229   stringstream ss; ss << "WdgGeo::closeEvent(...): type = " << event -> type();
00230   MsgInLog(_name_(), INFO, ss.str()); 
00231 }
00232 
00233 //--------------------------
00234 //--------------------------
00235 //--------------------------
00236 //--------------------------
00237 //--------------------------
00238 void 
00239 WdgGeo::onEdiStep()
00240 {
00241   MsgInLog(_name_(), INFO, "Step value is changed to " + (m_edi_step->displayText()).toStdString());
00242 }
00243 
00244 //--------------------------
00245 
00246 void
00247 WdgGeo::onRadioGroup()
00248 {
00249   QRadioButton* but = (QRadioButton*) m_rad_gr->checkedButton();
00250 
00251   //std::cout << "onRadioGroup:  checked radio button:" << (but->text()).toStdString();
00252   //std::cout << " mapped edit field:" << (map_radio_to_edit[but]->text()).toStdString() << '\n';  
00253 
00254   stringstream ss; ss << "Selected parameter " << (but->text()).toStdString() 
00255                       << " value=" << (map_radio_to_edit[but]->text()).toStdString();
00256   MsgInLog(_name_(), INFO, ss.str()); 
00257 
00258   if(but == m_rad_x0
00259   || but == m_rad_y0
00260   || but == m_rad_z0) {
00261       m_edi_step -> setText("100");
00262       m_edi_step -> setValidator(new QIntValidator(0,1000000,this));
00263   }
00264 
00265   if(but == m_rad_rot_x
00266   || but == m_rad_rot_y
00267   || but == m_rad_rot_z) {
00268       m_edi_step -> setText("90");
00269       m_edi_step -> setValidator(new QIntValidator(0,360,this));
00270   }
00271 
00272   if(but == m_rad_tilt_x
00273   || but == m_rad_tilt_y
00274   || but == m_rad_tilt_z) {
00275       m_edi_step -> setText("0.15");
00276       m_edi_step -> setValidator(new QDoubleValidator(0,10000,3,this));
00277   }
00278 }
00279 
00280 //--------------------------
00281 
00282 void
00283 WdgGeo::onButAddSub(QAbstractButton* button)
00284 {
00285   QPushButton*  but       = (QPushButton*) button;
00286   QRadioButton* but_radio = (QRadioButton*) m_rad_gr->checkedButton();
00287   QLineEdit* edi = map_radio_to_edit[but_radio];
00288 
00289   double dval = (m_edi_step->text()).toDouble();
00290   if (but == m_but_sub) dval = -dval;
00291 
00292   double val = (edi->text()).toDouble();
00293   
00294   //std::cout << "onButAddSub add/sub " << dval << " to the value " << val << '\n';
00295 
00296   val += dval;
00297 
00298   stringstream ss;
00299   if(but_radio == m_rad_tilt_x
00300   || but_radio == m_rad_tilt_y
00301   || but_radio == m_rad_tilt_z) ss << fixed << std::setprecision(3) << val;
00302   else                          ss << fixed << std::setprecision(0) << val;
00303 
00304   edi->setText(ss.str().c_str());
00305 
00306   stringstream smsg; smsg << "Value of \"" << (but_radio->text()).toStdString() << "\" is changed to " << val << " -> set geo, emit signal: geoIsChanged(m_geo)";
00307   MsgInLog(_name_(), INFO, smsg.str()); 
00308 
00309   this -> setGeoPars();
00310   //std::cout << "Do something here\n";
00311 }
00312 
00313 //--------------------------
00314 
00315 void
00316 WdgGeo::setGeoPars()
00317 {
00318   const double x0     = (m_edi_x0    ->text()).toDouble();
00319   const double y0     = (m_edi_y0    ->text()).toDouble();
00320   const double z0     = (m_edi_z0    ->text()).toDouble();
00321   const double rot_x  = (m_edi_rot_x ->text()).toDouble();
00322   const double rot_y  = (m_edi_rot_y ->text()).toDouble();
00323   const double rot_z  = (m_edi_rot_z ->text()).toDouble();
00324   const double tilt_x = (m_edi_tilt_x->text()).toDouble();
00325   const double tilt_y = (m_edi_tilt_y->text()).toDouble();
00326   const double tilt_z = (m_edi_tilt_z->text()).toDouble();
00327 
00328   m_geo->set_geo_pars(x0, y0, z0, rot_z, rot_y, rot_x, tilt_z, tilt_y, tilt_x);
00329   //m_geo->print_geo();
00330   
00331   MsgInLog(_name_(), DEBUG, "Emit signal with changed geo"); 
00332   emit geoIsChanged(m_geo);
00333 }
00334 
00335 //--------------------------
00336 
00337 void
00338 WdgGeo::updateGeoPars()
00339 {
00340   MsgInLog(_name_(), DEBUG, "updateGeoPars() for " + m_geo->get_geo_name());   
00341 
00342   if(m_geo->get_parent_name().empty()) {
00343     MsgInLog(_name_(), WARNING, "This is a top hierarchical geometry object."
00344              + std::string(" TOP COORDINATE FRAME PARAMETERS ARE NOT EDITABLE!"));
00345     m_but_add->setEnabled(false);
00346     m_but_sub->setEnabled(false);
00347   }
00348   else {
00349     m_but_add->setEnabled(true);
00350     m_but_sub->setEnabled(true);
00351   }
00352 
00353   double x, y, z, rot_z, rot_y, rot_x, tilt_z, tilt_y, tilt_x;     
00354   m_geo->get_geo_pars(x, y, z, rot_z, rot_y, rot_x, tilt_z, tilt_y, tilt_x);
00355 
00356   stringstream ss_geo, ss_par; 
00357   ss_geo << "Object: " << m_geo->get_geo_name()    << "." << m_geo->get_geo_index();
00358   ss_par << "Parent: " << m_geo->get_parent_name() << "." << m_geo->get_parent_index();
00359 
00360   //m_geo->print_geo();
00361   //std::string str = m_geo->string_geo();
00362   //std::cout << "string_geo(): " << str << '\n';
00363 
00364   stringstream ss_x0    ; ss_x0     << fixed << std::setprecision(0) << x;
00365   stringstream ss_y0    ; ss_y0     << fixed << std::setprecision(0) << y;
00366   stringstream ss_z0    ; ss_z0     << fixed << std::setprecision(0) << z;
00367   stringstream ss_rot_x ; ss_rot_x  << fixed << std::setprecision(0) << rot_x;
00368   stringstream ss_rot_y ; ss_rot_y  << fixed << std::setprecision(0) << rot_y;
00369   stringstream ss_rot_z ; ss_rot_z  << fixed << std::setprecision(0) << rot_z;
00370   stringstream ss_tilt_x; ss_tilt_x << fixed << std::setprecision(3) << tilt_x;
00371   stringstream ss_tilt_y; ss_tilt_y << fixed << std::setprecision(3) << tilt_y;
00372   stringstream ss_tilt_z; ss_tilt_z << fixed << std::setprecision(3) << tilt_z;
00373 
00374   m_lab_geo   ->setText(ss_geo.str().c_str());
00375   m_lab_par   ->setText(ss_par.str().c_str());
00376 
00377   m_edi_x0    ->setText(ss_x0    .str().c_str());
00378   m_edi_y0    ->setText(ss_y0    .str().c_str());
00379   m_edi_z0    ->setText(ss_z0    .str().c_str());
00380   m_edi_rot_x ->setText(ss_rot_x .str().c_str());
00381   m_edi_rot_y ->setText(ss_rot_y .str().c_str());
00382   m_edi_rot_z ->setText(ss_rot_z .str().c_str());
00383   m_edi_tilt_x->setText(ss_tilt_x.str().c_str());
00384   m_edi_tilt_y->setText(ss_tilt_y.str().c_str());
00385   m_edi_tilt_z->setText(ss_tilt_z.str().c_str());
00386 }
00387 
00388 //--------------------------
00389 
00390 void
00391 WdgGeo::setNewGO(shpGO& geo)
00392 {
00393   m_geo = geo;
00394   this -> updateGeoPars();
00395 }
00396 
00397 //--------------------------
00398 //--------------------------
00399 //--------------------------
00400 //--------------------------
00401 
00402 void 
00403 WdgGeo::testSignalGeoIsChanged(shpGO& geo)
00404 {
00405   //std::cout << "testSignalGeoIsChanged():\n";
00406   //geo->print_geo();
00407   //m_geo->print_geo();
00408   MsgInLog(_name_(), DEBUG, "testSignalGeoIsChanged(): " + geo->str_data()); // string_geo()); 
00409 }
00410 
00411 //--------------------------
00412 //--------------------------
00413 //--------------------------
00414 
00415 } // namespace PSQt
00416 
00417 //--------------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7