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
20 // Partitioning/decimation module for the SALOME v3.2 platform
23 * \file MULTIPR_GUI.cxx
25 * \brief see MULTIPR_GUI.h
27 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
32 //*****************************************************************************
34 //*****************************************************************************
37 #include "MULTIPR_GUI.h"
38 #include "MULTIPR_GUI_Dlg.h"
39 #include "MULTIPR_Utils.hxx"
42 #include <SalomeApp_Application.h>
43 #include <SalomeApp_DataModel.h>
44 #include <SalomeApp_Study.h>
45 #include <SalomeApp_CheckFileDlg.h>
47 #include <LightApp_Study.h>
48 #include <LightApp_DataModel.h>
49 #include <LightApp_DataOwner.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <CAM_DataModel.h>
53 #include <CAM_Module.h>
55 #include <SUIT_MessageBox.h>
56 #include <SUIT_ResourceMgr.h>
57 #include <SUIT_Session.h>
59 #include <SALOME_LifeCycleCORBA.hxx>
60 #include <SALOMEDS_Study.hxx>
62 #include <SALOME_Event.h>
64 #include <QtxPopupMgr.h>
67 #include <QApplication>
68 #include <QInputDialog>
70 #include <QPushButton>
72 #include <QVBoxLayout>
73 #include <QButtonGroup>
83 #include <QMessageBox>
88 #include <QListIterator>
93 //*****************************************************************************
95 //*****************************************************************************
99 // // progress callback used by the MULTIPR library
100 // extern MULTIPR_ProgressCallback* gProgressCallback;
101 // extern MULTIPR_EmptyMeshCallback* gEmptyMeshCallback;
103 class MULTIPR_GUI_FinishSaveEvent: public SALOME_Event
105 SalomeApp_Application* myApp;
108 MULTIPR_GUI_FinishSaveEvent (SalomeApp_Application* theApp,
111 myIsError(theIsError)
113 virtual void Execute()
116 SUIT_MessageBox::critical((QWidget*) MULTIPR_GUI::desktop(),
117 QObject::tr("SAVE_DISTMED_ERROR"),
118 // QString("Save distributed MED file error"),
119 QObject::tr("WRIT_DISTMED_ERROR"));
120 // QString("Error while writing distributed MED file"));
123 myApp->updateObjectBrowser();
124 myApp->updateActions();
126 QApplication::restoreOverrideCursor();
130 class MULTIPR_GUI_SaveThread : public QThread
133 MULTIPR_GUI_SaveThread (MULTIPR_GUI* pModule,
134 MULTIPR_ORB::MULTIPR_Obj_ptr pObj,
138 mObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(pObj);
144 MULTIPR_GUI* mModule;
145 MULTIPR_ORB::MULTIPR_Obj_ptr mObj;
149 void MULTIPR_GUI_SaveThread::run()
153 mObj->save(mPath.toLatin1());
157 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), true));
161 ProcessVoidEvent(new MULTIPR_GUI_FinishSaveEvent(mModule->getApp(), false));
164 //*****************************************************************************
166 //*****************************************************************************
169 MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen (SalomeApp_Application* app)
171 static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL;
175 SALOME_LifeCycleCORBA aLCC (SalomeApp_Application::namingService());
176 Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","MULTIPR" );
177 aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(comp);
178 if (!CORBA::is_nil(aGen))
181 SalomeApp_Study* aSAStudy =dynamic_cast<SalomeApp_Study*>(app->activeStudy());
182 _PTR(Study) aStudy = aSAStudy->studyDS();
183 SALOMEDS::Study_ptr aStudyDS;
185 aStudyDS = _CAST(Study,aStudy)->GetStudy();
186 aGen->SetCurrentStudy(aStudyDS);
190 if (CORBA::is_nil(aGen))
191 throw std::runtime_error("Can't find MULTIPR component");
197 //*****************************************************************************
198 // Class MULTIPR_GUI implementation
199 //*****************************************************************************
201 MULTIPR_GUI::MULTIPR_GUI()
202 : SalomeApp_Module("MULTIPR"),
203 LightApp_Module( "MULTIPR" ),
208 mTimer = new QTimer (this);
209 connect(mTimer, SIGNAL(timeout()), this, SLOT(timerDone()));
213 MULTIPR_GUI::~MULTIPR_GUI()
215 //if (mMULTIPRObj != NULL)
216 if (!CORBA::is_nil(mMULTIPRObj))
218 CORBA::release(mMULTIPRObj);
223 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
228 void MULTIPR_GUI::setMULTIPRObj (MULTIPR_ORB::MULTIPR_Obj_ptr theObj)
230 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(theObj);
233 SalomeApp_Application* MULTIPR_GUI::getAppli() const
239 void MULTIPR_GUI::initialize(CAM_Application* app)
241 SalomeApp_Module::initialize(app);
243 GetMultiprGen(dynamic_cast<SalomeApp_Application*>( app ));
245 QWidget* aParent = (QWidget*) application()->desktop();
246 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
248 //-------------------------------------------------------------------------
250 //-------------------------------------------------------------------------
251 QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED"));
255 tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"),
256 QIcon(aPixmapImportFromMEDFile),
257 tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"),
258 tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"),
259 (Qt::CTRL + Qt::Key_I),
263 SLOT(OnImportFromMEDFile()));
267 tr("MULTIPR_TLT_SPLIT"),
269 tr("MULTIPR_MEN_SPLIT"),
270 tr("MULTIPR_STS_SPLIT"),
275 SLOT(OnPartition2()));
279 tr("MULTIPR_TLT_DECIMATE"),
281 tr("MULTIPR_MEN_DECIMATE"),
282 tr("MULTIPR_STS_DECIMATE"),
291 tr("MULTIPR_TLT_REMOVE"),
293 tr("MULTIPR_MEN_REMOVE"),
294 tr("MULTIPR_STS_REMOVE"),
301 QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED"));
305 tr("MULTIPR_TLT_SAVE"),
306 QIcon(aPixmapSaveMEDFile),
307 tr("MULTIPR_MEN_SAVE"),
308 tr("MULTIPR_STS_SAVE"),
315 //-------------------------------------------------------------------------
317 //-------------------------------------------------------------------------
319 aMenuId = createMenu(tr("MULTIPR_MEN_FILE"), -1, -1);
320 createMenu(separator(), aMenuId, -1, 10);
321 aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10);
322 createMenu(ACTION_IMPORT_MED, aMenuId);
324 aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30);
325 createMenu(ACTION_IMPORT_MED, aMenuId, 10);
326 createMenu(ACTION_SAVE, aMenuId, 10);
327 createMenu(ACTION_SPLIT, aMenuId, 10);
328 createMenu(ACTION_DECIMATE, aMenuId, 10);
329 createMenu(ACTION_REMOVE, aMenuId, 10);
331 //-------------------------------------------------------------------------
333 //-------------------------------------------------------------------------
334 int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR"));
335 createTool(ACTION_IMPORT_MED, aToolId);
336 createTool(ACTION_SAVE, aToolId);
338 //-------------------------------------------------------------------------
339 // create popup menus
340 //-------------------------------------------------------------------------
341 QtxPopupMgr* mgr = popupMgr();
342 mgr->insert( action(ACTION_SPLIT), -1, -1, -1 );
343 mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 );
344 mgr->insert( action(ACTION_REMOVE), -1, -1, -1 );
345 mgr->insert( action(ACTION_SAVE), -1, -1, -1 );
347 QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}";
348 mgr->setRule(action(ACTION_SPLIT), aRule);
349 mgr->setRule(action(ACTION_DECIMATE), aRule);
350 mgr->setRule(action(ACTION_REMOVE), aRule);
351 mgr->setRule(action(ACTION_SAVE), aRule);
353 //-------------------------------------------------------------------------
354 // set progress dialog
355 //-------------------------------------------------------------------------
356 //MULTIPR_GUI_ProgressCallbackDlg* progressDlg =
357 // new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop());
358 //multipr::gProgressCallback = progressDlg;
360 //MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg =
361 // new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop());
362 //multipr::gEmptyMeshCallback = emptyMeshDlg;
366 CAM_DataModel* MULTIPR_GUI::createDataModel()
368 return new MULTIPR_GUI_DataModel(this);
372 QString MULTIPR_GUI::engineIOR() const
374 // SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(this);
375 CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(getApp()));
376 return QString(anIOR.in());
379 bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy)
381 bool bOk = SalomeApp_Module::activateModule(theStudy);
386 action(ACTION_IMPORT_MED)->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_I));
389 MULTIPR_ORB::MULTIPR_Gen_ptr aGen = GetMultiprGen(dynamic_cast<SalomeApp_Application*>(this));
390 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
391 _PTR(Study) aStudy = aSAStudy->studyDS();
392 SALOMEDS::Study_ptr aStudyDS;
394 aStudyDS = _CAST(Study,aStudy)->GetStudy();
395 aGen->SetCurrentStudy(aStudyDS);
398 _PTR(SComponent) aSComp = aStudy->FindComponent(name().toStdString());
400 _PTR(ChildIterator) it (aStudy->NewChildIterator(aSComp));
402 _PTR(SObject) aSObj = it->Value();
403 string anIOR = aSObj->GetIOR();
404 if (!anIOR.empty()) {
405 CORBA::Object_var anObj = getApp()->orb()->string_to_object(anIOR.c_str());
406 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
415 bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy)
420 // Unset actions accelerator keys
421 action(ACTION_IMPORT_MED)->setShortcut(QKeySequence());
423 mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_nil();
425 return SalomeApp_Module::deactivateModule(theStudy);
429 void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
432 theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea);
433 theMap.insert(SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
437 void MULTIPR_GUI::selected(QStringList& entries, const bool multiple)
439 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
443 SUIT_DataOwnerPtrList anOwnersList;
444 mgr->selected(anOwnersList);
446 for (int i = 0 ; i < anOwnersList.size() ; i++)
448 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(anOwnersList[i].get());
450 if (!entries.contains(owner->entry()))
452 entries.append(owner->entry());
461 void MULTIPR_GUI::OnImportFromMEDFile()
465 aFilter.append(tr("MULTIPR_FLT_MED_FILES"));
466 aFilter.append(tr("MULTIPR_FLT_ALL_FILES"));
468 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
469 (QWidget*) MULTIPR_GUI::desktop(),
473 fd->setWindowTitle(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"));
474 fd->setFilters(aFilter);
475 if (fd->exec() == QDialog::Rejected)
481 QFileInfo aFileInfo(fd->selectedFile());
484 // Check the file name
485 if (!aFileInfo.exists())
488 mMEDFileName = aFileInfo.filePath();
490 QApplication::setOverrideCursor(Qt::WaitCursor);
492 // Delete previous MULTIPR object.
493 //if (mMULTIPRObj != NULL)
494 if (!CORBA::is_nil(mMULTIPRObj) && !mMULTIPRObj->_non_existent())
496 mMULTIPRObj->reset();
499 MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(dynamic_cast<SalomeApp_Application*>( this ));
503 mMULTIPRObj = multiprgen->getObject(mMEDFileName.toLatin1());
507 SUIT_MessageBox::critical(
508 (QWidget*) MULTIPR_GUI::desktop(),
509 QObject::tr("IMPORT_MED_ERROR"),
510 // "Import MED file error",
511 QObject::tr("INVALID_MED_FILE"));
512 // "Invalid MED file (not recognized by MULTIPR)");
514 QApplication::restoreOverrideCursor();
516 //if (mMULTIPRObj != NULL)
517 if (!CORBA::is_nil(mMULTIPRObj))
519 SALOMEDS::SObject_ptr aSObject = SALOMEDS::SObject::_nil();
520 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
521 _PTR(Study) aStudyDSClient = aSAStudy->studyDS();
522 SALOMEDS::Study_ptr aStudyDS = _CAST(Study,aStudyDSClient)->GetStudy();
523 multiprgen->PublishInStudy(aStudyDS, aSObject, mMULTIPRObj, "Mesh");
527 if (mMULTIPRObj->isValidSequentialMEDFile())
536 getApp()->updateObjectBrowser();
537 getApp()->updateActions();
542 void MULTIPR_GUI::OnPartition1()
544 // check if MULTIPRObj exists
545 //if (mMULTIPRObj == NULL)
546 if (CORBA::is_nil(mMULTIPRObj))
552 MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
556 // Now we need to save the file.
557 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
558 (QWidget*) MULTIPR_GUI::desktop(),
562 fd->setWindowTitle(tr("Save distributed MED file - Destination directory"));
563 fd->setFileMode(QFileDialog::DirectoryOnly);
565 if (fd->exec() == QDialog::Rejected)
568 mMULTIPRObj->reset();
569 getApp()->updateObjectBrowser();
573 QFileInfo aFileInfo(fd->selectedFile());
576 QString path = aFileInfo.filePath();
578 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
579 mMULTIPRObj->resetSaveProgress();
581 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
585 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
586 //mProgress->start("Save mesh", 100);
587 if (mProgress == NULL)
588 mProgress = new QProgressDialog ("Save mesh", "Cancel", 0,/*totalSteps*/100, (QWidget*) MULTIPR_GUI::desktop());
589 //mProgress->setProgress(0);
590 //mProgress->init(100);
591 //mTimer->start(500); // 0.5 seconds timer
592 //QApplication::restoreOverrideCursor();
593 //getApp()->updateObjectBrowser();
598 void MULTIPR_GUI::OnPartition2()
600 // check if MULTIPRObj exists
601 //if (mMULTIPRObj == NULL)
602 if (CORBA::is_nil(mMULTIPRObj))
607 retrieveSelectedParts();
609 if (mSelectedParts.count() == 0)
611 SUIT_MessageBox::warning(
612 (QWidget*) MULTIPR_GUI::desktop(),
613 QString("Split warning"),
614 QString("No parts selected"));
618 if (!removeLowerResolution())
623 MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
626 getApp()->updateObjectBrowser();
627 getApp()->updateActions();
631 void MULTIPR_GUI::OnDecimate()
633 // check if MULTIPRObj exists
634 //if (mMULTIPRObj == NULL)
635 if (CORBA::is_nil(mMULTIPRObj))
640 retrieveSelectedParts();
642 if (mSelectedParts.count() == 0)
644 SUIT_MessageBox::warning(
645 (QWidget*) MULTIPR_GUI::desktop(),
646 QString("Decimation warning"),
647 QString("No parts selected"));
651 if (!removeLowerResolution())
656 const QStringList& partsList = this->getSelectedParts();
657 QString allParts = partsList.join("|");
658 MULTIPR_ORB::string_array* listFields = this->getMULTIPRObj()->getFields(allParts.toLatin1());
659 if (listFields->length() == 0)
661 SUIT_MessageBox::critical(
662 (QWidget*) MULTIPR_GUI::desktop(),
663 QObject::tr("DECIM_ERROR"),
664 // "Decimation error",
665 QObject::tr("NO_FIELD_ON_PART"));
666 // "No field for this part.",);
670 MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
673 getApp()->updateObjectBrowser();
674 getApp()->updateActions();
678 void MULTIPR_GUI::OnRemove()
680 // check if MULTIPRObj exists
681 //if (mMULTIPRObj == NULL)
682 if (CORBA::is_nil(mMULTIPRObj))
687 retrieveSelectedParts();
689 if (mSelectedParts.count() == 0)
691 SUIT_MessageBox::warning(
692 (QWidget*) MULTIPR_GUI::desktop(),
693 QString("Remove warning"),
694 QString("No parts selected"));
698 if (QMessageBox::question(
699 (QWidget*) MULTIPR_GUI::desktop(),
700 QString("Remove selected part(s)"),
701 QString("Do you want to remove selected part(s)?"),
702 QString("&Yes"), QString("&No"),
703 QString::null, 0, 1 ) )
708 QApplication::setOverrideCursor(Qt::WaitCursor);
712 QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
713 for (; it != last; it++)
715 const QString& partName = (*it);
716 cout << "Remove " << (const char*)partName.toLatin1() << endl;
717 mMULTIPRObj->removeParts(partName.toLatin1());
722 SUIT_MessageBox::critical(
723 (QWidget*) MULTIPR_GUI::desktop(),
724 QString("Remove error"),
725 QString("Error while removing selected part(s)"));
728 QApplication::restoreOverrideCursor();
730 getApp()->updateObjectBrowser();
731 getApp()->updateActions();
735 void MULTIPR_GUI::OnSave()
737 // check if MULTIPRObj exists
738 //if (mMULTIPRObj == NULL)
739 if (CORBA::is_nil(mMULTIPRObj))
744 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( (QWidget*) MULTIPR_GUI::desktop(), true,tr(""));
746 fd->setWindowTitle(tr("Save distributed MED file - Destination directory"));
747 fd->setFileMode(QFileDialog::DirectoryOnly);
749 if (fd->exec() == QDialog::Rejected)
755 QFileInfo aFileInfo(fd->selectedFile());
758 QApplication::setOverrideCursor(Qt::WaitCursor);
760 QString path = aFileInfo.filePath();
761 mMULTIPRObj->resetSaveProgress();
763 MULTIPR_GUI_SaveThread* a = new MULTIPR_GUI_SaveThread (this, mMULTIPRObj, path);
767 //mProgress = new MULTIPR_GUI_ProgressCallbackDlg (getApp()->desktop());
768 //mProgress->start("Save mesh", 100);
769 if (mProgress == NULL)
770 mProgress = new QProgressDialog ("Save mesh", "Cancel", 0,/*totalSteps*/100, (QWidget*) MULTIPR_GUI::desktop());
771 //mProgress->setProgress(0);
772 //mProgress->init(100);
773 mTimer->start(500); // 0.5 seconds timer
775 //QApplication::restoreOverrideCursor();
778 void MULTIPR_GUI::timerDone()
780 int progress = mMULTIPRObj->getSaveProgress();
781 if (mProgress != NULL) {
782 mProgress->setValue(progress);
784 if (progress >= 100) {
790 void MULTIPR_GUI::retrieveSelectedParts()
792 mSelectedParts.clear();
794 QStringList userSelection;
795 selected(userSelection, true);
796 for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
798 const QString& str = (*it);
799 QStringList words = str.split(":");
800 if (words.count() == 2)
802 if (words[0] == "MULTIPR_PART")
804 mSelectedParts.push_back(words[1]);
811 bool MULTIPR_GUI::isPartExist(const char* partName)
813 //if (mMULTIPRObj == NULL) return false;
814 if (CORBA::is_nil(mMULTIPRObj)) return false;
816 MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
817 for (int i=0 ; i<listParts->length() ; i++)
819 const char* strItem = (*listParts)[i];
820 if (strcmp(strItem, partName) == 0)
829 bool MULTIPR_GUI::removeLowerResolution()
831 // for each selected part, check if there are lower resolution
832 // and then propose to remove them before performing new process
833 QStringList partNameLowerResolution;
834 for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end();
837 const QString& partName = (*it);
838 QString partNameLow = partName + "_LOW";
839 QString partNameMed = partName + "_MED";
840 const char* strPartNameLow = partNameLow.toLatin1();
841 const char* strPartNameMed = partNameMed.toLatin1();
843 if (isPartExist(strPartNameLow))
845 partNameLowerResolution.push_back(partNameLow);
846 cout << "Part to be removed: " << strPartNameLow << endl;
849 if (isPartExist(strPartNameMed))
851 partNameLowerResolution.push_back(partNameMed);
852 cout << "Part to be removed: " << strPartNameMed << endl;
856 if (partNameLowerResolution.count() > 0)
858 if (QMessageBox::question(
859 (QWidget*) MULTIPR_GUI::desktop(),
860 QObject::tr("DEL_PREV_RESULTS"),
861 // tr("Remove previous results"),
862 QObject::tr("DEL_PREV_RESULTS_QUEST"),
863 // tr("Do you want to remove previous results?"),
864 tr("&Yes"), tr("&No"),
865 QString::null, 0, 1 ) )
870 QApplication::setOverrideCursor(Qt::WaitCursor);
874 for (QStringList::const_iterator it = partNameLowerResolution.begin(),
875 last = partNameLowerResolution.end(); it != last; it++)
877 const QString& partName = (*it);
878 cout << "Remove " << (const char*)partName.toLatin1() << endl;
879 mMULTIPRObj->removeParts(partName.toLatin1());
885 SUIT_MessageBox::critical(
886 (QWidget*) MULTIPR_GUI::desktop(),
887 QObject::tr("DEL_ERROR"),
889 QObject::tr("ERROR_DEL_PREV_RESULT"));
890 // "Error while removing previous results",
893 QApplication::restoreOverrideCursor();
895 getApp()->updateObjectBrowser();
896 getApp()->updateActions();
902 SUIT_Desktop* MULTIPR_GUI::desktop()
904 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
906 return app->desktop();
912 //*****************************************************************************
913 // Super class Data Object implementation
914 //*****************************************************************************
916 MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject (SUIT_DataObject* parent, const char* name)
917 : LightApp_DataObject(parent),
918 CAM_DataObject(parent)
924 MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject()
930 QString MULTIPR_GUI_DataObject::entry() const
932 return QString("MULTIPR_OBJECT");
936 QString MULTIPR_GUI_DataObject::name() const
942 QPixmap MULTIPR_GUI_DataObject::icon() const
944 //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
950 QString MULTIPR_GUI_DataObject::toolTip() const
952 // default behaviour: return an empty string
957 //*****************************************************************************
958 // Class Data Object Module implementation
959 //*****************************************************************************
962 MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module (CAM_DataModel* dm,
963 SUIT_DataObject* parent,
965 : MULTIPR_GUI_DataObject(parent, name),
966 // LightApp_DataObject(dm, parent),
967 CAM_DataObject(parent)
975 MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module()
981 QString MULTIPR_GUI_DataObject_Module::entry() const
983 return QString("MULTIPR_MODULE:" + mName);
987 QString MULTIPR_GUI_DataObject_Module::name() const
989 CAM_ModuleObject cam(mDm,mParent);
994 QPixmap MULTIPR_GUI_DataObject_Module::icon() const
1000 QString MULTIPR_GUI_DataObject_Module::toolTip() const
1002 return QString("Module MULTIPR");
1006 //*****************************************************************************
1007 // Class Data Object Mesh implementation
1008 //*****************************************************************************
1010 MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh (SUIT_DataObject* parent, const char* name)
1011 : MULTIPR_GUI_DataObject(parent, name),
1012 CAM_DataObject(parent)
1018 MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh()
1024 QString MULTIPR_GUI_DataObject_Mesh::entry() const
1026 return QString("MULTIPR_MESH:") + mName;
1030 QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const
1036 QString MULTIPR_GUI_DataObject_Mesh::toolTip() const
1038 return QString("Original mesh");
1042 //*****************************************************************************
1043 // Class Data Object Part implementation
1044 //*****************************************************************************
1046 MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part (SUIT_DataObject* parent,
1047 const char* name, const char* info)
1048 : MULTIPR_GUI_DataObject(parent, name),
1049 CAM_DataObject(parent)
1058 // parse info to retrieve all the fields
1059 char lMeshName[256];
1061 char lPartName[256];
1063 char lMEDFileName[256];
1065 int ret = sscanf(info, "%s %d %s %s %s",
1072 // number of read parameters should be 5
1073 if (ret != 5) return;
1075 mMeshName = lMeshName;
1078 mMEDFileName = lMEDFileName;
1082 MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part()
1088 QString MULTIPR_GUI_DataObject_Part::entry() const
1090 return QString("MULTIPR_PART:") + mName;
1094 QPixmap MULTIPR_GUI_DataObject_Part::icon() const
1100 QString MULTIPR_GUI_DataObject_Part::toolTip() const
1106 //*****************************************************************************
1107 // Class Data Object Resolution implementation
1108 //*****************************************************************************
1110 MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution (SUIT_DataObject* parent,
1111 const char* name, const char* info)
1112 : MULTIPR_GUI_DataObject_Part(parent, name, info),
1113 CAM_DataObject(parent)
1119 MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution()
1125 QString MULTIPR_GUI_DataObject_Resolution::entry() const
1127 return QString("MULTIPR_RESOLUTION:") + mName;
1131 QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const
1137 QString MULTIPR_GUI_DataObject_Resolution::toolTip() const
1143 //*****************************************************************************
1145 //*****************************************************************************
1147 MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module)
1148 // : LightApp_DataModel(module)
1149 : SalomeApp_DataModel(module)
1151 mMULTIPR_GUI = dynamic_cast<MULTIPR_GUI*>(module);
1154 MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
1159 void MULTIPR_GUI_DataModel::update (LightApp_DataObject*, LightApp_Study* theStudy)
1161 LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1163 //QListIterator<SUIT_DataObject> it1,it2;
1164 QMap<SUIT_DataObject*,int> aMap;
1167 ch = modelRoot->children();
1168 DataObjectList::const_iterator it = ch.begin(), it_last = ch.end();
1169 for (; it != it_last; it++)
1170 (*it)->setParent( 0);
1175 modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
1178 DataObjectList new_ch = modelRoot->children();
1179 DataObjectList::const_iterator it1 = new_ch.begin(), it1_last = new_ch.end();
1180 for (; it1 != it1_last; it1++)
1181 aMap.insert((*it1),0);
1185 DataObjectList::const_iterator it_del = ch.begin(), it_del_last = ch.end();
1186 for (; it_del != it_del_last; it_del++)
1187 if( !aMap.contains( (*it_del) ) )
1191 void MULTIPR_GUI_DataModel::build()
1195 void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy)
1199 SalomeApp_Study* aSAStudy = dynamic_cast<SalomeApp_Study*>(theStudy);
1201 aSAStudy = dynamic_cast<SalomeApp_Study*>(getModule()->getApp()->activeStudy());
1203 if (!aSAStudy) return;
1205 MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
1208 // root is not set yet
1209 modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
1213 // find SObject in Study
1214 MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_nil();
1216 _PTR(SComponent) aSComp = aSAStudy->studyDS()->FindComponent(module()->name().toStdString());
1219 _PTR(ChildIterator) it (aSAStudy->studyDS()->NewChildIterator(aSComp));
1222 _PTR(SObject) aSObj = it->Value();
1223 string anIOR = aSObj->GetIOR();
1226 CORBA::Object_var anObj = mMULTIPR_GUI->getApp()->orb()->string_to_object(anIOR.c_str());
1227 obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1229 // set Object to MULTIPR_GUI
1230 mMULTIPR_GUI->setMULTIPRObj(obj);
1232 //CORBA::Object_var anObj = aSObj->GetObject();
1233 //obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1234 //if (!CORBA::is_nil(obj))
1236 // // set Object to MULTIPR_GUI
1237 // mMULTIPR_GUI->setMULTIPRObj(obj);
1241 // remove Data Objects, automatically built for not loaded MULTIPR module
1242 // by SalomeApp_Application::updateObjectBrowser
1243 if (aSAStudy->root())
1245 DataObjectList ch_comp;
1246 aSAStudy->root()->children(ch_comp);
1247 DataObjectList::const_iterator anIt_comp = ch_comp.begin(), aLast_comp = ch_comp.end();
1248 for (; anIt_comp != aLast_comp; anIt_comp++)
1250 LightApp_DataObject* dobj = dynamic_cast<LightApp_DataObject*>(*anIt_comp);
1251 if (dobj && dobj->name() == aSComp->GetName().c_str())
1253 //SalomeApp_DataModelSync sync (aSAStudy->studyDS(), aSAStudy->root());
1254 //sync.deleteItemWithChildren(dobj);
1255 DataObjectList ch_obj;
1256 dobj->children(ch_obj);
1257 DataObjectList::const_iterator anIt_obj = ch_obj.begin(), aLast_obj = ch_obj.end();
1258 for (; anIt_obj != aLast_obj; anIt_obj++)
1259 // delete data object of each SObject
1262 // delete data object of SComponent itself
1271 if (!CORBA::is_nil(obj))
1274 std::string lMEDFile = obj->getFilename();
1275 std::string lMEDFileName = multipr::getFilenameWithoutPath(lMEDFile.c_str());
1276 MULTIPR_GUI_DataObject_Mesh* dataObjectMED =
1277 new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMEDFileName.c_str());
1280 MULTIPR_ORB::string_array* listParts = obj->getParts();
1282 if (listParts->length() >= 1)
1284 const char* strPartName0 = (*listParts)[0];
1285 char* strPartInfo0 = obj->getPartInfo(strPartName0);
1287 char lMeshName[256];
1289 char lPartName[256];
1291 char lMEDFileName[256];
1294 int ret = sscanf(strPartInfo0, "%s %d %s %s %s",
1303 cout << "MULTIPR: build() tree; error while parsing part info" << endl;
1304 std::runtime_error("MULTIPR: build() tree; error while parsing part info");
1308 MULTIPR_GUI_DataObject_Mesh* dataObjectMesh =
1309 new MULTIPR_GUI_DataObject_Mesh(dataObjectMED, lMeshName);
1311 // PART and RESOLUTION objects
1312 MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL;
1314 for (int i = 0 ; i < listParts->length() ; i++)
1316 const char* strItem = (*listParts)[i];
1317 char* strPartInfo = obj->getPartInfo(strItem);
1320 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
1327 if (ret != 5) return;
1329 if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
1331 new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
1335 dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
1349 CAM_Module* createModule()
1351 return new MULTIPR_GUI();