forked from eryar/occQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoccQt.cpp
620 lines (488 loc) · 21.7 KB
/
occQt.cpp
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*
* Copyright (c) 2014 eryar All Rights Reserved.
*
* File : occQt.cpp
* Author : [email protected]
* Date : 2014-07-15 21:00
* Version : OpenCASCADE6.8.0 & Qt5.4
*
* Description : Qt main window for OpenCASCADE.
*/
#include "occqt.h"
#include "OccView.h"
#include <QToolBar>
#include <QTreeView>
#include <QMessageBox>
#include <QDockWidget>
#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Pln.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeCone.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakeTorus.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepFilletAPI_MakeFillet2d.hxx>
#include <BRepFilletAPI_MakeChamfer.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <Aspect_DisplayConnection.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <AIS_Shape.hxx>
occQt::occQt(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
// occ modeler.
InitializeModeler();
mOccView = new OccView(mContext, this);
setCentralWidget(mOccView);
createActions();
createMenus();
createToolBars();
}
occQt::~occQt()
{
}
void occQt::createActions( void )
{
mExitAction = new QAction(tr("Exit"), this);
mExitAction->setShortcut(tr("Ctrl+Q"));
mExitAction->setIcon(QIcon(":/Resources/close.png"));
mExitAction->setStatusTip(tr("Exit the application"));
connect(mExitAction, SIGNAL(triggered()), this, SLOT(close()));
mViewZoomAction = new QAction(tr("Zoom"), this);
mViewZoomAction->setIcon(QIcon(":/Resources/Zoom.png"));
mViewZoomAction->setStatusTip(tr("Zoom the view"));
connect(mViewZoomAction, SIGNAL(triggered()), mOccView, SLOT(zoom()));
mViewPanAction = new QAction(tr("Pan"), this);
mViewPanAction->setIcon(QIcon(":/Resources/Pan.png"));
mViewPanAction->setStatusTip(tr("Pan the view"));
connect(mViewPanAction, SIGNAL(triggered()), mOccView, SLOT(pan()));
mViewRotateAction = new QAction(tr("Rotate"), this);
mViewRotateAction->setIcon(QIcon(":/Resources/Rotate.png"));
mViewRotateAction->setStatusTip(tr("Rotate the view"));
connect(mViewRotateAction, SIGNAL(triggered()), mOccView, SLOT(rotate()));
mViewResetAction = new QAction(tr("Reset"), this);
mViewResetAction->setIcon(QIcon(":/Resources/Home.png"));
mViewResetAction->setStatusTip(tr("Reset the view"));
connect(mViewResetAction, SIGNAL(triggered()), mOccView, SLOT(reset()));
mViewFitallAction = new QAction(tr("Fit All"), this);
mViewFitallAction->setIcon(QIcon(":/Resources/FitAll.png"));
mViewFitallAction->setStatusTip(tr("Fit all "));
connect(mViewFitallAction, SIGNAL(triggered()), mOccView, SLOT(fitAll()));
mMakeBoxAction = new QAction(tr("Box"), this);
mMakeBoxAction->setIcon(QIcon(":/Resources/box.png"));
mMakeBoxAction->setStatusTip(tr("Make a box"));
connect(mMakeBoxAction, SIGNAL(triggered()), this, SLOT(makeBox()));
mMakeConeAction = new QAction(tr("Cone"), this);
mMakeConeAction->setIcon(QIcon(":/Resources/cone.png"));
mMakeConeAction->setStatusTip(tr("Make a cone"));
connect(mMakeConeAction, SIGNAL(triggered()), this, SLOT(makeCone()));
mMakeSphereAction = new QAction(tr("Sphere"), this);
mMakeSphereAction->setStatusTip(tr("Make a sphere"));
mMakeSphereAction->setIcon(QIcon(":/Resources/sphere.png"));
connect(mMakeSphereAction, SIGNAL(triggered()), this, SLOT(makeSphere()));
mMakeCylinderAction = new QAction(tr("Cylinder"), this);
mMakeCylinderAction->setStatusTip(tr("Make a cylinder"));
mMakeCylinderAction->setIcon(QIcon(":/Resources/cylinder.png"));
connect(mMakeCylinderAction, SIGNAL(triggered()), this, SLOT(makeCylinder()));
mMakeTorusAction = new QAction(tr("Torus"), this);
mMakeTorusAction->setStatusTip(tr("Make a torus"));
mMakeTorusAction->setIcon(QIcon(":/Resources/torus.png"));
connect(mMakeTorusAction, SIGNAL(triggered()), this, SLOT(makeTorus()));
mFilletAction = new QAction(tr("Fillet"), this);
mFilletAction->setIcon(QIcon(":/Resources/fillet.png"));
mFilletAction->setStatusTip(tr("Test Fillet algorithm"));
connect(mFilletAction, SIGNAL(triggered()), this, SLOT(makeFillet()));
mChamferAction = new QAction(tr("Chamfer"), this);
mChamferAction->setIcon(QIcon(":/Resources/chamfer.png"));
mChamferAction->setStatusTip(tr("Test chamfer algorithm"));
connect(mChamferAction, SIGNAL(triggered()), this, SLOT(makeChamfer()));
mExtrudeAction = new QAction(tr("Extrude"), this);
mExtrudeAction->setIcon(QIcon(":/Resources/extrude.png"));
mExtrudeAction->setStatusTip(tr("Test extrude algorithm"));
connect(mExtrudeAction, SIGNAL(triggered()), this, SLOT(makeExtrude()));
mRevolveAction = new QAction(tr("Revolve"), this);
mRevolveAction->setIcon(QIcon(":/Resources/revolve.png"));
mRevolveAction->setStatusTip(tr("Test revol algorithm"));
connect(mRevolveAction, SIGNAL(triggered()), this, SLOT(makeRevol()));
mLoftAction = new QAction(tr("Loft"), this);
mLoftAction->setIcon(QIcon(":/Resources/loft.png"));
mLoftAction->setStatusTip(tr("Test loft algorithm"));
connect(mLoftAction, SIGNAL(triggered()), this, SLOT(makeLoft()));
mCutAction = new QAction(tr("Cut"), this);
mCutAction->setIcon(QIcon(":/Resources/cut.png"));
mCutAction->setStatusTip(tr("Boolean operation cut"));
connect(mCutAction, SIGNAL(triggered()), this, SLOT(testCut()));
mFuseAction = new QAction(tr("Fuse"), this);
mFuseAction->setIcon(QIcon(":/Resources/fuse.png"));
mFuseAction->setStatusTip(tr("Boolean operation fuse"));
connect(mFuseAction, SIGNAL(triggered()), this, SLOT(testFuse()));
mCommonAction = new QAction(tr("Common"), this);
mCommonAction->setIcon(QIcon(":/Resources/common.png"));
mCommonAction->setStatusTip(tr("Boolean operation common"));
connect(mCommonAction, SIGNAL(triggered()), this, SLOT(testCommon()));
mAboutAction = new QAction(tr("About"), this);
mAboutAction->setStatusTip(tr("About the application"));
mAboutAction->setIcon(QIcon(":/Resources/lamp.png"));
connect(mAboutAction, SIGNAL(triggered()), this, SLOT(about()));
}
void occQt::createMenus( void )
{
mFileMenu = menuBar()->addMenu(tr("&File"));
mFileMenu->addAction(mExitAction);
mViewMenu = menuBar()->addMenu(tr("&View"));
mViewMenu->addAction(mViewZoomAction);
mViewMenu->addAction(mViewPanAction);
mViewMenu->addAction(mViewRotateAction);
mViewMenu->addSeparator();
mViewMenu->addAction(mViewResetAction);
mViewMenu->addAction(mViewFitallAction);
mPrimitiveMenu = menuBar()->addMenu(tr("&Primitive"));
mPrimitiveMenu->addAction(mMakeBoxAction);
mPrimitiveMenu->addAction(mMakeConeAction);
mPrimitiveMenu->addAction(mMakeSphereAction);
mPrimitiveMenu->addAction(mMakeCylinderAction);
mPrimitiveMenu->addAction(mMakeTorusAction);
mModelingMenu = menuBar()->addMenu(tr("&Modeling"));
mModelingMenu->addAction(mFilletAction);
mModelingMenu->addAction(mChamferAction);
mModelingMenu->addAction(mExtrudeAction);
mModelingMenu->addAction(mRevolveAction);
mModelingMenu->addAction(mLoftAction);
mModelingMenu->addSeparator();
mModelingMenu->addAction(mCutAction);
mModelingMenu->addAction(mFuseAction);
mModelingMenu->addAction(mCommonAction);
mHelpMenu = menuBar()->addMenu(tr("&Help"));
mHelpMenu->addAction(mAboutAction);
}
void occQt::createToolBars( void )
{
mNavigateToolBar = addToolBar(tr("&Navigate"));
mNavigateToolBar->addAction(mViewZoomAction);
mNavigateToolBar->addAction(mViewPanAction);
mNavigateToolBar->addAction(mViewRotateAction);
mViewToolBar = addToolBar(tr("&View"));
mViewToolBar->addAction(mViewResetAction);
mViewToolBar->addAction(mViewFitallAction);
mPrimitiveToolBar = addToolBar(tr("&Primitive"));
mPrimitiveToolBar->addAction(mMakeBoxAction);
mPrimitiveToolBar->addAction(mMakeConeAction);
mPrimitiveToolBar->addAction(mMakeSphereAction);
mPrimitiveToolBar->addAction(mMakeCylinderAction);
mPrimitiveToolBar->addAction(mMakeTorusAction);
mModelingToolBar = addToolBar(tr("&Modeling"));
mModelingToolBar->addAction(mFilletAction);
mModelingToolBar->addAction(mChamferAction);
mModelingToolBar->addAction(mExtrudeAction);
mModelingToolBar->addAction(mRevolveAction);
mModelingToolBar->addAction(mLoftAction);
mModelingToolBar->addSeparator();
mModelingToolBar->addAction(mCutAction);
mModelingToolBar->addAction(mFuseAction);
mModelingToolBar->addAction(mCommonAction);
mHelpToolBar = addToolBar(tr("Help"));
mHelpToolBar->addAction(mAboutAction);
}
void occQt::about()
{
QMessageBox::about(this, tr("About occQt"),
tr("<h2>occQt 2.0</h2>"
"<p>Copyright © 2014 [email protected]"
"<p>occQt is a demo applicaton about Qt and OpenCASCADE."));
}
void occQt::InitializeModeler()
{
Handle_Aspect_DisplayConnection aDisplayConnection;
Handle_OpenGl_GraphicDriver aGraphicDriver;
// 1. Create a 3D viewer.
try
{
aGraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
}
catch (Standard_Failure)
{
QMessageBox::critical(this, tr("About occQt"),
tr("<h2>Fatal error in graphic initialisation!</h2>"),
QMessageBox::Apply);
}
mViewer = new V3d_Viewer(aGraphicDriver, Standard_ExtString("Visu3D"));
mViewer->SetDefaultLights();
mViewer->SetLightOn();
// 3. Create an interactive context.
mContext = new AIS_InteractiveContext(mViewer);
mContext->SetDisplayMode(AIS_Shaded);
}
void occQt::makeBox()
{
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(3.0, 4.0, 5.0);
Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
anAisBox->SetColor(Quantity_NOC_AZURE);
mContext->Display(anAisBox);
}
void occQt::makeCone()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 10.0, 0.0));
TopoDS_Shape aTopoReducer = BRepPrimAPI_MakeCone(anAxis, 3.0, 1.5, 5.0);
Handle_AIS_Shape anAisReducer = new AIS_Shape(aTopoReducer);
anAisReducer->SetColor(Quantity_NOC_BISQUE);
anAxis.SetLocation(gp_Pnt(8.0, 10.0, 0.0));
TopoDS_Shape aTopoCone = BRepPrimAPI_MakeCone(anAxis, 3.0, 0.0, 5.0);
Handle_AIS_Shape anAisCone = new AIS_Shape(aTopoCone);
anAisCone->SetColor(Quantity_NOC_CHOCOLATE);
mContext->Display(anAisReducer);
mContext->Display(anAisCone);
}
void occQt::makeSphere()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 20.0, 0.0));
TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 3.0);
Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere);
anAisSphere->SetColor(Quantity_NOC_BLUE1);
mContext->Display(anAisSphere);
}
void occQt::makeCylinder()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 30.0, 0.0));
TopoDS_Shape aTopoCylinder = BRepPrimAPI_MakeCylinder(anAxis, 3.0, 5.0);
Handle_AIS_Shape anAisCylinder = new AIS_Shape(aTopoCylinder);
anAisCylinder->SetColor(Quantity_NOC_RED);
anAxis.SetLocation(gp_Pnt(8.0, 30.0, 0.0));
TopoDS_Shape aTopoPie = BRepPrimAPI_MakeCylinder(anAxis, 3.0, 5.0, M_PI_2 * 3.0);
Handle_AIS_Shape anAisPie = new AIS_Shape(aTopoPie);
anAisPie->SetColor(Quantity_NOC_TAN);
mContext->Display(anAisCylinder);
mContext->Display(anAisPie);
}
void occQt::makeTorus()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 40.0, 0.0));
TopoDS_Shape aTopoTorus = BRepPrimAPI_MakeTorus(anAxis, 3.0, 1.0);
Handle_AIS_Shape anAisTorus = new AIS_Shape(aTopoTorus);
anAisTorus->SetColor(Quantity_NOC_YELLOW);
anAxis.SetLocation(gp_Pnt(8.0, 40.0, 0.0));
TopoDS_Shape aTopoElbow = BRepPrimAPI_MakeTorus(anAxis, 3.0, 1.0, M_PI_2);
Handle_AIS_Shape anAisElbow = new AIS_Shape(aTopoElbow);
anAisElbow->SetColor(Quantity_NOC_THISTLE);
mContext->Display(anAisTorus);
mContext->Display(anAisElbow);
}
void occQt::makeFillet()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 50.0, 0.0));
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
BRepFilletAPI_MakeFillet MF(aTopoBox);
// Add all the edges to fillet.
for (TopExp_Explorer ex(aTopoBox, TopAbs_EDGE); ex.More(); ex.Next())
{
MF.Add(1.0, TopoDS::Edge(ex.Current()));
}
Handle_AIS_Shape anAisShape = new AIS_Shape(MF.Shape());
anAisShape->SetColor(Quantity_NOC_VIOLET);
mContext->Display(anAisShape);
}
void occQt::makeChamfer()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(8.0, 50.0, 0.0));
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
BRepFilletAPI_MakeChamfer MC(aTopoBox);
TopTools_IndexedDataMapOfShapeListOfShape aEdgeFaceMap;
TopExp::MapShapesAndAncestors(aTopoBox, TopAbs_EDGE, TopAbs_FACE, aEdgeFaceMap);
for (Standard_Integer i = 1; i <= aEdgeFaceMap.Extent(); ++i)
{
TopoDS_Edge anEdge = TopoDS::Edge(aEdgeFaceMap.FindKey(i));
TopoDS_Face aFace = TopoDS::Face(aEdgeFaceMap.FindFromIndex(i).First());
MC.Add(0.6, 0.6, anEdge, aFace);
}
Handle_AIS_Shape anAisShape = new AIS_Shape(MC.Shape());
anAisShape->SetColor(Quantity_NOC_TOMATO);
mContext->Display(anAisShape);
}
void occQt::makeExtrude()
{
// prism a vertex result is an edge.
TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 60.0, 0.0));
TopoDS_Shape aPrismVertex = BRepPrimAPI_MakePrism(aVertex, gp_Vec(0.0, 0.0, 5.0));
Handle_AIS_Shape anAisPrismVertex = new AIS_Shape(aPrismVertex);
// prism an edge result is a face.
TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 60.0, 0.0), gp_Pnt(10.0, 60.0, 0.0));
TopoDS_Shape aPrismEdge = BRepPrimAPI_MakePrism(anEdge, gp_Vec(0.0, 0.0, 5.0));
Handle_AIS_Shape anAisPrismEdge = new AIS_Shape(aPrismEdge);
// prism a wire result is a shell.
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(16.0, 60.0, 0.0));
TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(anAxis, 3.0));
TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge);
TopoDS_Shape aPrismCircle = BRepPrimAPI_MakePrism(aCircleWire, gp_Vec(0.0, 0.0, 5.0));
Handle_AIS_Shape anAisPrismCircle = new AIS_Shape(aPrismCircle);
// prism a face or a shell result is a solid.
anAxis.SetLocation(gp_Pnt(24.0, 60.0, 0.0));
TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(anAxis, 3.0, 2.0));
TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge);
TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire);
TopoDS_Shape aPrismEllipse = BRepPrimAPI_MakePrism(aEllipseFace, gp_Vec(0.0, 0.0, 5.0));
Handle_AIS_Shape anAisPrismEllipse = new AIS_Shape(aPrismEllipse);
anAisPrismVertex->SetColor(Quantity_NOC_PAPAYAWHIP);
anAisPrismEdge->SetColor(Quantity_NOC_PEACHPUFF);
anAisPrismCircle->SetColor(Quantity_NOC_PERU);
anAisPrismEllipse->SetColor(Quantity_NOC_PINK);
mContext->Display(anAisPrismVertex);
mContext->Display(anAisPrismEdge);
mContext->Display(anAisPrismCircle);
mContext->Display(anAisPrismEllipse);
}
void occQt::makeRevol()
{
gp_Ax1 anAxis;
// revol a vertex result is an edge.
anAxis.SetLocation(gp_Pnt(0.0, 70.0, 0.0));
TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(2.0, 70.0, 0.0));
TopoDS_Shape aRevolVertex = BRepPrimAPI_MakeRevol(aVertex, anAxis);
Handle_AIS_Shape anAisRevolVertex = new AIS_Shape(aRevolVertex);
// revol an edge result is a face.
anAxis.SetLocation(gp_Pnt(8.0, 70.0, 0.0));
TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(6.0, 70.0, 0.0), gp_Pnt(6.0, 70.0, 5.0));
TopoDS_Shape aRevolEdge = BRepPrimAPI_MakeRevol(anEdge, anAxis);
Handle_AIS_Shape anAisRevolEdge = new AIS_Shape(aRevolEdge);
// revol a wire result is a shell.
anAxis.SetLocation(gp_Pnt(20.0, 70.0, 0.0));
anAxis.SetDirection(gp::DY());
TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(15.0, 70.0, 0.0), gp::DZ()), 1.5));
TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge);
TopoDS_Shape aRevolCircle = BRepPrimAPI_MakeRevol(aCircleWire, anAxis, M_PI_2);
Handle_AIS_Shape anAisRevolCircle = new AIS_Shape(aRevolCircle);
// revol a face result is a solid.
anAxis.SetLocation(gp_Pnt(30.0, 70.0, 0.0));
anAxis.SetDirection(gp::DY());
TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(gp_Ax2(gp_Pnt(25.0, 70.0, 0.0), gp::DZ()), 3.0, 2.0));
TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge);
TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire);
TopoDS_Shape aRevolEllipse = BRepPrimAPI_MakeRevol(aEllipseFace, anAxis, M_PI_4);
Handle_AIS_Shape anAisRevolEllipse = new AIS_Shape(aRevolEllipse);
anAisRevolVertex->SetColor(Quantity_NOC_LIMEGREEN);
anAisRevolEdge->SetColor(Quantity_NOC_LINEN);
anAisRevolCircle->SetColor(Quantity_NOC_MAGENTA1);
anAisRevolEllipse->SetColor(Quantity_NOC_MAROON);
mContext->Display(anAisRevolVertex);
mContext->Display(anAisRevolEdge);
mContext->Display(anAisRevolCircle);
mContext->Display(anAisRevolEllipse);
}
void occQt::makeLoft()
{
// bottom wire.
TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(0.0, 80.0, 0.0), gp::DZ()), 1.5));
TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge);
// top wire.
BRepBuilderAPI_MakePolygon aPolygon;
aPolygon.Add(gp_Pnt(-3.0, 77.0, 6.0));
aPolygon.Add(gp_Pnt(3.0, 77.0, 6.0));
aPolygon.Add(gp_Pnt(3.0, 83.0, 6.0));
aPolygon.Add(gp_Pnt(-3.0, 83.0, 6.0));
aPolygon.Close();
BRepOffsetAPI_ThruSections aShellGenerator;
BRepOffsetAPI_ThruSections aSolidGenerator(true);
aShellGenerator.AddWire(aCircleWire);
aShellGenerator.AddWire(aPolygon.Wire());
aSolidGenerator.AddWire(aCircleWire);
aSolidGenerator.AddWire(aPolygon.Wire());
// translate the solid.
gp_Trsf aTrsf;
aTrsf.SetTranslation(gp_Vec(18.0, 0.0, 0.0));
BRepBuilderAPI_Transform aTransform(aSolidGenerator.Shape(), aTrsf);
Handle_AIS_Shape anAisShell = new AIS_Shape(aShellGenerator.Shape());
Handle_AIS_Shape anAisSolid = new AIS_Shape(aTransform.Shape());
anAisShell->SetColor(Quantity_NOC_OLIVEDRAB);
anAisSolid->SetColor(Quantity_NOC_PEACHPUFF);
mContext->Display(anAisShell);
mContext->Display(anAisSolid);
}
void occQt::testCut()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 90.0, 0.0));
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5);
TopoDS_Shape aCuttedShape1 = BRepAlgoAPI_Cut(aTopoBox, aTopoSphere);
TopoDS_Shape aCuttedShape2 = BRepAlgoAPI_Cut(aTopoSphere, aTopoBox);
gp_Trsf aTrsf;
aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0));
BRepBuilderAPI_Transform aTransform1(aCuttedShape1, aTrsf);
aTrsf.SetTranslation(gp_Vec(16.0, 0.0, 0.0));
BRepBuilderAPI_Transform aTransform2(aCuttedShape2, aTrsf);
Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere);
Handle_AIS_Shape anAisCuttedShape1 = new AIS_Shape(aTransform1.Shape());
Handle_AIS_Shape anAisCuttedShape2 = new AIS_Shape(aTransform2.Shape());
anAisBox->SetColor(Quantity_NOC_SPRINGGREEN);
anAisSphere->SetColor(Quantity_NOC_STEELBLUE);
anAisCuttedShape1->SetColor(Quantity_NOC_TAN);
anAisCuttedShape2->SetColor(Quantity_NOC_SALMON);
mContext->Display(anAisBox);
mContext->Display(anAisSphere);
mContext->Display(anAisCuttedShape1);
mContext->Display(anAisCuttedShape2);
}
void occQt::testFuse()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 100.0, 0.0));
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5);
TopoDS_Shape aFusedShape = BRepAlgoAPI_Fuse(aTopoBox, aTopoSphere);
gp_Trsf aTrsf;
aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0));
BRepBuilderAPI_Transform aTransform(aFusedShape, aTrsf);
Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere);
Handle_AIS_Shape anAisFusedShape = new AIS_Shape(aTransform.Shape());
anAisBox->SetColor(Quantity_NOC_SPRINGGREEN);
anAisSphere->SetColor(Quantity_NOC_STEELBLUE);
anAisFusedShape->SetColor(Quantity_NOC_ROSYBROWN);
mContext->Display(anAisBox);
mContext->Display(anAisSphere);
mContext->Display(anAisFusedShape);
}
void occQt::testCommon()
{
gp_Ax2 anAxis;
anAxis.SetLocation(gp_Pnt(0.0, 110.0, 0.0));
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5);
TopoDS_Shape aCommonShape = BRepAlgoAPI_Common(aTopoBox, aTopoSphere);
gp_Trsf aTrsf;
aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0));
BRepBuilderAPI_Transform aTransform(aCommonShape, aTrsf);
Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere);
Handle_AIS_Shape anAisCommonShape = new AIS_Shape(aTransform.Shape());
anAisBox->SetColor(Quantity_NOC_SPRINGGREEN);
anAisSphere->SetColor(Quantity_NOC_STEELBLUE);
anAisCommonShape->SetColor(Quantity_NOC_ROYALBLUE);
mContext->Display(anAisBox);
mContext->Display(anAisSphere);
mContext->Display(anAisCommonShape);
}