PSQt/src/GUIMain.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------
00002 // File and Version Information:
00003 //   $Id: GUIMain.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/GUIMain.h"
00011 #include "PSQt/Logger.h"
00012 #include "PSQt/QGUtils.h"
00013 #include "AppUtils/AppDataPath.h"
00014 
00015 #include <sstream>   // for stringstream
00016 #include <iostream>    // cout
00017 #include <fstream>    // ifstream(fname), ofstream
00018 
00019 //using namespace std; // for cout without std::
00020 
00021 namespace PSQt {
00022 
00023 //--------------------------
00024 
00025 GUIMain::GUIMain( QWidget *parent
00026                 , const LEVEL& level
00027                 , const std::string& gfname
00028                 , const std::string& ifname
00029                 , const unsigned& xcent
00030                 , const unsigned& ycent
00031    ): Frame(parent)
00032 //  : QWidget(parent)
00033 {
00034   MsgInLog(_name_(), INFO, "Open main control window"); 
00035   m_guilogger = new PSQt::GUILogger(this, false, false); // true/false - show/do not show buttons, frame
00036   SetMsgLevel(level); // set level and update guilogger window for privious messages
00037 
00038 
00039   const std::string base_dir = "/reg/g/psdm/detector/alignment/cspad/calib-cxi-ds1-2014-05-15/";
00040   const std::string fname_geo = (gfname.empty()) ? (base_dir + "calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/geometry/2-end.data") : gfname; 
00041   const std::string fname_nda = (ifname.empty()) ? (base_dir + "cspad-arr-cxid2714-r0023-lysozyme-rings.txt") : ifname; 
00042 
00043   //const std::string base_dir = "/reg/g/psdm/detector/alignment/cspad/calib-cxi-ds2-2015-01-20/";
00044   //const std::string fname_geo = base_dir + "calib/CsPad::CalibV1/CxiDs2.0:Cspad.0/geometry/0-end.data"; 
00045   //const std::string fname_nda = base_dir + "cspad-ndarr-max-cxig0715-r0023-lysozyme-rings.txt"; 
00046 
00047   const bool pbits = 0;
00048 
00049   m_file_geo  = new PSQt::WdgFile(this, "Set geometry", fname_geo, "*.txt *.data \n *", false);
00050   m_file_nda  = new PSQt::WdgFile(this, "Set ndarray",  fname_nda, "*.txt *.dat \n *", false);
00051   m_wgt       = new PSQt::WdgGeoTree(this, fname_geo, pbits);
00052   m_wge       = new PSQt::WdgGeo(this);
00053   m_geoimg    = new PSQt::GeoImage(m_wgt->geoacc(), fname_nda, xcent, ycent);  
00054   m_guiimv    = new PSQt::GUIImageViewer(0, xcent, ycent);
00055   //m_wimage    = m_guiimv->wdgImage();
00056  
00057   m_but_image = new QPushButton("Image", this);
00058   m_but_save  = new QPushButton("Save", this);
00059 
00060   m_bbox = new QHBoxLayout();
00061   m_bbox -> addWidget(m_but_save);
00062   m_bbox -> addStretch(1);
00063   m_bbox -> addWidget(m_but_image);
00064 
00065   m_fbox = new QVBoxLayout();
00066   m_fbox -> addWidget(m_file_geo);
00067   m_fbox -> addWidget(m_file_nda);
00068 
00069   m_rbox = new QVBoxLayout();
00070   m_rbox -> addWidget(m_wge);
00071   m_rbox -> addStretch(1);
00072   m_rbox -> addLayout(m_bbox);
00073 
00074   m_wrp = new QWidget();
00075   m_wrp -> setLayout(m_rbox);
00076   m_wrp -> setContentsMargins(-9,-9,-9,-9);
00077 
00078   m_hsplit = new QSplitter(Qt::Horizontal);
00079   m_hsplit -> addWidget(m_wgt); 
00080   m_hsplit -> addWidget(m_wrp);
00081 
00082   m_mbox = new QVBoxLayout();
00083   m_mbox -> addLayout(m_fbox);
00084   m_mbox -> addWidget(m_hsplit); 
00085 
00086   m_wmbox = new QWidget();
00087   m_wmbox -> setLayout(m_mbox);
00088   m_wmbox -> setContentsMargins(-9,-9,-9,-9);
00089 
00090   m_vsplit = new QSplitter(Qt::Vertical); 
00091   m_vsplit -> addWidget(m_wmbox); 
00092   m_vsplit -> addWidget(m_guilogger); 
00093 
00094   m_vbox = new QVBoxLayout();
00095   m_vbox -> addWidget(m_vsplit);
00096 
00097   this -> setLayout(m_vbox);
00098 
00099   showTips();
00100   setStyle();
00101 
00102   connect(m_but_image, SIGNAL(clicked()), this, SLOT(onButImage()));
00103   connect(m_but_save,  SIGNAL(clicked()), this, SLOT(onButSave()));
00104 
00105   connect(m_wgt->get_view(), SIGNAL(selectedGO(shpGO&)),
00106           m_wge,             SLOT(setNewGO(shpGO&)));
00107 
00108   connect(m_file_geo,        SIGNAL(fileNameIsChanged(const std::string&)), 
00109           m_wgt->get_view(), SLOT(updateTreeModel(const std::string&))); 
00110 
00111   connect(m_wgt->get_view(), SIGNAL(geometryIsLoaded(PSCalib::GeometryAccess*)), 
00112           m_geoimg,          SLOT(onGeometryIsLoaded(PSCalib::GeometryAccess*))); 
00113 
00114   connect(m_file_nda, SIGNAL(fileNameIsChanged(const std::string&)), 
00115           m_geoimg,   SLOT(onImageFileNameIsChanged(const std::string&))); 
00116 
00117   connect(m_wge,      SIGNAL(geoIsChanged(shpGO&)), 
00118           m_geoimg,   SLOT(onGeoIsChanged(shpGO&)));
00119 
00120   //connect(m_geoimg,   SIGNAL(imageIsUpdated(ndarray<GeoImage::raw_image_t,2>&)), 
00121   //        m_wimage,   SLOT(onImageIsUpdated(ndarray<GeoImage::raw_image_t,2>&)));
00122 
00123   //connect(m_geoimg,                 SIGNAL(imageIsUpdated(ndarray<GeoImage::raw_image_t,2>&)), 
00124   //        m_guiimv->getImageProc(), SLOT(onImageIsUpdated(ndarray<GeoImage::raw_image_t,2>&)));
00125 
00126   connect(m_geoimg, SIGNAL(imageIsUpdated(ndarray<GeoImage::raw_image_t,2>&)), 
00127           m_guiimv, SLOT(onImageIsUpdated(ndarray<GeoImage::raw_image_t,2>&)));
00128 
00129   // Complete initialization through connected signals & slots
00130   m_wgt -> get_geotree() -> setItemSelected();
00131   m_geoimg -> setFirstImage();
00132   m_guiimv->wdgImage()->onZoomResetButton();
00133 }
00134 
00135 //--------------------------
00136 
00137 void
00138 GUIMain::showTips() 
00139 {
00140   m_file_geo  -> setToolTip("Select geometry file");
00141   m_file_nda  -> setToolTip("Select ndarray with image file");
00142   m_but_image -> setToolTip("Open/close image window");
00143 }
00144 
00145 //--------------------------
00146 
00147 void
00148 GUIMain::setStyle()
00149 {
00150   AppUtils::AppDataPath adp_icon_image("PSQt/icons/icon-monitor.png");
00151   AppUtils::AppDataPath adp_icon_exit("PSQt/icons/exit.png");
00152   AppUtils::AppDataPath adp_icon_save("PSQt/icons/save.png");
00153 
00154   m_but_image -> setIcon(QIcon(QString(adp_icon_image.path().c_str())));
00155   m_but_save  -> setIcon(QIcon(QString(adp_icon_save.path().c_str()))); 
00156 
00157   this -> setGeometry(0, 0, 600, 726);
00158   this -> setWindowTitle("Detector Alignment");
00159 
00160   m_guiimv -> move(this->pos().x() + this->size().width() + 8, this->pos().y());  
00161   m_guiimv -> show();
00162   m_guiimv -> showChildWindows();
00163 
00164   //m_file_geo->setFixedWidth(150);
00165   //m_file_nda->setFixedWidth(150);
00166   //this -> setContentsMargins(-9,-9,-9,-9);
00167   //this -> move(0,0);  
00168 }
00169 
00170 //--------------------------
00171 
00172 void 
00173 GUIMain::resizeEvent(QResizeEvent *event)
00174 {
00175   stringstream ss; ss << "Detector Alignment w:" << event->size().width() << " h:" <<  event->size().height();
00176   setWindowTitle(ss.str().c_str());
00177 }
00178 
00179 //--------------------------
00180 
00181 void
00182 GUIMain::moveEvent(QMoveEvent *event)
00183 {
00184   stringstream ss; ss << "Detector Alignment x:" << event->pos().x() << " y:" << event->pos().y();
00185   setWindowTitle(ss.str().c_str());
00186 }
00187 
00188 //--------------------------
00189 
00190 void 
00191 GUIMain::closeEvent(QCloseEvent *event)
00192 {
00193   QWidget::closeEvent(event);
00194   stringstream ss; ss << "closeEvent(...): type = " << event -> type();
00195   MsgInLog(_name_(), INFO, ss.str());
00196 
00197   if(m_guiimv) m_guiimv -> close();
00198   if(m_guilogger) m_guilogger -> close();
00199   m_guiimv   = 0;
00200   m_guilogger = 0;
00201 
00202   SaveLog("work/z-log.txt", true); // true - insert time-stamp
00203 }
00204 
00205 //--------------------------
00206 
00207 void 
00208 GUIMain::mousePressEvent(QMouseEvent *event)
00209 {
00210   //int x = event->pos().x();
00211   //int y = event->pos().y();
00212   //QString text = "mousePressEvent: " + QString::number(x) + "," + QString::number(y);
00213   //std::cout << text.toStdString()  << std::endl;
00214 }
00215 
00216 //--------------------------
00217 
00218 void 
00219 GUIMain::onButSave()
00220 {
00221   MsgInLog(_name_(), DEBUG, "onButSave()");
00222 
00223   //char* search_fmt="*.data *.txt \n *"; 
00224   std::string path = getGeometryFileName(); // from QGUtils
00225 
00226   QString path_file = QFileDialog::getSaveFileName(this, tr("Select input file"), 
00227                                                    QString(path.c_str()), tr("*.data *.txt \n *"));
00228   std::string str_path_file = path_file.toStdString();
00229 
00230   if(str_path_file.empty()) {
00231     MsgInLog(_name_(), INFO, "Cancel file selection");
00232     return;
00233   }
00234 
00235   MsgInLog(_name_(), INFO, "Selected file name: " + str_path_file);
00236   m_wgt -> get_geotree() -> saveGeometryInFile(str_path_file);
00237 }
00238 
00239 //--------------------------
00240 
00241 void 
00242 GUIMain::onButExit()
00243 {
00244   MsgInLog(_name_(), INFO, "onButExit"); 
00245   this->close(); // will call closeEvent(...)
00246 }
00247 
00248 //--------------------------
00249 
00250 void 
00251 GUIMain::onButImage()
00252 {
00253   m_guiimv -> setVisible(! (m_guiimv->isVisible()));
00254   m_guiimv -> move(this->pos().x() + this->size().width() + 8, this->pos().y());  
00255   stringstream ss; ss << "Image window " << ((m_guiimv->isVisible()) ? "is open" : "closed");
00256   MsgInLog(_name_(), INFO, ss.str());
00257 }
00258 
00259 //--------------------------
00260 //--------------------------
00261 //--------------------------
00262 //--------------------------
00263 //--------------------------
00264 //--------------------------
00265 
00266 } // namespace PSQt
00267 
00268 //--------------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7