Salome HOME
using a better solution to do compare doubles for shape physical properties
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_SalomeViewer.cpp
1 // Copyright (C) 2014-2024  CEA, EDF
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 "SHAPERGUI_SalomeViewer.h"
21 #include "SHAPERGUI_OCCSelector.h"
22
23 #include <OCCViewer_ViewPort3d.h>
24 #include <OCCViewer_ViewFrame.h>
25 #include <OCCViewer_ViewManager.h>
26 #include <SOCC_ViewModel.h>
27 #include <SUIT_ViewManager.h>
28
29 #include <QtxActionToolMgr.h>
30 #include <SALOME_AISShape.hxx>
31
32 #include <Standard_Version.hxx>
33 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
34 #include <AIS_TextLabel.hxx>
35 #include <Graphic3d_Vec2.hxx>
36
37 #include <QMouseEvent>
38 #include <QContextMenuEvent>
39 #include <QTimer>
40
41 #if OCC_VERSION_HEX < 0x070400
42   #define SALOME_PATCH_FOR_CTRL_WHEEL
43 #endif
44
45 SHAPERGUI_SalomeView::SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer)
46 : ModuleBase_IViewWindow(), myCurrentView(0)
47 {
48   myViewer = theViewer;
49 }
50
51
52 Handle(V3d_View) SHAPERGUI_SalomeView::v3dView() const
53 {
54   Handle(V3d_View) aView;
55   if (myCurrentView) {
56     OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(myCurrentView);
57     aView = aWnd->getViewPort()->getView();
58   }
59   return aView;
60 }
61
62 QWidget* SHAPERGUI_SalomeView::viewPort() const
63 {
64   QWidget* aViewPort = 0;
65   if (myCurrentView) {
66     OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(myCurrentView);
67     aViewPort = aWnd->getViewPort();
68   }
69   return aViewPort;
70 }
71
72 //**********************************************
73 //**********************************************
74 //**********************************************
75
76
77
78 SHAPERGUI_SalomeViewer::SHAPERGUI_SalomeViewer(QObject* theParent)
79     : ModuleBase_IViewer(theParent),
80       mySelector(0), myView(0), myIsSelectionChanged(false)
81 {
82 }
83
84 SHAPERGUI_SalomeViewer::~SHAPERGUI_SalomeViewer()
85 {
86   if (myView)
87     delete myView;
88 }
89
90
91 //**********************************************
92 Handle(AIS_InteractiveContext) SHAPERGUI_SalomeViewer::AISContext() const
93 {
94   if (mySelector && mySelector->viewer())
95     return mySelector->viewer()->getAISContext();
96   Handle(AIS_InteractiveContext) aNull;
97   return aNull;
98 }
99
100 //**********************************************
101 Handle(V3d_Viewer) SHAPERGUI_SalomeViewer::v3dViewer() const
102 {
103   if (mySelector)
104     return mySelector->viewer()->getViewer3d();
105   return Handle(V3d_Viewer)();
106 }
107
108 //**********************************************
109 Handle(AIS_Trihedron) SHAPERGUI_SalomeViewer::trihedron() const
110 {
111   return mySelector->viewer()->getTrihedron();
112 }
113
114 //**********************************************
115 Handle(V3d_View) SHAPERGUI_SalomeViewer::activeView() const
116 {
117   if (mySelector) {
118     OCCViewer_Viewer* aViewer = mySelector->viewer();
119     SUIT_ViewManager* aMgr = aViewer->getViewManager();
120     OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
121     return aWnd->getViewPort()->getView();
122   }
123   return Handle(V3d_View)();
124 }
125
126 //**********************************************
127 QWidget* SHAPERGUI_SalomeViewer::activeViewPort() const
128 {
129   QWidget* aViewPort = 0;
130   if (mySelector) {
131     OCCViewer_Viewer* aViewer = mySelector->viewer();
132     SUIT_ViewManager* aMgr = aViewer->getViewManager();
133     OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
134     aViewPort = aWnd->getViewPort();
135   }
136   return aViewPort;
137 }
138
139 //**********************************************
140 void SHAPERGUI_SalomeViewer::setSelector(SHAPERGUI_OCCSelector* theSel)
141 {
142   if (mySelector) {
143     if (mySelector == theSel)
144       return;
145     else {
146       mySelector->viewer()->getViewManager()->disconnect(this);
147       OCCViewer_Viewer* aViewer = mySelector->viewer();
148       if (aViewer)
149         aViewer->disconnect(this);
150     }
151   }
152   mySelector = theSel;
153   if (!mySelector)
154     return;
155   OCCViewer_Viewer* aViewer = mySelector->viewer();
156   SUIT_ViewManager* aMgr = aViewer->getViewManager();
157
158   myView = new SHAPERGUI_SalomeView(mySelector->viewer());
159
160   // TODO: Provide ModuleBase_IViewWindow interface
161   connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
162
163   connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)),
164           this, SLOT(onTryCloseView(SUIT_ViewWindow*)));
165   connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)),
166           this, SLOT(onDeleteView(SUIT_ViewWindow*)));
167   connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)),
168           this, SLOT(onViewCreated(SUIT_ViewWindow*)));
169   connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)),
170           this, SLOT(onActivated(SUIT_ViewManager*)));
171
172   connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
173           SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
174   connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
175           SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
176   connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
177           SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
178   connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
179           SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
180
181   connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
182           SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
183   connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
184           SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
185
186   connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
187 }
188
189 //**********************************************
190 void SHAPERGUI_SalomeViewer::onSelectionChanged()
191 {
192   // Selection event must be sent only after mouse release
193   myIsSelectionChanged = true;
194 }
195
196 //**********************************************
197 void SHAPERGUI_SalomeViewer::onMousePress(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
198 {
199   myView->setCurrentView(theView);
200   emit mousePress(myView, theEvent);
201 }
202
203 //**********************************************
204 void SHAPERGUI_SalomeViewer::onMouseRelease(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
205 {
206   myView->setCurrentView(theView);
207   emit mouseRelease(myView, theEvent);
208   if (myIsSelectionChanged) {
209     emit selectionChanged();
210     myIsSelectionChanged = false;
211   }
212 }
213
214 //**********************************************
215 void SHAPERGUI_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
216 {
217   myView->setCurrentView(theView);
218   emit mouseDoubleClick(myView, theEvent);
219 }
220
221 //**********************************************
222 void SHAPERGUI_SalomeViewer::onMouseMove(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
223 {
224   myView->setCurrentView(theView);
225   emit mouseMove(myView, theEvent);
226 }
227
228 //**********************************************
229 bool SHAPERGUI_SalomeViewer::canDragByMouse() const
230 {
231   OCCViewer_Viewer* aViewer = mySelector->viewer();
232   SUIT_ViewWindow* aWnd = aViewer->getViewManager()->getActiveView();
233   OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(aWnd);
234   if (aViewWnd) {
235     return (aViewWnd->interactionStyle() == 0);
236   }
237   return true;
238 }
239
240
241 //**********************************************
242 void SHAPERGUI_SalomeViewer::onKeyPress(SUIT_ViewWindow* /*theView*/, QKeyEvent* theEvent)
243 {
244   emit keyPress(myView, theEvent);
245 }
246
247 //**********************************************
248 void SHAPERGUI_SalomeViewer::onKeyRelease(SUIT_ViewWindow* /*theView*/, QKeyEvent* theEvent)
249 {
250   emit keyRelease(myView, theEvent);
251 }
252
253 //**********************************************
254 void SHAPERGUI_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
255 {
256   emit tryCloseView(myView);
257 }
258
259 //**********************************************
260 void SHAPERGUI_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
261 {
262   if(myWindowScale.contains(myView->v3dView()))
263     myWindowScale.remove(myView->v3dView());
264   emit deleteView(myView);
265 }
266
267 //**********************************************
268 void SHAPERGUI_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView)
269 {
270   myView->setCurrentView(theView);
271
272   OCCViewer_ViewFrame* aView = dynamic_cast<OCCViewer_ViewFrame*>(theView);
273
274   OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
275   if (aWnd) {
276     connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
277       this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
278     OCCViewer_ViewPort3d* aViewPort = aWnd->getViewPort();
279     if (aViewPort)
280       connect(aViewPort, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewPortMapped()));
281     
282     OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>(aWnd->getViewManager());
283     if (aMgr) aWnd->enableAutoRotation(aMgr->isAutoRotation());
284   }
285   reconnectActions(aWnd, true);
286
287   myWindowScale.insert(aView->getViewPort()->getView(),
288                        aView->getViewPort()->getView()->Camera()->Scale());
289
290   QTimer::singleShot(10, this, SLOT(onAfterViewCreated()));
291
292   emit viewCreated(myView);
293 }
294
295 //**********************************************
296 void SHAPERGUI_SalomeViewer::onAfterViewCreated()
297 {
298   // Update trihedron and dimension arrows
299   emit onViewTransformed(OCCViewer_ViewWindow::ZOOMVIEW);
300 }
301
302
303 //**********************************************
304 void SHAPERGUI_SalomeViewer::onActivated(SUIT_ViewManager* theMgr)
305 {
306   myView->setCurrentView(theMgr->getActiveView());
307   emit activated(myView);
308 }
309
310 //**********************************************
311 void SHAPERGUI_SalomeViewer::enableSelection(bool isEnabled)
312 {
313   if (mySelector)
314     if (mySelector->viewer()->isSelectionEnabled() != isEnabled)
315       mySelector->viewer()->enableSelection(isEnabled);
316   // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking)
317   // After this is corrected, the first row should be recommented, the last - removed
318     //mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
319     //                                                    : SUIT_ViewModel::KEY_FREE);
320 }
321
322 //**********************************************
323 bool SHAPERGUI_SalomeViewer::isSelectionEnabled() const
324 {
325   if (mySelector)
326     return mySelector->viewer()->isSelectionEnabled();
327   return false;
328 }
329
330 //**********************************************
331 void SHAPERGUI_SalomeViewer::enableMultiselection(bool isEnable)
332 {
333   if (mySelector)
334     mySelector->viewer()->enableMultiselection(isEnable);
335 }
336
337 //**********************************************
338 bool SHAPERGUI_SalomeViewer::isMultiSelectionEnabled() const
339 {
340   if (mySelector)
341     return mySelector->viewer()->isMultiSelectionEnabled();
342   return false;
343 }
344
345 //**********************************************
346 bool SHAPERGUI_SalomeViewer::enableDrawMode(bool isEnabled)
347 {
348   // TODO: Has to be replaced when SALOME patch become available
349   if (mySelector)
350     return mySelector->viewer()->enableDrawMode(isEnabled);
351   return false;
352 }
353
354 //**********************************************
355 void SHAPERGUI_SalomeViewer::reconnectActions(SUIT_ViewWindow* theWindow,
356                                             const bool theUseSHAPERSlot)
357 {
358   OCCViewer_ViewWindow* aWindow = dynamic_cast<OCCViewer_ViewWindow*>(theWindow);
359   if (!aWindow)
360     return;
361
362   QAction* anAction = theWindow->toolMgr()->action(OCCViewer_ViewWindow::TrihedronShowId);
363   if (!anAction)
364     return;
365
366   if (theUseSHAPERSlot) {
367     anAction->disconnect(anAction, SIGNAL(toggled(bool)),
368                          theWindow, SLOT(onTrihedronShow(bool)));
369     anAction->connect(anAction, SIGNAL(toggled(bool)),
370                       this, SIGNAL(trihedronVisibilityChanged(bool)));
371   }
372   else {
373     anAction->connect(anAction, SIGNAL(toggled(bool)),
374                       theWindow, SLOT(onTrihedronShow(bool)));
375     anAction->disconnect(anAction, SIGNAL(toggled(bool)),
376                          this, SIGNAL(trihedronVisibilityChanged(bool)));
377   }
378 }
379
380 //**********************************************
381 void SHAPERGUI_SalomeViewer::fitAll()
382 {
383   if (mySelector) {
384     SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
385     OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
386     if (aVFrame) {
387       aVFrame->onFitAll();
388     }
389   }
390 }
391
392 //**********************************************
393 void SHAPERGUI_SalomeViewer::eraseAll()
394 {
395   Handle(AIS_InteractiveContext) aContext = AISContext();
396   if (aContext.IsNull())
397     return;
398   AIS_ListOfInteractive aList;
399   aContext->DisplayedObjects(aList);
400   AIS_ListIteratorOfListOfInteractive aLIt;
401   Handle(AIS_InteractiveObject) anAISIO;
402   for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
403     anAISIO = aLIt.Value();
404     Handle(Standard_Type) aType = anAISIO->DynamicType();
405     if (anAISIO->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
406       aContext->Erase(anAISIO, false);
407     }
408   }
409 }
410
411 //**********************************************
412 void SHAPERGUI_SalomeViewer::setViewProjection(double theX, double theY,
413                                                double theZ, double theTwist)
414 {
415   if (!mySelector)
416     return;
417
418   SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
419   OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
420   if (aVFrame) {
421     Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
422     if (!aView3d.IsNull()) {
423       aView3d->SetProj(theX, theY, theZ);
424       aView3d->SetTwist( theTwist );
425       aView3d->FitAll(0.01, false);
426       //aView3d->SetZSize(0.);
427       if (aView3d->Depth() < 0.1)
428         aView3d->DepthFitAll();
429     }
430   }
431 }
432
433 //***************************************
434 void SHAPERGUI_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
435 {
436   Handle(AIS_InteractiveContext) aContext = AISContext();
437   if (!aContext.IsNull()) {
438     aContext->AddFilter(theFilter);
439   }
440 }
441
442 //***************************************
443 void SHAPERGUI_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
444 {
445   Handle(AIS_InteractiveContext) aContext = AISContext();
446   if (!aContext.IsNull()) {
447     aContext->RemoveFilter(theFilter);
448   }
449 }
450
451 //***************************************
452 bool SHAPERGUI_SalomeViewer::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
453 {
454   bool aFoundFilter = false;
455   Handle(AIS_InteractiveContext) aContext = AISContext();
456   if (!aContext.IsNull()) {
457     const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
458     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
459     for (; aIt.More() && !aFoundFilter; aIt.Next()) {
460       aFoundFilter = theFilter.get() == aIt.Value().get();
461     }
462   }
463   return aFoundFilter;
464 }
465
466 //***************************************
467 void SHAPERGUI_SalomeViewer::clearSelectionFilters()
468 {
469   Handle(AIS_InteractiveContext) aContext = AISContext();
470   if (!aContext.IsNull()) {
471     aContext->RemoveFilters();
472   }
473 }
474
475 //***************************************
476 void SHAPERGUI_SalomeViewer::update()
477 {
478   Handle(AIS_InteractiveContext) aContext = AISContext();
479   if (!aContext.IsNull()) {
480     aContext->UpdateCurrentViewer();
481   }
482 }
483
484 //***************************************
485 void SHAPERGUI_SalomeViewer::onViewTransformed(OCCViewer_ViewWindow::OperationType theType)
486 {
487   emit viewTransformed((int) theType);
488 }
489
490 //***************************************
491 void SHAPERGUI_SalomeViewer::onViewPortMapped()
492 {
493   emit trihedronVisibilityChanged(true);
494 }
495
496 //***************************************
497 void SHAPERGUI_SalomeViewer::activateViewer(bool toActivate)
498 {
499   if (!mySelector || !mySelector->viewer())
500     return;
501   SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
502 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
503   OCCViewer_Viewer* aViewer = dynamic_cast<OCCViewer_Viewer*>(aMgr->getViewModel());
504   if (aViewer)
505     aViewer->setUseLocalSelection(toActivate);
506 #endif
507   QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
508   if (toActivate) {
509     foreach (SUIT_ViewWindow* aView, aViews) {
510       OCCViewer_ViewFrame* aOCCView = dynamic_cast<OCCViewer_ViewFrame*>(aView);
511       OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
512       connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
513         this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
514       reconnectActions(aWnd, true);
515       OCCViewer_ViewManager* aOCCMgr = dynamic_cast<OCCViewer_ViewManager*>(aMgr);
516       if (aOCCMgr) aWnd->enableAutoRotation(aOCCMgr->isAutoRotation());
517     }
518   } else {
519     foreach (SUIT_ViewWindow* aView, aViews) {
520       OCCViewer_ViewFrame* aOCCView = dynamic_cast<OCCViewer_ViewFrame*>(aView);
521       OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW);
522       disconnect((OCCViewer_ViewWindow*)aWnd,
523                  SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)),
524         this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType)));
525       reconnectActions(aWnd, false);
526       aWnd->enableAutoRotation(false);
527     }
528   }
529 }
530
531 bool SHAPERGUI_SalomeViewer::isColorScaleVisible() const
532 {
533   if (mySelector) {
534     return mySelector->viewer()->isColorScaleVisible();
535   }
536   return false;
537 }
538
539 void SHAPERGUI_SalomeViewer::setColorScaleShown(bool on)
540 {
541   if (mySelector) {
542     mySelector->viewer()->setColorScaleShown(on);
543   }
544 }
545
546 void SHAPERGUI_SalomeViewer::setColorScalePosition(double theX, double theY)
547 {
548   if (mySelector) {
549     QWidget* aWindow = activeViewPort();
550     mySelector->viewer()->getColorScale()->SetPosition(aWindow->width() * theX,
551       aWindow->height() * theY);
552   }
553 }
554
555 void SHAPERGUI_SalomeViewer::setColorScaleSize(double theW, double theH)
556 {
557   if (mySelector) {
558     QWidget* aWindow = activeViewPort();
559     mySelector->viewer()->getColorScale()->SetSize(aWindow->width() * theW,
560       aWindow->height() * theH);
561   }
562 }
563
564 void SHAPERGUI_SalomeViewer::setColorScaleRange(double theMin, double theMax)
565 {
566   if (mySelector) {
567     mySelector->viewer()->getColorScale()->SetRange(theMin, theMax);
568   }
569 }
570
571 void SHAPERGUI_SalomeViewer::setColorScaleIntervals(int theNb)
572 {
573   if (mySelector) {
574     mySelector->viewer()->getColorScale()->SetNumberOfIntervals(theNb);
575   }
576 }
577
578 void SHAPERGUI_SalomeViewer::setColorScaleTextHeigth(int theH)
579 {
580   if (mySelector) {
581     mySelector->viewer()->getColorScale()->SetTextHeight(theH);
582   }
583 }
584
585 void SHAPERGUI_SalomeViewer::setColorScaleTextColor(const QColor& theColor)
586 {
587   if (mySelector) {
588     Quantity_Color aColor(theColor.redF(), theColor.greenF(), theColor.blueF(), Quantity_TOC_RGB);
589     mySelector->viewer()->getColorScale()->SetColor(aColor);
590   }
591 }
592
593 void SHAPERGUI_SalomeViewer::setColorScaleTitle(const QString& theText)
594 {
595   if (mySelector) {
596     mySelector->viewer()->getColorScale()->SetTitle(theText.toStdString().c_str());
597   }
598 }
599
600 void SHAPERGUI_SalomeViewer::setText(
601   const ModuleBase_IViewer::TextColor& theText, const int theSize)
602 {
603   Handle(AIS_InteractiveContext) aContext = AISContext();
604   if (aContext.IsNull())
605     return;
606   NCollection_List<Handle(AIS_TextLabel)>::Iterator aPrsIter(myText);
607   if (!theText.empty())
608   {
609     Quantity_Color aTextColor;
610     std::string aTextFont;
611
612     double anOffset = -theSize - 1; // initial offset from the toolbar of the viewer
613     ModuleBase_IViewer::TextColor::const_iterator aLine = theText.cbegin();
614     for (; aLine != theText.cend(); aLine++)
615     {
616       Quantity_Color aColor(aLine->second.at(0) / 255.,
617         aLine->second.at(1) / 255., aLine->second.at(2) / 255., Quantity_TOC_RGB);
618       if (aLine == theText.cbegin())
619       {  // the first is the font name and text color
620         aTextColor = aColor;
621         aTextFont = std::string(aLine->first.begin(), aLine->first.end());
622         continue;
623       }
624
625       Handle(AIS_TextLabel) aPrs;
626       if (!aPrsIter.More())
627       { // new presentation is added to the list forever
628         aPrs = new AIS_TextLabel;
629         aPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
630         aPrs->SetHJustification(Graphic3d_HTA_RIGHT);
631         aPrs->SetVJustification(Graphic3d_VTA_TOPFIRSTLINE);
632         aPrs->SetDisplayType(Aspect_TODT_SUBTITLE);
633         aPrs->SetTransparency(0.2);
634         static const Graphic3d_Vec2i aZOffset(0);
635         aPrs->SetTransformPersistence(new Graphic3d_TransformPers(
636           Graphic3d_TMF_2d, Aspect_TOTP_RIGHT_UPPER, aZOffset));
637       }
638       else
639       { // update the existing presentation
640         aPrs = aPrsIter.ChangeValue();
641         if (!aContext->IsDisplayed(aPrs))
642           aContext->Display(aPrs, Standard_False);
643       }
644       // common part of parameters for new and existing prs
645       aPrs->SetText(aLine->first.c_str());
646       aPrs->SetFont(aTextFont.c_str());
647       aPrs->SetHeight(theSize);
648       aPrs->SetPosition(gp_Pnt(0, anOffset, 0));
649       anOffset -= int(double(theSize) * 1.2 + 1); // to have a proportional gap between lines
650       aPrs->SetColor(aTextColor);
651       aPrs->SetColorSubTitle(aColor);
652       if (!aPrsIter.More())
653       { // for the new presentation
654         aContext->Display(aPrs, Standard_False);
655         myText.Append(aPrs);
656       }
657       else
658       { // update existing presentation
659         aContext->Redisplay(aPrs, Standard_False, Standard_False);
660         aPrsIter.Next();
661       }
662     }
663   }
664   // hide the left presentations, created previously, but unused for now
665   for (; aPrsIter.More(); aPrsIter.Next())
666     aContext->Erase(aPrsIter.ChangeValue(), Standard_False);
667 }
668
669 void SHAPERGUI_SalomeViewer::setFitter(OCCViewer_Fitter* theFitter)
670 {
671   if (mySelector)
672     mySelector->viewer()->setFitter(theFitter);
673 }
674
675 OCCViewer_Fitter* SHAPERGUI_SalomeViewer::fitter() const
676 {
677   if (mySelector)
678     return mySelector->viewer()->fitter();
679   return 0;
680 }