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"
23 #include <SUIT_MessageBox.h>
24 #include <SUIT_ResourceMgr.h>
25 #include <SUIT_Session.h>
26 #include <SalomeApp_Application.h>
27 #include <SalomeApp_DataModel.h>
28 #include <SalomeApp_Study.h>
29 #include <SalomeApp_CheckFileDlg.h>
30 #include <LightApp_Study.h>
31 #include <LightApp_DataModel.h>
32 #include <LightApp_DataOwner.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <CAM_DataModel.h>
35 #include <CAM_Module.h>
37 #include <SALOME_LifeCycleCORBA.hxx>
39 #include <QtxPopupMgr.h>
42 #include <qapplication.h>
43 #include <qinputdialog.h>
45 #include <qpushbutton.h>
46 #include <qgroupbox.h>
48 #include <qbuttongroup.h>
50 #include <qcombobox.h>
52 #include <qlineedit.h>
55 #include <qwhatsthis.h>
58 #include <qmessagebox.h>
64 //*****************************************************************************
66 //*****************************************************************************
70 // progress callback used by the MULTIPR library
71 extern MULTIPR_ProgressCallback* gProgressCallback;
75 //*****************************************************************************
76 // Class MULTIPR_GUI implementation
77 //*****************************************************************************
79 MULTIPR_GUI::MULTIPR_GUI() : SalomeApp_Module("MULTIPR")
86 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
92 SalomeApp_Application* MULTIPR_GUI::getAppli() const
98 MULTIPR_ORB::MULTIPR_Gen_ptr MULTIPR_GUI::InitMULTIPRGen(SalomeApp_Application* app)
100 Engines::Component_var comp = app->lcc()->FindOrLoad_Component("FactoryServer", "MULTIPR");
101 MULTIPR_ORB::MULTIPR_Gen_ptr clr = MULTIPR_ORB::MULTIPR_Gen::_narrow(comp);
102 ASSERT(!CORBA::is_nil(clr));
107 void MULTIPR_GUI::initialize(CAM_Application* app)
109 SalomeApp_Module::initialize(app);
111 InitMULTIPRGen(dynamic_cast<SalomeApp_Application*>(app));
113 QWidget* aParent = app->desktop();
114 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
116 //-------------------------------------------------------------------------
118 //-------------------------------------------------------------------------
119 QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("ICON_IMPORT_MED"));
123 tr("TLT_IMPORT_FROM_MED_FILE"),
124 QIconSet(aPixmapImportFromMEDFile),
125 tr("MEN_IMPORT_FROM_MED_FILE"),
126 tr("STS_IMPORT_FROM_MED_FILE"),
131 SLOT(OnImportFromMEDFile()));
143 SLOT(OnPartition2()));
169 QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("ICON_SAVE_MED"));
174 QIconSet(aPixmapSaveMEDFile),
183 //-------------------------------------------------------------------------
185 //-------------------------------------------------------------------------
187 aMenuId = createMenu(tr("MEN_FILE"), -1, -1);
188 createMenu(separator(), aMenuId, -1, 10);
189 aMenuId = createMenu(tr("MEN_FILE_MULTIPR"), aMenuId, -1, 10);
190 createMenu(ACTION_IMPORT_MED, aMenuId);
192 aMenuId = createMenu(tr("MEN_MULTIPR"), -1, -1, 30);
193 createMenu(ACTION_IMPORT_MED, aMenuId, 10);
194 createMenu(ACTION_SAVE, aMenuId, 10);
195 createMenu(ACTION_SPLIT, aMenuId, 10);
196 createMenu(ACTION_DECIMATE, aMenuId, 10);
197 createMenu(ACTION_REMOVE, aMenuId, 10);
199 //-------------------------------------------------------------------------
201 //-------------------------------------------------------------------------
202 int aToolId = createTool(tr("TOOL_MULTIPR"));
203 createTool(ACTION_IMPORT_MED, aToolId);
204 createTool(ACTION_SAVE, aToolId);
206 //-------------------------------------------------------------------------
207 // create popup menus
208 //-------------------------------------------------------------------------
209 QtxPopupMgr* mgr = popupMgr();
210 mgr->insert( action(ACTION_SPLIT), -1, -1, -1 );
211 mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 );
212 mgr->insert( action(ACTION_REMOVE), -1, -1, -1 );
213 mgr->insert( action(ACTION_SAVE), -1, -1, -1 );
215 QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}";
216 mgr->setRule(action(ACTION_SPLIT), aRule, true);
217 mgr->setRule(action(ACTION_DECIMATE), aRule, true);
218 mgr->setRule(action(ACTION_REMOVE), aRule, true);
219 mgr->setRule(action(ACTION_SAVE), aRule, true);
221 //-------------------------------------------------------------------------
222 // set progress dialog
223 //-------------------------------------------------------------------------
224 MULTIPR_GUI_ProgressCallbackDlg* progressDlg = new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop());
225 multipr::gProgressCallback = progressDlg;
229 CAM_DataModel* MULTIPR_GUI::createDataModel()
231 return new MULTIPR_GUI_DataModel(this);
235 QString MULTIPR_GUI::engineIOR() const
237 CORBA::String_var anIOR = getApp()->orb()->object_to_string(InitMULTIPRGen(getApp()));
238 return QString(anIOR.in());
242 bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy)
244 bool bOk = SalomeApp_Module::activateModule(theStudy);
253 bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy)
258 return SalomeApp_Module::deactivateModule(theStudy);
262 void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
265 theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft);
266 theMap.insert(SalomeApp_Application::WT_PyConsole, Qt::DockBottom);
270 void MULTIPR_GUI::selected(QStringList& entries, const bool multiple)
272 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
276 SUIT_DataOwnerPtrList anOwnersList;
277 mgr->selected(anOwnersList);
279 for (int i = 0 ; i < anOwnersList.size() ; i++)
281 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(anOwnersList[i].get());
283 if (!entries.contains(owner->entry()))
285 entries.append(owner->entry());
294 void MULTIPR_GUI::OnImportFromMEDFile()
298 aFilter.append(tr("FLT_MED_FILES"));
299 aFilter.append(tr("FLT_ALL_FILES"));
301 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
302 this->application()->desktop(),
304 tr("USE_BUILD_PROGRESS") );
306 fd->setCaption(tr("MEN_IMPORT_FROM_MED_FILE"));
307 fd->setFilters(aFilter);
309 QFileInfo aFileInfo(fd->selectedFile());
312 // Check the file name
313 if (!aFileInfo.exists())
316 mMEDFileName = aFileInfo.filePath();
318 QApplication::setOverrideCursor(Qt::waitCursor);
322 MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = MULTIPR_GUI::InitMULTIPRGen(getApp());
323 mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1());
327 SUIT_MessageBox::error1(
329 "Import MED file error",
330 "Invalid MED file (not recognized by MULTIPR)",
333 QApplication::restoreOverrideCursor();
335 if (mMULTIPRObj != NULL)
339 if (mMULTIPRObj->isValidSequentialMEDFile())
348 getApp()->updateObjectBrowser();
353 void MULTIPR_GUI::OnPartition1()
355 // check if MULTIPRObj exists
356 if (mMULTIPRObj == NULL)
361 MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
367 void MULTIPR_GUI::OnPartition2()
369 // check if MULTIPRObj exists
370 if (mMULTIPRObj == NULL)
375 retrieveSelectedParts();
377 if (mSelectedParts.count() == 0)
379 SUIT_MessageBox::warn1(
387 if (!removeLowerResolution())
392 MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
395 getApp()->updateObjectBrowser();
399 void MULTIPR_GUI::OnDecimate()
401 // check if MULTIPRObj exists
402 if (mMULTIPRObj == NULL)
407 retrieveSelectedParts();
409 if (mSelectedParts.count() == 0)
411 SUIT_MessageBox::warn1(
413 "Decimation warning",
419 if (!removeLowerResolution())
424 MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
427 getApp()->updateObjectBrowser();
431 void MULTIPR_GUI::OnRemove()
433 // check if MULTIPRObj exists
434 if (mMULTIPRObj == NULL)
439 retrieveSelectedParts();
441 if (mSelectedParts.count() == 0)
443 SUIT_MessageBox::warn1(
451 if (QMessageBox::question(
453 tr("Remove selected part(s)"),
454 tr("Do you want to remove selected part(s)?"),
455 tr("&Yes"), tr("&No"),
456 QString::null, 0, 1 ) )
461 QApplication::setOverrideCursor(Qt::waitCursor);
465 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
467 const QString& partName = (*it);
468 cout << "Remove " << partName.latin1() << endl;
469 mMULTIPRObj->removeParts(partName.latin1());
475 SUIT_MessageBox::error1(
478 "Error while removing selected part(s)",
482 QApplication::restoreOverrideCursor();
484 getApp()->updateObjectBrowser();
488 void MULTIPR_GUI::OnSave()
490 // check if MULTIPRObj exists
491 if (mMULTIPRObj == NULL)
496 QApplication::setOverrideCursor(Qt::waitCursor);
501 getApp()->updateObjectBrowser();
505 SUIT_MessageBox::error1(
507 "Save distributed MED file error",
508 "Error while writing distributed MED file",
512 QApplication::restoreOverrideCursor();
517 void MULTIPR_GUI::retrieveSelectedParts()
519 mSelectedParts.clear();
521 QStringList userSelection;
522 selected(userSelection, true);
523 for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
525 const QString& str = (*it);
526 QStringList words = QStringList::split(":", str);
527 if (words.count() == 2)
529 if (words[0] == "MULTIPR_PART")
531 mSelectedParts.push_back(words[1]);
538 bool MULTIPR_GUI::isPartExist(const char* partName)
540 if (mMULTIPRObj == NULL) return false;
542 MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
543 for (int i=0 ; i<listParts->length() ; i++)
545 const char* strItem = (*listParts)[i];
546 if (strcmp(strItem, partName) == 0)
555 bool MULTIPR_GUI::removeLowerResolution()
557 // for each selected part, check if there are lower resolution
558 // and then propose to remove them before performing new process
559 QStringList partNameLowerResolution;
560 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
562 const QString& partName = (*it);
563 QString partNameLow = partName + "_LOW";
564 QString partNameMed = partName + "_MED";
565 const char* strPartNameLow = partNameLow.latin1();
566 const char* strPartNameMed = partNameMed.latin1();
568 if (isPartExist(strPartNameLow))
570 partNameLowerResolution.push_back(partNameLow);
571 cout << "Part to be removed: " << partNameLow << endl;
574 if (isPartExist(strPartNameMed))
576 partNameLowerResolution.push_back(partNameMed);
577 cout << "Part to be removed: " << partNameMed << endl;
581 if (partNameLowerResolution.count() > 0)
583 if (QMessageBox::question(
585 tr("Remove previous results"),
586 tr("Do you want to remove previous results?"),
587 tr("&Yes"), tr("&No"),
588 QString::null, 0, 1 ) )
593 QApplication::setOverrideCursor(Qt::waitCursor);
597 for (QStringList::const_iterator it = partNameLowerResolution.begin(), last = partNameLowerResolution.end(); it != last; it++)
599 const QString& partName = (*it);
600 cout << "Remove " << partName.latin1() << endl;
601 mMULTIPRObj->removeParts(partName.latin1());
607 SUIT_MessageBox::error1(
610 "Error while removing previous results",
614 QApplication::restoreOverrideCursor();
616 getApp()->updateObjectBrowser();
623 //*****************************************************************************
624 // Super class Data Object implementation
625 //*****************************************************************************
627 MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject(SUIT_DataObject* parent, const char* name) :
628 LightApp_DataObject(parent),
629 CAM_DataObject(parent)
635 MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject()
641 QString MULTIPR_GUI_DataObject::entry() const
643 return QString("MULTIPR_OBJECT");
647 QString MULTIPR_GUI_DataObject::name() const
653 QPixmap MULTIPR_GUI_DataObject::icon() const
655 //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
661 QString MULTIPR_GUI_DataObject::toolTip() const
663 // default behaviour: return an empty string
668 //*****************************************************************************
669 // Class Data Object Module implementation
670 //*****************************************************************************
672 MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module(CAM_DataModel* dm, SUIT_DataObject* parent, const char* name) :
673 MULTIPR_GUI_DataObject(parent, name),
674 LightApp_ModuleObject(dm, parent),
675 CAM_DataObject(parent)
681 MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module()
687 QString MULTIPR_GUI_DataObject_Module::entry() const
689 return QString("MULTIPR_MODULE:" + mName);
693 QString MULTIPR_GUI_DataObject_Module::name() const
695 return CAM_RootObject::name();
699 QPixmap MULTIPR_GUI_DataObject_Module::icon() const
705 QString MULTIPR_GUI_DataObject_Module::toolTip() const
707 return QString("Module MULTIPR");
711 //*****************************************************************************
712 // Class Data Object Mesh implementation
713 //*****************************************************************************
715 MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh(SUIT_DataObject* parent, const char* name) :
716 MULTIPR_GUI_DataObject(parent, name),
717 CAM_DataObject(parent)
723 MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh()
729 QString MULTIPR_GUI_DataObject_Mesh::entry() const
731 return QString("MULTIPR_MESH:") + mName;
735 QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const
741 QString MULTIPR_GUI_DataObject_Mesh::toolTip() const
743 return QString("Original mesh");
747 //*****************************************************************************
748 // Class Data Object Part implementation
749 //*****************************************************************************
751 MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part(SUIT_DataObject* parent, const char* name, const char* info) :
752 MULTIPR_GUI_DataObject(parent, name),
753 CAM_DataObject(parent)
762 // parse info to retrieve all the fields
767 char lMEDFileName[256];
769 int ret = sscanf(info, "%s %d %s %s %s",
776 // number of read parameters should be 5
777 if (ret != 5) return;
779 mMeshName = lMeshName;
782 mMEDFileName = lMEDFileName;
786 MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part()
792 QString MULTIPR_GUI_DataObject_Part::entry() const
794 return QString("MULTIPR_PART:") + mName;
798 QPixmap MULTIPR_GUI_DataObject_Part::icon() const
804 QString MULTIPR_GUI_DataObject_Part::toolTip() const
810 //*****************************************************************************
811 // Class Data Object Resolution implementation
812 //*****************************************************************************
814 MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution(SUIT_DataObject* parent, const char* name, const char* info) :
815 MULTIPR_GUI_DataObject_Part(parent, name, info),
816 CAM_DataObject(parent)
822 MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution()
828 QString MULTIPR_GUI_DataObject_Resolution::entry() const
830 return QString("MULTIPR_RESOLUTION:") + mName;
834 QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const
840 QString MULTIPR_GUI_DataObject_Resolution::toolTip() const
846 //*****************************************************************************
848 //*****************************************************************************
850 MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module) :
851 LightApp_DataModel(module)
853 mMULTIPR_GUI = dynamic_cast<MULTIPR_GUI*>(module);
857 MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
863 void MULTIPR_GUI_DataModel::build()
867 MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
871 // root is not set yet
872 modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
876 MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj();
880 MULTIPR_ORB::string_array* listParts = obj->getParts();
882 if (listParts->length() >= 1)
884 const char* strPartName0 = (*listParts)[0];
885 char* strPartInfo0 = obj->getPartInfo(strPartName0);
891 char lMEDFileName[256];
894 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
901 if (ret != 5) return;
903 MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName);
905 MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL;
907 for (int i = 0 ; i < listParts->length() ; i++)
909 const char* strItem = (*listParts)[i];
910 char* strPartInfo = obj->getPartInfo(strItem);
913 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
920 if (ret != 5) return;
922 //cout << "Part : " << lPartName << endl;
923 if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
925 //cout << "Found MED/LOW" << endl;
926 new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
930 dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
944 CAM_Module* createModule()
946 return new MULTIPR_GUI();