3 // VISU VISUGUI : GUI of VISU component
5 // Copyright (C) 2003 CEA/DEN, EDF R&D
9 // File : VisuGUI_EditContainerDlg.cxx
14 #include "VisuGUI_EditContainerDlg.h"
16 #include "VISU_Table_i.hh"
18 #include "QAD_Application.h"
19 #include "QAD_Desktop.h"
22 #include <qcheckbox.h>
23 #include <qgroupbox.h>
26 #include CORBA_SERVER_HEADER(VISU_Gen)
27 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
29 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()
199 : QDialog( QAD_Application::getDesktop(), "VisuGUI_EditContainerDlg", true,
200 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
202 setCaption( "Edit Plot 2D Presentation" );
203 setSizeGripEnabled( true );
204 QVBoxLayout* TopLayout = new QVBoxLayout(this, 6, 11);
206 /***************************************************************/
207 QFrame* aControlFrame = new QFrame(this);
208 aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
210 QGridLayout* aControlLay = new QGridLayout(aControlFrame);
211 aControlLay->setSpacing( 6 );
212 aControlLay->setMargin( 11 );
213 aControlLay->addRowSpacing( 1, 30 );
214 aControlLay->addRowSpacing( 4, 30 );
215 aControlLay->setRowStretch( 1, 1 );
216 aControlLay->setRowStretch( 4, 1 );
217 aControlLay->addColSpacing( 0, 180 );
218 aControlLay->addColSpacing( 2, 180 );
220 QLabel* aSelectLbl = new QLabel(tr("Study"), aControlFrame);
221 aControlLay->addWidget(aSelectLbl, 0, 0);
223 myStudyLst = new QListView(aControlFrame);
224 myStudyLst->setSelectionMode(QListView::Extended);
225 myStudyLst->addColumn(tr("Table"), 80);
226 myStudyLst->addColumn(tr("Curve"), 50);
227 myStudyLst->addColumn(tr(""), 0);
228 myStudyLst->setAllColumnsShowFocus(true);
229 myStudyLst->setMinimumHeight(130);
230 connect(myStudyLst, SIGNAL( selectionChanged()), this, SLOT( onLeftSelected() ));
231 aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0);
233 myRightBtn = new QToolButton(aControlFrame);
234 myRightBtn->setIconSet(MYRightPix);
235 myRightBtn->setEnabled(false);
236 connect(myRightBtn, SIGNAL( clicked()), this, SLOT( onRightClicked() ));
237 aControlLay->addWidget(myRightBtn, 2, 1);
239 myLeftBtn = new QToolButton(aControlFrame);
240 myLeftBtn->setIconSet(MYLeftPix);
241 myLeftBtn->setEnabled(false);
242 connect(myLeftBtn, SIGNAL( clicked()), this, SLOT( onLeftClicked() ));
243 aControlLay->addWidget(myLeftBtn, 3, 1);
245 QLabel* aForceLbl = new QLabel(tr("Container"), aControlFrame);
246 aControlLay->addWidget(aForceLbl, 0, 2);
248 myContainerLst = new QListView(aControlFrame);
249 myContainerLst->setSelectionMode(QListView::Extended);
250 myContainerLst->addColumn(tr("Table"), 80);
251 myContainerLst->addColumn(tr("Curve"), 50);
252 myContainerLst->addColumn(tr(""), 0);
253 myContainerLst->setMinimumWidth(130);
254 connect(myContainerLst, SIGNAL( selectionChanged()), this, SLOT( onRightSelected() ));
255 aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2);
257 TopLayout->addWidget( aControlFrame );
259 // Common buttons ===========================================================
260 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
261 GroupButtons->setColumnLayout(0, Qt::Vertical );
262 GroupButtons->layout()->setSpacing( 0 );
263 GroupButtons->layout()->setMargin( 0 );
264 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
265 GroupButtonsLayout->setAlignment( Qt::AlignTop );
266 GroupButtonsLayout->setSpacing( 6 );
267 GroupButtonsLayout->setMargin( 11 );
269 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
270 buttonOk->setAutoDefault( TRUE );
271 buttonOk->setDefault( TRUE );
272 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
273 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
275 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
276 buttonCancel->setAutoDefault( TRUE );
277 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
279 TopLayout->addWidget( GroupButtons );
281 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
282 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
286 void VisuGUI_EditContainerDlg::initFromPrsObject(VISU::Container_i* theContainer) {
287 SALOMEDS::Study_var aStudy = visuGUI->GetStudyDocument();
288 SALOMEDS::SComponent_var aVisuSO = aStudy->FindComponent("VISU");
289 if (aVisuSO->_is_nil()) {
292 QValueList<CurveStruct> aStudyCurves;
293 QValueList<CurveStruct> aContainerCurves;
294 // Find curves in container
295 for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
296 VISU::Curve_i* aCurve = theContainer->GetCurve(i);
297 if (aCurve == NULL) continue;
299 aEntry.CurveName = aCurve->GetTitle();
300 aEntry.CurveEntry = aCurve->GetEntry();
301 SALOMEDS::SObject_var aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
302 if (CORBA::is_nil(aTableSO)) continue;
303 aEntry.TableName = getSObjectName(aTableSO);
304 aContainerCurves.append(aEntry);
305 new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry);
307 // Find curves in study
308 SALOMEDS::ChildIterator_var aIter = aStudy->NewChildIterator( aVisuSO );
309 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
310 SALOMEDS::SObject_var aSObject = aIter->Value();
311 CORBA::Object_var anObject = VISU::SObjectToObject(aSObject);
312 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
313 if (!CORBA::is_nil(aVisuObj)) {
314 if (aVisuObj->GetType() == VISU::TCURVE) {
315 SALOMEDS::SObject_var aTableSO = aSObject->GetFather();
317 aEntry.TableName = getSObjectName(aTableSO);
318 aEntry.CurveName = getSObjectName(aSObject);
319 aEntry.CurveEntry = aSObject->GetID();
320 aStudyCurves.append(aEntry);
324 //Show Curves which are not in Curve
325 QValueList<CurveStruct>::iterator it;
326 QValueList<CurveStruct>::iterator it2;
327 bool isExist = false;
328 for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it ) {
329 for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2 ) {
330 if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
334 new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
339 void VisuGUI_EditContainerDlg::storeToPrsObject(VISU::Container_i* theContainer) {
340 theContainer->Clear();
342 SALOMEDS::Study_var aStudy = visuGUI->GetStudyDocument();
343 QListViewItem* anItem = myContainerLst->firstChild();
345 SALOMEDS::SObject_var aCurveSO = aStudy->FindObjectID(anItem->text(2));
346 if (!aCurveSO->_is_nil()) {
347 CORBA::Object_var aObject = VISU::SObjectToObject(aCurveSO);
348 if (!CORBA::is_nil(aObject)) {
349 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aObject).in() );
350 if (aCurve) theContainer->AddCurve(aCurve->_this());
353 anItem = anItem->nextSibling();
358 QString VisuGUI_EditContainerDlg::getSObjectName(SALOMEDS::SObject_var theSObject) {
359 if (theSObject->_is_nil()) return QString("");
361 SALOMEDS::GenericAttribute_var anAttr;
362 SALOMEDS::AttributeName_var aName;
363 if ( theSObject->FindAttribute(anAttr, "AttributeName") ) {
364 aName = SALOMEDS::AttributeName::_narrow( anAttr );
365 return QString(strdup( aName->Value() ));
371 void VisuGUI_EditContainerDlg::onLeftClicked() {
372 QListViewItem* anItem = myContainerLst->firstChild();
374 if (anItem->isSelected()) {
375 QListViewItem* anTmpItem = anItem;
376 anItem = anTmpItem->nextSibling();
377 myContainerLst->takeItem(anTmpItem);
378 myStudyLst->insertItem(anTmpItem);
380 anItem = anItem->nextSibling();
386 void VisuGUI_EditContainerDlg::onRightClicked() {
387 QListViewItem* anItem = myStudyLst->firstChild();
389 if (anItem->isSelected()) {
390 QListViewItem* anTmpItem = anItem;
391 anItem = anTmpItem->nextSibling();
392 myStudyLst->takeItem(anTmpItem);
393 myContainerLst->insertItem(anTmpItem);
395 anItem = anItem->nextSibling();
401 void VisuGUI_EditContainerDlg::onLeftSelected() {
402 QListViewItem* anItem = myStudyLst->firstChild();
403 bool isSelected = false;
405 if (anItem->isSelected()) {
409 anItem = anItem->nextSibling();
411 myRightBtn->setEnabled(isSelected);
415 void VisuGUI_EditContainerDlg::onRightSelected() {
416 QListViewItem* anItem = myContainerLst->firstChild();
417 bool isSelected = false;
419 if (anItem->isSelected()) {
423 anItem = anItem->nextSibling();
425 myLeftBtn->setEnabled(isSelected);