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 bool MedGUI::OnGUIEvent (int theCommandID, QAD_Desktop* parent)
65 QAD_Study* myActiveStudy = parent->getActiveStudy();
66 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
67 SALOME_NamingService* myNameService = parent->getNameService();
70 QStringList filtersList ;
72 filtersList.append( tr("MED_MEN_IMPORT_MED") );
73 filtersList.append( tr("MED_MEN_ALL_FILES") ) ;
81 MESSAGE("command " << theCommandID << " activated");
83 QString myStudyName = myActiveStudy->getTitle();
85 int myStudyId = myActiveStudy->getStudyId();
88 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
90 // Selection du Fichier
91 file = QAD_FileDlg::getFileName(parent,
97 // Selection du Maillage
102 meshName = QInputDialog::getText( QString( tr("MED_INF_MESHNAME") ),
104 //VRV: porting on Qt 3.0.5
105 #if QT_VERSION >= 0x030005
108 //VRV: porting on Qt 3.0.5
110 if ( ! meshName.isEmpty())
114 medgen->readMeshInFile(file.latin1(),myStudyName,meshName);
115 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
116 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
117 QObject::tr("WRN_WARNING"),
118 QObject::tr("WRN_STUDY_LOCKED"),
119 QObject::tr("BUT_OK"));
122 catch (const SALOME::SALOME_Exception & S_ex)
124 QtCatchCorbaException(S_ex);
127 myActiveStudy->updateObjBrowser();
135 MESSAGE("command " << theCommandID << " activated");
137 QString myStudyName = myActiveStudy->getTitle();
139 int myStudyId = myActiveStudy->getStudyId();
142 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
144 // Selection du Fichier
145 file = QAD_FileDlg::getFileName(parent,
148 tr("MED_MEN_IMPORT"),
151 // Selection du Maillage
152 if (!file.isEmpty() )
156 fieldName = QInputDialog::getText(
157 QString( tr("MED_INF_FIELDNAME") ), QString::null,
158 //VRV: porting on Qt 3.0.5
159 #if QT_VERSION >= 0x030005
162 //VRV: porting on Qt 3.0.5
164 if ( ! fieldName.isEmpty())
168 medgen->readFieldInFile(file.latin1(),myStudyName,fieldName,-1,-1);
169 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
170 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
171 QObject::tr("WRN_WARNING"),
172 QObject::tr("WRN_STUDY_LOCKED"),
173 QObject::tr("BUT_OK"));
176 catch (const SALOME::SALOME_Exception & S_ex)
178 QtCatchCorbaException(S_ex);
181 myActiveStudy->updateObjBrowser();
189 MESSAGE("command " << theCommandID << " activated");
191 QString myStudyName = myActiveStudy->getTitle();
192 int myStudyId = myActiveStudy->getStudyId();
195 Engines::Med_Gen_ptr medgen = InitMedGen(parent);
197 // Selection du Fichier
198 file = QAD_FileDlg::getFileName(parent,
201 tr("MED_MEN_IMPORT"),
203 if (!file.isEmpty() )
208 // medgen->readStructFile(file.latin1(),myStudyName);
209 medgen->readStructFileWithFieldType(file.latin1(),myStudyName);
210 if (myActiveStudy->getStudyDocument()->GetProperties()->IsLocked()) {
211 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
212 QObject::tr("WRN_WARNING"),
213 QObject::tr("WRN_STUDY_LOCKED"),
214 QObject::tr("BUT_OK"));
217 catch (const SALOME::SALOME_Exception & S_ex)
219 QtCatchCorbaException(S_ex);
221 myActiveStudy->updateObjBrowser();
228 //Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
229 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
230 //Sel->AddFilter(aMeshFilter) ;
232 int nbSel = Sel->IObjectCount();
235 SMESH::SMESH_Mesh_var aM;
236 SALOME_MED::MESH_var aMesh;
237 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
238 if ( IObject->hasEntry() )
240 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
241 if ( !aMorSM->_is_nil() )
243 SALOMEDS::GenericAttribute_var anAttr;
244 SALOMEDS::AttributeIOR_var anIOR;
245 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
247 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
248 aMesh = SALOME_MED::MESH::_narrow( _orb->string_to_object(anIOR->Value()) );
249 if ( aMesh->_is_nil() )
251 aM = SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
254 QAD_MessageBox::warn1
255 ( QAD_Application::getDesktop(),
256 tr ("MED_WRN_WARNING"),
257 tr ("MED_INF_NOTIMPL"),
261 aMesh = aM->GetMEDMesh();
262 if ( aMesh->_is_nil() )
264 QAD_MessageBox::warn1
265 ( QAD_Application::getDesktop(),
266 tr ("MED_WRN_WARNING"),
267 tr ("MED_INF_NOTIMPL"),
273 //Sel->ClearFilters() ;
277 QAD_MessageBox::warn1
278 ( QAD_Application::getDesktop(),
279 tr ("MED_WRN_WARNING"),
280 tr ("MED_INF_NOIOR"),
292 //Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
293 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
294 //Sel->AddFilter(aSubMeshFilter) ;
296 int nbSel = Sel->IObjectCount();
299 SMESH::SMESH_subMesh_var aSubM;
300 SALOME_MED::FAMILY_var aFam;
301 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
302 if ( IObject->hasEntry() )
304 SALOMEDS::SObject_var aMorSM = aStudy->FindObjectID( IObject->getEntry() );
305 if ( !aMorSM->_is_nil() )
307 SALOMEDS::GenericAttribute_var anAttr;
308 SALOMEDS::AttributeIOR_var anIOR;
309 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
311 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
312 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
313 if ( aSubM->_is_nil() )
315 aFam=SALOME_MED::FAMILY::_narrow( _orb->string_to_object(anIOR->Value()));
316 if ( aFam->_is_nil() )
318 QAD_MessageBox::warn1
319 ( QAD_Application::getDesktop(),
320 tr ("MED_WRN_WARNING"),
321 tr ("MED_INF_NOTIMPL"),
329 DumpSubMesh( aSubM );
330 //Sel->ClearFilters() ;
335 QAD_MessageBox::warn1
336 ( QAD_Application::getDesktop(),
337 tr ("MED_WRN_WARNING"),
352 //=============================================================================
356 //=============================================================================
357 bool MedGUI::OnMousePress (QMouseEvent* pe ,
359 QAD_StudyFrame* studyFrame)
361 MESSAGE("MedGUI::OnMousePress");
365 //=============================================================================
369 //=============================================================================
370 bool MedGUI::OnMouseMove (QMouseEvent* pe ,
372 QAD_StudyFrame* studyFrame)
374 // MESSAGE("MedGUI::OnMouseMouve");
378 //=============================================================================
382 //=============================================================================
383 bool MedGUI::OnKeyPress (QKeyEvent* pe,
385 QAD_StudyFrame* studyFrame)
387 MESSAGE("MedGUI::OnKeyPress");
391 //=============================================================================
395 //=============================================================================
396 bool MedGUI::SetSettings (QAD_Desktop* parent)
398 MESSAGE("MedGUI::SetSettings");
402 //=============================================================================
406 //=============================================================================
407 bool MedGUI::CustomPopup ( QAD_Desktop* parent,
409 const QString & theContext,
410 const QString & theParent,
411 const QString & theObject )
413 MESSAGE("MedGUI::CustomPopup");
417 //=============================================================================
421 //=============================================================================
422 void MedGUI::ActiveStudyChanged( QAD_Desktop* parent )
426 //=============================================================================
430 //=============================================================================
431 void MedGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
437 //=============================================================================
441 //=============================================================================
442 bool MedGUI::DumpMesh( SALOME_MED::MESH_var MEDMesh)
445 if ( MEDMesh->_is_nil() )
450 //SALOME_MED::MESH_var MEDMesh = aMesh->GetMEDMesh();
451 string name = MEDMesh->getName();
454 int dim = MEDMesh->getMeshDimension();
456 int dim2 = MEDMesh->getSpaceDimension();
459 int k = MEDMesh->getNumberOfNodes() ;
461 Engines::double_array_var coords = MEDMesh->getCoordinates( SALOME_MED::MED_FULL_INTERLACE );
467 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] << " Z = " << coords[i+2] );
468 i = i + 3; // Only for triangles
472 MESSAGE ( " Coordinates X = " << coords[i] << " Y = " << coords[i+1] );
478 int nbfam=MEDMesh->getNumberOfFamilies(SALOME_MED::MED_NODE);
480 SALOME_MED::Family_array_var Families=MEDMesh->getFamilies(SALOME_MED::MED_NODE) ;
482 for (k=0; k < nbfam; k++) {
484 string nomFam=Families[k]->getName();
486 int identfam=Families[k]->getIdentifier();
488 int nbelemnts=Families[k]->getNumberOfElements(SALOME_MED::MED_NONE);
490 Engines::long_array_var tabnoeuds=Families[k]->getNumber(SALOME_MED::MED_NONE);
491 for (int l=0;l<tabnoeuds->length();l++)
492 SCRUTE(tabnoeuds[l]);
496 // SALOME_MED::FAMILY_ptr Family=MEDMesh->getFamily(SALOME_MED::MED_NODE,1) ;
498 // string nomFam=Family->getName();
500 // int identfam=Family->getIdentifier();
502 // Engines::long_array_var tabnoeuds=Family->getNumber(SALOME_MED::MED_NONE);
503 // for (int l=0;l<tabnoeuds->length();l++)
504 // SCRUTE(tabnoeuds[l]);
509 //=============================================================================
513 //=============================================================================
514 bool MedGUI::DumpSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh )
516 if ( aSubMesh->_is_nil() )
519 SALOME_MED::FAMILY_var Fam = aSubMesh->GetFamily();
520 if ( Fam->_is_nil() )
523 Engines::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
524 for (int l=0;l<tabnoeuds->length();l++)
525 SCRUTE(tabnoeuds[l]);
529 //=============================================================================
533 //=============================================================================
534 bool MedGUI::DumpSubMesh( SALOME_MED::FAMILY_var Fam )
537 if ( Fam->_is_nil() )
540 Engines::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE);
541 for (int l=0;l<tabnoeuds->length();l++)
542 SCRUTE(tabnoeuds[l]);
547 //=============================================================================
551 //=============================================================================
552 Engines::Med_Gen_ptr MedGUI::InitMedGen(QAD_Desktop* parent)
554 Engines::Component_var comp =
555 parent->getEngine("FactoryServer", "Med");
556 MESSAGE("_________________________________________");
557 Engines::Med_Gen_var clr = Engines::Med_Gen::_narrow(comp);
558 ASSERT(!CORBA::is_nil(clr));
562 //=============================================================================
566 //=============================================================================
567 void MedGUI::setOrb()
570 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
571 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
572 _orb = init( 0 , 0 );
574 INFOS("internal error : orb not found");
577 ASSERT(! CORBA::is_nil(_orb));
580 //=============================================================================
584 //=============================================================================
587 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
589 return MedGUI::OnGUIEvent(theCommandID, parent);
592 bool OnKeyPress (QKeyEvent* pe,
594 QAD_StudyFrame* studyFrame)
596 return MedGUI::OnKeyPress (pe, parent, studyFrame);
599 bool OnMousePress (QMouseEvent* pe,
601 QAD_StudyFrame* studyFrame)
603 return MedGUI::OnMousePress (pe, parent, studyFrame);
606 bool OnMouseMove (QMouseEvent* pe,
608 QAD_StudyFrame* studyFrame)
610 return MedGUI::OnMouseMove (pe, parent, studyFrame);
613 bool SetSettings ( QAD_Desktop* parent )
615 return MedGUI::SetSettings( parent );
618 bool customPopup ( QAD_Desktop* parent,
620 const QString & theContext,
621 const QString & theParent,
622 const QString & theObject )
624 return MedGUI::CustomPopup( parent, popup, theContext,
625 theParent, theObject );
628 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
630 MedGUI::DefinePopup( theContext, theParent, theObject );
633 bool activeStudyChanged ( QAD_Desktop* parent )
635 MedGUI::ActiveStudyChanged( parent );