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