Salome HOME
1d8923579eae739d8eb62c4d777cdbd24fb45e85
[modules/shaper.git] / src / XGUI / XGUI_ViewerProxy.cpp
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "XGUI_ViewerProxy.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_SalomeConnector.h"
23 #include "XGUI_Displayer.h"
24
25 #ifndef HAVE_SALOME
26   #include <AppElements_MainWindow.h>
27   #include <AppElements_ViewPort.h>
28   #include <AppElements_ViewWindow.h>
29   #include <AppElements_Viewer.h>
30 #endif
31
32 #include <ModuleBase_IViewWindow.h>
33 #include <ModuleBase_Preferences.h>
34 #include <GeomAPI_Shape.h>
35 #include <ModelAPI_ResultConstruction.h>
36
37 #include <Config_PropManager.h>
38
39 #include <SUIT_ResourceMgr.h>
40 #include <AIS_Shape.hxx>
41 #include <StdSelect_BRepOwner.hxx>
42
43 #include <QEvent>
44 #include <QKeyEvent>
45
46
47 #define HIGHLIGHT_COLOR Quantity_NOC_YELLOW
48
49 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
50     : ModuleBase_IViewer(theParent),
51       myWorkshop(theParent)
52 {
53 }
54
55 void XGUI_ViewerProxy::connectViewProxy()
56 {
57 #ifdef HAVE_SALOME
58   connect(myWorkshop->salomeConnector()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
59          SIGNAL(trihedronVisibilityChanged(bool)));
60 #else
61   connect(myWorkshop->mainWindow()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
62          SIGNAL(trihedronVisibilityChanged(bool)));
63 #endif
64 }
65
66 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
67 {
68   Handle(AIS_InteractiveContext) aContext;
69 #ifdef HAVE_SALOME
70   aContext = myWorkshop->salomeConnector()->viewer()->AISContext();
71 #else
72   aContext = myWorkshop->mainWindow()->viewer()->AISContext();
73 #endif
74   return aContext;
75 }
76
77 Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const
78 {
79 #ifdef HAVE_SALOME
80   return myWorkshop->salomeConnector()->viewer()->trihedron();
81 #else
82   return myWorkshop->mainWindow()->viewer()->trihedron();
83 #endif
84 }
85
86 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
87 {
88 #ifdef HAVE_SALOME
89   return myWorkshop->salomeConnector()->viewer()->v3dViewer();
90 #else
91   return myWorkshop->mainWindow()->viewer()->v3dViewer();
92 #endif
93 }
94
95 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
96 {
97 #ifdef HAVE_SALOME
98   return myWorkshop->salomeConnector()->viewer()->activeView();
99 #else
100   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
101   return (aViewer->activeViewWindow()) ?
102     aViewer->activeViewWindow()->viewPortApp()->getView() :
103     Handle(V3d_View)();
104 #endif
105 }
106
107 QWidget* XGUI_ViewerProxy::activeViewPort() const
108 {
109 #ifdef HAVE_SALOME
110   return myWorkshop->salomeConnector()->viewer()->activeViewPort();
111 #else
112   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
113   return (aViewer->activeViewWindow()) ?
114          aViewer->activeViewWindow()->viewPortApp(): 0;
115 #endif
116 }
117
118 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
119 {
120   Handle(V3d_View) aView3d = activeView();
121   if (!aView3d.IsNull()) {
122     aView3d->SetProj(theX, theY, theZ);
123     aView3d->SetTwist( theTwist );
124     aView3d->FitAll(0.01, false);
125     //aView3d->SetZSize(0.);
126     if (aView3d->Depth() < 0.1)
127       aView3d->DepthFitAll();
128   }
129 }
130
131 void XGUI_ViewerProxy::fitAll()
132 {
133 #ifdef HAVE_SALOME
134   myWorkshop->salomeConnector()->viewer()->fitAll();
135 #else
136   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
137   if (aViewer->activeViewWindow())
138     aViewer->activeViewWindow()->viewPortApp()->fitAll();
139 #endif
140 }
141
142 void XGUI_ViewerProxy::eraseAll()
143 {
144 #ifdef HAVE_SALOME
145   myWorkshop->salomeConnector()->viewer()->eraseAll();
146 #else
147 #endif
148 }
149
150 void XGUI_ViewerProxy::connectToViewer()
151 {
152 #ifdef HAVE_SALOME
153   ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
154
155   connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
156   connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
157     this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
158
159   connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
160     this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
161
162   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
163     this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
164
165   connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
166     this, SIGNAL(activated(ModuleBase_IViewWindow*)));
167
168   connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
169     this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
170
171   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
172     this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
173
174   connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
175           SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
176
177   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
178     this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
179
180   connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
181     this, SLOT(onKeyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
182
183   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
184     this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
185
186   connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
187
188   connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
189
190   connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
191           SIGNAL(contextMenuRequested(QContextMenuEvent*)));
192
193 #else
194   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
195
196   connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
197
198   connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
199           this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
200
201   connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
202           this, SLOT(onDeleteView(AppElements_ViewWindow*)));
203
204   connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
205           this, SLOT(onViewCreated(AppElements_ViewWindow*)));
206
207   connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
208           this, SLOT(onActivated(AppElements_ViewWindow*)));
209
210   connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
211           SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
212
213   connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
214           SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
215
216   connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
217           SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
218
219   connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
220           SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
221
222   connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
223           SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
224
225   connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
226           SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
227
228   connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
229   connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
230           SIGNAL(contextMenuRequested(QContextMenuEvent*)));
231 #endif
232 }
233
234 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
235 {
236   if (theEvent->type() == QEvent::Enter) {
237     emit enterViewPort();
238   }
239   else if (theEvent->type() == QEvent::Leave) {
240     emit leaveViewPort();
241   }
242   return ModuleBase_IViewer::eventFilter(theObject, theEvent);
243 }
244
245 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
246 {
247   theWnd->viewPort()->installEventFilter(this);
248   myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
249   emit viewCreated(theWnd);
250 }
251
252 #ifndef HAVE_SALOME
253 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
254 {
255   emit tryCloseView(theWnd);
256 }
257
258 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
259 {
260   if (myWindowScale.contains(theWnd->v3dView()))
261     myWindowScale.remove (theWnd->v3dView());
262   emit deleteView(theWnd);
263 }
264
265 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
266 {
267   theWnd->viewPort()->installEventFilter(this);
268
269   connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
270     this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
271
272   myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
273
274   emit viewCreated(theWnd);
275 }
276
277 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
278 {
279   emit activated(theWnd);
280 }
281
282 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
283 {
284   emit mousePress(theWnd, theEvent);
285 }
286
287 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
288 {
289   emit mouseRelease(theWnd, theEvent);
290 }
291
292 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
293 {
294   emit mouseDoubleClick(theWnd, theEvent);
295 }
296
297 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
298 {
299   if (theEvent->buttons() != Qt::NoButton)
300     eraseHighlight();
301   else {
302     if (myIs2dMode) {
303       bool aHighlight2d =
304         ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "highlighting-2d", true);
305       if (aHighlight2d) {
306         if (myShowHighlight)
307           eraseHighlight();
308         else
309           updateHighlight();
310       }
311       else {
312         if (myShowHighlight)
313           updateHighlight();
314         else
315           eraseHighlight();
316       }
317     }
318     else {
319       bool aHighlight3d =
320         ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "highlighting-3d", false);
321       if (aHighlight3d) {
322         if (myShowHighlight)
323           eraseHighlight();
324         else
325           updateHighlight();
326       }
327       else {
328         if (myShowHighlight)
329           updateHighlight();
330         else
331           eraseHighlight();
332       }
333     }
334   }
335   emit mouseMove(theWnd, theEvent);
336 }
337
338 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
339 {
340   myShowHighlight = theEvent->key() == Qt::Key_H;
341   emit keyPress(theWnd, theEvent);
342 }
343
344 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
345 {
346   if (theEvent->key() == Qt::Key_H) {
347     myShowHighlight = false;
348   }
349   emit keyRelease(theWnd, theEvent);
350 }
351
352 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
353 {
354   emit viewTransformed((int) theType);
355 }
356
357 #endif
358
359
360 //***************************************
361 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
362 {
363 #ifdef HAVE_SALOME
364   myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
365 #else
366   myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
367 #endif
368 }
369
370 //***************************************
371 bool XGUI_ViewerProxy::isSelectionEnabled() const
372 {
373 #ifdef HAVE_SALOME
374   return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
375 #else
376   return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
377 #endif
378 }
379
380 //***************************************
381 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
382 {
383 #ifdef HAVE_SALOME
384   myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
385 #else
386   myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
387 #endif
388 }
389
390 //***************************************
391 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
392 {
393 #ifdef HAVE_SALOME
394   return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
395 #else
396   return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
397 #endif
398 }
399
400 //***************************************
401 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
402 {
403 #ifdef HAVE_SALOME
404   return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
405 #else
406   return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
407 #endif
408 }
409
410 //***************************************
411 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
412 {
413   myWorkshop->displayer()->addSelectionFilter(theFilter);
414 }
415
416 //***************************************
417 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
418 {
419   myWorkshop->displayer()->removeSelectionFilter(theFilter);
420 }
421
422 //***************************************
423 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
424 {
425   return myWorkshop->displayer()->hasSelectionFilter(theFilter);
426 }
427
428 //***************************************
429 void XGUI_ViewerProxy::clearSelectionFilters()
430 {
431   myWorkshop->displayer()->removeFilters();
432 }
433
434 //***************************************
435 void XGUI_ViewerProxy::update()
436 {
437   myWorkshop->displayer()->updateViewer();
438 }
439
440 //***************************************
441 bool XGUI_ViewerProxy::canDragByMouse() const
442 {
443   if (myWorkshop->isSalomeMode()) {
444     ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
445     return aViewer->canDragByMouse();
446   } else {
447     return true;
448   }
449 }
450
451 //***************************************
452 Handle(AIS_Shape) createPresentation(const TopoDS_Shape& theShape, double theDeviation)
453 {
454   Handle(AIS_Shape) aAis = new AIS_Shape(theShape);
455   aAis->SetColor(HIGHLIGHT_COLOR);
456   aAis->SetZLayer(Graphic3d_ZLayerId_Top); //Graphic3d_ZLayerId_Topmost
457   aAis->Attributes()->SetDeviationCoefficient(theDeviation);
458   aAis->Attributes()->SetIsoOnPlane(false);
459   return aAis;
460 }
461
462 //***************************************
463 void XGUI_ViewerProxy::createPresentations(const ResultPtr& theRes,
464   const TopoDS_Shape& theIgnoreShape)
465 {
466   Handle(AIS_InteractiveContext) aContext = AISContext();
467   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
468   Handle(AIS_Shape) aAis;
469   Handle(AIS_InteractiveObject) anAISIO;
470   double aDeviation = 0.001;
471
472   TopoDS_Shape aTShape = theRes->shape()->impl<TopoDS_Shape>();
473   if (!aTShape.IsSame(theIgnoreShape)) {
474     AISObjectPtr aAISPrs = aDisplayer->getAISObject(theRes);
475     if (aAISPrs.get()) {
476       anAISIO = aAISPrs->impl<Handle(AIS_InteractiveObject)>();
477       aDeviation = anAISIO->Attributes()->DeviationCoefficient();
478     }
479     else {
480       aDeviation = Config_PropManager::real("Visualization", "construction_deflection");
481     }
482     aAis = createPresentation(aTShape, aDeviation);
483     myHighlights.Append(aAis);
484     aContext->Display(aAis, false);
485     aContext->Deactivate(aAis);
486   }
487 }
488
489
490 void XGUI_ViewerProxy::displayHighlight(FeaturePtr theFeature, const TopoDS_Shape& theIgnoreShape)
491 {
492   if (theFeature.get()) {
493     std::list<ResultPtr> aResults = theFeature->results();
494     std::list<ResultPtr>::const_iterator aIt;
495     for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
496       createPresentations((*aIt), theIgnoreShape);
497     }
498   }
499 }
500
501 bool XGUI_ViewerProxy::eraseHighlight()
502 {
503   Handle(AIS_InteractiveContext) aContext = AISContext();
504   Handle(AIS_InteractiveObject) anAISIO;
505   AIS_ListIteratorOfListOfInteractive aLIt;
506   bool isErased = myHighlights.Extent() > 0;
507   for (aLIt.Initialize(myHighlights); aLIt.More(); aLIt.Next()) {
508     anAISIO = aLIt.Value();
509     aContext->Remove(anAISIO, false);
510   }
511   myHighlights.Clear();
512   return isErased;
513 }
514
515 void XGUI_ViewerProxy::updateHighlight()
516 {
517   Handle(AIS_InteractiveContext) aContext = AISContext();
518   if (!aContext.IsNull()) {
519     Handle(StdSelect_BRepOwner) aOwner;
520     Handle(AIS_InteractiveObject) anIO;
521     bool isDisplayed = false;
522     TopoDS_Shape aShape, aShp;
523     ResultPtr aRes;
524     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
525     for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
526       aOwner = Handle(StdSelect_BRepOwner)::DownCast(aContext->DetectedOwner());
527       if ((!aOwner.IsNull()) && aOwner->HasShape()) {
528         aShape = aOwner->Shape();
529         anIO = Handle(AIS_InteractiveObject)::DownCast(aOwner->Selectable());
530         aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aDisplayer->getObject(anIO));
531         if (aRes.get() && (aRes != myResult)) {
532           eraseHighlight();
533           FeaturePtr aFeature = ModelAPI_Feature::feature(aRes);
534           aShp = aRes->shape()->impl<TopoDS_Shape>();
535           if ((aFeature->results().size() > 1) || (!aShp.IsSame(aShape))) {
536             myResult = aRes;
537             displayHighlight(aFeature, aShape);
538           }
539           else {
540             myResult = ResultPtr();
541           }
542           update();
543         }
544         isDisplayed = aRes.get();
545       }
546     }
547     if (!isDisplayed) {
548       if (eraseHighlight()) {
549         update();
550       }
551       myResult = ResultPtr();
552     }
553   }
554 }
555
556 #ifdef HAVE_SALOME
557 void XGUI_ViewerProxy::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
558 {
559   if (theEvent->buttons() != Qt::NoButton)
560     eraseHighlight();
561   else {
562     if (myIs2dMode) {
563       bool aHighlight2d =
564         ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "highlighting-2d", true);
565       if (aHighlight2d) {
566         if (myShowHighlight)
567           eraseHighlight();
568         else
569           updateHighlight();
570       }
571       else {
572         if (myShowHighlight)
573           updateHighlight();
574         else
575           eraseHighlight();
576       }
577     }
578     else {
579       bool aHighlight3d =
580         ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "highlighting-3d", false);
581       if (aHighlight3d) {
582         if (myShowHighlight)
583           eraseHighlight();
584         else
585           updateHighlight();
586       }
587       else {
588         if (myShowHighlight)
589           updateHighlight();
590         else
591           eraseHighlight();
592       }
593     }
594   }
595   emit mouseMove(theWnd, theEvent);
596 }
597
598 void XGUI_ViewerProxy::onKeyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
599 {
600   myShowHighlight = theEvent->key() == Qt::Key_H;
601   emit keyPress(theWnd, theEvent);
602 }
603
604 void XGUI_ViewerProxy::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
605 {
606   if (theEvent->key() == Qt::Key_H) {
607     myShowHighlight = false;
608   }
609   emit keyRelease(theWnd, theEvent);
610 }
611 #endif
612
613
614 bool XGUI_ViewerProxy::isColorScaleVisible() const
615 {
616 #ifdef HAVE_SALOME
617   return myWorkshop->salomeConnector()->viewer()->isColorScaleVisible();
618 #else
619   return myWorkshop->mainWindow()->viewer()->isColorScaleVisible();
620 #endif
621 }
622
623 void XGUI_ViewerProxy::setColorScaleShown(bool on)
624 {
625 #ifdef HAVE_SALOME
626   myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on);
627 #else
628   myWorkshop->mainWindow()->viewer()->setColorScaleShown(on);
629 #endif
630 }
631
632 void XGUI_ViewerProxy::setColorScalePosition(double theX, double theY)
633 {
634 #ifdef HAVE_SALOME
635   myWorkshop->salomeConnector()->viewer()->setColorScalePosition(theX, theY);
636 #else
637   QWidget* aWindow = activeViewPort();
638   Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale();
639   aColorScale->SetPosition(aWindow->width() * theX, aWindow->height() * theY);
640 #endif
641 }
642
643 void XGUI_ViewerProxy::setColorScaleSize(double theW, double theH)
644 {
645 #ifdef HAVE_SALOME
646   myWorkshop->salomeConnector()->viewer()->setColorScaleSize(theW, theH);
647 #else
648   QWidget* aWindow = activeViewPort();
649   Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale();
650   aColorScale->SetSize(aWindow->width() * theW, aWindow->height() * theH);
651 #endif
652 }
653
654 void XGUI_ViewerProxy::setColorScaleRange(double theMin, double theMax)
655 {
656 #ifdef HAVE_SALOME
657   myWorkshop->salomeConnector()->viewer()->setColorScaleRange(theMin, theMax);
658 #else
659   Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale();
660   aColorScale->SetRange(theMin, theMax);
661 #endif
662 }
663
664 void XGUI_ViewerProxy::setColorScaleIntervals(int theNb)
665 {
666 #ifdef HAVE_SALOME
667   myWorkshop->salomeConnector()->viewer()->setColorScaleIntervals(theNb);
668 #else
669   Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale();
670   aColorScale->SetNumberOfIntervals(theNb);
671 #endif
672 }
673
674 void XGUI_ViewerProxy::setColorScaleTextColor(const QColor& theColor)
675 {
676 #ifdef HAVE_SALOME
677   myWorkshop->salomeConnector()->viewer()->setColorScaleTextColor(theColor);
678 #else
679   Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale();
680   Quantity_Color aColor(theColor.redF(), theColor.greenF(), theColor.blueF(), Quantity_TOC_RGB);
681   aColorScale->SetColor(aColor);
682 #endif
683 }
684
685
686 void XGUI_ViewerProxy::setColorScaleTextHeigth(int theH)
687 {
688 #ifdef HAVE_SALOME
689   myWorkshop->salomeConnector()->viewer()->setColorScaleTextHeigth(theH);
690 #else
691   Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale();
692   aColorScale->SetTextHeight(theH);
693 #endif
694 }
695
696 void XGUI_ViewerProxy::setColorScaleTitle(const QString& theText)
697 {
698 #ifdef HAVE_SALOME
699   myWorkshop->salomeConnector()->viewer()->setColorScaleTitle(theText);
700 #else
701   Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale();
702   aColorScale->SetTitle(theText.toStdWString().c_str());
703 #endif
704 }
705
706
707 //******************************************************
708 void XGUI_ViewerProxy::setupColorScale()
709 {
710   SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
711   double aX = aResMgr->doubleValue("Viewer", "scalar_bar_x_position", 0.03);
712   double aY = aResMgr->doubleValue("Viewer", "scalar_bar_y_position", 0.35);
713   setColorScalePosition(aX, aY);
714
715   double aW = aResMgr->doubleValue("Viewer", "scalar_bar_width", 0.2);
716   double aH = aResMgr->doubleValue("Viewer", "scalar_bar_height", 0.5);
717   setColorScaleSize(aW, aH);
718
719   QColor aColor = aResMgr->colorValue("Viewer", "scalar_bar_text_color", Qt::black);
720   setColorScaleTextColor(aColor);
721
722   int aT = aResMgr->integerValue("Viewer", "scalar_bar_text_height", 14);
723   setColorScaleTextHeigth(aT);
724
725   int aN = aResMgr->integerValue("Viewer", "scalar_bar_nb_intervals", 20);
726   setColorScaleIntervals(aN);
727 }
728
729
730 //***************************************
731 //void XGUI_ViewerProxy::Zfitall()
732 //{
733 //#ifdef HAVE_SALOME
734 //  myWorkshop->salomeConnector()->viewer()->Zfitall();
735 //#else
736 //  AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
737 //  AppElements_ViewWindow* aView = aViewer->activeViewWindow();
738 //  if (aView) {
739 //    Handle(V3d_View) aView3d = aView->v3dView();
740 //    aView3d->ZFitAll();
741 //    if (aView3d->Depth() < 0.1)
742 //      aView3d->DepthFitAll();
743 //  }
744 //#endif
745 //}
746
747
748 #ifdef HAVE_SALOME
749 void XGUI_ViewerProxy::setFitter(OCCViewer_Fitter* theFitter)
750 {
751   myWorkshop->salomeConnector()->viewer()->setFitter(theFitter);
752 }
753
754 OCCViewer_Fitter* XGUI_ViewerProxy::fitter() const
755 {
756   return myWorkshop->salomeConnector()->viewer()->fitter();
757 }
758 #else
759 void XGUI_ViewerProxy::setFitter(AppElements_Fitter* theFitter)
760 {
761   myWorkshop->mainWindow()->viewer()->setFitter(theFitter);
762 }
763
764 AppElements_Fitter* XGUI_ViewerProxy::fitter() const
765 {
766   return myWorkshop->mainWindow()->viewer()->fitter();
767 }
768 #endif