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 myParametersMap = curModel->getViewAspects();
17 int aQuantityOfItems = myParametersMap.count();
19 setFixedSize( 400, 300 );
21 QGridLayout* aGrid = new QGridLayout( this, 2, 1, 5, 10 );
23 QWidget* aWidget1 = new QWidget( this );
24 QWidget* aWidget2 = new QWidget( this );
26 QHBoxLayout* aLayout = new QHBoxLayout( aWidget1 );
28 myListBox = new QtxListBox( aWidget1 );
29 myListBox->installEventFilter( this );
31 myCurViewPort = new OCCViewer_ViewPort3d( aWidget1, curModel->getViewer3d(), V3d_ORTHOGRAPHIC );
32 myCurViewPort->getView()->SetBackgroundColor( Quantity_NOC_BLACK );
34 myListBox->setEditEnabled( 1 );
36 if( aQuantityOfItems )
39 for( int i = 0; i < aQuantityOfItems; i++ )
40 myListBox->insertItem( myParametersMap[ i ].name );
42 changeImage( myListBox->item( 0 ) );
47 myListBox->insertItem( "No Items", 0 );
48 myListBox->setEditEnabled( 0 );
51 connect( myListBox, SIGNAL( clicked( QListBoxItem* ) ), this, SLOT( changeImage( QListBoxItem* ) ) );
52 connect( myListBox, SIGNAL( itemEdited( QListBoxItem* ) ), this, SLOT( editItemText( QListBoxItem* ) ) );
54 aLayout->addWidget( myListBox );
55 aLayout->addWidget( myCurViewPort, 30 );
57 QHBoxLayout* aButtonLayout = new QHBoxLayout( aWidget2, 0, 5 );
59 QPushButton* theOk = new QPushButton( tr( "Ok" ), aWidget2 ); theOk->setAutoDefault( false );
60 QPushButton* theCancel = new QPushButton( tr( "Cancel" ), aWidget2 ); theCancel->setAutoDefault( false );
61 QPushButton* theDelete = new QPushButton( tr( "Delete" ), aWidget2 ); theDelete->setAutoDefault( false );
62 QPushButton* theClearAll = new QPushButton( tr( "Clear List" ), aWidget2 ); theClearAll->setAutoDefault( false );
64 aButtonLayout->addWidget( theOk );
65 aButtonLayout->addWidget( theCancel );
66 aButtonLayout->addWidget( theDelete );
67 aButtonLayout->addWidget( theClearAll );
69 aGrid->addWidget( aWidget1, 0, 0 );
70 aGrid->addWidget( aWidget2, 1, 0 );
72 connect( theOk, SIGNAL( clicked() ), this, SLOT( OKpressed() ) );
73 connect( theCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
74 connect( theDelete, SIGNAL( clicked() ), this, SLOT( deleteSelectedItems() ) );
75 connect( theClearAll, SIGNAL( clicked() ), this, SLOT( clearList() ) );
78 OCCViewer_CreateRestoreViewDlg::~OCCViewer_CreateRestoreViewDlg()
82 void OCCViewer_CreateRestoreViewDlg::changeImage( QListBoxItem* curItem )
84 if( curItem && myListBox->isEditEnabled() )
88 int index = curItem->listBox()->index( curItem );
91 for( int i = 0; i < myListBox->count(); i++ )
93 if( myListBox->isSelected( i ) && i != index )
95 myListBox->clearSelection();
106 for( int j = lowLevel; j <= highLevel; j++ )
107 myListBox->setSelected( j, TRUE );
110 if( myListBox->isSelected( i ) && i == index )
111 myListBox->setSelected( i, TRUE );
115 Handle(V3d_View) aView3d = myCurViewPort->getView();
116 myCurrentItem = myParametersMap[ index ];
118 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
119 aView3d->SetScale( myCurrentItem.scale );
120 aView3d->SetCenter( myCurrentItem.centerX, myCurrentItem.centerY );
121 aView3d->SetProj( myCurrentItem.projX, myCurrentItem.projY, myCurrentItem.projZ );
122 aView3d->SetTwist( myCurrentItem.twist );
123 aView3d->SetAt( myCurrentItem.atX, myCurrentItem.atY, myCurrentItem.atZ );
124 aView3d->SetImmediateUpdate( prev );
125 aView3d->SetEye( myCurrentItem.eyeX, myCurrentItem.eyeY, myCurrentItem.eyeZ );
129 viewAspect OCCViewer_CreateRestoreViewDlg::currentItem() const
131 return myCurrentItem;
134 void OCCViewer_CreateRestoreViewDlg::deleteSelectedItems()
136 if( myListBox->count() && myListBox->isEditEnabled() )
139 for( int i = 0; i < myListBox->count(); i++ )
140 if( myListBox->isSelected( i ) )
142 myListBox->removeItem( i );
143 for( int j = i; j < myParametersMap.count(); j++ )
144 if( j != myParametersMap.count() - 1 )
145 myParametersMap[ j ] = myParametersMap[ j + 1 ];
147 myParametersMap.remove( myParametersMap.at(j) );
148 if( i != myListBox->count() )
156 myListBox->setCurrentItem( curIndex );
157 changeImage( myListBox->item( curIndex ) );
160 if( !myListBox->count() )
163 myListBox->insertItem( "No Items", 0 );
164 myListBox->setEditEnabled( 0 );
168 void OCCViewer_CreateRestoreViewDlg::clearList()
171 myListBox->insertItem( "No Items", 0 );
172 myListBox->setEditEnabled( 0 );
174 myParametersMap.clear();
177 const viewAspectList& OCCViewer_CreateRestoreViewDlg::parameters() const
179 return myParametersMap;
182 void OCCViewer_CreateRestoreViewDlg::editItemText( QListBoxItem* anItem )
184 int index = anItem->listBox()->index( anItem );
185 myParametersMap[ index ].name = anItem->text().latin1();
188 bool OCCViewer_CreateRestoreViewDlg::eventFilter( QObject* anObj, QEvent* anEv )
190 if( anEv->type() == QEvent::KeyPress )
192 QKeyEvent* aKeyEv = ( QKeyEvent* )anEv;
193 if( aKeyEv->key() == Qt::Key_Control )
196 myListBox->setSelectionMode( QListBox::Multi );
198 else if( aKeyEv->key() == Qt::Key_Shift )
201 myListBox->setSelectionMode( QListBox::Multi );
204 myListBox->setSelectionMode( QListBox::Single );
206 if( anEv->type() == QEvent::KeyRelease )
211 if( anEv->type() == QEvent::KeyPress || anEv->type() == QEvent::MouseButtonPress )
212 myListBox->setSelectionMode( QListBox::Single );
214 return QWidget::eventFilter( anObj, anEv );
217 void OCCViewer_CreateRestoreViewDlg::OKpressed()