1 // Copyright (C) 2008 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
19 // File: SalomeApp_NoteBookDlg.cxx
20 // Author : Roman NIKOLAEV, Open CASCADE S.A.S.
23 #include "SalomeApp_NoteBookDlg.h"
24 #include "SalomeApp_Application.h"
25 #include "SalomeApp_Study.h"
26 #include "SalomeApp_VisualState.h"
30 #include <CAM_Module.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
37 #include <PyConsole_Console.h>
39 #include <SALOMEDS_Tool.hxx>
43 #include <QGridLayout>
44 #include <QTableWidget>
45 #include <QTableWidgetItem>
46 #include <QPushButton>
50 #include <QApplication>
58 #define DEFAULT_MARGIN 11
59 #define DEFAULT_SPACING 6
60 #define SPACER_SIZE 120
61 #define COLUMN_SIZE 180
64 #define VALUE_COLUMN 1
67 ///////////////////////////////////////////////////////////////////////////
68 // NoteBook_TableRow class //
69 ///////////////////////////////////////////////////////////////////////////
70 //============================================================================
71 /*! Function : NoteBook_TableRow
72 * Purpose : Constructor
74 //============================================================================
75 NoteBook_TableRow::NoteBook_TableRow(int index, QWidget* parent):
78 myRowHeader(new QTableWidgetItem()),
79 myVariableName(new QTableWidgetItem()),
80 myVariableValue(new QTableWidgetItem())
84 //============================================================================
85 /*! Function : ~NoteBook_TableRow
86 * Purpose : Destructor
88 //============================================================================
89 NoteBook_TableRow::~NoteBook_TableRow()
93 //============================================================================
94 /*! Function : AddToTable
95 * Purpose : Add this row to the table theTable
97 //============================================================================
98 void NoteBook_TableRow::AddToTable(QTableWidget *theTable)
100 int aPosition = theTable->rowCount();
101 int aRowCount = aPosition+1;
102 theTable->setRowCount(aRowCount);
103 myRowHeader->setText(QString::number(aRowCount));
105 theTable->setVerticalHeaderItem(aPosition,myRowHeader);
106 theTable->setItem(aPosition, NAME_COLUMN, myVariableName);
107 theTable->setItem(aPosition, VALUE_COLUMN, myVariableValue);
110 //============================================================================
111 /*! Function : SetName
114 //============================================================================
115 void NoteBook_TableRow::SetName(const QString theName)
117 myVariableName->setText(theName);
120 //============================================================================
121 /*! Function : SetValue
124 //============================================================================
125 void NoteBook_TableRow::SetValue(const QString theValue)
127 myVariableValue->setText(theValue);
130 //============================================================================
131 /*! Function : GetName
132 * Purpose : Return variable name
134 //============================================================================
135 QString NoteBook_TableRow::GetName() const
137 return myVariableName->text();
140 //============================================================================
141 /*! Function : GetValue
142 * Purpose : Return variable value
144 //============================================================================
145 QString NoteBook_TableRow::GetValue() const
147 return myVariableValue->text();
150 //============================================================================
151 /*! Function : CheckName
152 * Purpose : Return true if variable name correct, otherwise return false
154 //============================================================================
155 bool NoteBook_TableRow::CheckName()
157 QString aName = GetName();
159 QRegExpValidator aValidator( QRegExp("^([a-zA-Z]+)([a-zA-Z0-9_]*)$"), 0 );
160 if( aName.isEmpty() || !aValidator.validate( aName, aPos ) )
165 //============================================================================
166 /*! Function : CheckValue
167 * Purpose : Return true if variable value correct, otherwise return false
169 //============================================================================
170 bool NoteBook_TableRow::CheckValue()
172 bool aResult = false;
173 QString aValue = GetValue();
174 if( (!aValue.isEmpty()) &&
175 (IsRealValue(aValue)) ||
176 IsIntegerValue(aValue)||
177 IsBooleanValue(aValue))
183 //============================================================================
184 /*! Function : GetVariableItem
187 //============================================================================
188 QTableWidgetItem* NoteBook_TableRow::GetVariableItem()
190 return myVariableValue;
193 //============================================================================
194 /*! Function : GetNameItem
197 //============================================================================
198 QTableWidgetItem* NoteBook_TableRow::GetNameItem()
200 return myVariableName;
203 //============================================================================
204 /*! Function : GetHeaderItem
207 //============================================================================
208 QTableWidgetItem* NoteBook_TableRow::GetHeaderItem()
213 //============================================================================
214 /*! Function : IsRealValue
215 * Purpose : Return true if theValue string is real value, otherwise return
218 //============================================================================
219 bool NoteBook_TableRow::IsRealValue(const QString theValue, double* theResult)
221 bool aResult = false;
222 double aDResult = theValue.toDouble(&aResult);
224 *theResult = aDResult;
229 //============================================================================
230 /*! Function : IsBooleanValue
231 * Purpose : Return true if theValue String is boolean value, otherwise return
234 //============================================================================
235 bool NoteBook_TableRow::IsBooleanValue(const QString theValue, bool* theResult){
236 bool aResult = false;
238 if(theValue.compare("True") == 0) {
242 else if(theValue.compare("False") == 0) {
247 *theResult = aBResult;
252 //============================================================================
253 /*! Function : IsIntegerValue
254 * Purpose : Return true if theValue string is integer value, otherwise return
257 //============================================================================
258 bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult)
260 bool aResult = false;
262 anIResult = theValue.toInt(&aResult);
265 *theResult = anIResult;
271 ///////////////////////////////////////////////////////////////////////////
272 // NoteBook_Table class //
273 ///////////////////////////////////////////////////////////////////////////
274 //============================================================================
275 /*! Function : NoteBook_Table
276 * Purpose : Constructor
278 //============================================================================
279 NoteBook_Table::NoteBook_Table(QWidget * parent)
280 :QTableWidget(parent),
281 isProcessItemChangedSignal(false),
285 setSelectionMode(QAbstractItemView::SingleSelection);
287 //Add Headers Columns
288 QFont aFont = QFont();
290 aFont.setPointSize(10);
293 QTableWidgetItem * aNameHeader = new QTableWidgetItem();
294 aNameHeader->setText(tr("VARNAME_COLUMN"));
295 aNameHeader->setFont(aFont);
296 setHorizontalHeaderItem(0,aNameHeader);
297 setColumnWidth ( 0, COLUMN_SIZE);
300 QTableWidgetItem * aValueHeader = new QTableWidgetItem();
301 aValueHeader->setText(tr("VARVALUE_COLUMN"));
302 aValueHeader->setFont(aFont);
303 setHorizontalHeaderItem(1,aValueHeader);
304 setColumnWidth ( 1, COLUMN_SIZE);
305 setSortingEnabled(false);
307 connect(this,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(onItemChanged(QTableWidgetItem*)));
310 //============================================================================
311 /*! Function : ~NoteBook_Table
312 * Purpose : Destructor
314 //============================================================================
315 NoteBook_Table::~NoteBook_Table(){}
317 //============================================================================
318 /*! Function : getUniqueIndex
319 * Purpose : Get a unique index for the new row
321 //============================================================================
322 int NoteBook_Table::getUniqueIndex() const
325 if( !myRows.isEmpty() )
326 if( NoteBook_TableRow* aRow = myRows.last() )
327 anIndex = aRow->GetIndex();
329 int aMaxRemovedRow = 0;
330 for( QListIterator<int> anIter( myRemovedRows ); anIter.hasNext(); )
332 int aRemovedRow = anIter.next();
333 aMaxRemovedRow = qMax( aRemovedRow, aMaxRemovedRow );
336 anIndex = qMax( anIndex, aMaxRemovedRow ) + 1;
340 //============================================================================
342 * Purpose : Add variables in the table from theStudy
344 //============================================================================
345 void NoteBook_Table::Init(_PTR(Study) theStudy)
347 isProcessItemChangedSignal = false;
349 int aNumRows = myRows.count();
352 for( int i = 0; i < myRows.size(); i++ )
354 NoteBook_TableRow* aRow = myRows[ i ];
365 myRemovedRows.clear();
366 myVariableMapRef.clear();
367 myVariableMap.clear();
369 //Add all variables into the table
370 vector<string> aVariables = theStudy->GetVariableNames();
371 for(int iVar = 0; iVar < aVariables.size(); iVar++ ) {
372 AddRow(QString(aVariables[iVar].c_str()),
373 Variable2String(aVariables[iVar],theStudy));
378 isProcessItemChangedSignal = true;
385 //============================================================================
386 /*! Function : Variable2String
387 * Purpose : Convert variable values to QString
389 //============================================================================
390 QString NoteBook_Table::Variable2String(const string& theVarName,
391 _PTR(Study) theStudy)
394 if( theStudy->IsReal(theVarName) )
395 aResult = QString::number(theStudy->GetReal(theVarName));
396 else if( theStudy->IsInteger(theVarName) )
397 aResult = QString::number(theStudy->GetInteger(theVarName));
398 else if( theStudy->IsBoolean(theVarName) )
399 aResult = theStudy->GetBoolean(theVarName) ? QString("True") : QString("False");
404 //============================================================================
405 /*! Function : IsValid
406 * Purpose : Check validity of the table data
408 //============================================================================
409 bool NoteBook_Table::IsValid() const
411 int aNumRows = myRows.count();
415 bool aLastRowIsEmpty = myRows[ aNumRows - 1 ]->GetName().isEmpty() &&
416 myRows[ aNumRows - 1 ]->GetValue().isEmpty();
418 for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ )
419 if( !myRows[i]->CheckName() || !IsUniqueName( myRows[i] ) || !myRows[i]->CheckValue() )
425 //============================================================================
426 /*! Function : RenamberRowItems
427 * Purpose : renumber row items
429 //============================================================================
430 void NoteBook_Table::RenamberRowItems(){
431 for(int i=0; i<myRows.size();i++){
432 myRows[i]->GetHeaderItem()->setText(QString::number(i+1));
436 //============================================================================
437 /*! Function : AddRow
438 * Purpose : Add a row into the table
440 //============================================================================
441 void NoteBook_Table::AddRow(const QString& theName, const QString& theValue)
443 int anIndex = getUniqueIndex();
444 NoteBook_TableRow* aRow = new NoteBook_TableRow(anIndex, this);
445 aRow->SetName(theName);
446 aRow->SetValue(theValue);
447 aRow->AddToTable(this);
450 myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theValue ) );
453 //============================================================================
454 /*! Function : AddEmptyRow
455 * Purpose : Add an empty row into the end of the table
457 //============================================================================
458 void NoteBook_Table::AddEmptyRow()
460 isProcessItemChangedSignal = false;
462 isProcessItemChangedSignal = true;
465 //============================================================================
466 /*! Function : GetRowByItem
469 //============================================================================
470 NoteBook_TableRow* NoteBook_Table::GetRowByItem(const QTableWidgetItem* theItem) const
472 int aCurrentRow = row(theItem);
474 if( (myRows.size() <= aCurrentRow ) && (aCurrentRow < 0))
477 return myRows.at(aCurrentRow);
480 //============================================================================
481 /*! Function : IsLastRow
482 * Purpose : Return true if theRow is last row in the table
484 //============================================================================
485 bool NoteBook_Table::IsLastRow(const NoteBook_TableRow* theRow) const
487 return (myRows.last() == theRow);
490 //============================================================================
491 /*! Function : onItemChanged
492 * Purpose : [slot] called then table item changed
494 //============================================================================
495 void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem)
497 if(isProcessItemChangedSignal) {
498 bool isModified = true;
499 NoteBook_TableRow* aRow = GetRowByItem(theItem);
501 int aCurrentColumn = column(theItem);
502 bool IsCorrect = true, IsVariableComplited = false;
505 if(aCurrentColumn == NAME_COLUMN) {
506 int anIndex = aRow->GetIndex();
507 if( myVariableMap.contains( anIndex ) )
509 const NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];
510 if( !aVariable.Name.isEmpty() && myStudy->IsVariableUsed( string( aVariable.Name.toLatin1().constData() ) ) )
512 if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),
513 tr( "RENAME_VARIABLE_IS_USED" ).arg( aVariable.Name ),
514 QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
516 bool isBlocked = blockSignals( true );
517 aRow->SetName( aVariable.Name );
518 blockSignals( isBlocked );
525 //Case then varible name changed.
526 if(aCurrentColumn == NAME_COLUMN) {
527 if(!aRow->CheckName()) {
529 aMsg = tr( "VARNAME_INCORRECT" ).arg(aRow->GetName());
531 else if(!IsUniqueName(aRow)) {
533 aMsg = tr( "VARNAME_EXISTS" ).arg(aRow->GetName());
536 IsVariableComplited = aRow->CheckValue();
539 //Case then varible value changed.
540 else if(aCurrentColumn == VALUE_COLUMN){
541 if(!aRow->CheckValue()) {
543 aMsg = tr( "VARVALUE_INCORRECT" ).arg(aRow->GetName());
546 IsVariableComplited = aRow->CheckName() && IsUniqueName(aRow);
549 if(!IsCorrect && !aMsg.isEmpty())
550 SUIT_MessageBox::warning( parentWidget(), tr( "WARNING" ), aMsg );
552 bool isBlocked = blockSignals( true );
553 theItem->setForeground( QBrush( IsCorrect ? Qt::black : Qt::red ) );
554 blockSignals( isBlocked );
556 int anIndex = aRow->GetIndex();
557 if( myVariableMap.contains( anIndex ) )
559 NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];
560 if( aVariable.Name.compare( aRow->GetName() ) != 0 ||
561 aVariable.Value.compare( aRow->GetValue() ) != 0 )
563 aVariable.Name = aRow->GetName();
564 aVariable.Value = aRow->GetValue();
570 if(IsCorrect && IsVariableComplited && IsLastRow(aRow))
575 myIsModified = isModified;
579 //============================================================================
580 /*! Function : IsUniqueName
581 * Purpose : Return true if theName is unique name of the Variable
583 //============================================================================
584 bool NoteBook_Table::IsUniqueName(const NoteBook_TableRow* theRow) const
586 for(int i=0; i<myRows.size();i++) {
587 if(myRows[i] == theRow )
589 if(myRows[i]->GetName().compare(theRow->GetName()) == 0)
595 //============================================================================
596 /*! Function : RemoveSelected
597 * Purpose : Remove selected rows in the table
599 //============================================================================
600 void NoteBook_Table::RemoveSelected()
602 isProcessItemChangedSignal = false;
603 QList<QTableWidgetItem*> aSelectedItems = selectedItems();
604 if( !(aSelectedItems.size() > 0)) {
605 isProcessItemChangedSignal = true;
608 bool removedFromStudy = false;
609 for(int i=0; i < aSelectedItems.size(); i++ ) {
610 NoteBook_TableRow* aRow = GetRowByItem(aSelectedItems[i]);
612 if(IsLastRow(aRow)) {
613 aRow->SetName(QString());
614 aRow->SetValue(QString());
617 int nRow = row(aSelectedItems[i]);
619 if( myStudy->IsVariableUsed( string( aRow->GetName().toLatin1().constData() ) ) )
621 if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),
622 tr( "REMOVE_VARIABLE_IS_USED" ).arg( aRow->GetName() ),
623 QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
625 isProcessItemChangedSignal = true;
630 int index = aRow->GetIndex();
631 QString aVarName = aRow->GetName();
632 myRemovedRows.append( index );
633 if( myVariableMap.contains( index ) )
634 myVariableMap.remove( index );
636 myRows.removeAt(nRow);
637 if(myStudy->IsVariable(aVarName.toLatin1().constData()))
638 removedFromStudy = true;
645 isProcessItemChangedSignal = true;
648 //============================================================================
649 /*! Function : SetProcessItemChangedSignalFlag
652 //============================================================================
653 void NoteBook_Table::SetProcessItemChangedSignalFlag(const bool enable)
655 isProcessItemChangedSignal = enable;
658 //============================================================================
659 /*! Function : GetProcessItemChangedSignalFlag
662 //============================================================================
663 bool NoteBook_Table::GetProcessItemChangedSignalFlag() const
665 return isProcessItemChangedSignal;
668 //============================================================================
669 /*! Function : GetRows
672 //============================================================================
673 QList<NoteBook_TableRow*> NoteBook_Table::GetRows() const
678 //============================================================================
679 /*! Function : ResetMaps
680 * Purpose : Reset variable maps
682 //============================================================================
683 void NoteBook_Table::ResetMaps()
685 myIsModified = false;
686 myVariableMapRef = myVariableMap;
687 myRemovedRows.clear();
690 ///////////////////////////////////////////////////////////////////////////
691 // SalomeApp_NoteBookDlg class //
692 ///////////////////////////////////////////////////////////////////////////
693 //============================================================================
694 /*! Function : SalomeApp_NoteBookDlg
695 * Purpose : Constructor
697 //============================================================================
698 SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg(QWidget * parent, _PTR(Study) theStudy):
699 QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
703 setObjectName("SalomeApp_NoteBookDlg");
704 setWindowTitle(tr("NOTEBOOK_TITLE"));
705 QGridLayout* aLayout = new QGridLayout(this);
706 aLayout->setMargin(DEFAULT_MARGIN);
707 aLayout->setSpacing(DEFAULT_SPACING);
710 myTable = new NoteBook_Table(this);
711 aLayout->addWidget(myTable, 0, 0, 1, 3);
714 myRemoveButton = new QPushButton(tr("BUT_REMOVE"));
715 aLayout->addWidget(myRemoveButton, 1, 0, 1, 1);
717 QSpacerItem* spacer =
718 new QSpacerItem(DEFAULT_SPACING, 5 , QSizePolicy::Expanding, QSizePolicy::Minimum);
719 aLayout->addItem(spacer, 1, 1, 2, 1);
721 myUpdateStudyBtn = new QPushButton(tr("BUT_UPDATE_STUDY"));
722 aLayout->addWidget(myUpdateStudyBtn, 1, 2, 1, 1);
724 QGroupBox* groupBox = new QGroupBox(this);
726 QGridLayout* aLayout1 = new QGridLayout(groupBox);
728 aLayout1->setMargin(DEFAULT_MARGIN);
729 aLayout1->setSpacing(DEFAULT_SPACING);
731 myOkBtn = new QPushButton(tr("BUT_APPLY_AND_CLOSE"));
732 aLayout1->addWidget(myOkBtn, 0, 0, 1, 1);
734 myApplyBtn = new QPushButton(tr("BUT_APPLY"));
735 aLayout1->addWidget(myApplyBtn, 0, 1, 1, 1);
737 QSpacerItem* spacer1 =
738 new QSpacerItem(DEFAULT_SPACING, 5, QSizePolicy::Expanding, QSizePolicy::Minimum);
739 aLayout1->addItem(spacer1, 0, 2, 1, 1);
741 myCancelBtn = new QPushButton(tr("BUT_CLOSE"));
742 aLayout1->addWidget(myCancelBtn, 0, 3, 1, 1);
744 myHelpBtn = new QPushButton(tr("BUT_HELP"));
745 aLayout1->addWidget(myHelpBtn, 0, 4, 1, 1);
747 aLayout->addWidget(groupBox, 2, 0, 1, 3);
749 QWidgetList aWidgetList;
750 aWidgetList.append( myTable );
751 aWidgetList.append( myOkBtn );
752 aWidgetList.append( myApplyBtn );
753 aWidgetList.append( myCancelBtn );
754 aWidgetList.append( myHelpBtn );
755 aWidgetList.append( myUpdateStudyBtn );
756 aWidgetList.append( myRemoveButton );
757 Qtx::setTabOrder( aWidgetList );
759 connect( myOkBtn, SIGNAL(clicked()), this, SLOT(onOK()) );
760 connect( myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()) );
761 connect( myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()) );
762 connect( myUpdateStudyBtn, SIGNAL(clicked()), this, SLOT(onUpdateStudy()) );
763 connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
764 connect( myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
766 myTable->Init(myStudy);
769 //============================================================================
770 /*! Function : ~SalomeApp_NoteBookDlg
771 * Purpose : Destructor
773 //============================================================================
774 SalomeApp_NoteBookDlg::~SalomeApp_NoteBookDlg(){}
777 //============================================================================
778 /*! Function : Init()
779 * Purpose : init variable table
781 //============================================================================
782 void SalomeApp_NoteBookDlg::Init(_PTR(Study) theStudy){
783 if(myStudy!= theStudy)
785 myTable->Init(myStudy);
789 //============================================================================
793 //============================================================================
794 void SalomeApp_NoteBookDlg::onOK()
797 if( myTable->IsValid() )
801 //============================================================================
802 /*! Function : onHelp
805 //============================================================================
806 void SalomeApp_NoteBookDlg::onHelp()
808 QString aHelpFileName("using_notebook.html");
809 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
811 app->onHelpContextModule("GUI",aHelpFileName);
815 platform = "winapplication";
817 platform = "application";
819 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
820 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
821 arg(app->resourceMgr()->stringValue("ExternalBrowser",
827 //============================================================================
828 /*! Function : onApply
831 //============================================================================
832 void SalomeApp_NoteBookDlg::onApply()
834 if( !myTable->IsValid() )
836 SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_DATA" ) );
844 const QList<int>& aRemovedRows = myTable->GetRemovedRows();
845 const VariableMap& aVariableMap = myTable->GetVariableMap();
846 const VariableMap& aVariableMapRef = myTable->GetVariableMapRef();
848 for( QListIterator<int> anIter( aRemovedRows ); anIter.hasNext(); )
850 int anIndex = anIter.next();
851 if( aVariableMapRef.contains( anIndex ) )
853 QString aRemovedVariable = aVariableMapRef[ anIndex ].Name;
854 myStudy->RemoveVariable( string( aRemovedVariable.toLatin1().constData() ) );
858 VariableMap::const_iterator it = aVariableMap.constBegin(), itEnd = aVariableMap.constEnd();
859 for( ; it != itEnd; ++it )
861 int anIndex = it.key();
862 const NoteBoox_Variable& aVariable = it.value();
863 QString aName = aVariable.Name;
864 QString aValue = aVariable.Value;
866 if( !aName.isEmpty() && !aValue.isEmpty() )
868 if( aVariableMapRef.contains( anIndex ) )
870 const NoteBoox_Variable& aVariableRef = aVariableMapRef[ anIndex ];
871 QString aNameRef = aVariableRef.Name;
872 QString aValueRef = aVariableRef.Value;
874 if( !aNameRef.isEmpty() && !aValueRef.isEmpty() && aNameRef != aName )
876 myStudy->RenameVariable( string( aNameRef.toLatin1().constData() ),
877 string( aName.toLatin1().constData() ) );
881 if( NoteBook_TableRow::IsIntegerValue(aValue,&anIVal) )
882 myStudy->SetInteger(string(aName.toLatin1().constData()),anIVal);
884 else if( NoteBook_TableRow::IsRealValue(aValue,&aDVal) )
885 myStudy->SetReal(string(aName.toLatin1().constData()),aDVal);
887 else if( NoteBook_TableRow::IsBooleanValue(aValue,&aBVal) )
888 myStudy->SetBoolean(string(aName.toLatin1().constData()),aBVal);
891 myTable->ResetMaps();
893 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
895 app->updateActions();
899 //============================================================================
900 /*! Function : onCancel
903 //============================================================================
904 void SalomeApp_NoteBookDlg::onCancel()
906 if( myTable->IsModified() )
908 int answer = QMessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "CLOSE_DESCRIPTION" ),
909 QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel );
912 case QMessageBox::Yes : onOK(); return;
913 case QMessageBox::No : break;
914 case QMessageBox::Cancel : return;
921 //============================================================================
922 /*! Function : onRemove
925 //============================================================================
926 void SalomeApp_NoteBookDlg::onRemove()
928 myTable->RemoveSelected();
931 //============================================================================
932 /*! Function : onUpdateStudy
935 //============================================================================
936 void SalomeApp_NoteBookDlg::onUpdateStudy()
939 if( !myTable->IsValid() )
942 QApplication::setOverrideCursor( Qt::WaitCursor );
945 SUIT_MessageBox::warning( this, tr( "ERROR" ), tr( "ERR_UPDATE_STUDY_FAILED" ) );
947 QApplication::restoreOverrideCursor();
950 //============================================================================
951 /*! Function : updateStudy
954 //============================================================================
955 bool SalomeApp_NoteBookDlg::updateStudy()
957 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
961 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
965 bool isStudySaved = study->isSaved();
966 QString aStudyName = study->studyName();
968 _PTR(Study) studyDS = study->studyDS();
970 // get unique temporary directory name
971 QString aTmpDir = QString::fromStdString( SALOMEDS_Tool::GetTmpDir() );
972 if( aTmpDir.isEmpty() )
975 if( aTmpDir.right( 1 ).compare( QDir::separator() ) == 0 )
976 aTmpDir.remove( aTmpDir.length() - 1, 1 );
978 // dump study to the temporary directory
979 QString aFileName( "notebook" );
980 bool toPublish = true;
981 bool toSaveGUI = true;
984 _PTR(AttributeParameter) ap;
985 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
986 if(ip->isDumpPython(studyDS)) ip->setDumpPython(studyDS); //Unset DumpPython flag.
987 if ( toSaveGUI ) { //SRN: Store a visual state of the study at the save point for DumpStudy method
988 ip->setDumpPython(studyDS);
989 savePoint = SalomeApp_VisualState( app ).storeState(); //SRN: create a temporary save point
991 bool ok = studyDS->DumpStudy( aTmpDir.toStdString(), aFileName.toStdString(), toPublish );
993 study->removeSavePoint(savePoint); //SRN: remove the created temporary save point.
998 // clear a study (delete all objects)
1001 // get active application
1002 app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1004 // load study from the temporary directory
1005 QString command = QString( "execfile(\"%1\")" ).arg( aTmpDir + QDir::separator() + aFileName + ".py" );
1007 PyConsole_Console* pyConsole = app->pythonConsole();
1009 pyConsole->execAndWait( command );
1011 // remove temporary directory
1012 QDir aDir( aTmpDir );
1013 QStringList aFiles = aDir.entryList( QStringList( "*.py*" ) );
1014 for( QStringList::iterator it = aFiles.begin(), itEnd = aFiles.end(); it != itEnd; ++it )
1015 ok = aDir.remove( *it ) && ok;
1017 ok = aDir.rmdir( aTmpDir );
1019 if( SalomeApp_Study* newStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) )
1021 myStudy = newStudy->studyDS();
1022 myTable->Init(myStudy);
1024 newStudy->markAsSavedIn(aStudyName);
1033 //============================================================================
1034 /*! Function : clearStudy
1037 //============================================================================
1038 void SalomeApp_NoteBookDlg::clearStudy()
1040 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1044 QList<SUIT_Application*> aList = SUIT_Session::session()->applications();
1045 int anIndex = aList.indexOf( app );
1047 //Store position and size of the this dialog
1053 // Disconnect dialog from application desktop in case if:
1054 // 1) Application is not the first application in the session
1055 // 2) Application is the first application in session but not the only.
1056 bool changeDesktop = ((anIndex > 0) || (anIndex == 0 && aList.count() > 1));
1061 app->onCloseDoc( false );
1063 if( anIndex > 0 && anIndex < aList.count() )
1064 app = dynamic_cast<SalomeApp_Application*>( aList[ anIndex - 1 ] );
1065 else if(anIndex == 0 && aList.count() > 1)
1066 app = dynamic_cast<SalomeApp_Application*>( aList[ 1 ] );
1073 app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1074 if( changeDesktop && app ) {
1075 setParent( app->desktop(), Qt::Dialog );
1076 app->setNoteBook(this);
1078 //Set position and size of the this dialog