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