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 "QAD_Application.h"
17 #include "QAD_Desktop.h"
20 #include <qcheckbox.h>
21 #include <qgroupbox.h>
22 #include <qpushbutton.h>
24 #include CORBA_SERVER_HEADER(VISU_Gen)
25 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
27 extern VisuGUI *visuGUI;
33 static const char * left_xpm[] = {
104 " .]>!^&~{ .]>!^&~{ ",
105 " ./>!/(_:{ ./>!/(_:{ ",
106 " .<*!^[}}|{.<*!^[}}|{ ",
107 " 123}45667{123}45667{ ",
108 " 890a45b7{ 890a45b7{ ",
109 " 8cdef5'{ 8cdef5'{ ",
121 static QPixmap MYLeftPix(left_xpm);
124 static const char * right_xpm[] = {
177 " ),!~{;+@ ),!~{;+@ ",
178 " ]^!/({;+@ ]^!/({;+@ ",
179 " _~:<[}|1+@_~:<[}|1+@ ",
180 " 23~[[{:45@23~[[{:45@ ",
181 " 6</[{:45@ 6</[{:45@ ",
182 " 789{:45@ 789{:45@ ",
194 static QPixmap MYRightPix(right_xpm);
197 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg()
198 : QDialog( QAD_Application::getDesktop(), "VisuGUI_EditContainerDlg", true,
199 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
201 setCaption( "Edit Plot 2D Presentation" );
202 setSizeGripEnabled( true );
203 QVBoxLayout* TopLayout = new QVBoxLayout(this, 6, 11);
205 /***************************************************************/
206 QFrame* aControlFrame = new QFrame(this);
207 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
209 QGridLayout* aControlLay = new QGridLayout(aControlFrame);
210 aControlLay->setSpacing( 6 );
211 aControlLay->setMargin( 11 );
212 aControlLay->addRowSpacing( 1, 30 );
213 aControlLay->addRowSpacing( 4, 30 );
214 aControlLay->setRowStretch( 1, 1 );
215 aControlLay->setRowStretch( 4, 1 );
216 aControlLay->addColSpacing( 0, 180 );
217 aControlLay->addColSpacing( 2, 180 );
219 QLabel* aSelectLbl = new QLabel(tr("Study"), aControlFrame);
220 aControlLay->addWidget(aSelectLbl, 0, 0);
222 myStudyLst = new QListView(aControlFrame);
223 myStudyLst->setSelectionMode(QListView::Extended);
224 myStudyLst->addColumn(tr("Table"), 80);
225 myStudyLst->addColumn(tr("Curve"), 50);
226 myStudyLst->addColumn(tr(""), 0);
227 myStudyLst->setAllColumnsShowFocus(true);
228 myStudyLst->setMinimumHeight(130);
229 connect(myStudyLst, SIGNAL( selectionChanged()), this, SLOT( onLeftSelected() ));
230 aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0);
232 myRightBtn = new QToolButton(aControlFrame);
233 myRightBtn->setIconSet(MYRightPix);
234 myRightBtn->setEnabled(false);
235 connect(myRightBtn, SIGNAL( clicked()), this, SLOT( onRightClicked() ));
236 aControlLay->addWidget(myRightBtn, 2, 1);
238 myLeftBtn = new QToolButton(aControlFrame);
239 myLeftBtn->setIconSet(MYLeftPix);
240 myLeftBtn->setEnabled(false);
241 connect(myLeftBtn, SIGNAL( clicked()), this, SLOT( onLeftClicked() ));
242 aControlLay->addWidget(myLeftBtn, 3, 1);
244 QLabel* aForceLbl = new QLabel(tr("Container"), aControlFrame);
245 aControlLay->addWidget(aForceLbl, 0, 2);
247 myContainerLst = new QListView(aControlFrame);
248 myContainerLst->setSelectionMode(QListView::Extended);
249 myContainerLst->addColumn(tr("Table"), 80);
250 myContainerLst->addColumn(tr("Curve"), 50);
251 myContainerLst->addColumn(tr(""), 0);
252 myContainerLst->setMinimumWidth(130);
253 connect(myContainerLst, SIGNAL( selectionChanged()), this, SLOT( onRightSelected() ));
254 aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2);
256 TopLayout->addWidget( aControlFrame );
258 // Common buttons ===========================================================
259 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
260 GroupButtons->setColumnLayout(0, Qt::Vertical );
261 GroupButtons->layout()->setSpacing( 0 );
262 GroupButtons->layout()->setMargin( 0 );
263 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
264 GroupButtonsLayout->setAlignment( Qt::AlignTop );
265 GroupButtonsLayout->setSpacing( 6 );
266 GroupButtonsLayout->setMargin( 11 );
268 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
269 buttonOk->setAutoDefault( TRUE );
270 buttonOk->setDefault( TRUE );
271 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
272 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
274 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
275 buttonCancel->setAutoDefault( TRUE );
276 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
278 TopLayout->addWidget( GroupButtons );
280 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
281 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
285 void VisuGUI_EditContainerDlg::initFromPrsObject(VISU::Container_i* theContainer) {
286 SALOMEDS::Study_var aStudy = visuGUI->GetStudyDocument();
287 SALOMEDS::SComponent_var aVisuSO = aStudy->FindComponent("VISU");
288 if (aVisuSO->_is_nil()) {
291 QValueList<CurveStruct> aStudyCurves;
292 QValueList<CurveStruct> aContainerCurves;
293 // Find curves in container
294 for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
295 VISU::Curve_i* aCurve = theContainer->GetCurve(i);
296 if (aCurve == NULL) continue;
298 aEntry.CurveName = aCurve->GetTitle();
299 aEntry.CurveEntry = aCurve->GetEntry();
300 SALOMEDS::SObject_var aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
301 if (CORBA::is_nil(aTableSO)) continue;
302 aEntry.TableName = getSObjectName(aTableSO);
303 aContainerCurves.append(aEntry);
304 new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry);
306 // Find curves in study
307 SALOMEDS::ChildIterator_var aIter = aStudy->NewChildIterator( aVisuSO );
308 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
309 SALOMEDS::SObject_var aSObject = aIter->Value();
310 CORBA::Object_var anObject = VISU::SObjectToObject(aSObject);
311 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
312 if (!CORBA::is_nil(aVisuObj)) {
313 if (aVisuObj->GetType() == VISU::TCURVE) {
314 SALOMEDS::SObject_var aTableSO = aSObject->GetFather();
316 aEntry.TableName = getSObjectName(aTableSO);
317 aEntry.CurveName = getSObjectName(aSObject);
318 aEntry.CurveEntry = aSObject->GetID();
319 aStudyCurves.append(aEntry);
323 //Show Curves which are not in Curve
324 QValueList<CurveStruct>::iterator it;
325 QValueList<CurveStruct>::iterator it2;
326 bool isExist = false;
327 for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it ) {
328 for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2 ) {
329 if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
333 new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
338 void VisuGUI_EditContainerDlg::storeToPrsObject(VISU::Container_i* theContainer) {
339 theContainer->Clear();
341 SALOMEDS::Study_var aStudy = visuGUI->GetStudyDocument();
342 QListViewItem* anItem = myContainerLst->firstChild();
344 SALOMEDS::SObject_var aCurveSO = aStudy->FindObjectID(anItem->text(2));
345 if (!aCurveSO->_is_nil()) {
346 CORBA::Object_var aObject = VISU::SObjectToObject(aCurveSO);
347 if (!CORBA::is_nil(aObject)) {
348 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aObject).in() );
349 if (aCurve) theContainer->AddCurve(aCurve->_this());
352 anItem = anItem->nextSibling();
357 QString VisuGUI_EditContainerDlg::getSObjectName(SALOMEDS::SObject_var theSObject) {
358 if (theSObject->_is_nil()) return QString("");
360 SALOMEDS::GenericAttribute_var anAttr;
361 SALOMEDS::AttributeName_var aName;
362 if ( theSObject->FindAttribute(anAttr, "AttributeName") ) {
363 aName = SALOMEDS::AttributeName::_narrow( anAttr );
364 return QString(strdup( aName->Value() ));
370 void VisuGUI_EditContainerDlg::onLeftClicked() {
371 QListViewItem* anItem = myContainerLst->firstChild();
373 if (anItem->isSelected()) {
374 QListViewItem* anTmpItem = anItem;
375 anItem = anTmpItem->nextSibling();
376 myContainerLst->takeItem(anTmpItem);
377 myStudyLst->insertItem(anTmpItem);
379 anItem = anItem->nextSibling();
385 void VisuGUI_EditContainerDlg::onRightClicked() {
386 QListViewItem* anItem = myStudyLst->firstChild();
388 if (anItem->isSelected()) {
389 QListViewItem* anTmpItem = anItem;
390 anItem = anTmpItem->nextSibling();
391 myStudyLst->takeItem(anTmpItem);
392 myContainerLst->insertItem(anTmpItem);
394 anItem = anItem->nextSibling();
400 void VisuGUI_EditContainerDlg::onLeftSelected() {
401 QListViewItem* anItem = myStudyLst->firstChild();
402 bool isSelected = false;
404 if (anItem->isSelected()) {
408 anItem = anItem->nextSibling();
410 myRightBtn->setEnabled(isSelected);
414 void VisuGUI_EditContainerDlg::onRightSelected() {
415 QListViewItem* anItem = myContainerLst->firstChild();
416 bool isSelected = false;
418 if (anItem->isSelected()) {
422 anItem = anItem->nextSibling();
424 myLeftBtn->setEnabled(isSelected);