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 (qgetenv ("DISPLAY").constData(),
51 a3DName.ToExtString(), "", 1000.0, 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()
70 QMdiArea* ws = myApp->getWorkspace();
71 return new MDIWindow (this, ws, 0);
74 void DocumentCommon::onCreateNewView()
76 QMdiArea* ws = myApp->getWorkspace();
77 MDIWindow* w = createNewMDIWindow();
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->subWindowList().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() )
133 removeView( myViews.first() );
137 int DocumentCommon::countOfWindow()
139 return myViews.count();
142 Handle(AIS_InteractiveContext) DocumentCommon::getContext()
147 void DocumentCommon::fitAll()
149 QList<MDIWindow*>::iterator i;
150 for ( i = myViews.begin(); i != myViews.end(); i++ )
154 void DocumentCommon::onWireframe()
156 QApplication::setOverrideCursor( Qt::WaitCursor );
157 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
158 myContext->SetDisplayMode( myContext->Current(), 0, false );
159 myContext->UpdateCurrentViewer();
160 getApplication()->onSelectionChanged();
161 QApplication::restoreOverrideCursor();
164 void DocumentCommon::onShading()
166 QApplication::setOverrideCursor( Qt::WaitCursor );
167 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
168 myContext->SetDisplayMode( myContext->Current(), 1, false );
169 myContext->UpdateCurrentViewer();
170 getApplication()->onSelectionChanged();
171 QApplication::restoreOverrideCursor();
174 void DocumentCommon::onColor()
177 Quantity_Color aShapeColor;
178 myContext->InitCurrent();
179 Handle_AIS_InteractiveObject Current = myContext->Current() ;
180 if ( Current->HasColor () )
182 aShapeColor = myContext->Color( Current );
183 aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 );
186 aColor.setRgb( 255, 255, 255 );
188 QColor aRetColor = QColorDialog::getColor( aColor );
189 if ( aRetColor.isValid() )
191 Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255.,
192 aRetColor.blue() / 255., Quantity_TOC_RGB );
193 for (; myContext->MoreCurrent(); myContext->NextCurrent() )
194 myContext->SetColor( myContext->Current(), color.Name() );
198 void DocumentCommon::onMaterial( int theMaterial )
200 for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () )
201 myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial );
204 void DocumentCommon::onMaterial()
206 DialogMaterial* m = new DialogMaterial();
207 connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) );
211 void DocumentCommon::onTransparency( int theTrans )
213 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() )
214 myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 );
217 void DocumentCommon::onTransparency()
219 DialogTransparency* aDialog = new DialogTransparency();
220 connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) );
224 void DocumentCommon::onDelete()
226 for ( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
227 myContext->Erase( myContext->Current(), false);
228 myContext->ClearSelected();
229 getApplication()->onSelectionChanged();