Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / VISUGUI / VisuGUI_EditContainerDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : VisuGUI_EditContainerDlg.cxx
8 //  Author : VSV
9 //  Module : VISU
10
11
12 #include "VisuGUI_EditContainerDlg.h"
13
14 #include "VisuGUI.h"
15 #include "VisuGUI_Tools.h"
16
17 #include "VISU_Table_i.hh"
18
19 #include "SalomeApp_Application.h"
20 #include "SUIT_Desktop.h"
21 #include "SUIT_Session.h"
22 #include "SUIT_MessageBox.h"
23 #include "SUIT_ResourceMgr.h"
24
25 #include <qlayout.h>
26 #include <qcheckbox.h>
27 #include <qgroupbox.h>
28 #include <qpushbutton.h>
29 #include <qlabel.h>
30
31 using namespace std;
32
33
34 /* XPM */
35 static const char * left_xpm[] = {
36 "24 24 61 1",
37 "       c None",
38 ".      c #323232",
39 "+      c #010101",
40 "@      c #4A4A4A",
41 "#      c #040404",
42 "$      c #979797",
43 "%      c #7B7B7B",
44 "&      c #939393",
45 "*      c #EEEEEE",
46 "=      c #686868",
47 "-      c #030303",
48 ";      c #9C9C9C",
49 ">      c #FFFFFF",
50 ",      c #B1B1B1",
51 "'      c #5E5E5E",
52 ")      c #060606",
53 "!      c #C1C1C1",
54 "~      c #626262",
55 "{      c #000000",
56 "]      c #989898",
57 "^      c #A1A1A1",
58 "/      c #A5A5A5",
59 "(      c #909090",
60 "_      c #868686",
61 ":      c #616161",
62 "<      c #959595",
63 "[      c #919191",
64 "}      c #848484",
65 "|      c #606060",
66 "1      c #0B0B0B",
67 "2      c #545454",
68 "3      c #727272",
69 "4      c #A2A2A2",
70 "5      c #969696",
71 "6      c #838383",
72 "7      c #5F5F5F",
73 "8      c #101010",
74 "9      c #434343",
75 "0      c #6B6B6B",
76 "a      c #858585",
77 "b      c #8E8E8E",
78 "c      c #373737",
79 "d      c #696969",
80 "e      c #8D8D8D",
81 "f      c #B5B5B5",
82 "g      c #111111",
83 "h      c #393939",
84 "i      c #898989",
85 "j      c #B0B0B0",
86 "k      c #191919",
87 "l      c #3A3A3A",
88 "m      c #646464",
89 "n      c #535353",
90 "o      c #050505",
91 "p      c #353535",
92 "q      c #585858",
93 "r      c #4C4C4C",
94 "s      c #0D0D0D",
95 "t      c #3E3E3E",
96 "u      c #020202",
97 "v      c #0A0A0A",
98 "                        ",
99 "                        ",
100 "         .+        .+   ",
101 "        .@#       .@#   ",
102 "       .$%#      .$%#   ",
103 "      .&*=-     .&*=-   ",
104 "     .;>,')    .;>,')   ",
105 "    .;>!;~{   .;>!;~{   ",
106 "   .]>!^&~{  .]>!^&~{   ",
107 "  ./>!/(_:{ ./>!/(_:{   ",
108 " .<*!^[}}|{.<*!^[}}|{   ",
109 " 123}45667{123}45667{   ",
110 "  890a45b7{ 890a45b7{   ",
111 "   8cdef5'{  8cdef5'{   ",
112 "    gh0ij7k   gh0ij7k   ",
113 "     8lm0no    8lm0no   ",
114 "      8pqr-     8pqr-   ",
115 "       sht-      sht-   ",
116 "        1.u       1.u   ",
117 "         v{        v{   ",
118 "                        ",
119 "                        ",
120 "                        ",
121 "                        "};
122
123 static QPixmap MYLeftPix(left_xpm);
124
125
126 static const char * right_xpm[] = {
127 "24 24 43 1",
128 "       g None",
129 ".      g #323232",
130 "+      g #5D5D5D",
131 "@      g #000000",
132 "#      g #C4C4C4",
133 "$      g #313131",
134 "%      g #C5C5C5",
135 "&      g #E4E4E4",
136 "*      g #2D2D2D",
137 "=      g #B7B7B7",
138 "-      g #EFEFEF",
139 ";      g #DCDCDC",
140 ">      g #282828",
141 ",      g #AFAFAF",
142 "'      g #E0E0E0",
143 ")      g #242424",
144 "!      g #C7C7C7",
145 "~      g #9A9A9A",
146 "{      g #8E8E8E",
147 "]      g #1F1F1F",
148 "^      g #A5A5A5",
149 "/      g #989898",
150 "(      g #888888",
151 "_      g #1B1B1B",
152 ":      g #ADADAD",
153 "<      g #858585",
154 "[      g #838383",
155 "}      g #868686",
156 "|      g #929292",
157 "1      g #C1C1C1",
158 "2      g #161616",
159 "3      g #909090",
160 "4      g #747474",
161 "5      g #3A3A3A",
162 "6      g #121212",
163 "7      g #0D0D0D",
164 "8      g #7A7A7A",
165 "9      g #8A8A8A",
166 "0      g #090909",
167 "a      g #040404",
168 "b      g #707070",
169 "c      g #6E6E6E",
170 "d      g #3F3F3F",
171 "                        ",
172 "                        ",
173 " ..        ..           ",
174 " .+@       .+@          ",
175 " .#+@      .#+@         ",
176 " $%&+@     $%&+@        ",
177 " *=-;+@    *=-;+@       ",
178 " >,'=;+@   >,'=;+@      ",
179 " ),!~{;+@  ),!~{;+@     ",
180 " ]^!/({;+@ ]^!/({;+@    ",
181 " _~:<[}|1+@_~:<[}|1+@   ",
182 " 23~[[{:45@23~[[{:45@   ",
183 " 6</[{:45@ 6</[{:45@    ",
184 " 789{:45@  789{:45@     ",
185 " 08~:45@   08~:45@      ",
186 " a4~45@    a4~45@       ",
187 " @b45@     @b45@        ",
188 " @c5@      @c5@         ",
189 " @d@       @d@          ",
190 " @@        @@           ",
191 "                        ",
192 "                        ",
193 "                        ",
194 "                        "};
195
196 static QPixmap MYRightPix(right_xpm);
197
198
199 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal)
200      : QDialog(VISU::GetDesktop(theModule), "VisuGUI_EditContainerDlg", theIsModal,
201                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
202        myVisuGUI(theModule)
203 {
204   if (!theIsModal) {
205     setWFlags(getWFlags() | WDestructiveClose);
206   }
207   setCaption("Edit Plot 2D Presentation");
208   setSizeGripEnabled(true);
209
210   QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
211
212   /***************************************************************/
213   QFrame* aControlFrame = new QFrame (this);
214   aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
215
216   QGridLayout* aControlLay = new QGridLayout (aControlFrame);
217   aControlLay->setSpacing(6);
218   aControlLay->setMargin(11);
219   aControlLay->addRowSpacing(1, 30);
220   aControlLay->addRowSpacing(4, 30);
221   aControlLay->setRowStretch(1, 1);
222   aControlLay->setRowStretch(4, 1);
223   aControlLay->addColSpacing(0, 180);
224   aControlLay->addColSpacing(2, 180);
225
226   QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
227   aControlLay->addWidget(aSelectLbl, 0, 0);
228
229   myStudyLst = new QListView (aControlFrame);
230   myStudyLst->setSelectionMode(QListView::Extended);
231   myStudyLst->addColumn(tr("TXT_TABLE"), 80);
232   myStudyLst->addColumn(tr("TXT_CURVE"), 50);
233   myStudyLst->addColumn(tr(""), 0);
234   myStudyLst->setAllColumnsShowFocus(true);
235   myStudyLst->setMinimumHeight(130);
236   connect(myStudyLst, SIGNAL(selectionChanged()), this, SLOT(onLeftSelected()));
237   aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0);
238
239   myRightBtn = new QToolButton (aControlFrame);
240   myRightBtn->setIconSet(MYRightPix);
241   myRightBtn->setEnabled(false);
242   connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked()));
243   aControlLay->addWidget(myRightBtn, 2, 1);
244
245   myLeftBtn = new QToolButton(aControlFrame);
246   myLeftBtn->setIconSet(MYLeftPix);
247   myLeftBtn->setEnabled(false);
248   connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked()));
249   aControlLay->addWidget(myLeftBtn, 3, 1);
250
251   QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
252   aControlLay->addWidget(aForceLbl, 0, 2);
253
254   myContainerLst = new QListView(aControlFrame);
255   myContainerLst->setSelectionMode(QListView::Extended);
256   myContainerLst->addColumn(tr("TXT_TABLE"), 80);
257   myContainerLst->addColumn(tr("TXT_CURVE"), 50);
258   myContainerLst->addColumn(tr(""), 0);
259   myContainerLst->setMinimumWidth(130);
260   connect(myContainerLst, SIGNAL(selectionChanged()), this, SLOT(onRightSelected()));
261   aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2);
262
263   TopLayout->addWidget(aControlFrame);
264
265   // Common buttons ===========================================================
266   QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
267   GroupButtons->setColumnLayout(0, Qt::Vertical);
268   GroupButtons->layout()->setSpacing(0);
269   GroupButtons->layout()->setMargin(0);
270   QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
271   GroupButtonsLayout->setAlignment(Qt::AlignTop);
272   GroupButtonsLayout->setSpacing(6);
273   GroupButtonsLayout->setMargin(11);
274
275   QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
276   buttonOk->setAutoDefault(TRUE);
277   buttonOk->setDefault(TRUE);
278   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
279   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding,
280                                               QSizePolicy::Minimum), 0, 1);
281
282   QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
283   buttonCancel->setAutoDefault(TRUE);
284   GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
285
286   QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp");
287   buttonHelp->setAutoDefault(TRUE);
288   GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
289
290   TopLayout->addWidget(GroupButtons);
291
292   connect(buttonOk,     SIGNAL(clicked()),      this, SLOT(accept()));
293   connect(buttonCancel, SIGNAL(clicked()),      this, SLOT(reject()));
294   connect(buttonHelp,   SIGNAL(clicked()),      this, SLOT(onHelp()));
295 }
296
297 void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
298 {
299   _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
300   _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
301   if (!aVisuSO) {
302     return;
303   }
304   QValueList<CurveStruct> aStudyCurves;
305   QValueList<CurveStruct> aContainerCurves;
306   // Find curves in container
307   for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
308     VISU::Curve_i* aCurve = theContainer->GetCurve(i);
309     if (aCurve == NULL) continue;
310     CurveStruct aEntry;
311     aEntry.CurveName = aCurve->GetTitle();
312     aEntry.CurveEntry = aCurve->GetEntry();
313     _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
314     if (!aTableSO) continue;
315     aEntry.TableName = getSObjectName(aTableSO);
316     aContainerCurves.append(aEntry);
317     new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry);
318   }
319   // Find curves in study
320   _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO);
321   for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
322     _PTR(SObject) aSObject = aIter->Value();
323     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
324     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
325     if (!CORBA::is_nil(aVisuObj)) {
326       if (aVisuObj->GetType() == VISU::TCURVE) {
327         _PTR(SObject) aTableSO = aSObject->GetFather();
328         CurveStruct aEntry;
329         aEntry.TableName = getSObjectName(aTableSO);
330         aEntry.CurveName = getSObjectName(aSObject);
331         aEntry.CurveEntry = aSObject->GetID().c_str();
332         aStudyCurves.append(aEntry);
333       }
334     }
335   }
336   //Show Curves which are not in Curve
337   QValueList<CurveStruct>::iterator it;
338   QValueList<CurveStruct>::iterator it2;
339   bool isExist = false;
340   for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) {
341     for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) {
342       if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
343         break;
344     }
345     if (!isExist)
346       new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
347   }
348 }
349
350 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
351 {
352   theContainer->Clear();
353
354   _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
355   QListViewItem* anItem = myContainerLst->firstChild();
356   while (anItem) {
357     _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2).latin1());
358     if (aCurveSO) {
359       CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO);
360       if (!CORBA::is_nil(aObject)) {
361         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aObject).in());
362         if (aCurve) theContainer->AddCurve(aCurve->_this());
363       }
364     }
365     anItem = anItem->nextSibling();
366   }
367 }
368
369 QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
370 {
371   if (!theSObject) return QString("");
372
373   _PTR(GenericAttribute) anAttr;
374   if (theSObject->FindAttribute(anAttr, "AttributeName")) {
375     _PTR(AttributeName) aName (anAttr);
376     return QString(aName->Value().c_str());
377   }
378   return QString("");
379 }
380
381 void VisuGUI_EditContainerDlg::onLeftClicked()
382 {
383   QListViewItem* anItem = myContainerLst->firstChild();
384   while (anItem) {
385     if (anItem->isSelected()) {
386       QListViewItem* anTmpItem = anItem;
387       anItem = anTmpItem->nextSibling();
388       myContainerLst->takeItem(anTmpItem);
389       myStudyLst->insertItem(anTmpItem);
390     } else {
391       anItem = anItem->nextSibling();
392     }
393   }
394 }
395
396 void VisuGUI_EditContainerDlg::onRightClicked()
397 {
398   QListViewItem* anItem = myStudyLst->firstChild();
399   while (anItem) {
400     if (anItem->isSelected()) {
401       QListViewItem* anTmpItem = anItem;
402       anItem = anTmpItem->nextSibling();
403       myStudyLst->takeItem(anTmpItem);
404       myContainerLst->insertItem(anTmpItem);
405     } else {
406       anItem = anItem->nextSibling();
407     }
408   }
409 }
410
411 void VisuGUI_EditContainerDlg::onLeftSelected()
412 {
413   QListViewItem* anItem = myStudyLst->firstChild();
414   bool isSelected = false;
415   while (anItem) {
416     if (anItem->isSelected()) {
417       isSelected = true;
418       break;
419     }
420     anItem = anItem->nextSibling();
421   }
422   myRightBtn->setEnabled(isSelected);
423 }
424
425 void VisuGUI_EditContainerDlg::onRightSelected()
426 {
427   QListViewItem* anItem = myContainerLst->firstChild();
428   bool isSelected = false;
429   while (anItem) {
430     if (anItem->isSelected()) {
431       isSelected = true;
432       break;
433     }
434     anItem = anItem->nextSibling();
435   }
436   myLeftBtn->setEnabled(isSelected);
437 }
438
439 void VisuGUI_EditContainerDlg::onHelp()
440 {
441   QString aHelpFileName = "/files/creating_xy_plot.htm";
442   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
443   if (app)
444     app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
445   else {
446     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
447                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
448                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
449                            QObject::tr("BUT_OK"));
450   }
451 }