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> |
dc3fe572 |
14 | #include <Graphic3d.hxx> |
7fd59977 |
15 | #include <Graphic3d_NameOfMaterial.hxx> |
dc3fe572 |
16 | #include <Graphic3d_GraphicDriver.hxx> |
17 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
18 | |
19 | Handle(V3d_Viewer) DocumentCommon::Viewer( const Standard_CString aDisplay, |
20 | const Standard_ExtString aName, |
21 | const Standard_CString aDomain, |
22 | const Standard_Real ViewSize, |
23 | const V3d_TypeOfOrientation ViewProj, |
24 | const Standard_Boolean ComputedMode, |
25 | const Standard_Boolean aDefaultComputedMode ) |
26 | { |
dc3fe572 |
27 | static Handle(Graphic3d_GraphicDriver) aGraphicDriver; |
28 | |
29 | if (aGraphicDriver.IsNull()) |
30 | { |
31 | Handle(Aspect_DisplayConnection) aDisplayConnection; |
32 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
33 | aDisplayConnection = new Aspect_DisplayConnection (aDisplay); |
7fd59977 |
34 | #endif |
dc3fe572 |
35 | aGraphicDriver = Graphic3d::InitGraphicDriver (aDisplayConnection); |
36 | } |
37 | |
38 | return new V3d_Viewer(aGraphicDriver,aName,aDomain,ViewSize,ViewProj, |
39 | Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT, |
40 | ComputedMode,aDefaultComputedMode,V3d_TEX_NONE); |
7fd59977 |
41 | } |
42 | |
43 | DocumentCommon::DocumentCommon( const int theIndex, ApplicationCommonWindow* app ) |
44 | : QObject( app ), |
45 | myApp( app ), |
46 | myIndex( theIndex ), |
47 | myNbViews( 0 ) |
48 | { |
49 | TCollection_ExtendedString a3DName("Visu3D"); |
50 | myViewer = Viewer( getenv("DISPLAY"), a3DName.ToExtString(), "", 1000.0, |
51 | V3d_XposYnegZpos, Standard_True, Standard_True ); |
52 | |
53 | myViewer->Init(); |
54 | myViewer->SetDefaultLights(); |
55 | myViewer->SetLightOn(); |
56 | |
57 | myContext =new AIS_InteractiveContext(myViewer); |
58 | //onCreateNewView(); |
59 | } |
60 | |
61 | DocumentCommon::~DocumentCommon() |
62 | { |
63 | } |
64 | |
65 | ApplicationCommonWindow* DocumentCommon::getApplication() |
66 | { |
67 | return myApp; |
68 | } |
69 | |
70 | MDIWindow* DocumentCommon::createNewMDIWindow() |
71 | { |
72 | QWorkspace* ws = myApp->getWorkspace(); |
73 | return new MDIWindow( this, ws, 0 ); |
74 | } |
75 | void DocumentCommon::onCreateNewView() |
76 | { |
77 | QWorkspace* ws = myApp->getWorkspace(); |
78 | MDIWindow* w = createNewMDIWindow(); |
79 | |
80 | if( !w ) |
81 | return; |
82 | |
83 | ws->addWindow( w ); |
84 | myViews.append(w); |
85 | |
86 | connect( w, SIGNAL( selectionChanged() ), |
87 | this, SIGNAL( selectionChanged() ) ); |
88 | connect( w, SIGNAL( message( const QString&, int ) ), |
89 | myApp->statusBar(), SLOT( message( const QString&, int ) ) ); |
90 | connect( w, SIGNAL( sendCloseView( MDIWindow* ) ), |
91 | this, SLOT( onCloseView( MDIWindow* ) ) ); |
92 | |
93 | QString aName; |
94 | w->setWindowTitle( aName.sprintf( "Document %d:%d", myIndex, ++myNbViews ) ); |
95 | QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" ); |
96 | |
97 | w->setWindowIcon( QPixmap( dir + QObject::tr("ICON_DOC") ) ); |
98 | |
99 | if ( ws->windowList().isEmpty() ) |
100 | { |
101 | // Due to strange Qt4.2.3 feature the child window icon is not drawn |
102 | // in the main menu if showMaximized() is called for a non-visible child window |
103 | // Therefore calling show() first... |
104 | w->show(); |
105 | w->showMaximized(); |
106 | } |
107 | else |
108 | w->show(); |
109 | |
110 | w->setFocus(); |
111 | |
112 | getApplication()->onSelectionChanged(); |
113 | } |
114 | |
115 | void DocumentCommon::onCloseView(MDIWindow* theView) |
116 | { |
117 | removeView(theView); |
118 | if( countOfWindow() == 0 ) |
119 | emit sendCloseDocument( this ); |
120 | } |
121 | |
122 | void DocumentCommon::removeView(MDIWindow* theView) |
123 | { |
124 | if ( myViews.count( theView ) ) |
125 | { |
126 | myViews.removeAll(theView); |
127 | delete theView; |
128 | } |
129 | } |
130 | void DocumentCommon::removeViews() |
131 | { |
132 | while( myViews.count() ) |
133 | removeView( (MDIWindow*)myViews.first() ); |
134 | } |
135 | |
136 | int DocumentCommon::countOfWindow() |
137 | { |
138 | return myViews.count(); |
139 | } |
140 | |
141 | Handle(AIS_InteractiveContext) DocumentCommon::getContext() |
142 | { |
143 | return myContext; |
144 | } |
145 | |
146 | void DocumentCommon::fitAll() |
147 | { |
148 | QList<MDIWindow*>::iterator i; |
149 | for ( i = myViews.begin(); i != myViews.end(); i++ ) |
150 | (*i)->fitAll(); |
151 | } |
152 | |
153 | void DocumentCommon::onWireframe() |
154 | { |
155 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
156 | for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() ) |
157 | myContext->SetDisplayMode( myContext->Current(), 0, false ); |
158 | myContext->UpdateCurrentViewer(); |
159 | getApplication()->onSelectionChanged(); |
160 | QApplication::restoreOverrideCursor(); |
161 | } |
162 | |
163 | void DocumentCommon::onShading() |
164 | { |
165 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
166 | for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() ) |
167 | myContext->SetDisplayMode( myContext->Current(), 1, false ); |
168 | myContext->UpdateCurrentViewer(); |
169 | getApplication()->onSelectionChanged(); |
170 | QApplication::restoreOverrideCursor(); |
171 | } |
172 | |
173 | void DocumentCommon::onColor() |
174 | { |
175 | QColor aColor ; |
176 | Quantity_Color aShapeColor; |
177 | myContext->InitCurrent(); |
178 | Handle_AIS_InteractiveObject Current = myContext->Current() ; |
179 | if ( Current->HasColor () ) |
180 | { |
181 | aShapeColor = myContext->Color( Current ); |
182 | aColor.setRgb( aShapeColor.Red() * 255, aShapeColor.Green() * 255, aShapeColor.Blue() * 255 ); |
183 | } |
184 | else |
185 | aColor.setRgb( 255, 255, 255 ); |
186 | |
187 | QColor aRetColor = QColorDialog::getColor( aColor ); |
188 | if ( aRetColor.isValid() ) |
189 | { |
190 | Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255., |
191 | aRetColor.blue() / 255., Quantity_TOC_RGB ); |
192 | for (; myContext->MoreCurrent(); myContext->NextCurrent() ) |
193 | myContext->SetColor( myContext->Current(), color.Name() ); |
194 | } |
195 | } |
196 | |
197 | void DocumentCommon::onMaterial( int theMaterial ) |
198 | { |
199 | for ( myContext->InitCurrent(); myContext->MoreCurrent (); myContext->NextCurrent () ) |
200 | myContext->SetMaterial( myContext->Current(), (Graphic3d_NameOfMaterial)theMaterial ); |
201 | } |
202 | |
203 | void DocumentCommon::onMaterial() |
204 | { |
205 | DialogMaterial* m = new DialogMaterial(); |
206 | connect( m, SIGNAL( sendMaterialChanged( int ) ), this, SLOT( onMaterial( int ) ) ); |
207 | m->exec(); |
208 | } |
209 | |
210 | void DocumentCommon::onTransparency( int theTrans ) |
211 | { |
212 | for( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextSelected() ) |
213 | myContext->SetTransparency( myContext->Current(), ((Standard_Real)theTrans) / 10.0 ); |
214 | } |
215 | |
216 | void DocumentCommon::onTransparency() |
217 | { |
218 | DialogTransparency* aDialog = new DialogTransparency(); |
219 | connect( aDialog, SIGNAL( sendTransparencyChanged( int ) ), this, SLOT( onTransparency( int ) ) ); |
220 | aDialog->exec(); |
221 | } |
222 | |
223 | void DocumentCommon::onDelete() |
224 | { |
225 | for ( myContext->InitCurrent(); myContext->MoreCurrent(); myContext->NextCurrent() ) |
226 | myContext->Erase( myContext->Current(), false, true ); |
227 | myContext->ClearSelected(); |
228 | getApplication()->onSelectionChanged(); |
229 | } |
230 | |
231 | |