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") );
305 fd->setCaption(tr("MEN_IMPORT_FROM_MED_FILE"));
306 fd->setFilters(aFilter);
308 QFileInfo aFileInfo(fd->selectedFile());
311 // Check the file name
312 if (!aFileInfo.exists())
315 mMEDFileName = aFileInfo.filePath();
317 QApplication::setOverrideCursor(Qt::waitCursor);
321 MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = MULTIPR_GUI::InitMULTIPRGen(getApp());
322 mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1());
326 SUIT_MessageBox::error1(
328 "Import MED file error",
329 "Invalid MED file (not recognized by MULTIPR)",
332 QApplication::restoreOverrideCursor();
336 if (mMULTIPRObj->isValidSequentialMEDFile())
345 getApp()->updateObjectBrowser();
349 void MULTIPR_GUI::OnPartition1()
351 MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
357 void MULTIPR_GUI::OnPartition2()
359 retrieveSelectedParts();
361 if (mSelectedParts.count() == 0)
363 SUIT_MessageBox::warn1(
371 MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
374 getApp()->updateObjectBrowser();
378 void MULTIPR_GUI::OnDecimate()
380 retrieveSelectedParts();
382 if (mSelectedParts.count() == 0)
384 SUIT_MessageBox::warn1(
386 "Decimation warning",
392 // for each selected part, check if there are lower resolution
393 // and then propose to remove them before processing new decimation
394 QStringList partNameLowerResolution;
395 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
397 const QString& partName = (*it);
398 QString partNameLow = partName + "_LOW";
399 QString partNameMed = partName + "_MED";
400 const char* strPartNameLow = partNameLow.latin1();
401 const char* strPartNameMed = partNameMed.latin1();
403 if (isPartExist(strPartNameLow))
405 partNameLowerResolution.push_back(partNameLow);
406 cout << "Part to be removed: " << partNameLow << endl;
409 if (isPartExist(strPartNameMed))
411 partNameLowerResolution.push_back(partNameMed);
412 cout << "Part to be removed: " << partNameMed << endl;
416 if (partNameLowerResolution.count() > 0)
418 if (QMessageBox::question(
420 tr("Decimation: remove previous results"),
421 tr("Do you want to remove previous results?"),
422 tr("&Yes"), tr("&No"),
423 QString::null, 0, 1 ) )
428 QApplication::setOverrideCursor(Qt::waitCursor);
432 for (QStringList::const_iterator it = partNameLowerResolution.begin(), last = partNameLowerResolution.end(); it != last; it++)
434 const QString& partName = (*it);
435 cout << "Remove " << partName.latin1() << endl;
436 mMULTIPRObj->removePart(partName.latin1());
442 SUIT_MessageBox::error1(
445 "Error while removing previous results",
449 QApplication::restoreOverrideCursor();
451 getApp()->updateObjectBrowser();
454 MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
457 getApp()->updateObjectBrowser();
461 void MULTIPR_GUI::OnRemove()
463 retrieveSelectedParts();
465 if (mSelectedParts.count() == 0)
467 SUIT_MessageBox::warn1(
475 if (QMessageBox::question(
477 tr("Remove selected part(s)"),
478 tr("Do you want to remove selected part(s)?"),
479 tr("&Yes"), tr("&No"),
480 QString::null, 0, 1 ) )
485 QApplication::setOverrideCursor(Qt::waitCursor);
489 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
491 const QString& partName = (*it);
492 cout << "Remove " << partName.latin1() << endl;
493 mMULTIPRObj->removePart(partName.latin1());
499 SUIT_MessageBox::error1(
502 "Error while removing selected part(s)",
506 QApplication::restoreOverrideCursor();
508 getApp()->updateObjectBrowser();
512 void MULTIPR_GUI::OnSave()
514 QApplication::setOverrideCursor(Qt::waitCursor);
519 getApp()->updateObjectBrowser();
523 SUIT_MessageBox::error1(
525 "Save distributed MED file error",
526 "Error while writing distributed MED file",
530 QApplication::restoreOverrideCursor();
535 void MULTIPR_GUI::retrieveSelectedParts()
537 mSelectedParts.clear();
539 QStringList userSelection;
540 selected(userSelection, true);
541 for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
543 const QString& str = (*it);
544 QStringList words = QStringList::split(":", str);
545 if (words.count() == 2)
547 if (words[0] == "MULTIPR_PART")
549 mSelectedParts.push_back(words[1]);
556 bool MULTIPR_GUI::isPartExist(const char* partName)
558 if (mMULTIPRObj == NULL) return false;
560 MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
561 for (int i=0 ; i<listParts->length() ; i++)
563 const char* strItem = (*listParts)[i];
564 if (strcmp(strItem, partName) == 0)
573 //*****************************************************************************
574 // Super class Data Object implementation
575 //*****************************************************************************
577 MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject(SUIT_DataObject* parent, const char* name) :
578 LightApp_DataObject(parent),
579 CAM_DataObject(parent)
585 MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject()
591 QString MULTIPR_GUI_DataObject::entry() const
593 return QString("MULTIPR_OBJECT");
597 QString MULTIPR_GUI_DataObject::name() const
603 QPixmap MULTIPR_GUI_DataObject::icon() const
605 //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
611 QString MULTIPR_GUI_DataObject::toolTip() const
613 // default behaviour: return an empty string
618 //*****************************************************************************
619 // Class Data Object Module implementation
620 //*****************************************************************************
622 MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module(CAM_DataModel* dm, SUIT_DataObject* parent, const char* name) :
623 MULTIPR_GUI_DataObject(parent, name),
624 LightApp_ModuleObject(dm, parent),
625 CAM_DataObject(parent)
631 MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module()
637 QString MULTIPR_GUI_DataObject_Module::entry() const
639 return QString("MULTIPR_MODULE:" + mName);
643 QString MULTIPR_GUI_DataObject_Module::name() const
645 return CAM_RootObject::name();
649 QPixmap MULTIPR_GUI_DataObject_Module::icon() const
655 QString MULTIPR_GUI_DataObject_Module::toolTip() const
657 return QString("Module MULTIPR");
661 //*****************************************************************************
662 // Class Data Object Mesh implementation
663 //*****************************************************************************
665 MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh(SUIT_DataObject* parent, const char* name) :
666 MULTIPR_GUI_DataObject(parent, name),
667 CAM_DataObject(parent)
673 MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh()
679 QString MULTIPR_GUI_DataObject_Mesh::entry() const
681 return QString("MULTIPR_MESH:") + mName;
685 QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const
691 QString MULTIPR_GUI_DataObject_Mesh::toolTip() const
693 return QString("Original mesh");
697 //*****************************************************************************
698 // Class Data Object Part implementation
699 //*****************************************************************************
701 MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part(SUIT_DataObject* parent, const char* name, const char* info) :
702 MULTIPR_GUI_DataObject(parent, name),
703 CAM_DataObject(parent)
712 // parse info to retrieve all the fields
717 char lMEDFileName[256];
719 int ret = sscanf(info, "%s %d %s %s %s",
726 // number of read parameters should be 5
727 if (ret != 5) return;
729 mMeshName = lMeshName;
732 mMEDFileName = lMEDFileName;
736 MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part()
742 QString MULTIPR_GUI_DataObject_Part::entry() const
744 return QString("MULTIPR_PART:") + mName;
748 QPixmap MULTIPR_GUI_DataObject_Part::icon() const
754 QString MULTIPR_GUI_DataObject_Part::toolTip() const
760 //*****************************************************************************
761 // Class Data Object Resolution implementation
762 //*****************************************************************************
764 MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution(SUIT_DataObject* parent, const char* name, const char* info) :
765 MULTIPR_GUI_DataObject_Part(parent, name, info),
766 CAM_DataObject(parent)
772 MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution()
778 QString MULTIPR_GUI_DataObject_Resolution::entry() const
780 return QString("MULTIPR_RESOLUTION:") + mName;
784 QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const
790 QString MULTIPR_GUI_DataObject_Resolution::toolTip() const
796 //*****************************************************************************
798 //*****************************************************************************
800 MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module) :
801 LightApp_DataModel(module)
803 mMULTIPR_GUI = dynamic_cast<MULTIPR_GUI*>(module);
807 MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
813 void MULTIPR_GUI_DataModel::build()
815 MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
819 // root is not set yet
820 modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
824 MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj();
828 MULTIPR_ORB::string_array* listParts = obj->getParts();
830 if (listParts->length() >= 1)
832 const char* strPartName0 = (*listParts)[0];
833 char* strPartInfo0 = obj->getPartInfo(strPartName0);
839 char lMEDFileName[256];
842 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
849 if (ret != 5) return;
851 MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName);
853 MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL;
855 for (int i = 0 ; i < listParts->length() ; i++)
857 const char* strItem = (*listParts)[i];
858 char* strPartInfo = obj->getPartInfo(strItem);
861 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
868 if (ret != 5) return;
870 //cout << "Part : " << lPartName << endl;
871 if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
873 //cout << "Found MED/LOW" << endl;
874 new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
878 dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
888 CAM_Module* createModule()
890 return new MULTIPR_GUI();