1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // MED MEDGUI : MED component GUI implemetation
29 #include "MEDGUIFileContentDial.h"
30 #include "MEDGUIDataBaseDockWidget.hxx"
31 #include "MEDGUISelection.hxx"
33 #include <MED_version.h>
35 #include "Utils_ORB_INIT.hxx"
36 #include "Utils_SINGLETON.hxx"
37 #include "utilities.h"
39 #include <SALOME_LifeCycleCORBA.hxx>
40 #include <SALOME_InteractiveObject.hxx>
41 #include <SALOME_ListIO.hxx>
42 #include <SalomeApp_Tools.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_Tools.h>
46 #include <SUIT_FileDlg.h>
47 #include <SUIT_ResourceMgr.h>
49 #include <CAM_Application.h>
50 #include <SalomeApp_Application.h>
51 #include <SalomeApp_DataModel.h>
52 #include <SalomeApp_Study.h>
53 #include <SALOMEDSClient_Study.hxx>
54 #include <SALOMEDSClient_SObject.hxx>
56 #include <LightApp_SelectionMgr.h>
60 #include <QInputDialog>
63 #include <QDockWidget>
65 static CORBA::ORB_var _orb;
67 //=============================================================================
71 //=============================================================================
72 MedGUI::MedGUI() : LightApp_Module( "MED" ),SalomeApp_Module( "MED" )
76 void MedGUI::createMedAction( const int id, const QString& po_id, const QString& icon_id )
78 QWidget* parent = application()->desktop();
79 SUIT_ResourceMgr* mgr = application()->resourceMgr();
83 if( !icon_id.isEmpty() )
84 pix = mgr->loadPixmap( "MED", tr( (const char*)icon_id.toLatin1() ) );
86 // pix = mgr->loadPixmap( "MED", tr( QString( "ICO_" )+po_id ) );
92 tr( (const char*)("TOP_" + po_id).toLatin1() ),
94 tr( (const char*)("MEN_" + po_id).toLatin1() ),
95 tr( (const char*)("STB_" + po_id).toLatin1() ),
100 SLOT( onGUIEvent() ) );
103 action( id )->setObjectName( QString( "Action %1" ).arg( id ) );
106 //=============================================================================
110 //=============================================================================
111 void MedGUI::initialize( CAM_Application* app )
113 SalomeApp_Module::initialize( app );
115 //QWidget* parent = application()->desktop();
117 createMedAction( 931, "MESHSEL", "ICO_TB_MESHSEL" );
118 createMedAction( 932, "FIELDSEL", "ICO_TB_FIELDSEL" );
119 createMedAction( 934, "DUMPMESH" );
120 createMedAction( 935, "DUMPSUBMESH" );
121 createMedAction( 936, "EXPLORE", "ICO_TB_EXPLORE");
123 createMedAction( 4031, "MESHSEL", "ICO_TB_MESHSEL" );
124 createMedAction( 4032, "FIELDSEL", "ICO_TB_FIELDSEL" );
125 createMedAction( 4034, "EXPLORE", "ICO_TB_EXPLORE");
127 int MedId = createMenu( tr( "MED" ), -1, 50, 10 );
128 createMenu( separator(), MedId, 10 );
129 createMenu( 931, MedId, 11 );
130 createMenu( 932, MedId, 11 );
131 createMenu( 934, MedId, 11 );
132 createMenu( 935, MedId, 11 );
133 createMenu( 936, MedId, 11 );
135 int medTb = createTool( tr( "TB_MED" ) );
136 createTool( 4031, medTb );
137 createTool( 4032, medTb );
138 createTool( 4034, medTb );
140 _data_base = new MEDGUIDataBaseDockWidget(application(),application()->desktop());
141 application()->desktop()->addDockWidget(Qt::LeftDockWidgetArea,_data_base);
144 QString MedGUI::engineIOR() const
147 SALOME_MED::MED_Gen_ptr aMedGen = InitMedGen();
148 if ( !CORBA::is_nil( aMedGen) )
150 CORBA::String_var objStr = getApp()->orb()->object_to_string( aMedGen );
151 anIOR = QString( objStr.in() );
156 void MedGUI::windows( QMap<int, int>& mappa ) const
159 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
160 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
163 //=============================================================================
167 //=============================================================================
168 #include <QMetaObject>
169 #include <QtxAction.h>
170 void MedGUI::onGUIEvent()
172 const QtxAction* obj = qobject_cast<const QtxAction*>(sender());
175 int id = actionId( obj );
180 //=============================================================================
184 //=============================================================================
185 void MedGUI::EmitSignalCloseAllDialogs()
187 emit SignalCloseAllDialogs();
190 //=============================================================================
194 //=============================================================================
195 bool MedGUI::deactivateModule( SUIT_Study* study )
197 setMenuShown( false );
198 setToolShown( false );
200 _data_base->setVisible( false );
201 _data_base->toggleViewAction()->setVisible( false );
203 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
204 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
206 EmitSignalCloseAllDialogs();
208 return SalomeApp_Module::deactivateModule( study );
211 //=============================================================================
215 //=============================================================================
216 bool MedGUI::activateModule( SUIT_Study* study )
218 bool res = SalomeApp_Module::activateModule( study );
220 setMenuShown( true );
221 setToolShown( true );
223 _data_base->setVisible( true );
224 _data_base->toggleViewAction()->setVisible( true );
226 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
227 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
231 //=============================================================================
235 //=============================================================================
236 void MedGUI::onWindowActivated( SUIT_ViewWindow* )
240 //=============================================================================
244 //=============================================================================
245 bool MedGUI::OnGUIEvent (int theCommandID)
249 SalomeApp_Study* myActiveStudy = dynamic_cast< SalomeApp_Study* >( application()->activeStudy() );
253 _PTR(Study) aStudy = myActiveStudy->studyDS();
254 //SALOME_NamingService* myNameService = parent->getNameService();
257 QStringList filtersList ;
259 filtersList.append( tr("MED_MEN_IMPORT_MED") );
260 filtersList.append( tr("MED_MEN_ALL_FILES") ) ;
262 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
266 switch (theCommandID)
272 MESSAGE("command " << theCommandID << " activated");
274 QString myStudyName = myActiveStudy->studyName();
276 // int myStudyId = myActiveStudy->id();
279 SALOME_MED::MED_Gen_ptr medgen = InitMedGen();
281 // Selection du Fichier
282 file = SUIT_FileDlg::getFileName(application()->desktop(),
285 tr("MED_MEN_IMPORT"),
288 // Selection du Maillage
289 if (!file.isEmpty() )
291 SCRUTE((const char*)file.toLatin1());
293 meshName = QInputDialog::getText( application()->desktop(),
294 tr("MED_INF_MESHNAME"),
299 if ( ok && !meshName.isEmpty() )
303 medgen->readMeshInFile( (const char*)file.toLatin1(),
304 (const char*)myStudyName.toLatin1(),
305 (const char*)meshName.toLatin1() );
306 if (myActiveStudy->studyDS()->GetProperties()->IsLocked()) {
307 SUIT_MessageBox::warning ( application()->desktop(),
309 tr("WRN_STUDY_LOCKED") );
310 //QObject::tr("BUT_OK")); by default
313 catch (const SALOME::SALOME_Exception & S_ex)
315 SalomeApp_Tools::QtCatchCorbaException(S_ex);
326 MESSAGE("command " << theCommandID << " activated");
328 QString myStudyName = myActiveStudy->studyName();
330 // int myStudyId = myActiveStudy->id();
333 SALOME_MED::MED_Gen_ptr medgen = InitMedGen();
335 // Selection du Fichier
336 QString anInitialPath = "";
337 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
338 anInitialPath = QDir::currentPath();
340 file = SUIT_FileDlg::getFileName(application()->desktop(),
343 tr("MED_MEN_IMPORT"),
346 // Selection du Maillage
347 if (!file.isEmpty() )
349 SCRUTE((const char*)file.toLatin1());
351 fieldName = QInputDialog::getText( application()->desktop(),
352 tr("MED_INF_FIELDNAME"),
357 if ( ok && !fieldName.isEmpty())
361 medgen->readFieldInFile( (const char*)file.toLatin1(),
362 (const char*)myStudyName.toLatin1(),
363 (const char*)fieldName.toLatin1(),
366 if (myActiveStudy->studyDS()->GetProperties()->IsLocked()) {
367 SUIT_MessageBox::warning ( application()->desktop(),
369 tr("WRN_STUDY_LOCKED") );
370 //tr("BUT_OK")); by default
373 catch (const SALOME::SALOME_Exception & S_ex)
375 SalomeApp_Tools::QtCatchCorbaException(S_ex);
384 //Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
387 SalomeApp_Application* app = getApp();
388 LightApp_SelectionMgr* mgr = app ? app->selectionMgr() : NULL;
390 mgr->selectedObjects( list );
391 //Sel->AddFilter(aMeshFilter) ;
393 int nbSel = list.Extent();
396 // SMESH::SMESH_Mesh_var aM;
397 SALOME_MED::MESH_var aMesh;
398 Handle(SALOME_InteractiveObject) IObject = list.First();
399 if ( IObject->hasEntry() )
401 _PTR(SObject) aMorSM = aStudy->FindObjectID( IObject->getEntry() );
404 _PTR(GenericAttribute) anAttr;
405 _PTR(AttributeIOR) anIOR;
406 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
409 aMesh = SALOME_MED::MESH::_narrow( _orb->string_to_object(anIOR->Value().c_str()) );
410 if ( aMesh->_is_nil() )
412 SUIT_MessageBox::warning
413 ( application()->desktop(),
414 tr ("MED_WRN_WARNING"),
415 tr ("MED_INF_NOTIMPL") );
419 //Sel->ClearFilters() ;
423 SUIT_MessageBox::warning
424 ( application()->desktop(),
425 tr ("MED_WRN_WARNING"),
426 tr ("MED_INF_NOIOR") );
427 //tr ("MED_BUT_OK") ); by default
438 //Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
441 SalomeApp_Application* app = getApp();
442 LightApp_SelectionMgr* mgr = app ? app->selectionMgr() : NULL;
444 mgr->selectedObjects( list );
446 //Sel->AddFilter(aSubMeshFilter) ;
448 int nbSel = list.Extent();
451 // SMESH::SMESH_subMesh_var aSubM;
452 SALOME_MED::FAMILY_var aFam;
453 Handle(SALOME_InteractiveObject) IObject = list.First();
454 if ( IObject->hasEntry() )
456 _PTR(SObject) aMorSM = aStudy->FindObjectID( IObject->getEntry() );
459 _PTR(GenericAttribute) anAttr;
460 _PTR(AttributeIOR) anIOR;
461 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
467 SUIT_MessageBox::warning
468 ( application()->desktop(),
469 tr ("MED_WRN_WARNING"),
470 tr ("MED_INFNOIOR") );
471 // tr ("MED_BUT_OK") ); by default
483 MEDGUIFileContentDial* mfcd = new MEDGUIFileContentDial(_data_base, application()->desktop());
489 app->updateActions(); //SRN: To update a Save button in the toolbar
495 //=============================================================================
499 //=============================================================================
500 bool MedGUI::OnMousePress (QMouseEvent* pe ,
501 SUIT_ViewWindow* wnd )
503 MESSAGE("MedGUI::OnMousePress");
507 //=============================================================================
511 //=============================================================================
512 bool MedGUI::OnMouseMove (QMouseEvent* pe ,
513 SUIT_ViewWindow* wnd )
515 // MESSAGE("MedGUI::OnMouseMouve");
519 //=============================================================================
523 //=============================================================================
524 bool MedGUI::OnKeyPress (QKeyEvent* pe,
525 SUIT_ViewWindow* wnd)
527 MESSAGE("MedGUI::OnKeyPress");
532 //=============================================================================
536 //=============================================================================
537 bool MedGUI::DumpMesh( SALOME_MED::MESH_var MEDMesh)
540 if ( MEDMesh->_is_nil() )
545 std::string name = MEDMesh->getName();
548 int dim2 = MEDMesh->getSpaceDimension();
551 int k = MEDMesh->getNumberOfNodes() ;
553 SALOME_TYPES::ListOfDouble_var coords = MEDMesh->getCoordinates( SALOME_MED::MED_FULL_INTERLACE );
559 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] << " Z = " << coords[i+2] );
564 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] );
570 int nbfam=MEDMesh->getNumberOfFamilies(SALOME_MED::MED_NODE);
572 SALOME_MED::Family_array_var Families=MEDMesh->getFamilies(SALOME_MED::MED_NODE) ;
574 for (k=0; k < nbfam; k++) {
576 std::string nomFam=Families[k]->getName();
578 SALOME_TYPES::ListOfLong_var tabnoeuds=Families[k]->getNumber(SALOME_MED::MED_NONE);
579 for (int l=0;l<(int)tabnoeuds->length();l++)
580 SCRUTE(tabnoeuds[l]);
586 //=============================================================================
590 //=============================================================================
591 bool MedGUI::DumpSubMesh( SALOME_MED::FAMILY_var Fam )
594 if ( Fam->_is_nil() )
597 SALOME_TYPES::ListOfLong_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
598 for (int l=0;l<(int)tabnoeuds->length();l++)
599 SCRUTE(tabnoeuds[l]);
604 //=============================================================================
608 //=============================================================================
609 SALOME_MED::MED_Gen_ptr MedGUI::InitMedGen() const
611 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
612 Engines::EngineComponent_var comp =
613 SALOME_LifeCycleCORBA(app->namingService()).FindOrLoad_Component( "FactoryServer", "MED" );
615 MESSAGE("_________________________________________");
616 SALOME_MED::MED_Gen_var clr = SALOME_MED::MED_Gen::_narrow(comp);
617 ASSERT(!CORBA::is_nil(clr));
621 //=============================================================================
625 //=============================================================================
626 void MedGUI::setOrb()
629 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
630 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
631 _orb = init( 0 , 0 );
633 INFOS("internal error : orb not found");
636 ASSERT(! CORBA::is_nil(_orb));
640 Standard_EXPORT CAM_Module* createModule() {
644 Standard_EXPORT char* getModuleVersion() {
645 return (char*)SALOMEMED_VERSION_STR;