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