1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : VisuGUI_EditContainerDlg.cxx
26 #include "VisuGUI_EditContainerDlg.h"
29 #include "VisuGUI_Tools.h"
31 #include "VISU_Table_i.hh"
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"
42 #include <QPushButton>
44 #include <QTreeWidget>
45 #include <QToolButton>
53 static const char * left_xpm[] = {
124 " .]>!^&~{ .]>!^&~{ ",
125 " ./>!/(_:{ ./>!/(_:{ ",
126 " .<*!^[}}|{.<*!^[}}|{ ",
127 " 123}45667{123}45667{ ",
128 " 890a45b7{ 890a45b7{ ",
129 " 8cdef5'{ 8cdef5'{ ",
141 static QPixmap MYLeftPix(left_xpm);
144 static const char * right_xpm[] = {
197 " ),!~{;+@ ),!~{;+@ ",
198 " ]^!/({;+@ ]^!/({;+@ ",
199 " _~:<[}|1+@_~:<[}|1+@ ",
200 " 23~[[{:45@23~[[{:45@ ",
201 " 6</[{:45@ 6</[{:45@ ",
202 " 789{:45@ 789{:45@ ",
214 static QPixmap MYRightPix(right_xpm);
217 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal)
218 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
221 setModal( theIsModal );
223 setAttribute( Qt::WA_DeleteOnClose, true );
225 setWindowTitle("Edit Plot 2D Presentation");
226 setSizeGripEnabled(true);
228 QVBoxLayout* TopLayout = new QVBoxLayout (this );
229 TopLayout->setMargin( 6 );
230 TopLayout->setSpacing( 11);
232 /***************************************************************/
233 QFrame* aControlFrame = new QFrame (this);
234 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
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);
246 QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
247 aControlLay->addWidget(aSelectLbl, 0, 0);
249 myStudyLst = new QTreeWidget (aControlFrame);
250 myStudyLst->setSelectionMode(QAbstractItemView::ExtendedSelection);
251 myStudyLst->setColumnCount( 3 );
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 );
261 //myStudyLst->addColumn(tr("TXT_TABLE"), 80);
262 //myStudyLst->addColumn(tr("TXT_CURVE"), 50);
263 //myStudyLst->addColumn(tr(""), 0);
265 myStudyLst->setAllColumnsShowFocus(true);
266 //myStudyLst->setMinimumHeight(130);
267 connect(myStudyLst, SIGNAL(itemSelectionChanged()), this, SLOT(onLeftSelected()));
268 aControlLay->addWidget(myStudyLst, 1, 0, 5, 1);
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);
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);
282 QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
283 aControlLay->addWidget(aForceLbl, 0, 2);
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 );
297 //myContainerLst->setMinimumWidth(130);
298 connect(myContainerLst, SIGNAL(itemSelectionChanged()), this, SLOT(onRightSelected()));
299 aControlLay->addWidget(myContainerLst, 1, 2, 5, 1);
301 TopLayout->addWidget(aControlFrame);
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);
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);
320 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons);
321 buttonCancel->setAutoDefault(TRUE);
322 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
324 QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons);
325 buttonHelp->setAutoDefault(TRUE);
326 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
328 TopLayout->addWidget(GroupButtons);
330 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
331 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
332 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
335 void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
337 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
338 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
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;
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);
356 aList.append( aEntry.TableName );
357 aList.append( aEntry.CurveName );
358 aList.append( aEntry.CurveEntry );
359 new QTreeWidgetItem(myContainerLst, aList);
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();
371 aEntry.TableName = getSObjectName(aTableSO);
372 aEntry.CurveName = getSObjectName(aSObject);
373 aEntry.CurveEntry = aSObject->GetID().c_str();
374 aStudyCurves.append(aEntry);
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))
390 aList.append( (*it).TableName );
391 aList.append( (*it).CurveName );
392 aList.append( (*it).CurveEntry );
393 new QTreeWidgetItem(myStudyLst, aList );
398 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
400 theContainer->Clear();
402 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
403 QTreeWidgetItem* anItem;
404 for ( int i= 0; i< myContainerLst->topLevelItemCount(); i++ )
406 anItem = myContainerLst->topLevelItem( i );
409 _PTR(SObject) aCurveSO = aStudy->FindObjectID((const char*)anItem->text(2).toLatin1());
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());
420 QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
422 if (!theSObject) return QString("");
424 _PTR(GenericAttribute) anAttr;
425 if (theSObject->FindAttribute(anAttr, "AttributeName")) {
426 _PTR(AttributeName) aName (anAttr);
427 return QString(aName->Value().c_str());
432 void VisuGUI_EditContainerDlg::onLeftClicked()
434 /*QListViewItem* anItem = myContainerLst->firstChild();
436 if (anItem->isSelected()) {
437 QListViewItem* anTmpItem = anItem;
438 anItem = anTmpItem->nextSibling();
439 myContainerLst->takeItem(anTmpItem);
440 myStudyLst->insertItem(anTmpItem);
442 anItem = anItem->nextSibling();
445 QList<QTreeWidgetItem*> selItem = myContainerLst->selectedItems();
446 QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
448 QList<QTreeWidgetItem*> topSelectedItems;
449 for ( ; anIt != selItem.end(); anIt++ )
451 int index = myContainerLst->indexOfTopLevelItem( *anIt );
453 topSelectedItems.append( myContainerLst->takeTopLevelItem( index ) );
456 myStudyLst->addTopLevelItems(topSelectedItems);
459 void VisuGUI_EditContainerDlg::onRightClicked()
461 /*QListViewItem* anItem = myStudyLst->firstChild();
463 if (anItem->isSelected()) {
464 QListViewItem* anTmpItem = anItem;
465 anItem = anTmpItem->nextSibling();
466 myStudyLst->takeItem(anTmpItem);
467 myContainerLst->insertItem(anTmpItem);
469 anItem = anItem->nextSibling();
472 QList<QTreeWidgetItem*> selItem = myStudyLst->selectedItems();
473 QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
475 QList<QTreeWidgetItem*> topSelectedItems;
476 for ( ; anIt != selItem.end(); anIt++ )
478 int index = myStudyLst->indexOfTopLevelItem( *anIt );
480 topSelectedItems.append( myStudyLst->takeTopLevelItem( index ) );
483 myContainerLst->addTopLevelItems(topSelectedItems);
486 void VisuGUI_EditContainerDlg::onLeftSelected()
488 myRightBtn->setEnabled( myStudyLst->selectedItems().count() > 0 );
491 void VisuGUI_EditContainerDlg::onRightSelected()
493 myLeftBtn->setEnabled( myContainerLst->selectedItems().count() > 0 );
496 void VisuGUI_EditContainerDlg::onHelp()
498 QString aHelpFileName = "creating_xy_plot_page.html";
499 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
501 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
505 platform = "winapplication";
507 platform = "application";
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"));
516 void VisuGUI_EditContainerDlg::keyPressEvent( QKeyEvent* e )
518 QDialog::keyPressEvent( e );
519 if ( e->isAccepted() )
522 if ( e->key() == Qt::Key_F1 )