1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "OCCViewer_CreateRestoreViewDlg.h"
20 #include "OCCViewer_ViewModel.h"
21 #include "OCCViewer_ViewPort3d.h"
23 #include <qpushbutton.h>
28 OCCViewer_CreateRestoreViewDlg::OCCViewer_CreateRestoreViewDlg( QWidget* aWin, OCCViewer_Viewer* curModel )
31 setCaption( tr( "CAPTION" ) );
33 myParametersMap = curModel->getViewAspects();
37 int aQuantityOfItems = myParametersMap.count();
39 setFixedSize( 400, 300 );
41 QGridLayout* aGrid = new QGridLayout( this, 2, 1, 5, 10 );
43 QWidget* aWidget1 = new QWidget( this );
44 QWidget* aWidget2 = new QWidget( this );
46 QHBoxLayout* aLayout = new QHBoxLayout( aWidget1 );
48 myListBox = new QtxListBox( aWidget1 );
49 myListBox->installEventFilter( this );
51 myCurViewPort = new OCCViewer_ViewPort3d( aWidget1, curModel->getViewer3d(), V3d_ORTHOGRAPHIC );
52 myCurViewPort->getView()->SetBackgroundColor( Quantity_NOC_BLACK );
54 myListBox->setEditEnabled( 1 );
56 if ( aQuantityOfItems )
59 for( int i = 0; i < aQuantityOfItems; i++ )
60 myListBox->insertItem( myParametersMap[ i ].name );
62 changeImage( myListBox->item( 0 ) );
67 myListBox->insertItem( "No Items", 0 );
68 myListBox->setEditEnabled( 0 );
71 connect( myListBox, SIGNAL( clicked( QListBoxItem* ) ), this, SLOT( changeImage( QListBoxItem* ) ) );
72 connect( myListBox, SIGNAL( itemEdited( QListBoxItem* ) ), this, SLOT( editItemText( QListBoxItem* ) ) );
74 aLayout->addWidget( myListBox );
75 aLayout->addWidget( myCurViewPort, 30 );
77 QHBoxLayout* aButtonLayout = new QHBoxLayout( aWidget2, 0, 5 );
79 QPushButton* theOk = new QPushButton( tr( "Ok" ), aWidget2 ); theOk->setAutoDefault( false );
80 QPushButton* theCancel = new QPushButton( tr( "Cancel" ), aWidget2 ); theCancel->setAutoDefault( false );
81 QPushButton* theDelete = new QPushButton( tr( "Delete" ), aWidget2 ); theDelete->setAutoDefault( false );
82 QPushButton* theClearAll = new QPushButton( tr( "Clear List" ), aWidget2 ); theClearAll->setAutoDefault( false );
84 aButtonLayout->addWidget( theOk );
85 aButtonLayout->addWidget( theCancel );
86 aButtonLayout->addWidget( theDelete );
87 aButtonLayout->addWidget( theClearAll );
89 aGrid->addWidget( aWidget1, 0, 0 );
90 aGrid->addWidget( aWidget2, 1, 0 );
92 connect( theOk, SIGNAL( clicked() ), this, SLOT( OKpressed() ) );
93 connect( theCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
94 connect( theDelete, SIGNAL( clicked() ), this, SLOT( deleteSelectedItems() ) );
95 connect( theClearAll, SIGNAL( clicked() ), this, SLOT( clearList() ) );
98 OCCViewer_CreateRestoreViewDlg::~OCCViewer_CreateRestoreViewDlg()
102 void OCCViewer_CreateRestoreViewDlg::changeImage( QListBoxItem* curItem )
104 if( curItem && myListBox->isEditEnabled() )
108 int index = curItem->listBox()->index( curItem );
111 for( int i = 0; i < myListBox->count(); i++ )
113 if( myListBox->isSelected( i ) && i != index )
115 myListBox->clearSelection();
126 for( int j = lowLevel; j <= highLevel; j++ )
127 myListBox->setSelected( j, TRUE );
130 if( myListBox->isSelected( i ) && i == index )
131 myListBox->setSelected( i, TRUE );
135 Handle(V3d_View) aView3d = myCurViewPort->getView();
136 myCurrentItem = myParametersMap[ index ];
138 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
139 aView3d->SetScale( myCurrentItem.scale );
140 aView3d->SetCenter( myCurrentItem.centerX, myCurrentItem.centerY );
141 aView3d->SetProj( myCurrentItem.projX, myCurrentItem.projY, myCurrentItem.projZ );
142 aView3d->SetTwist( myCurrentItem.twist );
143 aView3d->SetAt( myCurrentItem.atX, myCurrentItem.atY, myCurrentItem.atZ );
144 aView3d->SetImmediateUpdate( prev );
145 aView3d->SetEye( myCurrentItem.eyeX, myCurrentItem.eyeY, myCurrentItem.eyeZ );
149 viewAspect OCCViewer_CreateRestoreViewDlg::currentItem() const
151 return myCurrentItem;
154 void OCCViewer_CreateRestoreViewDlg::deleteSelectedItems()
156 if( myListBox->count() && myListBox->isEditEnabled() )
159 for( int i = 0; i < myListBox->count(); i++ )
160 if( myListBox->isSelected( i ) )
162 myListBox->removeItem( i );
163 for( int j = i; j < myParametersMap.count(); j++ )
164 if( j != myParametersMap.count() - 1 )
165 myParametersMap[ j ] = myParametersMap[ j + 1 ];
167 myParametersMap.remove( myParametersMap.at(j) );
168 if( i != myListBox->count() )
176 myListBox->setCurrentItem( curIndex );
177 changeImage( myListBox->item( curIndex ) );
180 if( !myListBox->count() )
183 myListBox->insertItem( "No Items", 0 );
184 myListBox->setEditEnabled( 0 );
188 void OCCViewer_CreateRestoreViewDlg::clearList()
191 myListBox->insertItem( "No Items", 0 );
192 myListBox->setEditEnabled( 0 );
194 myParametersMap.clear();
197 const viewAspectList& OCCViewer_CreateRestoreViewDlg::parameters() const
199 return myParametersMap;
202 void OCCViewer_CreateRestoreViewDlg::editItemText( QListBoxItem* anItem )
204 int index = anItem->listBox()->index( anItem );
205 myParametersMap[ index ].name = anItem->text().latin1();
208 bool OCCViewer_CreateRestoreViewDlg::eventFilter( QObject* anObj, QEvent* anEv )
210 if( anEv->type() == QEvent::KeyPress )
212 QKeyEvent* aKeyEv = ( QKeyEvent* )anEv;
213 if( aKeyEv->key() == Qt::Key_Control )
216 myListBox->setSelectionMode( QListBox::Multi );
218 else if( aKeyEv->key() == Qt::Key_Shift )
221 myListBox->setSelectionMode( QListBox::Multi );
224 myListBox->setSelectionMode( QListBox::Single );
226 if( anEv->type() == QEvent::KeyRelease )
231 if( anEv->type() == QEvent::KeyPress || anEv->type() == QEvent::MouseButtonPress )
232 myListBox->setSelectionMode( QListBox::Single );
234 return QWidget::eventFilter( anObj, anEv );
237 void OCCViewer_CreateRestoreViewDlg::OKpressed()