7fd59977 |
1 | #if !defined WNT |
2 | #define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */ |
3 | #endif |
4 | |
5 | #include <qapplication.h> |
6 | #include <qpainter.h> |
7 | #include <qmenu.h> |
8 | #include <qcolordialog.h> |
c6c9371f |
9 | #include <qcursor.h> |
10 | #include <qevent.h> |
7fd59977 |
11 | #include <qrubberband.h> |
12 | |
13 | #include "View.h" |
14 | #include "global.h" |
15 | #include "Application.h" |
16 | #include "ViewOperations.h" |
17 | |
18 | |
19 | #include <V3d_PerspectiveView.hxx> |
20 | #include <Visual3d_View.hxx> |
21 | #include <Graphic3d_NameOfMaterial.hxx> |
22 | #include <BRepPrimAPI_MakeBox.hxx> |
23 | #include <BRepPrimAPI_MakeSphere.hxx> |
24 | #include <BRepPrimAPI_MakeTorus.hxx> |
25 | #include <gp_Pnt.hxx> |
26 | #include <gp.hxx> |
27 | #include <Geom_Axis2Placement.hxx> |
28 | #include <AIS_Shape.hxx> |
29 | #include <AIS_Line.hxx> |
30 | #include <Geom_Line.hxx> |
31 | #include <AIS_Trihedron.hxx> |
32 | //#include <TopAbs_ShapeEnum.hxx> |
33 | |
34 | #ifdef WNT |
35 | #include <WNT_Window.hxx> |
36 | #include <Graphic3d_WNTGraphicDevice.hxx> |
37 | #else |
38 | #include <GL/glx.h> |
39 | #include <X11/Xlib.h> |
40 | #include <X11/Xutil.h> |
41 | #include <X11/Xatom.h> |
42 | #include <X11/Xmu/StdCmap.h> |
43 | #undef QT_CLEAN_NAMESPACE |
44 | #include <Xw_Window.hxx> |
45 | #include <Graphic3d_GraphicDevice.hxx> |
46 | #endif |
47 | |
48 | |
49 | // the key for multi selection : |
50 | #define MULTISELECTIONKEY Qt::ShiftModifier |
51 | |
52 | // the key for shortcut ( use to activate dynamic rotation, panning ) |
53 | #define CASCADESHORTCUTKEY Qt::ControlModifier |
54 | |
55 | // for elastic bean selection |
56 | #define ValZWMin 1 |
57 | |
58 | View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent, MDIWindow* mdi ) |
59 | : QWidget( parent ), myMDI( mdi ), myRubberBand( 0 ) |
60 | { |
c6c9371f |
61 | setBackgroundRole( QPalette::NoRole );//NoBackground ); |
62 | // set focus policy to threat QContextMenuEvent from keyboard |
63 | setFocusPolicy( Qt::StrongFocus ); |
64 | setAttribute( Qt::WA_PaintOnScreen ); |
65 | setAttribute( Qt::WA_NoSystemBackground ); |
66 | |
7fd59977 |
67 | #ifndef WNT |
68 | XSynchronize( x11Display(), true ); // it is possible to use QApplication::syncX(); |
69 | #endif |
70 | |
71 | myObjDlg = NULL; |
72 | myShapeDlg = NULL; |
73 | myFirst = true; |
74 | myContext = theContext; |
75 | |
76 | myCycleCounter = -1; |
77 | |
78 | myXmin=0; |
79 | myYmin=0; |
80 | myXmax=0; |
81 | myYmax=0; |
82 | myCurZoom=0; |
83 | |
84 | #if !defined WNT |
85 | XVisualInfo* pVisualInfo; |
86 | if ( x11Display() ) { |
87 | /* Initialization with the default VisualID |
88 | */ |
89 | Visual *v = DefaultVisual( x11Display(), DefaultScreen( x11Display() ) ); |
90 | int visualID = XVisualIDFromVisual( v ); |
c6c9371f |
91 | |
7fd59977 |
92 | /* Here we use the settings from |
93 | Optimizer_ViewInfo::TxglCreateWindow() |
94 | */ |
95 | int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, |
96 | GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, |
97 | GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, |
c6c9371f |
98 | None }; |
7fd59977 |
99 | pVisualInfo = ::glXChooseVisual (x11Display(), DefaultScreen(x11Display()), visualAttr); |
100 | |
c6c9371f |
101 | if ( isVisible() ) |
7fd59977 |
102 | hide(); |
103 | |
104 | XSetWindowAttributes a; |
105 | |
106 | Window p = RootWindow( x11Display(), DefaultScreen(x11Display()) ); |
107 | a.colormap = XCreateColormap( x11Display(), RootWindow(x11Display(), |
108 | pVisualInfo->screen), pVisualInfo->visual, AllocNone ); |
109 | a.background_pixel = backgroundColor().pixel(); |
110 | a.border_pixel = black.pixel(); |
111 | if ( parentWidget() ) |
112 | p = parentWidget()->winId(); |
113 | |
114 | Window w = XCreateWindow( x11Display(), p, x(), y(), width(), height(), |
115 | 0, pVisualInfo->depth, InputOutput, pVisualInfo->visual, |
116 | CWBackPixel | CWBorderPixel | CWColormap, &a ); |
117 | Window *cmw; |
118 | Window *cmwret; |
119 | int count; |
120 | if ( XGetWMColormapWindows( x11Display(), topLevelWidget()->winId(), |
121 | &cmwret, &count ) ) { |
c6c9371f |
122 | cmw = new Window[count+1]; |
123 | memcpy( (char *)cmw, (char *)cmwret, sizeof(Window)*count ); |
124 | XFree( (char *)cmwret ); |
125 | int i; |
126 | for (i = 0; i < count; i++) { |
127 | if ( cmw[i] == winId() ) { /* replace old window */ |
128 | cmw[i] = w; |
129 | break; |
130 | } |
131 | } |
132 | if ( i >= count ) /* append new window */ |
133 | cmw[count++] = w; |
134 | } else { |
135 | count = 1; |
136 | cmw = new Window[count]; |
137 | cmw[0] = w; |
138 | } |
139 | /* Creating new window (with good VisualID) for this widget */ |
140 | create( w ); |
141 | XSetWMColormapWindows( x11Display(), topLevelWidget()->winId(), cmw, count ); |
142 | delete [] cmw; |
143 | |
144 | if ( isVisible() ) |
145 | show(); |
146 | if ( pVisualInfo ) { |
147 | XFree( (char *)pVisualInfo ); |
148 | } |
149 | XFlush( x11Display() ); |
150 | } |
151 | #endif // !defined WNT |
152 | |
153 | // will be set in OnInitial update, but, for more security : |
154 | myCurrentMode = CurAction3d_Nothing; |
155 | setMouseTracking( true ); |
156 | myView = NULL; |
7fd59977 |
157 | } |
158 | |
159 | View::~View() |
c6c9371f |
160 | { |
7fd59977 |
161 | } |
162 | |
163 | void View::init() |
c6c9371f |
164 | { |
165 | myView = myContext->CurrentViewer()->CreateView(); |
166 | int windowHandle = (int) winId(); |
167 | short hi, lo; |
168 | lo = (short) windowHandle; |
169 | hi = (short) ( windowHandle >> 16 ); |
170 | #ifdef WNT |
171 | Handle(WNT_Window) hWnd = |
172 | new WNT_Window( Handle(Graphic3d_WNTGraphicDevice):: |
173 | DownCast( myContext->CurrentViewer()->Device() ) , (int) hi, (int) lo ); |
174 | #else |
175 | Handle(Xw_Window) hWnd = |
176 | new Xw_Window( Handle(Graphic3d_GraphicDevice):: |
177 | DownCast( myContext->CurrentViewer()->Device() ), |
178 | (int) hi, (int) lo, Xw_WQ_SAMEQUALITY, Quantity_NOC_BLACK ); |
179 | #endif // WNT |
180 | myView->SetWindow( hWnd ); |
181 | if ( !hWnd->IsMapped() ) |
182 | hWnd->Map(); |
183 | myView->SetBackgroundColor(Quantity_NOC_GRAY40); |
184 | myView->MustBeResized(); |
185 | |
186 | Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement( gp::XOY() ); |
187 | myTrihedron = new AIS_Trihedron( anAxis ); |
188 | myContext->Display( myTrihedron ); |
189 | |
190 | //myView->SetAntialiasingOn(); |
191 | myComputedModeIsOn = true; |
192 | myView->SetScale(3.0316); |
193 | |
194 | // This is to update View properties dialog |
195 | emit ViewInitialized(); |
196 | } |
7fd59977 |
197 | |
198 | void View::paintEvent ( QPaintEvent * e) |
199 | { |
200 | if(myFirst) { |
201 | init(); |
202 | myFirst = false; |
203 | } |
204 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
205 | Application::startTimer(); |
206 | myView->Redraw(); |
207 | Application::stopTimer( 0, "View REDRAW", false ); |
208 | QApplication::restoreOverrideCursor(); |
209 | } |
210 | |
211 | void View::resizeEvent ( QResizeEvent * e) |
212 | { |
213 | // QApplication::syncX(); |
214 | if(!myView.IsNull()) { |
215 | myView->MustBeResized(); |
216 | } |
217 | } |
218 | |
219 | void View::mousePressEvent(QMouseEvent* e) |
220 | { |
221 | if ( e->button() == Qt::LeftButton ) { |
222 | onLButtonDown(e->modifiers(),e->pos()); |
223 | } else if(e->button() == Qt::RightButton ) { |
224 | onRButtonDown(e->modifiers(),e->pos()); |
225 | } |
226 | } |
227 | |
228 | void View::mouseReleaseEvent(QMouseEvent* e) |
229 | { |
230 | if ( e->button() == Qt::LeftButton ) { |
231 | onLButtonUp(e->modifiers(),e->pos()); |
232 | } else if(e->button() == Qt::RightButton ) { |
233 | onRButtonUp(e->modifiers(),e->pos()); |
234 | } |
235 | } |
236 | |
237 | void View::mouseMoveEvent(QMouseEvent* e) |
238 | { |
239 | onMouseMove(e->buttons(),e->modifiers(),e->pos()); |
240 | } |
241 | |
242 | void View::onLButtonDown( Qt::KeyboardModifiers nFlags, const QPoint point ) |
243 | { |
244 | // save the current mouse coordinate in min |
245 | myXmin=point.x(); myYmin=point.y(); |
246 | myXmax=point.x(); myYmax=point.y(); |
247 | |
248 | if ( nFlags == CASCADESHORTCUTKEY ) { |
249 | // Button MB1 down Control :start zomming |
250 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
251 | } |
252 | else { // if ( Ctrl ) |
253 | switch (myCurrentMode) { |
254 | |
255 | case CurAction3d_Nothing : // start a drag |
256 | if (nFlags == MULTISELECTIONKEY) |
257 | MultiDragEvent(myXmax,myYmax,-1); |
258 | else |
259 | DragEvent(myXmax,myYmax,-1); |
260 | break; |
261 | case CurAction3d_DynamicZooming : // noting |
262 | break; |
263 | case CurAction3d_WindowZooming : |
264 | case CurAction3d_MagnifyView : |
265 | break; |
266 | case CurAction3d_DynamicPanning :// noting |
267 | break; |
268 | case CurAction3d_GlobalPanning :// noting |
269 | break; |
270 | case CurAction3d_DynamicRotation : |
c6c9371f |
271 | if (!myComputedModeIsOn){ |
272 | myView->SetComputedMode(false); |
273 | } |
7fd59977 |
274 | myView->SetAnimationModeOn(); |
275 | myView->StartRotation(point.x(),point.y()); |
276 | break; |
277 | default : |
278 | Standard_Failure::Raise(" incompatible Current Mode "); |
279 | break; |
280 | } |
281 | } |
282 | } |
283 | |
284 | void View::onRButtonDown( Qt::KeyboardModifiers nFlags, const QPoint point ) |
285 | { |
c6c9371f |
286 | if ( nFlags == CASCADESHORTCUTKEY ) { |
7fd59977 |
287 | if ( !myComputedModeIsOn ) |
288 | myView->SetComputedMode(false); |
c6c9371f |
289 | // Standard_Boolean anim, deg; |
290 | // anim = myView->AnimationMode( deg ); |
291 | // if ( anim /*&& deg*/ ) { |
7fd59977 |
292 | myCycleCounter = 0; |
293 | Application::startTimer(); |
c6c9371f |
294 | myView->SetAnimationModeOn(); |
7fd59977 |
295 | // myView->SetAnimationMode(true,true); |
296 | // myContext->DeactivateStandardMode( TopAbs_SHAPE ); |
297 | // } |
298 | myView->StartRotation( point.x(),point.y() ); |
299 | } |
300 | else |
301 | Popup(); |
302 | } |
303 | |
304 | void View::onLButtonUp(Qt::KeyboardModifiers nFlags, const QPoint point) |
305 | { |
306 | if ( nFlags == CASCADESHORTCUTKEY ) |
307 | { |
308 | return; |
309 | } |
310 | else // if ( Ctrl ) |
311 | { |
312 | switch ( myCurrentMode ) |
313 | { |
314 | case CurAction3d_Nothing : |
315 | if (point.x() == myXmin && point.y() == myYmin) |
316 | { // no offset between down and up --> selectEvent |
317 | myXmax=point.x(); |
318 | myYmax=point.y(); |
319 | if (nFlags == MULTISELECTIONKEY ) |
320 | MultiInputEvent(point.x(),point.y()); |
321 | else |
322 | InputEvent (point.x(),point.y()); |
323 | } else |
324 | { |
325 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); |
326 | myXmax=point.x(); |
327 | myYmax=point.y(); |
328 | if (nFlags == MULTISELECTIONKEY) |
329 | MultiDragEvent(point.x(),point.y(),1); |
330 | else |
331 | DragEvent(point.x(),point.y(),1); |
332 | } |
333 | break; |
334 | case CurAction3d_DynamicZooming : |
335 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
336 | myCurrentMode = CurAction3d_Nothing; |
337 | emit noActiveActions(); |
338 | break; |
339 | |
340 | case CurAction3d_WindowZooming : |
341 | case CurAction3d_MagnifyView : |
342 | |
343 | DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False ); |
344 | myXmax = point.x(); |
345 | myYmax = point.y(); |
346 | |
347 | if ( ( abs( myXmin - myXmax ) > ValZWMin ) || |
348 | ( abs( myYmin - myYmax ) > ValZWMin ) ) { |
349 | |
350 | if ( myCurrentMode == CurAction3d_MagnifyView ) |
351 | myMDI->getDocument()->createMagView( myXmin, myYmin, myXmax, myYmax ); |
352 | else |
353 | myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax ); |
354 | } |
355 | myCurrentMode = CurAction3d_Nothing; |
356 | emit noActiveActions(); |
357 | break; |
358 | |
359 | case CurAction3d_DynamicPanning : |
360 | myCurrentMode = CurAction3d_Nothing; |
361 | emit noActiveActions(); |
362 | break; |
363 | case CurAction3d_GlobalPanning : |
364 | myView->Place(point.x(),point.y(),myCurZoom); |
365 | myCurrentMode = CurAction3d_Nothing; |
366 | emit noActiveActions(); |
367 | break; |
368 | case CurAction3d_DynamicRotation : |
c6c9371f |
369 | myCurrentMode = CurAction3d_Nothing; |
7fd59977 |
370 | myView->SetAnimationModeOff(); |
371 | emit noActiveActions(); |
372 | break; |
373 | default : |
374 | Standard_Failure::Raise(" incompatible Current Mode "); |
375 | break; |
376 | } //switch (myCurrentMode) |
377 | } // else // if ( Ctrl ) |
378 | } |
379 | |
380 | void View::onRButtonUp(Qt::KeyboardModifiers nFlags, const QPoint point) |
381 | { |
382 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
383 | // reset computed mode according to the stored one |
384 | // --> dynamic rotation may have change it |
c6c9371f |
385 | |
7fd59977 |
386 | if (!myComputedModeIsOn) |
c6c9371f |
387 | { |
7fd59977 |
388 | myView->SetComputedMode(false); |
389 | myComputedModeIsOn = Standard_False; |
390 | } else |
c6c9371f |
391 | { |
7fd59977 |
392 | myView->SetComputedMode(false); |
393 | myComputedModeIsOn = Standard_True; |
c6c9371f |
394 | } |
7fd59977 |
395 | |
396 | //if ( myView->AnimationModeIsOn() ) { |
397 | myView->SetAnimationModeOff(); |
398 | Application::stopTimer( myCycleCounter, "Animation next UPDATE", false ); |
399 | //} |
400 | myCycleCounter = -1; |
401 | |
402 | myView->Update(); |
403 | QApplication::restoreOverrideCursor(); |
404 | } |
405 | |
406 | void View::onMouseMove(Qt::MouseButtons btns, Qt::KeyboardModifiers nFlags, const QPoint point) |
407 | { |
408 | // ============================ LEFT BUTTON ======================= |
409 | if ( btns == Qt::LeftButton ) { |
410 | if ( nFlags == CASCADESHORTCUTKEY ) |
411 | { |
412 | // move with MB1 and Control : on the dynamic zooming |
413 | // Do the zoom in function of mouse's coordinates |
414 | myView->Zoom(myXmax,myYmax,point.x(),point.y()); |
415 | // save the current mouse coordinate in min |
416 | myXmax = point.x(); |
417 | myYmax = point.y(); |
418 | } |
419 | else // if ( Ctrl ) |
420 | { |
421 | switch (myCurrentMode) |
422 | { |
423 | case CurAction3d_Nothing : |
424 | myXmax = point.x(); |
425 | myYmax = point.y(); |
426 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); |
427 | if (nFlags == MULTISELECTIONKEY) |
428 | MultiDragEvent(myXmax,myYmax,0); |
429 | else |
430 | DragEvent(myXmax,myYmax,0); |
431 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True); |
432 | break; |
433 | case CurAction3d_DynamicZooming : |
434 | myView->Zoom(myXmax,myYmax,point.x(),point.y()); |
435 | // save the current mouse coordinate in min \n"; |
436 | myXmax=point.x(); myYmax=point.y(); |
437 | break; |
438 | case CurAction3d_WindowZooming : |
439 | case CurAction3d_MagnifyView : |
440 | myXmax = point.x(); myYmax = point.y(); |
441 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);//,LongDash); |
442 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);//,LongDash); |
443 | break; |
444 | case CurAction3d_DynamicPanning : |
445 | myView->Pan(point.x()-myXmax,myYmax-point.y()); // Realize the panning |
446 | myXmax = point.x(); |
447 | myYmax = point.y(); |
448 | break; |
449 | case CurAction3d_GlobalPanning : // nothing |
450 | break; |
451 | case CurAction3d_DynamicRotation : |
452 | myView->Rotation(point.x(),point.y()); |
453 | // myView->Redraw(); |
454 | break; |
455 | default : |
456 | Standard_Failure::Raise(" incompatible Current Mode "); |
457 | break; |
458 | }// switch (myCurrentMode) |
459 | }// if ( nFlags == CASCADESHORTCUTKEY ) else |
460 | } else // if ( btns == MK_LBUTTON) |
461 | // ============================ MIDDLE BUTTON ======================= |
462 | if ( btns == Qt::MidButton ) { |
463 | if ( nFlags == CASCADESHORTCUTKEY ) |
464 | { |
465 | myView->Pan(point.x()-myXmax,myYmax-point.y()); // Realize the panning |
466 | myXmax = point.x(); |
467 | myYmax = point.y(); |
468 | |
469 | } |
470 | } else // if ( btns == MK_MBUTTON) |
471 | // ============================ RIGHT BUTTON ======================= |
472 | if ( btns == Qt::RightButton ) { |
473 | if ( nFlags == CASCADESHORTCUTKEY ) |
474 | { |
475 | myView->Rotation(point.x(),point.y()); |
476 | } |
477 | }else //if ( btns == MK_RBUTTON) |
478 | // ============================ NO BUTTON ======================= |
479 | { // No buttons |
480 | myXmax = point.x(); myYmax = point.y(); |
481 | if (nFlags == MULTISELECTIONKEY) |
482 | MultiMoveEvent(point.x(),point.y()); |
483 | else |
484 | MoveEvent(point.x(),point.y()); |
485 | } |
486 | //Standard_Boolean anim, deg; |
487 | //anim = myView->AnimationMode( deg ); |
488 | //if ( anim /*&& deg*/ ) { |
489 | if ( myCycleCounter != -1 ) { |
490 | if ( myCycleCounter == 0 ) |
491 | Application::showTimer( "Animation first UPDATE" ); |
492 | myCycleCounter++; |
493 | } |
494 | //} |
495 | } |
496 | |
497 | void View::DragEvent( int x, int y, int TheState ) |
498 | { |
499 | // TheState == -1 button down |
500 | // TheState == 0 move |
501 | // TheState == 1 button up |
502 | |
503 | static int theButtonDownX=0; |
504 | static int theButtonDownY=0; |
505 | |
506 | if (TheState == -1) |
507 | { |
508 | theButtonDownX=x; |
509 | theButtonDownY=y; |
510 | } |
511 | |
512 | if (TheState == 0) { |
513 | myContext->Select(theButtonDownX,theButtonDownY,x,y,myView); |
514 | } |
515 | } |
516 | |
517 | void View::InputEvent( int x, int y ) |
518 | { |
519 | Application::startTimer(); |
520 | myContext->Select(); |
521 | Application::stopTimer( 0, "Single selection", false ); |
522 | } |
523 | |
524 | void View::MoveEvent( int x, int y ) |
525 | { |
526 | myContext->MoveTo(x,y,myView); |
527 | } |
528 | |
529 | void View::MultiMoveEvent( int x, int y ) |
530 | { |
531 | myContext->MoveTo(x,y,myView); |
532 | } |
533 | |
534 | void View::MultiDragEvent( int x, int y, int TheState ) |
535 | { |
536 | static int theButtonDownX=0; |
537 | static int theButtonDownY=0; |
538 | |
539 | if (TheState == -1) |
540 | { theButtonDownX=x; theButtonDownY=y;} |
541 | |
542 | if (TheState == 0) { |
543 | myContext->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myView); |
544 | emit selectionChanged(); |
545 | } |
546 | } |
547 | |
548 | void View::MultiInputEvent( int x, int y ) |
549 | { |
550 | myContext->ShiftSelect(); |
551 | emit selectionChanged(); |
552 | } |
553 | |
554 | void View::Popup() |
555 | { |
556 | QMenu* popMenu = new QMenu( this ); |
557 | |
c6c9371f |
558 | if( myContext->NbCurrents()) { |
559 | QAction* a; |
560 | myContext->InitCurrent(); |
561 | if (! myContext->Current()->IsKind(STANDARD_TYPE(AIS_Trihedron))) |
7fd59977 |
562 | { |
563 | a = new QAction( tr( "MEN_POP_OBJPROP" ), this ); |
c6c9371f |
564 | verify( connect( a, SIGNAL( activated() ), SLOT( onEditObjectProperties() ) ) ); |
7fd59977 |
565 | popMenu->addAction( a ); |
566 | |
567 | QMenu* dMode = popMenu->addMenu( tr( "MEN_POP_DISPLAYMODE" ) ); |
568 | |
569 | a = new QAction( tr( "MEN_POP_WIREFRAME" ), this ); |
c6c9371f |
570 | verify( connect( a, SIGNAL( activated() ), SLOT( onWireframeMode() ) ) ); |
7fd59977 |
571 | dMode->addAction( a ); |
c6c9371f |
572 | |
7fd59977 |
573 | a = new QAction( tr( "MEN_POP_SHADING" ), this ); |
574 | verify( connect( a, SIGNAL( activated() ), SLOT( onShadingMode() ) ) ); |
c6c9371f |
575 | dMode->addAction( a ); |
7fd59977 |
576 | } |
577 | a = new QAction( tr( "MEN_POP_REMOVEOBJECT" ), this ); |
578 | verify( connect( a, SIGNAL( activated() ), SLOT( onRemoveObject() ) ) ); |
c6c9371f |
579 | popMenu->addAction( a ); |
7fd59977 |
580 | } |
581 | else { |
582 | QAction* a = new QAction( tr( "MEN_POP_VIEWPROP" ), this ); |
583 | verify( connect( a, SIGNAL( activated() ), Application::getApplication(), SLOT( onEditViewProperties() ) ) ); |
c6c9371f |
584 | popMenu->addAction( a ); |
7fd59977 |
585 | |
586 | a = new QAction( tr( "MEN_POP_IMPORT" ), this ); |
587 | verify( connect( a, SIGNAL( activated() ), SLOT( onImportObject() ) ) ); |
c6c9371f |
588 | popMenu->addAction( a ); |
7fd59977 |
589 | |
590 | popMenu->addSeparator(); |
591 | if ( myContext->IsDisplayed( myTrihedron ) ) { |
592 | a = new QAction( tr( "MEN_POP_ERASETRIHEDRON" ), this ); |
593 | verify( connect( a, SIGNAL( activated() ), SLOT( onEraseTrihedron() ) ) ); |
c6c9371f |
594 | popMenu->addAction( a ); |
7fd59977 |
595 | } |
596 | else { |
597 | a = new QAction( tr( "MEN_POP_DISPLAYTRIHEDRON" ), this ); |
598 | verify( connect( a, SIGNAL( activated() ), SLOT( onDisplayTrihedron() ) ) ); |
c6c9371f |
599 | popMenu->addAction( a ); |
7fd59977 |
600 | } |
601 | |
602 | popMenu->addSeparator(); |
603 | a = new QAction( tr( "MEN_POP_CREATESHAPE" ), this ); |
604 | verify( connect( a, SIGNAL( activated() ), SLOT( onCreateShape() ) ) ); |
c6c9371f |
605 | popMenu->addAction( a ); |
7fd59977 |
606 | |
607 | QMenu* loadObj = popMenu->addMenu( tr( "MEN_POP_LOADOBJECT" ) ); |
608 | |
609 | a = new QAction( tr( "MEN_POP_BOX" ), this ); |
610 | verify( connect( a, SIGNAL( activated() ), SLOT( onLoadBox() ) ) ); |
c6c9371f |
611 | loadObj->addAction( a ); |
7fd59977 |
612 | |
613 | a = new QAction( tr( "MEN_POP_SPHERE" ), this ); |
614 | verify( connect( a, SIGNAL( activated() ), SLOT( onLoadSphere() ) ) ); |
c6c9371f |
615 | loadObj->addAction( a ); |
7fd59977 |
616 | |
617 | a = new QAction( tr( "MEN_POP_TORUS" ), this ); |
618 | verify( connect( a, SIGNAL( activated() ), SLOT( onLoadTorus() ) ) ); |
c6c9371f |
619 | loadObj->addAction( a ); |
7fd59977 |
620 | |
c6c9371f |
621 | // a = new QAction( tr( "MEN_POP_LINE" ), this ); |
622 | // verify( connect( a, SIGNAL( activated() ), SLOT( onLoadLine() ) ) ); |
623 | // loadObj->addAction( a ); |
7fd59977 |
624 | } |
625 | popMenu->exec( QCursor::pos() ); |
626 | } |
627 | |
628 | void View::DrawRectangle( int MinX, int MinY, int MaxX, int MaxY, bool Draw ) |
c6c9371f |
629 | { |
630 | if ( !myRubberBand ) |
631 | myRubberBand = new QRubberBand( QRubberBand::Rectangle, this ); |
632 | |
633 | myRubberBand->setGeometry( QRect( QPoint( MinX, MinY ), QPoint( MaxX, MaxY ) ).normalized() ); |
634 | myRubberBand->setVisible( Draw ); |
7fd59977 |
635 | /* |
636 | QPainter thePainter(this); |
637 | thePainter.setRasterOp(Qt::XorROP); |
638 | thePainter.setPen(Qt::white); |
639 | static int StoredMinX, StoredMaxX, StoredMinY, StoredMaxY; |
640 | static bool m_IsVisible; |
641 | |
642 | QRect aRect; |
643 | if ( m_IsVisible && !Draw) // move or up : erase at the old position |
644 | { |
645 | aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY)); |
646 | thePainter.drawRect(aRect); |
647 | m_IsVisible = false; |
648 | } |
649 | |
650 | StoredMinX = (MinX < MaxX) ? MinX: MaxX ; |
651 | StoredMinY = (MinY < MaxY) ? MinY: MaxY ; |
652 | StoredMaxX = (MinX > MaxX) ? MinX: MaxX ; |
653 | StoredMaxY = (MinY > MaxY) ? MinY: MaxY ; |
654 | |
655 | if (Draw) // move : draw |
656 | { |
657 | aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY)); |
658 | thePainter.drawRect(aRect); |
659 | m_IsVisible = true; |
660 | } |
c6c9371f |
661 | */ |
7fd59977 |
662 | } |
663 | |
664 | void View::onImportObject() |
665 | { |
666 | Application::getApplication()->importBREP(); |
667 | } |
668 | |
669 | void View::setCurrentAction() |
670 | { |
671 | myCurrentMode = CurAction3d_MagnifyView; |
672 | } |
673 | |
674 | void View::onBackground() |
675 | { |
676 | QColor aColor ; |
677 | Standard_Real R1; |
678 | Standard_Real G1; |
679 | Standard_Real B1; |
680 | myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1); |
681 | aColor.setRgb(R1*255,G1*255,B1*255); |
682 | |
683 | QColor aRetColor = QColorDialog::getColor(aColor); |
684 | |
685 | if(aRetColor.isValid()) { |
686 | R1 = aRetColor.red()/255.; |
687 | G1 = aRetColor.green()/255.; |
688 | B1 = aRetColor.blue()/255.; |
689 | myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1); |
690 | } |
691 | myView->Redraw(); |
692 | } |
693 | |
694 | Handle(V3d_View)& View::getView() |
695 | { |
696 | return myView; |
697 | } |
698 | |
699 | void View::startAction( ViewOperations::Action action ) |
700 | { |
701 | switch( action ) { |
702 | case ViewOperations::ViewFitAllId : |
703 | myView->FitAll(); |
704 | break; |
705 | case ViewOperations::ViewFitAreaId : |
706 | myCurrentMode = CurAction3d_WindowZooming; |
707 | break; |
708 | case ViewOperations::ViewZoomId : |
709 | myCurrentMode = CurAction3d_DynamicZooming; |
710 | break; |
711 | case ViewOperations::ViewPanId : |
712 | myCurrentMode = CurAction3d_DynamicPanning; |
713 | break; |
714 | case ViewOperations::ViewGlobalPanId : |
715 | myCurZoom = myView->Scale(); |
716 | // Do a Global Zoom |
717 | myView->FitAll(); |
718 | // Set the mode |
719 | myCurrentMode = CurAction3d_GlobalPanning; |
720 | break; |
721 | case ViewOperations::ViewFrontId : |
722 | myView->SetProj( V3d_Xpos ); |
723 | myView->FitAll(); |
724 | break; |
725 | case ViewOperations::ViewBackId : |
726 | myView->SetProj( V3d_Xneg ); |
727 | myView->FitAll(); |
728 | break; |
729 | case ViewOperations::ViewTopId : |
730 | myView->SetProj( V3d_Zpos ); |
731 | myView->FitAll(); |
732 | break; |
733 | case ViewOperations::ViewBottomId : |
734 | myView->SetProj( V3d_Zneg ); |
735 | myView->FitAll(); |
736 | break; |
737 | case ViewOperations::ViewLeftId : |
738 | myView->SetProj( V3d_Ypos ); |
739 | myView->FitAll(); |
740 | break; |
741 | case ViewOperations::ViewRightId : |
742 | myView->SetProj( V3d_Yneg ); |
743 | myView->FitAll(); |
744 | break; |
745 | case ViewOperations::ViewAxoId : |
746 | myView->SetProj( V3d_XposYnegZpos ); |
747 | myView->FitAll(); |
748 | break; |
749 | case ViewOperations::ViewRotationId : |
750 | myCurrentMode = CurAction3d_DynamicRotation; |
751 | break; |
752 | case ViewOperations::ViewResetId : |
753 | myView->Reset(); |
754 | break; |
755 | } |
756 | } |
757 | |
758 | void View::onCreateShape() |
c6c9371f |
759 | { |
7fd59977 |
760 | myView->SetScale(3.0316); |
761 | if ( !myShapeDlg ) |
762 | myShapeDlg = new ShapeDlg( Application::getApplication(), myView, myContext ); |
763 | myShapeDlg->show(); |
764 | } |
765 | |
766 | void View::onLoadBox() |
c6c9371f |
767 | { |
7fd59977 |
768 | myView->SetScale(1.0); |
769 | Standard_Real size = myContext->CurrentViewer()->DefaultViewSize() / 4.; |
770 | gp_Pnt origin( -size / 2., -size / 2., -size / 2. ); |
771 | //myContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_RED); |
772 | Handle(AIS_Shape) box = |
773 | new AIS_Shape( BRepPrimAPI_MakeBox( origin, size, size, size ).Shape() ); |
774 | myContext->SetDisplayMode( box, myMDI->getDisplayMode(), false ); |
775 | |
776 | Application::startTimer(); |
777 | myContext->Display( box, false ); |
778 | Application::stopTimer( 0, "Display Box" ); |
779 | |
780 | Application::startTimer(); |
781 | myView->Update(); |
782 | Application::stopTimer( 0, "UPDATE" ); |
783 | } |
784 | |
785 | void View::onLoadSphere() |
c6c9371f |
786 | { |
7fd59977 |
787 | myView->SetScale(1.0); |
788 | Standard_Real radius = myContext->CurrentViewer()->DefaultViewSize() / 4.; |
789 | Handle(AIS_Shape) sphere = |
790 | new AIS_Shape( BRepPrimAPI_MakeSphere( radius ).Shape() ); |
791 | myContext->SetDisplayMode( sphere, myMDI->getDisplayMode(), false ); |
792 | |
793 | Application::startTimer(); |
794 | myContext->Display( sphere, false ); |
795 | Application::stopTimer( 0, "Display Sphere" ); |
796 | |
797 | Application::startTimer(); |
798 | //myContext->UpdateCurrentViewer(); |
799 | myView->Update(); |
800 | Application::stopTimer( 0, "UPDATE" ); |
801 | } |
802 | |
803 | void View::onLoadTorus() |
c6c9371f |
804 | { |
7fd59977 |
805 | myView->SetScale(1.0); |
806 | Handle(V3d_Viewer) viewer = myContext->CurrentViewer(); |
807 | Standard_Real r1 = viewer->DefaultViewSize() / 3.; |
808 | Standard_Real r2 = viewer->DefaultViewSize() / 6.; |
809 | Handle(AIS_Shape) torus = new AIS_Shape( BRepPrimAPI_MakeTorus( r1,r2 ).Shape() ); |
810 | myContext->SetDisplayMode( torus, myMDI->getDisplayMode(), false ); |
811 | |
812 | Application::startTimer(); |
813 | myContext->Display( torus, false ); |
814 | Application::stopTimer( 0, "Display Torus" ); |
815 | |
816 | Application::startTimer(); |
817 | //myContext->UpdateCurrentViewer(); |
818 | myView->Update(); |
819 | Application::stopTimer( 0, "UPDATE" ); |
820 | } |
821 | |
822 | void View::onLoadLine() |
c6c9371f |
823 | { |
7fd59977 |
824 | myView->SetScale(1.0); |
825 | Handle(AIS_Line) line = |
826 | new AIS_Line( new Geom_Line( gp_Pnt( 0, 0, 0), gp_Dir( 0, 0, 1) ) ); |
827 | myContext->Display( line ); |
828 | myContext->UpdateCurrentViewer(); |
829 | } |
830 | |
831 | void View::onEditObjectProperties() |
832 | { |
833 | if ( !myObjDlg ) |
834 | myObjDlg = new ObjectDlg( Application::getApplication(), myView, myContext ); |
835 | myObjDlg->show(); |
836 | } |
837 | |
838 | void View::onRemoveObject() |
839 | { |
840 | myContext->InitSelected(); |
841 | for( ; myContext->MoreSelected(); myContext->InitSelected() ) |
842 | myContext->Remove( myContext->SelectedInteractive(), false ); |
843 | myContext->UpdateCurrentViewer(); |
844 | } |
845 | |
846 | void View::onWireframeMode() |
847 | { |
848 | myContext->InitSelected(); |
849 | for( ; myContext->MoreSelected(); myContext->NextSelected() ) { |
850 | Handle(AIS_InteractiveObject) obj = myContext->SelectedInteractive(); |
851 | //myContext->Erase( obj, false ); |
852 | //myContext->Display( obj, /*0, 0,*/ false ); |
853 | //myContext->Activate( obj, 0 ); |
854 | myContext->SetDisplayMode( obj, 0 ); |
855 | } |
856 | myContext->UpdateCurrentViewer(); |
857 | } |
858 | |
859 | void View::onShadingMode() |
c6c9371f |
860 | { |
861 | |
862 | myContext->InitSelected(); |
863 | for( ; myContext->MoreSelected(); myContext->NextSelected() ) { |
864 | Handle(AIS_InteractiveObject) obj = myContext->SelectedInteractive(); |
865 | //myContext->Erase( obj, false ); |
866 | //myContext->Display( obj /*, 1, 0*/, false ); |
867 | //myContext->Activate( obj, 0 ); |
868 | myContext->SetDisplayMode( obj, 1 ); |
869 | } |
870 | myContext->UpdateCurrentViewer(); |
871 | |
7fd59977 |
872 | } |
873 | |
874 | void View::onDisplayTrihedron() |
875 | { |
876 | myContext->Display( myTrihedron ); |
877 | } |
878 | |
879 | void View::onEraseTrihedron() |
880 | { |
881 | myContext->Erase( myTrihedron ); |
882 | } |
883 | |