7fd59977 |
1 | #include "DocumentCommon.h" |
2 | |
3 | #include "ApplicationCommon.h" |
4 | #include "Transparency.h" |
5 | #include "Material.h" |
6 | |
55a40de8 |
7 | #include <Standard_WarningsDisable.hxx> |
7fd59977 |
8 | #include <QStatusBar> |
9 | #include <QApplication> |
10 | #include <QColor> |
11 | #include <QColorDialog> |
55a40de8 |
12 | #include <Standard_WarningsRestore.hxx> |
7fd59977 |
13 | |
dc3fe572 |
14 | #include <Aspect_DisplayConnection.hxx> |
7fd59977 |
15 | #include <AIS_InteractiveObject.hxx> |
16 | #include <Graphic3d_NameOfMaterial.hxx> |
65993a95 |
17 | #include <OpenGl_GraphicDriver.hxx> |
1fa16152 |
18 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
19 | #include <OSD_Environment.hxx> |
20 | #endif |
dc3fe572 |
21 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
22 | |
9764ccbb |
23 | // ======================================================================= |
24 | // function : Viewer |
25 | // purpose : |
26 | // ======================================================================= |
6a24c6de |
27 | Handle(V3d_Viewer) DocumentCommon::Viewer (const Standard_ExtString , |
28 | const Standard_CString , |
9764ccbb |
29 | const Standard_Real theViewSize, |
30 | const V3d_TypeOfOrientation theViewProj, |
31 | const Standard_Boolean theComputedMode, |
32 | const Standard_Boolean theDefaultComputedMode ) |
7fd59977 |
33 | { |
65993a95 |
34 | static Handle(OpenGl_GraphicDriver) aGraphicDriver; |
dc3fe572 |
35 | |
36 | if (aGraphicDriver.IsNull()) |
37 | { |
38 | Handle(Aspect_DisplayConnection) aDisplayConnection; |
39 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
1fa16152 |
40 | aDisplayConnection = new Aspect_DisplayConnection (OSD_Environment ("DISPLAY").Value()); |
7fd59977 |
41 | #endif |
65993a95 |
42 | aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection); |
dc3fe572 |
43 | } |
44 | |
6a24c6de |
45 | Handle(V3d_Viewer) aViewer = new V3d_Viewer (aGraphicDriver); |
46 | aViewer->SetDefaultViewSize (theViewSize); |
47 | aViewer->SetDefaultViewProj (theViewProj); |
48 | aViewer->SetComputedMode (theComputedMode); |
49 | aViewer->SetDefaultComputedMode (theDefaultComputedMode); |
50 | return aViewer; |
7fd59977 |
51 | } |
52 | |
53 | DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app ) |
54 | : QObject( app ), |
55 | myApp( app ), |
56 | myIndex( theIndex ), |
57 | myNbViews( 0 ) |
58 | { |
861a7b03 |
59 | TCollection_ExtendedString a3DName ("Visu3D"); |
7fd59977 |
60 | |
9764ccbb |
61 | myViewer = Viewer (a3DName.ToExtString(), "", 1000.0, V3d_XposYnegZpos, Standard_True, Standard_True); |
7fd59977 |
62 | |
9764ccbb |
63 | myViewer->SetDefaultLights(); |
64 | myViewer->SetLightOn(); |
65 | |
66 | myContext = new AIS_InteractiveContext (myViewer); |
7fd59977 |
67 | } |
68 | |
69 | DocumentCommon::~DocumentCommon() |
70 | { |
71 | } |
72 | |
73 | ApplicationCommonWindow* DocumentCommon::getApplication() |
74 | { |
2ad228f6 |
75 | return myApp; |
7fd59977 |
76 | } |
77 | |
861a7b03 |
78 | MDIWindow* DocumentCommon::createNewMDIWindow() |
7fd59977 |
79 | { |
861a7b03 |
80 | QMdiArea* ws = myApp->getWorkspace(); |
81 | return new MDIWindow (this, ws, 0); |
7fd59977 |
82 | } |
e276548b |
83 | |
861a7b03 |
84 | void DocumentCommon::onCreateNewView() |
7fd59977 |
85 | { |
861a7b03 |
86 | QMdiArea* ws = myApp->getWorkspace(); |
87 | MDIWindow* w = createNewMDIWindow(); |
2ad228f6 |
88 | |
89 | if (!w) |
90 | return; |
7fd59977 |
91 | |
861a7b03 |
92 | ws->addSubWindow (w); |
93 | myViews.append (w); |
7fd59977 |
94 | |
95 | connect( w, SIGNAL( selectionChanged() ), |
96 | this, SIGNAL( selectionChanged() ) ); |
97 | connect( w, SIGNAL( message( const QString&, int ) ), |
2ad228f6 |
98 | myApp->statusBar(), SLOT( showMessage( const QString&, int ) ) ); |
7fd59977 |
99 | connect( w, SIGNAL( sendCloseView( MDIWindow* ) ), |
2ad228f6 |
100 | this, SLOT( onCloseView( MDIWindow* ) ) ); |
7fd59977 |
101 | |
2ad228f6 |
102 | QString aName; |
103 | w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) ); |
7fd59977 |
104 | QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" ); |
2ad228f6 |
105 | |
7fd59977 |
106 | w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) ); |
107 | |
861a7b03 |
108 | if ( ws->subWindowList().isEmpty() ) |
7fd59977 |
109 | { |
110 | // Due to strange Qt4.2.3 feature the child window icon is not drawn |
111 | // in the main menu if showMaximized() is called for a non-visible child window |
112 | // Therefore calling show() first... |
113 | w->show(); |
2ad228f6 |
114 | w->showMaximized(); |
7fd59977 |
115 | } |
116 | else |
2ad228f6 |
117 | w->show(); |
7fd59977 |
118 | |
119 | w->setFocus(); |
120 | |
121 | getApplication()->onSelectionChanged(); |
122 | } |
123 | |
124 | void DocumentCommon::onCloseView(MDIWindow* theView) |
125 | { |
126 | removeView(theView); |
127 | if( countOfWindow() == 0 ) |
128 | emit sendCloseDocument( this ); |
129 | } |
130 | |
131 | void DocumentCommon::removeView(MDIWindow* theView) |
132 | { |
133 | if ( myViews.count( theView ) ) |
134 | { |
2ad228f6 |
135 | myViews.removeAll(theView); |
136 | delete theView; |
137 | } |
7fd59977 |
138 | } |
139 | void DocumentCommon::removeViews() |
140 | { |
141 | while( myViews.count() ) |
861a7b03 |
142 | { |
143 | removeView( myViews.first() ); |
144 | } |
7fd59977 |
145 | } |
146 | |
147 | int DocumentCommon::countOfWindow() |
148 | { |
2ad228f6 |
149 | return myViews.count(); |
7fd59977 |
150 | } |
151 | |
152 | Handle(AIS_InteractiveContext) DocumentCommon::getContext() |
153 | { |
2ad228f6 |
154 | return myContext; |
7fd59977 |
155 | } |
156 | |
157 | void DocumentCommon::fitAll() |
158 | { |
2ad228f6 |
159 | QList<MDIWindow*>::iterator i; |
160 | for ( i = myViews.begin(); i != myViews.end(); i++ ) |
161 | (*i)->fitAll(); |
7fd59977 |
162 | } |
163 | |
164 | void DocumentCommon::onWireframe() |
165 | { |
166 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
404c8936 |
167 | for( myContext->InitSelected(); myContext->MoreSelected(); myContext->NextSelected() ) |
168 | myContext->SetDisplayMode( myContext->SelectedInteractive(), 0, false ); |
7fd59977 |
169 | myContext->UpdateCurrentViewer(); |
170 | getApplication()->onSelectionChanged(); |
171 | QApplication::restoreOverrideCursor(); |
172 | } |
173 | |
174 | void DocumentCommon::onShading() |
175 | { |
176 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
404c8936 |
177 | for( myContext->InitSelected(); myContext->MoreSelected(); myContext->NextSelected() ) |
178 | myContext->SetDisplayMode( myContext->SelectedInteractive(), 1, false ); |
7fd59977 |
179 | myContext->UpdateCurrentViewer(); |
180 | getApplication()->onSelectionChanged(); |
181 | QApplication::restoreOverrideCursor(); |
182 | } |
183 | |
184 | void DocumentCommon::onColor() |
185 | { |
186 | QColor aColor ; |
404c8936 |
187 | myContext->InitSelected(); |
188 | Handle(AIS_InteractiveObject) Current = myContext->SelectedInteractive() ; |
7fd59977 |
189 | if ( Current->HasColor () ) |
190 | { |
87432b82 |
191 | Quantity_Color aShapeColor; |
192 | myContext->Color( Current, aShapeColor ); |
55a40de8 |
193 | aColor.setRgb( (Standard_Integer)(aShapeColor.Red() * 255), (Standard_Integer)(aShapeColor.Green() * 255), |
194 | (Standard_Integer)(aShapeColor.Blue() * 255)); |
7fd59977 |
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 ); |
404c8936 |
204 | for (; myContext->MoreSelected(); myContext->NextSelected() ) |
87432b82 |
205 | myContext->SetColor( myContext->SelectedInteractive(), color, Standard_False); |
0577ae8c |
206 | myContext->UpdateCurrentViewer(); |
7fd59977 |
207 | } |
208 | } |
209 | |
210 | void DocumentCommon::onMaterial( int theMaterial ) |
211 | { |
404c8936 |
212 | for ( myContext->InitSelected(); myContext->MoreSelected (); myContext->NextSelected () ) |
0577ae8c |
213 | myContext->SetMaterial( myContext->SelectedInteractive(), (Graphic3d_NameOfMaterial)theMaterial, Standard_False); |
214 | myContext->UpdateCurrentViewer(); |
7fd59977 |
215 | } |
216 | |
217 | void DocumentCommon::onMaterial() |
218 | { |
219 | DialogMaterial* m = new DialogMaterial(); |
220 | connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) ); |
221 | m->exec(); |
222 | } |
223 | |
224 | void DocumentCommon::onTransparency( int theTrans ) |
225 | { |
404c8936 |
226 | for( myContext->InitSelected(); myContext->MoreSelected(); myContext->NextSelected() ) |
0577ae8c |
227 | myContext->SetTransparency (myContext->SelectedInteractive(), ((Standard_Real)theTrans) / 10.0, Standard_False); |
228 | myContext->UpdateCurrentViewer(); |
7fd59977 |
229 | } |
230 | |
231 | void DocumentCommon::onTransparency() |
232 | { |
233 | DialogTransparency* aDialog = new DialogTransparency(); |
234 | connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) ); |
235 | aDialog->exec(); |
236 | } |
237 | |
238 | void DocumentCommon::onDelete() |
239 | { |
7140edaf |
240 | myContext->EraseSelected (Standard_False); |
0577ae8c |
241 | myContext->ClearSelected (Standard_False); |
4d6554d1 |
242 | myContext->UpdateCurrentViewer(); |
7fd59977 |
243 | getApplication()->onSelectionChanged(); |
244 | } |