Salome HOME
Fix of issue 0020593: EDF 885 VISU: Unchecking Filter by Scalar does not remove white...
[modules/visu.git] / src / VISUGUI / VisuGUI_EditContainerDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : VisuGUI_EditContainerDlg.cxx
23 //  Author : VSV
24 //  Module : VISU
25 //
26 #include "VisuGUI_EditContainerDlg.h"
27
28 #include "VisuGUI.h"
29 #include "VisuGUI_Tools.h"
30
31 #include "VISU_Table_i.hh"
32
33 #include "SalomeApp_Application.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_MessageBox.h"
37 #include "SUIT_ResourceMgr.h"
38
39 #include <QLayout>
40 #include <QCheckBox>
41 #include <QGroupBox>
42 #include <QPushButton>
43 #include <QLabel>
44 #include <QTreeWidget>
45 #include <QToolButton>
46 #include <QKeyEvent>
47
48
49 using namespace std;
50
51
52 /* XPM */
53 static const char * left_xpm[] = {
54 "24 24 61 1",
55 "       c None",
56 ".      c #323232",
57 "+      c #010101",
58 "@      c #4A4A4A",
59 "#      c #040404",
60 "$      c #979797",
61 "%      c #7B7B7B",
62 "&      c #939393",
63 "*      c #EEEEEE",
64 "=      c #686868",
65 "-      c #030303",
66 ";      c #9C9C9C",
67 ">      c #FFFFFF",
68 ",      c #B1B1B1",
69 "'      c #5E5E5E",
70 ")      c #060606",
71 "!      c #C1C1C1",
72 "~      c #626262",
73 "{      c #000000",
74 "]      c #989898",
75 "^      c #A1A1A1",
76 "/      c #A5A5A5",
77 "(      c #909090",
78 "_      c #868686",
79 ":      c #616161",
80 "<      c #959595",
81 "[      c #919191",
82 "}      c #848484",
83 "|      c #606060",
84 "1      c #0B0B0B",
85 "2      c #545454",
86 "3      c #727272",
87 "4      c #A2A2A2",
88 "5      c #969696",
89 "6      c #838383",
90 "7      c #5F5F5F",
91 "8      c #101010",
92 "9      c #434343",
93 "0      c #6B6B6B",
94 "a      c #858585",
95 "b      c #8E8E8E",
96 "c      c #373737",
97 "d      c #696969",
98 "e      c #8D8D8D",
99 "f      c #B5B5B5",
100 "g      c #111111",
101 "h      c #393939",
102 "i      c #898989",
103 "j      c #B0B0B0",
104 "k      c #191919",
105 "l      c #3A3A3A",
106 "m      c #646464",
107 "n      c #535353",
108 "o      c #050505",
109 "p      c #353535",
110 "q      c #585858",
111 "r      c #4C4C4C",
112 "s      c #0D0D0D",
113 "t      c #3E3E3E",
114 "u      c #020202",
115 "v      c #0A0A0A",
116 "                        ",
117 "                        ",
118 "         .+        .+   ",
119 "        .@#       .@#   ",
120 "       .$%#      .$%#   ",
121 "      .&*=-     .&*=-   ",
122 "     .;>,')    .;>,')   ",
123 "    .;>!;~{   .;>!;~{   ",
124 "   .]>!^&~{  .]>!^&~{   ",
125 "  ./>!/(_:{ ./>!/(_:{   ",
126 " .<*!^[}}|{.<*!^[}}|{   ",
127 " 123}45667{123}45667{   ",
128 "  890a45b7{ 890a45b7{   ",
129 "   8cdef5'{  8cdef5'{   ",
130 "    gh0ij7k   gh0ij7k   ",
131 "     8lm0no    8lm0no   ",
132 "      8pqr-     8pqr-   ",
133 "       sht-      sht-   ",
134 "        1.u       1.u   ",
135 "         v{        v{   ",
136 "                        ",
137 "                        ",
138 "                        ",
139 "                        "};
140
141 static QPixmap MYLeftPix(left_xpm);
142
143
144 static const char * right_xpm[] = {
145 "24 24 43 1",
146 "       g None",
147 ".      g #323232",
148 "+      g #5D5D5D",
149 "@      g #000000",
150 "#      g #C4C4C4",
151 "$      g #313131",
152 "%      g #C5C5C5",
153 "&      g #E4E4E4",
154 "*      g #2D2D2D",
155 "=      g #B7B7B7",
156 "-      g #EFEFEF",
157 ";      g #DCDCDC",
158 ">      g #282828",
159 ",      g #AFAFAF",
160 "'      g #E0E0E0",
161 ")      g #242424",
162 "!      g #C7C7C7",
163 "~      g #9A9A9A",
164 "{      g #8E8E8E",
165 "]      g #1F1F1F",
166 "^      g #A5A5A5",
167 "/      g #989898",
168 "(      g #888888",
169 "_      g #1B1B1B",
170 ":      g #ADADAD",
171 "<      g #858585",
172 "[      g #838383",
173 "}      g #868686",
174 "|      g #929292",
175 "1      g #C1C1C1",
176 "2      g #161616",
177 "3      g #909090",
178 "4      g #747474",
179 "5      g #3A3A3A",
180 "6      g #121212",
181 "7      g #0D0D0D",
182 "8      g #7A7A7A",
183 "9      g #8A8A8A",
184 "0      g #090909",
185 "a      g #040404",
186 "b      g #707070",
187 "c      g #6E6E6E",
188 "d      g #3F3F3F",
189 "                        ",
190 "                        ",
191 " ..        ..           ",
192 " .+@       .+@          ",
193 " .#+@      .#+@         ",
194 " $%&+@     $%&+@        ",
195 " *=-;+@    *=-;+@       ",
196 " >,'=;+@   >,'=;+@      ",
197 " ),!~{;+@  ),!~{;+@     ",
198 " ]^!/({;+@ ]^!/({;+@    ",
199 " _~:<[}|1+@_~:<[}|1+@   ",
200 " 23~[[{:45@23~[[{:45@   ",
201 " 6</[{:45@ 6</[{:45@    ",
202 " 789{:45@  789{:45@     ",
203 " 08~:45@   08~:45@      ",
204 " a4~45@    a4~45@       ",
205 " @b45@     @b45@        ",
206 " @c5@      @c5@         ",
207 " @d@       @d@          ",
208 " @@        @@           ",
209 "                        ",
210 "                        ",
211 "                        ",
212 "                        "};
213
214 static QPixmap MYRightPix(right_xpm);
215
216
217 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal)
218      : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
219        myVisuGUI(theModule)
220 {
221   setModal( theIsModal );
222   if (!theIsModal) {
223     setAttribute( Qt::WA_DeleteOnClose, true );
224   }
225   setWindowTitle("Edit Plot 2D Presentation");
226   setSizeGripEnabled(true);
227
228   QVBoxLayout* TopLayout = new QVBoxLayout (this );
229   TopLayout->setMargin( 6 );
230   TopLayout->setSpacing( 11);
231
232   /***************************************************************/
233   QFrame* aControlFrame = new QFrame (this);
234   aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
235
236   QGridLayout* aControlLay = new QGridLayout (aControlFrame);
237   aControlLay->setSpacing(6);
238   aControlLay->setMargin(11);
239   //aControlLay->addRowSpacing(1, 30);
240   //aControlLay->addRowSpacing(4, 30);
241   aControlLay->setRowStretch(1, 1);
242   aControlLay->setRowStretch(4, 1);
243   //aControlLay->addColSpacing(0, 180);
244   //aControlLay->addColSpacing(2, 180);
245
246   QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
247   aControlLay->addWidget(aSelectLbl, 0, 0);
248
249   myStudyLst = new QTreeWidget (aControlFrame);
250   myStudyLst->setSelectionMode(QAbstractItemView::ExtendedSelection);
251   myStudyLst->setColumnCount( 3 );
252   QStringList aLabels;
253   aLabels.append( tr("TXT_TABLE") );
254   aLabels.append( tr("TXT_CURVE") );
255   aLabels.append( "" );
256   myStudyLst->setHeaderLabels( aLabels );
257   myStudyLst->setColumnWidth( 0, 80 );
258   myStudyLst->setColumnWidth( 1, 50 );
259   myStudyLst->setColumnWidth( 2, 0 );
260   
261   //myStudyLst->addColumn(tr("TXT_TABLE"), 80);
262   //myStudyLst->addColumn(tr("TXT_CURVE"), 50);
263   //myStudyLst->addColumn(tr(""), 0);
264   
265   myStudyLst->setAllColumnsShowFocus(true);
266   //myStudyLst->setMinimumHeight(130);
267   connect(myStudyLst, SIGNAL(itemSelectionChanged()), this, SLOT(onLeftSelected()));
268   aControlLay->addWidget(myStudyLst, 1, 0, 5, 1);
269
270   myRightBtn = new QToolButton (aControlFrame);
271   myRightBtn->setIcon(MYRightPix);
272   myRightBtn->setEnabled(false);
273   connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked()));
274   aControlLay->addWidget(myRightBtn, 2, 1);
275
276   myLeftBtn = new QToolButton(aControlFrame);
277   myLeftBtn->setIcon(MYLeftPix);
278   myLeftBtn->setEnabled(false);
279   connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked()));
280   aControlLay->addWidget(myLeftBtn, 3, 1);
281
282   QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
283   aControlLay->addWidget(aForceLbl, 0, 2);
284
285   myContainerLst = new QTreeWidget(aControlFrame);
286   myContainerLst->setSelectionMode(QAbstractItemView::ExtendedSelection);
287   //myContainerLst->addColumn(tr("TXT_TABLE"), 80);
288   //myContainerLst->addColumn(tr("TXT_CURVE"), 50);
289   //myContainerLst->addColumn(tr(""), 0);
290   myContainerLst->setColumnCount( 3 );
291   myContainerLst->setHeaderLabels( aLabels );
292   myContainerLst->setColumnWidth( 0, 80 );
293   myContainerLst->setColumnWidth( 1, 50 );
294   myContainerLst->setColumnWidth( 2, 0 );
295
296   
297   //myContainerLst->setMinimumWidth(130);
298   connect(myContainerLst, SIGNAL(itemSelectionChanged()), this, SLOT(onRightSelected()));
299   aControlLay->addWidget(myContainerLst, 1, 2, 5, 1);
300
301   TopLayout->addWidget(aControlFrame);
302
303   // Common buttons ===========================================================
304   QGroupBox* GroupButtons = new QGroupBox(this);
305   //GroupButtons->setColumnLayout(0, Qt::Vertical);
306   //GroupButtons->layout()->setSpacing(0);
307   //GroupButtons->layout()->setMargin(0);
308   QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
309   GroupButtonsLayout->setAlignment(Qt::AlignTop);
310   GroupButtonsLayout->setSpacing(6);
311   GroupButtonsLayout->setMargin(11);
312
313   QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons);
314   buttonOk->setAutoDefault(TRUE);
315   buttonOk->setDefault(TRUE);
316   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
317   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding,
318                                               QSizePolicy::Minimum), 0, 1);
319
320   QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons);
321   buttonCancel->setAutoDefault(TRUE);
322   GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
323
324   QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons);
325   buttonHelp->setAutoDefault(TRUE);
326   GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
327
328   TopLayout->addWidget(GroupButtons);
329
330   connect(buttonOk,     SIGNAL(clicked()),      this, SLOT(accept()));
331   connect(buttonCancel, SIGNAL(clicked()),      this, SLOT(reject()));
332   connect(buttonHelp,   SIGNAL(clicked()),      this, SLOT(onHelp()));
333 }
334
335 void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
336 {
337   _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
338   _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
339   if (!aVisuSO) {
340     return;
341   }
342   QList<CurveStruct> aStudyCurves;
343   QList<CurveStruct> aContainerCurves;
344   // Find curves in container
345   for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
346     VISU::Curve_i* aCurve = theContainer->GetCurve(i);
347     if (aCurve == NULL) continue;
348     CurveStruct aEntry;
349     aEntry.CurveName = aCurve->GetTitle();
350     aEntry.CurveEntry = aCurve->GetEntry().c_str();
351     _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
352     if (!aTableSO) continue;
353     aEntry.TableName = getSObjectName(aTableSO);
354     aContainerCurves.append(aEntry);
355     QStringList aList;
356     aList.append( aEntry.TableName );
357     aList.append( aEntry.CurveName );
358     aList.append( aEntry.CurveEntry );
359     new QTreeWidgetItem(myContainerLst, aList);
360   }
361   // Find curves in study
362   _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO);
363   for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
364     _PTR(SObject) aSObject = aIter->Value();
365     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
366     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
367     if (!CORBA::is_nil(aVisuObj)) {
368       if (aVisuObj->GetType() == VISU::TCURVE) {
369         _PTR(SObject) aTableSO = aSObject->GetFather();
370         CurveStruct aEntry;
371         aEntry.TableName = getSObjectName(aTableSO);
372         aEntry.CurveName = getSObjectName(aSObject);
373         aEntry.CurveEntry = aSObject->GetID().c_str();
374         aStudyCurves.append(aEntry);
375       }
376     }
377   }
378   //Show Curves which are not in Curve
379   QList<CurveStruct>::iterator it;
380   QList<CurveStruct>::iterator it2;
381   bool isExist = false;
382   for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) {
383     for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) {
384       if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
385         break;
386     }
387     if (!isExist)
388     {
389       QStringList aList;
390       aList.append( (*it).TableName );
391       aList.append( (*it).CurveName );
392       aList.append( (*it).CurveEntry );
393       new QTreeWidgetItem(myStudyLst, aList );
394     }
395   }
396 }
397
398 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
399 {
400   theContainer->Clear();
401
402   _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
403   QTreeWidgetItem* anItem;
404   for ( int i= 0; i< myContainerLst->topLevelItemCount(); i++  )
405   {
406     anItem = myContainerLst->topLevelItem( i );
407     if ( !anItem )
408       continue;
409     _PTR(SObject) aCurveSO = aStudy->FindObjectID((const char*)anItem->text(2).toLatin1());
410     if (aCurveSO) {
411       CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO);
412       if (!CORBA::is_nil(aObject)) {
413         VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aObject).in());
414         if (aCurve) theContainer->AddCurve(aCurve->_this());
415       }
416     }
417   }
418 }
419
420 QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
421 {
422   if (!theSObject) return QString("");
423
424   _PTR(GenericAttribute) anAttr;
425   if (theSObject->FindAttribute(anAttr, "AttributeName")) {
426     _PTR(AttributeName) aName (anAttr);
427     return QString(aName->Value().c_str());
428   }
429   return QString("");
430 }
431
432 void VisuGUI_EditContainerDlg::onLeftClicked()
433 {
434   /*QListViewItem* anItem = myContainerLst->firstChild();
435   while (anItem) {
436     if (anItem->isSelected()) {
437       QListViewItem* anTmpItem = anItem;
438       anItem = anTmpItem->nextSibling();
439       myContainerLst->takeItem(anTmpItem);
440       myStudyLst->insertItem(anTmpItem);
441     } else {
442       anItem = anItem->nextSibling();
443     }
444     }*/
445   QList<QTreeWidgetItem*> selItem = myContainerLst->selectedItems();
446   QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
447
448   QList<QTreeWidgetItem*> topSelectedItems;
449   for ( ; anIt != selItem.end(); anIt++  )
450   {
451     int index = myContainerLst->indexOfTopLevelItem( *anIt );
452     if ( index != -1 )
453       topSelectedItems.append( myContainerLst->takeTopLevelItem( index ) );
454   }
455
456   myStudyLst->addTopLevelItems(topSelectedItems);
457 }
458
459 void VisuGUI_EditContainerDlg::onRightClicked()
460 {
461   /*QListViewItem* anItem = myStudyLst->firstChild();
462   while (anItem) {
463     if (anItem->isSelected()) {
464       QListViewItem* anTmpItem = anItem;
465       anItem = anTmpItem->nextSibling();
466       myStudyLst->takeItem(anTmpItem);
467       myContainerLst->insertItem(anTmpItem);
468     } else {
469       anItem = anItem->nextSibling();
470     }
471     }*/
472   QList<QTreeWidgetItem*> selItem = myStudyLst->selectedItems();
473   QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
474
475   QList<QTreeWidgetItem*> topSelectedItems;
476   for ( ; anIt != selItem.end(); anIt++  )
477   {
478     int index = myStudyLst->indexOfTopLevelItem( *anIt );
479     if ( index != -1 )
480       topSelectedItems.append( myStudyLst->takeTopLevelItem( index ) );
481   }
482
483   myContainerLst->addTopLevelItems(topSelectedItems);
484 }
485
486 void VisuGUI_EditContainerDlg::onLeftSelected()
487 {
488   myRightBtn->setEnabled( myStudyLst->selectedItems().count() > 0 );
489 }
490
491 void VisuGUI_EditContainerDlg::onRightSelected()
492 {
493   myLeftBtn->setEnabled( myContainerLst->selectedItems().count() > 0 );
494 }
495
496 void VisuGUI_EditContainerDlg::onHelp()
497 {
498   QString aHelpFileName = "creating_xy_plot_page.html";
499   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
500   if (app)
501     app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
502   else {
503     QString platform;
504 #ifdef WIN32
505     platform = "winapplication";
506 #else
507     platform = "application";
508 #endif
509     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
510                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
511                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
512                              QObject::tr("BUT_OK"));
513   }
514 }
515
516 void VisuGUI_EditContainerDlg::keyPressEvent( QKeyEvent* e )
517 {
518   QDialog::keyPressEvent( e );
519   if ( e->isAccepted() )
520     return;
521
522   if ( e->key() == Qt::Key_F1 )
523     {
524       e->accept();
525       onHelp();
526     }
527 }