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.hxx>
46 #include <QtxPopupMgr.h>
49 #include <qapplication.h>
50 #include <qinputdialog.h>
52 #include <qpushbutton.h>
53 #include <qgroupbox.h>
55 #include <qbuttongroup.h>
57 #include <qcombobox.h>
59 #include <qlineedit.h>
62 #include <qwhatsthis.h>
65 #include <qmessagebox.h>
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::error1(myApp->desktop(),
99 "Save distributed MED file error",
100 "Error while writing distributed MED file",
101 myApp->tr("MULTIPR_BUT_OK"));
104 myApp->updateObjectBrowser();
105 myApp->updateActions();
107 QApplication::restoreOverrideCursor();
111 class MULTIPR_GUI_SaveThread : public QThread
114 MULTIPR_GUI_SaveThread (MULTIPR_GUI* pModule,
115 MULTIPR_ORB::MULTIPR_Obj_ptr pObj,
119 mObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(pObj);
125 MULTIPR_GUI* mModule;
126 MULTIPR_ORB::MULTIPR_Obj_ptr mObj;
130 void MULTIPR_GUI_SaveThread::run()
138 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), true));
142 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), false));
145 //*****************************************************************************
147 //*****************************************************************************
150 MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen (const CAM_Module* theModule)
152 static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL;
156 SALOME_LifeCycleCORBA aLCC (SalomeApp_Application::namingService());
157 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer", "MULTIPR");
158 aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(aComponent);
159 if (!CORBA::is_nil(aGen))
162 SalomeApp_Study* aSAStudy =
163 dynamic_cast<SalomeApp_Study*>(theModule->application()->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"),
189 mTimer = new QTimer (this);
190 connect(mTimer, SIGNAL(timeout()), this, SLOT(timerDone()));
194 MULTIPR_GUI::~MULTIPR_GUI()
196 //if (mMULTIPRObj != NULL)
197 if (!CORBA::is_nil(mMULTIPRObj))
199 CORBA::release(mMULTIPRObj);
204 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
209 void MULTIPR_GUI::setMULTIPRObj (MULTIPR_ORB::MULTIPR_Obj_ptr theObj)
211 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(theObj);
214 SalomeApp_Application* MULTIPR_GUI::getAppli() const
220 void MULTIPR_GUI::initialize(CAM_Application* app)
222 SalomeApp_Module::initialize(app);
226 QWidget* aParent = app->desktop();
227 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
229 //-------------------------------------------------------------------------
231 //-------------------------------------------------------------------------
232 QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED"));
236 tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"),
237 QIconSet(aPixmapImportFromMEDFile),
238 tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"),
239 tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"),
244 SLOT(OnImportFromMEDFile()));
248 tr("MULTIPR_TLT_SPLIT"),
250 tr("MULTIPR_MEN_SPLIT"),
251 tr("MULTIPR_STS_SPLIT"),
256 SLOT(OnPartition2()));
260 tr("MULTIPR_TLT_DECIMATE"),
262 tr("MULTIPR_MEN_DECIMATE"),
263 tr("MULTIPR_STS_DECIMATE"),
272 tr("MULTIPR_TLT_REMOVE"),
274 tr("MULTIPR_MEN_REMOVE"),
275 tr("MULTIPR_STS_REMOVE"),
282 QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED"));
286 tr("MULTIPR_TLT_SAVE"),
287 QIconSet(aPixmapSaveMEDFile),
288 tr("MULTIPR_MEN_SAVE"),
289 tr("MULTIPR_STS_SAVE"),
296 //-------------------------------------------------------------------------
298 //-------------------------------------------------------------------------
300 aMenuId = createMenu(tr("MULTIPR_MEN_FILE"), -1, -1);
301 createMenu(separator(), aMenuId, -1, 10);
302 aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10);
303 createMenu(ACTION_IMPORT_MED, aMenuId);
305 aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30);
306 createMenu(ACTION_IMPORT_MED, aMenuId, 10);
307 createMenu(ACTION_SAVE, aMenuId, 10);
308 createMenu(ACTION_SPLIT, aMenuId, 10);
309 createMenu(ACTION_DECIMATE, aMenuId, 10);
310 createMenu(ACTION_REMOVE, aMenuId, 10);
312 //-------------------------------------------------------------------------
314 //-------------------------------------------------------------------------
315 int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR"));
316 createTool(ACTION_IMPORT_MED, aToolId);
317 createTool(ACTION_SAVE, aToolId);
319 //-------------------------------------------------------------------------
320 // create popup menus
321 //-------------------------------------------------------------------------
322 QtxPopupMgr* mgr = popupMgr();
323 mgr->insert( action(ACTION_SPLIT), -1, -1, -1 );
324 mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 );
325 mgr->insert( action(ACTION_REMOVE), -1, -1, -1 );
326 mgr->insert( action(ACTION_SAVE), -1, -1, -1 );
328 QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}";
329 mgr->setRule(action(ACTION_SPLIT), aRule, true);
330 mgr->setRule(action(ACTION_DECIMATE), aRule, true);
331 mgr->setRule(action(ACTION_REMOVE), aRule, true);
332 mgr->setRule(action(ACTION_SAVE), aRule, true);
334 //-------------------------------------------------------------------------
335 // set progress dialog
336 //-------------------------------------------------------------------------
337 //MULTIPR_GUI_ProgressCallbackDlg* progressDlg =
338 // new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop());
339 //multipr::gProgressCallback = progressDlg;
341 //MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg =
342 // new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop());
343 //multipr::gEmptyMeshCallback = emptyMeshDlg;
347 CAM_DataModel* MULTIPR_GUI::createDataModel()
349 return new MULTIPR_GUI_DataModel(this);
353 QString MULTIPR_GUI::engineIOR() const
355 CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(this));
356 return QString(anIOR.in());
359 bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy)
361 bool bOk = SalomeApp_Module::activateModule(theStudy);
366 action(ACTION_IMPORT_MED)->setAccel(QKeySequence(CTRL + Key_I));
369 MULTIPR_ORB::MULTIPR_Gen_ptr aGen = GetMultiprGen(this);
370 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
371 _PTR(Study) aStudy = aSAStudy->studyDS();
372 SALOMEDS::Study_ptr aStudyDS;
374 aStudyDS = _CAST(Study,aStudy)->GetStudy();
375 aGen->SetCurrentStudy(aStudyDS);
378 _PTR(SComponent) aSComp = aStudy->FindComponent(name());
380 _PTR(ChildIterator) it (aStudy->NewChildIterator(aSComp));
382 _PTR(SObject) aSObj = it->Value();
383 string anIOR = aSObj->GetIOR();
384 if (!anIOR.empty()) {
385 CORBA::Object_var anObj = getApp()->orb()->string_to_object(anIOR.c_str());
386 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
395 bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy)
400 // Unset actions accelerator keys
401 action(ACTION_IMPORT_MED)->setAccel(QKeySequence());
403 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_nil();
405 return SalomeApp_Module::deactivateModule(theStudy);
409 void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
412 theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft);
413 theMap.insert(SalomeApp_Application::WT_PyConsole, Qt::DockBottom);
417 void MULTIPR_GUI::selected(QStringList& entries, const bool multiple)
419 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
423 SUIT_DataOwnerPtrList anOwnersList;
424 mgr->selected(anOwnersList);
426 for (int i = 0 ; i < anOwnersList.size() ; i++)
428 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(anOwnersList[i].get());
430 if (!entries.contains(owner->entry()))
432 entries.append(owner->entry());
441 void MULTIPR_GUI::OnImportFromMEDFile()
445 aFilter.append(tr("MULTIPR_FLT_MED_FILES"));
446 aFilter.append(tr("MULTIPR_FLT_ALL_FILES"));
448 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
449 this->application()->desktop(),
453 fd->setCaption(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"));
454 fd->setFilters(aFilter);
455 if (fd->exec() == QDialog::Rejected)
461 QFileInfo aFileInfo(fd->selectedFile());
464 // Check the file name
465 if (!aFileInfo.exists())
468 mMEDFileName = aFileInfo.filePath();
470 QApplication::setOverrideCursor(Qt::waitCursor);
472 // Delete previous MULTIPR object.
473 //if (mMULTIPRObj != NULL)
474 if (!CORBA::is_nil(mMULTIPRObj) && !mMULTIPRObj->_non_existent())
476 mMULTIPRObj->reset();
479 MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(this);
483 mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1());
487 SUIT_MessageBox::error1(
489 "Import MED file error",
490 "Invalid MED file (not recognized by MULTIPR)",
491 tr("MULTIPR_BUT_OK") );
493 QApplication::restoreOverrideCursor();
495 //if (mMULTIPRObj != NULL)
496 if (!CORBA::is_nil(mMULTIPRObj))
498 SALOMEDS::SObject_ptr aSObject = SALOMEDS::SObject::_nil();
499 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
500 _PTR(Study) aStudyDSClient = aSAStudy->studyDS();
501 SALOMEDS::Study_ptr aStudyDS = _CAST(Study,aStudyDSClient)->GetStudy();
502 multiprgen->PublishInStudy(aStudyDS, aSObject, mMULTIPRObj, "Mesh");
506 if (mMULTIPRObj->isValidSequentialMEDFile())
515 getApp()->updateObjectBrowser();
516 getApp()->updateActions();
521 void MULTIPR_GUI::OnPartition1()
523 // check if MULTIPRObj exists
524 //if (mMULTIPRObj == NULL)
525 if (CORBA::is_nil(mMULTIPRObj))
531 MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
535 // Now we need to save the file.
536 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
537 this->application()->desktop(),
541 fd->setCaption(tr("Save distributed MED file - Destination directory"));
542 fd->setMode(QFileDialog::DirectoryOnly);
544 if (fd->exec() == QDialog::Rejected)
547 mMULTIPRObj->reset();
548 getApp()->updateObjectBrowser();
552 QFileInfo aFileInfo(fd->selectedFile());
555 QString path = aFileInfo.filePath();
557 QApplication::setOverrideCursor(Qt::waitCursor);
558 mMULTIPRObj->resetSaveProgress();
560 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
564 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
565 //mProgress->start("Save mesh", 100);
566 if (mProgress == NULL)
567 mProgress = new QProgressDialog ("Save mesh", "Cancel", /*totalSteps*/100, getApp()->desktop());
568 //mProgress->setProgress(0);
569 //mProgress->init(100);
570 //mTimer->start(500); // 0.5 seconds timer
571 //QApplication::restoreOverrideCursor();
572 //getApp()->updateObjectBrowser();
577 void MULTIPR_GUI::OnPartition2()
579 // check if MULTIPRObj exists
580 //if (mMULTIPRObj == NULL)
581 if (CORBA::is_nil(mMULTIPRObj))
586 retrieveSelectedParts();
588 if (mSelectedParts.count() == 0)
590 SUIT_MessageBox::warn1(
594 tr("MULTIPR_BUT_OK") );
598 if (!removeLowerResolution())
603 MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
606 getApp()->updateObjectBrowser();
607 getApp()->updateActions();
611 void MULTIPR_GUI::OnDecimate()
613 // check if MULTIPRObj exists
614 //if (mMULTIPRObj == NULL)
615 if (CORBA::is_nil(mMULTIPRObj))
620 retrieveSelectedParts();
622 if (mSelectedParts.count() == 0)
624 SUIT_MessageBox::warn1(
626 "Decimation warning",
628 tr("MULTIPR_BUT_OK") );
632 if (!removeLowerResolution())
637 const QStringList& partsList = this->getSelectedParts();
638 QString allParts = partsList.join("|");
639 MULTIPR_ORB::string_array* listFields = this->getMULTIPRObj()->getFields(allParts.latin1());
640 if (listFields->length() == 0)
642 SUIT_MessageBox::error1(
643 this->getAppli()->desktop(),
645 "No field for this part.",
650 MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
653 getApp()->updateObjectBrowser();
654 getApp()->updateActions();
658 void MULTIPR_GUI::OnRemove()
660 // check if MULTIPRObj exists
661 //if (mMULTIPRObj == NULL)
662 if (CORBA::is_nil(mMULTIPRObj))
667 retrieveSelectedParts();
669 if (mSelectedParts.count() == 0)
671 SUIT_MessageBox::warn1(
675 tr("MULTIPR_BUT_OK") );
679 if (QMessageBox::question(
681 tr("Remove selected part(s)"),
682 tr("Do you want to remove selected part(s)?"),
683 tr("&Yes"), tr("&No"),
684 QString::null, 0, 1 ) )
689 QApplication::setOverrideCursor(Qt::waitCursor);
693 QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
694 for (; it != last; it++)
696 const QString& partName = (*it);
697 cout << "Remove " << partName.latin1() << endl;
698 mMULTIPRObj->removeParts(partName.latin1());
703 SUIT_MessageBox::error1(
706 "Error while removing selected part(s)",
707 tr("MULTIPR_BUT_OK") );
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 =
727 new SalomeApp_CheckFileDlg(this->application()->desktop(),
731 fd->setCaption(tr("Save distributed MED file - Destination directory"));
732 fd->setMode(QFileDialog::DirectoryOnly);
734 if (fd->exec() == QDialog::Rejected)
740 QFileInfo aFileInfo(fd->selectedFile());
743 QApplication::setOverrideCursor(Qt::waitCursor);
745 QString path = aFileInfo.filePath();
746 mMULTIPRObj->resetSaveProgress();
748 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
752 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
753 //mProgress->start("Save mesh", 100);
754 if (mProgress == NULL)
755 mProgress = new QProgressDialog ("Save mesh", "Cancel", /*totalSteps*/100, getApp()->desktop());
756 //mProgress->setProgress(0);
757 //mProgress->init(100);
758 mTimer->start(500); // 0.5 seconds timer
760 //QApplication::restoreOverrideCursor();
763 void MULTIPR_GUI::timerDone()
765 int progress = mMULTIPRObj->getSaveProgress();
766 if (mProgress != NULL) {
767 mProgress->setProgress(progress);
769 if (progress >= 100) {
775 void MULTIPR_GUI::retrieveSelectedParts()
777 mSelectedParts.clear();
779 QStringList userSelection;
780 selected(userSelection, true);
781 for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
783 const QString& str = (*it);
784 QStringList words = QStringList::split(":", str);
785 if (words.count() == 2)
787 if (words[0] == "MULTIPR_PART")
789 mSelectedParts.push_back(words[1]);
796 bool MULTIPR_GUI::isPartExist(const char* partName)
798 //if (mMULTIPRObj == NULL) return false;
799 if (CORBA::is_nil(mMULTIPRObj)) return false;
801 MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
802 for (int i=0 ; i<listParts->length() ; i++)
804 const char* strItem = (*listParts)[i];
805 if (strcmp(strItem, partName) == 0)
814 bool MULTIPR_GUI::removeLowerResolution()
816 // for each selected part, check if there are lower resolution
817 // and then propose to remove them before performing new process
818 QStringList partNameLowerResolution;
819 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
822 const QString& partName = (*it);
823 QString partNameLow = partName + "_LOW";
824 QString partNameMed = partName + "_MED";
825 const char* strPartNameLow = partNameLow.latin1();
826 const char* strPartNameMed = partNameMed.latin1();
828 if (isPartExist(strPartNameLow))
830 partNameLowerResolution.push_back(partNameLow);
831 cout << "Part to be removed: " << partNameLow << endl;
834 if (isPartExist(strPartNameMed))
836 partNameLowerResolution.push_back(partNameMed);
837 cout << "Part to be removed: " << partNameMed << endl;
841 if (partNameLowerResolution.count() > 0)
843 if (QMessageBox::question(
845 tr("Remove previous results"),
846 tr("Do you want to remove previous results?"),
847 tr("&Yes"), tr("&No"),
848 QString::null, 0, 1 ) )
853 QApplication::setOverrideCursor(Qt::waitCursor);
857 for (QStringList::const_iterator it = partNameLowerResolution.begin(),
858 last = partNameLowerResolution.end(); it != last; it++)
860 const QString& partName = (*it);
861 cout << "Remove " << partName.latin1() << endl;
862 mMULTIPRObj->removeParts(partName.latin1());
868 SUIT_MessageBox::error1(
871 "Error while removing previous results",
872 tr("MULTIPR_BUT_OK") );
875 QApplication::restoreOverrideCursor();
877 getApp()->updateObjectBrowser();
878 getApp()->updateActions();
885 //*****************************************************************************
886 // Super class Data Object implementation
887 //*****************************************************************************
889 MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject (SUIT_DataObject* parent, const char* name)
890 : LightApp_DataObject(parent),
891 CAM_DataObject(parent)
897 MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject()
903 QString MULTIPR_GUI_DataObject::entry() const
905 return QString("MULTIPR_OBJECT");
909 QString MULTIPR_GUI_DataObject::name() const
915 QPixmap MULTIPR_GUI_DataObject::icon() const
917 //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
923 QString MULTIPR_GUI_DataObject::toolTip() const
925 // default behaviour: return an empty string
930 //*****************************************************************************
931 // Class Data Object Module implementation
932 //*****************************************************************************
934 MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module (CAM_DataModel* dm,
935 SUIT_DataObject* parent,
937 : MULTIPR_GUI_DataObject(parent, name),
938 LightApp_ModuleObject(dm, parent),
939 CAM_DataObject(parent)
945 MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module()
951 QString MULTIPR_GUI_DataObject_Module::entry() const
953 return QString("MULTIPR_MODULE:" + mName);
957 QString MULTIPR_GUI_DataObject_Module::name() const
959 return CAM_RootObject::name();
963 QPixmap MULTIPR_GUI_DataObject_Module::icon() const
969 QString MULTIPR_GUI_DataObject_Module::toolTip() const
971 return QString("Module MULTIPR");
975 //*****************************************************************************
976 // Class Data Object Mesh implementation
977 //*****************************************************************************
979 MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh (SUIT_DataObject* parent, const char* name)
980 : MULTIPR_GUI_DataObject(parent, name),
981 CAM_DataObject(parent)
987 MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh()
993 QString MULTIPR_GUI_DataObject_Mesh::entry() const
995 return QString("MULTIPR_MESH:") + mName;
999 QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const
1005 QString MULTIPR_GUI_DataObject_Mesh::toolTip() const
1007 return QString("Original mesh");
1011 //*****************************************************************************
1012 // Class Data Object Part implementation
1013 //*****************************************************************************
1015 MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part (SUIT_DataObject* parent,
1016 const char* name, const char* info)
1017 : MULTIPR_GUI_DataObject(parent, name),
1018 CAM_DataObject(parent)
1027 // parse info to retrieve all the fields
1028 char lMeshName[256];
1030 char lPartName[256];
1032 char lMEDFileName[256];
1034 int ret = sscanf(info, "%s %d %s %s %s",
1041 // number of read parameters should be 5
1042 if (ret != 5) return;
1044 mMeshName = lMeshName;
1047 mMEDFileName = lMEDFileName;
1051 MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part()
1057 QString MULTIPR_GUI_DataObject_Part::entry() const
1059 return QString("MULTIPR_PART:") + mName;
1063 QPixmap MULTIPR_GUI_DataObject_Part::icon() const
1069 QString MULTIPR_GUI_DataObject_Part::toolTip() const
1075 //*****************************************************************************
1076 // Class Data Object Resolution implementation
1077 //*****************************************************************************
1079 MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution (SUIT_DataObject* parent,
1080 const char* name, const char* info)
1081 : MULTIPR_GUI_DataObject_Part(parent, name, info),
1082 CAM_DataObject(parent)
1088 MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution()
1094 QString MULTIPR_GUI_DataObject_Resolution::entry() const
1096 return QString("MULTIPR_RESOLUTION:") + mName;
1100 QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const
1106 QString MULTIPR_GUI_DataObject_Resolution::toolTip() const
1112 //*****************************************************************************
1114 //*****************************************************************************
1116 MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module)
1117 //: LightApp_DataModel(module)
1118 : SalomeApp_DataModel(module)
1120 mMULTIPR_GUI = dynamic_cast<MULTIPR_GUI*>(module);
1123 MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
1129 void MULTIPR_GUI_DataModel::update (LightApp_DataObject*, LightApp_Study* theStudy)
1131 LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1133 QMap<SUIT_DataObject*,int> aMap;
1136 ch = modelRoot->children();
1137 for ( DataObjectListIterator it( ch ); it.current(); ++it )
1138 it.current()->setParent( 0 );
1143 modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1146 DataObjectList new_ch = modelRoot->children();
1147 for ( DataObjectListIterator it1( new_ch ); it1.current(); ++it1 )
1148 aMap.insert( it1.current(), 0 );
1153 for( DataObjectListIterator it( ch ); it.current(); ++it )
1154 if( !aMap.contains( it.current() ) )
1155 delete it.current();
1158 void MULTIPR_GUI_DataModel::build()
1162 void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
1166 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
1168 aSAStudy = dynamic_cast<SalomeApp_Study*>(getModule()->getApp()->activeStudy());
1170 if (!aSAStudy) return;
1172 MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
1175 // root is not set yet
1176 modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
1180 // find SObject in Study
1181 MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_nil();
1183 _PTR(SComponent) aSComp = aSAStudy->studyDS()->FindComponent(module()->name());
1186 _PTR(ChildIterator) it (aSAStudy->studyDS()->NewChildIterator(aSComp));
1189 _PTR(SObject) aSObj = it->Value();
1190 string anIOR = aSObj->GetIOR();
1193 CORBA::Object_var anObj = mMULTIPR_GUI->getApp()->orb()->string_to_object(anIOR.c_str());
1194 obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1196 // set Object to MULTIPR_GUI
1197 mMULTIPR_GUI->setMULTIPRObj(obj);
1199 //CORBA::Object_var anObj = aSObj->GetObject();
1200 //obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1201 //if (!CORBA::is_nil(obj))
1203 // // set Object to MULTIPR_GUI
1204 // mMULTIPR_GUI->setMULTIPRObj(obj);
1208 // remove Data Objects, automatically built for not loaded MULTIPR module
1209 // by SalomeApp_Application::updateObjectBrowser
1210 if (aSAStudy->root())
1212 DataObjectList ch_comp;
1213 aSAStudy->root()->children(ch_comp);
1214 DataObjectList::const_iterator anIt_comp = ch_comp.begin(), aLast_comp = ch_comp.end();
1215 for (; anIt_comp != aLast_comp; anIt_comp++)
1217 LightApp_DataObject* dobj = dynamic_cast<LightApp_DataObject*>(*anIt_comp);
1218 if (dobj && dobj->name() == aSComp->GetName().c_str())
1220 //SalomeApp_DataModelSync sync (aSAStudy->studyDS(), aSAStudy->root());
1221 //sync.deleteItemWithChildren(dobj);
1222 DataObjectList ch_obj;
1223 dobj->children(ch_obj);
1224 DataObjectList::const_iterator anIt_obj = ch_obj.begin(), aLast_obj = ch_obj.end();
1225 for (; anIt_obj != aLast_obj; anIt_obj++)
1226 // delete data object of each SObject
1229 // delete data object of SComponent itself
1238 if (!CORBA::is_nil(obj))
1241 std::string lMEDFile = obj->getFilename();
1242 std::string lMEDFileName = multipr::getFilenameWithoutPath(lMEDFile.c_str());
1243 MULTIPR_GUI_DataObject_Mesh* dataObjectMED =
1244 new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMEDFileName.c_str());
1247 MULTIPR_ORB::string_array* listParts = obj->getParts();
1249 if (listParts->length() >= 1)
1251 const char* strPartName0 = (*listParts)[0];
1252 char* strPartInfo0 = obj->getPartInfo(strPartName0);
1254 char lMeshName[256];
1256 char lPartName[256];
1258 char lMEDFileName[256];
1261 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
1270 cout << "MULTIPR: build() tree; error while parsing part info" << endl;
1271 std::runtime_error("MULTIPR: build() tree; error while parsing part info");
1275 MULTIPR_GUI_DataObject_Mesh* dataObjectMesh =
1276 new MULTIPR_GUI_DataObject_Mesh(dataObjectMED, lMeshName);
1278 // PART and RESOLUTION objects
1279 MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL;
1281 for (int i = 0 ; i < listParts->length() ; i++)
1283 const char* strItem = (*listParts)[i];
1284 char* strPartInfo = obj->getPartInfo(strItem);
1287 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
1294 if (ret != 5) return;
1296 if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
1298 new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
1302 dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
1316 CAM_Module* createModule()
1318 return new MULTIPR_GUI();