Salome HOME
bos #24228 [CEA 24217][Windows] cannot compile SMESH: additional fix.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SewingDlg.cxx
index 00ce12ef3044de3849791cec619aaa2049334d75..01f5c58af553f08ee4ecde4ff6e3be79eb130346 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -54,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>
@@ -451,7 +452,7 @@ SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule )
 
   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
 
-  myHelpFileName = "sewing_meshes_page.html";
+  myHelpFileName = "sewing_meshes.html";
 
   myActor = 0;
   myStoredEntityMode = 0;
@@ -825,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 ] );
     }
   }
@@ -851,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 ];
 
@@ -883,30 +886,30 @@ 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;
 
@@ -932,7 +935,7 @@ void SMESHGUI_SewingDlg::onRemoveGroupClicked()
     delete item;
     if ( myBorderDisplayers[ groupIndex ])
       myBorderDisplayers[ groupIndex ]->Hide();
-    SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ myCurGroupIndex ];
+    SMESH::FreeBordersGroup& aGRP = myBorders->coincidentGroups[ groupIndex ];
     aGRP.length( 0 );
   }
   myBusy = false;
@@ -956,7 +959,7 @@ void SMESHGUI_SewingDlg::showGroup( QListWidgetItem* item )
   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 ] && SMESH::GetCurrentVtkView())
       myBorderDisplayers[ groupIndex ] = new BorderGroupDisplayer( myBorders, groupIndex, groupColor, myMesh );
@@ -982,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() );
 }
 
 //=======================================================================
@@ -1001,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() );
 }
 
 //=======================================================================
@@ -1190,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();
@@ -1237,16 +1243,16 @@ void SMESHGUI_SewingDlg::onMoveBorderEnd(int button)
     {
       aPRT.node1 = ( aPRT.node1 + size + dn ) % size;
       aPRT.node2 = ( aPRT.node2 + size + dn ) % size;
-      break;
     }
+    break;
   case MOVE_LEFT_2:
   case MOVE_RIGHT_2:
     if (( isClosed ) ||
         ( 0 <= aPRT.nodeLast+dn && aPRT.nodeLast+dn < size ))
     {
       aPRT.nodeLast = ( aPRT.nodeLast + size + dn ) % size;
-      break;
     }
+    break;
   default:
     return; // impossible to move
   }
@@ -1287,7 +1293,7 @@ void SMESHGUI_SewingDlg::onSwapClicked()
 //=================================================================================
 bool SMESHGUI_SewingDlg::ClickOnApply()
 {
-  if (mySMESHGUI->isActiveStudyLocked())
+  if (SMESHGUI::isStudyLocked())
     return false;
 
   bool aResult = false;
@@ -1302,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)
       {
@@ -1362,8 +1368,8 @@ bool SMESHGUI_SewingDlg::ClickOnApply()
         QStringList aListElementsId1 = LineEdit1->text().split(" ", QString::SkipEmptyParts);
         QStringList aListElementsId2 = LineEdit4->text().split(" ", QString::SkipEmptyParts);
 
-        SMESH::long_array_var anElementsId1 = new SMESH::long_array;
-        SMESH::long_array_var anElementsId2 = new SMESH::long_array;
+        SMESH::smIdType_array_var anElementsId1 = new SMESH::smIdType_array;
+        SMESH::smIdType_array_var anElementsId2 = new SMESH::smIdType_array;
 
         anElementsId1->length(aListElementsId1.count());
         anElementsId2->length(aListElementsId2.count());
@@ -1389,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) {
@@ -1522,7 +1532,7 @@ void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
   else if (send == LineEdit6)
     myOk6 = false;
 
-  // hilight entered elements/nodes
+  // highlight entered elements/nodes
   SMDS_Mesh* aMesh = 0;
 
   if (myActor)
@@ -1531,7 +1541,7 @@ void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
     send->clear();
 
   if (aMesh) {
-    TColStd_MapOfInteger newIndices;
+    SVTK_TVtkIDsMap newIndices;
     
     if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
       SMESH::SetPointRepresentation(true);
@@ -1545,7 +1555,7 @@ void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
         mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
           aViewWindow->highlight( myActor->getIO(), true, true );
-        
+
         if      (send == LineEdit1)
           myOk1 = true;
         else if (send == LineEdit2)
@@ -1567,22 +1577,22 @@ void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
 
       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
 
-      bool isEvenOneExists = false;
+      bool atLeastOneExists = false;
 
       for (int i = 0; i < aListId.count(); i++) {
         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
-        if (e) 
+        if (e)
+        {
           newIndices.Add(e->GetID());
-        
-          if (!isEvenOneExists)
-            isEvenOneExists = true;
+          atLeastOneExists = true;
+        }
       }
-      
+
       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
         aViewWindow->highlight( myActor->getIO(), true, true );
-      
-      if (isEvenOneExists) {
+
+      if (atLeastOneExists) {
         if (send == LineEdit1)
           myOk1 = true;
         else if(send == LineEdit4)
@@ -1788,7 +1798,7 @@ void SMESHGUI_SewingDlg::ActivateThisDialog()
 // function : enterEvent()
 // purpose  :
 //=================================================================================
-void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
+void SMESHGUI_SewingDlg::enterEvent (QEvent* /*e*/)
 {
   if (!ConstructorsBox->isEnabled()) {
     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
@@ -1887,7 +1897,6 @@ SMESHGUI_SewingDlg::BorderGroupDisplayer::~BorderGroupDisplayer()
     }
   }
   myIdPreview.SetPointsLabeled(false);
-  //myViewWindow->Repaint();
 }
 
 void SMESHGUI_SewingDlg::BorderGroupDisplayer::Hide()
@@ -1939,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()
@@ -2010,7 +2024,6 @@ void SMESHGUI_SewingDlg::BorderGroupDisplayer::Update()
       myPartActors[ i ]->SetMarkerStd( VTK::MT_POINT, 13 );
       myPartActors[ i ]->SetPickable ( false );
       myViewWindow->AddActor( myPartActors[ i ]);
-      //myViewWindow->Repaint();
     }
   }
 }