1 #include "ViewOperations.h"
3 //#include "Material.h"
4 //#include "Transparency.h"
5 #include "Application.h"
8 #include <qcolordialog.h>
9 #include <qapplication.h>
10 #include <qsignalmapper.h>
11 #include <qworkspace.h>
16 #include <V3d_TypeOfView.hxx>
17 #include <AIS_InteractiveObject.hxx>
18 #include <AIS_ListOfInteractive.hxx>
19 #include <AIS_ListIteratorOfListOfInteractive.hxx>
21 #include <Quantity_Color.hxx>
24 static QCursor* defCursor = NULL;
25 static QCursor* handCursor = NULL;
26 static QCursor* panCursor = NULL;
27 static QCursor* zoomCursor = NULL;
28 static QCursor* rotCursor = NULL;
30 ViewOperations::ViewOperations( QObject* parent)
36 ViewOperations::ViewOperations( Handle(AIS_InteractiveContext) theContext,
40 myContext = theContext;
45 ViewOperations::~ViewOperations()
50 void ViewOperations::onWireframe()
52 AIS_ListOfInteractive displayed;
53 myContext->DisplayedObjects( displayed );
54 AIS_ListIteratorOfListOfInteractive it( displayed );
55 for ( ; it.More(); it.Next() )
56 myContext->SetDisplayMode( it.Value(), 0 );
58 for(myContext->InitCurrent();myContext->MoreCurrent();myContext->NextCurrent())
59 myContext->SetDisplayMode(myContext->Current(),0);
63 void ViewOperations::onShading()
65 QApplication::setOverrideCursor( Qt::WaitCursor );
67 AIS_ListOfInteractive displayed;
68 myContext->DisplayedObjects( displayed );
69 AIS_ListIteratorOfListOfInteractive it( displayed );
70 for ( ; it.More(); it.Next() )
71 myContext->SetDisplayMode( it.Value(), 1 );
74 for(myContext->InitCurrent();myContext->MoreCurrent();myContext->NextCurrent())
75 myContext->SetDisplayMode(myContext->Current(),1);
77 QApplication::restoreOverrideCursor();
80 void ViewOperations::initActions()
86 void ViewOperations::initCursors()
89 defCursor = new QCursor( Qt::ArrowCursor );
91 handCursor = new QCursor( Qt::PointingHandCursor );
93 panCursor = new QCursor( Qt::SizeAllCursor );
95 QString dir( Application::getResourceDir() );
97 zoomCursor = new QCursor( QPixmap( dir + tr( "ICON_CURSOR_ZOOM" ) ) );
99 rotCursor = new QCursor( QPixmap( dir + tr( "ICON_CURSOR_ROTATE" ) ) );
102 QList<QAction*> ViewOperations::getViewActions()
104 return myViewActions;
107 void ViewOperations::initViewActions()
109 if ( myViewActions.count() )
112 QString dir = Application::getResourceDir();
116 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_FITALL" ) ), "", this );
117 a->setToolTip( tr( "TBR_FITALL" ) );
118 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
119 myViewActions.insert( ViewFitAllId, a );
121 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_FITAREA" ) ), "", this );
122 a->setToolTip( tr( "TBR_FITAREA" ) );
123 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
124 a->setCheckable( true );
125 verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
126 myViewActions.insert( ViewFitAreaId, a );
128 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_ZOOM" ) ), "", this );
129 a->setToolTip( tr( "TBR_ZOOM" ) );
130 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
131 a->setCheckable( true );
132 verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
133 myViewActions.insert( ViewZoomId, a );
135 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_PAN" ) ), "", this );
136 a->setToolTip( tr( "TBR_PAN" ) );
137 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
138 a->setCheckable( true );
139 verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
140 myViewActions.insert( ViewPanId, a );
142 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_GLOBALPAN" ) ), "", this );
143 a->setToolTip( tr( "TBR_GLOBALPAN" ) );
144 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
145 a->setCheckable( true );
146 verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
147 myViewActions.insert( ViewGlobalPanId, a );
149 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_FRONT" ) ), "", this );
150 a->setToolTip( tr( "TBR_FRONT" ) );
151 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
152 myViewActions.insert( ViewFrontId, a );
154 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_BACK" ) ), "", this );
155 a->setToolTip( tr( "TBR_BACK" ) );
156 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
157 myViewActions.insert( ViewBackId, a );
159 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_TOP" ) ), "", this );
160 a->setToolTip( tr( "TBR_TOP" ) );
161 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
162 myViewActions.insert( ViewTopId, a );
164 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_BOTTOM" ) ), "", this );
165 a->setToolTip( tr( "TBR_BOTTOM" ) );
166 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
167 myViewActions.insert( ViewBottomId, a );
169 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_LEFT" ) ), "", this );
170 a->setToolTip( tr( "TBR_LEFT" ) );
171 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
172 myViewActions.insert( ViewLeftId, a );
174 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_RIGHT" ) ), "", this );
175 a->setToolTip( tr( "TBR_RIGHT" ) );
176 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
177 myViewActions.insert( ViewRightId, a );
179 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_AXO" ) ), "", this );
180 a->setToolTip( tr( "TBR_AXO" ) );
181 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
182 myViewActions.insert( ViewAxoId, a );
184 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_ROTATION" ) ), "", this );
185 a->setToolTip( tr( "TBR_ROTATION" ) );
186 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
187 a->setCheckable( true );
188 verify( connect( a, SIGNAL( toggled( bool ) ), SLOT( updateToggled( bool ) ) ) );
189 myViewActions.insert( ViewRotationId, a );
191 a = new QAction( QPixmap( dir + tr( "ICON_VIEW_RESET" ) ), "", this );
192 a->setToolTip( tr( "TBR_RESET" ) );
193 verify( connect( a, SIGNAL( activated() ), SLOT( onActionActivated() ) ) );
194 myViewActions.insert( ViewResetId, a );
197 void ViewOperations::updateToggled( bool isOn )
202 QAction* sentBy = (QAction*) sender();
204 for ( int i = ViewFitAllId;i <= ViewResetId ; i++)
206 QAction* anAction = myViewActions.at(i);
207 if( (anAction == myViewActions.at(ViewFitAreaId)) ||
208 (anAction == myViewActions.at(ViewZoomId)) ||
209 (anAction == myViewActions.at(ViewPanId)) ||
210 (anAction == myViewActions.at(ViewGlobalPanId)) ||
211 (anAction == myViewActions.at(ViewRotationId))) {
212 if (anAction && (anAction != sentBy)) {
213 anAction->setCheckable(true);
214 anAction->setChecked(false);
216 if(sentBy == myViewActions.at(ViewFitAreaId))
217 emit setCursor(*handCursor);
218 else if (sentBy == myViewActions.at(ViewZoomId))
219 emit setCursor(*zoomCursor);
220 else if (sentBy == myViewActions.at(ViewPanId))
221 emit setCursor(*panCursor);
222 else if (sentBy == myViewActions.at(ViewGlobalPanId))
223 emit setCursor(*defCursor);
224 else if (sentBy == myViewActions.at(ViewRotationId))
225 emit setCursor(*rotCursor);
226 sentBy->setCheckable(false);
232 QList<QAction*> ViewOperations::getToolActions()
235 return myToolActions;
238 void ViewOperations::initToolActions()
240 if( myToolActions.count() )
243 QString dir = Application::getResourceDir();
245 //QAction* a = new QAction( tr( "TBR_TOOL_MAGVIEW" ), QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ),
247 //verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
248 //myToolActions->insert( MagViewId, a );
250 // QAction* a = new QAction( tr( "TBR_TOOL_AXOVIEW" ), QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ),
252 // verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
253 // myToolActions->insert( AxoViewId, a );
255 // a = new QAction( tr( "TBR_TOOL_PERVIEW" ), QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ),
257 // verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
258 // myToolActions->insert( PerViewId, a );
260 QAction* a = new QAction( QPixmap( dir + tr( "ICON_TOOL_WIRE" ) ), "", this );
261 a->setToolTip( tr( "TBR_TOOL_WIRE" ) );
262 a->setCheckable( true );
263 verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
264 myToolActions.insert( ToolWireframeId, a );
266 a = new QAction( QPixmap( dir + tr( "ICON_TOOL_SHAD") ), "", this );
267 a->setToolTip( tr( "TBR_TOOL_SHAD" ) );
268 a->setCheckable( true );
269 a->setChecked( true );
270 verify( connect( a, SIGNAL( activated() ), SLOT( onToolAction() ) ) );
271 myToolActions.insert( ToolShadingId, a );
274 void ViewOperations::onToolAction()
276 QAction* sentBy = (QAction*) sender();
277 //MDIWindow* win = (MDIWindow*) Application::getWorkspace()->activeWindow();
278 MDIWindow* win = (MDIWindow*)Application::getApplication()->getActiveMDI();
279 Document* doc = win->getDocument();
281 // if( sentBy == myToolActions->at( MagViewId ) )
282 // win->defineMagView();
284 // if( sentBy == myToolActions->at( PerViewId ) )
285 // doc->createNewView( V3d_PERSPECTIVE );
287 // if( sentBy == myToolActions->at( AxoViewId ) )
288 // doc->createNewView();
290 if( sentBy == myToolActions.at( ToolWireframeId ) )
293 if( sentBy == myToolActions.at( ToolShadingId ) )
297 int ViewOperations::getDisplayMode()
299 bool on = myToolActions.at( ToolWireframeId )->isChecked();
303 void ViewOperations::onNoActiveActions()
305 for ( int i = ViewFitAllId;i <= ViewResetId ; i++ ) {
306 QAction* anAction = myViewActions.at( i );
307 if( ( anAction == myViewActions.at( ViewFitAreaId ) ) ||
308 ( anAction == myViewActions.at( ViewZoomId ) ) ||
309 ( anAction == myViewActions.at( ViewPanId ) ) ||
310 ( anAction == myViewActions.at( ViewGlobalPanId ) ) ||
311 ( anAction == myViewActions.at( ViewRotationId ) ) ) {
313 emit setCursor( *defCursor );
314 anAction->setCheckable( true );
315 anAction->setChecked( false );
320 void ViewOperations::onActionActivated()
322 QAction* a = (QAction*) sender();
323 //MDIWindow* win = (MDIWindow*) Application::getWorkspace()->activeWindow();
324 MDIWindow* win = (MDIWindow*) Application::getApplication()->getActiveMDI();
325 int index = myViewActions.indexOf( a );
327 win->activateAction( (Action)index );