Salome HOME
PAL14419 (IMP: a filter predicate to find nodes/elements lying on any
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CreatePatternDlg.cxx
index 28bb9ad0c5e05707628d1398d5994fee150ab6d1..85579d9f125642872bde0da3ecedd4bc5ffcbed8 100755 (executable)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software\r
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA\r
 //\r
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org\r
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //\r
 //\r
 //\r
 #include "SUIT_ResourceMgr.h"\r
 #include "SUIT_Desktop.h"\r
 #include "SUIT_FileDlg.h"\r
+#include "SUIT_Session.h"\r
+#include "SUIT_MessageBox.h"\r
 \r
 #include "SalomeApp_Study.h"\r
-#include "SalomeApp_DataOwner.h"\r
-#include "SalomeApp_SelectionMgr.h"\r
+#include "LightApp_Application.h"\r
+#include "LightApp_DataOwner.h"\r
+#include "LightApp_SelectionMgr.h"\r
 #include "SalomeApp_Tools.h"\r
 \r
 #include "SALOMEDS_SObject.hxx"\r
@@ -88,9 +91,7 @@ SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg( SMESHGUI*   theModule,
      : QDialog( SMESH::GetDesktop( theModule ), theName, false,\r
                 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),\r
      mySMESHGUI( theModule ),\r
-     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),\r
-     myViewWindow( SMESH::GetViewWindow( theModule ) ),\r
-     mySelector( myViewWindow->GetSelector() )\r
+     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )\r
 {\r
   setCaption(tr("CAPTION"));\r
 \r
@@ -104,6 +105,11 @@ SMESHGUI_CreatePatternDlg::SMESHGUI_CreatePatternDlg( SMESHGUI*   theModule,
 \r
   aDlgLay->setStretchFactor(aMainFrame, 1);\r
 \r
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))\r
+    mySelector = aViewWindow->GetSelector();\r
+\r
+  myHelpFileName = "pattern_mapping.htm";\r
+\r
   Init(theType);\r
 }\r
 \r
@@ -184,6 +190,7 @@ QFrame* SMESHGUI_CreatePatternDlg::createButtonFrame (QWidget* theParent)
   myOkBtn    = new QPushButton(tr("SMESH_BUT_OK"    ), aFrame);\r
   mySaveBtn  = new QPushButton(tr("SAVE"            ), aFrame);\r
   myCloseBtn = new QPushButton(tr("SMESH_BUT_CANCEL"), aFrame);\r
+  myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);\r
 \r
   QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);\r
 \r
@@ -193,10 +200,12 @@ QFrame* SMESHGUI_CreatePatternDlg::createButtonFrame (QWidget* theParent)
   aLay->addWidget(mySaveBtn);\r
   aLay->addItem(aSpacer);\r
   aLay->addWidget(myCloseBtn);\r
+  aLay->addWidget(myHelpBtn);\r
 \r
   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));\r
   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));\r
   connect(mySaveBtn, SIGNAL(clicked()), SLOT(onSave()));\r
+  connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));\r
 \r
   return aFrame;\r
 }\r
@@ -268,9 +277,6 @@ void SMESHGUI_CreatePatternDlg::Init( const int theType )
   activateSelection();\r
   onSelectionDone();\r
 \r
-  int x, y;\r
-  mySMESHGUI->DefineDlgPosition(this, x, y);\r
-  this->move(x, y);\r
   this->show();\r
 }\r
 \r
@@ -289,7 +295,7 @@ void SMESHGUI_CreatePatternDlg::SetMesh (SMESH::SMESH_Mesh_ptr thePtr)
     _PTR(SObject) aSobj = SMESH::FindSObject(myMesh.in());\r
     //Handle(SALOME_InteractiveObject) anIObj =\r
     //  new SALOME_InteractiveObject(aSobj->GetID().c_str(), "SMESH");\r
-    SUIT_DataOwnerPtr anIObj (new SalomeApp_DataOwner(aSobj->GetID().c_str()));\r
+    SUIT_DataOwnerPtr anIObj (new LightApp_DataOwner(aSobj->GetID().c_str()));\r
 \r
     isValidMesh = mySelectionMgr->isOk(anIObj);\r
   }\r
@@ -386,7 +392,8 @@ void SMESHGUI_CreatePatternDlg::onSave()
                                tr("ERROR_OF_SAVING"), QMessageBox::Ok);\r
     } else {\r
       //SUIT_Application::getDesktop()->setSelectionModes(ActorSelection);\r
-      myViewWindow->SetSelectionMode(ActorSelection);\r
+      if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))\r
+       aViewWindow->SetSelectionMode(ActorSelection);\r
       disconnect(mySelectionMgr, 0, this, 0);\r
       disconnect(mySMESHGUI, 0, this, 0);\r
       mySMESHGUI->ResetState();\r
@@ -435,7 +442,8 @@ void SMESHGUI_CreatePatternDlg::onOk()
       return;\r
     } else {\r
       //SUIT_Application::getDesktop()->setSelectionModes(ActorSelection);\r
-      myViewWindow->SetSelectionMode(ActorSelection);\r
+      if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))\r
+       aViewWindow->SetSelectionMode(ActorSelection);\r
       disconnect(mySelectionMgr, 0, this, 0);\r
       disconnect(mySMESHGUI, 0, this, 0);\r
       mySMESHGUI->ResetState();\r
@@ -454,7 +462,8 @@ void SMESHGUI_CreatePatternDlg::onOk()
 //=======================================================================\r
 void SMESHGUI_CreatePatternDlg::onClose()\r
 {\r
-  myViewWindow->SetSelectionMode(ActorSelection);\r
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))\r
+    aViewWindow->SetSelectionMode(ActorSelection);\r
   disconnect(mySelectionMgr, 0, this, 0);\r
   disconnect(mySMESHGUI, 0, this, 0);\r
   mySMESHGUI->ResetState();\r
@@ -462,6 +471,23 @@ void SMESHGUI_CreatePatternDlg::onClose()
   emit Close();\r
 }\r
 \r
+//=================================================================================\r
+// function : onHelp()\r
+// purpose  :\r
+//=================================================================================\r
+void SMESHGUI_CreatePatternDlg::onHelp()\r
+{\r
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());\r
+  if (app) \r
+    app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);\r
+  else {\r
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),\r
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").\r
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),\r
+                          QObject::tr("BUT_OK"));\r
+  }\r
+}\r
+\r
 //=======================================================================\r
 // function : loadFromObject()\r
 // purpose  : Load pattern from geom object corresponding to the mesh/submesh\r
@@ -490,6 +516,7 @@ bool SMESHGUI_CreatePatternDlg::loadFromObject (const bool theMess)
       if      (aCode == SMESH::SMESH_Pattern::ERR_LOAD_EMPTY_SUBMESH  ) aMess = tr("ERR_LOAD_EMPTY_SUBMESH");\r
       else if (aCode == SMESH::SMESH_Pattern::ERR_LOADF_NARROW_FACE   ) aMess = tr("ERR_LOADF_NARROW_FACE");\r
       else if (aCode == SMESH::SMESH_Pattern::ERR_LOADF_CLOSED_FACE   ) aMess = tr("ERR_LOADF_CLOSED_FACE");\r
+      else if (aCode == SMESH::SMESH_Pattern::ERR_LOADF_CANT_PROJECT   ) aMess = tr("ERR_LOADF_CANT_PROJECT");\r
       else if (aCode == SMESH::SMESH_Pattern::ERR_LOADV_BAD_SHAPE     ) aMess = tr("ERR_LOADV_BAD_SHAPE");\r
       else if (aCode == SMESH::SMESH_Pattern::ERR_LOADV_COMPUTE_PARAMS) aMess = tr("ERR_LOADV_COMPUTE_PARAMS");\r
       else                                                              aMess = tr("ERROR_OF_CREATION");\r
@@ -577,10 +604,13 @@ void SMESHGUI_CreatePatternDlg::onDeactivate()
 //=======================================================================\r
 void SMESHGUI_CreatePatternDlg::enterEvent (QEvent*)\r
 {\r
-  mySMESHGUI->EmitSignalDeactivateDialog();\r
-  setEnabled(true);\r
-  activateSelection();\r
-  connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));\r
+  // there is a stange problem that enterEvent() comes after onSave()\r
+  if ( isVisible () ) {\r
+    mySMESHGUI->EmitSignalDeactivateDialog();\r
+    setEnabled(true);\r
+    activateSelection();\r
+    connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));\r
+  }\r
 }\r
 \r
 //=================================================================================\r
@@ -682,7 +712,8 @@ void SMESHGUI_CreatePatternDlg::activateSelection()
 {\r
   mySelectionMgr->clearFilters();\r
   //SUIT_Application::getDesktop()->setSelectionModes(ActorSelection);\r
-  myViewWindow->SetSelectionMode(ActorSelection);\r
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))\r
+    aViewWindow->SetSelectionMode(ActorSelection);\r
 \r
   if (myType == Type_2d) {\r
     mySelectionMgr->installFilter(new SMESH_NumberFilter\r
@@ -713,3 +744,20 @@ void SMESHGUI_CreatePatternDlg::onTypeChanged (int theType)
   else\r
     myPicture2d->hide();\r
 }\r
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void SMESHGUI_CreatePatternDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Key_F1 )
+    {
+      e->accept();
+      onHelp();
+    }
+}