Salome HOME
Fix regressions
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SewingDlg.cxx
index 6979a07cee993db28e0a896288705330b210ec3d..22253c4d69caec10655af62a565c787b09d98365 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  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
@@ -44,6 +44,7 @@
 // SALOME GUI includes
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <SALOMEDSClient_Study.hxx>
 #include <SALOME_ListIO.hxx>
 #include <SUIT_Desktop.h>
 #include <SUIT_MessageBox.h>
@@ -53,6 +54,7 @@
 #include <SVTK_ViewModel.h>
 #include <SVTK_ViewWindow.h>
 #include <SalomeApp_IntSpinBox.h>
+#include <SalomeApp_Tools.h>
 
 // OCCT includes
 #include <TColStd_MapOfInteger.hxx>
@@ -282,7 +284,7 @@ SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule )
   AutoSewCheck->setChecked( true );
 
   // mesh
-  QGroupBox* GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), SewFreeBordersWidget);
+  QGroupBox* GroupMesh = new QGroupBox(tr("SMESH_MESH"), SewFreeBordersWidget);
   QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
   GroupMeshLayout->setSpacing(SPACING);
   GroupMeshLayout->setMargin(MARGIN);
@@ -329,14 +331,13 @@ SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule )
 
   SelectAllCheck = new QCheckBox(tr("SELECT_ALL"), GroupCoincident);
 
-  aCoincidentLayout->addWidget(ListCoincident,    0, 0, 4, 2);
+  aCoincidentLayout->addWidget(ListCoincident,    0, 0, 5, 2);
   aCoincidentLayout->addWidget(DetectButton,      1, 2);
   aCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
-  aCoincidentLayout->addWidget(SelectAllCheck,    4, 0);
+  aCoincidentLayout->addWidget(SelectAllCheck,    5, 0);
   aCoincidentLayout->setRowMinimumHeight(1, 10);
-  aCoincidentLayout->setRowStretch      (1, 5);
-
-  GroupCoincidentLayout->addWidget( GroupCoincident );
+  aCoincidentLayout->setRowStretch      (4, 5);
+  aCoincidentLayout->setRowStretch      (5, 0);
 
   /*****************************************/
   // Controls for editing the selected group
@@ -391,8 +392,13 @@ SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule )
   GroupEditLayout->addWidget(SwapBut,          1, 7);
   GroupEditLayout->addWidget(StepLabel,        1, 8);
   GroupEditLayout->addWidget(StepSpin,         1, 9);
+  GroupEditLayout->setRowStretch( 0, 1 );
 
+  GroupCoincidentLayout->addWidget( GroupCoincident );
   GroupCoincidentLayout->addWidget( GroupEdit );
+  GroupCoincidentLayout->setRowStretch( 0, 10 );
+  GroupCoincidentLayout->setRowStretch( 1, 1 );
+
   aSewFreeBordersLayout->addWidget( GroupCoincidentWidget );
 
   // layout
@@ -449,8 +455,9 @@ SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule )
   myHelpFileName = "sewing_meshes_page.html";
 
   myActor = 0;
-  setDisplayMode();
+  myStoredEntityMode = 0;
 
+  setDisplayMode();
   Init();
 
   /* signals and slots connections */
@@ -568,6 +575,8 @@ void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
       CheckBoxPolyedrs->hide();
   }
 
+  CheckBoxMerge->setVisible ( constructorId == 3 );
+
   if (( !SubGroup1->isVisible() ) &&
       ( constructorId != 0 || ModeButGrp->checkedId() == MODE_MANUAL ))
   {
@@ -579,6 +588,7 @@ void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
   {
     ModeGroup->hide();
     SewFreeBordersWidget->hide();
+    restoreDisplayMode();
   }
 
   bool isNodeSelection = true;
@@ -673,12 +683,11 @@ void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
     LineEdit4->setValidator(new SMESHGUI_IdValidator(this, 1));
   }
 
-  if ( isNodeSelection )
-  {
-    SMESH::SetPointRepresentation(true);
-    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-      aViewWindow->SetSelectionMode(NodeSelection);
-  }
+  if ( myActor )
+    myActor->SetPointRepresentation( isNodeSelection );
+
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode( isNodeSelection ? NodeSelection : ActorSelection );
 
   UpdateButtons();
 
@@ -698,9 +707,12 @@ void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
 
 void SMESHGUI_SewingDlg::setDisplayMode()
 {
+  if ( myStoredEntityMode )
+    return;
   myStoredEntityMode = 0;
   myStoredRepresentation = -1;
-  if ( myActor )
+
+  if ( myActor && AutoSewCheck->isVisible() && !AutoSewCheck->isChecked() )
   {
     myStoredEntityMode     = myActor->GetEntityMode();
     myStoredRepresentation = myActor->GetRepresentation();
@@ -728,6 +740,9 @@ void SMESHGUI_SewingDlg::restoreDisplayMode()
     myStoredEntityMode = 0;
     myStoredRepresentation = -1;
   }
+  for ( size_t i = 0; i < myBorderDisplayers.size(); ++i )
+    if ( myBorderDisplayers[ i ])
+      myBorderDisplayers[ i ]->Hide();
 }
 
 //=======================================================================
@@ -751,6 +766,12 @@ void SMESHGUI_SewingDlg::onModeChange( int mode )
     if ( !SewFreeBordersWidget->isVisible() )
       SewFreeBordersWidget->show();
   }
+  if ( myActor )
+    myActor->SetPointRepresentation( mode == MODE_MANUAL );
+
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() )
+    aViewWindow->SetSelectionMode( mode == MODE_MANUAL ? NodeSelection : ActorSelection );
+
   onAutoSew( AutoSewCheck->isChecked() );
 
   QApplication::instance()->processEvents();
@@ -774,6 +795,12 @@ void SMESHGUI_SewingDlg::onAutoSew( int isAuto )
   if ( ModeButGrp->checkedId() == MODE_AUTO )
     SewFreeBordersWidget->show();
 
+  if ( isAuto )
+    restoreDisplayMode();
+  else
+    setDisplayMode();
+  SMESH::RepaintCurrentView();
+
   UpdateButtons();
 
   updateGeometry();
@@ -799,15 +826,17 @@ bool SMESHGUI_SewingDlg::haveBorders()
 
 QString SMESHGUI_SewingDlg::getPartText(const SMESH::FreeBorderPart& aPART)
 {
+  typedef CORBA::Long TInt;
   QString text;
-  if ( 0 <= aPART.border && aPART.border < myBorders->borders.length() )
+  if ( 0 <= aPART.border && aPART.border < (TInt)myBorders->borders.length() )
   {
     const SMESH::FreeBorder& aBRD = myBorders->borders[ aPART.border ];
-    if ( 0 <= aPART.node1    && aPART.node1 aBRD.nodeIDs.length() &&
-         0 <= aPART.nodeLast && aPART.nodeLast < aBRD.nodeIDs.length() )
+    if ( 0 <= aPART.node1    && aPART.node1    < (TInt)aBRD.nodeIDs.length() &&
+         0 <= aPART.nodeLast && aPART.nodeLast < (TInt)aBRD.nodeIDs.length() )
     {
-      text += QString("( %1 %2 ) ")
+      text += QString("( %1 %2 %3 ) ")
         .arg( aBRD.nodeIDs[ aPART.node1 ] )
+        .arg( aBRD.nodeIDs[ aPART.node2 ] )
         .arg( aBRD.nodeIDs[ aPART.nodeLast ] );
     }
   }
@@ -825,7 +854,7 @@ QString SMESHGUI_SewingDlg::getGroupText(int groupIndex)
 
   if ( haveBorders()   &&
        groupIndex >= 0 &&
-       groupIndex < myBorders->coincidentGroups.length() )
+       groupIndex < (int)myBorders->coincidentGroups.length() )
   {
     const SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ groupIndex ];
 
@@ -847,6 +876,7 @@ QString SMESHGUI_SewingDlg::getGroupText(int groupIndex)
 
 void SMESHGUI_SewingDlg::onDetectClicked()
 {
+  myBusy = true;
   ListCoincident->clear();
 
   if ( myMesh->_is_nil() )
@@ -856,31 +886,32 @@ void SMESHGUI_SewingDlg::onDetectClicked()
 
   SMESH::SMESH_MeshEditor_var editor = myMesh->GetMeshEditor();
   myBorders = editor->FindCoincidentFreeBorders( SpinBoxTolerance->GetValue() );
-  if ( !haveBorders() )
-    return;
-
-  for ( size_t i = 0; i < myBorderDisplayers.size(); ++i )
+  if ( haveBorders() )
   {
-    delete myBorderDisplayers[ i ];
-    myBorderDisplayers[ i ] = 0;
-  }
-  myBorderDisplayers.resize( myBorders->coincidentGroups.length(), 0 );
+    for ( size_t i = 0; i < myBorderDisplayers.size(); ++i )
+    {
+      delete myBorderDisplayers[ i ];
+      myBorderDisplayers[ i ] = 0;
+    }
+    myBorderDisplayers.resize( myBorders->coincidentGroups.length(), 0 );
 
-  for ( CORBA::ULong i = 0; i < myBorders->coincidentGroups.length(); ++i )
-  {
-    QString groupText = getGroupText( i );
-    if ( groupText.isEmpty() )
-      continue;
-
-    QColor groupColor;
-    groupColor.setHsvF( float(i) / myBorders->coincidentGroups.length(), 1., 1. );
-    QPixmap icon( QSize( 20, 20 ));
-    icon.fill( groupColor );
-
-    QListWidgetItem * item = new QListWidgetItem( icon, groupText, ListCoincident );
-    item->setData( GROUP_COLOR, groupColor );
-    item->setData( GROUP_INDEX, i );
+    for ( uint i = 0; i < myBorders->coincidentGroups.length(); ++i )
+    {
+      QString groupText = getGroupText( i );
+      if ( groupText.isEmpty() )
+        continue;
+
+      QColor groupColor;
+      groupColor.setHsvF( float(i) / myBorders->coincidentGroups.length(), 1., 1. );
+      QPixmap icon( QSize( 20, 20 ));
+      icon.fill( groupColor );
+
+      QListWidgetItem * item = new QListWidgetItem( icon, groupText, ListCoincident );
+      item->setData( GROUP_COLOR, groupColor );
+      item->setData( GROUP_INDEX, i );
+    }
   }
+  myBusy = false;
 
   onSelectGroup();
 
@@ -894,6 +925,7 @@ void SMESHGUI_SewingDlg::onDetectClicked()
 
 void SMESHGUI_SewingDlg::onRemoveGroupClicked()
 {
+  myBusy = true;
   QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
   for ( int i = 0; i < selItems.count(); ++i )
   {
@@ -901,10 +933,14 @@ void SMESHGUI_SewingDlg::onRemoveGroupClicked()
     item->setSelected( false );
     int groupIndex = item->data( GROUP_INDEX ).toInt();
     delete item;
-    myBorderDisplayers[ groupIndex ]->Hide();
-    SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ myCurGroupIndex ];
+    if ( myBorderDisplayers[ groupIndex ])
+      myBorderDisplayers[ groupIndex ]->Hide();
+    SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ groupIndex ];
     aGRP.length( 0 );
   }
+  myBusy = false;
+
+  onSelectGroup();
   UpdateButtons();
 }
 
@@ -917,18 +953,19 @@ void SMESHGUI_SewingDlg::showGroup( QListWidgetItem* item )
 {
   if ( !item ||
        item->listWidget() != ListCoincident ||
-       !haveBorders() )
+       !haveBorders())
     return;
 
   int    groupIndex = item->data( GROUP_INDEX ).toInt();
   QColor groupColor = item->data( GROUP_COLOR ).value<QColor>();
   if ( groupIndex >= 0       &&
-       groupIndex < myBorders->coincidentGroups.length() )
+       groupIndex < (int)myBorders->coincidentGroups.length() )
   {
-    if ( !myBorderDisplayers[ groupIndex ])
+    if ( !myBorderDisplayers[ groupIndex ] && SMESH::GetCurrentVtkView())
       myBorderDisplayers[ groupIndex ] = new BorderGroupDisplayer( myBorders, groupIndex, groupColor, myMesh );
     bool wholeBorders = setCurrentGroup();
-    myBorderDisplayers[ groupIndex ]->ShowGroup( wholeBorders );
+    if ( myBorderDisplayers[ groupIndex ])
+      myBorderDisplayers[ groupIndex ]->ShowGroup( wholeBorders );
   }
 }
 
@@ -948,7 +985,7 @@ bool SMESHGUI_SewingDlg::setCurrentGroup()
   
   myCurGroupIndex = selItems[0]->data( GROUP_INDEX ).toInt();
 
-  return ( myCurGroupIndex >= 0 && myCurGroupIndex < myBorders->coincidentGroups.length() );
+  return ( myCurGroupIndex >= 0 && myCurGroupIndex < (int)myBorders->coincidentGroups.length() );
 }
 
 //=======================================================================
@@ -967,7 +1004,7 @@ bool SMESHGUI_SewingDlg::setCurrentPart()
   myCurPartIndex = ListEdit->currentRow();
   const SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ myCurGroupIndex ];
 
-  return ( myCurPartIndex >= 0 && myCurPartIndex < aGRP.length() );
+  return ( myCurPartIndex >= 0 && myCurPartIndex < (int)aGRP.length() );
 }
 
 //=======================================================================
@@ -1111,7 +1148,8 @@ void SMESHGUI_SewingDlg::onGroupChange( bool partChange )
   for ( int i = 0; i < ListEdit->count(); ++i )
     ListEdit->item( i )->setText( getPartText( aGRP[ i ]));
 
-  myBorderDisplayers[ myCurGroupIndex ]->Update();
+  if ( myBorderDisplayers[ myCurGroupIndex ])
+    myBorderDisplayers[ myCurGroupIndex ]->Update();
 
   if ( partChange )
     onSelectBorderPartFromGroup();
@@ -1155,15 +1193,18 @@ void SMESHGUI_SewingDlg::onRemoveElemClicked()
 
   SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ myCurGroupIndex ];
 
+  myBusy = true;
   QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
   for ( int i = 0; i < selItems.count(); ++i )
   {
     int part = ListEdit->row( selItems[i] );
-    for ( ; part + 1 < aGRP.length(); ++part )
+    for ( ; part + 1 < (int)aGRP.length(); ++part )
       aGRP[ part ] = aGRP[ part + 1 ];
-    aGRP.length( aGRP.length() - 1 );
+    if ( aGRP.length() > 0 )
+      aGRP.length( aGRP.length() - 1 );
     delete selItems[i];
   }
+  myBusy = false;
 
   if ( aGRP.length() == 0 )
     onRemoveGroupClicked();
@@ -1267,7 +1308,7 @@ bool SMESHGUI_SewingDlg::ClickOnApply()
       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
 
       int aConstructorId = GetConstructorId();
-      SMESH::SMESH_MeshEditor::Sew_Error anError;
+      SMESH::SMESH_MeshEditor::Sew_Error anError = SMESH::SMESH_MeshEditor::SEW_OK;
 
       if (aConstructorId == 0)
       {
@@ -1354,7 +1395,11 @@ bool SMESHGUI_SewingDlg::ClickOnApply()
         QString msg = tr(QString("ERROR_%1").arg(anError).toLatin1().data());
         SUIT_MessageBox::warning(this, tr("SMESH_WRN_WARNING"), msg);
       }
-    } catch (...) {
+    }
+    catch ( const SALOME::SALOME_Exception& S_ex )
+    {
+      SalomeApp_Tools::QtCatchCorbaException( S_ex );
+      return false;
     }
 
     if (aResult) {
@@ -1410,6 +1455,7 @@ void SMESHGUI_SewingDlg::onCloseView()
 {
   DeactivateActiveDialog();
   mySelector = 0;
+  myActor = 0;
 
   for ( size_t i = 0; i < myBorderDisplayers.size(); ++i )
   {
@@ -1610,7 +1656,8 @@ void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
 
   if ( myEditCurrentArgument == LineEditMesh )
   {
-    LineEditMesh->setText( IO->getName() );
+    if ( _PTR(SObject) meshSO = SMESH::FindSObject( myMesh ))
+      LineEditMesh->setText( meshSO->GetName().c_str() );
     ListCoincident->clear();
     if ( AutoSewCheck->isChecked() )
     {
@@ -1850,7 +1897,6 @@ SMESHGUI_SewingDlg::BorderGroupDisplayer::~BorderGroupDisplayer()
     }
   }
   myIdPreview.SetPointsLabeled(false);
-  //myViewWindow->Repaint();
 }
 
 void SMESHGUI_SewingDlg::BorderGroupDisplayer::Hide()
@@ -1902,16 +1948,21 @@ void SMESHGUI_SewingDlg::BorderGroupDisplayer::getPartEnds( int                p
                                                             std::vector<int> & ids,
                                                             std::list<gp_XYZ>& coords)
 {
+  if ( partIndex >= (int)myGroup.length() ) return;
   const SMESH::FreeBorderPart& aPART = myGroup  [ partIndex ];
   const SMESH::FreeBorder&      aBRD = myBorders[ aPART.border ];
 
   ids.push_back( aBRD.nodeIDs[ aPART.node1 ]);
   ids.push_back( aBRD.nodeIDs[ aPART.nodeLast ]);
+  if ( aPART.node1 == aPART.nodeLast )
+    ids.push_back( aBRD.nodeIDs[ aPART.node2 ]);
 
   SMDS_Mesh* mesh = myPartActors[ partIndex ]->GetObject()->GetMesh();
 
   coords.push_back( SMESH_TNodeXYZ( mesh->FindNode( aPART.node1+1 )));
   coords.push_back( SMESH_TNodeXYZ( mesh->FindNode( aPART.nodeLast+1 )));
+  if ( aPART.node1 == aPART.nodeLast )
+    coords.push_back( SMESH_TNodeXYZ( mesh->FindNode( aPART.node2+1 )));
 }
 
 void SMESHGUI_SewingDlg::BorderGroupDisplayer::Update()
@@ -1969,11 +2020,10 @@ void SMESHGUI_SewingDlg::BorderGroupDisplayer::Update()
       myPartActors[ i ] = SMESH_Actor::New( obj, "", "", 1 );
       myPartActors[ i ]->SetEdgeColor( myColor.redF(), myColor.greenF(), myColor.blueF() );
       myPartActors[ i ]->SetLineWidth( 3 * SMESH::GetFloat("SMESH:element_width",1));
-      myPartActors[ i ]->SetPickable( false );
       myPartActors[ i ]->SetNodeColor( myColor.redF(), myColor.greenF(), myColor.blueF() );
       myPartActors[ i ]->SetMarkerStd( VTK::MT_POINT, 13 );
+      myPartActors[ i ]->SetPickable ( false );
       myViewWindow->AddActor( myPartActors[ i ]);
-      myViewWindow->Repaint();
     }
   }
 }