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