Salome HOME
imn/auto-reorder_of_nodes_ver2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddQuadraticElementDlg.cxx
index 94fdeec8a5b45d9dd32e139f5506e975b0165839..31a6214dc95fe7eb5bb8430e22af1aff7d0068a5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -55,6 +55,8 @@
 
 #include <SalomeApp_Application.h>
 
+#include <Qtx.h>
+
 // IDL includes
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
@@ -111,7 +113,7 @@ namespace
 }
 namespace SMESH
 {
-  class TElementSimulation {
+  class TElementSimulationQuad {
     SalomeApp_Application* myApplication;
     SUIT_ViewWindow* myViewWindow;
     SVTK_ViewWindow* myVTKViewWindow;
@@ -128,7 +130,7 @@ namespace SMESH
     SMESH_FaceOrientationFilter* myFaceOrientationFilter;
 
   public:
-    TElementSimulation (SalomeApp_Application* theApplication)
+    TElementSimulationQuad (SalomeApp_Application* theApplication)
     {
       myApplication = theApplication;
       SUIT_ViewManager* mgr = theApplication->activeViewManager();
@@ -146,17 +148,19 @@ namespace SMESH
       myPreviewActor->PickableOff();
       myPreviewActor->VisibilityOff();
       myPreviewActor->SetMapper(myMapper);
-
+      
+      QColor ffc, bfc;
+      int delta;
       vtkProperty* myProp = vtkProperty::New();
-      double aRGB[3], aBackRGB[3];
-      GetColor( "SMESH", "fill_color", aRGB[0], aRGB[1], aRGB[2], QColor( 0, 170, 255 ) );
-      myProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
+      SMESH::GetColor( "SMESH", "preview_color", ffc, delta, "0, 255, 0|-100" ) ;
+   
+      myProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. );
       myPreviewActor->SetProperty( myProp );
       myProp->Delete();
 
       vtkProperty* myBackProp = vtkProperty::New();
-      GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
-      myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
+      bfc = Qtx::mainColorToSecondary(ffc, delta);
+      myBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
       myPreviewActor->SetBackfaceProperty( myBackProp );
       myBackProp->Delete();
 
@@ -175,6 +179,7 @@ namespace SMESH
       myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
 
       vtkProperty* anOrientationProp = vtkProperty::New();
+      double aRGB[3];
       GetColor( "SMESH", "orientation_color", aRGB[0], aRGB[1], aRGB[2], QColor( 255, 255, 255 ) );
       anOrientationProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
       myFaceOrientation->SetProperty( anOrientationProp );
@@ -225,7 +230,7 @@ namespace SMESH
     }
 
 
-    ~TElementSimulation()
+    ~TElementSimulationQuad()
     {
       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
         myVTKViewWindow->RemoveActor(myPreviewActor);
@@ -278,7 +283,6 @@ static int LastHexahedronIds[] =  {1,2,3,0,5,6,7,4,4,5,6,7};
   \brief Simple 'busy state' flag locker.
   \internal
 */
-
 class BusyLocker
 {
 public:
@@ -295,7 +299,6 @@ private:
   \brief Simple editable table item.
   \internal
 */
-
 class IdEditItem: public QTableWidgetItem
 {
 public:
@@ -325,6 +328,7 @@ QWidget* IdEditItem::createEditor() const
 // function : SMESHGUI_AddQuadraticElementDlg()
 // purpose  : constructor
 //=================================================================================
+
 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
                                                                   const SMDSAbs_EntityType theType )
   : QDialog( SMESH::GetDesktop( theModule ) ),
@@ -340,7 +344,7 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
     (SUIT_Session::session()->activeApplication());
 
-  mySimulation = new SMESH::TElementSimulation (anApp);
+  mySimulation = new SMESH::TElementSimulationQuad (anApp);
   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
 
   QString anElementName;
@@ -358,6 +362,9 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
   case SMDSEntity_BiQuad_Quadrangle:
     anElementName = QString("BIQUADRATIC_QUADRANGLE");
     break;
+  case SMDSEntity_BiQuad_Triangle:
+    anElementName = QString("BIQUADRATIC_TRIANGLE");
+    break;
   case SMDSEntity_Quad_Tetra:
     anElementName = QString("QUADRATIC_TETRAHEDRON");
     break;
@@ -501,6 +508,7 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
 // function : ~SMESHGUI_AddQuadraticElementDlg()
 // purpose  : Destroys the object and frees any allocated resources
 //=================================================================================
+
 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
 {
   delete mySimulation;
@@ -510,6 +518,7 @@ SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
 // function : Init()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::Init()
 {
   myRadioButton1->setChecked(true);
@@ -535,6 +544,12 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
     myNbCorners = 3;
     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
     break;
+  case SMDSEntity_BiQuad_Triangle:
+    aNumRows = 3;
+    myNbCorners = 3;
+    myNbCenterNodes = 1;
+    myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
+    break;
   case SMDSEntity_Quad_Quadrangle:
     aNumRows = 4;
     myNbCorners = 4;
@@ -651,13 +666,14 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
 // function : ClickOnApply()
 // purpose  :
 //=================================================================================
-void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
+
+bool SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
 {
   if( !isValid() )
-    return;
+    return false;
 
   if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
-    return;
+    return false;
 
   BusyLocker lock( myBusy );
 
@@ -671,6 +687,7 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
     break;
   case SMDSEntity_Quad_Triangle:
   case SMDSEntity_Quad_Quadrangle:
+  case SMDSEntity_BiQuad_Triangle:
   case SMDSEntity_BiQuad_Quadrangle:
   case SMDSEntity_Quad_Tetra:
   case SMDSEntity_Quad_Pyramid:
@@ -722,7 +739,7 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
         int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
                                              tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
                                              tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
-        if ( res == 1 ) return;
+        if ( res == 1 ) return false;
       }
       aGroup = myGroups[idx-1];
     }
@@ -737,6 +754,7 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
     anElemId = aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
   case SMDSEntity_Quad_Triangle:
   case SMDSEntity_Quad_Quadrangle:
+  case SMDSEntity_BiQuad_Triangle:
   case SMDSEntity_BiQuad_Quadrangle:
     anElementType = SMESH::FACE;
     anElemId = aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
@@ -794,22 +812,26 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
   updateButtons();
 
   SMESHGUI::Modified();
+
+  return true;
 }
 
 //=================================================================================
 // function : ClickOnOk()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
 {
-  ClickOnApply();
-  reject();
+  if ( ClickOnApply() )
+    reject();
 }
 
 //=================================================================================
 // function : reject()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::reject()
 {
   mySelectionMgr->clearSelected();
@@ -826,6 +848,7 @@ void SMESHGUI_AddQuadraticElementDlg::reject()
 // function : ClickOnHelp()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
 {
   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
@@ -850,6 +873,7 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
 // function : onTextChange()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
 {
   if (myBusy) return;
@@ -901,6 +925,7 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
 // function : SelectionIntoArgument()
 // purpose  : Called when selection has changed
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 {
   if (myBusy) return;
@@ -922,7 +947,7 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 
     // get selected mesh
     SALOME_ListIO aList;
-    mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
+    mySelectionMgr->selectedObjects(aList);
 
     if (aList.Extent() != 1)
     {
@@ -951,6 +976,7 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
       anElementType = SMESH::EDGE; break;
     case SMDSEntity_Quad_Triangle:
     case SMDSEntity_Quad_Quadrangle:
+    case SMDSEntity_BiQuad_Triangle:
     case SMDSEntity_BiQuad_Quadrangle:
       anElementType = SMESH::FACE; break;
     case SMDSEntity_Quad_Tetra:
@@ -1008,11 +1034,12 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 // function : displaySimulation()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
 {
   if ( IsValid() )
   {
-    SMESH::TElementSimulation::TVTKIds anIds;
+    SMESH::TElementSimulationQuad::TVTKIds anIds;
 
     // Collect ids from the dialog
     int anID;
@@ -1068,6 +1095,7 @@ void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
 // function : SetCurrentSelection()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::SetCurrentSelection()
 {
   QPushButton* send = (QPushButton*)sender();
@@ -1091,6 +1119,7 @@ void SMESHGUI_AddQuadraticElementDlg::SetCurrentSelection()
 // function : DeactivateActiveDialog()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
 {
   if (GroupConstructors->isEnabled()) {
@@ -1107,6 +1136,7 @@ void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
 // function : ActivateThisDialog()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
 {
   /* Emit a signal to deactivate the active dialog */
@@ -1127,6 +1157,7 @@ void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
 // function : enterEvent()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
 {
   if (GroupConstructors->isEnabled())
@@ -1138,6 +1169,7 @@ void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
 // function : onReverse()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
 {
   mySimulation->SetVisibility(false);
@@ -1145,11 +1177,11 @@ void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
   updateButtons();
 }
 
-
 //=================================================================================
 // function : IsValid()
 // purpose  :
 //=================================================================================
+
 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
 {
   SMDS_Mesh* aMesh = 0;
@@ -1196,6 +1228,7 @@ bool SMESHGUI_AddQuadraticElementDlg::IsValid()
 // function : UpdateTable()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
 {
   QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
@@ -1217,6 +1250,7 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
       aLastColIds  = LastEdgeIds;
       break;
     case SMDSEntity_Quad_Triangle:
+    case SMDSEntity_BiQuad_Triangle:
       aFirstColIds = FirstTriangleIds;
       aLastColIds  = LastTriangleIds;
       break;
@@ -1262,11 +1296,11 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
   }
 }
 
-
 //=================================================================================
 // function : onTableActivate()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
 {
   myCurrentLineEdit = 0;
@@ -1274,11 +1308,11 @@ void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCo
   updateButtons();
 }
 
-
 //=================================================================================
 // function : onCellTextChange()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
 {
   myCurrentLineEdit = 0;
@@ -1290,6 +1324,7 @@ void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
 // function : keyPressEvent()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
 {
   QDialog::keyPressEvent( e );
@@ -1302,6 +1337,11 @@ void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
   }
 }
 
+//=======================================================================
+//function : updateButtons
+//purpose  : 
+//=======================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
 {
   bool valid = IsValid();
@@ -1313,6 +1353,7 @@ void SMESHGUI_AddQuadraticElementDlg::updateButtons()
 // function : isValid
 // purpose  :
 //=================================================================================
+
 bool SMESHGUI_AddQuadraticElementDlg::isValid()
 {
   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {