1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SalomeApp_StudyPropertiesDlg.cxx
22 // Author : Sergey ANIKIN
26 #include "SalomeApp_StudyPropertiesDlg.h"
27 #include "SalomeApp_ListView.h"
28 #include "SalomeApp_Study.h"
30 #include "SUIT_Session.h"
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
35 #include <OSD_Process.hxx>
36 #include <Quantity_Date.hxx>
39 #include <SALOMEconfig.h>
40 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
43 #include <qpushbutton.h>
48 #define DEFAULT_MARGIN 11
49 #define DEFAULT_SPACING 6
51 #define MIN_LIST_WIDTH 300
52 #define MIN_LIST_HEIGHT 150
54 class SalomeApp_PropItem : public SalomeApp_ListViewItem
58 SalomeApp_PropItem(SalomeApp_ListView* parent,
59 const QString theName,
60 const bool theEditable,
61 const int theUserType) :
62 SalomeApp_ListViewItem( parent, theName, theEditable )
64 setUserType(theUserType);
67 SalomeApp_PropItem(SalomeApp_ListView* parent,
68 SalomeApp_ListViewItem* after,
69 const QString theName,
70 const bool theEditable,
71 const int theUserType) :
72 SalomeApp_ListViewItem( parent, after, theName, theEditable )
74 setUserType(theUserType);
76 /*! fills widget with initial values (list or single value)*/
77 void fillWidgetWithValues( SalomeApp_EntityEdit* theWidget )
80 switch(getUserType()) {
81 //case SalomeApp_StudyPropertiesDlg::prpModeId:
83 // list << SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_SCRATCH") <<
84 // SalomeApp_StudyPropertiesDlg::tr("PRP_MODE_FROM_COPYFROM");
85 // theWidget->insertList(list);
88 case SalomeApp_StudyPropertiesDlg::prpLockedId:
90 list << SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) << SalomeApp_StudyPropertiesDlg::tr( "PRP_YES" );
91 theWidget->insertList(list, getValue() == SalomeApp_StudyPropertiesDlg::tr( "PRP_NO" ) ? 0 : 1 );
94 case SalomeApp_StudyPropertiesDlg::prpModificationsId:
96 SalomeApp_Study* study =
97 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
99 _PTR(Study) studyDoc = study->studyDS();
100 _PTR(AttributeStudyProperties) propAttr;
102 propAttr = studyDoc->GetProperties();
104 std::vector<std::string> aUsers;
105 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
106 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
107 int aCnt = aUsers.size();
108 for ( int i = 0; i < aCnt; i++ ) {
110 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
116 val = val + " : " + QString( aUsers[i].c_str() );
119 theWidget->setDuplicatesEnabled(true);
120 theWidget->insertList(list);
128 SalomeApp_ListViewItem::fillWidgetWithValues(theWidget);
133 /*! finishes editing of entity */
134 virtual UpdateType finishEditing( SalomeApp_EntityEdit* theWidget ) {
135 if ( getUserType() == SalomeApp_StudyPropertiesDlg::prpModificationsId )
138 return SalomeApp_ListViewItem::finishEditing(theWidget);
142 /*!Constructor. Initialize study properties dialog.*/
143 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
144 : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
147 setCaption(tr("TLT_STUDY_PROPERTIES"));
148 setSizeGripEnabled( true );
150 clearWFlags(Qt::WStyle_ContextHelp);
152 QGridLayout* mainLayout = new QGridLayout(this);
153 mainLayout->setMargin(DEFAULT_MARGIN);
154 mainLayout->setSpacing(DEFAULT_SPACING);
156 myPropList = new SalomeApp_ListView(this);
157 myPropList->addColumn("");
158 myPropList->addColumn("");
159 myPropList->enableEditing(TRUE);
160 myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
161 mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2);
163 myOKBtn = new QPushButton(tr("BUT_OK"), this);
164 mainLayout->addWidget(myOKBtn, 1, 0);
166 myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
167 mainLayout->addWidget(myCancelBtn, 1, 2);
169 QSpacerItem* spacer1 =
170 new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
171 mainLayout->addItem(spacer1, 1, 1);
173 // Display study properties
174 SalomeApp_Study* study =
175 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
177 myStudyDoc = study->studyDS();
181 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
182 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
188 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
193 Data initializetion for dialog.(Study author's name, date of creation etc.)
195 void SalomeApp_StudyPropertiesDlg::initData()
197 bool hasData = myStudyDoc;
198 _PTR(AttributeStudyProperties) propAttr;
200 propAttr = myStudyDoc->GetProperties();
201 hasData = hasData && propAttr;
203 // Study author's name
204 SalomeApp_PropItem* item = new SalomeApp_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
206 item->setValue(propAttr->GetUserName().c_str());
209 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
211 int minutes, hours, day, month, year;
212 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
214 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
215 item->setValue(strDate);
220 // item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
221 // item->setEditingType( SalomeApp_EntityEdit::etComboBox);
222 // if (hasData) item->setValue(propAttr->GetCreationMode());
225 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
226 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
228 item->setValue( tr( propAttr->IsLocked() ? "PRP_YES" : "PRP_NO" ) );
231 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
232 bool isModified = false;
233 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
234 (SUIT_Session::session()->activeApplication()->activeStudy());
236 isModified = study->isModified();
238 if (propAttr->IsModified() != isModified) {
239 propAttr->SetModified((int)isModified);
244 if (propAttr->IsModified())
245 item->setValue( tr( "PRP_YES" ) );
247 item->setValue( tr( "PRP_NO" ) );
250 // Modifications list
251 item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
252 item->setEditingType( SalomeApp_EntityEdit::etComboBox);
254 std::vector<std::string> aUsers;
255 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
256 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
257 int aLast = aUsers.size()-1;
260 val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
266 val = val + " : " + QString(aUsers[aUsers.size()-1].c_str());
271 myOKBtn->setEnabled(hasData);
275 accept data. Return true.
277 bool SalomeApp_StudyPropertiesDlg::acceptData()
283 Fill properties attributes.
285 void SalomeApp_StudyPropertiesDlg::onOK()
287 myPropList->accept();
290 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
291 //myChanged = propChanged();
292 if ( propAttr /*&& myChanged*/ ) {
293 QListViewItemIterator it( myPropList );
294 // iterate through all items of the listview
295 for ( ; it.current(); ++it ) {
296 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
297 switch (item->getUserType()) {
299 if (QString(propAttr->GetUserName().c_str()) != item->getValue().stripWhiteSpace()) {
300 if (!propAttr->IsLocked()) {
301 propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1());
304 SUIT_MessageBox::warn1(SUIT_Session::session()->activeApplication()->desktop(),
305 QObject::tr("WRN_WARNING"),
306 QObject::tr("WRN_STUDY_LOCKED"),
307 QObject::tr("BUT_OK"));
312 // propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1());
316 bool bLocked = item->getValue().compare(tr("PRP_YES")) == 0;
317 if (propAttr->IsLocked() != bLocked) {
318 propAttr->SetLocked(bLocked);
333 Check is properties changed?
335 bool SalomeApp_StudyPropertiesDlg::propChanged()
337 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
339 QListViewItemIterator it (myPropList);
340 // iterate through all items of the listview
341 for (; it.current(); ++it) {
342 SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
343 switch (item->getUserType()) {
345 if ( QString( propAttr->GetUserName().c_str() ) != item->getValue().stripWhiteSpace() ) {
350 // if ( QString( propAttr->GetCreationMode().c_str() ) != item->getValue().stripWhiteSpace() ) {
356 bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
357 if ( propAttr->IsLocked() != bLocked ) {