2 //=============================================================================
5 // Copyright : EDF 2001
6 //=============================================================================
11 #include "Utils_ORB_INIT.hxx"
12 #include "Utils_SINGLETON.hxx"
13 #include "utilities.h"
15 #include "SALOME_Selection.h"
16 #include "SALOME_InteractiveObject.hxx"
17 #include "SALOMEGUI_QtCatchCorbaException.hxx"
19 #include "QAD_MessageBox.h"
20 #include "QAD_Tools.h"
21 #include "QAD_FileDlg.h"
23 //#include "SMESH_TypeFilter.hxx"
26 #include <qinputdialog.h>
28 //VRV: porting on Qt 3.0.5
29 #if QT_VERSION >= 0x030005
30 #include <qlineedit.h>
32 //VRV: porting on Qt 3.0.5
34 static CORBA::ORB_var _orb;
36 //=============================================================================
40 //=============================================================================
41 bool MedGUI::OnGUIEvent (int theCommandID, QAD_Desktop* parent)
45 QAD_Study* myActiveStudy = parent->getActiveStudy();
46 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
47 SALOME_NamingService* myNameService = parent->getNameService();
50 QStringList filtersList ;
52 filtersList.append( tr("MED_MEN_IMPORT_MED") );
53 filtersList.append( tr("MED_MEN_ALL_FILES") ) ;
61 MESSAGE("command " << theCommandID << " activated");
63 QString myStudyName = myActiveStudy->getTitle();
65 int myStudyId = myActiveStudy->getStudyId();
68 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
70 // Selection du Fichier
71 file = QAD_FileDlg::getFileName(parent,
77 // Selection du Maillage
82 meshName = QInputDialog::getText( QString( tr("MED_INF_MESHNAME") ),
84 //VRV: porting on Qt 3.0.5
85 #if QT_VERSION >= 0x030005
88 //VRV: porting on Qt 3.0.5
90 if ( ! meshName.isEmpty())
94 medgen->readMeshInFile(file.latin1(),myStudyName,meshName);
95 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
96 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
97 QObject::tr("WRN_WARNING"),
98 QObject::tr("WRN_STUDY_LOCKED"),
99 QObject::tr("BUT_OK"));
102 catch (const SALOME::SALOME_Exception & S_ex)
104 QtCatchCorbaException(S_ex);
107 myActiveStudy->updateObjBrowser();
115 MESSAGE("command " << theCommandID << " activated");
117 QString myStudyName = myActiveStudy->getTitle();
119 int myStudyId = myActiveStudy->getStudyId();
122 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
124 // Selection du Fichier
125 file = QAD_FileDlg::getFileName(parent,
128 tr("MED_MEN_IMPORT"),
131 // Selection du Maillage
132 if (!file.isEmpty() )
136 fieldName = QInputDialog::getText(
137 QString( tr("MED_INF_FIELDNAME") ), QString::null,
138 //VRV: porting on Qt 3.0.5
139 #if QT_VERSION >= 0x030005
142 //VRV: porting on Qt 3.0.5
144 if ( ! fieldName.isEmpty())
148 medgen->readFieldInFile(file.latin1(),myStudyName,fieldName,-1,-1);
149 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
150 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
151 QObject::tr("WRN_WARNING"),
152 QObject::tr("WRN_STUDY_LOCKED"),
153 QObject::tr("BUT_OK"));
156 catch (const SALOME::SALOME_Exception & S_ex)
158 QtCatchCorbaException(S_ex);
161 myActiveStudy->updateObjBrowser();
169 MESSAGE("command " << theCommandID << " activated");
171 QString myStudyName = myActiveStudy->getTitle();
172 int myStudyId = myActiveStudy->getStudyId();
175 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
177 // Selection du Fichier
178 file = QAD_FileDlg::getFileName(parent,
181 tr("MED_MEN_IMPORT"),
183 if (!file.isEmpty() )
188 // medgen->readStructFile(file.latin1(),myStudyName);
189 medgen->readStructFileWithFieldType(file.latin1(),myStudyName);
190 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
191 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
192 QObject::tr("WRN_WARNING"),
193 QObject::tr("WRN_STUDY_LOCKED"),
194 QObject::tr("BUT_OK"));
197 catch (const SALOME::SALOME_Exception & S_ex)
199 QtCatchCorbaException(S_ex);
201 myActiveStudy->updateObjBrowser();
208 //Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
209 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
210 //Sel->AddFilter(aMeshFilter) ;
212 int nbSel = Sel->IObjectCount();
215 // SMESH::SMESH_Mesh_var aM;
216 SALOME_MED::MESH_var aMesh;
217 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
218 if ( IObject->hasEntry() )
220 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
221 if ( !aMorSM->_is_nil() )
223 SALOMEDS::GenericAttribute_var anAttr;
224 SALOMEDS::AttributeIOR_var anIOR;
225 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
227 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
228 aMesh = SALOME_MED::MESH::_narrow( _orb->string_to_object(anIOR->Value()) );
229 if ( aMesh->_is_nil() )
231 // aM = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
232 // if ( aM->_is_nil() )
234 // QAD_MessageBox::warn1
235 // ( QAD_Application::getDesktop(),
236 // tr ("MED_WRN_WARNING"),
237 // tr ("MED_INF_NOTIMPL"),
238 // tr ("MED_BUT_OK") );
241 // aMesh = aM->GetMEDMesh();
242 if ( aMesh->_is_nil() )
244 QAD_MessageBox::warn1
245 ( QAD_Application::getDesktop(),
246 tr ("MED_WRN_WARNING"),
247 tr ("MED_INF_NOTIMPL"),
253 //Sel->ClearFilters() ;
257 QAD_MessageBox::warn1
258 ( QAD_Application::getDesktop(),
259 tr ("MED_WRN_WARNING"),
260 tr ("MED_INF_NOIOR"),
272 //Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
273 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
274 //Sel->AddFilter(aSubMeshFilter) ;
276 int nbSel = Sel->IObjectCount();
279 // SMESH::SMESH_subMesh_var aSubM;
280 SALOME_MED::FAMILY_var aFam;
281 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
282 if ( IObject->hasEntry() )
284 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
285 if ( !aMorSM->_is_nil() )
287 SALOMEDS::GenericAttribute_var anAttr;
288 SALOMEDS::AttributeIOR_var anIOR;
289 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
291 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
292 // aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
293 // if ( aSubM->_is_nil() )
295 // aFam=SALOME_MED::FAMILY::_narrow( _orb->string_to_object(anIOR->Value()));
296 // if ( aFam->_is_nil() )
298 // QAD_MessageBox::warn1
299 // ( QAD_Application::getDesktop(),
300 // tr ("MED_WRN_WARNING"),
301 // tr ("MED_INF_NOTIMPL"),
302 // tr ("MED_BUT_OK") );
305 // DumpSubMesh( aFam );
309 // DumpSubMesh( aSubM );
310 //Sel->ClearFilters() ;
315 QAD_MessageBox::warn1
316 ( QAD_Application::getDesktop(),
317 tr ("MED_WRN_WARNING"),
332 //=============================================================================
336 //=============================================================================
337 bool MedGUI::OnMousePress (QMouseEvent* pe ,
339 QAD_StudyFrame* studyFrame)
341 MESSAGE("MedGUI::OnMousePress");
345 //=============================================================================
349 //=============================================================================
350 bool MedGUI::OnMouseMove (QMouseEvent* pe ,
352 QAD_StudyFrame* studyFrame)
354 // MESSAGE("MedGUI::OnMouseMouve");
358 //=============================================================================
362 //=============================================================================
363 bool MedGUI::OnKeyPress (QKeyEvent* pe,
365 QAD_StudyFrame* studyFrame)
367 MESSAGE("MedGUI::OnKeyPress");
371 //=============================================================================
375 //=============================================================================
376 bool MedGUI::SetSettings (QAD_Desktop* parent)
378 MESSAGE("MedGUI::SetSettings");
382 //=============================================================================
386 //=============================================================================
387 bool MedGUI::CustomPopup ( QAD_Desktop* parent,
389 const QString & theContext,
390 const QString & theParent,
391 const QString & theObject )
393 MESSAGE("MedGUI::CustomPopup");
397 //=============================================================================
401 //=============================================================================
402 void MedGUI::ActiveStudyChanged( QAD_Desktop* parent )
406 //=============================================================================
410 //=============================================================================
411 void MedGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
417 //=============================================================================
421 //=============================================================================
422 bool MedGUI::DumpMesh( SALOME_MED::MESH_var MEDMesh)
425 if ( MEDMesh->_is_nil() )
430 //SALOME_MED::MESH_var MEDMesh = aMesh->GetMEDMesh();
431 string name = MEDMesh->getName();
434 int dim = MEDMesh->getMeshDimension();
436 int dim2 = MEDMesh->getSpaceDimension();
439 int k = MEDMesh->getNumberOfNodes() ;
441 Engines::double_array_var coords = MEDMesh->getCoordinates( SALOME_MED::MED_FULL_INTERLACE );
447 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] << " Z = " << coords[i+2] );
448 i = i + 3; // Only for triangles
452 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] );
458 int nbfam=MEDMesh->getNumberOfFamilies(SALOME_MED::MED_NODE);
460 SALOME_MED::Family_array_var Families=MEDMesh->getFamilies(SALOME_MED::MED_NODE) ;
462 for (k=0; k < nbfam; k++) {
464 string nomFam=Families[k]->getName();
466 int identfam=Families[k]->getIdentifier();
468 int nbelemnts=Families[k]->getNumberOfElements(SALOME_MED::MED_NONE);
470 Engines::long_array_var tabnoeuds=Families[k]->getNumber(SALOME_MED::MED_NONE);
471 for (int l=0;l<tabnoeuds->length();l++)
472 SCRUTE(tabnoeuds[l]);
476 // SALOME_MED::FAMILY_ptr Family=MEDMesh->getFamily(SALOME_MED::MED_NODE,1) ;
478 // string nomFam=Family->getName();
480 // int identfam=Family->getIdentifier();
482 // Engines::long_array_var tabnoeuds=Family->getNumber(SALOME_MED::MED_NONE);
483 // for (int l=0;l<tabnoeuds->length();l++)
484 // SCRUTE(tabnoeuds[l]);
489 //=============================================================================
493 //=============================================================================
494 // bool MedGUI::DumpSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh )
496 // if ( aSubMesh->_is_nil() )
499 // SALOME_MED::FAMILY_var Fam = aSubMesh->GetFamily();
500 // if ( Fam->_is_nil() )
503 // Engines::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
504 // for (int l=0;l<tabnoeuds->length();l++)
505 // SCRUTE(tabnoeuds[l]);
509 //=============================================================================
513 //=============================================================================
514 bool MedGUI::DumpSubMesh( SALOME_MED::FAMILY_var Fam )
517 if ( Fam->_is_nil() )
520 Engines::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
521 for (int l=0;l<tabnoeuds->length();l++)
522 SCRUTE(tabnoeuds[l]);
527 //=============================================================================
531 //=============================================================================
532 Engines::Med_Gen_ptr MedGUI::InitMedGen(QAD_Desktop* parent)
534 Engines::Component_var comp =
535 parent->getEngine("FactoryServer", "Med");
536 MESSAGE("_________________________________________");
537 Engines::Med_Gen_var clr = Engines::Med_Gen::_narrow(comp);
538 ASSERT(!CORBA::is_nil(clr));
542 //=============================================================================
546 //=============================================================================
547 void MedGUI::setOrb()
550 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
551 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
552 _orb = init( 0 , 0 );
554 INFOS("internal error : orb not found");
557 ASSERT(! CORBA::is_nil(_orb));
560 //=============================================================================
564 //=============================================================================
567 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
569 return MedGUI::OnGUIEvent(theCommandID, parent);
572 bool OnKeyPress (QKeyEvent* pe,
574 QAD_StudyFrame* studyFrame)
576 return MedGUI::OnKeyPress (pe, parent, studyFrame);
579 bool OnMousePress (QMouseEvent* pe,
581 QAD_StudyFrame* studyFrame)
583 return MedGUI::OnMousePress (pe, parent, studyFrame);
586 bool OnMouseMove (QMouseEvent* pe,
588 QAD_StudyFrame* studyFrame)
590 return MedGUI::OnMouseMove (pe, parent, studyFrame);
593 bool SetSettings ( QAD_Desktop* parent )
595 return MedGUI::SetSettings( parent );
598 bool customPopup ( QAD_Desktop* parent,
600 const QString & theContext,
601 const QString & theParent,
602 const QString & theObject )
604 return MedGUI::CustomPopup( parent, popup, theContext,
605 theParent, theObject );
608 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
610 MedGUI::DefinePopup( theContext, theParent, theObject );
613 bool activeStudyChanged ( QAD_Desktop* parent )
615 MedGUI::ActiveStudyChanged( parent );