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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
31 #include "Utils_ORB_INIT.hxx"
32 #include "Utils_SINGLETON.hxx"
33 #include "utilities.h"
35 #include "SALOME_Selection.h"
36 #include "SALOME_InteractiveObject.hxx"
37 #include "SALOMEGUI_QtCatchCorbaException.hxx"
39 #include "QAD_MessageBox.h"
40 #include "QAD_Tools.h"
41 #include "QAD_FileDlg.h"
43 //#include "SMESH_TypeFilter.hxx"
46 #include <qinputdialog.h>
48 //VRV: porting on Qt 3.0.5
49 #if QT_VERSION >= 0x030005
50 #include <qlineedit.h>
52 //VRV: porting on Qt 3.0.5
54 static CORBA::ORB_var _orb;
56 //=============================================================================
60 //=============================================================================
61 MedGUI::MedGUI( const QString& theName, QObject* theParent ) :
62 SALOMEGUI( theName, theParent )
65 bool MedGUI::OnGUIEvent (int theCommandID, QAD_Desktop* parent)
69 QAD_Study* myActiveStudy = parent->getActiveStudy();
70 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
71 SALOME_NamingService* myNameService = parent->getNameService();
74 QStringList filtersList ;
76 filtersList.append( tr("MED_MEN_IMPORT_MED") );
77 filtersList.append( tr("MED_MEN_ALL_FILES") ) ;
85 MESSAGE("command " << theCommandID << " activated");
87 QString myStudyName = myActiveStudy->getTitle();
89 int myStudyId = myActiveStudy->getStudyId();
92 SALOME_MED::MED_Gen_ptr medgen = InitMedGen(parent);
94 // Selection du Fichier
95 file = QAD_FileDlg::getFileName(parent,
101 // Selection du Maillage
102 if (!file.isEmpty() )
106 meshName = QInputDialog::getText( QString( tr("MED_INF_MESHNAME") ),
108 //VRV: porting on Qt 3.0.5
109 #if QT_VERSION >= 0x030005
112 //VRV: porting on Qt 3.0.5
114 if ( ! meshName.isEmpty())
118 medgen->readMeshInFile(file.latin1(),myStudyName,meshName);
119 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
120 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
121 QObject::tr("WRN_WARNING"),
122 QObject::tr("WRN_STUDY_LOCKED"),
123 QObject::tr("BUT_OK"));
126 catch (const SALOME::SALOME_Exception & S_ex)
128 QtCatchCorbaException(S_ex);
131 myActiveStudy->updateObjBrowser();
139 MESSAGE("command " << theCommandID << " activated");
141 QString myStudyName = myActiveStudy->getTitle();
143 int myStudyId = myActiveStudy->getStudyId();
146 SALOME_MED::MED_Gen_ptr medgen = InitMedGen(parent);
148 // Selection du Fichier
149 file = QAD_FileDlg::getFileName(parent,
152 tr("MED_MEN_IMPORT"),
155 // Selection du Maillage
156 if (!file.isEmpty() )
160 fieldName = QInputDialog::getText(
161 QString( tr("MED_INF_FIELDNAME") ), QString::null,
162 //VRV: porting on Qt 3.0.5
163 #if QT_VERSION >= 0x030005
166 //VRV: porting on Qt 3.0.5
168 if ( ! fieldName.isEmpty())
172 medgen->readFieldInFile(file.latin1(),myStudyName,fieldName,-1,-1);
173 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
174 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
175 QObject::tr("WRN_WARNING"),
176 QObject::tr("WRN_STUDY_LOCKED"),
177 QObject::tr("BUT_OK"));
180 catch (const SALOME::SALOME_Exception & S_ex)
182 QtCatchCorbaException(S_ex);
185 myActiveStudy->updateObjBrowser();
193 MESSAGE("command " << theCommandID << " activated");
195 QString myStudyName = myActiveStudy->getTitle();
196 int myStudyId = myActiveStudy->getStudyId();
199 SALOME_MED::MED_Gen_ptr medgen = InitMedGen(parent);
201 // Selection du Fichier
202 file = QAD_FileDlg::getFileName(parent,
205 tr("MED_MEN_IMPORT"),
207 if (!file.isEmpty() )
212 // medgen->readStructFile(file.latin1(),myStudyName);
213 medgen->readStructFileWithFieldType(file.latin1(),myStudyName);
214 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
215 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
216 QObject::tr("WRN_WARNING"),
217 QObject::tr("WRN_STUDY_LOCKED"),
218 QObject::tr("BUT_OK"));
221 catch (const SALOME::SALOME_Exception & S_ex)
223 QtCatchCorbaException(S_ex);
225 myActiveStudy->updateObjBrowser();
232 //Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
233 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
234 //Sel->AddFilter(aMeshFilter) ;
236 int nbSel = Sel->IObjectCount();
239 // SMESH::SMESH_Mesh_var aM;
240 SALOME_MED::MESH_var aMesh;
241 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
242 if ( IObject->hasEntry() )
244 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
245 if ( !aMorSM->_is_nil() )
247 SALOMEDS::GenericAttribute_var anAttr;
248 SALOMEDS::AttributeIOR_var anIOR;
249 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
251 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
252 aMesh = SALOME_MED::MESH::_narrow( _orb->string_to_object(anIOR->Value()) );
253 if ( aMesh->_is_nil() )
255 // aM = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
256 // if ( aM->_is_nil() )
258 // QAD_MessageBox::warn1
259 // ( QAD_Application::getDesktop(),
260 // tr ("MED_WRN_WARNING"),
261 // tr ("MED_INF_NOTIMPL"),
262 // tr ("MED_BUT_OK") );
265 // aMesh = aM->GetMEDMesh();
266 if ( aMesh->_is_nil() )
268 QAD_MessageBox::warn1
269 ( QAD_Application::getDesktop(),
270 tr ("MED_WRN_WARNING"),
271 tr ("MED_INF_NOTIMPL"),
277 //Sel->ClearFilters() ;
281 QAD_MessageBox::warn1
282 ( QAD_Application::getDesktop(),
283 tr ("MED_WRN_WARNING"),
284 tr ("MED_INF_NOIOR"),
296 //Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
297 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
298 //Sel->AddFilter(aSubMeshFilter) ;
300 int nbSel = Sel->IObjectCount();
303 // SMESH::SMESH_subMesh_var aSubM;
304 SALOME_MED::FAMILY_var aFam;
305 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
306 if ( IObject->hasEntry() )
308 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
309 if ( !aMorSM->_is_nil() )
311 SALOMEDS::GenericAttribute_var anAttr;
312 SALOMEDS::AttributeIOR_var anIOR;
313 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
315 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
316 // aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
317 // if ( aSubM->_is_nil() )
319 // aFam=SALOME_MED::FAMILY::_narrow( _orb->string_to_object(anIOR->Value()));
320 // if ( aFam->_is_nil() )
322 // QAD_MessageBox::warn1
323 // ( QAD_Application::getDesktop(),
324 // tr ("MED_WRN_WARNING"),
325 // tr ("MED_INF_NOTIMPL"),
326 // tr ("MED_BUT_OK") );
329 // DumpSubMesh( aFam );
333 // DumpSubMesh( aSubM );
334 //Sel->ClearFilters() ;
339 QAD_MessageBox::warn1
340 ( QAD_Application::getDesktop(),
341 tr ("MED_WRN_WARNING"),
356 //=============================================================================
360 //=============================================================================
361 bool MedGUI::OnMousePress (QMouseEvent* pe ,
363 QAD_StudyFrame* studyFrame)
365 MESSAGE("MedGUI::OnMousePress");
369 //=============================================================================
373 //=============================================================================
374 bool MedGUI::OnMouseMove (QMouseEvent* pe ,
376 QAD_StudyFrame* studyFrame)
378 // MESSAGE("MedGUI::OnMouseMouve");
382 //=============================================================================
386 //=============================================================================
387 bool MedGUI::OnKeyPress (QKeyEvent* pe,
389 QAD_StudyFrame* studyFrame)
391 MESSAGE("MedGUI::OnKeyPress");
395 //=============================================================================
399 //=============================================================================
400 bool MedGUI::SetSettings (QAD_Desktop* parent)
402 MESSAGE("MedGUI::SetSettings");
406 //=============================================================================
410 //=============================================================================
411 bool MedGUI::CustomPopup ( QAD_Desktop* parent,
413 const QString & theContext,
414 const QString & theParent,
415 const QString & theObject )
417 MESSAGE("MedGUI::CustomPopup");
422 //=============================================================================
426 //=============================================================================
427 bool MedGUI::ActiveStudyChanged( QAD_Desktop* parent )
432 //=============================================================================
436 //=============================================================================
437 void MedGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
443 //=============================================================================
447 //=============================================================================
448 bool MedGUI::DumpMesh( SALOME_MED::MESH_var MEDMesh)
451 if ( MEDMesh->_is_nil() )
456 //SALOME_MED::MESH_var MEDMesh = aMesh->GetMEDMesh();
457 string name = MEDMesh->getName();
460 int dim = MEDMesh->getMeshDimension();
462 int dim2 = MEDMesh->getSpaceDimension();
465 int k = MEDMesh->getNumberOfNodes() ;
467 SALOME_MED::double_array_var coords = MEDMesh->getCoordinates( SALOME_MED::MED_FULL_INTERLACE );
473 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] << " Z = " << coords[i+2] );
474 i = i + 3; // Only for triangles
478 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] );
484 int nbfam=MEDMesh->getNumberOfFamilies(SALOME_MED::MED_NODE);
486 SALOME_MED::Family_array_var Families=MEDMesh->getFamilies(SALOME_MED::MED_NODE) ;
488 for (k=0; k < nbfam; k++) {
490 string nomFam=Families[k]->getName();
492 int identfam=Families[k]->getIdentifier();
494 int nbelemnts=Families[k]->getNumberOfElements(SALOME_MED::MED_NONE);
496 SALOME_MED::long_array_var tabnoeuds=Families[k]->getNumber(SALOME_MED::MED_NONE);
497 for (int l=0;l<tabnoeuds->length();l++)
498 SCRUTE(tabnoeuds[l]);
502 // SALOME_MED::FAMILY_ptr Family=MEDMesh->getFamily(SALOME_MED::MED_NODE,1) ;
504 // string nomFam=Family->getName();
506 // int identfam=Family->getIdentifier();
508 // SALOME_MED::long_array_var tabnoeuds=Family->getNumber(SALOME_MED::MED_NONE);
509 // for (int l=0;l<tabnoeuds->length();l++)
510 // SCRUTE(tabnoeuds[l]);
515 //=============================================================================
519 //=============================================================================
520 // bool MedGUI::DumpSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh )
522 // if ( aSubMesh->_is_nil() )
525 // SALOME_MED::FAMILY_var Fam = aSubMesh->GetFamily();
526 // if ( Fam->_is_nil() )
529 // SALOME_MED::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
530 // for (int l=0;l<tabnoeuds->length();l++)
531 // SCRUTE(tabnoeuds[l]);
535 //=============================================================================
539 //=============================================================================
540 bool MedGUI::DumpSubMesh( SALOME_MED::FAMILY_var Fam )
543 if ( Fam->_is_nil() )
546 SALOME_MED::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
547 for (int l=0;l<tabnoeuds->length();l++)
548 SCRUTE(tabnoeuds[l]);
553 //=============================================================================
557 //=============================================================================
558 SALOME_MED::MED_Gen_ptr MedGUI::InitMedGen(QAD_Desktop* parent)
560 Engines::Component_var comp =
561 parent->getEngine("FactoryServer", "MED");
562 MESSAGE("_________________________________________");
563 SALOME_MED::MED_Gen_var clr = SALOME_MED::MED_Gen::_narrow(comp);
564 ASSERT(!CORBA::is_nil(clr));
568 //=============================================================================
572 //=============================================================================
573 void MedGUI::setOrb()
576 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
577 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
578 _orb = init( 0 , 0 );
580 INFOS("internal error : orb not found");
583 ASSERT(! CORBA::is_nil(_orb));
586 static MedGUI aGUI("");
589 Standard_EXPORT SALOMEGUI* GetComponentGUI() {