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"
14 #include "VISU_Table_i.hh"
16 #include "SalomeApp_Application.h"
17 #include "SUIT_Desktop.h"
20 #include <qcheckbox.h>
21 #include <qgroupbox.h>
22 #include <qpushbutton.h>
25 #include CORBA_SERVER_HEADER(VISU_Gen)
26 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
28 //extern VisuGUI *visuGUI;
34 static const char * left_xpm[] = {
105 " .]>!^&~{ .]>!^&~{ ",
106 " ./>!/(_:{ ./>!/(_:{ ",
107 " .<*!^[}}|{.<*!^[}}|{ ",
108 " 123}45667{123}45667{ ",
109 " 890a45b7{ 890a45b7{ ",
110 " 8cdef5'{ 8cdef5'{ ",
122 static QPixmap MYLeftPix(left_xpm);
125 static const char * right_xpm[] = {
178 " ),!~{;+@ ),!~{;+@ ",
179 " ]^!/({;+@ ]^!/({;+@ ",
180 " _~:<[}|1+@_~:<[}|1+@ ",
181 " 23~[[{:45@23~[[{:45@ ",
182 " 6</[{:45@ 6</[{:45@ ",
183 " 789{:45@ 789{:45@ ",
195 static QPixmap MYRightPix(right_xpm);
198 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (QWidget* parent, bool theIsModal)
199 : QDialog(parent, "VisuGUI_EditContainerDlg", theIsModal, WStyle_Customize |
200 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
203 setWFlags(getWFlags() | WDestructiveClose);
205 setCaption("Edit Plot 2D Presentation");
206 setSizeGripEnabled(true);
208 QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
210 /***************************************************************/
211 QFrame* aControlFrame = new QFrame (this);
212 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
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);
224 QLabel* aSelectLbl = new QLabel (tr("Study"), aControlFrame);
225 aControlLay->addWidget(aSelectLbl, 0, 0);
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);
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);
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);
249 QLabel* aForceLbl = new QLabel(tr("Container"), aControlFrame);
250 aControlLay->addWidget(aForceLbl, 0, 2);
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);
261 TopLayout->addWidget(aControlFrame);
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);
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);
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 SALOMEDS::Study_var aStudy = theContainer->GetStudyDocument();
292 SALOMEDS::SComponent_var aVisuSO = aStudy->FindComponent("VISU");
293 if (CORBA::is_nil(aVisuSO)) {
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 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);
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();
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::initFromPrsObject (VISU::Container_i* theContainer)
344 _PTR(Study) aStudy = theContainer->GetStudyDocument();
345 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
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;
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);
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();
374 aEntry.TableName = getSObjectName(aTableSO);
375 aEntry.CurveName = getSObjectName(aSObject);
376 aEntry.CurveEntry = aSObject->GetID();
377 aStudyCurves.append(aEntry);
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))
391 new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
395 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
397 theContainer->Clear();
399 SALOMEDS::Study_var aStudy = theContainer->GetStudyDocument();
400 QListViewItem* anItem = myContainerLst->firstChild();
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());
410 anItem = anItem->nextSibling();
414 /*void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
416 theContainer->Clear();
418 _PTR(Study) aStudy = theContainer->GetStudyDocument();
419 QListViewItem* anItem = myContainerLst->firstChild();
421 _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2));
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());
429 anItem = anItem->nextSibling();
433 QString VisuGUI_EditContainerDlg::getSObjectName (SALOMEDS::SObject_ptr theSObject)
435 if (CORBA::is_nil(theSObject)) return QString("");
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());
446 /*QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
448 if (!theSObject) return QString("");
450 _PTR(GenericAttribute) anAttr;
451 if (theSObject->FindAttribute(anAttr, "AttributeName")) {
452 _PTR(AttributeName) aName (anAttr);
453 return QString(aName->Value());
458 void VisuGUI_EditContainerDlg::onLeftClicked()
460 QListViewItem* anItem = myContainerLst->firstChild();
462 if (anItem->isSelected()) {
463 QListViewItem* anTmpItem = anItem;
464 anItem = anTmpItem->nextSibling();
465 myContainerLst->takeItem(anTmpItem);
466 myStudyLst->insertItem(anTmpItem);
468 anItem = anItem->nextSibling();
473 void VisuGUI_EditContainerDlg::onRightClicked()
475 QListViewItem* anItem = myStudyLst->firstChild();
477 if (anItem->isSelected()) {
478 QListViewItem* anTmpItem = anItem;
479 anItem = anTmpItem->nextSibling();
480 myStudyLst->takeItem(anTmpItem);
481 myContainerLst->insertItem(anTmpItem);
483 anItem = anItem->nextSibling();
488 void VisuGUI_EditContainerDlg::onLeftSelected()
490 QListViewItem* anItem = myStudyLst->firstChild();
491 bool isSelected = false;
493 if (anItem->isSelected()) {
497 anItem = anItem->nextSibling();
499 myRightBtn->setEnabled(isSelected);
502 void VisuGUI_EditContainerDlg::onRightSelected()
504 QListViewItem* anItem = myContainerLst->firstChild();
505 bool isSelected = false;
507 if (anItem->isSelected()) {
511 anItem = anItem->nextSibling();
513 myLeftBtn->setEnabled(isSelected);