1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : HOMARDGUI.cxx
21 // Author : Paul RASCLE, EDF
25 #include "HOMARDGUI.h"
28 #include "Utils_ORB_INIT.hxx"
29 #include "Utils_SINGLETON.hxx"
30 #include "SALOME_LifeCycleCORBA.hxx"
32 #include "SUIT_ResourceMgr.h"
33 #include "SUIT_MessageBox.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_ViewWindow.h"
36 #include "SUIT_ViewManager.h"
37 #include <SUIT_Desktop.h>
39 #include "CAM_Module.h"
40 #include "OB_Browser.h"
42 #include "SALOME_ListIO.hxx"
43 #include "SALOME_ListIteratorOfListIO.hxx"
45 #include "SalomeApp_Application.h"
46 #include "SalomeApp_DataModel.h"
47 #include "SalomeApp_Study.h"
48 #include "LightApp_SelectionMgr.h"
49 #include "LightApp_Selection.h"
50 #include <LightApp_Preferences.h>
51 #include "SalomeApp_Module.h"
52 #include "SALOMEconfig.h"
53 #include <SALOME_LifeCycleCORBA.hxx>
55 #include <utilities.h>
60 #include "MonCreateCase.h"
61 #include "MonCreateIteration.h"
62 #include "MonPursueIteration.h"
63 #include "MonEditFile.h"
64 #include "MonEditCase.h"
65 #include "MonEditIteration.h"
66 #include "MonEditHypothesis.h"
67 #include "MonEditZone.h"
68 #include "MonEditBoundaryAn.h"
69 #include "MonEditBoundaryDi.h"
70 #include "MonMeshInfo.h"
71 #include "MonIterInfo.h"
72 #include "HomardQtCommun.h"
75 #include <boost/shared_ptr.hpp>
78 #include "SALOMEDS_Study.hxx"
79 #include "HOMARDGUI_Utils.h"
81 static CORBA::ORB_var _orb;
83 //=======================================================================
84 // function : HOMARDGUI()
85 // purpose : Constructor
86 //=======================================================================
87 HOMARDGUI::HOMARDGUI(const QString&) :
88 SalomeApp_Module( "HOMARD" ) // default name
93 //=======================================================================
94 // function : ~HOMARDGUI()
95 // purpose : Destructor
96 //=======================================================================
97 HOMARDGUI::~HOMARDGUI()
101 //=======================================================================
102 // function : InitHOMARDGen
103 // launch HOMARD component and return a handle
104 //=======================================================================
105 HOMARD::HOMARD_Gen_var HOMARDGUI::InitHOMARDGen(SalomeApp_Application* app)
107 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","HOMARD" );
108 HOMARD::HOMARD_Gen_var clr = HOMARD::HOMARD_Gen::_narrow(comp);
109 ASSERT(!CORBA::is_nil(clr));
113 //=======================================================================
114 // Module's initialization
115 void HOMARDGUI::initialize( CAM_Application* app )
116 //=======================================================================
118 SalomeApp_Module::initialize( app );
119 InitHOMARDGen(dynamic_cast<SalomeApp_Application*>( app ));
125 //================================================
126 // function : createHOMARDAction
127 // create an item in status bar and Homard menu
128 //================================================
129 void HOMARDGUI::createHOMARDAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
131 // MESSAGE("createHOMARDAction");
133 QWidget* parent = application()->desktop();
134 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
136 if ( icon_id.length() )
137 pix = resMgr->loadPixmap( "HOMARD", tr( icon_id .toLatin1().data()) );
139 pix = resMgr->loadPixmap( "HOMARD", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data()), false );
143 QString tooltip = tr(QString( "HOM_TOP_%1" ).arg( po_id ).toLatin1().data()),
144 menu = tr(QString( "HOM_MEN_%1" ).arg( po_id ).toLatin1().data()),
145 status_bar = tr(QString( "HOM_STB_%1" ).arg( po_id ).toLatin1().data());
147 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
150 //================================================
151 // function : createAction
152 // constructs Homard menu
153 // calls createHOMARDAction for each item
154 //================================================
155 void HOMARDGUI::createActions(){
157 createHOMARDAction( 1101, "NEW_CASE", "cas_calcule.png" );
158 createHOMARDAction( 1102, "PURSUE_ITERATION", "iter_poursuite.png" );
159 createHOMARDAction( 1103, "NEW_ITERATION", "iter_next.png" );
160 createHOMARDAction( 1111, "COMPUTE", "mesh_compute.png" );
161 createHOMARDAction( 1121, "MESH_INFO", "advanced_mesh_info.png" );
163 createHOMARDAction( 1201, "EDIT", "whatis.png" );
164 createHOMARDAction( 1211, "DELETE", "delete.png" );
166 createHOMARDAction( 1301, "MESH_INFO", "advanced_mesh_info.png" );
167 createHOMARDAction( 1302, "EDIT_MESS_FILE", "texte.png" );
171 //================================================
172 // function : createPreferences
173 // No preferences for Homard
175 //================================================
176 void HOMARDGUI::createPreferences(){
177 QString toto = tr( "PREF_GROUP_GENERAL" );
178 int tabId = addPreference( tr( "PREF_GROUP_GENERAL" ) );
179 int genGroup = addPreference( tr( "PREF_TAB_SETTINGS" ), tabId );
180 addPreference( tr( "PREF_TEST" ), genGroup, LightApp_Preferences::Color, "Homard", "shading_color" );
184 //================================================
185 // function : createMenus
186 // Verifier l'avant dernier nombre passe en parametre
187 //================================================
188 void HOMARDGUI::createMenus(){
189 MESSAGE("createMenus")
191 int HOMARD_Id = createMenu( tr( "HOM_MEN_HOMARD" ), -1, 5, 10 );
192 createMenu( 1101, HOMARD_Id, -1 ); //Create_Case
193 createMenu( 1102, HOMARD_Id, -1 ); //Pursue_Iteration
194 createMenu( 1103, HOMARD_Id, -1 ); //Create_Iteration
195 createMenu( 1111, HOMARD_Id, -1 ); //COMPUTE
197 HOMARD_Id = createMenu( tr( "HOM_MEN_MODIFICATION" ), -1, 5, 10 );
198 createMenu( 1201, HOMARD_Id, -1 ); //Edit
199 createMenu( 1211, HOMARD_Id, -1 ); //Delete
201 HOMARD_Id = createMenu( tr( "HOM_MEN_INFORMATION" ), -1, 5, 10 );
202 createMenu( 1301, HOMARD_Id, -1 ); //Information sur un maillage
203 createMenu( separator(), HOMARD_Id,-1);
204 createMenu( 1302, HOMARD_Id, -1 ); //EditAsciiFile pour le fichier listeStd ou bilan
205 createMenu( separator(), HOMARD_Id,-1);
206 createMenu( 1201, HOMARD_Id, -1 ); //Edit
207 createMenu( separator(), HOMARD_Id,-1);
209 /*// La langue des preferences
210 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
211 QString langue = resMgr->stringValue("language", "language", "en");
212 MESSAGE("langue " << langue.toStdString().c_str() );*/
215 //================================================
216 void HOMARDGUI::OnGUIEvent()
217 //================================================
219 MESSAGE("OnGUIEvent()")
221 const QObject* obj = sender();
222 if ( !obj || !obj->inherits( "QAction" ) )
224 int id = actionId((QAction*)obj);
227 ret = OnGUIEvent( id );
228 MESSAGE("************** End of OnGUIEvent()");
231 //=======================================================================
232 // Method OnGUIEvent pour Homard
233 //=======================================================================
234 bool HOMARDGUI::OnGUIEvent (int theCommandID)
236 MESSAGE("OnGUIEvent(int)");
237 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( application() );
238 if ( !app ) return false;
240 SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
242 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
246 SUIT_Desktop* parent = application()->desktop();
247 HOMARD::HOMARD_Gen_var homardGen = HOMARDGUI::InitHOMARDGen(app);
249 if (!CORBA::is_nil(homardGen))
252 SalomeApp_Study* aSAStudy =dynamic_cast<SalomeApp_Study*>(app->activeStudy());
253 _PTR(Study) aStudy = aSAStudy->studyDS();
254 SALOMEDS::Study_ptr aStudyDS;
256 aStudyDS = _CAST(Study,aStudy)->GetStudy();
257 homardGen->SetCurrentStudy(aStudyDS);
259 getApp()->updateObjectBrowser();
262 SCRUTE(theCommandID);
263 switch (theCommandID)
265 case 1101: // Creation d un Cas
267 MESSAGE("command " << theCommandID << " activated");
268 MonCreateCase *aDlg = new MonCreateCase( parent, true,
269 HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
274 case 1102: // Poursuite d une iteration
276 MESSAGE("command " << theCommandID << " activated");
277 MonPursueIteration *aDlg = new MonPursueIteration( parent, true,
278 HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
283 case 1103: // Creation d une Iteration
285 MESSAGE("command " << theCommandID << " activated");
286 QString IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 0);
287 MESSAGE("IterParentName " << IterParentName.toStdString().c_str() << " choisi dans arbre");
288 MonCreateIteration *IterDlg = new MonCreateIteration( parent, true,
289 HOMARD::HOMARD_Gen::_duplicate(homardGen), IterParentName ) ;
294 case 1111: // Compute une Iteration
296 MESSAGE("command " << theCommandID << " activated");
297 QString monIter=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
298 if (monIter == QString("")) break;
301 homardGen->Compute(monIter.toStdString().c_str(), 0, 1, -1, 2);
303 catch( SALOME::SALOME_Exception& S_ex )
305 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
306 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
307 getApp()->updateObjectBrowser();
313 case 1121: // Information sur le maillage de l'iteration
315 MESSAGE("command " << theCommandID << " activated");
316 QString IterName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 0);
317 MESSAGE("IterName " << IterName.toStdString().c_str() << " choisi dans arbre");
318 MonIterInfo *IterDlg = new MonIterInfo( parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), IterName ) ;
323 case 1201: // Edition d'un objet
325 MESSAGE("command " << theCommandID << " activated");
326 QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
327 if (nomObjet == QString("")) break;
328 _PTR(SObject) obj = chercheMonObjet();
332 if (HOMARD_UTILS::isCase(obj))
334 MonEditCase *aDlg = new MonEditCase(parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
337 // Edition d'une iteration
338 else if (HOMARD_UTILS::isIter(obj))
340 MonEditIteration *aDlg = new MonEditIteration(parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
343 // Edition d'une hypothese
344 else if (HOMARD_UTILS::isHypo(obj))
346 MonEditHypothesis *aDlg = new MonEditHypothesis(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName, QString(""), QString("")) ;
349 // Edition d'une zone
350 else if (HOMARD_UTILS::isZone(obj))
352 MonEditZone *aDlg = new MonEditZone(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
355 // Edition d'une frontiere discrete
356 else if (HOMARD_UTILS::isBoundaryDi(obj))
358 MESSAGE(".. Lancement de MonEditBoundaryDi" );
359 MonEditBoundaryDi *aDlg = new MonEditBoundaryDi(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
362 // Edition d'une frontiere analytique
363 else if (HOMARD_UTILS::isBoundaryAn(obj))
365 MESSAGE(".. Lancement de MonEditBoundaryAn" );
366 MonEditBoundaryAn *aDlg = new MonEditBoundaryAn(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
373 case 1211: // Suppression d'un objet
375 MESSAGE("command " << theCommandID << " activated");
376 QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
377 if (nomObjet == QString("")) break;
378 _PTR(SObject) obj = chercheMonObjet();
381 // Suppression d'un cas
382 if (HOMARD_UTILS::isCase(obj))
385 { homardGen->DeleteCase(_ObjectName.toStdString().c_str(), 1); }
386 catch( SALOME::SALOME_Exception& S_ex )
388 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
389 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
390 getApp()->updateObjectBrowser();
394 // Suppression d'une iteration
395 else if (HOMARD_UTILS::isIter(obj))
398 { homardGen->DeleteIteration(_ObjectName.toStdString().c_str(), 1); }
399 catch( SALOME::SALOME_Exception& S_ex )
401 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
402 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
403 getApp()->updateObjectBrowser();
407 // Suppression d'une hypothese
408 else if (HOMARD_UTILS::isHypo(obj))
411 { homardGen->DeleteHypo(_ObjectName.toStdString().c_str()); }
412 catch( SALOME::SALOME_Exception& S_ex )
414 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
415 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
416 getApp()->updateObjectBrowser();
420 // Suppression d'une zone
421 else if (HOMARD_UTILS::isZone(obj))
424 { homardGen->DeleteZone(_ObjectName.toStdString().c_str()); }
425 catch( SALOME::SALOME_Exception& S_ex )
427 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
428 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
429 getApp()->updateObjectBrowser();
433 // Suppression d'une frontiere
434 else if ( HOMARD_UTILS::isBoundaryDi(obj) or HOMARD_UTILS::isBoundaryAn(obj) )
437 { homardGen->DeleteBoundary(_ObjectName.toStdString().c_str()); }
438 catch( SALOME::SALOME_Exception& S_ex )
440 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
441 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
442 getApp()->updateObjectBrowser();
450 case 1301: // Information sur un maillage
452 MESSAGE("etape 1301")
453 MESSAGE("command " << theCommandID << " activated");
454 MonMeshInfo *aDlg = new MonMeshInfo( parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
459 case 1302: // Affichage du fichier mess
461 MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
462 _PTR(SObject) obj = chercheMonObjet();
463 if ((obj) and ((HOMARD_UTILS::isFilelog(obj) or HOMARD_UTILS::isFileSummary(obj))))
465 MonEditFile *aDlg = new MonEditFile( 0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
466 if ( aDlg->_codret == 0 ) { aDlg->show(); }
472 getApp()->updateObjectBrowser();
476 //=============================================================================
480 //=============================================================================
482 // Module's engine IOR
483 //=============================================================================
484 QString HOMARDGUI::engineIOR() const
485 //=============================================================================
487 CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHOMARDGen(getApp()) );
488 return QString( anIOR.in() );
491 // Module's activation
492 //=============================================================================
493 bool HOMARDGUI::activateModule( SUIT_Study* theStudy )
494 //=============================================================================
496 bool bOk = SalomeApp_Module::activateModule( theStudy );
498 setMenuShown( true );
499 setToolShown( true );
504 // Module's deactivation
505 //=============================================================================
506 bool HOMARDGUI::deactivateModule( SUIT_Study* theStudy )
507 //=============================================================================
509 setMenuShown( false );
510 setToolShown( false );
512 return SalomeApp_Module::deactivateModule( theStudy );
516 //=============================================================================
517 void HOMARDGUI::windows( QMap<int, int>& theMap ) const
518 //=============================================================================
521 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
522 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
525 //=============================================================================
526 void HOMARDGUI::setOrb()
527 //=============================================================================
531 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
532 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
533 _orb = init( 0 , 0 );
537 INFOS("internal error : orb not found");
540 ASSERT(! CORBA::is_nil(_orb));
542 //========================================
543 _PTR(SObject) HOMARDGUI::chercheMonObjet()
544 //========================================
547 SALOMEDSClient_SObject* aSO = NULL;
550 getApp()->selectionMgr()->selectedObjects( lst );
551 if ( lst.Extent() == 1 )
553 Handle(SALOME_InteractiveObject) io = lst.First();
554 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
555 _PTR(Study) study = appStudy->studyDS();
556 _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
557 _ObjectName = QString( obj->GetName().c_str() );
561 return _PTR(SObject)(aSO);
563 //=============================================================================
564 void HOMARDGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
565 //=============================================================================
567 MESSAGE("Debut de contextMenuPopup");
568 _PTR(SObject) obj = chercheMonObjet();
571 title = QString( obj->GetName().c_str() );
573 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
576 bool DeleteObject = false ;
577 bool EditObject = false ;
579 if ( HOMARD_UTILS::isBoundaryAn(obj) )
582 DeleteObject = true ;
584 else if ( HOMARD_UTILS::isBoundaryDi(obj) )
587 DeleteObject = true ;
589 else if ( HOMARD_UTILS::isZone(obj) )
592 DeleteObject = true ;
594 else if ( HOMARD_UTILS::isHypo(obj) )
597 DeleteObject = true ;
599 else if ( HOMARD_UTILS::isIter(obj) )
601 pix = resMgr->loadPixmap( "HOMARD", "iter_next.png" );
602 menu->addAction(QIcon(pix), tr(QString("HOM_MEN_NEW_ITERATION").toLatin1().data()), this,SLOT(NextIter()));
603 QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "mesh_compute.png" );
604 menu->addAction(QIcon(pix2), tr(QString("HOM_MEN_COMPUTE").toLatin1().data()), this, SLOT(LanceCalcul()));
605 pix2 = resMgr->loadPixmap( "HOMARD", "advanced_mesh_info.png" );
606 menu->addAction(QIcon(pix2), tr(QString("HOM_MEN_MESH_INFO").toLatin1().data()), this, SLOT(IterInfo()));
608 DeleteObject = true ;
610 else if ( HOMARD_UTILS::isCase(obj) )
613 DeleteObject = true ;
615 else if ( HOMARD_UTILS::isFilelog(obj) or HOMARD_UTILS::isFileSummary(obj) )
617 pix = resMgr->loadPixmap( "HOMARD", "texte.png" );
618 menu->addAction(QIcon(pix), tr(QString("HOM_MEN_EDIT_MESS_FILE").toLatin1().data()), this,SLOT(EditAsciiFile()));
620 // Ajout d'un menu d'edition pour les objets qui le proposent
623 pix = resMgr->loadPixmap( "HOMARD", "whatis.png" );
624 menu->addAction(QIcon(pix), tr(QString("HOM_MEN_EDIT").toLatin1().data()), this,SLOT(Edit()));
626 // Ajout d'un menu de destruction pour les objets qui le proposent
629 pix = resMgr->loadPixmap( "HOMARD", "delete.png" );
630 menu->addAction(QIcon(pix), tr(QString("HOM_MEN_DELETE").toLatin1().data()), this,SLOT(Delete()));
635 void HOMARDGUI::NextIter()
637 this->OnGUIEvent(1103);
640 void HOMARDGUI::LanceCalcul()
642 this->OnGUIEvent(1111);
645 void HOMARDGUI::IterInfo()
647 this->OnGUIEvent(1121);
650 void HOMARDGUI::Edit()
652 this->OnGUIEvent(1201);
655 void HOMARDGUI::Delete()
657 this->OnGUIEvent(1211);
660 // void HOMARDGUI::EditAsciiFile()
662 // this->OnGUIEvent(1301);
665 void HOMARDGUI::EditAsciiFile()
667 this->OnGUIEvent(1302);
671 //=============================================================================
673 //=============================================================================
675 Standard_EXPORT CAM_Module* createModule()
677 return new HOMARDGUI("");