1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VisuGUI_EditContainerDlg.cxx
25 #include "VisuGUI_EditContainerDlg.h"
28 #include "VisuGUI_Tools.h"
30 #include "VISU_Table_i.hh"
32 #include "SalomeApp_Application.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_MessageBox.h"
36 #include "SUIT_ResourceMgr.h"
39 #include <qcheckbox.h>
40 #include <qgroupbox.h>
41 #include <qpushbutton.h>
48 static const char * left_xpm[] = {
119 " .]>!^&~{ .]>!^&~{ ",
120 " ./>!/(_:{ ./>!/(_:{ ",
121 " .<*!^[}}|{.<*!^[}}|{ ",
122 " 123}45667{123}45667{ ",
123 " 890a45b7{ 890a45b7{ ",
124 " 8cdef5'{ 8cdef5'{ ",
136 static QPixmap MYLeftPix(left_xpm);
139 static const char * right_xpm[] = {
192 " ),!~{;+@ ),!~{;+@ ",
193 " ]^!/({;+@ ]^!/({;+@ ",
194 " _~:<[}|1+@_~:<[}|1+@ ",
195 " 23~[[{:45@23~[[{:45@ ",
196 " 6</[{:45@ 6</[{:45@ ",
197 " 789{:45@ 789{:45@ ",
209 static QPixmap MYRightPix(right_xpm);
212 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal)
213 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_EditContainerDlg", theIsModal,
214 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
218 setWFlags(getWFlags() | WDestructiveClose);
220 setCaption("Edit Plot 2D Presentation");
221 setSizeGripEnabled(true);
223 QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
225 /***************************************************************/
226 QFrame* aControlFrame = new QFrame (this);
227 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
229 QGridLayout* aControlLay = new QGridLayout (aControlFrame);
230 aControlLay->setSpacing(6);
231 aControlLay->setMargin(11);
232 aControlLay->addRowSpacing(1, 30);
233 aControlLay->addRowSpacing(4, 30);
234 aControlLay->setRowStretch(1, 1);
235 aControlLay->setRowStretch(4, 1);
236 aControlLay->addColSpacing(0, 180);
237 aControlLay->addColSpacing(2, 180);
239 QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
240 aControlLay->addWidget(aSelectLbl, 0, 0);
242 myStudyLst = new QListView (aControlFrame);
243 myStudyLst->setSelectionMode(QListView::Extended);
244 myStudyLst->addColumn(tr("TXT_TABLE"), 80);
245 myStudyLst->addColumn(tr("TXT_CURVE"), 50);
246 myStudyLst->addColumn(tr(""), 0);
247 myStudyLst->setAllColumnsShowFocus(true);
248 myStudyLst->setMinimumHeight(130);
249 connect(myStudyLst, SIGNAL(selectionChanged()), this, SLOT(onLeftSelected()));
250 aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0);
252 myRightBtn = new QToolButton (aControlFrame);
253 myRightBtn->setIconSet(MYRightPix);
254 myRightBtn->setEnabled(false);
255 connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked()));
256 aControlLay->addWidget(myRightBtn, 2, 1);
258 myLeftBtn = new QToolButton(aControlFrame);
259 myLeftBtn->setIconSet(MYLeftPix);
260 myLeftBtn->setEnabled(false);
261 connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked()));
262 aControlLay->addWidget(myLeftBtn, 3, 1);
264 QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
265 aControlLay->addWidget(aForceLbl, 0, 2);
267 myContainerLst = new QListView(aControlFrame);
268 myContainerLst->setSelectionMode(QListView::Extended);
269 myContainerLst->addColumn(tr("TXT_TABLE"), 80);
270 myContainerLst->addColumn(tr("TXT_CURVE"), 50);
271 myContainerLst->addColumn(tr(""), 0);
272 myContainerLst->setMinimumWidth(130);
273 connect(myContainerLst, SIGNAL(selectionChanged()), this, SLOT(onRightSelected()));
274 aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2);
276 TopLayout->addWidget(aControlFrame);
278 // Common buttons ===========================================================
279 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
280 GroupButtons->setColumnLayout(0, Qt::Vertical);
281 GroupButtons->layout()->setSpacing(0);
282 GroupButtons->layout()->setMargin(0);
283 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
284 GroupButtonsLayout->setAlignment(Qt::AlignTop);
285 GroupButtonsLayout->setSpacing(6);
286 GroupButtonsLayout->setMargin(11);
288 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
289 buttonOk->setAutoDefault(TRUE);
290 buttonOk->setDefault(TRUE);
291 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
292 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding,
293 QSizePolicy::Minimum), 0, 1);
295 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
296 buttonCancel->setAutoDefault(TRUE);
297 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
299 QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp");
300 buttonHelp->setAutoDefault(TRUE);
301 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
303 TopLayout->addWidget(GroupButtons);
305 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
306 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
307 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
310 void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
312 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
313 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
317 QValueList<CurveStruct> aStudyCurves;
318 QValueList<CurveStruct> aContainerCurves;
319 // Find curves in container
320 for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
321 VISU::Curve_i* aCurve = theContainer->GetCurve(i);
322 if (aCurve == NULL) continue;
324 aEntry.CurveName = aCurve->GetTitle();
325 aEntry.CurveEntry = aCurve->GetEntry();
326 _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
327 if (!aTableSO) continue;
328 aEntry.TableName = getSObjectName(aTableSO);
329 aContainerCurves.append(aEntry);
330 new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry);
332 // Find curves in study
333 _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO);
334 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
335 _PTR(SObject) aSObject = aIter->Value();
336 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
337 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
338 if (!CORBA::is_nil(aVisuObj)) {
339 if (aVisuObj->GetType() == VISU::TCURVE) {
340 _PTR(SObject) aTableSO = aSObject->GetFather();
342 aEntry.TableName = getSObjectName(aTableSO);
343 aEntry.CurveName = getSObjectName(aSObject);
344 aEntry.CurveEntry = aSObject->GetID().c_str();
345 aStudyCurves.append(aEntry);
349 //Show Curves which are not in Curve
350 QValueList<CurveStruct>::iterator it;
351 QValueList<CurveStruct>::iterator it2;
352 bool isExist = false;
353 for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) {
354 for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) {
355 if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
359 new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
363 void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
365 theContainer->Clear();
367 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
368 QListViewItem* anItem = myContainerLst->firstChild();
370 _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2).latin1());
372 CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO);
373 if (!CORBA::is_nil(aObject)) {
374 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aObject).in());
375 if (aCurve) theContainer->AddCurve(aCurve->_this());
378 anItem = anItem->nextSibling();
382 QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
384 if (!theSObject) return QString("");
386 _PTR(GenericAttribute) anAttr;
387 if (theSObject->FindAttribute(anAttr, "AttributeName")) {
388 _PTR(AttributeName) aName (anAttr);
389 return QString(aName->Value().c_str());
394 void VisuGUI_EditContainerDlg::onLeftClicked()
396 QListViewItem* anItem = myContainerLst->firstChild();
398 if (anItem->isSelected()) {
399 QListViewItem* anTmpItem = anItem;
400 anItem = anTmpItem->nextSibling();
401 myContainerLst->takeItem(anTmpItem);
402 myStudyLst->insertItem(anTmpItem);
404 anItem = anItem->nextSibling();
409 void VisuGUI_EditContainerDlg::onRightClicked()
411 QListViewItem* anItem = myStudyLst->firstChild();
413 if (anItem->isSelected()) {
414 QListViewItem* anTmpItem = anItem;
415 anItem = anTmpItem->nextSibling();
416 myStudyLst->takeItem(anTmpItem);
417 myContainerLst->insertItem(anTmpItem);
419 anItem = anItem->nextSibling();
424 void VisuGUI_EditContainerDlg::onLeftSelected()
426 QListViewItem* anItem = myStudyLst->firstChild();
427 bool isSelected = false;
429 if (anItem->isSelected()) {
433 anItem = anItem->nextSibling();
435 myRightBtn->setEnabled(isSelected);
438 void VisuGUI_EditContainerDlg::onRightSelected()
440 QListViewItem* anItem = myContainerLst->firstChild();
441 bool isSelected = false;
443 if (anItem->isSelected()) {
447 anItem = anItem->nextSibling();
449 myLeftBtn->setEnabled(isSelected);
452 void VisuGUI_EditContainerDlg::onHelp()
454 QString aHelpFileName = "creating_xy_plot_page.html";
455 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
457 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
461 platform = "winapplication";
463 platform = "application";
465 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
466 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
467 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
468 QObject::tr("BUT_OK"));
472 void VisuGUI_EditContainerDlg::keyPressEvent( QKeyEvent* e )
474 QDialog::keyPressEvent( e );
475 if ( e->isAccepted() )
478 if ( e->key() == Key_F1 )