-// SALOME SalomeApp
+// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// Copyright (C) 2005 CEA/DEN, EDF R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// SALOME SalomeApp
// File : SalomeApp_StudyPropertiesDlg.cxx
-// Author : Sergey ANIKIN
-// Module : SALOME
-// $Header$
+// Author : Roman NIKOLAEV
#include "SalomeApp_StudyPropertiesDlg.h"
-#include "SalomeApp_ListView.h"
+#include "SalomeApp_Application.h"
#include "SalomeApp_Study.h"
#include "SUIT_Session.h"
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
-#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
+// CORBA Headers
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
-#include <qpushbutton.h>
-#include <qlayout.h>
-using namespace std;
+// QT Includes
+#include <QPushButton>
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QFrame>
+#include <QLineEdit>
+#include <QLabel>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QTextEdit>
+#include <QTreeWidget>
+#include <QPushButton>
+#include <iostream>
+
#define DEFAULT_MARGIN 11
-#define DEFAULT_SPACING 6
+#define DEFAULT_SPACING 6
#define SPACER_SIZE 5
#define MIN_LIST_WIDTH 300
#define MIN_LIST_HEIGHT 150
-class SalomeApp_PropItem : public SalomeApp_ListViewItem
-{
-public:
-// constructor
- SalomeApp_PropItem(SalomeApp_ListView* parent,
- const QString theName,
- const bool theEditable,
- const int theUserType) :
- SalomeApp_ListViewItem( parent, theName, theEditable )
- {
- setUserType(theUserType);
- }
-// constructor
- SalomeApp_PropItem(SalomeApp_ListView* parent,
- SalomeApp_ListViewItem* after,
- const QString theName,
- const bool theEditable,
- const int theUserType) :
- SalomeApp_ListViewItem( parent, after, theName, theEditable )
- {
- setUserType(theUserType);
- }
-// fills widget with initial values (list or single value)
- void fillWidgetWithValues( SalomeApp_EntityEdit* theWidget )
- {
- QStringList list;
- switch(getUserType()) {
- case SalomeApp_StudyPropertiesDlg::prpModeId:
- {
- list << QObject::tr("PRP_MODE_FROM_SCRATCH") <<
- QObject::tr("PRP_MODE_FROM_COPYFROM");
- theWidget->insertList(list);
- break;
- }
- case SalomeApp_StudyPropertiesDlg::prpLockedId:
- {
- list << QObject::tr("PRP_NO") << QObject::tr("PRP_YES");
- theWidget->insertList(list, getValue() == QObject::tr("PRP_NO") ? 0 : 1);
- break;
- }
- case SalomeApp_StudyPropertiesDlg::prpModificationsId:
- {
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if (study) {
- _PTR(Study) studyDoc = study->studyDS();
- _PTR(AttributeStudyProperties) propAttr;
- if ( studyDoc ) {
- propAttr = studyDoc->GetProperties();
- if ( propAttr ) {
- std::vector<std::string> aUsers;
- std::vector<int> aMins, aHours, aDays, aMonths, aYears;
- propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
- int aCnt = aUsers.size();
- for ( int i = 0; i < aCnt; i++ ) {
- QString val;
- val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
- aDays [i],
- aMonths[i],
- aYears [i],
- aHours [i],
- aMins [i]);
- val = val + " : " + QString(aUsers[i]);
- list.prepend(val);
- }
- theWidget->setDuplicatesEnabled(true);
- theWidget->insertList(list);
- }
- }
- }
- break;
- }
- default:
- {
- SalomeApp_ListViewItem::fillWidgetWithValues(theWidget);
- break;
- }
- }
- }
-// finishes editing of entity
- virtual UpdateType finishEditing( SalomeApp_EntityEdit* theWidget ) {
- if ( getUserType() == SalomeApp_StudyPropertiesDlg::prpModificationsId )
- return utCancel;
- else
- return SalomeApp_ListViewItem::finishEditing(theWidget);
- }
-};
+/*!Constructor. Initialize study properties dialog.*/
SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
- : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
- myChanged( false )
+ : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
+ myIsChanged(false)
{
- setCaption(tr("TLT_STUDY_PROPERTIES"));
+ setModal( true );
+
+ setWindowTitle(tr("TLT_STUDY_PROPERTIES"));
setSizeGripEnabled( true );
- clearWFlags(Qt::WStyle_ContextHelp);
+ setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
- QGridLayout* mainLayout = new QGridLayout(this);
- mainLayout->setMargin(DEFAULT_MARGIN);
- mainLayout->setSpacing(DEFAULT_SPACING);
-
- myPropList = new SalomeApp_ListView(this);
- myPropList->addColumn("");
- myPropList->addColumn("");
- myPropList->enableEditing(TRUE);
- myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT);
- mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2);
+ //Author
+ QLabel* authorLbl = new QLabel(tr("PRP_AUTHOR"),this);
+ myAuthor = new QLineEdit(this);
- myOKBtn = new QPushButton(tr("BUT_OK"), this);
- mainLayout->addWidget(myOKBtn, 1, 0);
+ //Creation date
+ QLabel* dateLbl = new QLabel(tr("PRP_DATE"),this);
+ myDate = new QLabel(this);
- myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this);
- mainLayout->addWidget(myCancelBtn, 1, 2);
+ //Locked flag
+ myLocked = new QCheckBox(tr("PRP_LOCKED"), this);
- QSpacerItem* spacer1 = new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum);
- mainLayout->addItem(spacer1, 1, 1);
+ //Modification flag
+ myModification = new QLabel(this);
- // Display study properties
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if (study)
- myStudyDoc = study->studyDS();
+ //Units
+ QLabel* unitsLbl = new QLabel(tr("PRP_UNITS"),this);
+ myUnits = new QComboBox(this);
- initData();
+ //Comment
+ QLabel* commentLabel = new QLabel(tr("PRP_COMMENT"),this);
+ myComment = new QTextEdit(this);
+ myComment->setMaximumHeight(80);
+
+ //Modifications
+ QLabel* modificationsLabel = new QLabel(tr("PRP_MODIFICATIONS"),this);
+ myModifications = new QTreeWidget(this);
+ myModifications->setRootIsDecorated(false);
+ myModifications->setUniformRowHeights(true);
+ myModifications->setAllColumnsShowFocus(true);
+ myModifications->setColumnCount(2);
+ myModifications->setMaximumHeight(80);
+ QStringList columnNames;
+ columnNames.append(tr("PRP_AUTHOR"));
+ columnNames.append(tr("PRP_DATE_MODIF"));
+ myModifications->setHeaderLabels( columnNames );
+
+ //Component versions
+ QLabel* versionsLabel = new QLabel(tr("PRP_VERSIONS"),this);
+ myVersions = new QTreeWidget(this);
+ myVersions->setRootIsDecorated(false);
+ myVersions->setUniformRowHeights(true);
+ myVersions->setAllColumnsShowFocus(true);
+ myVersions->setColumnCount(2);
+ myVersions->setMaximumHeight(80);
+ columnNames.clear();
+ columnNames.append(tr("PRP_COMPONENT"));
+ columnNames.append(tr("PRP_VERSION"));
+ myVersions->setHeaderLabels( columnNames );
+
+ QFrame* buttonFrame = new QFrame(this);
- connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
- connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
+ QHBoxLayout* horizontalLayout = new QHBoxLayout(buttonFrame);
+
+ myOkButton = new QPushButton(tr("BUT_OK"), buttonFrame);
+ myCancelButton = new QPushButton(tr("BUT_CANCEL"), buttonFrame);
+
+ horizontalLayout->addWidget(myOkButton);
+ horizontalLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum) );
+ horizontalLayout->addWidget(myCancelButton);
+
+ QGridLayout* gridLayout = new QGridLayout(this);
+ gridLayout->setMargin(DEFAULT_MARGIN);
+ gridLayout->setSpacing(DEFAULT_SPACING);
+ gridLayout->addWidget(authorLbl, 0, 0, 1, 1);
+ gridLayout->addWidget(myAuthor, 0, 1, 1, 1);
+ gridLayout->addWidget(dateLbl, 1, 0, 1, 1);
+ gridLayout->addWidget(myDate, 1, 1, 1, 1);
+ gridLayout->addWidget(myLocked, 2, 0, 1, 1);
+ gridLayout->addWidget(myModification, 2, 1, 1, 1);
+ gridLayout->addWidget(unitsLbl, 3, 0, 1, 1);
+ gridLayout->addWidget(myUnits, 3, 1, 1, 1);
+ gridLayout->addItem(new QSpacerItem(/*72*/0, 0/*20*/, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 2, 1, 1);
+ gridLayout->addWidget(commentLabel, 4, 0, 1, 1);
+ gridLayout->addWidget(myComment, 4, 1, 1, 2);
+ gridLayout->addWidget(modificationsLabel, 5, 0, 1, 1);
+ gridLayout->addWidget(myModifications, 5, 1, 1, 2);
+ gridLayout->addWidget(versionsLabel, 6, 0, 1, 1);
+ gridLayout->addWidget(myVersions, 6, 1, 1, 2);
+ gridLayout->addWidget(buttonFrame, 7, 0, 1, 3);
+
+ connect(myOkButton, SIGNAL(clicked()), this, SLOT(clickOnOk()));
+ connect(myCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+
+ initData();
}
+/*!
+ Destructor.
+*/
SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
{
}
+/*!
+ Data initializetion for dialog.(Study author's name, date of creation etc.)
+*/
void SalomeApp_StudyPropertiesDlg::initData()
{
- bool hasData = myStudyDoc;
+ bool hasData = (SalomeApp_Application::getStudy() != NULL);
_PTR(AttributeStudyProperties) propAttr;
- if (hasData)
- propAttr = myStudyDoc->GetProperties();
- hasData = hasData && propAttr;
-
- // Study author's name
- SalomeApp_PropItem* item = new SalomeApp_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId);
if (hasData)
- item->setValue(propAttr->GetUserName());
-
- // Date of creation
- item = new SalomeApp_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId);
+ propAttr = SalomeApp_Application::getStudy()->GetProperties();
+ hasData = hasData && propAttr;
+
if (hasData) {
+ //Creator and creation date
+ myAuthor->setText(propAttr->GetUserName().c_str());
int minutes, hours, day, month, year;
if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
QString strDate;
strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
- item->setValue(strDate);
+ myDate->setText(strDate);
}
- }
-
- // Creation mode
-// item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId);
-// item->setEditingType( SalomeApp_EntityEdit::etComboBox);
-// if (hasData) item->setValue(propAttr->GetCreationMode());
+
+ //Is Locked?
+ myLocked->setChecked(propAttr->IsLocked());
- // Locked or not
- item = new SalomeApp_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId);
- item->setEditingType( SalomeApp_EntityEdit::etComboBox);
- if (hasData) (propAttr->IsLocked()) ? item->setValue(tr("PRP_YES")) : item->setValue(tr("PRP_NO"));
+ //Is Modified?
+ bool isModified = false;
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
+ (SUIT_Session::session()->activeApplication()->activeStudy());
+ isModified = study->isModified();
+ if (propAttr->IsModified() != isModified) {
+ propAttr->SetModified((int)isModified);
+ }
+
+ QString modif = propAttr->IsModified() ? tr( "PRP_MODIFIED" ) : tr( "PRP_NOT_MODIFIED" );
+ myModification->setText(modif);
+
+ //Units
+ QStringList theList;
+ theList <<""<<"mm"<<"cm"<<"m"<<"km"<<"inch";
+ myUnits->insertItems(0,theList);
- // Saved or not
- item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId);
- if (hasData) {
- if (propAttr->IsModified())
- item->setValue(tr("PRP_YES"));
- else
- item->setValue(tr("PRP_NO"));
- }
+ QString anUnit = propAttr->GetUnits().c_str();
- // Modifications list
- item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId);
- item->setEditingType( SalomeApp_EntityEdit::etComboBox);
- if (hasData) {
+ int aFound = -1;
+ for (int i = 0; i < myUnits->count(); i++) {
+ if ( myUnits->itemText(i) == anUnit ) {
+ aFound = i;
+ break;
+ }
+ }
+
+ if (aFound >= 0) {
+ myUnits->setCurrentIndex(aFound);
+ }
+
+ //Comments
+ myComment->setPlainText(propAttr->GetComment().c_str());
+
+ //Modifications
std::vector<std::string> aUsers;
- std::vector<int> aMins, aHours, aDays, aMonths, aYears;
+ std::vector<int> aMins, aHours, aDays, aMonths, aYears;
propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
- int aLast = aUsers.size()-1;
- if (aLast >= 0) {
- QString val;
- val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
- aDays [aLast],
- aMonths[aLast],
- aYears [aLast],
- aHours [aLast],
- aMins [aLast]);
- val = val + " : " + QString(aUsers[aUsers.size()-1]);
- item->setValue(val);
+ int aCnt = aUsers.size();
+ for ( int i = 0; i < (int)aCnt; i++ ) {
+ QString date;
+ date.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
+ aDays [i],
+ aMonths[i],
+ aYears [i],
+ aHours [i],
+ aMins [i]);
+ QStringList aList;
+ aList.append(aUsers[i].c_str());
+ aList.append(date);
+ QTreeWidgetItem* item = new QTreeWidgetItem(aList);
+ myModifications->addTopLevelItem(item);
+ }
+
+ //Component versions
+ std::vector<std::string> aComponents = propAttr->GetStoredComponents();
+ for ( int i = 0; i < (int)aComponents.size(); i++ ) {
+ std::vector<int> aMins, aHours, aDays, aMonths, aYears;
+ std::vector<std::string> aVersions = propAttr->GetComponentVersions(aComponents[i]);
+ QStringList aData;
+ aData.append( aComponents[i].c_str() );
+ aData.append( aVersions.empty() || aVersions[0] == "" ? "unknown" : aVersions[0].c_str() );
+ QTreeWidgetItem* item = new QTreeWidgetItem( aData );
+ if ( aVersions.size() > 1 )
+ item->setForeground( 1, Qt::red );
+ myVersions->addTopLevelItem(item);
}
}
-
- myOKBtn->setEnabled(hasData);
-}
-
-bool SalomeApp_StudyPropertiesDlg::acceptData()
-{
- return TRUE;
+ adjustSize();
}
-void SalomeApp_StudyPropertiesDlg::onOK()
+/*!
+ Fill properties attributes.
+*/
+void SalomeApp_StudyPropertiesDlg::clickOnOk()
{
- myPropList->accept();
-
- if (acceptData()) {
- _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
- myChanged = propChanged();
- if ( propAttr && myChanged ) {
- QListViewItemIterator it( myPropList );
- // iterate through all items of the listview
- for ( ; it.current(); ++it ) {
- SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
- switch (item->getUserType()) {
- case prpAuthorId:
- propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1());
- break;
- case prpModeId:
- propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1());
- break;
- case prpLockedId:
- propAttr->SetLocked(item->getValue().compare(tr("PRP_YES")) == 0);
- break;
- default:
- break;
- }
+ _PTR(AttributeStudyProperties) propAttr = SalomeApp_Application::getStudy()->GetProperties();
+ //Firstly, store locked flag
+ if(propAttr) {
+ bool bLocked = myLocked->isChecked();
+ if (propAttr->IsLocked() != bLocked) {
+ propAttr->SetLocked(bLocked);
+ myIsChanged = true;
+ }
+
+ bool needWarning = false;
+
+ //Author
+ if (QString(propAttr->GetUserName().c_str()) != myAuthor->text().trimmed()) {
+ if(!propAttr->IsLocked()) {
+ propAttr->SetUserName(myAuthor->text().trimmed().toStdString());
+ myIsChanged = true;
+ } else {
+ needWarning = true;
}
}
- accept();
- }
-}
-bool SalomeApp_StudyPropertiesDlg::propChanged() {
- _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
- if ( propAttr ) {
- QListViewItemIterator it( myPropList );
- // iterate through all items of the listview
- for ( ; it.current(); ++it ) {
- SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current());
- switch (item->getUserType()) {
- case prpAuthorId:
- if ( QString( propAttr->GetUserName() ) != item->getValue().stripWhiteSpace() ) {
- return true;
- }
- break;
- case prpModeId:
- if ( QString( propAttr->GetCreationMode() ) != item->getValue().stripWhiteSpace() ) {
- return true;
- }
- break;
- case prpLockedId:
- {
- bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0;
- if ( propAttr->IsLocked() != bLocked ) {
- return true;
- }
- break;
- }
- default:
- break;
+ //Unit
+ if (QString(propAttr->GetUnits().c_str()) != myUnits->currentText()) {
+ if(!propAttr->IsLocked()) {
+ propAttr->SetUnits(myUnits->currentText().toStdString());
+ myIsChanged = true;
+ } else {
+ needWarning = true;
+ }
+ }
+
+ //Comment
+ if (QString(propAttr->GetComment().c_str()) != myComment->toPlainText()) {
+ if(!propAttr->IsLocked()) {
+ propAttr->SetComment(myComment->toPlainText().toStdString());
+ myIsChanged = true;
+ } else {
+ needWarning = true;
}
}
+
+ if(needWarning) {
+ SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(),
+ QObject::tr("WRN_WARNING"),
+ QObject::tr("WRN_STUDY_LOCKED") );
+ }
+
+ accept();
}
- return false;
}