Salome HOME
SMH: 3.0.0 preparation - merged and adopted version (POLYWORK+HEAD)
[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 #include "VisuGUI.h"
14 #include "VISU_Table_i.hh"
15
16 #include "SalomeApp_Application.h"
17 #include "SUIT_Desktop.h"
18
19 #include <qlayout.h>
20 #include <qcheckbox.h>
21 #include <qgroupbox.h>
22 #include <qpushbutton.h>
23 #include <qlabel.h>
24
25 #include CORBA_SERVER_HEADER(VISU_Gen)
26 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
27
28 //extern VisuGUI *visuGUI;
29
30 using namespace std;
31
32
33 /* XPM */
34 static const char * left_xpm[] = {
35 "24 24 61 1",
36 "       c None",
37 ".      c #323232",
38 "+      c #010101",
39 "@      c #4A4A4A",
40 "#      c #040404",
41 "$      c #979797",
42 "%      c #7B7B7B",
43 "&      c #939393",
44 "*      c #EEEEEE",
45 "=      c #686868",
46 "-      c #030303",
47 ";      c #9C9C9C",
48 ">      c #FFFFFF",
49 ",      c #B1B1B1",
50 "'      c #5E5E5E",
51 ")      c #060606",
52 "!      c #C1C1C1",
53 "~      c #626262",
54 "{      c #000000",
55 "]      c #989898",
56 "^      c #A1A1A1",
57 "/      c #A5A5A5",
58 "(      c #909090",
59 "_      c #868686",
60 ":      c #616161",
61 "<      c #959595",
62 "[      c #919191",
63 "}      c #848484",
64 "|      c #606060",
65 "1      c #0B0B0B",
66 "2      c #545454",
67 "3      c #727272",
68 "4      c #A2A2A2",
69 "5      c #969696",
70 "6      c #838383",
71 "7      c #5F5F5F",
72 "8      c #101010",
73 "9      c #434343",
74 "0      c #6B6B6B",
75 "a      c #858585",
76 "b      c #8E8E8E",
77 "c      c #373737",
78 "d      c #696969",
79 "e      c #8D8D8D",
80 "f      c #B5B5B5",
81 "g      c #111111",
82 "h      c #393939",
83 "i      c #898989",
84 "j      c #B0B0B0",
85 "k      c #191919",
86 "l      c #3A3A3A",
87 "m      c #646464",
88 "n      c #535353",
89 "o      c #050505",
90 "p      c #353535",
91 "q      c #585858",
92 "r      c #4C4C4C",
93 "s      c #0D0D0D",
94 "t      c #3E3E3E",
95 "u      c #020202",
96 "v      c #0A0A0A",
97 "                        ",
98 "                        ",
99 "         .+        .+   ",
100 "        .@#       .@#   ",
101 "       .$%#      .$%#   ",
102 "      .&*=-     .&*=-   ",
103 "     .;>,')    .;>,')   ",
104 "    .;>!;~{   .;>!;~{   ",
105 "   .]>!^&~{  .]>!^&~{   ",
106 "  ./>!/(_:{ ./>!/(_:{   ",
107 " .<*!^[}}|{.<*!^[}}|{   ",
108 " 123}45667{123}45667{   ",
109 "  890a45b7{ 890a45b7{   ",
110 "   8cdef5'{  8cdef5'{   ",
111 "    gh0ij7k   gh0ij7k   ",
112 "     8lm0no    8lm0no   ",
113 "      8pqr-     8pqr-   ",
114 "       sht-      sht-   ",
115 "        1.u       1.u   ",
116 "         v{        v{   ",
117 "                        ",
118 "                        ",
119 "                        ",
120 "                        "};
121
122 static QPixmap MYLeftPix(left_xpm);
123
124
125 static const char * right_xpm[] = {
126 "24 24 43 1",
127 "       g None",
128 ".      g #323232",
129 "+      g #5D5D5D",
130 "@      g #000000",
131 "#      g #C4C4C4",
132 "$      g #313131",
133 "%      g #C5C5C5",
134 "&      g #E4E4E4",
135 "*      g #2D2D2D",
136 "=      g #B7B7B7",
137 "-      g #EFEFEF",
138 ";      g #DCDCDC",
139 ">      g #282828",
140 ",      g #AFAFAF",
141 "'      g #E0E0E0",
142 ")      g #242424",
143 "!      g #C7C7C7",
144 "~      g #9A9A9A",
145 "{      g #8E8E8E",
146 "]      g #1F1F1F",
147 "^      g #A5A5A5",
148 "/      g #989898",
149 "(      g #888888",
150 "_      g #1B1B1B",
151 ":      g #ADADAD",
152 "<      g #858585",
153 "[      g #838383",
154 "}      g #868686",
155 "|      g #929292",
156 "1      g #C1C1C1",
157 "2      g #161616",
158 "3      g #909090",
159 "4      g #747474",
160 "5      g #3A3A3A",
161 "6      g #121212",
162 "7      g #0D0D0D",
163 "8      g #7A7A7A",
164 "9      g #8A8A8A",
165 "0      g #090909",
166 "a      g #040404",
167 "b      g #707070",
168 "c      g #6E6E6E",
169 "d      g #3F3F3F",
170 "                        ",
171 "                        ",
172 " ..        ..           ",
173 " .+@       .+@          ",
174 " .#+@      .#+@         ",
175 " $%&+@     $%&+@        ",
176 " *=-;+@    *=-;+@       ",
177 " >,'=;+@   >,'=;+@      ",
178 " ),!~{;+@  ),!~{;+@     ",
179 " ]^!/({;+@ ]^!/({;+@    ",
180 " _~:<[}|1+@_~:<[}|1+@   ",
181 " 23~[[{:45@23~[[{:45@   ",
182 " 6</[{:45@ 6</[{:45@    ",
183 " 789{:45@  789{:45@     ",
184 " 08~:45@   08~:45@      ",
185 " a4~45@    a4~45@       ",
186 " @b45@     @b45@        ",
187 " @c5@      @c5@         ",
188 " @d@       @d@          ",
189 " @@        @@           ",
190 "                        ",
191 "                        ",
192 "                        ",
193 "                        "};
194
195 static QPixmap MYRightPix(right_xpm);
196
197
198 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (QWidget* parent, bool theIsModal)
199      : QDialog(parent, "VisuGUI_EditContainerDlg", theIsModal, WStyle_Customize |
200                WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
201 {
202   if (!theIsModal) {
203     setWFlags(getWFlags() | WDestructiveClose);
204   }
205   setCaption("Edit Plot 2D Presentation");
206   setSizeGripEnabled(true);
207
208   QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
209
210   /***************************************************************/
211   QFrame* aControlFrame = new QFrame (this);
212   aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
213
214   QGridLayout* aControlLay = new QGridLayout (aControlFrame);
215   aControlLay->setSpacing(6);
216   aControlLay->setMargin(11);
217   aControlLay->addRowSpacing(1, 30);
218   aControlLay->addRowSpacing(4, 30);
219   aControlLay->setRowStretch(1, 1);
220   aControlLay->setRowStretch(4, 1);
221   aControlLay->addColSpacing(0, 180);
222   aControlLay->addColSpacing(2, 180);
223
224   QLabel* aSelectLbl = new QLabel (tr("Study"), aControlFrame);
225   aControlLay->addWidget(aSelectLbl, 0, 0);
226
227   myStudyLst = new QListView (aControlFrame);
228   myStudyLst->setSelectionMode(QListView::Extended);
229   myStudyLst->addColumn(tr("Table"), 80);
230   myStudyLst->addColumn(tr("Curve"), 50);
231   myStudyLst->addColumn(tr(""), 0);
232   myStudyLst->setAllColumnsShowFocus(true);
233   myStudyLst->setMinimumHeight(130);
234   connect(myStudyLst, SIGNAL(selectionChanged()), this, SLOT(onLeftSelected()));
235   aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0);
236
237   myRightBtn = new QToolButton (aControlFrame);
238   myRightBtn->setIconSet(MYRightPix);
239   myRightBtn->setEnabled(false);
240   connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked()));
241   aControlLay->addWidget(myRightBtn, 2, 1);
242
243   myLeftBtn = new QToolButton(aControlFrame);
244   myLeftBtn->setIconSet(MYLeftPix);
245   myLeftBtn->setEnabled(false);
246   connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked()));
247   aControlLay->addWidget(myLeftBtn, 3, 1);
248
249   QLabel* aForceLbl = new QLabel(tr("Container"), aControlFrame);
250   aControlLay->addWidget(aForceLbl, 0, 2);
251
252   myContainerLst = new QListView(aControlFrame);
253   myContainerLst->setSelectionMode(QListView::Extended);
254   myContainerLst->addColumn(tr("Table"), 80);
255   myContainerLst->addColumn(tr("Curve"), 50);
256   myContainerLst->addColumn(tr(""), 0);
257   myContainerLst->setMinimumWidth(130);
258   connect(myContainerLst, SIGNAL(selectionChanged()), this, SLOT(onRightSelected()));
259   aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2);
260
261   TopLayout->addWidget(aControlFrame);
262
263   // Common buttons ===========================================================
264   QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
265   GroupButtons->setColumnLayout(0, Qt::Vertical);
266   GroupButtons->layout()->setSpacing(0);
267   GroupButtons->layout()->setMargin(0);
268   QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
269   GroupButtonsLayout->setAlignment(Qt::AlignTop);
270   GroupButtonsLayout->setSpacing(6);
271   GroupButtonsLayout->setMargin(11);
272
273   QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
274   buttonOk->setAutoDefault(TRUE);
275   buttonOk->setDefault(TRUE);
276   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
277   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, 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   SALOMEDS::Study_var aStudy = theContainer->GetStudyDocument();
292   SALOMEDS::SComponent_var aVisuSO = aStudy->FindComponent("VISU");
293   if (CORBA::is_nil(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     SALOMEDS::SObject_var aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
306     if (CORBA::is_nil(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   SALOMEDS::ChildIterator_var aIter = aStudy->NewChildIterator(aVisuSO);
313   for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
314     SALOMEDS::SObject_var aSObject = aIter->Value();
315     CORBA::Object_var anObject = VISU::SObjectToObject(aSObject);
316     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
317     if (!CORBA::is_nil(aVisuObj)) {
318       if (aVisuObj->GetType() == VISU::TCURVE) {
319         SALOMEDS::SObject_var aTableSO = aSObject->GetFather();
320         CurveStruct aEntry;
321         aEntry.TableName = getSObjectName(aTableSO);
322         aEntry.CurveName = getSObjectName(aSObject);
323         aEntry.CurveEntry = aSObject->GetID();
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::initFromPrsObject (VISU::Container_i* theContainer)
343 {
344   _PTR(Study) aStudy = theContainer->GetStudyDocument();
345   _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
346   if (!aVisuSO) {
347     return;
348   }
349   QValueList<CurveStruct> aStudyCurves;
350   QValueList<CurveStruct> aContainerCurves;
351   // Find curves in container
352   for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
353     VISU::Curve_i* aCurve = theContainer->GetCurve(i);
354     if (aCurve == NULL) continue;
355     CurveStruct aEntry;
356     aEntry.CurveName = aCurve->GetTitle();
357     aEntry.CurveEntry = aCurve->GetEntry();
358     _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
359     if (!aTableSO) continue;
360     aEntry.TableName = getSObjectName(aTableSO);
361     aContainerCurves.append(aEntry);
362     new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry);
363   }
364   // Find curves in study
365   _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO);
366   for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
367     _PTR(SObject) aSObject = aIter->Value();
368     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
369     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
370     if (!CORBA::is_nil(aVisuObj)) {
371       if (aVisuObj->GetType() == VISU::TCURVE) {
372         _PTR(SObject) aTableSO = aSObject->GetFather();
373         CurveStruct aEntry;
374         aEntry.TableName = getSObjectName(aTableSO);
375         aEntry.CurveName = getSObjectName(aSObject);
376         aEntry.CurveEntry = aSObject->GetID();
377         aStudyCurves.append(aEntry);
378       }
379     }
380   }
381   //Show Curves which are not in Curve
382   QValueList<CurveStruct>::iterator it;
383   QValueList<CurveStruct>::iterator it2;
384   bool isExist = false;
385   for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) {
386     for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) {
387       if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
388         break;
389     }
390     if (!isExist)
391       new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
392   }
393 }*/
394
395 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
396 {
397   theContainer->Clear();
398
399   SALOMEDS::Study_var aStudy = theContainer->GetStudyDocument();
400   QListViewItem* anItem = myContainerLst->firstChild();
401   while (anItem) {
402     SALOMEDS::SObject_var aCurveSO = aStudy->FindObjectID(anItem->text(2));
403     if (!CORBA::is_nil(aCurveSO)) {
404       CORBA::Object_var aObject = VISU::SObjectToObject(aCurveSO);
405       if (!CORBA::is_nil(aObject)) {
406         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aObject).in());
407         if (aCurve) theContainer->AddCurve(aCurve->_this());
408       }
409     }
410     anItem = anItem->nextSibling();
411   }
412 }
413
414 /*void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
415 {
416   theContainer->Clear();
417
418   _PTR(Study) aStudy = theContainer->GetStudyDocument();
419   QListViewItem* anItem = myContainerLst->firstChild();
420   while (anItem) {
421     _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2));
422     if (aCurveSO) {
423       CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO);
424       if (!CORBA::is_nil(aObject)) {
425         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aObject).in());
426         if (aCurve) theContainer->AddCurve(aCurve->_this());
427       }
428     }
429     anItem = anItem->nextSibling();
430   }
431 }*/
432
433 QString VisuGUI_EditContainerDlg::getSObjectName (SALOMEDS::SObject_ptr theSObject)
434 {
435   if (CORBA::is_nil(theSObject)) return QString("");
436
437   SALOMEDS::GenericAttribute_var anAttr;
438   SALOMEDS::AttributeName_var    aName;
439   if (theSObject->FindAttribute(anAttr, "AttributeName")) {
440     aName = SALOMEDS::AttributeName::_narrow(anAttr);
441     return QString(aName->Value());
442   }
443   return QString("");
444 }
445
446 /*QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
447 {
448   if (!theSObject) return QString("");
449
450   _PTR(GenericAttribute) anAttr;
451   if (theSObject->FindAttribute(anAttr, "AttributeName")) {
452     _PTR(AttributeName) aName (anAttr);
453     return QString(aName->Value());
454   }
455   return QString("");
456 }*/
457
458 void VisuGUI_EditContainerDlg::onLeftClicked()
459 {
460   QListViewItem* anItem = myContainerLst->firstChild();
461   while (anItem) {
462     if (anItem->isSelected()) {
463       QListViewItem* anTmpItem = anItem;
464       anItem = anTmpItem->nextSibling();
465       myContainerLst->takeItem(anTmpItem);
466       myStudyLst->insertItem(anTmpItem);
467     } else {
468       anItem = anItem->nextSibling();
469     }
470   }
471 }
472
473 void VisuGUI_EditContainerDlg::onRightClicked()
474 {
475   QListViewItem* anItem = myStudyLst->firstChild();
476   while (anItem) {
477     if (anItem->isSelected()) {
478       QListViewItem* anTmpItem = anItem;
479       anItem = anTmpItem->nextSibling();
480       myStudyLst->takeItem(anTmpItem);
481       myContainerLst->insertItem(anTmpItem);
482     } else {
483       anItem = anItem->nextSibling();
484     }
485   }
486 }
487
488 void VisuGUI_EditContainerDlg::onLeftSelected()
489 {
490   QListViewItem* anItem = myStudyLst->firstChild();
491   bool isSelected = false;
492   while (anItem) {
493     if (anItem->isSelected()) {
494       isSelected = true;
495       break;
496     }
497     anItem = anItem->nextSibling();
498   }
499   myRightBtn->setEnabled(isSelected);
500 }
501
502 void VisuGUI_EditContainerDlg::onRightSelected()
503 {
504   QListViewItem* anItem = myContainerLst->firstChild();
505   bool isSelected = false;
506   while (anItem) {
507     if (anItem->isSelected()) {
508       isSelected = true;
509       break;
510     }
511     anItem = anItem->nextSibling();
512   }
513   myLeftBtn->setEnabled(isSelected);
514 }