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_NameOfMaterial.hxx>
15 #include <OpenGl_GraphicDriver.hxx>
16 #include <TCollection_AsciiString.hxx>
18 // =======================================================================
21 // =======================================================================
22 Handle(V3d_Viewer) DocumentCommon::Viewer (const Standard_ExtString theName,
23 const Standard_CString theDomain,
24 const Standard_Real theViewSize,
25 const V3d_TypeOfOrientation theViewProj,
26 const Standard_Boolean theComputedMode,
27 const Standard_Boolean theDefaultComputedMode )
29 static Handle(OpenGl_GraphicDriver) aGraphicDriver;
31 if (aGraphicDriver.IsNull())
33 Handle(Aspect_DisplayConnection) aDisplayConnection;
34 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
35 aDisplayConnection = new Aspect_DisplayConnection (qgetenv ("DISPLAY").constData());
37 aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection);
40 return new V3d_Viewer (aGraphicDriver,
50 theDefaultComputedMode,
54 DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app )
60 TCollection_ExtendedString a3DName ("Visu3D");
62 myViewer = Viewer (a3DName.ToExtString(), "", 1000.0, V3d_XposYnegZpos, Standard_True, Standard_True);
64 myViewer->SetDefaultLights();
65 myViewer->SetLightOn();
67 myContext = new AIS_InteractiveContext (myViewer);
70 DocumentCommon::~DocumentCommon()
74 ApplicationCommonWindow* DocumentCommon::getApplication()
79 MDIWindow* DocumentCommon::createNewMDIWindow()
81 QMdiArea* ws = myApp->getWorkspace();
82 return new MDIWindow (this, ws, 0);
85 void DocumentCommon::onCreateNewView()
87 QMdiArea* ws = myApp->getWorkspace();
88 MDIWindow* w = createNewMDIWindow();
96 connect( w, SIGNAL( selectionChanged() ),
97 this, SIGNAL( selectionChanged() ) );
98 connect( w, SIGNAL( message( const QString&, int ) ),
99 myApp->statusBar(), SLOT( showMessage( const QString&, int ) ) );
100 connect( w, SIGNAL( sendCloseView( MDIWindow* ) ),
101 this, SLOT( onCloseView( MDIWindow* ) ) );
104 w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) );
105 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
107 w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) );
109 if ( ws->subWindowList().isEmpty() )
111 // Due to strange Qt4.2.3 feature the child window icon is not drawn
112 // in the main menu if showMaximized() is called for a non-visible child window
113 // Therefore calling show() first...
122 getApplication()->onSelectionChanged();
125 void DocumentCommon::onCloseView(MDIWindow* theView)
128 if( countOfWindow() == 0 )
129 emit sendCloseDocument( this );
132 void DocumentCommon::removeView(MDIWindow* theView)
134 if ( myViews.count( theView ) )
136 myViews.removeAll(theView);
140 void DocumentCommon::removeViews()
142 while( myViews.count() )
144 removeView( myViews.first() );
148 int DocumentCommon::countOfWindow()
150 return myViews.count();
153 Handle(AIS_InteractiveContext) DocumentCommon::getContext()
158 void DocumentCommon::fitAll()
160 QList<MDIWindow*>::iterator i;
161 for ( i = myViews.begin(); i != myViews.end(); i++ )
165 void DocumentCommon::onWireframe()
167 QApplication::setOverrideCursor( Qt::WaitCursor );
168 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
169 myContext->SetDisplayMode( myContext->Current(), 0, false );
170 myContext->UpdateCurrentViewer();
171 getApplication()->onSelectionChanged();
172 QApplication::restoreOverrideCursor();
175 void DocumentCommon::onShading()
177 QApplication::setOverrideCursor( Qt::WaitCursor );
178 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
179 myContext->SetDisplayMode( myContext->Current(), 1, false );
180 myContext->UpdateCurrentViewer();
181 getApplication()->onSelectionChanged();
182 QApplication::restoreOverrideCursor();
185 void DocumentCommon::onColor()
188 Quantity_Color aShapeColor;
189 myContext->InitCurrent();
190 Handle_AIS_InteractiveObject Current = myContext->Current() ;
191 if ( Current->HasColor () )
193 aShapeColor = myContext->Color( Current );
194 aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 );
197 aColor.setRgb( 255, 255, 255 );
199 QColor aRetColor = QColorDialog::getColor( aColor );
200 if ( aRetColor.isValid() )
202 Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255.,
203 aRetColor.blue() / 255., Quantity_TOC_RGB );
204 for (; myContext->MoreCurrent(); myContext->NextCurrent() )
205 myContext->SetColor( myContext->Current(), color.Name() );
209 void DocumentCommon::onMaterial( int theMaterial )
211 for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () )
212 myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial );
215 void DocumentCommon::onMaterial()
217 DialogMaterial* m = new DialogMaterial();
218 connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) );
222 void DocumentCommon::onTransparency( int theTrans )
224 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() )
225 myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 );
228 void DocumentCommon::onTransparency()
230 DialogTransparency* aDialog = new DialogTransparency();
231 connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) );
235 void DocumentCommon::onDelete()
237 for ( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
238 myContext->Erase( myContext->Current(), false);
239 myContext->ClearSelected();
240 getApplication()->onSelectionChanged();