Salome HOME
Merge branch 'master' into pre/penta18
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshPatternDlg.cxx
index 8456928f772b1cd96094c5d28c172ea1186fbcc9..53e60ce65f9153acf8287c81e517ca0a0bb30952 100755 (executable)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, 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) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // SMESH SMESHGUI : GUI for SMESH component
 // File   : SMESHGUI_MeshPatternDlg.cxx
 // Author : Sergey LITONIN, Open CASCADE S.A.S.
@@ -118,13 +119,13 @@ SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( SMESHGUI* theModule )
   aDlgLay->setMargin( MARGIN );
   aDlgLay->setSpacing( SPACING );
 
-  QWidget* aMainFrame = createMainFrame  ( this );
+  myMainFrame = createMainFrame  ( this );
   QWidget* aBtnFrame  = createButtonFrame( this );
 
-  aDlgLay->addWidget( aMainFrame );
+  aDlgLay->addWidget( myMainFrame );
   aDlgLay->addWidget( aBtnFrame );
 
-  aDlgLay->setStretchFactor( aMainFrame, 1 );
+  aDlgLay->setStretchFactor( myMainFrame, 1 );
 
   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
 
@@ -351,7 +352,7 @@ QWidget* SMESHGUI_MeshPatternDlg::createButtonFrame (QWidget* theParent)
   aLay->addWidget(myHelpBtn);
 
   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
-  connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
+  connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
   connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
 
@@ -389,7 +390,9 @@ void SMESHGUI_MeshPatternDlg::Init()
   // selection and SMESHGUI
   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
-  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
+  connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT( onOpenView()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT( onCloseView()));
 
   myTypeGrp->button(Type_2d)->setChecked(true);
   onTypeChanged(Type_2d);
@@ -397,7 +400,7 @@ void SMESHGUI_MeshPatternDlg::Init()
 
   updateGeometry();
 
-  resize(minimumSize());
+  resize(100,100);
 
   activateSelection();
   onSelectionDone();
@@ -420,10 +423,10 @@ bool SMESHGUI_MeshPatternDlg::isValid (const bool theMess)
       ok = myNode2->isValid( msg, theMess ) && ok;
     if( !ok ) {
       if( theMess ) {
-       QString str( tr( "SMESH_INCORRECT_INPUT" ) );
-       if ( !msg.isEmpty() )
-         str += "\n" + msg;
-       SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
+        QString str( tr( "SMESH_INCORRECT_INPUT" ) );
+        if ( !msg.isEmpty() )
+          str += "\n" + msg;
+        SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
       }
       return false;
     }
@@ -432,22 +435,22 @@ bool SMESHGUI_MeshPatternDlg::isValid (const bool theMess)
   QList<int> ids;
   if ((isRefine() &&
        (myMesh->_is_nil() || !getIds(ids) || getNode(false) < 0 ||
-        myType == Type_3d && (getNode(true) < 0 || getNode(false) == getNode(true))))
+        (myType == Type_3d && (getNode(true) < 0 || getNode(false) == getNode(true)))))
       ||
       (!isRefine() &&
        (myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() ||
-        myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil())))
+        myGeomObj[ Vertex1 ]->_is_nil() || (myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil()))))
   {
     if (theMess)
       SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
-                                  tr("SMESHGUI_INVALID_PARAMETERS"));
+                                   tr("SMESHGUI_INVALID_PARAMETERS"));
     return false;
   }
 
   if ( myName->text().isEmpty() ) {
     if (theMess)
       SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
-                                  tr("SMESHGUI_INVALID_PARAMETERS"));
+                                   tr("SMESHGUI_INVALID_PARAMETERS"));
     return false;
   }
 
@@ -467,22 +470,23 @@ bool SMESHGUI_MeshPatternDlg::onApply()
     erasePreview();
 
     if (isRefine()) { // Refining existing mesh elements
+      {
+        QStringList aParameters;
+        aParameters << myNode1->text();
+        if(myType == Type_3d )
+          aParameters << myNode2->text();
+        myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
+      }
       QList<int> ids;
       getIds(ids);
       SMESH::long_array_var varIds = new SMESH::long_array();
       varIds->length(ids.count());
       int i = 0;
       for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
-       varIds[i++] = *it;
+        varIds[i++] = *it;
       myType == Type_2d
-       ? myPattern->ApplyToMeshFaces  (myMesh, varIds, getNode(false), myReverseChk->isChecked())
-       : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
-
-      QStringList aParameters;
-      aParameters << myNode1->text();
-      if(myType == Type_3d )
-       aParameters << myNode2->text();
-      myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
+        ? myPattern->ApplyToMeshFaces  (myMesh, varIds, getNode(false), myReverseChk->isChecked())
+        : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
 
     } else { // Applying a pattern to geometrical object
       if (myType == Type_2d)
@@ -497,18 +501,19 @@ bool SMESHGUI_MeshPatternDlg::onApply()
       //mySelectionMgr->clearSelected();
       bool autoUpdate = SMESHGUI::automaticUpdate();
       if (!isRefine() && autoUpdate) {
-       _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in());
-       SMESH_Actor* anActor = SMESH::FindActorByEntry(aSO->GetID().c_str());
-       if (!anActor) {
-         anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str());
-         if (anActor) {
-           SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
-           SMESH::FitAll();
-         }
-       }
+        _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in());
+        SMESH_Actor* anActor = SMESH::FindActorByEntry(aSO->GetID().c_str());
+        if (!anActor) {
+          anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str());
+          if (anActor) {
+            SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
+            SMESH::FitAll();
+          }
+        }
       }
       mySelectionMgr->clearSelected();
       SMESH::UpdateView();
+      SMESHGUI::Modified();
 
       mySMESHGUI->updateObjBrowser(true);
 
@@ -517,7 +522,7 @@ bool SMESHGUI_MeshPatternDlg::onApply()
       return true;
     } else {
       SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
-                                  tr("SMESH_OPERATION_FAILED"));
+                                   tr("SMESH_OPERATION_FAILED"));
       return false;
     }
   } catch (const SALOME::SALOME_Exception& S_ex) {
@@ -535,14 +540,14 @@ bool SMESHGUI_MeshPatternDlg::onApply()
 void SMESHGUI_MeshPatternDlg::onOk()
 {
   if (onApply())
-    onClose();
+    reject();
 }
 
 //=======================================================================
-// name    : SMESHGUI_MeshPatternDlg::onClose
+// name    : SMESHGUI_MeshPatternDlg::reject
 // Purpose : SLOT called when "Close" button pressed. Close dialog
 //=======================================================================
-void SMESHGUI_MeshPatternDlg::onClose()
+void SMESHGUI_MeshPatternDlg::reject()
 {
   mySelectionMgr->clearFilters();
   SMESH::SetPickable();
@@ -552,9 +557,35 @@ void SMESHGUI_MeshPatternDlg::onClose()
   disconnect(mySMESHGUI, 0, this, 0);
   mySMESHGUI->ResetState();
   erasePreview();
-  reject();
+  QDialog::reject();
+}
+
+//=================================================================================
+// function : onOpenView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MeshPatternDlg::onOpenView()
+{
+  if(!mySelector) {
+    mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
+    mySMESHGUI->EmitSignalDeactivateDialog();
+    setEnabled(true);
+    activateSelection();
+    connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
+  }
+}
+
+//=================================================================================
+// function : onCloseView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MeshPatternDlg::onCloseView()
+{
+  onDeactivate();
+  mySelector = 0;
 }
 
+
 //=================================================================================
 // function : onHelp()
 // purpose  :
@@ -565,17 +596,17 @@ void SMESHGUI_MeshPatternDlg::onHelp()
   if (app) 
     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
   else {
-               QString platform;
+                QString platform;
 #ifdef WIN32
-               platform = "winapplication";
+                platform = "winapplication";
 #else
-               platform = "application";
+                platform = "application";
 #endif
     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
-                            tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-                            arg(app->resourceMgr()->stringValue("ExternalBrowser", 
-                                                                platform)).
-                            arg(myHelpFileName));
+                             tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg(app->resourceMgr()->stringValue("ExternalBrowser", 
+                                                                 platform)).
+                             arg(myHelpFileName));
   }
 }
 
@@ -593,7 +624,7 @@ void SMESHGUI_MeshPatternDlg::onSelectionDone()
       SALOME_ListIO aList;
       mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
       if (aList.Extent() != 1)
-       return;
+        return;
 
       // Retrieve mesh from selection
       Handle(SALOME_InteractiveObject) anIO = aList.First();
@@ -624,11 +655,11 @@ void SMESHGUI_MeshPatternDlg::onSelectionDone()
       SALOME_ListIO aList;
       mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
       if (aList.Extent() != 1)
-       return;
+        return;
 
       QString anIds;
       if (!SMESH::GetNameOfSelectedElements(mySelector, aList.First(), anIds))
-       anIds = "";
+        anIds = "";
 
       myBusy = true;
       mySelEdit[ Ids ]->setText(anIds);
@@ -638,7 +669,7 @@ void SMESHGUI_MeshPatternDlg::onSelectionDone()
       SALOME_ListIO aList;
       mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
       if (aList.Extent() != 1)
-       return;
+        return;
 
       // Get geom object from selection
       Handle(SALOME_InteractiveObject) anIO = aList.First();
@@ -712,8 +743,13 @@ void SMESHGUI_MeshPatternDlg::enterEvent (QEvent*)
   if (myIsCreateDlgOpen)
     return;
 
-  if (myReverseChk->isChecked())
+  if (myReverseChk->isChecked()) {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
+    if ( aViewWindow && !mySelector) {
+      mySelector = aViewWindow->GetSelector();
+    }
     displayPreview();
+  }
   mySMESHGUI->EmitSignalDeactivateDialog();
   setEnabled(true);
   activateSelection();
@@ -721,15 +757,6 @@ void SMESHGUI_MeshPatternDlg::enterEvent (QEvent*)
   onTextChanged(mySelEdit[Ids]->text());
 }
 
-//=======================================================================
-// name    : SMESHGUI_MeshPatternDlg::closeEvent
-// Purpose :
-//=======================================================================
-void SMESHGUI_MeshPatternDlg::closeEvent (QCloseEvent*)
-{
-  onClose();
-}
-
 //=======================================================================
 // name    : SMESHGUI_MeshPatternDlg::onSelInputChanged
 // Purpose : SLOT. Called when -> button clicked.
@@ -782,10 +809,10 @@ void SMESHGUI_MeshPatternDlg::onOpen()
   SUIT_FileDlg* aDlg = new SUIT_FileDlg (this, true);
   aDlg->setWindowTitle(tr("LOAD_PATTERN"));
   aDlg->setFileMode(QFileDialog::ExistingFile);
-  aDlg->setFilters(prepareFilters());
+  aDlg->setNameFilters(prepareFilters());
   if (!myName->text().isEmpty())
     aDlg->selectFile(myName->text() + ".smp");
-  QPushButton* anOkBtn = qFindChild<QPushButton*>( aDlg, "OK" );
+  QPushButton* anOkBtn = aDlg->findChild<QPushButton*>( "OK" );
   if (anOkBtn != 0)
     anOkBtn->setText(tr("SMESH_BUT_OK"));
 
@@ -799,9 +826,9 @@ void SMESHGUI_MeshPatternDlg::onOpen()
   if (QFileInfo(fName).suffix().isEmpty())
     fName = autoExtension(fName);
 
-  fName = QDir::convertSeparators(fName);
+  fName = QDir::toNativeSeparators(fName);
 
-  QString prev = QDir::convertSeparators(myName->text());
+  QString prev = QDir::toNativeSeparators(myName->text());
   if (prev == fName)
     return;
 
@@ -809,14 +836,14 @@ void SMESHGUI_MeshPatternDlg::onOpen()
   QFile aFile(fName);
   if (!aFile.open(QIODevice::ReadOnly)) {
     SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
-                                tr("ERROR_OF_OPENING"));
+                                 tr("ERROR_OF_OPENING"));
     return;
   }
 
   QByteArray aDataArray = aFile.readAll();
   if (aDataArray.isEmpty()) {
     SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
-                                tr("ERROR_OF_READING"));
+                                 tr("ERROR_OF_READING"));
     return;
   }
 
@@ -954,7 +981,7 @@ void SMESHGUI_MeshPatternDlg::displayPreview()
 
     // Create and display actor
     vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
-    aMapper->SetInput(aGrid);
+    aMapper->SetInputData(aGrid);
 
     myPreviewActor = SALOME_Actor::New();
     myPreviewActor->PickableOff();
@@ -1046,11 +1073,11 @@ void SMESHGUI_MeshPatternDlg::updateWgState()
     if (!CORBA::is_nil(myPattern)/* && getIds(ids)*/) {
       SMESH::long_array_var keyPoints = myPattern->GetKeyPoints();
       if (keyPoints->length()) {
-       myNode1->setEnabled(true);
-       myNode2->setEnabled(true);
-       myNode1->setRange(1, keyPoints->length());
-       myNode2->setRange(1, keyPoints->length());
-       return;
+        myNode1->setEnabled(true);
+        myNode2->setEnabled(true);
+        myNode1->setRange(1, keyPoints->length());
+        myNode2->setRange(1, keyPoints->length());
+        return;
       }
     }
 
@@ -1075,13 +1102,13 @@ void SMESHGUI_MeshPatternDlg::activateSelection()
 
     if (myType == Type_2d)
       {
-       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-         aViewWindow->SetSelectionMode(FaceSelection);
+        if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+          aViewWindow->SetSelectionMode(FaceSelection);
       }
     else
       {
-       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-         aViewWindow->SetSelectionMode(CellSelection);
+        if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+          aViewWindow->SetSelectionMode(CellSelection);
       }
   }
   else {
@@ -1123,7 +1150,7 @@ bool SMESHGUI_MeshPatternDlg::loadFromFile (const QString& theName)
     SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern();
 
     if (!aPattern->LoadFromFile(theName.toLatin1().data()) ||
-        myType == Type_2d && !aPattern->Is2D()) {
+        (myType == Type_2d && !aPattern->Is2D())) {
       SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode();
       QString aMess;
       if      (aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS     ) aMess = tr("ERR_READ_NB_POINTS");
@@ -1146,7 +1173,7 @@ bool SMESHGUI_MeshPatternDlg::loadFromFile (const QString& theName)
   } catch (const SALOME::SALOME_Exception& S_ex) {
     SalomeApp_Tools::QtCatchCorbaException(S_ex);
     SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
-                                tr("ERROR_OF_LOADING") );
+                                 tr("ERROR_OF_LOADING") );
     return false;
   }
 }
@@ -1207,11 +1234,16 @@ void SMESHGUI_MeshPatternDlg::onTypeChanged (int theType)
     myNode2Lbl->show();
     myNode2   ->show();
   }
-
   mySelInput = Mesh;
   activateSelection();
   updateWgState();
   displayPreview();
+  myPicture2d->hide();
+  myPicture2d->show();
+  myPicture2d->resize(minimumSizeHint());
+  myMainFrame->hide();
+  myMainFrame->show();
+  resize(minimumSizeHint());
 }
 
 //=======================================================================
@@ -1229,13 +1261,13 @@ vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
       varIds->length(ids.count());
       int i = 0;
       for (QList<int>::iterator it = ids.begin(); it != ids.end(); ++it)
-       varIds[i++] = *it;
+        varIds[i++] = *it;
       pnts = myType == Type_2d
-       ? myPattern->ApplyToMeshFaces  (myMesh, varIds, getNode(false), myReverseChk->isChecked())
-       : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
+        ? myPattern->ApplyToMeshFaces  (myMesh, varIds, getNode(false), myReverseChk->isChecked())
+        : myPattern->ApplyToHexahedrons(myMesh, varIds, getNode(false), getNode(true));
     } else {
       pnts = myType == Type_2d
-       ? myPattern->ApplyToFace   (myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked())
+        ? myPattern->ApplyToFace   (myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked())
       : myPattern->ApplyTo3DBlock(myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ]);
     }
 
@@ -1270,7 +1302,7 @@ vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid()
     for (int i = 0, n = elemPoints->length(); i < n; i++)
       aCellsSize += elemPoints[ i ].length();
 
-    // Create unstructured grid and other  usefull arrays
+    // Create unstructured grid and other useful arrays
     vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
 
     vtkCellArray* aConnectivity = vtkCellArray::New();
@@ -1337,8 +1369,10 @@ void SMESHGUI_MeshPatternDlg::onModeToggled (bool on)
 {
   on ? myRefineGrp->show() : myRefineGrp->hide();
   on ? myGeomGrp->hide()   : myGeomGrp->show();
-
+  myMainFrame->hide();
+  myMainFrame->show();
   displayPreview();
+  resize(minimumSizeHint());
 }
 
 //=======================================================================
@@ -1380,7 +1414,7 @@ void SMESHGUI_MeshPatternDlg::onTextChanged (const QString& theNewText)
     for (int i = 0; i < aListId.count(); i++) {
       const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
       if (e && e->GetType() == (myType == Type_2d ? SMDSAbs_Face : SMDSAbs_Volume))
-       newIndices.Add(e->GetID());
+        newIndices.Add(e->GetID());
     }
     mySelector->AddOrRemoveIndex( anActor->getIO(), newIndices, false);
     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))