1 //=============================================================================
4 // Copyright : EDF 2001
5 //=============================================================================
10 #include "Utils_ORB_INIT.hxx"
11 #include "Utils_SINGLETON.hxx"
12 #include "utilities.h"
14 #include "SALOME_Selection.h"
15 #include "SALOME_InteractiveObject.hxx"
16 #include "SALOMEGUI_QtCatchCorbaException.hxx"
18 #include "QAD_MessageBox.h"
19 #include "QAD_Tools.h"
20 #include "QAD_FileDlg.h"
22 #include "SMESH_TypeFilter.hxx"
25 #include <qinputdialog.h>
27 //VRV: porting on Qt 3.0.5
28 #if QT_VERSION >= 0x030005
29 #include <qlineedit.h>
31 //VRV: porting on Qt 3.0.5
33 static CORBA::ORB_var _orb;
35 //=============================================================================
39 //=============================================================================
40 bool MedGUI::OnGUIEvent (int theCommandID, QAD_Desktop* parent)
44 QAD_Study* myActiveStudy = parent->getActiveStudy();
45 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
46 SALOME_NamingService* myNameService = parent->getNameService();
49 QStringList filtersList ;
51 filtersList.append( tr("MED_MEN_IMPORT_MED") );
52 filtersList.append( tr("MED_MEN_ALL_FILES") ) ;
60 MESSAGE("command " << theCommandID << " activated");
62 QString myStudyName = myActiveStudy->getTitle();
64 int myStudyId = myActiveStudy->getStudyId();
67 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
69 // Selection du Fichier
70 file = QAD_FileDlg::getFileName(parent,
76 // Selection du Maillage
81 meshName = QInputDialog::getText( QString( tr("MED_INF_MESHNAME") ),
83 //VRV: porting on Qt 3.0.5
84 #if QT_VERSION >= 0x030005
87 //VRV: porting on Qt 3.0.5
89 if ( ! meshName.isEmpty())
93 medgen->readMeshInFile(file.latin1(),myStudyName,meshName);
94 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
95 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
96 QObject::tr("WRN_WARNING"),
97 QObject::tr("WRN_STUDY_LOCKED"),
98 QObject::tr("BUT_OK"));
101 catch (const SALOME::SALOME_Exception & S_ex)
103 QtCatchCorbaException(S_ex);
106 myActiveStudy->updateObjBrowser();
114 MESSAGE("command " << theCommandID << " activated");
116 QString myStudyName = myActiveStudy->getTitle();
118 int myStudyId = myActiveStudy->getStudyId();
121 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
123 // Selection du Fichier
124 file = QAD_FileDlg::getFileName(parent,
127 tr("MED_MEN_IMPORT"),
130 // Selection du Maillage
131 if (!file.isEmpty() )
135 fieldName = QInputDialog::getText(
136 QString( tr("MED_INF_FIELDNAME") ), QString::null,
137 //VRV: porting on Qt 3.0.5
138 #if QT_VERSION >= 0x030005
141 //VRV: porting on Qt 3.0.5
143 if ( ! fieldName.isEmpty())
147 medgen->readFieldInFile(file.latin1(),myStudyName,fieldName,-1,-1);
148 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
149 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
150 QObject::tr("WRN_WARNING"),
151 QObject::tr("WRN_STUDY_LOCKED"),
152 QObject::tr("BUT_OK"));
155 catch (const SALOME::SALOME_Exception & S_ex)
157 QtCatchCorbaException(S_ex);
160 myActiveStudy->updateObjBrowser();
168 MESSAGE("command " << theCommandID << " activated");
170 QString myStudyName = myActiveStudy->getTitle();
171 int myStudyId = myActiveStudy->getStudyId();
174 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
176 // Selection du Fichier
177 file = QAD_FileDlg::getFileName(parent,
180 tr("MED_MEN_IMPORT"),
182 if (!file.isEmpty() )
187 medgen->readStructFile(file.latin1(),myStudyName);
188 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
189 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
190 QObject::tr("WRN_WARNING"),
191 QObject::tr("WRN_STUDY_LOCKED"),
192 QObject::tr("BUT_OK"));
195 catch (const SALOME::SALOME_Exception & S_ex)
197 QtCatchCorbaException(S_ex);
199 myActiveStudy->updateObjBrowser();
206 //Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
207 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
208 //Sel->AddFilter(aMeshFilter) ;
210 int nbSel = Sel->IObjectCount();
213 SMESH::SMESH_Mesh_var aM;
214 SALOME_MED::MESH_var aMesh;
215 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
216 if ( IObject->hasEntry() )
218 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
219 if ( !aMorSM->_is_nil() )
221 SALOMEDS::GenericAttribute_var anAttr;
222 SALOMEDS::AttributeIOR_var anIOR;
223 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
225 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
226 aMesh = SALOME_MED::MESH::_narrow( _orb->string_to_object(anIOR->Value()) );
227 if ( aMesh->_is_nil() )
229 aM = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
232 QAD_MessageBox::warn1
233 ( QAD_Application::getDesktop(),
234 tr ("MED_WRN_WARNING"),
235 tr ("MED_INF_NOTIMPL"),
239 aMesh = aM->GetMEDMesh();
240 if ( aMesh->_is_nil() )
242 QAD_MessageBox::warn1
243 ( QAD_Application::getDesktop(),
244 tr ("MED_WRN_WARNING"),
245 tr ("MED_INF_NOTIMPL"),
251 //Sel->ClearFilters() ;
255 QAD_MessageBox::warn1
256 ( QAD_Application::getDesktop(),
257 tr ("MED_WRN_WARNING"),
258 tr ("MED_INF_NOIOR"),
270 //Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
271 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
272 //Sel->AddFilter(aSubMeshFilter) ;
274 int nbSel = Sel->IObjectCount();
277 SMESH::SMESH_subMesh_var aSubM;
278 SALOME_MED::FAMILY_var aFam;
279 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
280 if ( IObject->hasEntry() )
282 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
283 if ( !aMorSM->_is_nil() )
285 SALOMEDS::GenericAttribute_var anAttr;
286 SALOMEDS::AttributeIOR_var anIOR;
287 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
289 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
290 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
291 if ( aSubM->_is_nil() )
293 aFam=SALOME_MED::FAMILY::_narrow( _orb->string_to_object(anIOR->Value()));
294 if ( aFam->_is_nil() )
296 QAD_MessageBox::warn1
297 ( QAD_Application::getDesktop(),
298 tr ("MED_WRN_WARNING"),
299 tr ("MED_INF_NOTIMPL"),
307 DumpSubMesh( aSubM );
308 //Sel->ClearFilters() ;
313 QAD_MessageBox::warn1
314 ( QAD_Application::getDesktop(),
315 tr ("MED_WRN_WARNING"),
330 //=============================================================================
334 //=============================================================================
335 bool MedGUI::OnMousePress (QMouseEvent* pe ,
337 QAD_StudyFrame* studyFrame)
339 MESSAGE("MedGUI::OnMousePress");
343 //=============================================================================
347 //=============================================================================
348 bool MedGUI::OnMouseMove (QMouseEvent* pe ,
350 QAD_StudyFrame* studyFrame)
352 // MESSAGE("MedGUI::OnMouseMouve");
356 //=============================================================================
360 //=============================================================================
361 bool MedGUI::OnKeyPress (QKeyEvent* pe,
363 QAD_StudyFrame* studyFrame)
365 MESSAGE("MedGUI::OnKeyPress");
369 //=============================================================================
373 //=============================================================================
374 bool MedGUI::SetSettings (QAD_Desktop* parent)
376 MESSAGE("MedGUI::SetSettings");
380 //=============================================================================
384 //=============================================================================
385 bool MedGUI::CustomPopup ( QAD_Desktop* parent,
387 const QString & theContext,
388 const QString & theParent,
389 const QString & theObject )
391 MESSAGE("MedGUI::CustomPopup");
395 //=============================================================================
399 //=============================================================================
400 void MedGUI::ActiveStudyChanged( QAD_Desktop* parent )
404 //=============================================================================
408 //=============================================================================
409 void MedGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
415 //=============================================================================
419 //=============================================================================
420 bool MedGUI::DumpMesh( SALOME_MED::MESH_var MEDMesh)
423 if ( MEDMesh->_is_nil() )
428 //SALOME_MED::MESH_var MEDMesh = aMesh->GetMEDMesh();
429 string name = MEDMesh->getName();
432 int dim = MEDMesh->getMeshDimension();
434 int dim2 = MEDMesh->getSpaceDimension();
437 int k = MEDMesh->getNumberOfNodes() ;
439 Engines::double_array_var coords = MEDMesh->getCoordinates( SALOME_MED::MED_FULL_INTERLACE );
445 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] << " Z = " << coords[i+2] );
446 i = i + 3; // Only for triangles
450 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] );
456 int nbfam=MEDMesh->getNumberOfFamilies(SALOME_MED::MED_NODE);
458 SALOME_MED::Family_array_var Families=MEDMesh->getFamilies(SALOME_MED::MED_NODE) ;
460 for (k=0; k < nbfam; k++) {
462 string nomFam=Families[k]->getName();
464 int identfam=Families[k]->getIdentifier();
466 int nbelemnts=Families[k]->getNumberOfElements(SALOME_MED::MED_NONE);
468 Engines::long_array_var tabnoeuds=Families[k]->getNumber(SALOME_MED::MED_NONE);
469 for (int l=0;l<tabnoeuds->length();l++)
470 SCRUTE(tabnoeuds[l]);
474 // SALOME_MED::FAMILY_ptr Family=MEDMesh->getFamily(SALOME_MED::MED_NODE,1) ;
476 // string nomFam=Family->getName();
478 // int identfam=Family->getIdentifier();
480 // Engines::long_array_var tabnoeuds=Family->getNumber(SALOME_MED::MED_NONE);
481 // for (int l=0;l<tabnoeuds->length();l++)
482 // SCRUTE(tabnoeuds[l]);
487 //=============================================================================
491 //=============================================================================
492 bool MedGUI::DumpSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh )
494 if ( aSubMesh->_is_nil() )
497 SALOME_MED::FAMILY_var Fam = aSubMesh->GetFamily();
498 if ( Fam->_is_nil() )
501 Engines::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
502 for (int l=0;l<tabnoeuds->length();l++)
503 SCRUTE(tabnoeuds[l]);
507 //=============================================================================
511 //=============================================================================
512 bool MedGUI::DumpSubMesh( SALOME_MED::FAMILY_var Fam )
515 if ( Fam->_is_nil() )
518 Engines::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
519 for (int l=0;l<tabnoeuds->length();l++)
520 SCRUTE(tabnoeuds[l]);
525 //=============================================================================
529 //=============================================================================
530 Engines::Med_Gen_ptr MedGUI::InitMedGen(QAD_Desktop* parent)
532 Engines::Component_var comp =
533 parent->getEngine("FactoryServer", "Med");
534 MESSAGE("_________________________________________");
535 Engines::Med_Gen_var clr = Engines::Med_Gen::_narrow(comp);
536 ASSERT(!CORBA::is_nil(clr));
540 //=============================================================================
544 //=============================================================================
545 void MedGUI::setOrb()
548 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
549 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
550 _orb = init( 0 , 0 );
552 INFOS("internal error : orb not found");
555 ASSERT(! CORBA::is_nil(_orb));
558 //=============================================================================
562 //=============================================================================
565 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
567 return MedGUI::OnGUIEvent(theCommandID, parent);
570 bool OnKeyPress (QKeyEvent* pe,
572 QAD_StudyFrame* studyFrame)
574 return MedGUI::OnKeyPress (pe, parent, studyFrame);
577 bool OnMousePress (QMouseEvent* pe,
579 QAD_StudyFrame* studyFrame)
581 return MedGUI::OnMousePress (pe, parent, studyFrame);
584 bool OnMouseMove (QMouseEvent* pe,
586 QAD_StudyFrame* studyFrame)
588 return MedGUI::OnMouseMove (pe, parent, studyFrame);
591 bool SetSettings ( QAD_Desktop* parent )
593 return MedGUI::SetSettings( parent );
596 bool customPopup ( QAD_Desktop* parent,
598 const QString & theContext,
599 const QString & theParent,
600 const QString & theObject )
602 return MedGUI::CustomPopup( parent, popup, theContext,
603 theParent, theObject );
606 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
608 MedGUI::DefinePopup( theContext, theParent, theObject );
611 bool activeStudyChanged ( QAD_Desktop* parent )
613 MedGUI::ActiveStudyChanged( parent );