Salome HOME
53539: 0D Element
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.cxx
index 44cba417c84887f55bb10c98755ca80dc2c491db..25bbd46e7c12d24af2e0db2541e6bb6c3d72ffe7 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
@@ -214,12 +214,13 @@ namespace SMESH
       SetVisibility(true, theActor->GetFacesOriented(), false);
     }
 
-    void SetBallPosition(SMESH_Actor* theActor,TVTKIds& theIds, double theDiameter) {
+    void SetBallPosition(SMESH_Actor* theActor,TVTKIds& theIds, double theDiameter)
+    {
       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
       myBallPolyData->Reset();
       myBallPolyData->DeleteCells();
       myBallPolyData->SetPoints(aGrid->GetPoints());
-      
+
       vtkDataArray* aScalars = vtkDataArray::CreateDataArray(VTK_DOUBLE);
       aScalars->SetNumberOfComponents(1);
       aScalars->SetNumberOfTuples(theIds.size());
@@ -235,7 +236,7 @@ namespace SMESH
         aScalars->SetTuple(anId,&d);
         anIds->Reset();
       }
-      
+
       anIds->Delete();
       myBallPolyData->Modified();
       SetVisibility (false, false, true);
@@ -412,7 +413,9 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI*          theMo
   LineEditC1A1->setValidator
     (new SMESHGUI_IdValidator(this, ( myIsPoly || myNbNodes == 1 ) ? 1000 : myNbNodes));
 
-  Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
+  ReverseOrDulicate = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
+  if ( myElementType == SMDSAbs_0DElement )
+    ReverseOrDulicate = new QCheckBox(tr("SMESH_DUPLICATE_0D"), GroupC1);
 
   DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
   QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
@@ -420,8 +423,8 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI*          theMo
   GroupC1Layout->addWidget(TextLabelC1A1,    0, 0);
   GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
   GroupC1Layout->addWidget(LineEditC1A1,     0, 2);
-  if ( Reverse ) {
-    GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
+  if ( ReverseOrDulicate ) {
+    GroupC1Layout->addWidget(ReverseOrDulicate, 1, 0, 1, 3);
   }
   if ( DiameterSpinBox ) {
     GroupC1Layout->addWidget(diameterLabel,   1, 0);
@@ -523,8 +526,8 @@ void SMESHGUI_AddMeshElementDlg::Init()
   connect(mySMESHGUI,      SIGNAL(SignalActivatedViewManager()),  SLOT(onOpenView()));
   connect(mySMESHGUI,      SIGNAL(SignalCloseView()),             SLOT(onCloseView()));
 
-  if (Reverse)
-    connect(Reverse,       SIGNAL(stateChanged(int)),             SLOT(CheckBox(int)));
+  if (ReverseOrDulicate)
+    connect(ReverseOrDulicate,       SIGNAL(stateChanged(int)),             SLOT(CheckBox(int)));
 
   // set selection mode
   SMESH::SetPointRepresentation(true);
@@ -552,10 +555,10 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
     anArrayOfIndices->length(aListId.count());
     const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
-    if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
+    if ( ReverseOrDulicate && ReverseOrDulicate->isChecked() && (int)revIndex.size() == aListId.count() )
       for (int i = 0; i < aListId.count(); i++)
         anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
-    else if ( Reverse && Reverse->isChecked() && revIndex.empty() ) // polygon
+    else if ( ReverseOrDulicate && ReverseOrDulicate->isChecked() && revIndex.empty() ) // polygon
       for (int i = 0; i < aListId.count(); i++)
         anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
     else
@@ -582,6 +585,13 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
                                                tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
           if ( res == 1 ) return;
         }
+        SMESH::SMESH_GroupOnFilter_var aFilterGroup = SMESH::SMESH_GroupOnFilter::_narrow( myGroups[idx-1] );
+        if ( !aFilterGroup->_is_nil() ) {
+          int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
+                                               tr( "MESH_FILTER_GRP_CHOSEN" ).arg( aGroupName ),
+                                               tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
+          if ( res == 1 ) return;
+        }
         aGroup = myGroups[idx-1];
       }
     }
@@ -590,16 +600,26 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     SMESH::long_array_var anIdList = new SMESH::long_array;
     anIdList->length( 1 );
     anIdList[0] = -1;
-    const bool onlyNodesInMesh = ( myMesh->NbElements() == 0 );
+    int nbElemsBefore = 0;
 
     switch (myElementType) {
-    case SMDSAbs_0DElement:
+    case SMDSAbs_0DElement: {
+      bool duplicateElements = ReverseOrDulicate->isChecked();
+      nbElemsBefore = myMesh->Nb0DElements();
       anIdList->length( anArrayOfIndices->length() );
       for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
-        anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i]);
+        anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i], duplicateElements);
+
+      CORBA::ULong nbAdded = myMesh->Nb0DElements() - nbElemsBefore;
+      if ( !duplicateElements && nbAdded < anArrayOfIndices->length() )
+        SUIT_MessageBox::information(SMESHGUI::desktop(),
+                                     tr("SMESH_INFORMATION"),
+                                     tr("NB_ADDED").arg( nbAdded ));
       break;
+    }
     case SMDSAbs_Ball:
       if ( myGeomType == SMDSEntity_Ball ) {
+        nbElemsBefore = myMesh->NbBalls();
         anIdList->length( anArrayOfIndices->length() );
         for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
           anIdList[i] = aMeshEditor->AddBall(anArrayOfIndices[i],
@@ -607,21 +627,24 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
       }
       break;
     case SMDSAbs_Edge:
+      nbElemsBefore = myMesh->NbEdges();
       anIdList[0] = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
     case SMDSAbs_Face:
+      nbElemsBefore = myMesh->NbFaces();
       if ( myIsPoly )
         anIdList[0] = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
       else
         anIdList[0] = aMeshEditor->AddFace(anArrayOfIndices.inout());
       break;
     default:
+      nbElemsBefore = myMesh->NbVolumes();
       anIdList[0] = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
     }
 
     if ( anIdList[0] > 0 && addToGroup && !aGroupName.isEmpty() ) {
       SMESH::SMESH_Group_var aGroupUsed;
       if ( aGroup->_is_nil() ) {
-        // create new group 
+        // create new group
         aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
         if ( !aGroupUsed->_is_nil() ) {
           myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
@@ -629,7 +652,8 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
         }
       }
       else {
-        SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
+        SMESH::SMESH_GroupOnGeom_var     aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
+        SMESH::SMESH_GroupOnFilter_var aFilterGroup = SMESH::SMESH_GroupOnFilter::_narrow( aGroup );
         if ( !aGeomGroup->_is_nil() ) {
           aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
           if ( !aGroupUsed->_is_nil() && idx > 0 ) {
@@ -637,6 +661,13 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
             SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
           }
         }
+        else if ( !aFilterGroup->_is_nil() ) {
+          aGroupUsed = myMesh->ConvertToStandalone( aFilterGroup );
+          if ( !aGroupUsed->_is_nil() && idx > 0 ) {
+            myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
+            SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
+          }
+        }
         else
           aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
       }
@@ -650,8 +681,23 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     mySelectionMgr->setSelectedObjects( aList, false );
 
     mySimulation->SetVisibility(false);
-    if ( onlyNodesInMesh )
-      myActor->SetRepresentation( SMESH_Actor::eEdge ); // wireframe
+
+    if ( nbElemsBefore == 0  )
+    {
+      // 1st element of the type has been added, update actor to show this entity
+      unsigned int aMode = myActor->GetEntityMode();
+      switch ( myElementType ) {
+      case SMDSAbs_Edge:
+        myActor->SetRepresentation(SMESH_Actor::eEdge);
+        myActor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
+      case SMDSAbs_Face:
+        myActor->SetRepresentation(SMESH_Actor::eSurface);
+        myActor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
+      case SMDSAbs_Volume:
+        myActor->SetRepresentation(SMESH_Actor::eSurface);
+        myActor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
+      }
+    }
     SMESH::UpdateView();
 
     buttonOk->setEnabled(false);
@@ -870,10 +916,10 @@ void SMESHGUI_AddMeshElementDlg::displaySimulation()
     for (int i = 0; i < aListId.count(); i++)
       anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
 
-    if (Reverse && Reverse->isChecked())
+    if (ReverseOrDulicate && ReverseOrDulicate->isChecked())
     {
       const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
-      if ( i.empty() ) // polygon
+      if ( i.size() != anIds.size() ) // polygon
         std::reverse( anIds.begin(), anIds.end() );
       else
         SMDS_MeshCell::applyInterlace( i, anIds );