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 // =======================================================================
22 // =======================================================================
23 Handle(V3d_Viewer) DocumentCommon::Viewer (const Standard_ExtString theName,
24 const Standard_CString theDomain,
25 const Standard_Real theViewSize,
26 const V3d_TypeOfOrientation theViewProj,
27 const Standard_Boolean theComputedMode,
28 const Standard_Boolean theDefaultComputedMode )
30 static Handle(OpenGl_GraphicDriver) aGraphicDriver;
32 if (aGraphicDriver.IsNull())
34 Handle(Aspect_DisplayConnection) aDisplayConnection;
35 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
36 aDisplayConnection = new Aspect_DisplayConnection (qgetenv ("DISPLAY").constData());
38 aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection);
41 return new V3d_Viewer (aGraphicDriver,
51 theDefaultComputedMode,
55 DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app )
61 TCollection_ExtendedString a3DName ("Visu3D");
63 myViewer = Viewer (a3DName.ToExtString(), "", 1000.0, V3d_XposYnegZpos, Standard_True, Standard_True);
65 myViewer->SetDefaultLights();
66 myViewer->SetLightOn();
68 myContext = new AIS_InteractiveContext (myViewer);
71 DocumentCommon::~DocumentCommon()
75 ApplicationCommonWindow* DocumentCommon::getApplication()
80 MDIWindow* DocumentCommon::createNewMDIWindow()
82 QMdiArea* ws = myApp->getWorkspace();
83 return new MDIWindow (this, ws, 0);
86 void DocumentCommon::onCreateNewView()
88 QMdiArea* ws = myApp->getWorkspace();
89 MDIWindow* w = createNewMDIWindow();
97 connect( w, SIGNAL( selectionChanged() ),
98 this, SIGNAL( selectionChanged() ) );
99 connect( w, SIGNAL( message( const QString&, int ) ),
100 myApp->statusBar(), SLOT( showMessage( const QString&, int ) ) );
101 connect( w, SIGNAL( sendCloseView( MDIWindow* ) ),
102 this, SLOT( onCloseView( MDIWindow* ) ) );
105 w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) );
106 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
108 w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) );
110 if ( ws->subWindowList().isEmpty() )
112 // Due to strange Qt4.2.3 feature the child window icon is not drawn
113 // in the main menu if showMaximized() is called for a non-visible child window
114 // Therefore calling show() first...
123 getApplication()->onSelectionChanged();
126 void DocumentCommon::onCloseView(MDIWindow* theView)
129 if( countOfWindow() == 0 )
130 emit sendCloseDocument( this );
133 void DocumentCommon::removeView(MDIWindow* theView)
135 if ( myViews.count( theView ) )
137 myViews.removeAll(theView);
141 void DocumentCommon::removeViews()
143 while( myViews.count() )
145 removeView( myViews.first() );
149 int DocumentCommon::countOfWindow()
151 return myViews.count();
154 Handle(AIS_InteractiveContext) DocumentCommon::getContext()
159 void DocumentCommon::fitAll()
161 QList<MDIWindow*>::iterator i;
162 for ( i = myViews.begin(); i != myViews.end(); i++ )
166 void DocumentCommon::onWireframe()
168 QApplication::setOverrideCursor( Qt::WaitCursor );
169 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
170 myContext->SetDisplayMode( myContext->Current(), 0, false );
171 myContext->UpdateCurrentViewer();
172 getApplication()->onSelectionChanged();
173 QApplication::restoreOverrideCursor();
176 void DocumentCommon::onShading()
178 QApplication::setOverrideCursor( Qt::WaitCursor );
179 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
180 myContext->SetDisplayMode( myContext->Current(), 1, false );
181 myContext->UpdateCurrentViewer();
182 getApplication()->onSelectionChanged();
183 QApplication::restoreOverrideCursor();
186 void DocumentCommon::onColor()
189 Quantity_Color aShapeColor;
190 myContext->InitCurrent();
191 Handle_AIS_InteractiveObject Current = myContext->Current() ;
192 if ( Current->HasColor () )
194 aShapeColor = myContext->Color( Current );
195 aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 );
198 aColor.setRgb( 255, 255, 255 );
200 QColor aRetColor = QColorDialog::getColor( aColor );
201 if ( aRetColor.isValid() )
203 Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255.,
204 aRetColor.blue() / 255., Quantity_TOC_RGB );
205 for (; myContext->MoreCurrent(); myContext->NextCurrent() )
206 myContext->SetColor( myContext->Current(), color.Name() );
210 void DocumentCommon::onMaterial( int theMaterial )
212 for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () )
213 myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial );
216 void DocumentCommon::onMaterial()
218 DialogMaterial* m = new DialogMaterial();
219 connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) );
223 void DocumentCommon::onTransparency( int theTrans )
225 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() )
226 myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 );
229 void DocumentCommon::onTransparency()
231 DialogTransparency* aDialog = new DialogTransparency();
232 connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) );
236 void DocumentCommon::onDelete()
238 for ( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
239 myContext->Erase( myContext->Current(), false);
240 myContext->ClearSelected();
241 getApplication()->onSelectionChanged();