1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VisuGUI_EditContainerDlg.cxx
12 #include "VisuGUI_EditContainerDlg.h"
15 #include "VisuGUI_Tools.h"
17 #include "VISU_Table_i.hh"
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"
26 #include <qcheckbox.h>
27 #include <qgroupbox.h>
28 #include <qpushbutton.h>
35 static const char * left_xpm[] = {
106 " .]>!^&~{ .]>!^&~{ ",
107 " ./>!/(_:{ ./>!/(_:{ ",
108 " .<*!^[}}|{.<*!^[}}|{ ",
109 " 123}45667{123}45667{ ",
110 " 890a45b7{ 890a45b7{ ",
111 " 8cdef5'{ 8cdef5'{ ",
123 static QPixmap MYLeftPix(left_xpm);
126 static const char * right_xpm[] = {
179 " ),!~{;+@ ),!~{;+@ ",
180 " ]^!/({;+@ ]^!/({;+@ ",
181 " _~:<[}|1+@_~:<[}|1+@ ",
182 " 23~[[{:45@23~[[{:45@ ",
183 " 6</[{:45@ 6</[{:45@ ",
184 " 789{:45@ 789{:45@ ",
196 static QPixmap MYRightPix(right_xpm);
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),
205 setWFlags(getWFlags() | WDestructiveClose);
207 setCaption("Edit Plot 2D Presentation");
208 setSizeGripEnabled(true);
210 QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
212 /***************************************************************/
213 QFrame* aControlFrame = new QFrame (this);
214 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
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);
226 QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
227 aControlLay->addWidget(aSelectLbl, 0, 0);
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);
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);
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);
251 QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
252 aControlLay->addWidget(aForceLbl, 0, 2);
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);
263 TopLayout->addWidget(aControlFrame);
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);
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);
282 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
283 buttonCancel->setAutoDefault(TRUE);
284 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
286 QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp");
287 buttonHelp->setAutoDefault(TRUE);
288 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
290 TopLayout->addWidget(GroupButtons);
292 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
293 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
294 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
297 void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
299 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
300 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
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;
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);
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();
329 aEntry.TableName = getSObjectName(aTableSO);
330 aEntry.CurveName = getSObjectName(aSObject);
331 aEntry.CurveEntry = aSObject->GetID().c_str();
332 aStudyCurves.append(aEntry);
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))
346 new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
350 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
352 theContainer->Clear();
354 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
355 QListViewItem* anItem = myContainerLst->firstChild();
357 _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2).latin1());
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());
365 anItem = anItem->nextSibling();
369 QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
371 if (!theSObject) return QString("");
373 _PTR(GenericAttribute) anAttr;
374 if (theSObject->FindAttribute(anAttr, "AttributeName")) {
375 _PTR(AttributeName) aName (anAttr);
376 return QString(aName->Value().c_str());
381 void VisuGUI_EditContainerDlg::onLeftClicked()
383 QListViewItem* anItem = myContainerLst->firstChild();
385 if (anItem->isSelected()) {
386 QListViewItem* anTmpItem = anItem;
387 anItem = anTmpItem->nextSibling();
388 myContainerLst->takeItem(anTmpItem);
389 myStudyLst->insertItem(anTmpItem);
391 anItem = anItem->nextSibling();
396 void VisuGUI_EditContainerDlg::onRightClicked()
398 QListViewItem* anItem = myStudyLst->firstChild();
400 if (anItem->isSelected()) {
401 QListViewItem* anTmpItem = anItem;
402 anItem = anTmpItem->nextSibling();
403 myStudyLst->takeItem(anTmpItem);
404 myContainerLst->insertItem(anTmpItem);
406 anItem = anItem->nextSibling();
411 void VisuGUI_EditContainerDlg::onLeftSelected()
413 QListViewItem* anItem = myStudyLst->firstChild();
414 bool isSelected = false;
416 if (anItem->isSelected()) {
420 anItem = anItem->nextSibling();
422 myRightBtn->setEnabled(isSelected);
425 void VisuGUI_EditContainerDlg::onRightSelected()
427 QListViewItem* anItem = myContainerLst->firstChild();
428 bool isSelected = false;
430 if (anItem->isSelected()) {
434 anItem = anItem->nextSibling();
436 myLeftBtn->setEnabled(isSelected);
439 void VisuGUI_EditContainerDlg::onHelp()
441 QString aHelpFileName = "/files/creating_xy_plot.htm";
442 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
444 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
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"));