Salome HOME
updated copyright message
[modules/gui.git] / src / VTKViewer / VTKViewer_FramedTextActor.cxx
index 53a138eb557e94d0d9ae95ca8eacfdab63213c1f..232ccfc88c0e4e103312f1ac62a1c9126feec830 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #define TEXT_MARGIN    4
 #define OFFSET_SPACING 2
 
+//VSR: uncomment below macro to support unicode text properly in SALOME
+//     current commented out due to regressions
+//#define PAL22528_UNICODE
+
+namespace
+{
+  QString fromUtf8( const char* txt )
+  {
+#ifdef PAL22528_UNICODE
+    return QString::fromUtf8( txt );
+#else
+    return QString( txt );
+#endif
+  }
+  std::string toUtf8( const QString& txt )
+  {
+#ifdef PAL22528_UNICODE
+    return txt.toUtf8().constData();
+#else
+    return txt.toLatin1().constData();
+#endif
+  }
+}
+
 //==================================================================
-vtkStandardNewMacro(VTKViewer_FramedTextActor);
+vtkStandardNewMacro(VTKViewer_FramedTextActor)
 
 //==================================================================
 // function : VTKViewer_FramedTextActor
@@ -64,12 +88,9 @@ VTKViewer_FramedTextActor::VTKViewer_FramedTextActor()
   myTextProperty->SetItalic(0);
   myTextProperty->SetShadow(1);
   myTextProperty->SetFontFamilyToArial();
-
-  myTextMapper=vtkTextMapper::New();
-  myTextMapper->SetInput("");
-  myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
-  myTextActor=vtkActor2D::New();
-  myTextActor->SetMapper(myTextMapper);
+  
+  myTextActor=vtkTextActor::New();
+  myTextActor->SetTextProperty(myTextProperty);
 
   myBarActor->SetVisibility(1);
   myTextActor->SetVisibility(1);
@@ -99,7 +120,6 @@ VTKViewer_FramedTextActor::VTKViewer_FramedTextActor()
 VTKViewer_FramedTextActor::~VTKViewer_FramedTextActor()
 {
   myTextActor->Delete();
-  myTextMapper->Delete();
   myTextProperty->Delete();
   myBarActor->Delete();
   myBarMapper->Delete();
@@ -148,9 +168,9 @@ int VTKViewer_FramedTextActor::GetPickable()
 // function : GetSize
 // purpose  :
 //==================================================================
-void VTKViewer_FramedTextActor::GetSize(vtkRenderer* theRenderer, int theSize[2]) const
+void VTKViewer_FramedTextActor::GetSize(vtkRenderer* vport, double theSize[2]) const
 {
-  myTextMapper->GetSize(theRenderer, theSize);
+  myTextActor->GetSize(vport, theSize);
   theSize[0] = theSize[0] + 2 * GetTextMargin() + OFFSET_SPACING;
   theSize[1] = theSize[1] + 2 * GetTextMargin() + OFFSET_SPACING;
 }
@@ -164,7 +184,7 @@ void VTKViewer_FramedTextActor::SetForegroundColor(const double r,
                                                    const double b)
 {
   myTextProperty->SetColor(r, g, b);
-  myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
+  myTextActor->GetTextProperty()->ShallowCopy(myTextProperty);
   Modified();
 }
 
@@ -257,7 +277,7 @@ int VTKViewer_FramedTextActor::GetTextMargin() const
 // function : SetOffset
 // purpose  :
 //==================================================================
-void VTKViewer_FramedTextActor::SetOffset(const int theOffset[2])
+void VTKViewer_FramedTextActor::SetOffset(const double theOffset[2])
 {
   myHorizontalOffset = theOffset[0];
   myVerticalOffset = theOffset[1];
@@ -272,7 +292,7 @@ void VTKViewer_FramedTextActor::SetText(const char* theText)
 {
   // remove whitespaces from from the start and the end
   // additionally, consider a case of multi-string text
-  QString aString(theText);
+  QString aString(fromUtf8(theText));
 
   QStringList aTrimmedStringList;
   QStringList aStringList = aString.split("\n");
@@ -280,7 +300,7 @@ void VTKViewer_FramedTextActor::SetText(const char* theText)
   while(anIter.hasNext())
     aTrimmedStringList.append(anIter.next().trimmed());
 
-  myTextMapper->SetInput(aTrimmedStringList.join("\n").toLatin1().constData());
+  myTextActor->SetInput(toUtf8(aTrimmedStringList.join("\n")).c_str());
   Modified();
 }
 
@@ -290,7 +310,7 @@ void VTKViewer_FramedTextActor::SetText(const char* theText)
 //==================================================================
 char* VTKViewer_FramedTextActor::GetText()
 {
-  return myTextMapper->GetInput();
+  return myTextActor->GetInput();
 }
 
 //==================================================================
@@ -410,8 +430,8 @@ void VTKViewer_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win)
 int VTKViewer_FramedTextActor::RenderOverlay(vtkViewport *viewport)
 {
   int renderedSomething = 0;
-  myBarActor->RenderOverlay(viewport);
   renderedSomething +=myTextActor->RenderOverlay(viewport);
+  renderedSomething +=myBarActor->RenderOverlay(viewport);
   return renderedSomething;
 }
 
@@ -431,7 +451,7 @@ VTKViewer_FramedTextActor
   if(aViewPortWidth == 1 || aViewPortHeight == 1)
     return anIsRenderedSomething;
 
-  if(!myTextMapper->GetInput())
+  if(!myTextActor->GetInput())
     return anIsRenderedSomething;
 
   myBar->Initialize();
@@ -449,8 +469,8 @@ VTKViewer_FramedTextActor
   myBar->SetPolys(aPolys);
   aPolys->Delete(); 
 
-  int aTextSize[2]; 
-  myTextMapper->GetSize(theViewport, aTextSize);
+  double aTextSize[2]; 
+  myTextActor->GetSize(theViewport, aTextSize);
   int aBarWidth = aTextSize[0];
   int aBarHeight = aTextSize[1];
 
@@ -511,6 +531,7 @@ VTKViewer_FramedTextActor
                                  y / (double)aViewPortHeight);
   }
 
+
   aPoints->SetPoint(0, xMin, yMax, 0.0);
   aPoints->SetPoint(1, xMin, yMin, 0.0);
   aPoints->SetPoint(2, xMax, yMax, 0.0);
@@ -518,7 +539,6 @@ VTKViewer_FramedTextActor
 
   myTextProperty->SetVerticalJustificationToCentered();
 
-  myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
   myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
   myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);