7fd59977 |
1 | #include "DocumentCommon.h" |
2 | |
3 | #include "ApplicationCommon.h" |
4 | #include "Transparency.h" |
5 | #include "Material.h" |
6 | |
7 | #include <QStatusBar> |
8 | #include <QApplication> |
9 | #include <QColor> |
10 | #include <QColorDialog> |
11 | |
dc3fe572 |
12 | #include <Aspect_DisplayConnection.hxx> |
7fd59977 |
13 | #include <AIS_InteractiveObject.hxx> |
14 | #include <Graphic3d_NameOfMaterial.hxx> |
65993a95 |
15 | #include <OpenGl_GraphicDriver.hxx> |
dc3fe572 |
16 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
17 | |
9764ccbb |
18 | // ======================================================================= |
19 | // function : Viewer |
20 | // purpose : |
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 ) |
7fd59977 |
28 | { |
65993a95 |
29 | static Handle(OpenGl_GraphicDriver) aGraphicDriver; |
dc3fe572 |
30 | |
31 | if (aGraphicDriver.IsNull()) |
32 | { |
33 | Handle(Aspect_DisplayConnection) aDisplayConnection; |
34 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
9764ccbb |
35 | aDisplayConnection = new Aspect_DisplayConnection (qgetenv ("DISPLAY").constData()); |
7fd59977 |
36 | #endif |
65993a95 |
37 | aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection); |
dc3fe572 |
38 | } |
39 | |
9764ccbb |
40 | return new V3d_Viewer (aGraphicDriver, |
41 | theName, |
42 | theDomain, |
43 | theViewSize, |
44 | theViewProj, |
45 | Quantity_NOC_GRAY30, |
46 | V3d_ZBUFFER, |
47 | V3d_GOURAUD, |
48 | V3d_WAIT, |
49 | theComputedMode, |
50 | theDefaultComputedMode, |
51 | V3d_TEX_NONE); |
7fd59977 |
52 | } |
53 | |
54 | DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app ) |
55 | : QObject( app ), |
56 | myApp( app ), |
57 | myIndex( theIndex ), |
58 | myNbViews( 0 ) |
59 | { |
861a7b03 |
60 | TCollection_ExtendedString a3DName ("Visu3D"); |
7fd59977 |
61 | |
9764ccbb |
62 | myViewer = Viewer (a3DName.ToExtString(), "", 1000.0, V3d_XposYnegZpos, Standard_True, Standard_True); |
7fd59977 |
63 | |
9764ccbb |
64 | myViewer->SetDefaultLights(); |
65 | myViewer->SetLightOn(); |
66 | |
67 | myContext = new AIS_InteractiveContext (myViewer); |
7fd59977 |
68 | } |
69 | |
70 | DocumentCommon::~DocumentCommon() |
71 | { |
72 | } |
73 | |
74 | ApplicationCommonWindow* DocumentCommon::getApplication() |
75 | { |
2ad228f6 |
76 | return myApp; |
7fd59977 |
77 | } |
78 | |
861a7b03 |
79 | MDIWindow* DocumentCommon::createNewMDIWindow() |
7fd59977 |
80 | { |
861a7b03 |
81 | QMdiArea* ws = myApp->getWorkspace(); |
82 | return new MDIWindow (this, ws, 0); |
7fd59977 |
83 | } |
e276548b |
84 | |
861a7b03 |
85 | void DocumentCommon::onCreateNewView() |
7fd59977 |
86 | { |
861a7b03 |
87 | QMdiArea* ws = myApp->getWorkspace(); |
88 | MDIWindow* w = createNewMDIWindow(); |
2ad228f6 |
89 | |
90 | if (!w) |
91 | return; |
7fd59977 |
92 | |
861a7b03 |
93 | ws->addSubWindow (w); |
94 | myViews.append (w); |
7fd59977 |
95 | |
96 | connect( w, SIGNAL( selectionChanged() ), |
97 | this, SIGNAL( selectionChanged() ) ); |
98 | connect( w, SIGNAL( message( const QString&, int ) ), |
2ad228f6 |
99 | myApp->statusBar(), SLOT( showMessage( const QString&, int ) ) ); |
7fd59977 |
100 | connect( w, SIGNAL( sendCloseView( MDIWindow* ) ), |
2ad228f6 |
101 | this, SLOT( onCloseView( MDIWindow* ) ) ); |
7fd59977 |
102 | |
2ad228f6 |
103 | QString aName; |
104 | w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) ); |
7fd59977 |
105 | QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" ); |
2ad228f6 |
106 | |
7fd59977 |
107 | w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) ); |
108 | |
861a7b03 |
109 | if ( ws->subWindowList().isEmpty() ) |
7fd59977 |
110 | { |
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... |
114 | w->show(); |
2ad228f6 |
115 | w->showMaximized(); |
7fd59977 |
116 | } |
117 | else |
2ad228f6 |
118 | w->show(); |
7fd59977 |
119 | |
120 | w->setFocus(); |
121 | |
122 | getApplication()->onSelectionChanged(); |
123 | } |
124 | |
125 | void DocumentCommon::onCloseView(MDIWindow* theView) |
126 | { |
127 | removeView(theView); |
128 | if( countOfWindow() == 0 ) |
129 | emit sendCloseDocument( this ); |
130 | } |
131 | |
132 | void DocumentCommon::removeView(MDIWindow* theView) |
133 | { |
134 | if ( myViews.count( theView ) ) |
135 | { |
2ad228f6 |
136 | myViews.removeAll(theView); |
137 | delete theView; |
138 | } |
7fd59977 |
139 | } |
140 | void DocumentCommon::removeViews() |
141 | { |
142 | while( myViews.count() ) |
861a7b03 |
143 | { |
144 | removeView( myViews.first() ); |
145 | } |
7fd59977 |
146 | } |
147 | |
148 | int DocumentCommon::countOfWindow() |
149 | { |
2ad228f6 |
150 | return myViews.count(); |
7fd59977 |
151 | } |
152 | |
153 | Handle(AIS_InteractiveContext) DocumentCommon::getContext() |
154 | { |
2ad228f6 |
155 | return myContext; |
7fd59977 |
156 | } |
157 | |
158 | void DocumentCommon::fitAll() |
159 | { |
2ad228f6 |
160 | QList<MDIWindow*>::iterator i; |
161 | for ( i = myViews.begin(); i != myViews.end(); i++ ) |
162 | (*i)->fitAll(); |
7fd59977 |
163 | } |
164 | |
165 | void DocumentCommon::onWireframe() |
166 | { |
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(); |
173 | } |
174 | |
175 | void DocumentCommon::onShading() |
176 | { |
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(); |
183 | } |
184 | |
185 | void DocumentCommon::onColor() |
186 | { |
187 | QColor aColor ; |
188 | Quantity_Color aShapeColor; |
189 | myContext->InitCurrent(); |
190 | Handle_AIS_InteractiveObject Current = myContext->Current() ; |
191 | if ( Current->HasColor () ) |
192 | { |
193 | aShapeColor = myContext->Color( Current ); |
194 | aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 ); |
195 | } |
196 | else |
197 | aColor.setRgb( 255, 255, 255 ); |
198 | |
199 | QColor aRetColor = QColorDialog::getColor( aColor ); |
200 | if ( aRetColor.isValid() ) |
201 | { |
202 | Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255., |
2ad228f6 |
203 | aRetColor.blue() / 255., Quantity_TOC_RGB ); |
7fd59977 |
204 | for (; myContext->MoreCurrent(); myContext->NextCurrent() ) |
205 | myContext->SetColor( myContext->Current(), color.Name() ); |
206 | } |
207 | } |
208 | |
209 | void DocumentCommon::onMaterial( int theMaterial ) |
210 | { |
211 | for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () ) |
212 | myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial ); |
213 | } |
214 | |
215 | void DocumentCommon::onMaterial() |
216 | { |
217 | DialogMaterial* m = new DialogMaterial(); |
218 | connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) ); |
219 | m->exec(); |
220 | } |
221 | |
222 | void DocumentCommon::onTransparency( int theTrans ) |
223 | { |
224 | for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() ) |
225 | myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 ); |
226 | } |
227 | |
228 | void DocumentCommon::onTransparency() |
229 | { |
230 | DialogTransparency* aDialog = new DialogTransparency(); |
231 | connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) ); |
232 | aDialog->exec(); |
233 | } |
234 | |
235 | void DocumentCommon::onDelete() |
236 | { |
7140edaf |
237 | myContext->EraseSelected (Standard_False); |
7fd59977 |
238 | myContext->ClearSelected(); |
239 | getApplication()->onSelectionChanged(); |
240 | } |