Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.cxx
index a15542896d3dc1096a00767baafa98bea2f529b3..df2bb4df18227499a267cbd2d308177a8aa19966 100644 (file)
@@ -65,6 +65,7 @@
 #include <vtkUnsignedCharArray.h>
 #include <vtkUnstructuredGrid.h>
 #include <vtkDataSetMapper.h>
+#include <vtkProperty.h>
 
 // QT Includes
 #include <qbuttongroup.h>
@@ -118,21 +119,17 @@ namespace SMESH {
       myPreviewActor->VisibilityOff();
       myPreviewActor->SetMapper(myMapper);
 
-      vtkProperty* aProp = vtkProperty::New();
       float anRGB[3];
-      anRGB[0] = GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
-      anRGB[1] = GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
-      anRGB[2] = GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
-      aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
-      myPreviewActor->SetProperty(aProp);
+      vtkProperty* aProp = vtkProperty::New();
+      GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
+      aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
+      myPreviewActor->SetProperty( aProp );
       aProp->Delete();
 
       vtkProperty* aBackProp = vtkProperty::New();
-      anRGB[0] = GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
-      anRGB[1] = GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
-      anRGB[2] = GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
-      aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
-      myPreviewActor->SetBackfaceProperty(aBackProp);
+      GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
+      aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
+      myPreviewActor->SetBackfaceProperty( aBackProp );
       aBackProp->Delete();
 
       myVTKViewWindow->AddActor(myPreviewActor);
@@ -220,14 +217,13 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
      mySMESHGUI( theModule ),
-     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
-     myViewWindow( SMESH::GetViewWindow( theModule ) ),
-     mySelector( myViewWindow->GetSelector() )
+     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
 {
   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
     (SUIT_Session::session()->activeApplication());
   myIsPoly = false;
   mySimulation = new SMESH::TElementSimulation (anApp);
+  mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
 
   // verify nb nodes and type
   myNbNodes = nbNodes;
@@ -268,8 +264,8 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
   QString caption       = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName));
   QString grBoxTitle    = tr(QString("SMESH_ADD_%1").arg(elemName));
 
-  QPixmap image0 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", iconName));
-  QPixmap image1 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
+  QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
+  QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
 
   if (!name)
     setName("SMESHGUI_AddMeshElementDlg");
@@ -415,16 +411,13 @@ void SMESHGUI_AddMeshElementDlg::Init()
   if (Reverse)
     connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
 
-  // Move widget on the botton right corner of main widget
-  int x, y;
-  mySMESHGUI->DefineDlgPosition(this, x, y);
-  this->move(x, y);
   this->show(); // displays Dialog
 
   // set selection mode
   SMESH::SetPointRepresentation(true);
 
-  myViewWindow->SetSelectionMode( NodeSelection );
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode( NodeSelection );
 
   myBusy = false;
 
@@ -461,6 +454,7 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     }
 
     SALOME_ListIO aList; aList.Append( myActor->getIO() );
+    mySelector->ClearIndex();
     mySelectionMgr->setSelectedObjects( aList, false );
 
     SMESH::UpdateView();
@@ -492,10 +486,11 @@ void SMESHGUI_AddMeshElementDlg::ClickOnOk()
 //=================================================================================
 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
 {
-  mySelectionMgr->clearSelected();
+  //mySelectionMgr->clearSelected();
   mySimulation->SetVisibility(false);
   SMESH::SetPointRepresentation(false);
-  myViewWindow->SetSelectionMode( ActorSelection );
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode( ActorSelection );
   disconnect(mySelectionMgr, 0, this, 0);
   mySMESHGUI->ResetState();
   reject();
@@ -524,33 +519,33 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
     aMesh = myActor->GetObject()->GetMesh();
 
   if (aMesh) {
-    SALOME_ListIO aList; aList.Append( myActor->getIO() );
-    mySelectionMgr->setSelectedObjects( aList, false );
-
-    TColStd_IndexedMapOfInteger selectedIndices;
     TColStd_MapOfInteger newIndices;
-    mySelector->GetIndex(myActor->getIO(), selectedIndices);
-
+    
     QStringList aListId = QStringList::split(" ", theNewText, false);
+    bool allOk = true;
     for (int i = 0; i < aListId.count(); i++) {
       if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
       {
-       if( selectedIndices.Add( n->GetID() ) )
-         newIndices.Add( n->GetID() );
+       newIndices.Add( n->GetID() );
        myNbOkNodes++;
       }
+      else
+       allOk = false;  
     }
     
-    if( newIndices.Extent()>0 )
-    {
-      mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, true );
-      myViewWindow->highlight( myActor->getIO(), true, true );
-    }
-    bool aNodesOK = false;
-    if (myIsPoly && myElementType == SMDSAbs_Face && aListId.count() >=3 ){
-      myNbOkNodes = aListId.count();
-      aNodesOK = true;
-    }
+    mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->highlight( myActor->getIO(), true, true );
+    
+    myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
+    
+    if (myIsPoly)
+      {
+       if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
+         myNbOkNodes = 0;
+       else
+         myNbOkNodes = aListId.count();
+      }
   }
   
   if(myNbOkNodes) {
@@ -656,6 +651,7 @@ void SMESHGUI_AddMeshElementDlg::displaySimulation()
     }
 
     mySimulation->SetPosition(myActor,aType,anIds);
+    SMESH::UpdateView();
   }
 }
 
@@ -704,7 +700,8 @@ void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
 
   SMESH::SetPointRepresentation(true);
 
-  myViewWindow->SetSelectionMode( NodeSelection );
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode( NodeSelection );
   SelectionIntoArgument();
 }