1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_GUI.cxx
7 * \brief see MULTIPR_GUI.h
9 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
14 //*****************************************************************************
16 //*****************************************************************************
19 #include "MULTIPR_GUI.h"
20 #include "MULTIPR_GUI_Dlg.h"
21 #include "MULTIPR_Utils.hxx"
24 #include <SalomeApp_Application.h>
25 #include <SalomeApp_DataModel.h>
26 #include <SalomeApp_Study.h>
27 #include <SalomeApp_CheckFileDlg.h>
29 #include <LightApp_Study.h>
30 #include <LightApp_DataModel.h>
31 #include <LightApp_DataOwner.h>
32 #include <LightApp_SelectionMgr.h>
34 #include <CAM_DataModel.h>
35 #include <CAM_Module.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
41 #include <SALOME_LifeCycleCORBA.hxx>
42 #include <SALOMEDS_Study.hxx>
44 #include <SALOME_Event.h>
46 #include <QtxPopupMgr.h>
49 #include <QApplication>
50 #include <QInputDialog>
52 #include <QPushButton>
54 #include <QVBoxLayout>
55 #include <QButtonGroup>
65 #include <QMessageBox>
70 #include <QListIterator>
75 //*****************************************************************************
77 //*****************************************************************************
81 // // progress callback used by the MULTIPR library
82 // extern MULTIPR_ProgressCallback* gProgressCallback;
83 // extern MULTIPR_EmptyMeshCallback* gEmptyMeshCallback;
85 class MULTIPR_GUI_FinishSaveEvent: public SALOME_Event
87 SalomeApp_Application* myApp;
90 MULTIPR_GUI_FinishSaveEvent (SalomeApp_Application* theApp,
95 virtual void Execute()
98 SUIT_MessageBox::critical((QWidget*) MULTIPR_GUI::desktop(),
99 QObject::tr("SAVE_DISTMED_ERROR"),
100 // QString("Save distributed MED file error"),
101 QObject::tr("WRIT_DISTMED_ERROR"));
102 // QString("Error while writing distributed MED file"));
105 myApp->updateObjectBrowser();
106 myApp->updateActions();
108 QApplication::restoreOverrideCursor();
112 class MULTIPR_GUI_SaveThread : public QThread
115 MULTIPR_GUI_SaveThread (MULTIPR_GUI* pModule,
116 MULTIPR_ORB::MULTIPR_Obj_ptr pObj,
120 mObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(pObj);
126 MULTIPR_GUI* mModule;
127 MULTIPR_ORB::MULTIPR_Obj_ptr mObj;
131 void MULTIPR_GUI_SaveThread::run()
135 mObj->save(mPath.toLatin1());
139 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), true));
143 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), false));
146 //*****************************************************************************
148 //*****************************************************************************
151 MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen (SalomeApp_Application* app)
153 static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL;
157 SALOME_LifeCycleCORBA aLCC (SalomeApp_Application::namingService());
158 Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","MULTIPR" );
159 aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(comp);
160 if (!CORBA::is_nil(aGen))
163 SalomeApp_Study* aSAStudy =dynamic_cast<SalomeApp_Study*>(app->activeStudy());
164 _PTR(Study) aStudy = aSAStudy->studyDS();
165 SALOMEDS::Study_ptr aStudyDS;
167 aStudyDS = _CAST(Study,aStudy)->GetStudy();
168 aGen->SetCurrentStudy(aStudyDS);
172 if (CORBA::is_nil(aGen))
173 throw std::runtime_error("Can't find MULTIPR component");
179 //*****************************************************************************
180 // Class MULTIPR_GUI implementation
181 //*****************************************************************************
183 MULTIPR_GUI::MULTIPR_GUI()
184 : SalomeApp_Module("MULTIPR"),
185 LightApp_Module( "MULTIPR" ),
190 mTimer = new QTimer (this);
191 connect(mTimer, SIGNAL(timeout()), this, SLOT(timerDone()));
195 MULTIPR_GUI::~MULTIPR_GUI()
197 //if (mMULTIPRObj != NULL)
198 if (!CORBA::is_nil(mMULTIPRObj))
200 CORBA::release(mMULTIPRObj);
205 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
210 void MULTIPR_GUI::setMULTIPRObj (MULTIPR_ORB::MULTIPR_Obj_ptr theObj)
212 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(theObj);
215 SalomeApp_Application* MULTIPR_GUI::getAppli() const
221 void MULTIPR_GUI::initialize(CAM_Application* app)
223 SalomeApp_Module::initialize(app);
225 GetMultiprGen(dynamic_cast<SalomeApp_Application*>( app ));
227 QWidget* aParent = (QWidget*) application()->desktop();
228 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
230 //-------------------------------------------------------------------------
232 //-------------------------------------------------------------------------
233 QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED"));
237 tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"),
238 QIcon(aPixmapImportFromMEDFile),
239 tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"),
240 tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"),
241 (Qt::CTRL + Qt::Key_I),
245 SLOT(OnImportFromMEDFile()));
249 tr("MULTIPR_TLT_SPLIT"),
251 tr("MULTIPR_MEN_SPLIT"),
252 tr("MULTIPR_STS_SPLIT"),
257 SLOT(OnPartition2()));
261 tr("MULTIPR_TLT_DECIMATE"),
263 tr("MULTIPR_MEN_DECIMATE"),
264 tr("MULTIPR_STS_DECIMATE"),
273 tr("MULTIPR_TLT_REMOVE"),
275 tr("MULTIPR_MEN_REMOVE"),
276 tr("MULTIPR_STS_REMOVE"),
283 QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED"));
287 tr("MULTIPR_TLT_SAVE"),
288 QIcon(aPixmapSaveMEDFile),
289 tr("MULTIPR_MEN_SAVE"),
290 tr("MULTIPR_STS_SAVE"),
297 //-------------------------------------------------------------------------
299 //-------------------------------------------------------------------------
301 aMenuId = createMenu(tr("MULTIPR_MEN_FILE"), -1, -1);
302 createMenu(separator(), aMenuId, -1, 10);
303 aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10);
304 createMenu(ACTION_IMPORT_MED, aMenuId);
306 aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30);
307 createMenu(ACTION_IMPORT_MED, aMenuId, 10);
308 createMenu(ACTION_SAVE, aMenuId, 10);
309 createMenu(ACTION_SPLIT, aMenuId, 10);
310 createMenu(ACTION_DECIMATE, aMenuId, 10);
311 createMenu(ACTION_REMOVE, aMenuId, 10);
313 //-------------------------------------------------------------------------
315 //-------------------------------------------------------------------------
316 int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR"));
317 createTool(ACTION_IMPORT_MED, aToolId);
318 createTool(ACTION_SAVE, aToolId);
320 //-------------------------------------------------------------------------
321 // create popup menus
322 //-------------------------------------------------------------------------
323 QtxPopupMgr* mgr = popupMgr();
324 mgr->insert( action(ACTION_SPLIT), -1, -1, -1 );
325 mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 );
326 mgr->insert( action(ACTION_REMOVE), -1, -1, -1 );
327 mgr->insert( action(ACTION_SAVE), -1, -1, -1 );
329 QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}";
330 mgr->setRule(action(ACTION_SPLIT), aRule);
331 mgr->setRule(action(ACTION_DECIMATE), aRule);
332 mgr->setRule(action(ACTION_REMOVE), aRule);
333 mgr->setRule(action(ACTION_SAVE), aRule);
335 //-------------------------------------------------------------------------
336 // set progress dialog
337 //-------------------------------------------------------------------------
338 //MULTIPR_GUI_ProgressCallbackDlg* progressDlg =
339 // new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop());
340 //multipr::gProgressCallback = progressDlg;
342 //MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg =
343 // new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop());
344 //multipr::gEmptyMeshCallback = emptyMeshDlg;
348 CAM_DataModel* MULTIPR_GUI::createDataModel()
350 return new MULTIPR_GUI_DataModel(this);
354 QString MULTIPR_GUI::engineIOR() const
356 // SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(this);
357 CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(getApp()));
358 return QString(anIOR.in());
361 bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy)
363 bool bOk = SalomeApp_Module::activateModule(theStudy);
368 action(ACTION_IMPORT_MED)->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_I));
371 MULTIPR_ORB::MULTIPR_Gen_ptr aGen = GetMultiprGen(dynamic_cast<SalomeApp_Application*>(this));
372 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
373 _PTR(Study) aStudy = aSAStudy->studyDS();
374 SALOMEDS::Study_ptr aStudyDS;
376 aStudyDS = _CAST(Study,aStudy)->GetStudy();
377 aGen->SetCurrentStudy(aStudyDS);
380 _PTR(SComponent) aSComp = aStudy->FindComponent(name().toStdString());
382 _PTR(ChildIterator) it (aStudy->NewChildIterator(aSComp));
384 _PTR(SObject) aSObj = it->Value();
385 string anIOR = aSObj->GetIOR();
386 if (!anIOR.empty()) {
387 CORBA::Object_var anObj = getApp()->orb()->string_to_object(anIOR.c_str());
388 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
397 bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy)
402 // Unset actions accelerator keys
403 action(ACTION_IMPORT_MED)->setShortcut(QKeySequence());
405 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_nil();
407 return SalomeApp_Module::deactivateModule(theStudy);
411 void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
414 theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea);
415 theMap.insert(SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
419 void MULTIPR_GUI::selected(QStringList& entries, const bool multiple)
421 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
425 SUIT_DataOwnerPtrList anOwnersList;
426 mgr->selected(anOwnersList);
428 for (int i = 0 ; i < anOwnersList.size() ; i++)
430 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(anOwnersList[i].get());
432 if (!entries.contains(owner->entry()))
434 entries.append(owner->entry());
443 void MULTIPR_GUI::OnImportFromMEDFile()
447 aFilter.append(tr("MULTIPR_FLT_MED_FILES"));
448 aFilter.append(tr("MULTIPR_FLT_ALL_FILES"));
450 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
451 (QWidget*) MULTIPR_GUI::desktop(),
455 fd->setWindowTitle(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"));
456 fd->setFilters(aFilter);
457 if (fd->exec() == QDialog::Rejected)
463 QFileInfo aFileInfo(fd->selectedFile());
466 // Check the file name
467 if (!aFileInfo.exists())
470 mMEDFileName = aFileInfo.filePath();
472 QApplication::setOverrideCursor(Qt::WaitCursor);
474 // Delete previous MULTIPR object.
475 //if (mMULTIPRObj != NULL)
476 if (!CORBA::is_nil(mMULTIPRObj) && !mMULTIPRObj->_non_existent())
478 mMULTIPRObj->reset();
481 MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(dynamic_cast<SalomeApp_Application*>( this ));
485 mMULTIPRObj = multiprgen->getObject(mMEDFileName.toLatin1());
489 SUIT_MessageBox::critical(
490 (QWidget*) MULTIPR_GUI::desktop(),
491 QObject::tr("IMPORT_MED_ERROR"),
492 // "Import MED file error",
493 QObject::tr("INVALID_MED_FILE"));
494 // "Invalid MED file (not recognized by MULTIPR)");
496 QApplication::restoreOverrideCursor();
498 //if (mMULTIPRObj != NULL)
499 if (!CORBA::is_nil(mMULTIPRObj))
501 SALOMEDS::SObject_ptr aSObject = SALOMEDS::SObject::_nil();
502 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
503 _PTR(Study) aStudyDSClient = aSAStudy->studyDS();
504 SALOMEDS::Study_ptr aStudyDS = _CAST(Study,aStudyDSClient)->GetStudy();
505 multiprgen->PublishInStudy(aStudyDS, aSObject, mMULTIPRObj, "Mesh");
509 if (mMULTIPRObj->isValidSequentialMEDFile())
518 getApp()->updateObjectBrowser();
519 getApp()->updateActions();
524 void MULTIPR_GUI::OnPartition1()
526 // check if MULTIPRObj exists
527 //if (mMULTIPRObj == NULL)
528 if (CORBA::is_nil(mMULTIPRObj))
534 MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
538 // Now we need to save the file.
539 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
540 (QWidget*) MULTIPR_GUI::desktop(),
544 fd->setWindowTitle(tr("Save distributed MED file - Destination directory"));
545 fd->setFileMode(QFileDialog::DirectoryOnly);
547 if (fd->exec() == QDialog::Rejected)
550 mMULTIPRObj->reset();
551 getApp()->updateObjectBrowser();
555 QFileInfo aFileInfo(fd->selectedFile());
558 QString path = aFileInfo.filePath();
560 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
561 mMULTIPRObj->resetSaveProgress();
563 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
567 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
568 //mProgress->start("Save mesh", 100);
569 if (mProgress == NULL)
570 mProgress = new QProgressDialog ("Save mesh", "Cancel", 0,/*totalSteps*/100, (QWidget*) MULTIPR_GUI::desktop());
571 //mProgress->setProgress(0);
572 //mProgress->init(100);
573 //mTimer->start(500); // 0.5 seconds timer
574 //QApplication::restoreOverrideCursor();
575 //getApp()->updateObjectBrowser();
580 void MULTIPR_GUI::OnPartition2()
582 // check if MULTIPRObj exists
583 //if (mMULTIPRObj == NULL)
584 if (CORBA::is_nil(mMULTIPRObj))
589 retrieveSelectedParts();
591 if (mSelectedParts.count() == 0)
593 SUIT_MessageBox::warning(
594 (QWidget*) MULTIPR_GUI::desktop(),
595 QString("Split warning"),
596 QString("No parts selected"));
600 if (!removeLowerResolution())
605 MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
608 getApp()->updateObjectBrowser();
609 getApp()->updateActions();
613 void MULTIPR_GUI::OnDecimate()
615 // check if MULTIPRObj exists
616 //if (mMULTIPRObj == NULL)
617 if (CORBA::is_nil(mMULTIPRObj))
622 retrieveSelectedParts();
624 if (mSelectedParts.count() == 0)
626 SUIT_MessageBox::warning(
627 (QWidget*) MULTIPR_GUI::desktop(),
628 QString("Decimation warning"),
629 QString("No parts selected"));
633 if (!removeLowerResolution())
638 const QStringList& partsList = this->getSelectedParts();
639 QString allParts = partsList.join("|");
640 MULTIPR_ORB::string_array* listFields = this->getMULTIPRObj()->getFields(allParts.toLatin1());
641 if (listFields->length() == 0)
643 SUIT_MessageBox::critical(
644 (QWidget*) MULTIPR_GUI::desktop(),
645 QObject::tr("DECIM_ERROR"),
646 // "Decimation error",
647 QObject::tr("NO_FIELD_ON_PART"));
648 // "No field for this part.",);
652 MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
655 getApp()->updateObjectBrowser();
656 getApp()->updateActions();
660 void MULTIPR_GUI::OnRemove()
662 // check if MULTIPRObj exists
663 //if (mMULTIPRObj == NULL)
664 if (CORBA::is_nil(mMULTIPRObj))
669 retrieveSelectedParts();
671 if (mSelectedParts.count() == 0)
673 SUIT_MessageBox::warning(
674 (QWidget*) MULTIPR_GUI::desktop(),
675 QString("Remove warning"),
676 QString("No parts selected"));
680 if (QMessageBox::question(
681 (QWidget*) MULTIPR_GUI::desktop(),
682 QString("Remove selected part(s)"),
683 QString("Do you want to remove selected part(s)?"),
684 QString("&Yes"), QString("&No"),
685 QString::null, 0, 1 ) )
690 QApplication::setOverrideCursor(Qt::WaitCursor);
694 QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
695 for (; it != last; it++)
697 const QString& partName = (*it);
698 cout << "Remove " << (const char*)partName.toLatin1() << endl;
699 mMULTIPRObj->removeParts(partName.toLatin1());
704 SUIT_MessageBox::critical(
705 (QWidget*) MULTIPR_GUI::desktop(),
706 QString("Remove error"),
707 QString("Error while removing selected part(s)"));
710 QApplication::restoreOverrideCursor();
712 getApp()->updateObjectBrowser();
713 getApp()->updateActions();
717 void MULTIPR_GUI::OnSave()
719 // check if MULTIPRObj exists
720 //if (mMULTIPRObj == NULL)
721 if (CORBA::is_nil(mMULTIPRObj))
726 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( (QWidget*) MULTIPR_GUI::desktop(), true,tr(""));
728 fd->setWindowTitle(tr("Save distributed MED file - Destination directory"));
729 fd->setFileMode(QFileDialog::DirectoryOnly);
731 if (fd->exec() == QDialog::Rejected)
737 QFileInfo aFileInfo(fd->selectedFile());
740 QApplication::setOverrideCursor(Qt::WaitCursor);
742 QString path = aFileInfo.filePath();
743 mMULTIPRObj->resetSaveProgress();
745 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
749 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
750 //mProgress->start("Save mesh", 100);
751 if (mProgress == NULL)
752 mProgress = new QProgressDialog ("Save mesh", "Cancel", 0,/*totalSteps*/100, (QWidget*) MULTIPR_GUI::desktop());
753 //mProgress->setProgress(0);
754 //mProgress->init(100);
755 mTimer->start(500); // 0.5 seconds timer
757 //QApplication::restoreOverrideCursor();
760 void MULTIPR_GUI::timerDone()
762 int progress = mMULTIPRObj->getSaveProgress();
763 if (mProgress != NULL) {
764 mProgress->setValue(progress);
766 if (progress >= 100) {
772 void MULTIPR_GUI::retrieveSelectedParts()
774 mSelectedParts.clear();
776 QStringList userSelection;
777 selected(userSelection, true);
778 for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
780 const QString& str = (*it);
781 QStringList words = str.split(":");
782 if (words.count() == 2)
784 if (words[0] == "MULTIPR_PART")
786 mSelectedParts.push_back(words[1]);
793 bool MULTIPR_GUI::isPartExist(const char* partName)
795 //if (mMULTIPRObj == NULL) return false;
796 if (CORBA::is_nil(mMULTIPRObj)) return false;
798 MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
799 for (int i=0 ; i<listParts->length() ; i++)
801 const char* strItem = (*listParts)[i];
802 if (strcmp(strItem, partName) == 0)
811 bool MULTIPR_GUI::removeLowerResolution()
813 // for each selected part, check if there are lower resolution
814 // and then propose to remove them before performing new process
815 QStringList partNameLowerResolution;
816 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
819 const QString& partName = (*it);
820 QString partNameLow = partName + "_LOW";
821 QString partNameMed = partName + "_MED";
822 const char* strPartNameLow = partNameLow.toLatin1();
823 const char* strPartNameMed = partNameMed.toLatin1();
825 if (isPartExist(strPartNameLow))
827 partNameLowerResolution.push_back(partNameLow);
828 cout << "Part to be removed: " << strPartNameLow << endl;
831 if (isPartExist(strPartNameMed))
833 partNameLowerResolution.push_back(partNameMed);
834 cout << "Part to be removed: " << strPartNameMed << endl;
838 if (partNameLowerResolution.count() > 0)
840 if (QMessageBox::question(
841 (QWidget*) MULTIPR_GUI::desktop(),
842 QObject::tr("DEL_PREV_RESULTS"),
843 // tr("Remove previous results"),
844 QObject::tr("DEL_PREV_RESULTS_QUEST"),
845 // tr("Do you want to remove previous results?"),
846 tr("&Yes"), tr("&No"),
847 QString::null, 0, 1 ) )
852 QApplication::setOverrideCursor(Qt::WaitCursor);
856 for (QStringList::const_iterator it = partNameLowerResolution.begin(),
857 last = partNameLowerResolution.end(); it != last; it++)
859 const QString& partName = (*it);
860 cout << "Remove " << (const char*)partName.toLatin1() << endl;
861 mMULTIPRObj->removeParts(partName.toLatin1());
867 SUIT_MessageBox::critical(
868 (QWidget*) MULTIPR_GUI::desktop(),
869 QObject::tr("DEL_ERROR"),
871 QObject::tr("ERROR_DEL_PREV_RESULT"));
872 // "Error while removing previous results",
875 QApplication::restoreOverrideCursor();
877 getApp()->updateObjectBrowser();
878 getApp()->updateActions();
884 SUIT_Desktop* MULTIPR_GUI::desktop()
886 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
888 return app->desktop();
894 //*****************************************************************************
895 // Super class Data Object implementation
896 //*****************************************************************************
898 MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject (SUIT_DataObject* parent, const char* name)
899 : LightApp_DataObject(parent),
900 CAM_DataObject(parent)
906 MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject()
912 QString MULTIPR_GUI_DataObject::entry() const
914 return QString("MULTIPR_OBJECT");
918 QString MULTIPR_GUI_DataObject::name() const
924 QPixmap MULTIPR_GUI_DataObject::icon() const
926 //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
932 QString MULTIPR_GUI_DataObject::toolTip() const
934 // default behaviour: return an empty string
939 //*****************************************************************************
940 // Class Data Object Module implementation
941 //*****************************************************************************
944 MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module (CAM_DataModel* dm,
945 SUIT_DataObject* parent,
947 : MULTIPR_GUI_DataObject(parent, name),
948 // LightApp_DataObject(dm, parent),
949 CAM_DataObject(parent)
957 MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module()
963 QString MULTIPR_GUI_DataObject_Module::entry() const
965 return QString("MULTIPR_MODULE:" + mName);
969 QString MULTIPR_GUI_DataObject_Module::name() const
971 CAM_ModuleObject cam(mDm,mParent);
976 QPixmap MULTIPR_GUI_DataObject_Module::icon() const
982 QString MULTIPR_GUI_DataObject_Module::toolTip() const
984 return QString("Module MULTIPR");
988 //*****************************************************************************
989 // Class Data Object Mesh implementation
990 //*****************************************************************************
992 MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh (SUIT_DataObject* parent, const char* name)
993 : MULTIPR_GUI_DataObject(parent, name),
994 CAM_DataObject(parent)
1000 MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh()
1006 QString MULTIPR_GUI_DataObject_Mesh::entry() const
1008 return QString("MULTIPR_MESH:") + mName;
1012 QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const
1018 QString MULTIPR_GUI_DataObject_Mesh::toolTip() const
1020 return QString("Original mesh");
1024 //*****************************************************************************
1025 // Class Data Object Part implementation
1026 //*****************************************************************************
1028 MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part (SUIT_DataObject* parent,
1029 const char* name, const char* info)
1030 : MULTIPR_GUI_DataObject(parent, name),
1031 CAM_DataObject(parent)
1040 // parse info to retrieve all the fields
1041 char lMeshName[256];
1043 char lPartName[256];
1045 char lMEDFileName[256];
1047 int ret = sscanf(info, "%s %d %s %s %s",
1054 // number of read parameters should be 5
1055 if (ret != 5) return;
1057 mMeshName = lMeshName;
1060 mMEDFileName = lMEDFileName;
1064 MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part()
1070 QString MULTIPR_GUI_DataObject_Part::entry() const
1072 return QString("MULTIPR_PART:") + mName;
1076 QPixmap MULTIPR_GUI_DataObject_Part::icon() const
1082 QString MULTIPR_GUI_DataObject_Part::toolTip() const
1088 //*****************************************************************************
1089 // Class Data Object Resolution implementation
1090 //*****************************************************************************
1092 MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution (SUIT_DataObject* parent,
1093 const char* name, const char* info)
1094 : MULTIPR_GUI_DataObject_Part(parent, name, info),
1095 CAM_DataObject(parent)
1101 MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution()
1107 QString MULTIPR_GUI_DataObject_Resolution::entry() const
1109 return QString("MULTIPR_RESOLUTION:") + mName;
1113 QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const
1119 QString MULTIPR_GUI_DataObject_Resolution::toolTip() const
1125 //*****************************************************************************
1127 //*****************************************************************************
1129 MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module)
1130 // : LightApp_DataModel(module)
1131 : SalomeApp_DataModel(module)
1133 mMULTIPR_GUI = dynamic_cast<MULTIPR_GUI*>(module);
1136 MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
1141 void MULTIPR_GUI_DataModel::update (LightApp_DataObject*, LightApp_Study* theStudy)
1143 LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1145 //QListIterator<SUIT_DataObject> it1,it2;
1146 QMap<SUIT_DataObject*,int> aMap;
1149 ch = modelRoot->children();
1150 DataObjectList::const_iterator it = ch.begin(), it_last = ch.end();
1151 for (; it != it_last; it++)
1152 (*it)->setParent( 0);
1157 modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1160 DataObjectList new_ch = modelRoot->children();
1161 DataObjectList::const_iterator it1 = new_ch.begin(), it1_last = new_ch.end();
1162 for (; it1 != it1_last; it1++)
1163 aMap.insert((*it1),0);
1167 DataObjectList::const_iterator it_del = ch.begin(), it_del_last = ch.end();
1168 for (; it_del != it_del_last; it_del++)
1169 if( !aMap.contains( (*it_del) ) )
1173 void MULTIPR_GUI_DataModel::build()
1177 void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
1181 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
1183 aSAStudy = dynamic_cast<SalomeApp_Study*>(getModule()->getApp()->activeStudy());
1185 if (!aSAStudy) return;
1187 MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
1190 // root is not set yet
1191 modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
1195 // find SObject in Study
1196 MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_nil();
1198 _PTR(SComponent) aSComp = aSAStudy->studyDS()->FindComponent(module()->name().toStdString());
1201 _PTR(ChildIterator) it (aSAStudy->studyDS()->NewChildIterator(aSComp));
1204 _PTR(SObject) aSObj = it->Value();
1205 string anIOR = aSObj->GetIOR();
1208 CORBA::Object_var anObj = mMULTIPR_GUI->getApp()->orb()->string_to_object(anIOR.c_str());
1209 obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1211 // set Object to MULTIPR_GUI
1212 mMULTIPR_GUI->setMULTIPRObj(obj);
1214 //CORBA::Object_var anObj = aSObj->GetObject();
1215 //obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1216 //if (!CORBA::is_nil(obj))
1218 // // set Object to MULTIPR_GUI
1219 // mMULTIPR_GUI->setMULTIPRObj(obj);
1223 // remove Data Objects, automatically built for not loaded MULTIPR module
1224 // by SalomeApp_Application::updateObjectBrowser
1225 if (aSAStudy->root())
1227 DataObjectList ch_comp;
1228 aSAStudy->root()->children(ch_comp);
1229 DataObjectList::const_iterator anIt_comp = ch_comp.begin(), aLast_comp = ch_comp.end();
1230 for (; anIt_comp != aLast_comp; anIt_comp++)
1232 LightApp_DataObject* dobj = dynamic_cast<LightApp_DataObject*>(*anIt_comp);
1233 if (dobj && dobj->name() == aSComp->GetName().c_str())
1235 //SalomeApp_DataModelSync sync (aSAStudy->studyDS(), aSAStudy->root());
1236 //sync.deleteItemWithChildren(dobj);
1237 DataObjectList ch_obj;
1238 dobj->children(ch_obj);
1239 DataObjectList::const_iterator anIt_obj = ch_obj.begin(), aLast_obj = ch_obj.end();
1240 for (; anIt_obj != aLast_obj; anIt_obj++)
1241 // delete data object of each SObject
1244 // delete data object of SComponent itself
1253 if (!CORBA::is_nil(obj))
1256 std::string lMEDFile = obj->getFilename();
1257 std::string lMEDFileName = multipr::getFilenameWithoutPath(lMEDFile.c_str());
1258 MULTIPR_GUI_DataObject_Mesh* dataObjectMED =
1259 new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMEDFileName.c_str());
1262 MULTIPR_ORB::string_array* listParts = obj->getParts();
1264 if (listParts->length() >= 1)
1266 const char* strPartName0 = (*listParts)[0];
1267 char* strPartInfo0 = obj->getPartInfo(strPartName0);
1269 char lMeshName[256];
1271 char lPartName[256];
1273 char lMEDFileName[256];
1276 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
1285 cout << "MULTIPR: build() tree; error while parsing part info" << endl;
1286 std::runtime_error("MULTIPR: build() tree; error while parsing part info");
1290 MULTIPR_GUI_DataObject_Mesh* dataObjectMesh =
1291 new MULTIPR_GUI_DataObject_Mesh(dataObjectMED, lMeshName);
1293 // PART and RESOLUTION objects
1294 MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL;
1296 for (int i = 0 ; i < listParts->length() ; i++)
1298 const char* strItem = (*listParts)[i];
1299 char* strPartInfo = obj->getPartInfo(strItem);
1302 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
1309 if (ret != 5) return;
1311 if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
1313 new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
1317 dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
1331 CAM_Module* createModule()
1333 return new MULTIPR_GUI();