1 // Copyright (C) 2007-2010 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
23 // File : VisuGUI_EditContainerDlg.cxx
27 #include "VisuGUI_EditContainerDlg.h"
30 #include "VisuGUI_Tools.h"
32 #include "VISU_Table_i.hh"
34 #include "SalomeApp_Application.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_Session.h"
37 #include "SUIT_MessageBox.h"
38 #include "SUIT_ResourceMgr.h"
43 #include <QPushButton>
45 #include <QTreeWidget>
46 #include <QToolButton>
54 static const char * left_xpm[] = {
125 " .]>!^&~{ .]>!^&~{ ",
126 " ./>!/(_:{ ./>!/(_:{ ",
127 " .<*!^[}}|{.<*!^[}}|{ ",
128 " 123}45667{123}45667{ ",
129 " 890a45b7{ 890a45b7{ ",
130 " 8cdef5'{ 8cdef5'{ ",
142 static QPixmap MYLeftPix(left_xpm);
145 static const char * right_xpm[] = {
198 " ),!~{;+@ ),!~{;+@ ",
199 " ]^!/({;+@ ]^!/({;+@ ",
200 " _~:<[}|1+@_~:<[}|1+@ ",
201 " 23~[[{:45@23~[[{:45@ ",
202 " 6</[{:45@ 6</[{:45@ ",
203 " 789{:45@ 789{:45@ ",
215 static QPixmap MYRightPix(right_xpm);
218 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal)
219 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
222 setModal( theIsModal );
224 setAttribute( Qt::WA_DeleteOnClose, true );
226 setWindowTitle("Edit Plot 2D Presentation");
227 setSizeGripEnabled(true);
229 QVBoxLayout* TopLayout = new QVBoxLayout (this );
230 TopLayout->setMargin( 6 );
231 TopLayout->setSpacing( 11);
233 /***************************************************************/
234 QFrame* aControlFrame = new QFrame (this);
235 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
237 QGridLayout* aControlLay = new QGridLayout (aControlFrame);
238 aControlLay->setSpacing(6);
239 aControlLay->setMargin(11);
240 //aControlLay->addRowSpacing(1, 30);
241 //aControlLay->addRowSpacing(4, 30);
242 aControlLay->setRowStretch(1, 1);
243 aControlLay->setRowStretch(4, 1);
244 //aControlLay->addColSpacing(0, 180);
245 //aControlLay->addColSpacing(2, 180);
247 QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
248 aControlLay->addWidget(aSelectLbl, 0, 0);
250 myStudyLst = new QTreeWidget (aControlFrame);
251 myStudyLst->setSelectionMode(QAbstractItemView::ExtendedSelection);
252 myStudyLst->setColumnCount( 3 );
254 aLabels.append( tr("TXT_TABLE") );
255 aLabels.append( tr("TXT_CURVE") );
256 aLabels.append( "" );
257 myStudyLst->setHeaderLabels( aLabels );
258 myStudyLst->setColumnWidth( 0, 80 );
259 myStudyLst->setColumnWidth( 1, 50 );
260 myStudyLst->setColumnWidth( 2, 0 );
262 //myStudyLst->addColumn(tr("TXT_TABLE"), 80);
263 //myStudyLst->addColumn(tr("TXT_CURVE"), 50);
264 //myStudyLst->addColumn(tr(""), 0);
266 myStudyLst->setAllColumnsShowFocus(true);
267 //myStudyLst->setMinimumHeight(130);
268 connect(myStudyLst, SIGNAL(itemSelectionChanged()), this, SLOT(onLeftSelected()));
269 aControlLay->addWidget(myStudyLst, 1, 0, 5, 1);
271 myRightBtn = new QToolButton (aControlFrame);
272 myRightBtn->setIcon(MYRightPix);
273 myRightBtn->setEnabled(false);
274 connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked()));
275 aControlLay->addWidget(myRightBtn, 2, 1);
277 myLeftBtn = new QToolButton(aControlFrame);
278 myLeftBtn->setIcon(MYLeftPix);
279 myLeftBtn->setEnabled(false);
280 connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked()));
281 aControlLay->addWidget(myLeftBtn, 3, 1);
283 QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
284 aControlLay->addWidget(aForceLbl, 0, 2);
286 myContainerLst = new QTreeWidget(aControlFrame);
287 myContainerLst->setSelectionMode(QAbstractItemView::ExtendedSelection);
288 //myContainerLst->addColumn(tr("TXT_TABLE"), 80);
289 //myContainerLst->addColumn(tr("TXT_CURVE"), 50);
290 //myContainerLst->addColumn(tr(""), 0);
291 myContainerLst->setColumnCount( 3 );
292 myContainerLst->setHeaderLabels( aLabels );
293 myContainerLst->setColumnWidth( 0, 80 );
294 myContainerLst->setColumnWidth( 1, 50 );
295 myContainerLst->setColumnWidth( 2, 0 );
298 //myContainerLst->setMinimumWidth(130);
299 connect(myContainerLst, SIGNAL(itemSelectionChanged()), this, SLOT(onRightSelected()));
300 aControlLay->addWidget(myContainerLst, 1, 2, 5, 1);
302 TopLayout->addWidget(aControlFrame);
304 // Common buttons ===========================================================
305 QGroupBox* GroupButtons = new QGroupBox(this);
306 //GroupButtons->setColumnLayout(0, Qt::Vertical);
307 //GroupButtons->layout()->setSpacing(0);
308 //GroupButtons->layout()->setMargin(0);
309 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
310 GroupButtonsLayout->setAlignment(Qt::AlignTop);
311 GroupButtonsLayout->setSpacing(6);
312 GroupButtonsLayout->setMargin(11);
314 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons);
315 buttonOk->setAutoDefault(TRUE);
316 buttonOk->setDefault(TRUE);
317 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
318 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding,
319 QSizePolicy::Minimum), 0, 1);
321 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons);
322 buttonCancel->setAutoDefault(TRUE);
323 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
325 QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons);
326 buttonHelp->setAutoDefault(TRUE);
327 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
329 TopLayout->addWidget(GroupButtons);
331 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
332 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
333 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
336 void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
338 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
339 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
343 QList<CurveStruct> aStudyCurves;
344 QList<CurveStruct> aContainerCurves;
345 // Find curves in container
346 for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
347 VISU::Curve_i* aCurve = theContainer->GetCurve(i);
348 if (aCurve == NULL) continue;
350 aEntry.CurveName = aCurve->GetTitle();
351 aEntry.CurveEntry = aCurve->GetEntry().c_str();
352 _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
353 if (!aTableSO) continue;
354 aEntry.TableName = getSObjectName(aTableSO);
355 aContainerCurves.append(aEntry);
357 aList.append( aEntry.TableName );
358 aList.append( aEntry.CurveName );
359 aList.append( aEntry.CurveEntry );
360 new QTreeWidgetItem(myContainerLst, aList);
362 // Find curves in study
363 _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO);
364 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
365 _PTR(SObject) aSObject = aIter->Value();
366 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
367 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
368 if (!CORBA::is_nil(aVisuObj)) {
369 if (aVisuObj->GetType() == VISU::TCURVE) {
370 _PTR(SObject) aTableSO = aSObject->GetFather();
372 aEntry.TableName = getSObjectName(aTableSO);
373 aEntry.CurveName = getSObjectName(aSObject);
374 aEntry.CurveEntry = aSObject->GetID().c_str();
375 aStudyCurves.append(aEntry);
379 //Show Curves which are not in Curve
380 QList<CurveStruct>::iterator it;
381 QList<CurveStruct>::iterator it2;
382 bool isExist = false;
383 for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) {
384 for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) {
385 if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
391 aList.append( (*it).TableName );
392 aList.append( (*it).CurveName );
393 aList.append( (*it).CurveEntry );
394 new QTreeWidgetItem(myStudyLst, aList );
399 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
401 theContainer->Clear();
403 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
404 QTreeWidgetItem* anItem;
405 for ( int i= 0; i< myContainerLst->topLevelItemCount(); i++ )
407 anItem = myContainerLst->topLevelItem( i );
410 _PTR(SObject) aCurveSO = aStudy->FindObjectID((const char*)anItem->text(2).toLatin1());
412 CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO);
413 if (!CORBA::is_nil(aObject)) {
414 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aObject).in());
415 if (aCurve) theContainer->AddCurve(aCurve->_this());
421 QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
423 if (!theSObject) return QString("");
425 _PTR(GenericAttribute) anAttr;
426 if (theSObject->FindAttribute(anAttr, "AttributeName")) {
427 _PTR(AttributeName) aName (anAttr);
428 return QString(aName->Value().c_str());
433 void VisuGUI_EditContainerDlg::onLeftClicked()
435 /*QListViewItem* anItem = myContainerLst->firstChild();
437 if (anItem->isSelected()) {
438 QListViewItem* anTmpItem = anItem;
439 anItem = anTmpItem->nextSibling();
440 myContainerLst->takeItem(anTmpItem);
441 myStudyLst->insertItem(anTmpItem);
443 anItem = anItem->nextSibling();
446 QList<QTreeWidgetItem*> selItem = myContainerLst->selectedItems();
447 QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
449 QList<QTreeWidgetItem*> topSelectedItems;
450 for ( ; anIt != selItem.end(); anIt++ )
452 int index = myContainerLst->indexOfTopLevelItem( *anIt );
454 topSelectedItems.append( myContainerLst->takeTopLevelItem( index ) );
457 myStudyLst->addTopLevelItems(topSelectedItems);
460 void VisuGUI_EditContainerDlg::onRightClicked()
462 /*QListViewItem* anItem = myStudyLst->firstChild();
464 if (anItem->isSelected()) {
465 QListViewItem* anTmpItem = anItem;
466 anItem = anTmpItem->nextSibling();
467 myStudyLst->takeItem(anTmpItem);
468 myContainerLst->insertItem(anTmpItem);
470 anItem = anItem->nextSibling();
473 QList<QTreeWidgetItem*> selItem = myStudyLst->selectedItems();
474 QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
476 QList<QTreeWidgetItem*> topSelectedItems;
477 for ( ; anIt != selItem.end(); anIt++ )
479 int index = myStudyLst->indexOfTopLevelItem( *anIt );
481 topSelectedItems.append( myStudyLst->takeTopLevelItem( index ) );
484 myContainerLst->addTopLevelItems(topSelectedItems);
487 void VisuGUI_EditContainerDlg::onLeftSelected()
489 myRightBtn->setEnabled( myStudyLst->selectedItems().count() > 0 );
492 void VisuGUI_EditContainerDlg::onRightSelected()
494 myLeftBtn->setEnabled( myContainerLst->selectedItems().count() > 0 );
497 void VisuGUI_EditContainerDlg::onHelp()
499 QString aHelpFileName = "creating_xy_plot_page.html";
500 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
502 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
506 platform = "winapplication";
508 platform = "application";
510 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
511 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
512 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
513 QObject::tr("BUT_OK"));
517 void VisuGUI_EditContainerDlg::keyPressEvent( QKeyEvent* e )
519 QDialog::keyPressEvent( e );
520 if ( e->isAccepted() )
523 if ( e->key() == Qt::Key_F1 )