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