Back to index

salome-gui  6.5.0
SalomeApp_StudyPropertiesDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME SalomeApp
00024 //  File   : SalomeApp_StudyPropertiesDlg.cxx
00025 //  Author : Roman NIKOLAEV
00026 
00027 #include "SalomeApp_StudyPropertiesDlg.h"
00028 #include "SalomeApp_Study.h"
00029 
00030 #include "SUIT_Session.h"
00031 #include <SUIT_Desktop.h>
00032 #include <SUIT_MessageBox.h>
00033 
00034 // CORBA Headers
00035 #include <SALOMEconfig.h>
00036 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
00037 
00038 // QT Includes
00039 #include <QPushButton>
00040 #include <QGridLayout>
00041 #include <QHBoxLayout>
00042 #include <QFrame>
00043 #include <QLineEdit>
00044 #include <QLabel>
00045 #include <QCheckBox>
00046 #include <QComboBox>
00047 #include <QTextEdit>
00048 #include <QTreeWidget>
00049 #include <QPushButton>
00050 
00051 #include <iostream>
00052  
00053 #define  DEFAULT_MARGIN 11
00054 #define  DEFAULT_SPACING 6
00055 #define     SPACER_SIZE 5
00056 #define MIN_LIST_WIDTH  300
00057 #define MIN_LIST_HEIGHT 150
00058 
00059 
00061 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
00062   : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
00063     myIsChanged(false)
00064 {
00065   setModal( TRUE );
00066 
00067   setWindowTitle(tr("TLT_STUDY_PROPERTIES"));
00068   setSizeGripEnabled( true );
00069 
00070   setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
00071 
00072   // Display study properties
00073   SalomeApp_Study* study =
00074     dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
00075   if (study)
00076     myStudyDoc = study->studyDS();
00077 
00078   //Author
00079   QLabel* authorLbl = new QLabel(tr("PRP_AUTHOR"),this);
00080   myAuthor = new QLineEdit(this);
00081 
00082   //Creation date
00083   QLabel* dateLbl = new QLabel(tr("PRP_DATE"),this);
00084   myDate = new QLabel(this);
00085 
00086   //Locked flag
00087   myLocked = new QCheckBox(tr("PRP_LOCKED"), this);
00088 
00089   //Modification flag
00090   myModification = new QLabel(this);
00091 
00092   //Units
00093   QLabel* unitsLbl = new QLabel(tr("PRP_UNITS"),this);
00094   myUnits = new QComboBox(this);
00095 
00096   //Comment
00097   QLabel* commentLabel = new QLabel(tr("PRP_COMMENT"),this);
00098   myComment = new QTextEdit(this);
00099   myComment->setMaximumHeight(80);
00100 
00101   //Modifications
00102   QLabel* modificationsLabel = new QLabel(tr("PRP_MODIFICATIONS"),this);  
00103   myModifications = new QTreeWidget(this);
00104   myModifications->setRootIsDecorated(false);
00105   myModifications->setUniformRowHeights(true);
00106   myModifications->setAllColumnsShowFocus(true);
00107   myModifications->setColumnCount(2);
00108   myModifications->setMaximumHeight(80);
00109   QStringList columnNames;
00110   columnNames.append(tr("PRP_AUTHOR"));
00111   columnNames.append(tr("PRP_DATE_MODIF"));
00112 
00113   QTreeWidgetItem * headerItem = new QTreeWidgetItem(columnNames);
00114   myModifications->setHeaderItem ( headerItem );
00115 
00116   QFrame* buttonFrame = new QFrame(this);
00117 
00118   QHBoxLayout* horizontalLayout = new QHBoxLayout(buttonFrame);
00119   
00120   myOkButton = new QPushButton(tr("BUT_OK"), buttonFrame);
00121   myCancelButton = new QPushButton(tr("BUT_CANCEL"), buttonFrame);
00122 
00123   horizontalLayout->addWidget(myOkButton);
00124   horizontalLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum) );
00125   horizontalLayout->addWidget(myCancelButton);
00126   
00127   QGridLayout* gridLayout = new QGridLayout(this);
00128   gridLayout->setMargin(DEFAULT_MARGIN);
00129   gridLayout->setSpacing(DEFAULT_SPACING);
00130   gridLayout->addWidget(authorLbl, 0, 0, 1, 1);
00131   gridLayout->addWidget(myAuthor, 0, 1, 1, 1);
00132   gridLayout->addWidget(dateLbl, 1, 0, 1, 1);
00133   gridLayout->addWidget(myDate, 1, 1, 1, 1);
00134   gridLayout->addWidget(myLocked, 2, 0, 1, 1);
00135   gridLayout->addWidget(myModification, 2, 1, 1, 1);
00136   gridLayout->addWidget(unitsLbl, 3, 0, 1, 1);
00137   gridLayout->addWidget(myUnits, 3, 1, 1, 1);
00138   gridLayout->addItem(new QSpacerItem(/*72*/0, 0/*20*/, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 2, 1, 1);
00139   gridLayout->addWidget(commentLabel, 4, 0, 1, 1);
00140   gridLayout->addWidget(myComment, 4, 1, 1, 2);
00141   gridLayout->addWidget(modificationsLabel, 5, 0, 1, 1);
00142   gridLayout->addWidget(myModifications, 5, 1, 1, 2);
00143   gridLayout->addWidget(buttonFrame, 6, 0, 1, 3);
00144 
00145   connect(myOkButton,     SIGNAL(clicked()), this, SLOT(clickOnOk()));
00146   connect(myCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
00147   
00148   initData();
00149 }
00150 
00154 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
00155 {
00156 }
00157 
00161 void SalomeApp_StudyPropertiesDlg::initData()
00162 {
00163   bool hasData = myStudyDoc;
00164   _PTR(AttributeStudyProperties) propAttr;
00165   if (hasData)
00166     propAttr = myStudyDoc->GetProperties();
00167   hasData = hasData && propAttr;
00168   
00169   if (hasData) {
00170     //Creator and creation date
00171     myAuthor->setText(propAttr->GetUserName().c_str());
00172     int minutes, hours, day, month, year;
00173     if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
00174       QString strDate;
00175       strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
00176       myDate->setText(strDate);
00177     }
00178     
00179     //Is Locked?
00180     myLocked->setChecked(propAttr->IsLocked());
00181 
00182     //Is Modified?
00183     bool isModified = false;
00184     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
00185       (SUIT_Session::session()->activeApplication()->activeStudy());
00186     if (study) {
00187       isModified = study->isModified();
00188       if (hasData) {
00189         if (propAttr->IsModified() != isModified) {
00190           propAttr->SetModified((int)isModified);
00191         }
00192       }
00193     }
00194 
00195     QString modif = propAttr->IsModified() ? tr( "PRP_MODIFIED" ) : tr( "PRP_NOT_MODIFIED" );
00196     myModification->setText(modif);
00197     
00198     //Units
00199     QStringList theList;
00200     theList <<""<<"mm"<<"cm"<<"m"<<"km"<<"inch";
00201     myUnits->insertItems(0,theList); 
00202 
00203     QString anUnit = propAttr->GetUnits().c_str();
00204 
00205     int aFound = -1;
00206     for (int i = 0; i < myUnits->count(); i++) {
00207       if ( myUnits->itemText(i) == anUnit ) {
00208         aFound = i;
00209         break;
00210       }
00211     }
00212     
00213     if (aFound >= 0) {
00214       myUnits->setCurrentIndex(aFound);
00215     }
00216     
00217     //Comments
00218     myComment->setPlainText(propAttr->GetComment().c_str());
00219     
00220     //Modifications
00221     std::vector<std::string> aUsers;
00222     std::vector<int>  aMins, aHours, aDays, aMonths, aYears;
00223     propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
00224     int aCnt = aUsers.size();
00225     for ( int i = 0; i < aCnt; i++ ) {
00226       QString date;
00227       date.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
00228                   aDays  [i],
00229                   aMonths[i],
00230                   aYears [i],
00231                   aHours [i],
00232                   aMins  [i]);
00233       QStringList aList;
00234       aList.append(aUsers[i].c_str());
00235       aList.append(date);
00236       QTreeWidgetItem* item = new  QTreeWidgetItem(aList);
00237       myModifications->addTopLevelItem(item);
00238     }        
00239   }
00240   adjustSize();
00241 }
00242 
00246 void SalomeApp_StudyPropertiesDlg::clickOnOk()
00247 {
00248   _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
00249   //Firstly, store locked flag
00250   if(propAttr) {
00251     bool bLocked = myLocked->isChecked();
00252     if (propAttr->IsLocked() != bLocked) {
00253       propAttr->SetLocked(bLocked);
00254       myIsChanged = true;
00255     }
00256     
00257     bool needWarning = false;
00258     
00259     //Author
00260     if (QString(propAttr->GetUserName().c_str()) != myAuthor->text().trimmed()) {
00261       if(!propAttr->IsLocked()) {
00262         propAttr->SetUserName(myAuthor->text().trimmed().toStdString());
00263         myIsChanged = true;
00264       } else {
00265         needWarning = true;
00266       }
00267     }
00268 
00269     //Unit
00270     if (QString(propAttr->GetUnits().c_str()) != myUnits->currentText()) {
00271       if(!propAttr->IsLocked()) {
00272         propAttr->SetUnits(myUnits->currentText().toStdString());
00273         myIsChanged = true;
00274       } else {
00275         needWarning = true;
00276       }
00277     }
00278       
00279     //Comment      
00280     if (QString(propAttr->GetComment().c_str()) != myComment->toPlainText()) {
00281       if(!propAttr->IsLocked()) {
00282         propAttr->SetComment(myComment->toPlainText().toStdString());
00283         myIsChanged = true;
00284       } else {
00285         needWarning = true;
00286       }
00287     }
00288     
00289     if(needWarning) {
00290       SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(),
00291                                QObject::tr("WRN_WARNING"),
00292                                QObject::tr("WRN_STUDY_LOCKED") );
00293     }
00294     
00295     accept();
00296   }
00297 }