1 #include "DocumentCommon.h"
3 #include "ApplicationCommon.h"
4 #include "Transparency.h"
8 #include <QApplication>
10 #include <QColorDialog>
12 #include <Aspect_DisplayConnection.hxx>
13 #include <AIS_InteractiveObject.hxx>
14 #include <Graphic3d.hxx>
15 #include <Graphic3d_NameOfMaterial.hxx>
16 #include <OpenGl_GraphicDriver.hxx>
17 #include <TCollection_AsciiString.hxx>
19 Handle(V3d_Viewer) DocumentCommon::Viewer( const Standard_CString aDisplay,
20 const Standard_ExtString aName,
21 const Standard_CString aDomain,
22 const Standard_Real ViewSize,
23 const V3d_TypeOfOrientation ViewProj,
24 const Standard_Boolean ComputedMode,
25 const Standard_Boolean aDefaultComputedMode )
27 static Handle(OpenGl_GraphicDriver) aGraphicDriver;
29 if (aGraphicDriver.IsNull())
31 Handle(Aspect_DisplayConnection) aDisplayConnection;
32 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
33 aDisplayConnection = new Aspect_DisplayConnection (aDisplay);
35 aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection);
38 return new V3d_Viewer(aGraphicDriver,aName,aDomain,ViewSize,ViewProj,
39 Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
40 ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
43 DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app )
49 TCollection_ExtendedString a3DName("Visu3D");
50 myViewer = Viewer( getenv("DISPLAY"), a3DName.ToExtString(), "", 1000.0,
51 V3d_XposYnegZpos, Standard_True, Standard_True );
53 myViewer->SetDefaultLights();
54 myViewer->SetLightOn();
56 myContext =new AIS_InteractiveContext(myViewer);
59 DocumentCommon::~DocumentCommon()
63 ApplicationCommonWindow* DocumentCommon::getApplication()
68 MDIWindow* DocumentCommon::createNewMDIWindow( bool theRT )
70 QWorkspace* ws = myApp->getWorkspace();
71 return new MDIWindow( this, ws, 0, theRT );
74 void DocumentCommon::onCreateNewView( bool theRT )
76 QWorkspace* ws = myApp->getWorkspace();
77 MDIWindow* w = createNewMDIWindow( theRT );
85 connect( w, SIGNAL( selectionChanged() ),
86 this, SIGNAL( selectionChanged() ) );
87 connect( w, SIGNAL( message( const QString&, int ) ),
88 myApp->statusBar(), SLOT( showMessage( const QString&, int ) ) );
89 connect( w, SIGNAL( sendCloseView( MDIWindow* ) ),
90 this, SLOT( onCloseView( MDIWindow* ) ) );
93 w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) );
94 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
96 w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) );
98 if ( ws->windowList().isEmpty() )
100 // Due to strange Qt4.2.3 feature the child window icon is not drawn
101 // in the main menu if showMaximized() is called for a non-visible child window
102 // Therefore calling show() first...
111 getApplication()->onSelectionChanged();
114 void DocumentCommon::onCloseView(MDIWindow* theView)
117 if( countOfWindow() == 0 )
118 emit sendCloseDocument( this );
121 void DocumentCommon::removeView(MDIWindow* theView)
123 if ( myViews.count( theView ) )
125 myViews.removeAll(theView);
129 void DocumentCommon::removeViews()
131 while( myViews.count() )
132 removeView( (MDIWindow*)myViews.first() );
135 int DocumentCommon::countOfWindow()
137 return myViews.count();
140 Handle(AIS_InteractiveContext) DocumentCommon::getContext()
145 void DocumentCommon::fitAll()
147 QList<MDIWindow*>::iterator i;
148 for ( i = myViews.begin(); i != myViews.end(); i++ )
152 void DocumentCommon::onWireframe()
154 QApplication::setOverrideCursor( Qt::WaitCursor );
155 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
156 myContext->SetDisplayMode( myContext->Current(), 0, false );
157 myContext->UpdateCurrentViewer();
158 getApplication()->onSelectionChanged();
159 QApplication::restoreOverrideCursor();
162 void DocumentCommon::onShading()
164 QApplication::setOverrideCursor( Qt::WaitCursor );
165 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
166 myContext->SetDisplayMode( myContext->Current(), 1, false );
167 myContext->UpdateCurrentViewer();
168 getApplication()->onSelectionChanged();
169 QApplication::restoreOverrideCursor();
172 void DocumentCommon::onColor()
175 Quantity_Color aShapeColor;
176 myContext->InitCurrent();
177 Handle_AIS_InteractiveObject Current = myContext->Current() ;
178 if ( Current->HasColor () )
180 aShapeColor = myContext->Color( Current );
181 aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 );
184 aColor.setRgb( 255, 255, 255 );
186 QColor aRetColor = QColorDialog::getColor( aColor );
187 if ( aRetColor.isValid() )
189 Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255.,
190 aRetColor.blue() / 255., Quantity_TOC_RGB );
191 for (; myContext->MoreCurrent(); myContext->NextCurrent() )
192 myContext->SetColor( myContext->Current(), color.Name() );
196 void DocumentCommon::onMaterial( int theMaterial )
198 for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () )
199 myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial );
202 void DocumentCommon::onMaterial()
204 DialogMaterial* m = new DialogMaterial();
205 connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) );
209 void DocumentCommon::onTransparency( int theTrans )
211 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() )
212 myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 );
215 void DocumentCommon::onTransparency()
217 DialogTransparency* aDialog = new DialogTransparency();
218 connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) );
222 void DocumentCommon::onDelete()
224 for ( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
225 myContext->Erase( myContext->Current(), false);
226 myContext->ClearSelected();
227 getApplication()->onSelectionChanged();
232 void DocumentCommon::onShadows( int state )
234 QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
236 MDIWindow* window = qobject_cast< MDIWindow* >( ws->activeWindow() );
241 window->setRaytracedShadows( state );
243 myContext->UpdateCurrentViewer();
246 void DocumentCommon::onReflections( int state )
248 QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
250 MDIWindow* window = qobject_cast< MDIWindow* >( ws->activeWindow() );
255 window->setRaytracedReflections( state );
257 myContext->UpdateCurrentViewer();
260 void DocumentCommon::onAntialiasing( int state )
262 QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
264 MDIWindow* window = qobject_cast< MDIWindow* >( ws->activeWindow() );
269 window->setRaytracedAntialiasing( state );
271 myContext->UpdateCurrentViewer();