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>
31 OCCViewer_CreateRestoreViewDlg::OCCViewer_CreateRestoreViewDlg( QWidget* aWin, OCCViewer_Viewer* curModel )
34 setCaption( tr( "CAPTION" ) );
36 myParametersMap = curModel->getViewAspects();
40 int aQuantityOfItems = myParametersMap.count();
42 setFixedSize( 400, 300 );
44 QGridLayout* aGrid = new QGridLayout( this, 2, 1, 5, 10 );
46 QWidget* aWidget1 = new QWidget( this );
47 QWidget* aWidget2 = new QWidget( this );
49 QHBoxLayout* aLayout = new QHBoxLayout( aWidget1 );
51 myListBox = new QtxListBox( aWidget1 );
52 myListBox->installEventFilter( this );
54 myCurViewPort = new OCCViewer_ViewPort3d( aWidget1, curModel->getViewer3d(), V3d_ORTHOGRAPHIC );
55 myCurViewPort->getView()->SetBackgroundColor( Quantity_NOC_BLACK );
57 myListBox->setEditEnabled( 1 );
59 if ( aQuantityOfItems )
62 for( int i = 0; i < aQuantityOfItems; i++ )
63 myListBox->insertItem( myParametersMap[ i ].name );
65 changeImage( myListBox->item( 0 ) );
70 myListBox->insertItem( "No Items", 0 );
71 myListBox->setEditEnabled( 0 );
74 connect( myListBox, SIGNAL( clicked( QListBoxItem* ) ), this, SLOT( changeImage( QListBoxItem* ) ) );
75 connect( myListBox, SIGNAL( itemEdited( QListBoxItem* ) ), this, SLOT( editItemText( QListBoxItem* ) ) );
77 aLayout->addWidget( myListBox );
78 aLayout->addWidget( myCurViewPort, 30 );
80 QHBoxLayout* aButtonLayout = new QHBoxLayout( aWidget2, 0, 5 );
82 QPushButton* theOk = new QPushButton( tr( "Ok" ), aWidget2 ); theOk->setAutoDefault( false );
83 QPushButton* theCancel = new QPushButton( tr( "Cancel" ), aWidget2 ); theCancel->setAutoDefault( false );
84 QPushButton* theDelete = new QPushButton( tr( "Delete" ), aWidget2 ); theDelete->setAutoDefault( false );
85 QPushButton* theClearAll = new QPushButton( tr( "Clear List" ), aWidget2 ); theClearAll->setAutoDefault( false );
87 aButtonLayout->addWidget( theOk );
88 aButtonLayout->addWidget( theCancel );
89 aButtonLayout->addWidget( theDelete );
90 aButtonLayout->addWidget( theClearAll );
92 aGrid->addWidget( aWidget1, 0, 0 );
93 aGrid->addWidget( aWidget2, 1, 0 );
95 connect( theOk, SIGNAL( clicked() ), this, SLOT( OKpressed() ) );
96 connect( theCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
97 connect( theDelete, SIGNAL( clicked() ), this, SLOT( deleteSelectedItems() ) );
98 connect( theClearAll, SIGNAL( clicked() ), this, SLOT( clearList() ) );
104 OCCViewer_CreateRestoreViewDlg::~OCCViewer_CreateRestoreViewDlg()
109 Changes image in accordance with item
110 \param curItem - item contains info about view parameters
112 void OCCViewer_CreateRestoreViewDlg::changeImage( QListBoxItem* curItem )
114 if( curItem && myListBox->isEditEnabled() )
118 int index = curItem->listBox()->index( curItem );
121 for( int i = 0; i < myListBox->count(); i++ )
123 if( myListBox->isSelected( i ) && i != index )
125 myListBox->clearSelection();
136 for( int j = lowLevel; j <= highLevel; j++ )
137 myListBox->setSelected( j, TRUE );
140 if( myListBox->isSelected( i ) && i == index )
141 myListBox->setSelected( i, TRUE );
145 Handle(V3d_View) aView3d = myCurViewPort->getView();
146 myCurrentItem = myParametersMap[ index ];
148 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
149 aView3d->SetScale( myCurrentItem.scale );
150 aView3d->SetCenter( myCurrentItem.centerX, myCurrentItem.centerY );
151 aView3d->SetProj( myCurrentItem.projX, myCurrentItem.projY, myCurrentItem.projZ );
152 aView3d->SetTwist( myCurrentItem.twist );
153 aView3d->SetAt( myCurrentItem.atX, myCurrentItem.atY, myCurrentItem.atZ );
154 aView3d->SetImmediateUpdate( prev );
155 aView3d->SetEye( myCurrentItem.eyeX, myCurrentItem.eyeY, myCurrentItem.eyeZ );
160 \return current view parameters (corresponding to current item)
162 viewAspect OCCViewer_CreateRestoreViewDlg::currentItem() const
164 return myCurrentItem;
168 Deletes selected items from list view
170 void OCCViewer_CreateRestoreViewDlg::deleteSelectedItems()
172 if( myListBox->count() && myListBox->isEditEnabled() )
175 for( int i = 0; i < myListBox->count(); i++ )
176 if( myListBox->isSelected( i ) )
178 myListBox->removeItem( i );
179 for( int j = i; j < myParametersMap.count(); j++ )
180 if( j != myParametersMap.count() - 1 )
181 myParametersMap[ j ] = myParametersMap[ j + 1 ];
183 myParametersMap.remove( myParametersMap.at(j) );
184 if( i != myListBox->count() )
192 myListBox->setCurrentItem( curIndex );
193 changeImage( myListBox->item( curIndex ) );
196 if( !myListBox->count() )
199 myListBox->insertItem( "No Items", 0 );
200 myListBox->setEditEnabled( 0 );
205 Clears list of view aspects
207 void OCCViewer_CreateRestoreViewDlg::clearList()
210 myListBox->insertItem( "No Items", 0 );
211 myListBox->setEditEnabled( 0 );
213 myParametersMap.clear();
217 \return const reference to all view aspects
219 const viewAspectList& OCCViewer_CreateRestoreViewDlg::parameters() const
221 return myParametersMap;
225 Renames key of view aspect map in accordance with item name
228 void OCCViewer_CreateRestoreViewDlg::editItemText( QListBoxItem* anItem )
230 int index = anItem->listBox()->index( anItem );
231 myParametersMap[ index ].name = anItem->text().latin1();
237 bool OCCViewer_CreateRestoreViewDlg::eventFilter( QObject* anObj, QEvent* anEv )
239 if( anEv->type() == QEvent::KeyPress )
241 QKeyEvent* aKeyEv = ( QKeyEvent* )anEv;
242 if( aKeyEv->key() == Qt::Key_Control )
245 myListBox->setSelectionMode( QListBox::Multi );
247 else if( aKeyEv->key() == Qt::Key_Shift )
250 myListBox->setSelectionMode( QListBox::Multi );
253 myListBox->setSelectionMode( QListBox::Single );
255 if( anEv->type() == QEvent::KeyRelease )
260 if( anEv->type() == QEvent::KeyPress || anEv->type() == QEvent::MouseButtonPress )
261 myListBox->setSelectionMode( QListBox::Single );
263 return QWidget::eventFilter( anObj, anEv );
267 SLOT: called on OK click, emits dlgOk() and closes dialog
269 void OCCViewer_CreateRestoreViewDlg::OKpressed()