1 #include "OCCViewer_CreateRestoreViewDlg.h"
2 #include "OCCViewer_ViewModel.h"
3 #include "OCCViewer_ViewPort3d.h"
5 #include <qpushbutton.h>
10 OCCViewer_CreateRestoreViewDlg::OCCViewer_CreateRestoreViewDlg( QWidget* aWin, OCCViewer_Viewer* curModel )
13 setCaption( tr( "CAPTION" ) );
15 myParametersMap = curModel->getViewAspects();
19 int aQuantityOfItems = myParametersMap.count();
21 setFixedSize( 400, 300 );
23 QGridLayout* aGrid = new QGridLayout( this, 2, 1, 5, 10 );
25 QWidget* aWidget1 = new QWidget( this );
26 QWidget* aWidget2 = new QWidget( this );
28 QHBoxLayout* aLayout = new QHBoxLayout( aWidget1 );
30 myListBox = new QtxListBox( aWidget1 );
31 myListBox->installEventFilter( this );
33 myCurViewPort = new OCCViewer_ViewPort3d( aWidget1, curModel->getViewer3d(), V3d_ORTHOGRAPHIC );
34 myCurViewPort->getView()->SetBackgroundColor( Quantity_NOC_BLACK );
36 myListBox->setEditEnabled( 1 );
38 if ( aQuantityOfItems )
41 for( int i = 0; i < aQuantityOfItems; i++ )
42 myListBox->insertItem( myParametersMap[ i ].name );
44 changeImage( myListBox->item( 0 ) );
49 myListBox->insertItem( "No Items", 0 );
50 myListBox->setEditEnabled( 0 );
53 connect( myListBox, SIGNAL( clicked( QListBoxItem* ) ), this, SLOT( changeImage( QListBoxItem* ) ) );
54 connect( myListBox, SIGNAL( itemEdited( QListBoxItem* ) ), this, SLOT( editItemText( QListBoxItem* ) ) );
56 aLayout->addWidget( myListBox );
57 aLayout->addWidget( myCurViewPort, 30 );
59 QHBoxLayout* aButtonLayout = new QHBoxLayout( aWidget2, 0, 5 );
61 QPushButton* theOk = new QPushButton( tr( "Ok" ), aWidget2 ); theOk->setAutoDefault( false );
62 QPushButton* theCancel = new QPushButton( tr( "Cancel" ), aWidget2 ); theCancel->setAutoDefault( false );
63 QPushButton* theDelete = new QPushButton( tr( "Delete" ), aWidget2 ); theDelete->setAutoDefault( false );
64 QPushButton* theClearAll = new QPushButton( tr( "Clear List" ), aWidget2 ); theClearAll->setAutoDefault( false );
66 aButtonLayout->addWidget( theOk );
67 aButtonLayout->addWidget( theCancel );
68 aButtonLayout->addWidget( theDelete );
69 aButtonLayout->addWidget( theClearAll );
71 aGrid->addWidget( aWidget1, 0, 0 );
72 aGrid->addWidget( aWidget2, 1, 0 );
74 connect( theOk, SIGNAL( clicked() ), this, SLOT( OKpressed() ) );
75 connect( theCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
76 connect( theDelete, SIGNAL( clicked() ), this, SLOT( deleteSelectedItems() ) );
77 connect( theClearAll, SIGNAL( clicked() ), this, SLOT( clearList() ) );
80 OCCViewer_CreateRestoreViewDlg::~OCCViewer_CreateRestoreViewDlg()
84 void OCCViewer_CreateRestoreViewDlg::changeImage( QListBoxItem* curItem )
86 if( curItem && myListBox->isEditEnabled() )
90 int index = curItem->listBox()->index( curItem );
93 for( int i = 0; i < myListBox->count(); i++ )
95 if( myListBox->isSelected( i ) && i != index )
97 myListBox->clearSelection();
108 for( int j = lowLevel; j <= highLevel; j++ )
109 myListBox->setSelected( j, TRUE );
112 if( myListBox->isSelected( i ) && i == index )
113 myListBox->setSelected( i, TRUE );
117 Handle(V3d_View) aView3d = myCurViewPort->getView();
118 myCurrentItem = myParametersMap[ index ];
120 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
121 aView3d->SetScale( myCurrentItem.scale );
122 aView3d->SetCenter( myCurrentItem.centerX, myCurrentItem.centerY );
123 aView3d->SetProj( myCurrentItem.projX, myCurrentItem.projY, myCurrentItem.projZ );
124 aView3d->SetTwist( myCurrentItem.twist );
125 aView3d->SetAt( myCurrentItem.atX, myCurrentItem.atY, myCurrentItem.atZ );
126 aView3d->SetImmediateUpdate( prev );
127 aView3d->SetEye( myCurrentItem.eyeX, myCurrentItem.eyeY, myCurrentItem.eyeZ );
131 viewAspect OCCViewer_CreateRestoreViewDlg::currentItem() const
133 return myCurrentItem;
136 void OCCViewer_CreateRestoreViewDlg::deleteSelectedItems()
138 if( myListBox->count() && myListBox->isEditEnabled() )
141 for( int i = 0; i < myListBox->count(); i++ )
142 if( myListBox->isSelected( i ) )
144 myListBox->removeItem( i );
145 for( int j = i; j < myParametersMap.count(); j++ )
146 if( j != myParametersMap.count() - 1 )
147 myParametersMap[ j ] = myParametersMap[ j + 1 ];
149 myParametersMap.remove( myParametersMap.at(j) );
150 if( i != myListBox->count() )
158 myListBox->setCurrentItem( curIndex );
159 changeImage( myListBox->item( curIndex ) );
162 if( !myListBox->count() )
165 myListBox->insertItem( "No Items", 0 );
166 myListBox->setEditEnabled( 0 );
170 void OCCViewer_CreateRestoreViewDlg::clearList()
173 myListBox->insertItem( "No Items", 0 );
174 myListBox->setEditEnabled( 0 );
176 myParametersMap.clear();
179 const viewAspectList& OCCViewer_CreateRestoreViewDlg::parameters() const
181 return myParametersMap;
184 void OCCViewer_CreateRestoreViewDlg::editItemText( QListBoxItem* anItem )
186 int index = anItem->listBox()->index( anItem );
187 myParametersMap[ index ].name = anItem->text().latin1();
190 bool OCCViewer_CreateRestoreViewDlg::eventFilter( QObject* anObj, QEvent* anEv )
192 if( anEv->type() == QEvent::KeyPress )
194 QKeyEvent* aKeyEv = ( QKeyEvent* )anEv;
195 if( aKeyEv->key() == Qt::Key_Control )
198 myListBox->setSelectionMode( QListBox::Multi );
200 else if( aKeyEv->key() == Qt::Key_Shift )
203 myListBox->setSelectionMode( QListBox::Multi );
206 myListBox->setSelectionMode( QListBox::Single );
208 if( anEv->type() == QEvent::KeyRelease )
213 if( anEv->type() == QEvent::KeyPress || anEv->type() == QEvent::MouseButtonPress )
214 myListBox->setSelectionMode( QListBox::Single );
216 return QWidget::eventFilter( anObj, anEv );
219 void OCCViewer_CreateRestoreViewDlg::OKpressed()