Salome HOME
d74519edac0f6e6aa644271469d96b5add1b8f07
[modules/multipr.git] / src / MULTIPRGUI / MULTIPR_GUI.cxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_GUI.cxx
6  *
7  * \brief   see MULTIPR_GUI.h
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13   
14 //*****************************************************************************
15 // Includes section
16 //*****************************************************************************
17
18 // MULTIPR Includes
19 #include "MULTIPR_GUI.h"
20 #include "MULTIPR_GUI_Dlg.h"
21 #include "MULTIPR_Utils.hxx"
22
23 // Salome Includes
24 #include <SUIT_MessageBox.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_Session.h>
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_DataModel.h>
29 #include <SalomeApp_Study.h>
30 #include <SalomeApp_CheckFileDlg.h>
31 #include <LightApp_Study.h>
32 #include <LightApp_DataModel.h>
33 #include <LightApp_DataOwner.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <CAM_DataModel.h>
36 #include <CAM_Module.h>
37
38 #include <SALOME_LifeCycleCORBA.hxx>
39
40 #include <QtxPopupMgr.h>
41
42 // QT Includes
43 #include <qapplication.h>
44 #include <qinputdialog.h>
45 #include <qlayout.h>
46 #include <qpushbutton.h>
47 #include <qgroupbox.h>
48 #include <qvbox.h>
49 #include <qbuttongroup.h>
50 #include <qlabel.h>
51 #include <qcombobox.h>
52 #include <qvariant.h>
53 #include <qlineedit.h>
54 #include <qspinbox.h>
55 #include <qtooltip.h>
56 #include <qwhatsthis.h>
57 #include <qimage.h>
58 #include <qpixmap.h>
59 #include <qmessagebox.h>
60 #include <qaction.h>
61
62
63 #include <stdexcept>
64
65 using namespace std;
66
67
68 //*****************************************************************************
69 // Global variable
70 //*****************************************************************************
71
72 namespace multipr
73 {
74     // progress callback used by the MULTIPR library
75     extern MULTIPR_ProgressCallback*  gProgressCallback;
76     extern MULTIPR_EmptyMeshCallback* gEmptyMeshCallback;
77 }
78
79
80 //*****************************************************************************
81 // Global function
82 //*****************************************************************************
83
84 // singleton
85 MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen(const CAM_Module* theModule)
86 {
87     static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL;
88     
89     if (!aGen)
90     {
91         SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
92         Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer", "MULTIPR");
93         aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(aComponent);
94         if (!CORBA::is_nil(aGen))
95         {
96             //aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
97         }
98     }
99     
100     if (CORBA::is_nil(aGen))
101         throw std::runtime_error("Can't find MULTIPR component");
102     
103     return aGen;
104 }
105   
106
107 //*****************************************************************************
108 // Class MULTIPR_GUI implementation
109 //*****************************************************************************
110
111 MULTIPR_GUI::MULTIPR_GUI() : SalomeApp_Module("MULTIPR")
112 {
113     mMEDFileName = "";
114     mMULTIPRObj = NULL;
115 }
116
117
118 MULTIPR_GUI::~MULTIPR_GUI()
119 {
120     if (mMULTIPRObj != NULL)
121     {
122         CORBA::release(mMULTIPRObj);
123     }
124 }
125
126
127 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj()
128 {
129     return mMULTIPRObj;
130 }
131
132
133 SalomeApp_Application* MULTIPR_GUI::getAppli() const
134 {
135     return getApp();
136 }
137
138
139 void MULTIPR_GUI::initialize(CAM_Application* app)
140 {
141     SalomeApp_Module::initialize(app);
142     
143     GetMultiprGen(this);
144     
145     QWidget* aParent = app->desktop();
146     SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
147     
148     //-------------------------------------------------------------------------
149     // create actions
150     //-------------------------------------------------------------------------    
151     QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED"));
152     
153     createAction( 
154         ACTION_IMPORT_MED, 
155         tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"), 
156         QIconSet(aPixmapImportFromMEDFile), 
157         tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"), 
158         tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"), 
159         (CTRL + Key_I),
160         aParent, 
161         false,
162         this, 
163         SLOT(OnImportFromMEDFile()));
164         
165     createAction( 
166         ACTION_SPLIT, 
167         tr("MULTIPR_TLT_SPLIT"), 
168         QIconSet(), 
169         tr("MULTIPR_MEN_SPLIT"), 
170         tr("MULTIPR_STS_SPLIT"), 
171         0,
172         aParent, 
173         false,
174         this, 
175         SLOT(OnPartition2()));
176     
177     createAction( 
178         ACTION_DECIMATE, 
179         tr("MULTIPR_TLT_DECIMATE"), 
180         QIconSet(), 
181         tr("MULTIPR_MEN_DECIMATE"), 
182         tr("MULTIPR_STS_DECIMATE"), 
183         0,
184         aParent, 
185         false,
186         this, 
187         SLOT(OnDecimate()));
188     
189     createAction( 
190         ACTION_REMOVE, 
191         tr("MULTIPR_TLT_REMOVE"), 
192         QIconSet(), 
193         tr("MULTIPR_MEN_REMOVE"), 
194         tr("MULTIPR_STS_REMOVE"), 
195         0,
196         aParent, 
197         false,
198         this, 
199         SLOT(OnRemove()));
200         
201     QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED"));
202     
203     createAction( 
204         ACTION_SAVE, 
205         tr("MULTIPR_TLT_SAVE"), 
206         QIconSet(aPixmapSaveMEDFile), 
207         tr("MULTIPR_MEN_SAVE"), 
208         tr("MULTIPR_STS_SAVE"), 
209         0,
210         aParent, 
211         false,
212         this, 
213         SLOT(OnSave()));
214     
215     //-------------------------------------------------------------------------
216     // create menus
217     //-------------------------------------------------------------------------
218     int aMenuId;
219     aMenuId = createMenu(tr("MULTIPR_MEN_FILE"), -1, -1);
220     createMenu(separator(), aMenuId, -1, 10);
221     aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10);
222     createMenu(ACTION_IMPORT_MED, aMenuId);
223     
224     aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30);
225     createMenu(ACTION_IMPORT_MED, aMenuId, 10);
226     createMenu(ACTION_SAVE, aMenuId, 10);
227     createMenu(ACTION_SPLIT, aMenuId, 10);
228     createMenu(ACTION_DECIMATE, aMenuId, 10);
229     createMenu(ACTION_REMOVE, aMenuId, 10);
230     
231     //-------------------------------------------------------------------------
232     // create toolbars
233     //-------------------------------------------------------------------------
234     int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR"));
235     createTool(ACTION_IMPORT_MED, aToolId);
236     createTool(ACTION_SAVE, aToolId);
237     
238     //-------------------------------------------------------------------------
239     // create popup menus
240     //-------------------------------------------------------------------------
241     QtxPopupMgr* mgr = popupMgr();
242     mgr->insert( action(ACTION_SPLIT), -1, -1, -1 );
243     mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 );
244     mgr->insert( action(ACTION_REMOVE), -1, -1, -1 );
245     mgr->insert( action(ACTION_SAVE), -1, -1, -1 );
246     
247     QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}";
248     mgr->setRule(action(ACTION_SPLIT), aRule, true);
249     mgr->setRule(action(ACTION_DECIMATE), aRule, true);
250     mgr->setRule(action(ACTION_REMOVE), aRule, true);
251     mgr->setRule(action(ACTION_SAVE), aRule, true);
252     
253     //-------------------------------------------------------------------------
254     // set progress dialog
255     //-------------------------------------------------------------------------
256     MULTIPR_GUI_ProgressCallbackDlg* progressDlg = new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop());
257     multipr::gProgressCallback = progressDlg;
258     
259     MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg = new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop());
260     multipr::gEmptyMeshCallback = emptyMeshDlg;
261 }
262
263
264 CAM_DataModel* MULTIPR_GUI::createDataModel()
265 {
266     return new MULTIPR_GUI_DataModel(this);
267 }
268
269
270 QString MULTIPR_GUI::engineIOR() const
271 {
272     CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(this));
273     return QString(anIOR.in());
274 }
275
276
277 bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy)
278 {
279     bool bOk = SalomeApp_Module::activateModule(theStudy);
280     
281     setMenuShown(true);
282     setToolShown(true);
283     
284     action(ACTION_IMPORT_MED)->setAccel(QKeySequence(CTRL + Key_I));
285     
286     return bOk;
287 }
288
289
290 bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy)
291 {
292     setMenuShown(false);
293     setToolShown(false);
294     
295     // Unset actions accelerator keys
296     action(ACTION_IMPORT_MED)->setAccel(QKeySequence());
297   
298     return SalomeApp_Module::deactivateModule(theStudy);
299 }
300
301   
302 void MULTIPR_GUI::windows(QMap<int, int>& theMap) const
303 {
304     theMap.clear();
305     theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft);
306     theMap.insert(SalomeApp_Application::WT_PyConsole,     Qt::DockBottom);
307 }
308
309
310 void MULTIPR_GUI::selected(QStringList& entries, const bool multiple)
311 {
312     LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
313     
314     if(!mgr) return;
315     
316     SUIT_DataOwnerPtrList anOwnersList;
317     mgr->selected(anOwnersList);
318     
319     for (int i = 0 ; i < anOwnersList.size() ; i++)
320     {
321         const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(anOwnersList[i].get());
322         
323         if (!entries.contains(owner->entry()))
324         {
325             entries.append(owner->entry());
326         }
327             
328         if (!multiple)
329             break;
330     }
331 }
332
333
334 void MULTIPR_GUI::OnImportFromMEDFile()
335 {
336     // Get file name
337     QStringList aFilter;
338     aFilter.append(tr("MULTIPR_FLT_MED_FILES"));
339     aFilter.append(tr("MULTIPR_FLT_ALL_FILES"));
340     
341     SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
342         this->application()->desktop(), 
343         true, 
344         tr("") );
345         
346     fd->setCaption(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"));
347     fd->setFilters(aFilter);
348     if (fd->exec() == QDialog::Rejected)
349     {
350         delete fd;
351         return;
352     }
353     
354     QFileInfo aFileInfo(fd->selectedFile());
355     delete fd;
356     
357     // Check the file name
358     if (!aFileInfo.exists())
359         return;
360         
361     mMEDFileName = aFileInfo.filePath();
362     
363     QApplication::setOverrideCursor(Qt::waitCursor);
364     
365     try
366     {
367         MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(this);
368         mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1());
369     }
370     catch(...)
371     {
372         SUIT_MessageBox::error1( 
373             getApp()->desktop(),
374             "Import MED file error", 
375             "Invalid MED file (not recognized by MULTIPR)", 
376             tr("MULTIPR_BUT_OK") );
377     }
378     QApplication::restoreOverrideCursor();
379     
380     if (mMULTIPRObj != NULL)
381     {
382         try
383         {
384             if (mMULTIPRObj->isValidSequentialMEDFile())
385             {
386                 OnPartition1();
387             }
388         }
389         catch (...)
390         {
391         }
392         
393         getApp()->updateObjectBrowser();
394     }
395 }
396
397
398 void MULTIPR_GUI::OnPartition1()
399 {
400     // check if MULTIPRObj exists
401     if (mMULTIPRObj == NULL)
402     {
403         return;
404     }
405     
406     MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this);
407     dialog->exec();
408     delete dialog;
409 }
410
411
412 void MULTIPR_GUI::OnPartition2()
413 {
414     // check if MULTIPRObj exists
415     if (mMULTIPRObj == NULL)
416     {
417         return;
418     }
419     
420     retrieveSelectedParts();
421     
422     if (mSelectedParts.count() == 0)
423     {
424         SUIT_MessageBox::warn1( 
425             getApp()->desktop(),
426             "Split warning", 
427             "No parts selected", 
428             tr("MULTIPR_BUT_OK") );
429         return;
430     }
431     
432     if (!removeLowerResolution())
433     {
434         return;
435     }
436     
437     MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
438     dialog->exec();
439     delete dialog;
440     getApp()->updateObjectBrowser();
441 }
442
443
444 void MULTIPR_GUI::OnDecimate()
445 {
446     // check if MULTIPRObj exists
447     if (mMULTIPRObj == NULL)
448     {
449         return;
450     }
451     
452     retrieveSelectedParts();
453     
454     if (mSelectedParts.count() == 0)
455     {
456         SUIT_MessageBox::warn1( 
457             getApp()->desktop(),
458             "Decimation warning", 
459             "No parts selected", 
460             tr("MULTIPR_BUT_OK") );
461         return;
462     }
463     
464     if (!removeLowerResolution())
465     {
466         return;
467     }
468     
469     MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
470     dialog->exec();
471     delete dialog;
472     getApp()->updateObjectBrowser();
473 }
474
475
476 void MULTIPR_GUI::OnRemove()
477 {
478     // check if MULTIPRObj exists
479     if (mMULTIPRObj == NULL)
480     {
481         return;
482     }
483     
484     retrieveSelectedParts();
485     
486     if (mSelectedParts.count() == 0)
487     {
488         SUIT_MessageBox::warn1( 
489             getApp()->desktop(),
490             "Remove warning", 
491             "No parts selected", 
492             tr("MULTIPR_BUT_OK") );
493         return;
494     }
495     
496     if (QMessageBox::question(
497             getApp()->desktop(),
498             tr("Remove selected part(s)"),
499             tr("Do you want to remove selected part(s)?"),
500             tr("&Yes"), tr("&No"),
501             QString::null, 0, 1 ) )
502     {
503         return;
504     }
505
506     QApplication::setOverrideCursor(Qt::waitCursor);
507     
508     try
509     {
510         for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
511         {
512             const QString& partName = (*it);
513             cout << "Remove " << partName.latin1() << endl;
514             mMULTIPRObj->removeParts(partName.latin1());
515         }
516         
517     }
518     catch(...)
519     {
520         SUIT_MessageBox::error1( 
521             getApp()->desktop(),
522             "Remove error", 
523             "Error while removing selected part(s)", 
524             tr("MULTIPR_BUT_OK") );
525     }
526     
527     QApplication::restoreOverrideCursor();
528     
529     getApp()->updateObjectBrowser();
530 }
531
532
533 void MULTIPR_GUI::OnSave()
534 {
535     // check if MULTIPRObj exists
536     if (mMULTIPRObj == NULL)
537     {
538         return;
539     }
540     
541     SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg(
542         this->application()->desktop(), 
543         true, 
544         tr("") );
545         
546     fd->setCaption(tr("Save distributed MED file - Destination directory"));
547     fd->setMode(QFileDialog::DirectoryOnly);
548     
549     if (fd->exec() == QDialog::Rejected)
550     {
551         delete fd;
552         return;
553     }
554     
555     QFileInfo aFileInfo(fd->selectedFile());
556     delete fd;
557         
558     QString path = aFileInfo.filePath();
559     
560     QApplication::setOverrideCursor(Qt::waitCursor);
561     
562     try
563     {
564         mMULTIPRObj->save(path);
565         getApp()->updateObjectBrowser();
566     }
567     catch(...)
568     {
569         SUIT_MessageBox::error1( 
570             getApp()->desktop(),
571             "Save distributed MED file error", 
572             "Error while writing distributed MED file", 
573             tr("MULTIPR_BUT_OK") );
574     }
575     
576     QApplication::restoreOverrideCursor();
577 }
578
579
580
581 void MULTIPR_GUI::retrieveSelectedParts()
582 {
583     mSelectedParts.clear();
584
585     QStringList userSelection;    
586     selected(userSelection, true);
587     for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
588     {
589         const QString& str = (*it);
590         QStringList words = QStringList::split(":", str);
591         if (words.count() == 2)
592         {
593             if (words[0] == "MULTIPR_PART")
594             {
595                 mSelectedParts.push_back(words[1]);
596             }
597         }
598     }
599 }
600
601
602 bool MULTIPR_GUI::isPartExist(const char* partName)
603 {
604     if (mMULTIPRObj == NULL) return false;
605     
606     MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts();
607     for (int i=0 ; i<listParts->length() ; i++)
608     {
609         const char* strItem = (*listParts)[i];
610         if (strcmp(strItem, partName) == 0) 
611         {
612             return true;
613         }
614     }
615     return false;
616 }
617
618
619 bool MULTIPR_GUI::removeLowerResolution()
620 {
621     // for each selected part, check if there are lower resolution
622     // and then propose to remove them before performing new process
623     QStringList partNameLowerResolution;
624     for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
625     {
626         const QString& partName = (*it);
627         QString partNameLow = partName + "_LOW";
628         QString partNameMed = partName + "_MED";
629         const char* strPartNameLow = partNameLow.latin1();
630         const char* strPartNameMed = partNameMed.latin1();
631         
632         if (isPartExist(strPartNameLow))
633         {
634             partNameLowerResolution.push_back(partNameLow);
635             cout << "Part to be removed: " << partNameLow << endl;
636         }
637         
638         if (isPartExist(strPartNameMed))
639         {
640             partNameLowerResolution.push_back(partNameMed);
641             cout << "Part to be removed: " << partNameMed << endl;
642         }
643     }
644      
645     if (partNameLowerResolution.count() > 0)
646     {
647         if (QMessageBox::question(
648                 getApp()->desktop(),
649                 tr("Remove previous results"),
650                 tr("Do you want to remove previous results?"),
651                 tr("&Yes"), tr("&No"),
652                 QString::null, 0, 1 ) )
653         {
654             return false;
655         }
656     
657         QApplication::setOverrideCursor(Qt::waitCursor);
658         
659         try
660         {
661             for (QStringList::const_iterator it = partNameLowerResolution.begin(), last = partNameLowerResolution.end(); it != last; it++)
662             {
663                 const QString& partName = (*it);
664                 cout << "Remove " << partName.latin1() << endl;
665                 mMULTIPRObj->removeParts(partName.latin1());
666             }
667             
668         }
669         catch(...)
670         {
671             SUIT_MessageBox::error1( 
672                 getApp()->desktop(),
673                 "Remove error", 
674                 "Error while removing previous results", 
675                 tr("MULTIPR_BUT_OK") );
676         }
677         
678         QApplication::restoreOverrideCursor();
679         
680         getApp()->updateObjectBrowser();
681     }
682     
683     return true;
684 }
685
686
687 //*****************************************************************************
688 // Super class Data Object implementation
689 //*****************************************************************************
690
691 MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject(SUIT_DataObject* parent, const char* name) : 
692     LightApp_DataObject(parent),
693     CAM_DataObject(parent)
694 {
695     mName = name;
696 }
697
698
699 MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject()
700 {
701     // do nothing!
702 }
703
704
705 QString MULTIPR_GUI_DataObject::entry() const
706 {
707     return QString("MULTIPR_OBJECT");
708 }
709
710
711 QString MULTIPR_GUI_DataObject::name() const
712 {
713   return mName;
714 }
715
716
717 QPixmap MULTIPR_GUI_DataObject::icon() const
718 {
719     //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false);
720     return QPixmap();
721     
722 }
723
724
725 QString MULTIPR_GUI_DataObject::toolTip() const
726 {
727     // default behaviour: return an empty string
728     return "";
729 }
730
731
732 //*****************************************************************************
733 // Class Data Object Module implementation
734 //*****************************************************************************
735
736 MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module(CAM_DataModel* dm, SUIT_DataObject* parent, const char* name) : 
737     MULTIPR_GUI_DataObject(parent, name),
738     LightApp_ModuleObject(dm, parent),
739     CAM_DataObject(parent)
740 {
741     // do nothing!
742 }
743
744
745 MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module()
746 {
747     // do nothing!
748 }
749
750
751 QString MULTIPR_GUI_DataObject_Module::entry() const
752 {
753     return QString("MULTIPR_MODULE:" + mName);
754 }
755
756
757 QString MULTIPR_GUI_DataObject_Module::name() const
758 {
759   return CAM_RootObject::name();
760 }
761
762
763 QPixmap MULTIPR_GUI_DataObject_Module::icon() const
764 {
765     return QPixmap();
766 }
767
768
769 QString MULTIPR_GUI_DataObject_Module::toolTip() const
770 {
771     return QString("Module MULTIPR");
772 }
773
774
775 //*****************************************************************************
776 // Class Data Object Mesh implementation
777 //*****************************************************************************
778
779 MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh(SUIT_DataObject* parent, const char* name) : 
780     MULTIPR_GUI_DataObject(parent, name),
781     CAM_DataObject(parent)
782 {
783     // do nothing!
784 }
785
786
787 MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh()
788 {
789     // do nothing!
790 }
791
792
793 QString MULTIPR_GUI_DataObject_Mesh::entry() const
794 {
795     return QString("MULTIPR_MESH:") + mName;
796 }
797
798
799 QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const
800 {
801     return QPixmap();
802 }
803
804
805 QString MULTIPR_GUI_DataObject_Mesh::toolTip() const
806 {
807     return QString("Original mesh");
808 }
809
810
811 //*****************************************************************************
812 // Class Data Object Part implementation
813 //*****************************************************************************
814
815 MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part(SUIT_DataObject* parent, const char* name, const char* info) : 
816     MULTIPR_GUI_DataObject(parent, name),
817     CAM_DataObject(parent)
818 {
819     mMeshName    = "";
820     mId          = 0;
821     mPath        = "";
822     mMEDFileName = "";
823     
824     mTooltip = info;
825     
826     // parse info to retrieve all the fields
827     char   lMeshName[256];
828     int    lId;
829     char   lPartName[256];
830     char   lPath[256];
831     char   lMEDFileName[256];
832     
833     int ret = sscanf(info, "%s %d %s %s %s", 
834                 lMeshName,
835                 &lId,
836                 lPartName,
837                 lPath,
838                 lMEDFileName);
839                 
840     // number of read parameters should be 5
841     if (ret != 5) return;
842     
843     mMeshName    = lMeshName;
844     mId          = lId;
845     mPath        = lPath;
846     mMEDFileName = lMEDFileName;
847 }
848
849
850 MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part()
851 {
852     // do nothing!
853 }
854
855
856 QString MULTIPR_GUI_DataObject_Part::entry() const
857 {
858     return QString("MULTIPR_PART:") + mName;
859 }
860
861
862 QPixmap MULTIPR_GUI_DataObject_Part::icon() const
863 {
864     return QPixmap();
865 }
866
867
868 QString MULTIPR_GUI_DataObject_Part::toolTip() const
869 {
870     return mTooltip;
871 }
872
873
874 //*****************************************************************************
875 // Class Data Object Resolution implementation
876 //*****************************************************************************
877
878 MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution(SUIT_DataObject* parent, const char* name, const char* info) : 
879     MULTIPR_GUI_DataObject_Part(parent, name, info),
880     CAM_DataObject(parent)
881 {
882     // do nothing!
883 }
884
885
886 MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution()
887 {
888     // do nothing!
889 }
890
891
892 QString MULTIPR_GUI_DataObject_Resolution::entry() const
893 {
894     return QString("MULTIPR_RESOLUTION:") + mName;
895 }
896
897
898 QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const
899 {
900     return QPixmap();
901 }
902
903
904 QString MULTIPR_GUI_DataObject_Resolution::toolTip() const
905 {
906     return mTooltip;
907 }
908
909
910 //*****************************************************************************
911 // Data Model
912 //*****************************************************************************
913
914 MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module) : 
915     LightApp_DataModel(module)
916 {
917     mMULTIPR_GUI = dynamic_cast<MULTIPR_GUI*>(module);
918 }
919
920
921 MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
922 {
923     // do nothing!
924 }
925
926
927 void MULTIPR_GUI_DataModel::build()
928 {
929     try
930     {
931         MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
932         
933         if (!modelRoot)  
934         {  
935             // root is not set yet
936             modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
937             setRoot(modelRoot);
938         }
939         
940         MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj();
941         
942         if (obj != NULL)
943         {
944             MULTIPR_ORB::string_array* listParts = obj->getParts();
945             
946             if (listParts->length() >= 1)
947             {
948                 const char* strPartName0 = (*listParts)[0];
949                 char* strPartInfo0 = obj->getPartInfo(strPartName0);
950                 
951                 char   lMeshName[256];
952                 int    lId;
953                 char   lPartName[256];
954                 char   lPath[256];
955                 char   lMEDFileName[256];    
956                 
957                 // parse infos
958                 int ret = sscanf(strPartInfo0, "%s %d %s %s %s", 
959                     lMeshName,
960                     &lId,
961                     lPartName,
962                     lPath,
963                     lMEDFileName);
964                     
965                 if (ret != 5) 
966                 {
967                     cout << "MULTIPR: build() tree; error while parsing part info" << endl;
968                     std::runtime_error("MULTIPR: build() tree; error while parsing part info");
969                     return;
970                 }
971                 
972                 MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName);
973                 
974                 MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL;
975                 
976                 for (int i = 0 ; i < listParts->length() ; i++)
977                 {
978                     const char* strItem = (*listParts)[i];
979                     char* strPartInfo = obj->getPartInfo(strItem);
980                     
981                     // parse infos
982                     int ret = sscanf(strPartInfo, "%s %d %s %s %s", 
983                         lMeshName,
984                         &lId,
985                         lPartName,
986                         lPath,
987                         lMEDFileName);
988                     
989                     if (ret != 5) return;
990                 
991                     if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
992                     {
993                         new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
994                     }
995                     else
996                     {
997                         dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
998                     }
999                 }
1000             }
1001         }
1002     }
1003     catch (...)
1004     {
1005     }
1006 }
1007
1008
1009 extern "C" 
1010 {
1011     CAM_Module* createModule()
1012     {
1013         return new MULTIPR_GUI();
1014     }
1015 }
1016
1017
1018 // EOF