Salome HOME
fix bug 12361. In SetName(): there may be no study
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.cxx
index c9a559b388060bec0d348a076d4e08c33522bf2c..28eba22e9b073334e862ee200bc06cb13f1e2bb9 100644 (file)
@@ -39,6 +39,8 @@
 #include "SMESH_Actor.h"
 
 #include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
+#include "LightApp_Application.h"
 
 #include "SVTK_Selection.h"
 #include "SVTK_Selector.h"
@@ -65,6 +67,7 @@
 #include <vtkUnsignedCharArray.h>
 #include <vtkUnstructuredGrid.h>
 #include <vtkDataSetMapper.h>
+#include <vtkProperty.h>
 
 // QT Includes
 #include <qbuttongroup.h>
@@ -118,7 +121,7 @@ namespace SMESH {
       myPreviewActor->VisibilityOff();
       myPreviewActor->SetMapper(myMapper);
 
-      float anRGB[3];
+      vtkFloatingPointType anRGB[3];
       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] );
@@ -216,14 +219,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;
@@ -243,20 +245,34 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
   }
 
   QString elemName;
-  if (myNbNodes == 2)
+  if (myNbNodes == 2) {
     elemName = "EDGE";
-  else if (myNbNodes == 3)
+    myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_edges";
+  }
+  else if (myNbNodes == 3) {
     elemName = "TRIANGLE";
+    myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_triangles";
+  }
   else if (myNbNodes == 4)
-    if (myElementType == SMDSAbs_Face)
+    if (myElementType == SMDSAbs_Face) {
       elemName = "QUADRANGLE";
-    else
+      myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_quadrangles";
+    }
+    else {
       elemName = "TETRAS";
-  else if (myNbNodes == 8)
+      myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_tetrahedrons";
+    }
+  else if (myNbNodes == 8) {
     elemName = "HEXAS";
-  else if (myElementType == SMDSAbs_Face){
+    myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_hexahedrons";
+  }
+  else if (myElementType == SMDSAbs_Face) {
     elemName = "POLYGON";
     myIsPoly = true;
+    myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_polygons";
+  }
+  else if (myElementType == SMDSAbs_Volume) {
+    myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_polyhedrons";
   }
   
   QString iconName      = tr(QString("ICON_DLG_%1").arg(elemName));
@@ -326,6 +342,11 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
   buttonOk->setAutoDefault(TRUE);
   buttonOk->setDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
+  buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
+  buttonHelp->setText(tr("SMESH_BUT_HELP" ));
+  buttonHelp->setAutoDefault(TRUE);
+  GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
+
   SMESHGUI_AddMeshElementDlgLayout->addWidget(GroupButtons, 2, 0);
 
   /***************************************************************/
@@ -400,6 +421,7 @@ void SMESHGUI_AddMeshElementDlg::Init()
   connect(buttonOk, SIGNAL(clicked()),     SLOT(ClickOnOk()));
   connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
   connect(buttonApply, SIGNAL(clicked()),  SLOT(ClickOnApply()));
+  connect(buttonHelp, SIGNAL(clicked()),   SLOT(ClickOnHelp()));
 
   connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
   connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
@@ -411,16 +433,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;
 
@@ -449,14 +468,21 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     switch (myElementType) {
     case SMDSAbs_Edge:
       aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
-    case SMDSAbs_Face:
-      aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
+    case SMDSAbs_Face:{
+      if(myIsPoly)
+       aMeshEditor->AddPolygonalFace(anArrayOfIdeces.inout());
+      else
+       aMeshEditor->AddFace(anArrayOfIdeces.inout());
+      break;
+
+    }
     case SMDSAbs_Volume:
       aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
     default:;
     }
 
     SALOME_ListIO aList; aList.Append( myActor->getIO() );
+    mySelector->ClearIndex();
     mySelectionMgr->setSelectedObjects( aList, false );
 
     SMESH::UpdateView();
@@ -488,16 +514,34 @@ 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();
   return;
 }
 
+//=================================================================================
+// function : ClickOnHelp()
+// purpose  :
+//=================================================================================
+void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) 
+    app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
+  else {
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
+                          QObject::tr("BUT_OK"));
+  }
+}
+
 //=================================================================================
 // function : onTextChange()
 // purpose  :
@@ -523,22 +567,30 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
     TColStd_MapOfInteger newIndices;
     
     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() ) )
       {
        newIndices.Add( n->GetID() );
        myNbOkNodes++;
       }
+      else
+       allOk = false;  
     }
     
     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
-    myViewWindow->highlight( myActor->getIO(), true, true );
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->highlight( myActor->getIO(), true, true );
     
-    bool aNodesOK = false;
-    if (myIsPoly && myElementType == SMDSAbs_Face && aListId.count() >=3 ){
-      myNbOkNodes = aListId.count();
-      aNodesOK = true;
-    }
+    myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
+    
+    if (myIsPoly)
+      {
+       if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
+         myNbOkNodes = 0;
+       else
+         myNbOkNodes = aListId.count();
+      }
   }
   
   if(myNbOkNodes) {
@@ -644,6 +696,7 @@ void SMESHGUI_AddMeshElementDlg::displaySimulation()
     }
 
     mySimulation->SetPosition(myActor,aType,anIds);
+    SMESH::UpdateView();
   }
 }
 
@@ -692,7 +745,8 @@ void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
 
   SMESH::SetPointRepresentation(true);
 
-  myViewWindow->SetSelectionMode( NodeSelection );
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode( NodeSelection );
   SelectionIntoArgument();
 }