1 // MED MEDGUI : MED component GUI implemetation
3 // Copyright (C) 2003 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
30 #include "Utils_ORB_INIT.hxx"
31 #include "Utils_SINGLETON.hxx"
32 #include "utilities.h"
34 #include <SALOME_LifeCycleCORBA.hxx>
35 #include <SALOME_InteractiveObject.hxx>
36 #include <SALOME_ListIO.hxx>
37 #include <SalomeApp_Tools.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_Tools.h>
41 #include <SUIT_FileDlg.h>
42 #include <SUIT_ResourceMgr.h>
44 #include <CAM_Application.h>
45 #include <SalomeApp_Application.h>
46 #include <SalomeApp_DataModel.h>
47 #include <SalomeApp_Study.h>
48 #include <SALOMEDSClient_Study.hxx>
49 #include <SALOMEDSClient_SObject.hxx>
51 #include <LightApp_SelectionMgr.h>
53 #include <OB_Browser.h>
55 //#include "SMESH_TypeFilter.hxx"
57 #include <MedGUI_Selection.h>
60 #include <qinputdialog.h>
62 //VRV: porting on Qt 3.0.5
63 #if QT_VERSION >= 0x030005
64 #include <qlineedit.h>
66 //VRV: porting on Qt 3.0.5
70 static CORBA::ORB_var _orb;
72 //=============================================================================
76 //=============================================================================
78 SalomeApp_Module( "MED" )
81 //=============================================================================
85 //=============================================================================
86 void MedGUI::createPopupItem( const int id,
87 const QString& clients,
89 const QString& theRule,
94 parentId = popupMgr()->actionId( action( pId ) );
96 if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
97 popupMgr()->insert( action( id ), parentId, 0 );
99 QChar lc = QtxPopupMgr::Selection::defEquality();
100 QString rule = "(%1)";
101 if( !types.isEmpty() )
102 rule += " and (%2) and (%3)";
104 rule = rule.arg( QString( "client in {%1}" ).arg( clients ) );
106 if( !types.isEmpty() )
108 rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
109 rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
112 popupMgr()->setRule( action( id ), rule, true );
115 void MedGUI::createMedAction( const int id, const QString& po_id, const QString& icon_id )
117 QWidget* parent = application()->desktop();
118 SUIT_ResourceMgr* mgr = application()->resourceMgr();
120 QPixmap pix; QIconSet icon;
121 if( !icon_id.isEmpty() )
122 pix = mgr->loadPixmap( "MED", tr( icon_id ) );
124 // pix = mgr->loadPixmap( "MED", tr( QString( "ICO_" )+po_id ) );
127 icon = QIconSet( pix );
129 createAction( id, tr( "TOP_" + po_id ), icon, tr( "MEN_" + po_id ), tr( "STB_" + po_id ), 0, parent, false, this, SLOT( onGUIEvent() ) );
132 //=============================================================================
136 //=============================================================================
137 void MedGUI::initialize( CAM_Application* app )
139 SalomeApp_Module::initialize( app );
141 QWidget* parent = application()->desktop();
143 createMedAction( 931, "MESHSEL" );
144 createMedAction( 932, "FIELDSEL" );
145 createMedAction( 933, "EXPLORE" );
146 createMedAction( 934, "DUMPMESH" );
147 createMedAction( 935, "DUMPSUBMESH" );
148 // createMedAction( 8031, "POPUPTEST" );
149 // createMedAction( 9002, "ERASE" );
150 // createMedAction( 9003, "DISPLAY" );
151 createMedAction( 4031, "MESHSEL", "ICO_TB_MESHSEL" );
152 createMedAction( 4032, "FIELDSEL", "ICO_TB_FIELDSEL" );
153 createMedAction( 4033, "EXPLORE", "ICO_TB_EXPLORE" );
155 int MedId = createMenu( tr( "MED" ), -1, 50, 10 );
156 createMenu( separator(), MedId, 10 );
157 createMenu( 931, MedId, 11 );
158 createMenu( 932, MedId, 11 );
159 createMenu( 933, MedId, 11 );
160 createMenu( 934, MedId, 11 );
161 createMenu( 935, MedId, 11 );
163 int medTb = createTool( tr( "TB_MED" ) );
164 createTool( 4031, medTb );
165 createTool( 4032, medTb );
166 createTool( 4033, medTb );
168 // QString OB = "'ObjectBrowser'",
169 // View = QString("'%1'").arg( "VTKViewer" /* SVTK_Viewer::Type()*/ );
171 // createPopupItem( 8031, View, "", "" );
172 // createPopupItem( 9002, OB, "", "" );
173 // createPopupItem( 903, OB, "", "" );
176 void MedGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
178 MedGUI_Selection sel;
179 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
182 sel.init( client, app->selectionMgr() );
183 popupMgr()->updatePopup( menu, &sel );
187 QString MedGUI::engineIOR() const
190 SALOME_MED::MED_Gen_ptr aMedGen = InitMedGen();
191 if ( !CORBA::is_nil( aMedGen) )
193 CORBA::String_var objStr = getApp()->orb()->object_to_string( aMedGen );
194 anIOR = QString( objStr.in() );
199 void MedGUI::windows( QMap<int, int>& mappa ) const
201 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
202 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
206 //=============================================================================
210 //=============================================================================
211 void MedGUI::onGUIEvent()
213 const QObject* obj = sender();
214 if ( !obj || !obj->inherits( "QAction" ) )
216 int id = actionId((QAction*)obj);
221 //=============================================================================
225 //=============================================================================
226 void MedGUI::EmitSignalCloseAllDialogs()
228 emit SignalCloseAllDialogs();
231 //=============================================================================
235 //=============================================================================
236 bool MedGUI::deactivateModule( SUIT_Study* study )
238 setMenuShown( false );
239 setToolShown( false );
241 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
242 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
244 EmitSignalCloseAllDialogs();
246 return SalomeApp_Module::deactivateModule( study );
249 //=============================================================================
253 //=============================================================================
254 bool MedGUI::activateModule( SUIT_Study* study )
256 bool res = SalomeApp_Module::activateModule( study );
258 setMenuShown( true );
259 setToolShown( true );
261 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
262 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
266 //=============================================================================
270 //=============================================================================
271 void MedGUI::onWindowActivated( SUIT_ViewWindow* )
275 //=============================================================================
279 //=============================================================================
280 bool MedGUI::OnGUIEvent (int theCommandID)
284 SalomeApp_Study* myActiveStudy = dynamic_cast< SalomeApp_Study* >( application()->activeStudy() );
288 _PTR(Study) aStudy = myActiveStudy->studyDS();
289 //SALOME_NamingService* myNameService = parent->getNameService();
292 QStringList filtersList ;
294 filtersList.append( tr("MED_MEN_IMPORT_MED") );
295 filtersList.append( tr("MED_MEN_ALL_FILES") ) ;
297 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
301 switch (theCommandID)
307 MESSAGE("command " << theCommandID << " activated");
309 QString myStudyName = myActiveStudy->studyName();
311 // int myStudyId = myActiveStudy->id();
314 SALOME_MED::MED_Gen_ptr medgen = InitMedGen();
316 // Selection du Fichier
317 file = SUIT_FileDlg::getFileName(application()->desktop(),
320 tr("MED_MEN_IMPORT"),
323 // Selection du Maillage
324 if (!file.isEmpty() )
328 meshName = QInputDialog::getText( QString( tr("MED_INF_MESHNAME") ),
330 //VRV: porting on Qt 3.0.5
331 #if QT_VERSION >= 0x030005
334 //VRV: porting on Qt 3.0.5
336 if ( ! meshName.isEmpty())
340 medgen->readMeshInFile(file.latin1(),myStudyName,meshName);
341 if (myActiveStudy->studyDS()->GetProperties()->IsLocked()) {
342 SUIT_MessageBox::warn1 (application()->desktop(),
343 QObject::tr("WRN_WARNING"),
344 QObject::tr("WRN_STUDY_LOCKED"),
345 QObject::tr("BUT_OK"));
348 catch (const SALOME::SALOME_Exception & S_ex)
350 SalomeApp_Tools::QtCatchCorbaException(S_ex);
361 MESSAGE("command " << theCommandID << " activated");
363 QString myStudyName = myActiveStudy->studyName();
365 // int myStudyId = myActiveStudy->id();
368 SALOME_MED::MED_Gen_ptr medgen = InitMedGen();
370 // Selection du Fichier
371 file = SUIT_FileDlg::getFileName(application()->desktop(),
374 tr("MED_MEN_IMPORT"),
377 // Selection du Maillage
378 if (!file.isEmpty() )
382 fieldName = QInputDialog::getText(
383 QString( tr("MED_INF_FIELDNAME") ), QString::null,
384 //VRV: porting on Qt 3.0.5
385 #if QT_VERSION >= 0x030005
388 //VRV: porting on Qt 3.0.5
390 if ( ! fieldName.isEmpty())
394 medgen->readFieldInFile(file.latin1(),myStudyName,fieldName,-1,-1);
395 if (myActiveStudy->studyDS()->GetProperties()->IsLocked()) {
396 SUIT_MessageBox::warn1 (application()->desktop(),
397 QObject::tr("WRN_WARNING"),
398 QObject::tr("WRN_STUDY_LOCKED"),
399 QObject::tr("BUT_OK"));
402 catch (const SALOME::SALOME_Exception & S_ex)
404 SalomeApp_Tools::QtCatchCorbaException(S_ex);
414 MESSAGE("command " << theCommandID << " activated");
416 QString myStudyName = myActiveStudy->studyName();
417 // int myStudyId = myActiveStudy->id();
420 SALOME_MED::MED_Gen_ptr medgen = InitMedGen();
422 // Selection du Fichier
423 file = SUIT_FileDlg::getFileName(application()->desktop(),
426 tr("MED_MEN_IMPORT"),
428 if (!file.isEmpty() )
433 // medgen->readStructFile(file.latin1(),myStudyName);
434 medgen->readStructFileWithFieldType(file.latin1(),myStudyName);
436 MESSAGE("Ouais on est la !!!!");
438 if (myActiveStudy->studyDS()->GetProperties()->IsLocked()) {
440 MESSAGE("Ouais on est la 1 !!!!");
442 SUIT_MessageBox::warn1 (application()->desktop(),
443 QObject::tr("WRN_WARNING"),
444 QObject::tr("WRN_STUDY_LOCKED"),
445 QObject::tr("BUT_OK"));
448 catch (const SALOME::SALOME_Exception & S_ex)
450 MESSAGE("Ouais on est la 2 !!!!");
452 SalomeApp_Tools::QtCatchCorbaException(S_ex);
455 MESSAGE("Ouais on est la 3 !!!!");
464 //Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
467 SalomeApp_Application* app = getApp();
468 LightApp_SelectionMgr* mgr = app ? app->selectionMgr() : NULL;
470 mgr->selectedObjects( list );
471 //Sel->AddFilter(aMeshFilter) ;
473 int nbSel = list.Extent();
476 // SMESH::SMESH_Mesh_var aM;
477 SALOME_MED::MESH_var aMesh;
478 Handle(SALOME_InteractiveObject) IObject = list.First();
479 if ( IObject->hasEntry() )
481 _PTR(SObject) aMorSM = aStudy->FindObjectID( IObject->getEntry() );
484 _PTR(GenericAttribute) anAttr;
485 _PTR(AttributeIOR) anIOR;
486 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
489 aMesh = SALOME_MED::MESH::_narrow( _orb->string_to_object(anIOR->Value().c_str()) );
490 if ( aMesh->_is_nil() )
492 // aM = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
493 // if ( aM->_is_nil() )
495 // QAD_MessageBox::warn1
496 // ( QAD_Application::getDesktop(),
497 // tr ("MED_WRN_WARNING"),
498 // tr ("MED_INF_NOTIMPL"),
499 // tr ("MED_BUT_OK") );
502 // aMesh = aM->GetMEDMesh();
503 if ( aMesh->_is_nil() )
505 SUIT_MessageBox::warn1
506 ( application()->desktop(),
507 tr ("MED_WRN_WARNING"),
508 tr ("MED_INF_NOTIMPL"),
514 //Sel->ClearFilters() ;
518 SUIT_MessageBox::warn1
519 ( application()->desktop(),
520 tr ("MED_WRN_WARNING"),
521 tr ("MED_INF_NOIOR"),
533 //Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
536 SalomeApp_Application* app = getApp();
537 LightApp_SelectionMgr* mgr = app ? app->selectionMgr() : NULL;
539 mgr->selectedObjects( list );
541 //Sel->AddFilter(aSubMeshFilter) ;
543 int nbSel = list.Extent();
546 // SMESH::SMESH_subMesh_var aSubM;
547 SALOME_MED::FAMILY_var aFam;
548 Handle(SALOME_InteractiveObject) IObject = list.First();
549 if ( IObject->hasEntry() )
551 _PTR(SObject) aMorSM = aStudy->FindObjectID( IObject->getEntry() );
554 _PTR(GenericAttribute) anAttr;
555 _PTR(AttributeIOR) anIOR;
556 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
559 // aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
560 // if ( aSubM->_is_nil() )
562 // aFam=SALOME_MED::FAMILY::_narrow( _orb->string_to_object(anIOR->Value()));
563 // if ( aFam->_is_nil() )
565 // QAD_MessageBox::warn1
566 // ( QAD_Application::getDesktop(),
567 // tr ("MED_WRN_WARNING"),
568 // tr ("MED_INF_NOTIMPL"),
569 // tr ("MED_BUT_OK") );
572 // DumpSubMesh( aFam );
576 // DumpSubMesh( aSubM );
577 //Sel->ClearFilters() ;
582 SUIT_MessageBox::warn1
583 ( application()->desktop(),
584 tr ("MED_WRN_WARNING"),
596 app->updateActions(); //SRN: To update a Save button in the toolbar
602 //=============================================================================
606 //=============================================================================
607 bool MedGUI::OnMousePress (QMouseEvent* pe ,
608 SUIT_ViewWindow* wnd )
610 MESSAGE("MedGUI::OnMousePress");
614 //=============================================================================
618 //=============================================================================
619 bool MedGUI::OnMouseMove (QMouseEvent* pe ,
620 SUIT_ViewWindow* wnd )
622 // MESSAGE("MedGUI::OnMouseMouve");
626 //=============================================================================
630 //=============================================================================
631 bool MedGUI::OnKeyPress (QKeyEvent* pe,
632 SUIT_ViewWindow* wnd)
634 MESSAGE("MedGUI::OnKeyPress");
638 //=============================================================================
642 //=============================================================================
643 /*bool MedGUI::SetSettings ()
645 MESSAGE("MedGUI::SetSettings");
649 //=============================================================================
653 //=============================================================================
654 /*bool MedGUI::CustomPopup ( QPopupMenu* popup,
655 const QString & theContext,
656 const QString & theParent,
657 const QString & theObject )
659 MESSAGE("MedGUI::CustomPopup");
664 //=============================================================================
668 //=============================================================================
669 /*bool MedGUI::ActiveStudyChanged()
674 //=============================================================================
678 //=============================================================================
679 /*void MedGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
685 //=============================================================================
689 //=============================================================================
690 bool MedGUI::DumpMesh( SALOME_MED::MESH_var MEDMesh)
693 if ( MEDMesh->_is_nil() )
698 //SALOME_MED::MESH_var MEDMesh = aMesh->GetMEDMesh();
699 string name = MEDMesh->getName();
702 int dim = MEDMesh->getMeshDimension();
704 int dim2 = MEDMesh->getSpaceDimension();
707 int k = MEDMesh->getNumberOfNodes() ;
709 SALOME_MED::double_array_var coords = MEDMesh->getCoordinates( SALOME_MED::MED_FULL_INTERLACE );
715 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] << " Z = " << coords[i+2] );
716 i = i + 3; // Only for triangles
720 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] );
726 int nbfam=MEDMesh->getNumberOfFamilies(SALOME_MED::MED_NODE);
728 SALOME_MED::Family_array_var Families=MEDMesh->getFamilies(SALOME_MED::MED_NODE) ;
730 for (k=0; k < nbfam; k++) {
732 string nomFam=Families[k]->getName();
734 int identfam=Families[k]->getIdentifier();
736 int nbelemnts=Families[k]->getNumberOfElements(SALOME_MED::MED_NONE);
738 SALOME_MED::long_array_var tabnoeuds=Families[k]->getNumber(SALOME_MED::MED_NONE);
739 for (int l=0;l<(int)tabnoeuds->length();l++)
740 SCRUTE(tabnoeuds[l]);
744 // SALOME_MED::FAMILY_ptr Family=MEDMesh->getFamily(SALOME_MED::MED_NODE,1) ;
746 // string nomFam=Family->getName();
748 // int identfam=Family->getIdentifier();
750 // SALOME_MED::long_array_var tabnoeuds=Family->getNumber(SALOME_MED::MED_NONE);
751 // for (int l=0;l<tabnoeuds->length();l++)
752 // SCRUTE(tabnoeuds[l]);
757 //=============================================================================
761 //=============================================================================
762 // bool MedGUI::DumpSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh )
764 // if ( aSubMesh->_is_nil() )
767 // SALOME_MED::FAMILY_var Fam = aSubMesh->GetFamily();
768 // if ( Fam->_is_nil() )
771 // SALOME_MED::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
772 // for (int l=0;l<tabnoeuds->length();l++)
773 // SCRUTE(tabnoeuds[l]);
777 //=============================================================================
781 //=============================================================================
782 bool MedGUI::DumpSubMesh( SALOME_MED::FAMILY_var Fam )
785 if ( Fam->_is_nil() )
788 SALOME_MED::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
789 for (int l=0;l<(int)tabnoeuds->length();l++)
790 SCRUTE(tabnoeuds[l]);
795 //=============================================================================
799 //=============================================================================
800 SALOME_MED::MED_Gen_ptr MedGUI::InitMedGen() const
802 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
803 Engines::Component_var comp =
804 SALOME_LifeCycleCORBA(app->namingService()).FindOrLoad_Component( "FactoryServer", "MED" );
806 MESSAGE("_________________________________________");
807 SALOME_MED::MED_Gen_var clr = SALOME_MED::MED_Gen::_narrow(comp);
808 ASSERT(!CORBA::is_nil(clr));
812 //=============================================================================
816 //=============================================================================
817 void MedGUI::setOrb()
820 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
821 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
822 _orb = init( 0 , 0 );
824 INFOS("internal error : orb not found");
827 ASSERT(! CORBA::is_nil(_orb));
831 Standard_EXPORT CAM_Module* createModule() {