1 #include "DocumentCommon.h"
3 #include "ApplicationCommon.h"
4 #include "Transparency.h"
8 #include <QApplication>
10 #include <QColorDialog>
13 #include <Graphic3d_GraphicDevice.hxx>
15 #include <Graphic3d_WNTGraphicDevice.hxx>
18 #include <AIS_InteractiveObject.hxx>
19 #include <Graphic3d_NameOfMaterial.hxx>
21 Handle(V3d_Viewer) DocumentCommon::Viewer( const Standard_CString aDisplay,
22 const Standard_ExtString aName,
23 const Standard_CString aDomain,
24 const Standard_Real ViewSize,
25 const V3d_TypeOfOrientation ViewProj,
26 const Standard_Boolean ComputedMode,
27 const Standard_Boolean aDefaultComputedMode )
30 static Handle(Graphic3d_GraphicDevice) defaultdevice;
31 if( defaultdevice.IsNull() )
32 defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
33 return new V3d_Viewer(defaultdevice,aName,aDomain,ViewSize,ViewProj,
34 Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
35 ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
37 static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
38 if( defaultdevice.IsNull() )
39 defaultdevice = new Graphic3d_WNTGraphicDevice();
40 return new V3d_Viewer(defaultdevice,aName,aDomain,ViewSize,ViewProj,
41 Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
42 ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
46 DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app )
52 TCollection_ExtendedString a3DName("Visu3D");
53 myViewer = Viewer( getenv("DISPLAY"), a3DName.ToExtString(), "", 1000.0,
54 V3d_XposYnegZpos, Standard_True, Standard_True );
57 myViewer->SetDefaultLights();
58 myViewer->SetLightOn();
60 myContext =new AIS_InteractiveContext(myViewer);
64 DocumentCommon::~DocumentCommon()
68 ApplicationCommonWindow* DocumentCommon::getApplication()
73 MDIWindow* DocumentCommon::createNewMDIWindow()
75 QWorkspace* ws = myApp->getWorkspace();
76 return new MDIWindow( this, ws, 0 );
78 void DocumentCommon::onCreateNewView()
80 QWorkspace* ws = myApp->getWorkspace();
81 MDIWindow* w = createNewMDIWindow();
89 connect( w, SIGNAL( selectionChanged() ),
90 this, SIGNAL( selectionChanged() ) );
91 connect( w, SIGNAL( message( const QString&, int ) ),
92 myApp->statusBar(), SLOT( message( const QString&, int ) ) );
93 connect( w, SIGNAL( sendCloseView( MDIWindow* ) ),
94 this, SLOT( onCloseView( MDIWindow* ) ) );
97 w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) );
98 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
100 w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) );
102 if ( ws->windowList().isEmpty() )
104 // Due to strange Qt4.2.3 feature the child window icon is not drawn
105 // in the main menu if showMaximized() is called for a non-visible child window
106 // Therefore calling show() first...
115 getApplication()->onSelectionChanged();
118 void DocumentCommon::onCloseView(MDIWindow* theView)
121 if( countOfWindow() == 0 )
122 emit sendCloseDocument( this );
125 void DocumentCommon::removeView(MDIWindow* theView)
127 if ( myViews.count( theView ) )
129 myViews.removeAll(theView);
133 void DocumentCommon::removeViews()
135 while( myViews.count() )
136 removeView( (MDIWindow*)myViews.first() );
139 int DocumentCommon::countOfWindow()
141 return myViews.count();
144 Handle(AIS_InteractiveContext) DocumentCommon::getContext()
149 void DocumentCommon::fitAll()
151 QList<MDIWindow*>::iterator i;
152 for ( i = myViews.begin(); i != myViews.end(); i++ )
156 void DocumentCommon::onWireframe()
158 QApplication::setOverrideCursor( Qt::WaitCursor );
159 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
160 myContext->SetDisplayMode( myContext->Current(), 0, false );
161 myContext->UpdateCurrentViewer();
162 getApplication()->onSelectionChanged();
163 QApplication::restoreOverrideCursor();
166 void DocumentCommon::onShading()
168 QApplication::setOverrideCursor( Qt::WaitCursor );
169 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
170 myContext->SetDisplayMode( myContext->Current(), 1, false );
171 myContext->UpdateCurrentViewer();
172 getApplication()->onSelectionChanged();
173 QApplication::restoreOverrideCursor();
176 void DocumentCommon::onColor()
179 Quantity_Color aShapeColor;
180 myContext->InitCurrent();
181 Handle_AIS_InteractiveObject Current = myContext->Current() ;
182 if ( Current->HasColor () )
184 aShapeColor = myContext->Color( Current );
185 aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 );
188 aColor.setRgb( 255, 255, 255 );
190 QColor aRetColor = QColorDialog::getColor( aColor );
191 if ( aRetColor.isValid() )
193 Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255.,
194 aRetColor.blue() / 255., Quantity_TOC_RGB );
195 for (; myContext->MoreCurrent(); myContext->NextCurrent() )
196 myContext->SetColor( myContext->Current(), color.Name() );
200 void DocumentCommon::onMaterial( int theMaterial )
202 for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () )
203 myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial );
206 void DocumentCommon::onMaterial()
208 DialogMaterial* m = new DialogMaterial();
209 connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) );
213 void DocumentCommon::onTransparency( int theTrans )
215 for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() )
216 myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 );
219 void DocumentCommon::onTransparency()
221 DialogTransparency* aDialog = new DialogTransparency();
222 connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) );
226 void DocumentCommon::onDelete()
228 for ( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() )
229 myContext->Erase( myContext->Current(), false, true );
230 myContext->ClearSelected();
231 getApplication()->onSelectionChanged();