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