-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.cxx
1727 lines (1519 loc) · 51.5 KB
/
View.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
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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if !defined WNT
#define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
#endif
#include <iosfwd>
#include "View.h"
#include "ApplicationCommon.h"
#include <QApplication>
#include <QPainter>
#include <QMenu>
#include <QColorDialog>
#include <QCursor>
#include <QFileInfo>
#include <QFileDialog>
#include <QMouseEvent>
#include <QRubberBand>
#include <QMdiSubWindow>
#include <QStyleFactory>
#include <Visual3d_View.hxx>
#include <Graphic3d_ExportFormat.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <Geom_CartesianPoint.hxx>
#include <gp_Pln.hxx>
#include <IntAna_IntConicQuad.hxx>
#include <ElCLib.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#if defined(_WIN32) || defined(__WIN32__)
#include <WNT_Window.hxx>
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
#include <Cocoa_Window.hxx>
#else
#include <QX11Info>
#include <GL/glx.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xmu/StdCmap.h>
#include <X11/Xlib.h>
#include <Xw_Window.hxx>
#include <QColormap>
#endif
#include <math.h>
#include <Aspect_DisplayConnection.hxx>
/*!
ConvertToPlane convert 2d window position to 3d point on privileged plane.
*/
Standard_Boolean View::ConvertToPlane(Handle(V3d_View) const myView,
const Standard_Real Xs,
const Standard_Real Ys,
Standard_Real& X,
Standard_Real& Y,
Standard_Real& Z,
Standard_Boolean usePrecision)
{
Standard_Real Xp = Xs, Yp = Ys;
Standard_Real Xv, Yv, Zv;
Standard_Real Vx, Vy, Vz;
gp_Pln aPlane(myView->Viewer()->PrivilegedPlane());
myView->Convert( Xp, Yp, Xv, Yv, Zv );
myView->Proj( Vx, Vy, Vz );
gp_Lin aLine(gp_Pnt(Xv, Yv, Zv), gp_Dir(Vx, Vy, Vz));
IntAna_IntConicQuad theIntersection (aLine, aPlane, Precision::Angular());
if (theIntersection.IsDone())
{
if (!theIntersection.IsParallel())
{
if (theIntersection.NbPoints() > 0)
{
gp_Pnt theSolution(theIntersection.Point(1));
X = theSolution.X();
Y = theSolution.Y();
Z = theSolution.Z();
if (usePrecision)
{
Standard_Real myPrecision = 1.0;
X = (X < 0. ? -1 : (X > 0. ? 1 : 0.)) * floor((abs(X)) / myPrecision) * myPrecision;
Y = (Y < 0. ? -1 : (Y > 0. ? 1 : 0.)) * floor((abs(Y)) / myPrecision) * myPrecision;
Z = (Z < 0. ? -1 : (Z > 0. ? 1 : 0.)) * floor((abs(Z)) / myPrecision) * myPrecision;
}
return Standard_True;
}
}
}
return Standard_False;
}
void View::arch_wall::construct_wall(Handle(AIS_InteractiveContext) ais_ctx, gp_Pnt const& corner, Standard_Real dx, Standard_Real dy, Standard_Real dz)
{
dy = dy == 0 ? 1 : dy;
// Create geometric points
gp_Pnt p0(corner);
gp_Pnt p1(p0.X(), p0.Y(), p0.Z() + dz);
gp_Pnt p2(p0.X(), p0.Y() + dy, p0.Z() + dz);
gp_Pnt p3(p0.X(), p0.Y() + dy, p0.Z());
gp_Pnt p4(p0.X() + dx, p0.Y() + dy, p0.Z());
gp_Pnt p5(p0.X() + dx, p0.Y() + dy, p0.Z() + dz);
gp_Pnt p6(p0.X() + dx, p0.Y(), p0.Z() + dz);
gp_Pnt p7(p0.X() + dx, p0.Y(), p0.Z());
// Create topological vertices
TopoDS_Vertex v0 = BRepBuilderAPI_MakeVertex(p0);
TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(p1);
TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(p2);
TopoDS_Vertex v3 = BRepBuilderAPI_MakeVertex(p3);
TopoDS_Vertex v4 = BRepBuilderAPI_MakeVertex(p4);
TopoDS_Vertex v5 = BRepBuilderAPI_MakeVertex(p5);
TopoDS_Vertex v6 = BRepBuilderAPI_MakeVertex(p6);
TopoDS_Vertex v7 = BRepBuilderAPI_MakeVertex(p7);
_vertices.Clear();
_vertices.Append(v0);
_vertices.Append(v1);
_vertices.Append(v2);
_vertices.Append(v3);
_vertices.Append(v4);
_vertices.Append(v5);
_vertices.Append(v6);
_vertices.Append(v7);
// Create topological edges
TopoDS_Edge e0 = BRepBuilderAPI_MakeEdge(v0, v1);
TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(v1, v2);
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(v2, v3);
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(v3, v0);
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(v4, v5);
TopoDS_Edge e5 = BRepBuilderAPI_MakeEdge(v5, v6);
TopoDS_Edge e6 = BRepBuilderAPI_MakeEdge(v6, v7);
TopoDS_Edge e7 = BRepBuilderAPI_MakeEdge(v7, v4);
TopoDS_Edge e8 = BRepBuilderAPI_MakeEdge(v2, v3);
TopoDS_Edge e9 = BRepBuilderAPI_MakeEdge(v3, v4);
TopoDS_Edge e10 = BRepBuilderAPI_MakeEdge(v4, v5);
TopoDS_Edge e11 = BRepBuilderAPI_MakeEdge(v5, v2);
TopoDS_Edge e12 = BRepBuilderAPI_MakeEdge(v0, v1);
TopoDS_Edge e13 = BRepBuilderAPI_MakeEdge(v1, v6);
TopoDS_Edge e14 = BRepBuilderAPI_MakeEdge(v6, v7);
TopoDS_Edge e15 = BRepBuilderAPI_MakeEdge(v7, v0);
TopoDS_Edge e16 = BRepBuilderAPI_MakeEdge(v1, v2);
TopoDS_Edge e17 = BRepBuilderAPI_MakeEdge(v2, v5);
TopoDS_Edge e18 = BRepBuilderAPI_MakeEdge(v5, v6);
TopoDS_Edge e19 = BRepBuilderAPI_MakeEdge(v6, v1);
TopoDS_Edge e20 = BRepBuilderAPI_MakeEdge(v0, v3);
TopoDS_Edge e21 = BRepBuilderAPI_MakeEdge(v3, v4);
TopoDS_Edge e22 = BRepBuilderAPI_MakeEdge(v4, v7);
TopoDS_Edge e23 = BRepBuilderAPI_MakeEdge(v7, v0);
_edges.Clear();
_edges.Append(e0);
_edges.Append(e1);
_edges.Append(e2);
_edges.Append(e3);
_edges.Append(e4);
_edges.Append(e5);
_edges.Append(e6);
_edges.Append(e7);
_edges.Append(e8);
_edges.Append(e9);
_edges.Append(e10);
_edges.Append(e11);
_edges.Append(e12);
_edges.Append(e13);
_edges.Append(e14);
_edges.Append(e15);
_edges.Append(e16);
_edges.Append(e17);
_edges.Append(e18);
_edges.Append(e19);
_edges.Append(e20);
_edges.Append(e21);
_edges.Append(e22);
_edges.Append(e23);
// Create topological wire
TopoDS_Wire w0 = BRepBuilderAPI_MakeWire(e0, e1, e2, e3);
TopoDS_Wire w1 = BRepBuilderAPI_MakeWire(e4, e5, e6, e7);
TopoDS_Wire w2 = BRepBuilderAPI_MakeWire(e8, e9, e10, e11);
TopoDS_Wire w3 = BRepBuilderAPI_MakeWire(e12, e13, e14, e15);
TopoDS_Wire w4 = BRepBuilderAPI_MakeWire(e16, e17, e18, e19);
TopoDS_Wire w5 = BRepBuilderAPI_MakeWire(e20, e21, e22, e23);
_wires.Clear();
_wires.Append(w0);
_wires.Append(w1);
_wires.Append(w2);
_wires.Append(w3);
_wires.Append(w4);
_wires.Append(w5);
// Create topological faces
TopoDS_Face f0 = BRepBuilderAPI_MakeFace(w0);
TopoDS_Face f1 = BRepBuilderAPI_MakeFace(w1);
TopoDS_Face f2 = BRepBuilderAPI_MakeFace(w2);
TopoDS_Face f3 = BRepBuilderAPI_MakeFace(w3);
TopoDS_Face f4 = BRepBuilderAPI_MakeFace(w4);
TopoDS_Face f5 = BRepBuilderAPI_MakeFace(w5);
_faces.Clear();
_faces.Append(f0);
_faces.Append(f1);
_faces.Append(f2);
_faces.Append(f3);
_faces.Append(f4);
_faces.Append(f5);
ais_ctx->ActivateStandardMode(TopAbs_FACE);
ais_ctx->ActivateStandardMode(TopAbs_VERTEX);
//BRep_Builder builder;
//TopoDS_Compound comp;
//builder.MakeCompound(comp);
//builder.Add(comp, v0);
//builder.Add(comp, v1);
//builder.Add(comp, v2);
//builder.Add(comp, v3);
//builder.Add(comp, v4);
//builder.Add(comp, v5);
//builder.Add(comp, v6);
//builder.Add(comp, v7);
//BRepBuilderAPI_Transform xform(comp, tr);
//ais_ctx->Remove(_vertices_shape, 0);
//_vertices_shape = new AIS_Shape(xform.Shape());
//ais_ctx->Display(_vertices_shape, 0);
{
BRepBuilderAPI_Sewing sewing;
sewing.SetNonManifoldMode(Standard_False);
sewing.Add(f0);
sewing.Add(f1);
sewing.Add(f2);
sewing.Add(f3);
sewing.Add(f4);
sewing.Add(f5);
sewing.Perform();
BRep_Builder builder;
TopoDS_Solid solid;
builder.MakeSolid(solid);
TopoDS_Shell sewed = TopoDS::Shell(sewing.SewedShape());
builder.Add(solid, sewed);
builder.Add(solid, v0);
builder.Add(solid, v1);
builder.Add(solid, v2);
builder.Add(solid, v3);
builder.Add(solid, v4);
builder.Add(solid, v5);
builder.Add(solid, v6);
builder.Add(solid, v7);
//ais_ctx->SetDisplayMode(AIS_Shaded);
ais_ctx->SetDisplayMode(AIS_WireFrame);
gp_Vec w(_start, gp_Pnt(_start.X() + dx, _start.Y() + dy, _start.Z()/* + dz*/));
gp_Quaternion qua(_old_dir, w);
gp_Trsf tr;
tr.SetRotation(qua);
BRepBuilderAPI_Transform xform(solid, tr);
ais_ctx->Remove(_shape, 0);
_shape = new AIS_Shape(xform.Shape());
ais_ctx->SetMaterial(_shape, Graphic3d_NOM_PLASTIC, 0);
ais_ctx->Display(_shape, 1);
}
}
void View::arch_wall::make_wall(Handle(V3d_View) const myView, gp_Pnt const& corner, Standard_Real dx, Standard_Real dy, Standard_Real dz)
{
if(_wall != 0)
{
delete _wall;
}
Standard_Real xv, yv, zv;
ConvertToPlane(myView, dx, dy, xv, yv, zv, Standard_False);
_wall = new BRepPrimAPI_MakeBox(corner, gp_Pnt(corner.X() + dx, corner.Y() + dy, dz));
_wall->Build();
for(TopTools_ListIteratorOfListOfShape it(_wall->Generated(_wall->Solid())); it.More(); it.Next())
{
switch(it.Value().ShapeType())
{
case TopAbs_COMPOUND:
qDebug("TopAbs_COMPOUND\n");
break;
case TopAbs_COMPSOLID:
qDebug("TopAbs_COMPSOLID\n");
break;
case TopAbs_SOLID:
qDebug("TopAbs_SOLID\n");
break;
case TopAbs_SHELL:
qDebug("TopAbs_SHELL\n");
break;
case TopAbs_FACE:
qDebug("TopAbs_FACE\n");
break;
case TopAbs_WIRE:
qDebug("TopAbs_WIRE\n");
break;
case TopAbs_EDGE:
qDebug("TopAbs_EDGE\n");
break;
case TopAbs_VERTEX:
qDebug("TopAbs_VERTEX\n");
break;
case TopAbs_SHAPE:
qDebug("TopAbs_SHAPE\n");
break;
default:
qDebug("Unknown\n");
break;
}
}
}
// the key for multi selection :
#define MULTISELECTIONKEY Qt::ShiftModifier
// the key for shortcut ( use to activate dynamic rotation, panning )
#define CASCADESHORTCUTKEY Qt::ControlModifier
// for elastic bean selection
#define ValZWMin 1
static QCursor* defCursor = NULL;
static QCursor* handCursor = NULL;
static QCursor* panCursor = NULL;
static QCursor* globPanCursor = NULL;
static QCursor* zoomCursor = NULL;
static QCursor* rotCursor = NULL;
View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
: QWidget( parent ),
myIsRaytracing( false ),
myIsShadowsEnabled (true),
myIsReflectionsEnabled (true),
myIsAntialiasingEnabled (false),
myViewActions( 0 ),
myRaytraceActions( 0 ),
myBackMenu( NULL ),
_wall(0)
{
#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
//XSynchronize( x11Display(),true ); // it is possible to use QApplication::syncX();
XSynchronize( x11Info().display(),true ); // it is possible to use QApplication::syncX();
#endif
myFirst = true;
myContext = theContext;
_wall._length = 1;
//if (theRT)
// myContext->SetDisplayMode( AIS_DisplayMode::AIS_Shaded, 1 );
myXmin = 0;
myYmin = 0;
myXmax = 0;
myYmax = 0;
myCurZoom = 0;
myRectBand = 0;
_times_pressed = 0;
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
XVisualInfo* pVisualInfo;
if ( x11Info().display() )
{
/* Initialization with the default VisualID */
Visual *v = DefaultVisual( x11Info().display(), DefaultScreen( x11Info().display() ) );
int visualID = XVisualIDFromVisual( v );
/* Here we use the settings from Optimizer_ViewInfo::TxglCreateWindow() */
int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None };
pVisualInfo = ::glXChooseVisual( x11Info().display(), DefaultScreen( x11Info().display() ), visualAttr );
if ( isVisible() )
hide();
XSetWindowAttributes a;
Window p = RootWindow( x11Info().display(), DefaultScreen( x11Info().display() ) );
a.colormap = XCreateColormap( x11Info().display(), RootWindow( x11Info().display(), pVisualInfo->screen ),
pVisualInfo->visual, AllocNone );
QColor color = palette().color( backgroundRole() );
QColormap colmap = QColormap::instance();
a.background_pixel = colmap.pixel( color );
a.border_pixel = colmap.pixel( Qt::black );
if ( parentWidget() )
p = parentWidget()->winId();
Window w = XCreateWindow( x11Info().display(), p, x(), y(), width(), height(),
0, pVisualInfo->depth, InputOutput, pVisualInfo->visual,
CWBackPixel | CWBorderPixel | CWColormap, &a );
Window *cmw;
Window *cmwret;
int count;
if ( XGetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), &cmwret, &count ) )
{
cmw = new Window[count+1];
memcpy( (char *)cmw, (char *)cmwret, sizeof(Window)*count );
XFree( (char *)cmwret );
int i;
for ( i = 0; i < count; i++ )
{
if ( cmw[i] == winId() ) /* replace old window */
{
cmw[i] = w;
break;
}
}
if ( i >= count ) /* append new window */
cmw[count++] = w;
}
else
{
count = 1;
cmw = new Window[count];
cmw[0] = w;
}
/* Creating new window (with good VisualID) for this widget */
create(w);
XSetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), cmw, count );
delete [] cmw;
if ( isVisible() )
show();
if ( pVisualInfo )
XFree( (char *)pVisualInfo );
XFlush( x11Info().display() );
}
#endif
myCurrentMode = CurAction3d_Nothing;
myHlrModeIsOn = Standard_False;
setMouseTracking( true );
if( myFirst )
{
init();
myFirst = false;
}
initViewActions();
initCursors();
connect(this, SIGNAL(scene_display(Handle_AIS_InteractiveContext, ch_arch_object&, bool)),
ch_scene::scene_builder(), SLOT(on_display(Handle_AIS_InteractiveContext, ch_arch_object&, bool)));
connect(this, SIGNAL(scene_erase(Handle_AIS_InteractiveContext, ch_arch_object&)),
ch_scene::scene_builder(), SLOT(on_erase(Handle_AIS_InteractiveContext, ch_arch_object&)));
setBackgroundRole( QPalette::NoRole );//NoBackground );
// set focus policy to threat QContextMenuEvent from keyboard
setFocusPolicy( Qt::StrongFocus );
setAttribute( Qt::WA_PaintOnScreen );
setAttribute( Qt::WA_NoSystemBackground );
}
View::~View()
{
myContext->CloseLocalContext();
delete myBackMenu;
}
void View::init()
{
if ( myView.IsNull() )
myView = myContext->CurrentViewer()->CreateView();
#if defined(_WIN32) || defined(__WIN32__)
Aspect_Handle aWindowHandle = (Aspect_Handle )winId();
Handle(WNT_Window) hWnd = new WNT_Window (aWindowHandle);
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
NSView* aViewHandle = (NSView* )winId();
Handle(Cocoa_Window) hWnd = new Cocoa_Window (aViewHandle);
#else
Window aWindowHandle = (Window )winId();
Handle(Aspect_DisplayConnection) aDispConnection = myContext->CurrentViewer()->Driver()->GetDisplayConnection();
Handle(Xw_Window) hWnd = new Xw_Window (aDispConnection, aWindowHandle);
#endif // WNT
myView->SetWindow (hWnd);
if ( !hWnd->IsMapped() )
{
hWnd->Map();
}
myView->SetBackgroundColor (Quantity_NOC_BLACK);
myView->MustBeResized();
if (myIsRaytracing)
myView->SetRaytracingMode();
myView->ZBufferTriedronSetup(Quantity_NOC_RED,Quantity_NOC_GREEN,Quantity_NOC_BLUE1,0.8,0.05,12);
myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER,Quantity_NOC_WHITE,0.1,V3d_ZBUFFER);
myView->SetProj( V3d_Zpos );
//Standard_Real Vx, Vy, Vz;
//myView->Proj(Vx, Vy, Vz);
gp_Ax3 Ax3(gp_Pnt(), gp_Dir(0, 0, 1));
//gp_Ax3 Ax3(myView->Viewer()->PrivilegedPlane().Location(), myView->Viewer()->PrivilegedPlane().Axis().Direction());
myView->Viewer()->SetPrivilegedPlane(Ax3);
myView->Viewer()->SetRectangularGridValues(0, 0, 50, 50, 0);
myView->Viewer()->SetRectangularGridGraphicValues(1000, 1000, 0);
myView->Viewer()->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines);
myContext->OpenLocalContext();
}
void View::paintEvent( QPaintEvent * )
{
// QApplication::syncX();
if( myFirst )
{
init();
myFirst = false;
}
myView->Redraw();
}
void View::resizeEvent( QResizeEvent * )
{
// QApplication::syncX();
if( !myView.IsNull() )
{
myView->MustBeResized();
}
}
void View::fitAll()
{
myView->FitAll();
myView->ZFitAll();
myView->Redraw();
}
void View::fitArea()
{
myCurrentMode = CurAction3d_WindowZooming;
}
void View::zoom()
{
myCurrentMode = CurAction3d_DynamicZooming;
}
void View::pan()
{
myCurrentMode = CurAction3d_DynamicPanning;
}
void View::rotation()
{
myCurrentMode = CurAction3d_DynamicRotation;
}
void View::draw_point()
{
myCurrentMode = CurAction3d_DrawPoint;
}
void View::draw_line()
{
myCurrentMode = CurAction3d_DrawLine;
}
void View::draw_wall()
{
reference<ch_arch_object> wall(new ch_wall());
connect(this, SIGNAL(wall_begin_construct(Handle_V3d_View const, gp_Pnt2d const&)),
wall, SLOT(on_begin_construct(Handle_V3d_View const, gp_Pnt2d const&)));
connect(this, SIGNAL(wall_constructing(Handle_V3d_View const, gp_Pnt2d const&)),
wall, SLOT(on_constructing(Handle_V3d_View const, gp_Pnt2d const&)));
connect(this, SIGNAL(wall_cancel_construct()),
wall, SLOT(on_cancel_construct()));
connect(this, SIGNAL(wall_end_construct(Handle_V3d_View const, gp_Pnt2d const&)),
wall, SLOT(on_end_construct(Handle_V3d_View const, gp_Pnt2d const&)));
connect(wall, SIGNAL(canceled(ch_arch_object&)), this, SLOT(on_wall_canceled(ch_arch_object&)));
connect(wall, SIGNAL(constructed(ch_arch_object&)), this, SLOT(on_wall_constructed(ch_arch_object&)));
_coll.add(wall);
myCurrentMode = CurAction3d_DrawWall;
}
void View::on_wall_canceled(ch_arch_object& obj)
{
emit scene_erase(myContext, obj);
_coll.remove(ch_arch_object::ref_type(&obj));
}
void View::on_wall_constructed(ch_arch_object& obj)
{
emit scene_display(myContext, obj, true);
}
void View::globalPan()
{
// save the current zoom value
myCurZoom = myView->Scale();
// Do a Global Zoom
myView->FitAll();
// Set the mode
myCurrentMode = CurAction3d_GlobalPanning;
}
void View::front()
{
myView->SetProj( V3d_Xpos );
}
void View::back()
{
myView->SetProj( V3d_Xneg );
}
void View::top()
{
myView->SetProj( V3d_Zpos );
}
void View::bottom()
{
myView->SetProj( V3d_Zneg );
}
void View::left()
{
myView->SetProj( V3d_Ypos );
}
void View::right()
{
myView->SetProj( V3d_Yneg );
}
void View::axo()
{
myView->SetProj( V3d_XposYnegZpos );
}
void View::reset()
{
myView->Reset();
}
void View::hlrOff()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
myHlrModeIsOn = Standard_False;
myView->SetComputedMode (myHlrModeIsOn);
QApplication::restoreOverrideCursor();
}
void View::hlrOn()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
myHlrModeIsOn = Standard_True;
myView->SetComputedMode (myHlrModeIsOn);
QApplication::restoreOverrideCursor();
}
void View::SetRaytracedShadows (bool theState)
{
if (theState)
myView->EnableRaytracedShadows();
else
myView->DisableRaytracedShadows();
myIsShadowsEnabled = theState;
myContext->UpdateCurrentViewer();
}
void View::SetRaytracedReflections (bool theState)
{
if (theState)
myView->EnableRaytracedReflections();
else
myView->DisableRaytracedReflections();
myIsReflectionsEnabled = theState;
myContext->UpdateCurrentViewer();
}
void View::onRaytraceAction()
{
QAction* aSentBy = (QAction*)sender();
if (aSentBy == myRaytraceActions->at (ToolRaytracingId))
{
bool aState = myRaytraceActions->at (ToolRaytracingId)->isChecked();
QApplication::setOverrideCursor (Qt::WaitCursor);
if (aState)
EnableRaytracing();
else
DisableRaytracing();
QApplication::restoreOverrideCursor();
}
if (aSentBy == myRaytraceActions->at (ToolShadowsId))
{
bool aState = myRaytraceActions->at (ToolShadowsId)->isChecked();
SetRaytracedShadows (aState);
}
if (aSentBy == myRaytraceActions->at (ToolReflectionsId))
{
bool aState = myRaytraceActions->at (ToolReflectionsId)->isChecked();
SetRaytracedReflections (aState);
}
if (aSentBy == myRaytraceActions->at (ToolAntialiasingId))
{
bool aState = myRaytraceActions->at (ToolAntialiasingId)->isChecked();
SetRaytracedAntialiasing (aState);
}
}
void View::SetRaytracedAntialiasing (bool theState)
{
if (theState)
myView->EnableRaytracedAntialiasing();
else
myView->DisableRaytracedAntialiasing();
myIsAntialiasingEnabled = theState;
myContext->UpdateCurrentViewer();
}
void View::EnableRaytracing()
{
if (!myIsRaytracing)
myView->SetRaytracingMode();
myIsRaytracing = true;
myContext->UpdateCurrentViewer();
}
void View::DisableRaytracing()
{
if (myIsRaytracing)
myView->SetRasterizationMode();
myIsRaytracing = false;
myContext->UpdateCurrentViewer();
}
void View::updateToggled( bool isOn )
{
QAction* sentBy = (QAction*)sender();
if( !isOn )
return;
for ( int i = ViewFitAllId; i < ViewHlrOffId; i++ )
{
QAction* anAction = myViewActions->at( i );
if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
( anAction == myViewActions->at( ViewZoomId ) ) ||
( anAction == myViewActions->at( ViewPanId ) ) ||
( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
( anAction == myViewActions->at( ViewRotationId ) ) )
{
if ( anAction && ( anAction != sentBy ) )
{
anAction->setCheckable( true );
anAction->setChecked( false );
}
else
{
if ( sentBy == myViewActions->at( ViewFitAreaId ) )
setCursor( *handCursor );
else if ( sentBy == myViewActions->at( ViewZoomId ) )
setCursor( *zoomCursor );
else if ( sentBy == myViewActions->at( ViewPanId ) )
setCursor( *panCursor );
else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
setCursor( *globPanCursor );
else if ( sentBy == myViewActions->at( ViewRotationId ) )
setCursor( *rotCursor );
else
setCursor( *defCursor );
sentBy->setCheckable( false );
}
}
}
}
void View::initCursors()
{
if ( !defCursor )
defCursor = new QCursor( Qt::ArrowCursor );
if ( !handCursor )
handCursor = new QCursor( Qt::PointingHandCursor );
if ( !panCursor )
panCursor = new QCursor( Qt::SizeAllCursor );
if ( !globPanCursor )
globPanCursor = new QCursor( Qt::CrossCursor );
if ( !zoomCursor )
zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
if ( !rotCursor )
rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
}
QList<QAction*>* View::getViewActions()
{
initViewActions();
return myViewActions;
}
QList<QAction*>* View::getRaytraceActions()
{
initRaytraceActions();
return myRaytraceActions;
}
/*!
Get paint engine for the OpenGL viewer. [ virtual public ]
*/
QPaintEngine* View::paintEngine() const
{
return 0;
}
void View::initViewActions()
{
if ( myViewActions )
return;
myViewActions = new QList<QAction*>();
QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
QAction* a;
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
a->setToolTip( QObject::tr("TBR_FITALL") );
a->setStatusTip( QObject::tr("TBR_FITALL") );
connect( a, SIGNAL( triggered() ) , this, SLOT( fitAll() ) );
myViewActions->insert(ViewFitAllId, a);
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
a->setToolTip( QObject::tr("TBR_FITAREA") );
a->setStatusTip( QObject::tr("TBR_FITAREA") );
connect( a, SIGNAL( triggered() ) , this, SLOT( fitArea() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
myViewActions->insert( ViewFitAreaId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
a->setToolTip( QObject::tr("TBR_ZOOM") );
a->setStatusTip( QObject::tr("TBR_ZOOM") );
connect( a, SIGNAL( triggered() ) , this, SLOT( zoom() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewZoomId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
a->setToolTip( QObject::tr("TBR_PAN") );
a->setStatusTip( QObject::tr("TBR_PAN") );
connect( a, SIGNAL( triggered() ) , this, SLOT( pan() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewPanId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
connect( a, SIGNAL( triggered() ) , this, SLOT( globalPan() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewGlobalPanId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
a->setToolTip( QObject::tr("TBR_FRONT") );
a->setStatusTip( QObject::tr("TBR_FRONT") );
connect( a, SIGNAL( triggered() ) , this, SLOT( front() ) );
myViewActions->insert( ViewFrontId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
a->setToolTip( QObject::tr("TBR_BACK") );
a->setStatusTip( QObject::tr("TBR_BACK") );
connect( a, SIGNAL( triggered() ) , this, SLOT( back() ) );
myViewActions->insert(ViewBackId, a);
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
a->setToolTip( QObject::tr("TBR_TOP") );
a->setStatusTip( QObject::tr("TBR_TOP") );
connect( a, SIGNAL( triggered() ) , this, SLOT( top() ) );
myViewActions->insert( ViewTopId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
a->setToolTip( QObject::tr("TBR_BOTTOM") );
a->setStatusTip( QObject::tr("TBR_BOTTOM") );
connect( a, SIGNAL( triggered() ) , this, SLOT( bottom() ) );
myViewActions->insert( ViewBottomId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
a->setToolTip( QObject::tr("TBR_LEFT") );
a->setStatusTip( QObject::tr("TBR_LEFT") );
connect( a, SIGNAL( triggered() ) , this, SLOT( left() ) );
myViewActions->insert( ViewLeftId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
a->setToolTip( QObject::tr("TBR_RIGHT") );
a->setStatusTip( QObject::tr("TBR_RIGHT") );
connect( a, SIGNAL( triggered() ) , this, SLOT( right() ) );
myViewActions->insert( ViewRightId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
a->setToolTip( QObject::tr("TBR_AXO") );
a->setStatusTip( QObject::tr("TBR_AXO") );
connect( a, SIGNAL( triggered() ) , this, SLOT( axo() ) );
myViewActions->insert( ViewAxoId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
a->setToolTip( QObject::tr("TBR_ROTATION") );
a->setStatusTip( QObject::tr("TBR_ROTATION") );
connect( a, SIGNAL( triggered() ) , this, SLOT( rotation() ) );
a->setCheckable( true );
connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
myViewActions->insert( ViewRotationId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
a->setToolTip( QObject::tr("TBR_RESET") );
a->setStatusTip( QObject::tr("TBR_RESET") );
connect( a, SIGNAL( triggered() ) , this, SLOT( reset() ) );
myViewActions->insert( ViewResetId, a );
QActionGroup* ag = new QActionGroup( this );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
a->setToolTip( QObject::tr("TBR_HLROFF") );
a->setStatusTip( QObject::tr("TBR_HLROFF") );
connect( a, SIGNAL( triggered() ) , this, SLOT( hlrOff() ) );
a->setCheckable( true );
ag->addAction(a);
myViewActions->insert(ViewHlrOffId, a);
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
a->setToolTip( QObject::tr("TBR_HLRON") );
a->setStatusTip( QObject::tr("TBR_HLRON") );
connect( a, SIGNAL( triggered() ) ,this, SLOT( hlrOn() ) );
a->setCheckable( true );
ag->addAction(a);
myViewActions->insert( ViewHlrOnId, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_DRAW_PNT"), this );
a->setToolTip( QObject::tr("DRAW_PNT") );
a->setStatusTip( QObject::tr("DRAW_PNT") );
connect( a, SIGNAL( triggered() ) ,this, SLOT( draw_point() ) );
ag->addAction(a);
myViewActions->insert( ViewDrawPoint, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_DRAW_LN"), this );
a->setToolTip( QObject::tr("DRAW_LN") );
a->setStatusTip( QObject::tr("DRAW_LN") );
connect( a, SIGNAL( triggered() ) ,this, SLOT( draw_line() ) );
ag->addAction(a);
myViewActions->insert( ViewDrawLine, a );
a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_DRAW_WL"), this );
a->setToolTip( QObject::tr("DRAW_WL") );
a->setStatusTip( QObject::tr("DRAW_WL") );
connect( a, SIGNAL( triggered() ) ,this, SLOT( draw_wall() ) );
ag->addAction(a);
myViewActions->insert( ViewDrawWall, a );
}
void View::initRaytraceActions()
{
if ( myRaytraceActions )
return;
myRaytraceActions = new QList<QAction*>();