00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <QtGui/QMouseEvent>
00035
00036 #include <qnamespace.h>
00037 #include "qoccdocument.h"
00038 #include "qocccommands.h"
00039 #include "qocccontroller.h"
00040 #include "qocc3dwidget.h"
00041 #include "qoccinternal.h"
00042
00043 QoccController::QoccController()
00044 {
00045
00046 TCollection_ExtendedString a3DName( "Visual3D" );
00047 myViewer = createViewer( "DISPLAY", a3DName.ToExtString(), "", 1000.0 );
00048 myViewer->Init();
00049 myViewer->SetZBufferManagment( Standard_False );
00050 myViewer->SetDefaultViewProj( V3d_Zpos );
00051 myContext = new AIS_InteractiveContext( myViewer );
00052
00053 myGridType = Aspect_GT_Rectangular;
00054 myGridMode = Aspect_GDM_Lines;
00055 myGridColor = Quantity_NOC_RED4;
00056 myGridTenthColor = Quantity_NOC_GRAY90;
00057 myCommand = NULL;
00058 myDocument = NULL;
00059 myIsDrawing = false;
00060 myLcType = TopAbs_COMPOUND;
00061
00062
00063
00064 myContext->HiddenLineAspect();
00065
00066 setGridOffset ( 0.0 );
00067 gridXY();
00068 gridOn();
00069 }
00070
00071 QoccController::QoccController( QoccDocument* qDoc )
00072 {
00073
00074 TCollection_ExtendedString a3DName( "Visual3D" );
00075 myViewer = createViewer( "DISPLAY", a3DName.ToExtString(), "", 1000.0 );
00076 myViewer->Init();
00077 myViewer->SetZBufferManagment( Standard_False );
00078 myViewer->SetDefaultViewProj( V3d_Zpos );
00079
00080 TPrsStd_AISViewer::New ( qDoc->getDocument()->Main(), myViewer );
00081 TPrsStd_AISViewer::Find( qDoc->getDocument()->Main(), myContext );
00082
00083 myContext->SetDisplayMode(AIS_Shaded);
00084 myContext->HiddenLineAspect();
00085
00086 myGridType = Aspect_GT_Rectangular;
00087 myGridMode = Aspect_GDM_Lines;
00088 myGridColor = Quantity_NOC_RED4;
00089 myGridTenthColor = Quantity_NOC_GRAY90;
00090 myCommand = NULL;
00091 myDocument = qDoc;
00092 myIsDrawing = false;
00093 myLcType = TopAbs_COMPOUND;
00094
00095 setGridOffset ( 0.0 );
00096 gridXY();
00097 gridOn();
00098 }
00099
00100 QoccController::~QoccController()
00101 {
00102 if (myCommand)
00103 {
00104 delete myCommand;
00105 }
00106 }
00107
00108 #ifndef WNT
00109 Handle(V3d_Viewer) QoccController::createViewer( const Standard_CString aDisplay,
00110 const Standard_ExtString aName,
00111 const Standard_CString aDomain,
00112 const Standard_Real ViewSize )
00113 {
00114 static Handle(Graphic3d_GraphicDevice) defaultdevice;
00115
00116 if( defaultdevice.IsNull() )
00117 {
00118 defaultdevice = new Graphic3d_GraphicDevice( getenv(aDisplay) );
00119 }
00120
00121 return new V3d_Viewer( defaultdevice,
00122 aName,
00123 aDomain,
00124 ViewSize,
00125 V3d_XposYnegZpos,
00126 Quantity_NOC_BLACK,
00127 V3d_ZBUFFER,
00128 V3d_GOURAUD,
00129 V3d_WAIT );
00130 }
00131 #else
00132 Handle(V3d_Viewer) QoccController::createViewer( const Standard_CString ,
00133 const Standard_ExtString aName,
00134 const Standard_CString aDomain,
00135 const Standard_Real ViewSize )
00136 {
00137 static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
00138 if( defaultdevice.IsNull() )
00139 {
00140 defaultdevice = new Graphic3d_WNTGraphicDevice();
00141 }
00142
00143 return new V3d_Viewer( defaultdevice,
00144 aName,
00145 aDomain,
00146 ViewSize,
00147 V3d_XposYnegZpos,
00148 Quantity_NOC_BLACK,
00149 V3d_ZBUFFER,
00150 V3d_GOURAUD,
00151 V3d_WAIT );
00152 }
00153 #endif // WNT
00154
00155 bool QoccController::isDrawing()
00156 {
00157 if (myCommand)
00158 {
00159 return myCommand->isDrawing();
00160 }
00161 else
00162 {
00163 return false;
00164 }
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 void QoccController::deleteAllObjects()
00174 {
00175 AIS_ListOfInteractive aList;
00176 myContext->DisplayedObjects( aList );
00177 AIS_ListIteratorOfListOfInteractive aListIterator;
00178 for ( aListIterator.Initialize( aList ); aListIterator.More(); aListIterator.Next() )
00179 {
00180 myContext->Remove( aListIterator.Value(), Standard_False);
00181 }
00182 }
00183
00184
00185
00186 void QoccController::gridXY ( void )
00187 {
00188 myGridColor = Quantity_NOC_RED4;
00189 myViewer->Grid()->SetColors( myGridColor, myGridTenthColor );
00190 gp_Ax3 aPlane(gp_Pnt( 0., 0., 0. ),gp_Dir(0., 0., 1.));
00191 myViewer->SetPrivilegedPlane( aPlane );
00192 }
00193
00194
00195
00196
00197
00198
00199 void QoccController::gridXZ ( void )
00200 {
00201 myGridColor = Quantity_NOC_BLUE4;
00202 myViewer->Grid()->SetColors( myGridColor, myGridTenthColor );
00203 gp_Ax3 aPlane( gp_Pnt(0., 0., 0.),gp_Dir(0., -1., 0.) );
00204 myViewer->SetPrivilegedPlane( aPlane );
00205 }
00206
00207
00208
00209 void QoccController::gridYZ ( void )
00210 {
00211 myGridColor = Quantity_NOC_GREEN4;
00212 myViewer->Grid()->SetColors( myGridColor, myGridTenthColor );
00213 gp_Ax3 aPlane( gp_Pnt( 0., 0., 0.), gp_Dir( 1., 0., 0. ) );
00214 myViewer->SetPrivilegedPlane( aPlane );
00215 }
00216
00217
00218
00219
00220 void QoccController::gridOn ( void )
00221 {
00222 myViewer->ActivateGrid( myGridType , myGridMode );
00223 myViewer->SetGridEcho ( Standard_True );
00224 }
00225
00226
00227
00228
00229 void QoccController::gridOff ( void )
00230 {
00231 myViewer->DeactivateGrid();
00232 myViewer->SetGridEcho( Standard_False );
00233 }
00234
00235
00236
00237
00238 void QoccController::gridRect ( void )
00239 {
00240 myGridType = Aspect_GT_Rectangular;
00241 myViewer->ActivateGrid( myGridType , myGridMode );
00242 myViewer->Grid()->SetColors( myGridColor, myGridTenthColor );
00243 }
00244
00245
00246
00247
00248 void QoccController::gridCirc ( void )
00249 {
00250 myGridType = Aspect_GT_Circular;
00251 myViewer->ActivateGrid( myGridType , myGridMode );
00252 myViewer->Grid()->SetColors( myGridColor, myGridTenthColor );
00253 }
00254
00255
00256
00257
00258 void QoccController::setCommand ( QoccCommand* command )
00259 {
00260 clearCommand();
00261 myCommand = command;
00262 }
00263
00264
00265
00266
00267 void QoccController::clearCommand ( )
00268 {
00269 if (myCommand)
00270 {
00271 delete myCommand;
00272 myCommand = NULL;
00273 }
00274 }
00275
00276 void QoccController::setGridOffset (Quantity_Length offset)
00277 {
00278 Quantity_Length radius;
00279 Quantity_Length xSize, ySize;
00280 Quantity_Length oldOffset;
00281
00282 myViewer->CircularGridGraphicValues( radius, oldOffset );
00283 myViewer->SetCircularGridGraphicValues( radius, offset);
00284
00285 myViewer->RectangularGridGraphicValues(xSize, ySize, oldOffset);
00286 myViewer->SetRectangularGridGraphicValues(xSize, ySize, offset);
00287 }
00288
00289 void QoccController::setLocalContext( TopAbs_ShapeEnum lcType )
00290 {
00291 clearLocalContext();
00292 myContext->OpenLocalContext();
00293 myContext->ActivateStandardMode(lcType);
00294 myLcType = lcType;
00295 }
00296
00297 void QoccController::clearLocalContext( void )
00298 {
00299 if (hasLocalContext())
00300 {
00301 myContext->ClearLocalContext();
00302 myContext->CloseLocalContext();
00303 }
00304 }
00305
00306 void QoccController::clearAllLocalContexts( void )
00307 {
00308 if (hasLocalContext())
00309 {
00310 myContext->CloseAllContexts();
00311 }
00312 }
00313
00314 bool QoccController::hasLocalContext( void )
00315 {
00316 return (bool) myContext->HasOpenedContext();
00317 }
00318
00319 void QoccController::moveEvent( Qocc3dWidget* widget, QMouseEvent* e )
00320 {
00321 if ( myCommand )
00322 {
00323 myCommand->moveEvent ( widget, e );
00324 if ( myCommand->isDrawing() )
00325 {
00326 myViewer->Update();
00327 }
00328 }
00329 }
00330
00331 void QoccController::clickEvent( Qocc3dWidget* widget, QMouseEvent* e )
00332 {
00333
00334 if ( myCommand )
00335 {
00336 if ( e->button() & Qt::RightButton )
00337 {
00338 clearCommand();
00339 myViewer->Update();
00340 }
00341 else
00342 {
00343 myCommand->clickEvent ( widget, e );
00344 if ( myCommand->isDrawing() )
00345 {
00346 update();
00347 }
00348 }
00349 }
00350 }
00351
00352 void QoccController::undo( void )
00353 {
00354 myDocument->undo();
00355 update();
00356 }
00357
00358 void QoccController::redo( void )
00359 {
00360 myDocument->redo();
00361 update();
00362 }
00363
00364 void QoccController::update( void )
00365 {
00366 myViewer->Update();
00367 }