1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Partitioning/decimation module for the SALOME v3.2 platform
22 * \file MULTIPR_GUI.cxx
24 * \brief see MULTIPR_GUI.h
26 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
31 //*****************************************************************************
33 //*****************************************************************************
36 #include "MULTIPR_GUI.h"
37 #include "MULTIPR_GUI_Dlg.h"
38 #include "MULTIPR_Utils.hxx"
41 #include <SalomeApp_Application.h>
42 #include <SalomeApp_DataModel.h>
43 #include <SalomeApp_Study.h>
44 #include <SalomeApp_CheckFileDlg.h>
46 #include <LightApp_Study.h>
47 #include <LightApp_DataModel.h>
48 #include <LightApp_DataOwner.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <CAM_DataModel.h>
52 #include <CAM_Module.h>
54 #include <SUIT_MessageBox.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <SUIT_Session.h>
58 #include <SALOME_LifeCycleCORBA.hxx>
59 #include <SALOMEDS_Study.hxx>
61 #include <SALOME_Event.h>
63 #include <QtxPopupMgr.h>
66 #include <QApplication>
67 #include <QInputDialog>
69 #include <QPushButton>
71 #include <QVBoxLayout>
72 #include <QButtonGroup>
82 #include <QMessageBox>
87 #include <QListIterator>
92 //*****************************************************************************
94 //*****************************************************************************
98 // // progress callback used by the MULTIPR library
99 // extern MULTIPR_ProgressCallback* gProgressCallback;
100 // extern MULTIPR_EmptyMeshCallback* gEmptyMeshCallback;
102 class MULTIPR_GUI_FinishSaveEvent: public SALOME_Event
104 SalomeApp_Application* myApp;
107 MULTIPR_GUI_FinishSaveEvent (SalomeApp_Application* theApp,
110 myIsError(theIsError)
112 virtual void Execute()
115 SUIT_MessageBox::critical((QWidget*) MULTIPR_GUI::desktop(),
116 QObject::tr("SAVE_DISTMED_ERROR"),
117 // QString("Save distributed MED file error"),
118 QObject::tr("WRIT_DISTMED_ERROR"));
119 // QString("Error while writing distributed MED file"));
122 myApp->updateObjectBrowser();
123 myApp->updateActions();
125 QApplication::restoreOverrideCursor();
129 class MULTIPR_GUI_SaveThread : public QThread
132 MULTIPR_GUI_SaveThread (MULTIPR_GUI* pModule,
133 MULTIPR_ORB::MULTIPR_Obj_ptr pObj,
137 mObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(pObj);
143 MULTIPR_GUI* mModule;
144 MULTIPR_ORB::MULTIPR_Obj_ptr mObj;
148 void MULTIPR_GUI_SaveThread::run()
152 mObj->save(mPath.toLatin1());
156 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), true));
160 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), false));
163 //*****************************************************************************
165 //*****************************************************************************
168 MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen (SalomeApp_Application* app)
170 static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL;
174 SALOME_LifeCycleCORBA aLCC (SalomeApp_Application::namingService());
175 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","MULTIPR" );
176 aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(comp);
177 if (!CORBA::is_nil(aGen))
180 SalomeApp_Study* aSAStudy =dynamic_cast<SalomeApp_Study*>(app->activeStudy());
181 _PTR(Study) aStudy = aSAStudy->studyDS();
182 SALOMEDS::Study_ptr aStudyDS;
184 aStudyDS = _CAST(Study,aStudy)->GetStudy();
185 aGen->SetCurrentStudy(aStudyDS);
189 if (CORBA::is_nil(aGen))
190 throw std::runtime_error("Can't find MULTIPR component");
196 //*****************************************************************************
197 // Class MULTIPR_GUI implementation
198 //*****************************************************************************
200 MULTIPR_GUI::MULTIPR_GUI()
201 : SalomeApp_Module("MULTIPR"),
202 LightApp_Module( "MULTIPR" ),
207 mTimer = new QTimer (this);
208 connect(mTimer, SIGNAL(timeout()), this, SLOT(timerDone()));
212 MULTIPR_GUI::~MULTIPR_GUI()
214 //if (mMULTIPRObj != NULL)
215 if (!CORBA::is_nil(mMULTIPRObj))
217 CORBA::release(mMULTIPRObj);
222 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
227 void MULTIPR_GUI::setMULTIPRObj (MULTIPR_ORB::MULTIPR_Obj_ptr theObj)
229 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(theObj);
232 SalomeApp_Application* MULTIPR_GUI::getAppli() const
238 void MULTIPR_GUI::initialize(CAM_Application* app)
240 SalomeApp_Module::initialize(app);
242 GetMultiprGen(dynamic_cast<SalomeApp_Application*>( app ));
244 QWidget* aParent = (QWidget*) application()->desktop();
245 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
247 //-------------------------------------------------------------------------
249 //-------------------------------------------------------------------------
250 QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED"));
254 tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"),
255 QIcon(aPixmapImportFromMEDFile),
256 tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"),
257 tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"),
258 (Qt::CTRL + Qt::Key_I),
262 SLOT(OnImportFromMEDFile()));
266 tr("MULTIPR_TLT_SPLIT"),
268 tr("MULTIPR_MEN_SPLIT"),
269 tr("MULTIPR_STS_SPLIT"),
274 SLOT(OnPartition2()));
278 tr("MULTIPR_TLT_DECIMATE"),
280 tr("MULTIPR_MEN_DECIMATE"),
281 tr("MULTIPR_STS_DECIMATE"),
290 tr("MULTIPR_TLT_REMOVE"),
292 tr("MULTIPR_MEN_REMOVE"),
293 tr("MULTIPR_STS_REMOVE"),
300 QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED"));
304 tr("MULTIPR_TLT_SAVE"),
305 QIcon(aPixmapSaveMEDFile),
306 tr("MULTIPR_MEN_SAVE"),
307 tr("MULTIPR_STS_SAVE"),
314 //-------------------------------------------------------------------------
316 //-------------------------------------------------------------------------
318 aMenuId = createMenu(tr("MULTIPR_MEN_FILE"), -1, -1);
319 createMenu(separator(), aMenuId, -1, 10);
320 aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10);
321 createMenu(ACTION_IMPORT_MED, aMenuId);
323 aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30);
324 createMenu(ACTION_IMPORT_MED, aMenuId, 10);
325 createMenu(ACTION_SAVE, aMenuId, 10);
326 createMenu(ACTION_SPLIT, aMenuId, 10);
327 createMenu(ACTION_DECIMATE, aMenuId, 10);
328 createMenu(ACTION_REMOVE, aMenuId, 10);
330 //-------------------------------------------------------------------------
332 //-------------------------------------------------------------------------
333 int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR"));
334 createTool(ACTION_IMPORT_MED, aToolId);
335 createTool(ACTION_SAVE, aToolId);
337 //-------------------------------------------------------------------------
338 // create popup menus
339 //-------------------------------------------------------------------------
340 QtxPopupMgr* mgr = popupMgr();
341 mgr->insert( action(ACTION_SPLIT), -1, -1, -1 );
342 mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 );
343 mgr->insert( action(ACTION_REMOVE), -1, -1, -1 );
344 mgr->insert( action(ACTION_SAVE), -1, -1, -1 );
346 QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}";
347 mgr->setRule(action(ACTION_SPLIT), aRule);
348 mgr->setRule(action(ACTION_DECIMATE), aRule);
349 mgr->setRule(action(ACTION_REMOVE), aRule);
350 mgr->setRule(action(ACTION_SAVE), aRule);
352 //-------------------------------------------------------------------------
353 // set progress dialog
354 //-------------------------------------------------------------------------
355 //MULTIPR_GUI_ProgressCallbackDlg* progressDlg =
356 // new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop());
357 //multipr::gProgressCallback = progressDlg;
359 //MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg =
360 // new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop());
361 //multipr::gEmptyMeshCallback = emptyMeshDlg;
365 CAM_DataModel* MULTIPR_GUI::createDataModel()
367 return new MULTIPR_GUI_DataModel(this);
371 QString MULTIPR_GUI::engineIOR() const
373 // SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(this);
374 CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(getApp()));
375 return QString(anIOR.in());
378 bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy)
380 bool bOk = SalomeApp_Module::activateModule(theStudy);
385 action(ACTION_IMPORT_MED)->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_I));
388 MULTIPR_ORB::MULTIPR_Gen_ptr aGen = GetMultiprGen(dynamic_cast<SalomeApp_Application*>(this));
389 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
390 _PTR(Study) aStudy = aSAStudy->studyDS();
391 SALOMEDS::Study_ptr aStudyDS;
393 aStudyDS = _CAST(Study,aStudy)->GetStudy();
394 aGen->SetCurrentStudy(aStudyDS);
397 _PTR(SComponent) aSComp = aStudy->FindComponent(name().toStdString());
399 _PTR(ChildIterator) it (aStudy->NewChildIterator(aSComp));
401 _PTR(SObject) aSObj = it->Value();
402 string anIOR = aSObj->GetIOR();
403 if (!anIOR.empty()) {
404 CORBA::Object_var anObj = getApp()->orb()->string_to_object(anIOR.c_str());
405 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
414 bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy)
419 // Unset actions accelerator keys
420 action(ACTION_IMPORT_MED)->setShortcut(QKeySequence());
422 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_nil();
424 return SalomeApp_Module::deactivateModule(theStudy);
428 void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
431 theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea);
432 theMap.insert(SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
436 void MULTIPR_GUI::selected(QStringList& entries, const bool multiple)
438 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
442 SUIT_DataOwnerPtrList anOwnersList;
443 mgr->selected(anOwnersList);
445 for (int i = 0 ; i < anOwnersList.size() ; i++)
447 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(anOwnersList[i].get());
449 if (!entries.contains(owner->entry()))
451 entries.append(owner->entry());
460 void MULTIPR_GUI::OnImportFromMEDFile()
464 aFilter.append(tr("MULTIPR_FLT_MED_FILES"));
465 aFilter.append(tr("MULTIPR_FLT_ALL_FILES"));
467 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
468 (QWidget*) MULTIPR_GUI::desktop(),
472 fd->setWindowTitle(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"));
473 fd->setFilters(aFilter);
474 if (fd->exec() == QDialog::Rejected)
480 QFileInfo aFileInfo(fd->selectedFile());
483 // Check the file name
484 if (!aFileInfo.exists())
487 mMEDFileName = aFileInfo.filePath();
489 QApplication::setOverrideCursor(Qt::WaitCursor);
491 // Delete previous MULTIPR object.
492 //if (mMULTIPRObj != NULL)
493 if (!CORBA::is_nil(mMULTIPRObj) && !mMULTIPRObj->_non_existent())
495 mMULTIPRObj->reset();
498 MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(dynamic_cast<SalomeApp_Application*>( this ));
502 mMULTIPRObj = multiprgen->getObject(mMEDFileName.toLatin1());
506 SUIT_MessageBox::critical(
507 (QWidget*) MULTIPR_GUI::desktop(),
508 QObject::tr("IMPORT_MED_ERROR"),
509 // "Import MED file error",
510 QObject::tr("INVALID_MED_FILE"));
511 // "Invalid MED file (not recognized by MULTIPR)");
513 QApplication::restoreOverrideCursor();
515 //if (mMULTIPRObj != NULL)
516 if (!CORBA::is_nil(mMULTIPRObj))
518 SALOMEDS::SObject_ptr aSObject = SALOMEDS::SObject::_nil();
519 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
520 _PTR(Study) aStudyDSClient = aSAStudy->studyDS();
521 SALOMEDS::Study_ptr aStudyDS = _CAST(Study,aStudyDSClient)->GetStudy();
522 multiprgen->PublishInStudy(aStudyDS, aSObject, mMULTIPRObj, "Mesh");
526 if (mMULTIPRObj->isValidSequentialMEDFile())
535 getApp()->updateObjectBrowser();
536 getApp()->updateActions();
541 void MULTIPR_GUI::OnPartition1()
543 // check if MULTIPRObj exists
544 //if (mMULTIPRObj == NULL)
545 if (CORBA::is_nil(mMULTIPRObj))
551 MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
555 // Now we need to save the file.
556 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
557 (QWidget*) MULTIPR_GUI::desktop(),
561 fd->setWindowTitle(tr("Save distributed MED file - Destination directory"));
562 fd->setFileMode(QFileDialog::DirectoryOnly);
564 if (fd->exec() == QDialog::Rejected)
567 mMULTIPRObj->reset();
568 getApp()->updateObjectBrowser();
572 QFileInfo aFileInfo(fd->selectedFile());
575 QString path = aFileInfo.filePath();
577 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
578 mMULTIPRObj->resetSaveProgress();
580 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
584 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
585 //mProgress->start("Save mesh", 100);
586 if (mProgress == NULL)
587 mProgress = new QProgressDialog ("Save mesh", "Cancel", 0,/*totalSteps*/100, (QWidget*) MULTIPR_GUI::desktop());
588 //mProgress->setProgress(0);
589 //mProgress->init(100);
590 //mTimer->start(500); // 0.5 seconds timer
591 //QApplication::restoreOverrideCursor();
592 //getApp()->updateObjectBrowser();
597 void MULTIPR_GUI::OnPartition2()
599 // check if MULTIPRObj exists
600 //if (mMULTIPRObj == NULL)
601 if (CORBA::is_nil(mMULTIPRObj))
606 retrieveSelectedParts();
608 if (mSelectedParts.count() == 0)
610 SUIT_MessageBox::warning(
611 (QWidget*) MULTIPR_GUI::desktop(),
612 QString("Split warning"),
613 QString("No parts selected"));
617 if (!removeLowerResolution())
622 MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
625 getApp()->updateObjectBrowser();
626 getApp()->updateActions();
630 void MULTIPR_GUI::OnDecimate()
632 // check if MULTIPRObj exists
633 //if (mMULTIPRObj == NULL)
634 if (CORBA::is_nil(mMULTIPRObj))
639 retrieveSelectedParts();
641 if (mSelectedParts.count() == 0)
643 SUIT_MessageBox::warning(
644 (QWidget*) MULTIPR_GUI::desktop(),
645 QString("Decimation warning"),
646 QString("No parts selected"));
650 if (!removeLowerResolution())
655 const QStringList& partsList = this->getSelectedParts();
656 QString allParts = partsList.join("|");
657 MULTIPR_ORB::string_array* listFields = this->getMULTIPRObj()->getFields(allParts.toLatin1());
658 if (listFields->length() == 0)
660 SUIT_MessageBox::critical(
661 (QWidget*) MULTIPR_GUI::desktop(),
662 QObject::tr("DECIM_ERROR"),
663 // "Decimation error",
664 QObject::tr("NO_FIELD_ON_PART"));
665 // "No field for this part.",);
669 MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
672 getApp()->updateObjectBrowser();
673 getApp()->updateActions();
677 void MULTIPR_GUI::OnRemove()
679 // check if MULTIPRObj exists
680 //if (mMULTIPRObj == NULL)
681 if (CORBA::is_nil(mMULTIPRObj))
686 retrieveSelectedParts();
688 if (mSelectedParts.count() == 0)
690 SUIT_MessageBox::warning(
691 (QWidget*) MULTIPR_GUI::desktop(),
692 QString("Remove warning"),
693 QString("No parts selected"));
697 if (QMessageBox::question(
698 (QWidget*) MULTIPR_GUI::desktop(),
699 QString("Remove selected part(s)"),
700 QString("Do you want to remove selected part(s)?"),
701 QString("&Yes"), QString("&No"),
702 QString::null, 0, 1 ) )
707 QApplication::setOverrideCursor(Qt::WaitCursor);
711 QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
712 for (; it != last; it++)
714 const QString& partName = (*it);
715 cout << "Remove " << (const char*)partName.toLatin1() << endl;
716 mMULTIPRObj->removeParts(partName.toLatin1());
721 SUIT_MessageBox::critical(
722 (QWidget*) MULTIPR_GUI::desktop(),
723 QString("Remove error"),
724 QString("Error while removing selected part(s)"));
727 QApplication::restoreOverrideCursor();
729 getApp()->updateObjectBrowser();
730 getApp()->updateActions();
734 void MULTIPR_GUI::OnSave()
736 // check if MULTIPRObj exists
737 //if (mMULTIPRObj == NULL)
738 if (CORBA::is_nil(mMULTIPRObj))
743 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( (QWidget*) MULTIPR_GUI::desktop(), true,tr(""));
745 fd->setWindowTitle(tr("Save distributed MED file - Destination directory"));
746 fd->setFileMode(QFileDialog::DirectoryOnly);
748 if (fd->exec() == QDialog::Rejected)
754 QFileInfo aFileInfo(fd->selectedFile());
757 QApplication::setOverrideCursor(Qt::WaitCursor);
759 QString path = aFileInfo.filePath();
760 mMULTIPRObj->resetSaveProgress();
762 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
766 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
767 //mProgress->start("Save mesh", 100);
768 if (mProgress == NULL)
769 mProgress = new QProgressDialog ("Save mesh", "Cancel", 0,/*totalSteps*/100, (QWidget*) MULTIPR_GUI::desktop());
770 //mProgress->setProgress(0);
771 //mProgress->init(100);
772 mTimer->start(500); // 0.5 seconds timer
774 //QApplication::restoreOverrideCursor();
777 void MULTIPR_GUI::timerDone()
779 int progress = mMULTIPRObj->getSaveProgress();
780 if (mProgress != NULL) {
781 mProgress->setValue(progress);
783 if (progress >= 100) {
789 void MULTIPR_GUI::retrieveSelectedParts()
791 mSelectedParts.clear();
793 QStringList userSelection;
794 selected(userSelection, true);
795 for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
797 const QString& str = (*it);
798 QStringList words = str.split(":");
799 if (words.count() == 2)
801 if (words[0] == "MULTIPR_PART")
803 mSelectedParts.push_back(words[1]);
810 bool MULTIPR_GUI::isPartExist(const char* partName)
812 //if (mMULTIPRObj == NULL) return false;
813 if (CORBA::is_nil(mMULTIPRObj)) return false;
815 MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
816 for (int i=0 ; i<listParts->length() ; i++)
818 const char* strItem = (*listParts)[i];
819 if (strcmp(strItem, partName) == 0)
828 bool MULTIPR_GUI::removeLowerResolution()
830 // for each selected part, check if there are lower resolution
831 // and then propose to remove them before performing new process
832 QStringList partNameLowerResolution;
833 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
836 const QString& partName = (*it);
837 QString partNameLow = partName + "_LOW";
838 QString partNameMed = partName + "_MED";
839 const char* strPartNameLow = partNameLow.toLatin1();
840 const char* strPartNameMed = partNameMed.toLatin1();
842 if (isPartExist(strPartNameLow))
844 partNameLowerResolution.push_back(partNameLow);
845 cout << "Part to be removed: " << strPartNameLow << endl;
848 if (isPartExist(strPartNameMed))
850 partNameLowerResolution.push_back(partNameMed);
851 cout << "Part to be removed: " << strPartNameMed << endl;
855 if (partNameLowerResolution.count() > 0)
857 if (QMessageBox::question(
858 (QWidget*) MULTIPR_GUI::desktop(),
859 QObject::tr("DEL_PREV_RESULTS"),
860 // tr("Remove previous results"),
861 QObject::tr("DEL_PREV_RESULTS_QUEST"),
862 // tr("Do you want to remove previous results?"),
863 tr("&Yes"), tr("&No"),
864 QString::null, 0, 1 ) )
869 QApplication::setOverrideCursor(Qt::WaitCursor);
873 for (QStringList::const_iterator it = partNameLowerResolution.begin(),
874 last = partNameLowerResolution.end(); it != last; it++)
876 const QString& partName = (*it);
877 cout << "Remove " << (const char*)partName.toLatin1() << endl;
878 mMULTIPRObj->removeParts(partName.toLatin1());
883 SUIT_MessageBox::critical(
884 (QWidget*) MULTIPR_GUI::desktop(),
885 QObject::tr("DEL_ERROR"),
887 QObject::tr("ERROR_DEL_PREV_RESULT"));
888 // "Error while removing previous results",
891 QApplication::restoreOverrideCursor();
893 getApp()->updateObjectBrowser();
894 getApp()->updateActions();
900 SUIT_Desktop* MULTIPR_GUI::desktop()
902 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
904 return app->desktop();
910 //*****************************************************************************
911 // Super class Data Object implementation
912 //*****************************************************************************
914 MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject (SUIT_DataObject* parent, const char* name)
915 : LightApp_DataObject(parent),
916 CAM_DataObject(parent)
922 MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject()
928 QString MULTIPR_GUI_DataObject::entry() const
930 return QString("MULTIPR_OBJECT");
934 QString MULTIPR_GUI_DataObject::name() const
940 QPixmap MULTIPR_GUI_DataObject::icon() const
942 //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
948 QString MULTIPR_GUI_DataObject::toolTip() const
950 // default behaviour: return an empty string
955 //*****************************************************************************
956 // Class Data Object Module implementation
957 //*****************************************************************************
960 MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module (CAM_DataModel* dm,
961 SUIT_DataObject* parent,
963 : MULTIPR_GUI_DataObject(parent, name),
964 // LightApp_DataObject(dm, parent),
965 CAM_DataObject(parent)
973 MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module()
979 QString MULTIPR_GUI_DataObject_Module::entry() const
981 return QString("MULTIPR_MODULE:" + mName);
985 QString MULTIPR_GUI_DataObject_Module::name() const
987 CAM_ModuleObject cam(mDm,mParent);
992 QPixmap MULTIPR_GUI_DataObject_Module::icon() const
998 QString MULTIPR_GUI_DataObject_Module::toolTip() const
1000 return QString("Module MULTIPR");
1004 //*****************************************************************************
1005 // Class Data Object Mesh implementation
1006 //*****************************************************************************
1008 MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh (SUIT_DataObject* parent, const char* name)
1009 : MULTIPR_GUI_DataObject(parent, name),
1010 CAM_DataObject(parent)
1016 MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh()
1022 QString MULTIPR_GUI_DataObject_Mesh::entry() const
1024 return QString("MULTIPR_MESH:") + mName;
1028 QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const
1034 QString MULTIPR_GUI_DataObject_Mesh::toolTip() const
1036 return QString("Original mesh");
1040 //*****************************************************************************
1041 // Class Data Object Part implementation
1042 //*****************************************************************************
1044 MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part (SUIT_DataObject* parent,
1045 const char* name, const char* info)
1046 : MULTIPR_GUI_DataObject(parent, name),
1047 CAM_DataObject(parent)
1056 // parse info to retrieve all the fields
1057 char lMeshName[256];
1059 char lPartName[256];
1061 char lMEDFileName[256];
1063 int ret = sscanf(info, "%s %d %s %s %s",
1070 // number of read parameters should be 5
1071 if (ret != 5) return;
1073 mMeshName = lMeshName;
1076 mMEDFileName = lMEDFileName;
1080 MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part()
1086 QString MULTIPR_GUI_DataObject_Part::entry() const
1088 return QString("MULTIPR_PART:") + mName;
1092 QPixmap MULTIPR_GUI_DataObject_Part::icon() const
1098 QString MULTIPR_GUI_DataObject_Part::toolTip() const
1104 //*****************************************************************************
1105 // Class Data Object Resolution implementation
1106 //*****************************************************************************
1108 MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution (SUIT_DataObject* parent,
1109 const char* name, const char* info)
1110 : MULTIPR_GUI_DataObject_Part(parent, name, info),
1111 CAM_DataObject(parent)
1117 MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution()
1123 QString MULTIPR_GUI_DataObject_Resolution::entry() const
1125 return QString("MULTIPR_RESOLUTION:") + mName;
1129 QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const
1135 QString MULTIPR_GUI_DataObject_Resolution::toolTip() const
1141 //*****************************************************************************
1143 //*****************************************************************************
1145 MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module)
1146 // : LightApp_DataModel(module)
1147 : SalomeApp_DataModel(module)
1149 mMULTIPR_GUI = dynamic_cast<MULTIPR_GUI*>(module);
1152 MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
1157 void MULTIPR_GUI_DataModel::update (LightApp_DataObject*, LightApp_Study* theStudy)
1159 LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1161 //QListIterator<SUIT_DataObject> it1,it2;
1162 QMap<SUIT_DataObject*,int> aMap;
1165 ch = modelRoot->children();
1166 DataObjectList::const_iterator it = ch.begin(), it_last = ch.end();
1167 for (; it != it_last; it++)
1168 (*it)->setParent( 0);
1173 modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1176 DataObjectList new_ch = modelRoot->children();
1177 DataObjectList::const_iterator it1 = new_ch.begin(), it1_last = new_ch.end();
1178 for (; it1 != it1_last; it1++)
1179 aMap.insert((*it1),0);
1183 DataObjectList::const_iterator it_del = ch.begin(), it_del_last = ch.end();
1184 for (; it_del != it_del_last; it_del++)
1185 if( !aMap.contains( (*it_del) ) )
1189 void MULTIPR_GUI_DataModel::build()
1193 void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
1197 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
1199 aSAStudy = dynamic_cast<SalomeApp_Study*>(getModule()->getApp()->activeStudy());
1201 if (!aSAStudy) return;
1203 MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
1206 // root is not set yet
1207 modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
1211 // find SObject in Study
1212 MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_nil();
1214 _PTR(SComponent) aSComp = aSAStudy->studyDS()->FindComponent(module()->name().toStdString());
1217 _PTR(ChildIterator) it (aSAStudy->studyDS()->NewChildIterator(aSComp));
1220 _PTR(SObject) aSObj = it->Value();
1221 string anIOR = aSObj->GetIOR();
1224 CORBA::Object_var anObj = mMULTIPR_GUI->getApp()->orb()->string_to_object(anIOR.c_str());
1225 obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1227 // set Object to MULTIPR_GUI
1228 mMULTIPR_GUI->setMULTIPRObj(obj);
1230 //CORBA::Object_var anObj = aSObj->GetObject();
1231 //obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1232 //if (!CORBA::is_nil(obj))
1234 // // set Object to MULTIPR_GUI
1235 // mMULTIPR_GUI->setMULTIPRObj(obj);
1239 // remove Data Objects, automatically built for not loaded MULTIPR module
1240 // by SalomeApp_Application::updateObjectBrowser
1241 if (aSAStudy->root())
1243 DataObjectList ch_comp;
1244 aSAStudy->root()->children(ch_comp);
1245 DataObjectList::const_iterator anIt_comp = ch_comp.begin(), aLast_comp = ch_comp.end();
1246 for (; anIt_comp != aLast_comp; anIt_comp++)
1248 LightApp_DataObject* dobj = dynamic_cast<LightApp_DataObject*>(*anIt_comp);
1249 if (dobj && dobj->name() == aSComp->GetName().c_str())
1251 //SalomeApp_DataModelSync sync (aSAStudy->studyDS(), aSAStudy->root());
1252 //sync.deleteItemWithChildren(dobj);
1253 DataObjectList ch_obj;
1254 dobj->children(ch_obj);
1255 DataObjectList::const_iterator anIt_obj = ch_obj.begin(), aLast_obj = ch_obj.end();
1256 for (; anIt_obj != aLast_obj; anIt_obj++)
1257 // delete data object of each SObject
1260 // delete data object of SComponent itself
1269 if (!CORBA::is_nil(obj))
1272 std::string lMEDFile = obj->getFilename();
1273 std::string lMEDFileName = multipr::getFilenameWithoutPath(lMEDFile.c_str());
1274 MULTIPR_GUI_DataObject_Mesh* dataObjectMED =
1275 new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMEDFileName.c_str());
1278 MULTIPR_ORB::string_array* listParts = obj->getParts();
1280 if (listParts->length() >= 1)
1282 const char* strPartName0 = (*listParts)[0];
1283 char* strPartInfo0 = obj->getPartInfo(strPartName0);
1285 char lMeshName[256];
1287 char lPartName[256];
1289 char lMEDFileName[256];
1292 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
1301 cout << "MULTIPR: build() tree; error while parsing part info" << endl;
1302 std::runtime_error("MULTIPR: build() tree; error while parsing part info");
1306 MULTIPR_GUI_DataObject_Mesh* dataObjectMesh =
1307 new MULTIPR_GUI_DataObject_Mesh(dataObjectMED, lMeshName);
1309 // PART and RESOLUTION objects
1310 MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL;
1312 for (int i = 0 ; i < listParts->length() ; i++)
1314 const char* strItem = (*listParts)[i];
1315 char* strPartInfo = obj->getPartInfo(strItem);
1318 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
1325 if (ret != 5) return;
1327 if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
1329 new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
1333 dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
1347 CAM_Module* createModule()
1349 return new MULTIPR_GUI();