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"
23 #include <qcheckbox.h>
24 #include <qgroupbox.h>
25 #include <qpushbutton.h>
32 static const char * left_xpm[] = {
103 " .]>!^&~{ .]>!^&~{ ",
104 " ./>!/(_:{ ./>!/(_:{ ",
105 " .<*!^[}}|{.<*!^[}}|{ ",
106 " 123}45667{123}45667{ ",
107 " 890a45b7{ 890a45b7{ ",
108 " 8cdef5'{ 8cdef5'{ ",
120 static QPixmap MYLeftPix(left_xpm);
123 static const char * right_xpm[] = {
176 " ),!~{;+@ ),!~{;+@ ",
177 " ]^!/({;+@ ]^!/({;+@ ",
178 " _~:<[}|1+@_~:<[}|1+@ ",
179 " 23~[[{:45@23~[[{:45@ ",
180 " 6</[{:45@ 6</[{:45@ ",
181 " 789{:45@ 789{:45@ ",
193 static QPixmap MYRightPix(right_xpm);
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),
202 setWFlags(getWFlags() | WDestructiveClose);
204 setCaption("Edit Plot 2D Presentation");
205 setSizeGripEnabled(true);
207 QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
209 /***************************************************************/
210 QFrame* aControlFrame = new QFrame (this);
211 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
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);
223 QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
224 aControlLay->addWidget(aSelectLbl, 0, 0);
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);
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);
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);
248 QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
249 aControlLay->addWidget(aForceLbl, 0, 2);
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);
260 TopLayout->addWidget(aControlFrame);
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);
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);
279 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
280 buttonCancel->setAutoDefault(TRUE);
281 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
283 TopLayout->addWidget(GroupButtons);
285 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
286 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
289 void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
291 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
292 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
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;
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);
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();
321 aEntry.TableName = getSObjectName(aTableSO);
322 aEntry.CurveName = getSObjectName(aSObject);
323 aEntry.CurveEntry = aSObject->GetID();
324 aStudyCurves.append(aEntry);
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))
338 new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
342 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
344 theContainer->Clear();
346 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
347 QListViewItem* anItem = myContainerLst->firstChild();
349 _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2));
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());
357 anItem = anItem->nextSibling();
361 QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
363 if (!theSObject) return QString("");
365 _PTR(GenericAttribute) anAttr;
366 if (theSObject->FindAttribute(anAttr, "AttributeName")) {
367 _PTR(AttributeName) aName (anAttr);
368 return QString(aName->Value());
373 void VisuGUI_EditContainerDlg::onLeftClicked()
375 QListViewItem* anItem = myContainerLst->firstChild();
377 if (anItem->isSelected()) {
378 QListViewItem* anTmpItem = anItem;
379 anItem = anTmpItem->nextSibling();
380 myContainerLst->takeItem(anTmpItem);
381 myStudyLst->insertItem(anTmpItem);
383 anItem = anItem->nextSibling();
388 void VisuGUI_EditContainerDlg::onRightClicked()
390 QListViewItem* anItem = myStudyLst->firstChild();
392 if (anItem->isSelected()) {
393 QListViewItem* anTmpItem = anItem;
394 anItem = anTmpItem->nextSibling();
395 myStudyLst->takeItem(anTmpItem);
396 myContainerLst->insertItem(anTmpItem);
398 anItem = anItem->nextSibling();
403 void VisuGUI_EditContainerDlg::onLeftSelected()
405 QListViewItem* anItem = myStudyLst->firstChild();
406 bool isSelected = false;
408 if (anItem->isSelected()) {
412 anItem = anItem->nextSibling();
414 myRightBtn->setEnabled(isSelected);
417 void VisuGUI_EditContainerDlg::onRightSelected()
419 QListViewItem* anItem = myContainerLst->firstChild();
420 bool isSelected = false;
422 if (anItem->isSelected()) {
426 anItem = anItem->nextSibling();
428 myLeftBtn->setEnabled(isSelected);