Salome HOME
updated copyright message
[modules/gui.git] / src / SalomeApp / SalomeApp_NoteBook.cxx
index af848322c7f682e874afbe1cd5a4b0ae1a27d323..4090d44b4267090168e37da80239712b5c86f49b 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // 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.
+// 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
@@ -21,8 +21,8 @@
 // Author : Roman NIKOLAEV, Open CASCADE S.A.S.
 // Module : GUI
 //
-#include <PyConsole_Interp.h> // this include must be first (see PyInterp_base.h)!
-#include <PyConsole_Console.h>
+#include "PyConsole_Interp.h" // this include must be first (see PyInterp_base.h)!
+#include "PyConsole_Console.h"
 
 #include "SalomeApp_NoteBook.h"
 #include "SalomeApp_Application.h"
@@ -71,8 +71,8 @@
 //============================================================================
 NoteBook_TableRow::NoteBook_TableRow(int index, NoteBook_Table* parentTable, QWidget* parent):
   QWidget(parent),
-  myParentTable(parentTable),
   myIndex(index),
+  myParentTable(parentTable),
   myRowHeader(new QTableWidgetItem()),
   myVariableName(new QTableWidgetItem()),
   myVariableValue(new QTableWidgetItem())
@@ -274,7 +274,7 @@ bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult)
  *             The whole notebook is verified on apply
  */
 //============================================================================
-bool NoteBook_TableRow::IsValidStringValue(const QString theValue)
+bool NoteBook_TableRow::IsValidStringValue(const QString /*theValue*/)
 {
   int aNumRows = myParentTable->myRows.count();
   if( aNumRows == 0 )
@@ -285,8 +285,8 @@ bool NoteBook_TableRow::IsValidStringValue(const QString theValue)
 
   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
   PyConsole_Console* pyConsole = app->pythonConsole();
-  PyConsole_Interp* pyInterp = pyConsole->getInterp();
-  PyLockWrapper aLock = pyInterp->GetLockWrapper();
+  PyConsole_Interp* pyInterp = app->getPyInterp();
+  PyLockWrapper aLock; // Acquire GIL
   std::string command = "import salome_notebook ; ";
   command += "salome_notebook.checkThisNoteBook(";
   for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ ) {
@@ -378,7 +378,7 @@ int NoteBook_Table::getUniqueIndex() const
  *  Purpose  : Add variables in the table from theStudy
  */
 //============================================================================
-void NoteBook_Table::Init(_PTR(Study) theStudy)
+void NoteBook_Table::Init()
 {
   isProcessItemChangedSignal = false;
 
@@ -403,10 +403,10 @@ void NoteBook_Table::Init(_PTR(Study) theStudy)
   myVariableMap.clear();
 
   //Add all variables into the table
-  std::vector<std::string> aVariables = theStudy->GetVariableNames();
-  for(int iVar = 0; iVar < aVariables.size(); iVar++ ) {
+  std::vector<std::string> aVariables = SalomeApp_Application::getStudy()->GetVariableNames();
+  for(int iVar = 0; iVar < (int)aVariables.size(); iVar++ ) {
     AddRow(QString(aVariables[iVar].c_str()),
-           Variable2String(aVariables[iVar],theStudy));
+           Variable2String(aVariables[iVar]));
   }
 
   //Add empty row
@@ -414,8 +414,6 @@ void NoteBook_Table::Init(_PTR(Study) theStudy)
   isProcessItemChangedSignal = true;
 
   ResetMaps();
-
-  myStudy = theStudy;
 }
 
 //============================================================================
@@ -423,18 +421,18 @@ void NoteBook_Table::Init(_PTR(Study) theStudy)
  *  Purpose  : Convert variable values to QString
  */
 //============================================================================
-QString NoteBook_Table::Variable2String(const std::string& theVarName,
-                                        _PTR(Study) theStudy)
+QString NoteBook_Table::Variable2String(const std::string& theVarName)
 {
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
   QString aResult;
-  if( theStudy->IsReal(theVarName) )
-    aResult = QString::number(theStudy->GetReal(theVarName));
-  else if( theStudy->IsInteger(theVarName) )
-    aResult = QString::number(theStudy->GetInteger(theVarName));
-  else if( theStudy->IsBoolean(theVarName) )
-    aResult = theStudy->GetBoolean(theVarName) ? QString("True") : QString("False");
-  else if( theStudy->IsString(theVarName) )
-    aResult = theStudy->GetString(theVarName).c_str();
+  if( aStudy->IsReal(theVarName) )
+    aResult = QString::number(aStudy->GetReal(theVarName));
+  else if( aStudy->IsInteger(theVarName) )
+    aResult = QString::number(aStudy->GetInteger(theVarName));
+  else if( aStudy->IsBoolean(theVarName) )
+    aResult = aStudy->GetBoolean(theVarName) ? QString("True") : QString("False");
+  else if( aStudy->IsString(theVarName) )
+    aResult = aStudy->GetString(theVarName).c_str();
   
   return aResult;
 }
@@ -459,8 +457,8 @@ bool NoteBook_Table::IsValid() const
 
   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
   PyConsole_Console* pyConsole = app->pythonConsole();
-  PyConsole_Interp* pyInterp = pyConsole->getInterp();
-  PyLockWrapper aLock = pyInterp->GetLockWrapper();
+  PyConsole_Interp* pyInterp = app->getPyInterp();
+  PyLockWrapper aLock; // Acquire GIL
   std::string command = "import salome_notebook ; ";
   command += "salome_notebook.checkThisNoteBook(";
   for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ )
@@ -566,7 +564,7 @@ void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem)
         if( myVariableMap.contains( anIndex ) )
         {
           const NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];
-          if( !aVariable.Name.isEmpty() && myStudy->IsVariableUsed( std::string( aVariable.Name.toLatin1().constData() ) ) )
+          if( !aVariable.Name.isEmpty() && SalomeApp_Application::getStudy()->IsVariableUsed( std::string( aVariable.Name.toUtf8().constData() ) ) )
           {
             if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),
                                       tr( "RENAME_VARIABLE_IS_USED" ).arg( aVariable.Name ),
@@ -661,6 +659,7 @@ bool NoteBook_Table::IsUniqueName(const NoteBook_TableRow* theRow) const
 //============================================================================
 void NoteBook_Table::RemoveSelected()
 {
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
   isProcessItemChangedSignal = false;
   QList<QTableWidgetItem*> aSelectedItems = selectedItems();
   if( !(aSelectedItems.size() > 0)) {
@@ -678,7 +677,7 @@ void NoteBook_Table::RemoveSelected()
       else {
         int nRow = row(aSelectedItems[i]);
 
-        if( myStudy->IsVariableUsed( std::string( aRow->GetName().toLatin1().constData() ) ) )
+        if( aStudy->IsVariableUsed( std::string( aRow->GetName().toUtf8().constData() ) ) )
         {
           if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),
                                     tr( "REMOVE_VARIABLE_IS_USED" ).arg( aRow->GetName() ),
@@ -696,7 +695,7 @@ void NoteBook_Table::RemoveSelected()
           myVariableMap.remove( index );
         removeRow(nRow);
         myRows.removeAt(nRow);
-        if(myStudy->IsVariable(aVarName.toLatin1().constData()))
+        if(aStudy->IsVariable(aVarName.toUtf8().constData()))
           removedFromStudy = true;
       }
     }
@@ -757,9 +756,8 @@ void NoteBook_Table::ResetMaps()
  *  Purpose  : Constructor
  */
 //============================================================================
-SalomeApp_NoteBook::SalomeApp_NoteBook(QWidget * parent, _PTR(Study) theStudy):
-  QWidget(parent),
-  myStudy(theStudy)
+SalomeApp_NoteBook::SalomeApp_NoteBook(QWidget * parent):
+  QWidget(parent)
 {
   setObjectName("SalomeApp_NoteBook");
   setWindowTitle(tr("NOTEBOOK_TITLE"));
@@ -789,7 +787,7 @@ SalomeApp_NoteBook::SalomeApp_NoteBook(QWidget * parent, _PTR(Study) theStudy):
   connect( myUpdateStudyBtn, SIGNAL(clicked()), this, SLOT(onUpdateStudy()) );
   connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
   
-  myTable->Init(myStudy);
+  myTable->Init();
 
   myDumpedStudyScript = "";  
   myIsDumpedStudySaved = false;
@@ -808,10 +806,8 @@ SalomeApp_NoteBook::~SalomeApp_NoteBook(){}
  *  Purpose  : init variable table
  */
 //============================================================================
-void SalomeApp_NoteBook::Init(_PTR(Study) theStudy){
-  if(myStudy!= theStudy)
-    myStudy = theStudy;
-  myTable->Init(myStudy);
+void SalomeApp_NoteBook::Init(){
+  myTable->Init();
 }
 
 
@@ -820,9 +816,9 @@ void SalomeApp_NoteBook::Init(_PTR(Study) theStudy){
  *  Purpose  : [slot]
  */
 //============================================================================
-void SalomeApp_NoteBook::onVarUpdate(QString theVarName)
+void SalomeApp_NoteBook::onVarUpdate(QString /*theVarName*/)
 {
-  myTable->Init(myStudy);
+  myTable->Init();
 }
 
 //============================================================================
@@ -837,6 +833,7 @@ void SalomeApp_NoteBook::onApply()
     SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_DATA" ) );
     return;
   }
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
 
   double aDVal;
   int    anIVal;
@@ -852,7 +849,7 @@ void SalomeApp_NoteBook::onApply()
     if( aVariableMapRef.contains( anIndex ) )
     {
       QString aRemovedVariable = aVariableMapRef[ anIndex ].Name;
-      myStudy->RemoveVariable( std::string( aRemovedVariable.toLatin1().constData() ) );
+      aStudy->RemoveVariable( std::string( aRemovedVariable.toUtf8().constData() ) );
     }
   }
 
@@ -874,22 +871,22 @@ void SalomeApp_NoteBook::onApply()
 
         if( !aNameRef.isEmpty() && !aValueRef.isEmpty() && aNameRef != aName )
         {
-          myStudy->RenameVariable( std::string( aNameRef.toLatin1().constData() ),
-                                   std::string( aName.toLatin1().constData() ) );
+          aStudy->RenameVariable( std::string( aNameRef.toUtf8().constData() ),
+                                  std::string( aName.toUtf8().constData() ) );
         }
       }
 
       if( NoteBook_TableRow::IsIntegerValue(aValue,&anIVal) )
-        myStudy->SetInteger(std::string(aName.toLatin1().constData()),anIVal);
+        aStudy->SetInteger(std::string(aName.toUtf8().constData()),anIVal);
 
       else if( NoteBook_TableRow::IsRealValue(aValue,&aDVal) )
-        myStudy->SetReal(std::string(aName.toLatin1().constData()),aDVal);
+        aStudy->SetReal(std::string(aName.toUtf8().constData()),aDVal);
     
       else if( NoteBook_TableRow::IsBooleanValue(aValue,&aBVal) )
-        myStudy->SetBoolean(std::string(aName.toLatin1().constData()),aBVal);
+        aStudy->SetBoolean(std::string(aName.toUtf8().constData()),aBVal);
     
       else
-        myStudy->SetString(std::string(aName.toLatin1().constData()),aValue.toStdString());
+        aStudy->SetString(std::string(aName.toUtf8().constData()),aValue.toStdString());
     }
   }
   myTable->ResetMaps();
@@ -898,7 +895,7 @@ void SalomeApp_NoteBook::onApply()
   if(app)
     app->updateActions();
   
-  myStudy->Modified();
+  aStudy->Modified();
 }
 
 //============================================================================