]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
[bos #35155][EDF](2023-T1) Trihedron axes. Added font and color settings in Preferenc... kleontev/35155_Trihedron_axes 8/head
authorKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Mon, 2 Oct 2023 21:09:40 +0000 (22:09 +0100)
committerKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Wed, 25 Oct 2023 09:01:59 +0000 (10:01 +0100)
27 files changed:
doc/salome/gui/images/pref_salome_3dviewer.png
doc/salome/gui/input/setting_preferences.rst
src/LightApp/LightApp_Application.cxx
src/LightApp/resources/LightApp.xml
src/LightApp/resources/LightApp_msg_en.ts
src/LightApp/resources/LightApp_msg_fr.ts
src/LightApp/resources/LightApp_msg_ja.ts
src/OCCViewer/CMakeLists.txt
src/OCCViewer/OCCViewer.cxx
src/OCCViewer/OCCViewer_TrihedronSetup.cxx [new file with mode: 0644]
src/OCCViewer/OCCViewer_TrihedronSetup.h [new file with mode: 0644]
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/OCCViewer_ViewModel.h
src/OCCViewer/OCCViewer_ViewPort3d.cxx
src/OCCViewer/OCCViewer_ViewPort3d.h
src/SVTK/CMakeLists.txt
src/SVTK/SVTK_TrihedronSetup.cxx [new file with mode: 0644]
src/SVTK/SVTK_TrihedronSetup.h [new file with mode: 0644]
src/SVTK/SVTK_ViewModel.cxx
src/SVTK/SVTK_ViewModel.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h
src/VTKViewer/VTKViewer_Trihedron.cxx
src/VTKViewer/VTKViewer_Trihedron.h
src/ViewerTools/CMakeLists.txt
src/ViewerTools/ViewerTools_TrihedronSetup.cxx [new file with mode: 0644]
src/ViewerTools/ViewerTools_TrihedronSetup.h [new file with mode: 0644]

index cfdc0be7b3430bb35c0f0035578cc90c63391c59..884c0538d78aab3af3e1e391af6dd0993e6980be 100644 (file)
Binary files a/doc/salome/gui/images/pref_salome_3dviewer.png and b/doc/salome/gui/images/pref_salome_3dviewer.png differ
index 80f3e6318b16f7ab880f35e3c802e54c2a9c1130..90735ccef5421eab6b5ce19a41274ae550466a2d 100644 (file)
@@ -97,6 +97,25 @@ General Preferences
   - **Relative** - if this option is switched on, trihedron axes scale to fit the size of the scene displayed in 3D viewer.
   - **Show static trihedron** - allows to show/hide the static mini-trihedron located in the bottom-left corner of the viewer.
 
+  The settings below are for trihedron labels.
+
+  - **Use Custom Text Font** - allows to change text's font for trihedron labels individually for each axis (only for OCC 3D Viewer):
+
+    - X Text Font
+    - Y Text Font
+    - Z Text Font
+
+    Notes:
+      - Not all fonts are supported and could be automatically replaced by the similar ones.
+      - Changing the size of the font is not implemented at the moment.
+      - Works only with OCCT V7_7_0 and greater. With older versions altering the font settings does nothing.
+
+  - **Use Custom Text Color** - allows to change text's color for trihedron labels individually for each axis (only for OCC 3D Viewer and VTK 3D Viewer):
+
+    - X Text Color
+    - Y Text Color
+    - Z Text Color
+
 .. _occ_preferences:
 
 OCC 3D Viewer Preferences
index 89fb8ec1278723b21a344ea4783e00963e0672e2..a0a8653a9c023ca812a063692cdfffe811b7591a 100644 (file)
@@ -2054,6 +2054,11 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
     SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
     if( vm )
     {
+      // TODO:
+      // Methods like setTrihedronSize() and setStaticTrihedronVisible() do nothing for a created view here
+      // because such a view doesn't exist on this step.
+      // It's going to be created on viewMgr->createViewWindow() way below.
+      // As a workaround we could update a view inside SVTK_Viewer::onViewCreated() method.
       vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) );
       vm->setStereoType( resMgr->integerValue( "VTKViewer", "stereo_type", vm->stereoType() ) );
       vm->setAnaglyphFilter( resMgr->integerValue( "VTKViewer", "anaglyph_filter", vm->anaglyphFilter() ) );
@@ -2861,6 +2866,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   anIndicesList << 0                            << 1;
   pref->setItemProperty( "strings", aValuesList,   occZoomingStyleMode );
   pref->setItemProperty( "indexes", anIndicesList, occZoomingStyleMode );
+
   // ... "Trihedron" group <<start>>
   int occTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), Viewer3DGroup );
   pref->setItemProperty( "columns", 2, occTriGroup );
@@ -2871,6 +2877,26 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "max", 1000, occTS );
   // .... -> relative size of trihedron
   pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "relative_size" );
+
+  // .... -> trihedron text's font
+  const int trihedronTxtFontDef = pref->addPreference(tr("PREF_TRIHEDRON_TEXT_FONT_CUSTOM"), Viewer3DGroup, LightApp_Preferences::Auto, "3DViewer", "trihedron_text_font_custom");
+  pref->setItemProperty("columns", 1, trihedronTxtFontDef);
+
+  int trihedronFont = pref->addPreference(tr("PREF_TRIHEDRON_X_TEXT_FONT"), trihedronTxtFontDef, LightApp_Preferences::Font, "3DViewer", "trihedron_x_text_font");
+  pref->setItemProperty("features", QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic, trihedronFont);
+  trihedronFont = pref->addPreference(tr("PREF_TRIHEDRON_Y_TEXT_FONT"), trihedronTxtFontDef, LightApp_Preferences::Font, "3DViewer", "trihedron_y_text_font");
+  pref->setItemProperty("features", QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic, trihedronFont);
+  trihedronFont = pref->addPreference(tr("PREF_TRIHEDRON_Z_TEXT_FONT"), trihedronTxtFontDef, LightApp_Preferences::Font, "3DViewer", "trihedron_z_text_font");
+  pref->setItemProperty("features", QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic, trihedronFont);
+
+  // .... -> trihedron text's color
+  const int trihedronTxtColorDef = pref->addPreference(tr("PREF_TRIHEDRON_TEXT_COLOR_CUSTOM"), Viewer3DGroup, LightApp_Preferences::Auto, "3DViewer", "trihedron_text_color_custom");
+  pref->setItemProperty("columns", 3, trihedronTxtColorDef);
+
+  pref->addPreference(tr("PREF_TRIHEDRON_X_TEXT_COLOR"), trihedronTxtColorDef, LightApp_Preferences::Color, "3DViewer", "trihedron_x_text_color");
+  pref->addPreference(tr("PREF_TRIHEDRON_Y_TEXT_COLOR"), trihedronTxtColorDef, LightApp_Preferences::Color, "3DViewer", "trihedron_y_text_color");
+  pref->addPreference(tr("PREF_TRIHEDRON_Z_TEXT_COLOR"), trihedronTxtColorDef, LightApp_Preferences::Color, "3DViewer", "trihedron_z_text_color");
+
   // .... -> show static trihedron
   pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "show_static_trihedron" );
   // ... "Trihedron" group <<end>>
@@ -3544,6 +3570,65 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->retrieve();
 }
 
+// Helper funcitons to reduce code repetition
+namespace
+{
+#ifndef DISABLE_OCCVIEWER
+  /*!
+  Iterates all OCCT viewers and call a given functor with each viewer as an argument.
+  \param app - current application
+  \param functor - function to call 
+  */
+  template<typename T>
+  void forEachOcctViewer(const LightApp_Application& app, T functor)
+  {
+    QList<SUIT_ViewManager*> lst;
+
+    app.viewManagers(OCCViewer_Viewer::Type(), lst);
+    QListIterator<SUIT_ViewManager*> itOCC(lst);
+    while (itOCC.hasNext())
+    {
+      SUIT_ViewModel* vm = itOCC.next()->getViewModel();
+      if (!vm || !vm->inherits("OCCViewer_Viewer"))
+        continue;
+
+      OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+      functor(occVM);
+      occVM->getAISContext()->UpdateCurrentViewer();
+    }
+  }
+#endif
+
+#if !defined DISABLE_VTKVIEWER && !defined DISABLE_SALOMEOBJECT
+/*!
+  Iterates all Vtk viewers and call a given functor with each viewer as an argument
+  \param app - current application
+  \param functor - function to call 
+  */
+  template<typename T>
+  void forEachVtkViewer(const LightApp_Application& app, T functor)
+  {
+    QList<SUIT_ViewManager*> lst;
+
+    app.viewManagers(SVTK_Viewer::Type(), lst);
+    QListIterator<SUIT_ViewManager*> itVTK(lst);
+    while (itVTK.hasNext())
+    {
+      SUIT_ViewModel* vm = itVTK.next()->getViewModel();
+      if (!vm || !vm->inherits("SVTK_Viewer"))
+        continue;
+
+      SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>(vm);
+      if(vtkVM)
+      {
+        functor(vtkVM);
+        vtkVM->Repaint();
+      }
+    }
+  }
+#endif
+}
+
 /*!
   Changes appearance of application according to changed preferences
   \param sec - section
@@ -3606,6 +3691,40 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
 #endif
   }
 
+  if (sec == QString("3DViewer"))
+  {
+    if (param == QString("trihedron_text_font_custom") ||
+      param == QString("trihedron_x_text_font") ||
+      param == QString("trihedron_y_text_font") ||
+      param == QString("trihedron_z_text_font"))
+    {
+#ifndef DISABLE_OCCVIEWER
+      forEachOcctViewer(*this, [](OCCViewer_Viewer* occVM) {
+        occVM->setTrihedronTextFont();
+        occVM->setStaticTrihedronTextFont();
+        });
+#endif
+    }
+    else if (param == QString("trihedron_text_color_custom") ||
+      param == QString("trihedron_x_text_color") ||
+      param == QString("trihedron_y_text_color") ||
+      param == QString("trihedron_z_text_color"))
+    {
+#ifndef DISABLE_OCCVIEWER
+      forEachOcctViewer(*this, [](OCCViewer_Viewer* occVM) {
+        occVM->setTrihedronTextColor();
+        occVM->setStaticTrihedronTextColor();
+        });
+#endif
+#if !defined DISABLE_VTKVIEWER && !defined DISABLE_SALOMEOBJECT
+      forEachVtkViewer(*this, [](SVTK_Viewer* vtkVM) {
+        vtkVM->setTrihedronTextColor();
+        vtkVM->setStaticTrihedronTextColor();
+        });
+#endif
+    }
+  }
+
   if ( sec == QString( "3DViewer" ) && param == QString( "show_static_trihedron" ) )
   {
     bool isVisible = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
index 0e1c4249e764cebd02385eaca650232a47048102..e3d3ef66a228f29f16a5442f41621bfe0e2c6351 100644 (file)
   <section name="3DViewer">
     <parameter name="trihedron_size"        value="100" />
     <parameter name="relative_size"         value="true"/>
+    <parameter name="trihedron_text_font_custom"   value="false"/>
+    <parameter name="trihedron_text_color_custom"  value="false"/>
+    <parameter name="trihedron_x_text_font"         value="Sans Serif,12"/>
+    <parameter name="trihedron_x_text_color"        value="255, 0, 0"/>
+    <parameter name="trihedron_y_text_font"         value="Sans Serif,12"/>
+    <parameter name="trihedron_y_text_color"        value="0, 255, 0"/>
+    <parameter name="trihedron_z_text_font"         value="Sans Serif,12"/>
+    <parameter name="trihedron_z_text_color"        value="0, 0, 255"/>
     <parameter name="navigation_mode"       value="0" />
     <parameter name="zooming_mode"          value="1" />
     <parameter name="show_static_trihedron" value="true"/>
index bb72f990ac87dd07b8a4224c512825b2b69e1a24..621dcac81dd9a23d21b633bfafae2b5f401ebabb 100644 (file)
@@ -180,6 +180,38 @@ The changes will be applied on the next application session.</translation>
         <source>PREF_TRIHEDRON_SIZE</source>
         <translation>Size</translation>
     </message>
+    <message>
+        <source>PREF_TRIHEDRON_TEXT_FONT_CUSTOM</source>
+        <translation>Use Custom Text Font</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_TEXT_COLOR_CUSTOM</source>
+        <translation>Use Custom Text Color</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_X_TEXT_FONT</source>
+        <translation>X Text Font</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_X_TEXT_COLOR</source>
+        <translation>X Text Color</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Y_TEXT_FONT</source>
+        <translation>Y Text Font</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Y_TEXT_COLOR</source>
+        <translation>Y Text Color</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Z_TEXT_FONT</source>
+        <translation>Z Text Font</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Z_TEXT_COLOR</source>
+        <translation>Z Text Color</translation>
+    </message>
     <message>
         <source>OBJECT_BROWSER</source>
         <translation>Object Browser</translation>
index 00b1bf008870894a5279528e3edd5460ae45a0ef..89422b35f51173c1c21f055e542aefcd9b1ed095 100644 (file)
@@ -180,6 +180,38 @@ Les modifications seront appliquées à la prochaine session.</translation>
         <source>PREF_TRIHEDRON_SIZE</source>
         <translation>Taille</translation>
     </message>
+    <message>
+        <source>PREF_TRIHEDRON_TEXT_FONT_CUSTOM</source>
+        <translation>Utiliser une police de texte personnalisée</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_TEXT_COLOR_CUSTOM</source>
+        <translation>Utiliser une couleur de texte personnalisée</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_X_TEXT_FONT</source>
+        <translation>X Police du texte</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_X_TEXT_COLOR</source>
+        <translation>X Couleur du texte</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Y_TEXT_FONT</source>
+        <translation>Y Police du texte</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Y_TEXT_COLOR</source>
+        <translation>Y Couleur du texte</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Z_TEXT_FONT</source>
+        <translation>Z Police du texte</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Z_TEXT_COLOR</source>
+        <translation>Z Couleur du texte</translation>
+    </message>
     <message>
         <source>OBJECT_BROWSER</source>
         <translation>Arbre d&apos;étude</translation>
index 99841e9d747afffc505bd076b1dce9d4f4f81c00..7f86d7b53a78e15e8ed6da4c8674289092013aa1 100644 (file)
@@ -179,6 +179,38 @@ Pythonファイルは、文字、数字、アンダースコアが含まれて
       <source>PREF_TRIHEDRON_SIZE</source>
       <translation>サイズ</translation>
     </message>
+    <message>
+      <source>PREF_TRIHEDRON_TEXT_FONT_CUSTOM</source>
+      <translation>カスタムテキストフォントを使用する</translation>
+  </message>
+    <message>
+      <source>PREF_TRIHEDRON_TEXT_COLOR_CUSTOM</source>
+      <translation>カスタムテキストカラーを使用する</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_X_TEXT_FONT</source>
+        <translation>X テキストフォント</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_X_TEXT_COLOR</source>
+        <translation>X テキストの色</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Y_TEXT_FONT</source>
+        <translation>Y テキストフォント</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Y_TEXT_COLOR</source>
+        <translation>Y テキストの色</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Z_TEXT_FONT</source>
+        <translation>Z テキストフォント</translation>
+    </message>
+    <message>
+        <source>PREF_TRIHEDRON_Z_TEXT_COLOR</source>
+        <translation>Z テキストの色</translation>
+    </message>
     <message>
       <source>OBJECT_BROWSER</source>
       <translation>オブジェクトブラウザー</translation>
index 499577b5c265e583cc2a4ffac9317fc8d67f5667..6497daa527b51d7f306d897531f4d893a57d9c78 100644 (file)
@@ -82,6 +82,7 @@ SET(_moc_HEADERS
 SET(_other_HEADERS
   OCCViewer.h
   OCCViewer_ClipPlane.h
+  OCCViewer_TrihedronSetup.h
   OCCViewer_VService.h
   OCCViewer_Utilities.h
 )
@@ -180,6 +181,7 @@ SET(_other_SOURCES
   OCCViewer_FontWidget.cxx
   OCCViewer_SetRotationPointDlg.cxx
   OCCViewer_ToolTip.cxx
+  OCCViewer_TrihedronSetup.cxx
   OCCViewer_VService.cxx
   OCCViewer_ViewFrame.cxx
   OCCViewer_ViewManager.cxx
index 740501a3626a830f212c5ec72539bf0b3d02734d..6f69e2ed6d908d44b6dc3f3a53dfc193c6147348 100644 (file)
 */
 Quantity_Color OCCViewer::color( const QColor& c )
 {
-  Quantity_Color aColor;
-  if ( c.isValid() )
-    aColor = Quantity_Color( c.red()   / 255., c.green() / 255.,
-                             c.blue()  / 255., Quantity_TOC_RGB );
-  return aColor;
+  if (c.isValid())
+    return Quantity_Color(c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB);
+
+  return {};
 }
 
 /*!
diff --git a/src/OCCViewer/OCCViewer_TrihedronSetup.cxx b/src/OCCViewer/OCCViewer_TrihedronSetup.cxx
new file mode 100644 (file)
index 0000000..09a94de
--- /dev/null
@@ -0,0 +1,178 @@
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "OCCViewer_TrihedronSetup.h"
+
+#include <Basics_OCCTVersion.hxx>
+#include <AIS_Trihedron.hxx>
+#include <V3d_View.hxx>
+#include <V3d_Trihedron.hxx>
+
+#include <QFont>
+#include <QColor>
+
+
+// Common helper functions to separate algorithm from implementation
+// and reduce code repetition.
+namespace
+{
+    Font_FontAspect getFontAspect(const QFont& font)
+    {
+        if (font.bold() && font.italic())
+        {
+            return Font_FontAspect_BoldItalic;
+        }
+        else if (font.bold())
+        {
+            return Font_FontAspect_Bold;
+        }
+        else if (font.italic())
+        {
+            return Font_FontAspect_Italic;
+        }
+
+        return Font_FontAspect_Regular;
+    }
+
+    void setTextFontByAxis(const Handle(AIS_Trihedron)& trihedron, Prs3d_DatumParts axis, const QFont& font)
+    {
+#if OCC_VERSION_LARGE >= 0x07070000
+        Handle(Prs3d_Drawer) drawer = trihedron->Attributes();
+        if (!drawer->HasOwnDatumAspect())
+        {
+            return;
+        }
+
+        Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
+        daspect->TextAspect(axis)->SetFont(font.family().toStdString().c_str());
+
+        const Font_FontAspect fontAspect = getFontAspect(font);
+        daspect->TextAspect(axis)->Aspect()->SetTextFontAspect(fontAspect);
+#endif // OCC_VERSION_LARGE >= 0x0707000
+    }
+
+    void setTextColorByAxis(const Handle(AIS_Trihedron)& trihedron, Prs3d_DatumParts axis, const QColor& color)
+    {
+#if OCC_VERSION_LARGE >= 0x07070000
+        trihedron->SetTextColor(axis, OCCViewer::color(color));
+#endif // OCC_VERSION_LARGE >= 0x0707000
+    }
+
+    void setTextFontByAxis(const Handle(V3d_Trihedron)& trihedron, V3d_TypeOfAxe axis, const QFont& font)
+    {
+#if OCC_VERSION_LARGE >= 0x07070000
+        const Handle(Prs3d_TextAspect)& labelAspect = trihedron->LabelAspect(axis);
+        labelAspect->SetFont(font.family().toStdString().c_str());
+
+        const Font_FontAspect fontAspect = getFontAspect(font);
+        labelAspect->Aspect()->SetTextFontAspect(fontAspect);
+#endif // OCC_VERSION_LARGE >= 0x0707000
+    }
+
+    void setTextColorByAxis(const Handle(V3d_Trihedron)& trihedron, V3d_TypeOfAxe axis, const QColor& color)
+    {
+#if OCC_VERSION_LARGE >= 0x07070000
+        trihedron->LabelAspect(axis)->SetColor(OCCViewer::color(color));
+#endif // OCC_VERSION_LARGE >= 0x0707000
+    }
+}
+
+
+/*!
+ * Class       : OCCViewer_TrihedronSetupAIS
+ * Description : Helper class to setup trihedron settings for AIS_Trihedron (OCCT viewer)
+ */
+
+QFont OCCViewer_TrihedronSetupAIS::getDefaultTextFont() const
+{
+    return QFont(Font_NOF_ASCII_MONO);
+}
+
+void OCCViewer_TrihedronSetupAIS::setTextFontX(const QFont& font)
+{
+    setTextFontByAxis(myTrihedron, Prs3d_DP_XAxis, font);
+}
+
+void OCCViewer_TrihedronSetupAIS::setTextFontY(const QFont& font)
+{
+    setTextFontByAxis(myTrihedron, Prs3d_DP_YAxis, font);
+}
+
+void OCCViewer_TrihedronSetupAIS::setTextFontZ(const QFont& font)
+{
+    setTextFontByAxis(myTrihedron, Prs3d_DP_ZAxis, font);
+}
+
+void OCCViewer_TrihedronSetupAIS::setTextColorX(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, Prs3d_DP_XAxis, color);
+}
+
+void OCCViewer_TrihedronSetupAIS::setTextColorY(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, Prs3d_DP_YAxis, color);
+}
+
+void OCCViewer_TrihedronSetupAIS::setTextColorZ(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, Prs3d_DP_ZAxis, color);
+}
+
+/*!
+ * Class       : OCCViewer_TrihedronSetupV3d
+ * Description : Helper class to setup trihedron settings for V3d_Trihedron (OCCT viewer)
+ */
+
+QFont OCCViewer_TrihedronSetupV3d::getDefaultTextFont() const
+{
+    return QFont(Font_NOF_ASCII_MONO);
+}
+
+void OCCViewer_TrihedronSetupV3d::setTextFontX(const QFont& font)
+{
+    setTextFontByAxis(myTrihedron, V3d_TypeOfAxe::V3d_X, font);
+}
+
+void OCCViewer_TrihedronSetupV3d::setTextFontY(const QFont& font)
+{
+    setTextFontByAxis(myTrihedron, V3d_TypeOfAxe::V3d_Y, font);
+}
+
+void OCCViewer_TrihedronSetupV3d::setTextFontZ(const QFont& font)
+{
+    setTextFontByAxis(myTrihedron, V3d_TypeOfAxe::V3d_Z, font);
+}
+
+void OCCViewer_TrihedronSetupV3d::setTextColorX(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, V3d_TypeOfAxe::V3d_X, color);
+}
+
+void OCCViewer_TrihedronSetupV3d::setTextColorY(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, V3d_TypeOfAxe::V3d_Y, color);
+}
+
+void OCCViewer_TrihedronSetupV3d::setTextColorZ(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, V3d_TypeOfAxe::V3d_Z, color);
+}
diff --git a/src/OCCViewer/OCCViewer_TrihedronSetup.h b/src/OCCViewer/OCCViewer_TrihedronSetup.h
new file mode 100644 (file)
index 0000000..715e773
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef OCCVIEWER_TRIHEDRON_SETUP_H
+#define OCCVIEWER_TRIHEDRON_SETUP_H
+
+#include "OCCViewer.h"
+#include "ViewerTools_TrihedronSetup.h"
+
+class AIS_Trihedron;
+class V3d_Trihedron;
+
+/*!
+ * Class       : OCCViewer_TrihedronSetupAIS
+ * Description : Helper class to setup trihedron settings for AIS_Trihedron (OCCT viewer)
+ */
+class OCCVIEWER_EXPORT OCCViewer_TrihedronSetupAIS : public ViewerTools_TrihedronSetupBase
+{
+public:
+    OCCViewer_TrihedronSetupAIS(const Handle(AIS_Trihedron)& trihedron) : myTrihedron(trihedron) {}
+    virtual ~OCCViewer_TrihedronSetupAIS() {}
+
+protected:
+    virtual QFont getDefaultTextFont() const override;
+
+    virtual void setTextFontX(const QFont& font) override;
+    virtual void setTextFontY(const QFont& font) override;
+    virtual void setTextFontZ(const QFont& font) override;
+
+    virtual void setTextColorX(const QColor& color) override;
+    virtual void setTextColorY(const QColor& color) override;
+    virtual void setTextColorZ(const QColor& color) override;
+
+private:
+    const Handle(AIS_Trihedron)& myTrihedron;
+};
+
+/*!
+ * Class       : OCCViewer_TrihedronSetupV3d
+ * Description : Helper class to setup trihedron settings for V3d_Trihedron (OCCT viewer)
+ */
+class OCCVIEWER_EXPORT OCCViewer_TrihedronSetupV3d : public ViewerTools_TrihedronSetupBase
+{
+public:
+    OCCViewer_TrihedronSetupV3d(const Handle(V3d_Trihedron)& trihedron) : myTrihedron(trihedron) {}
+    virtual ~OCCViewer_TrihedronSetupV3d() {}
+
+protected:
+    virtual QFont getDefaultTextFont() const override;
+
+    virtual void setTextFontX(const QFont& font) override;
+    virtual void setTextFontY(const QFont& font) override;
+    virtual void setTextFontZ(const QFont& font) override;
+
+    virtual void setTextColorX(const QColor& color) override;
+    virtual void setTextColorY(const QColor& color) override;
+    virtual void setTextColorZ(const QColor& color) override;
+
+private:
+    const Handle(V3d_Trihedron)& myTrihedron;
+};
+
+#endif
\ No newline at end of file
index 0c05bd6acab4a1279db5a5e38a84a961555b83ff..b15572adf0fbdec53d9e28416c9bec7cc9a2d717 100644 (file)
@@ -26,6 +26,7 @@
 #include "OCCViewer_ViewPort3d.h"
 #include "OCCViewer_ClippingDlg.h"
 #include "OCCViewer_Utilities.h"
+#include "OCCViewer_TrihedronSetup.h"
 
 #include "SUIT_ViewWindow.h"
 #include "SUIT_ViewManager.h"
@@ -151,24 +152,9 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
   myColorScale->SetTransformPersistence( new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER) );
 #endif
 
-  /* create trihedron */
-  if ( DisplayTrihedron )
+  if (DisplayTrihedron)
   {
-    Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
-    myTrihedron = new AIS_Trihedron(anAxis);
-    myTrihedron->SetInfiniteState( Standard_True );
-
-    Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
-    //myTrihedron->SetColor( Col );
-    myTrihedron->SetArrowColor( Col.Name() );
-    myTrihedron->SetSize(100);
-    Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
-    if (drawer->HasOwnDatumAspect()) {
-      Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
-      daspect->LineAspect(Prs3d_DP_XAxis)->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
-      daspect->LineAspect(Prs3d_DP_YAxis)->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
-      daspect->LineAspect(Prs3d_DP_ZAxis)->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
-    }
+    initTrihedron();
   }
 
   /* create view cube */
@@ -1297,6 +1283,68 @@ void OCCViewer_Viewer::setColorScaleShown( const bool on )
   }
 }
 
+/*!
+  Inits trihedron if it's enabled
+*/
+void OCCViewer_Viewer::initTrihedron()
+{
+  // Basic params
+  Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
+  myTrihedron = new AIS_Trihedron(anAxis);
+  myTrihedron->SetInfiniteState(Standard_True);
+  myTrihedron->SetSize(100);
+
+  // Init default colors
+  const Quantity_Color rColor(1.0, 0.0, 0.0, Quantity_TOC_RGB);
+  const Quantity_Color gColor(0.0, 1.0, 0.0, Quantity_TOC_RGB);
+  const Quantity_Color bColor(0.0, 0.0, 1.0, Quantity_TOC_RGB);
+
+#if OCC_VERSION_LARGE >= 0x07070000
+  // Set colors for axes
+  myTrihedron->SetDatumPartColor(Prs3d_DP_XAxis, rColor);
+  myTrihedron->SetDatumPartColor(Prs3d_DP_YAxis, gColor);
+  myTrihedron->SetDatumPartColor(Prs3d_DP_ZAxis, bColor);
+
+  // Set the same colors for axes' arrows
+  myTrihedron->SetArrowColor(Prs3d_DP_XAxis, rColor);
+  myTrihedron->SetArrowColor(Prs3d_DP_YAxis, gColor);
+  myTrihedron->SetArrowColor(Prs3d_DP_ZAxis, bColor);
+#else
+  Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
+  myTrihedron->SetArrowColor( Col.Name() );
+  Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
+  if (drawer->HasOwnDatumAspect())
+  {
+    Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
+
+    daspect->LineAspect(Prs3d_DP_XAxis)->SetColor(rColor);
+    daspect->LineAspect(Prs3d_DP_YAxis)->SetColor(gColor);
+    daspect->LineAspect(Prs3d_DP_ZAxis)->SetColor(bColor);
+  }
+#endif
+
+  setTrihedronTextFont();
+  setTrihedronTextColor();
+}
+
+/*!
+  Sets font for trihedron labels from the 3D Viewer settings
+*/
+void OCCViewer_Viewer::setTrihedronTextFont()
+{
+  OCCViewer_TrihedronSetupAIS trihedronSetup(myTrihedron);
+  trihedronSetup.setTextFont();
+}
+
+/*!
+  Sets color for trihedron labels from the 3D Viewer settings
+*/
+void OCCViewer_Viewer::setTrihedronTextColor()
+{
+  OCCViewer_TrihedronSetupAIS trihedronSetup(myTrihedron);
+  trihedronSetup.setTextColor();
+}
+
 /*!
   \return true if trihedron is visible
 */
@@ -1499,6 +1547,43 @@ void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on)
   if ( aView ) aView->showStaticTrihedron( on );
 }
 
+/*!
+  Set the font for axes labels of static trihedron
+*/
+void OCCViewer_Viewer::setStaticTrihedronTextFont()
+{
+  OCCViewer_ViewPort3d* viewport = getViewPort();
+  if (!viewport)
+    return;
+
+  viewport->setStaticTrihedronTextFont();
+}
+
+
+/*!
+  Set the color for axes labels of static trihedron
+*/
+void OCCViewer_Viewer::setStaticTrihedronTextColor()
+{
+  OCCViewer_ViewPort3d* viewport = getViewPort();
+  if (!viewport)
+    return;
+
+  viewport->setStaticTrihedronTextColor();
+}
+
+/*!
+  Get the viewport for active view
+*/
+OCCViewer_ViewPort3d* OCCViewer_Viewer::getViewPort()
+{
+  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
+  if (!aView)
+    return nullptr;
+
+  return aView->getViewPort();
+}
+
 /*!
   Get new and current trihedron size corresponding to the current model size
 */
index a19659c6f44784c75f22f277ccd90545b071fe5f..074bb7b2c7bfaebfbc85e762654c2c1fa4f1d0df 100644 (file)
@@ -132,6 +132,10 @@ public:
   bool                            isColorScaleVisible() const;
   virtual void                    setColorScaleShown( const bool );
 
+  void                            initTrihedron();
+  void                            setTrihedronTextFont();
+  void                            setTrihedronTextColor();
+
   //! returns true if 3d Trihedron in viewer was created
   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
 
@@ -236,6 +240,10 @@ public:
   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
 
   void                            setStaticTrihedronDisplayed(const bool on);
+  void                            setStaticTrihedronTextFont();
+  void                            setStaticTrihedronTextColor();
+
+  OCCViewer_ViewPort3d*           getViewPort();
 
   /* Clip planes management */
   Handle(Graphic3d_ClipPlane)     createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
index 49c2250e7c91bce111e96b342ad2a9a7c1222272..b94982e756545570d26eab7794be4f7b41c4c45f 100644 (file)
@@ -25,6 +25,7 @@
 #include "OCCViewer_VService.h"
 #include "OCCViewer_ViewWindow.h"
 #include "OCCViewer_ViewModel.h"
+#include "OCCViewer_TrihedronSetup.h"
 
 #include <SUIT_ViewManager.h>
 #include <SUIT_ViewModel.h>
@@ -823,12 +824,45 @@ void OCCViewer_ViewPort3d::showStaticTrihedron( bool on )
   if ( on ) {
     aView->ZBufferTriedronSetup();
     aView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
+
+    setStaticTrihedronTextFont();
+    setStaticTrihedronTextColor();
   } else {
     aView->TriedronErase();
   }
   aView->Update();
 }
 
+/*!
+  Set the font for axes labels of static trihedron
+*/
+void OCCViewer_ViewPort3d::setStaticTrihedronTextFont()
+{
+  Handle(V3d_View) aView = activeView();
+  if (!aView)
+    return;
+    
+#if OCC_VERSION_LARGE >= 0x07070000
+  OCCViewer_TrihedronSetupV3d trihedronSetup(aView->Trihedron());
+  trihedronSetup.setTextFont();
+#endif // OCC_VERSION_LARGE >= 0x0707000
+}
+
+/*!
+  Set the color for axes labels of static trihedron
+*/
+void OCCViewer_ViewPort3d::setStaticTrihedronTextColor()
+{
+  Handle(V3d_View) aView = activeView();
+  if (!aView)
+    return;
+
+#if OCC_VERSION_LARGE >= 0x07070000
+  OCCViewer_TrihedronSetupV3d trihedronSetup(aView->Trihedron());
+  trihedronSetup.setTextColor();
+#endif // OCC_VERSION_LARGE >= 0x0707000
+}
+
 /*
  * Create default cursor with a specific shape
  */
index 834f061bf552257f2c5da41500d65335734e9dff..6cc6d3194977717db7c80a359de40e3392f510c7 100644 (file)
@@ -95,6 +95,8 @@ public:
   bool                  isAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
 
   void                  showStaticTrihedron( bool );
+  void                  setStaticTrihedronTextFont();
+  void                  setStaticTrihedronTextColor();
 
   void                  setDefaultCursor( Qt::CursorShape theCursorShape );
   QCursor*              getDefaultCursor() const;
index 91b7dba35d0d8fc135f4ee4c4c25b87a5a3779ab..96891bc3d637d835ef3435565268412b1e23f556 100644 (file)
@@ -100,6 +100,7 @@ SET(_other_HEADERS
    SVTK_SelectionEvent.h
    SVTK_Selector.h
    SVTK_SpaceMouse.h
+   SVTK_TrihedronSetup.h
    SVTK_Utils.h
    SVTK_Hash.h
 )
@@ -180,6 +181,7 @@ SET(_other_SOURCES
   SVTK_SetRotationPointDlg.cxx
   SVTK_SpaceMouse.cxx
   SVTK_Trihedron.cxx
+  SVTK_TrihedronSetup.cxx
   SVTK_UpdateRateDlg.cxx
   SVTK_Utils.cxx
   SVTK_View.cxx
diff --git a/src/SVTK/SVTK_TrihedronSetup.cxx b/src/SVTK/SVTK_TrihedronSetup.cxx
new file mode 100644 (file)
index 0000000..378edbc
--- /dev/null
@@ -0,0 +1,141 @@
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SVTK_TrihedronSetup.h"
+
+#include "VTKViewer_Trihedron.h"
+
+#include "salomevtkPVAxesWidget.h"
+#include "salomevtkPVAxesActor.h"
+
+#include "vtkProperty.h"
+
+#include <QFont>
+#include <QColor>
+
+// Common helper functions to separate algorithm from implementation
+// and reduce code repetition.
+namespace
+{
+    void setTextColorByAxis(VTKViewer_Trihedron* trihedron, VTKViewer_Trihedron::Axis axis, const QColor& color)
+    {
+        trihedron->SetTextColor(axis, color.red(), color.green(), color.blue());
+    }
+
+    void setTextColorByAxis(vtkProperty* property, const QColor& color)
+    {
+        property->SetColor(color.redF(), color.greenF(), color.blueF());
+    }
+}
+
+/*!
+ * Class       : SVTK_TrihedronSetupVTK
+ * Description : Helper class to setup trihedron settings for VTKViewer_Trihedron (Vtk viewer)
+ */
+
+QFont SVTK_TrihedronSetupVTK::getDefaultTextFont() const
+{
+    // TODO: implement this method
+    return {};
+}
+
+void SVTK_TrihedronSetupVTK::setTextFontX(const QFont& font)
+{
+    // TODO: find an easy method to change font for vtkVectorText (VTKViewer_Axis::myVectorText).
+    // Vtk defines only VTK_ARIAL, VTK_COURIER, VTK_TIMES and VTK_FONT_FILE ids to use with vtkTextProperty.
+    // Maybe vtkFreeTypeTools class could give some hints.
+    (void)font; // disable unused param warning
+}
+
+void SVTK_TrihedronSetupVTK::setTextFontY(const QFont& font)
+{
+    // TODO: implement this method
+    (void)font; // disable unused param warning
+}
+
+void SVTK_TrihedronSetupVTK::setTextFontZ(const QFont& font)
+{
+    // TODO: implement this method
+    (void)font; // disable unused param warning
+}
+
+void SVTK_TrihedronSetupVTK::setTextColorX(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, VTKViewer_Trihedron::Axis::X, color);
+}
+
+void SVTK_TrihedronSetupVTK::setTextColorY(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, VTKViewer_Trihedron::Axis::Y, color);
+}
+
+void SVTK_TrihedronSetupVTK::setTextColorZ(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron, VTKViewer_Trihedron::Axis::Z, color);
+}
+
+
+/*!
+ * Class       : SVTK_TrihedronSetupPVAxes
+ * Description : Helper class to setup static trihedron settings for salomevtk::vtkPVAxesActor (Vtk viewer)
+ */
+
+QFont SVTK_TrihedronSetupPVAxes::getDefaultTextFont() const
+{
+    // TODO: implement this method
+    return {};
+}
+
+void SVTK_TrihedronSetupPVAxes::setTextFontX(const QFont& font)
+{
+    // TODO: find an easy method to change font for vtkVectorText (VTKViewer_Axis::myVectorText).
+    // Vtk defines only VTK_ARIAL, VTK_COURIER, VTK_TIMES and VTK_FONT_FILE ids to use with vtkTextProperty.
+    // Maybe vtkFreeTypeTools class could give some hints.
+    (void)font; // disable unused param warning
+}
+
+void SVTK_TrihedronSetupPVAxes::setTextFontY(const QFont& font)
+{
+    // TODO: implement this method
+    (void)font; // disable unused param warning
+}
+
+void SVTK_TrihedronSetupPVAxes::setTextFontZ(const QFont& font)
+{
+    // TODO: implement this method
+    (void)font; // disable unused param warning
+}
+
+void SVTK_TrihedronSetupPVAxes::setTextColorX(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron->GetAxesActor()->GetXAxisLabelProperty(), color);
+}
+
+void SVTK_TrihedronSetupPVAxes::setTextColorY(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron->GetAxesActor()->GetYAxisLabelProperty(), color);
+}
+
+void SVTK_TrihedronSetupPVAxes::setTextColorZ(const QColor& color)
+{
+    setTextColorByAxis(myTrihedron->GetAxesActor()->GetZAxisLabelProperty(), color);
+}
\ No newline at end of file
diff --git a/src/SVTK/SVTK_TrihedronSetup.h b/src/SVTK/SVTK_TrihedronSetup.h
new file mode 100644 (file)
index 0000000..26f975d
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SVTK_TRIHEDRON_SETUP_H
+#define SVTK_TRIHEDRON_SETUP_H
+
+#include "SVTK.h"
+#include "ViewerTools_TrihedronSetup.h"
+
+class VTKViewer_Trihedron;
+
+namespace salomevtk
+{
+    class vtkPVAxesWidget;
+}
+
+/*!
+ * Class       : SVTK_TrihedronSetupVTK
+ * Description : Helper class to setup trihedron settings for VTKViewer_Trihedron (Vtk viewer)
+ */
+class SVTK_EXPORT SVTK_TrihedronSetupVTK : public ViewerTools_TrihedronSetupBase
+{
+public:
+    SVTK_TrihedronSetupVTK(VTKViewer_Trihedron* trihedron) : myTrihedron(trihedron) {}
+    virtual ~SVTK_TrihedronSetupVTK() {}
+
+protected:
+    virtual QFont getDefaultTextFont() const override;
+
+    virtual void setTextFontX(const QFont& font) override;
+    virtual void setTextFontY(const QFont& font) override;
+    virtual void setTextFontZ(const QFont& font) override;
+
+    virtual void setTextColorX(const QColor& color) override;
+    virtual void setTextColorY(const QColor& color) override;
+    virtual void setTextColorZ(const QColor& color) override;
+
+private:
+    VTKViewer_Trihedron* myTrihedron = nullptr;
+};
+
+/*!
+ * Class       : SVTK_TrihedronSetupPVAxes
+ * Description : Helper class to setup static trihedron settings for salomevtk::vtkPVAxesWidget (Vtk viewer)
+ */
+class SVTK_EXPORT SVTK_TrihedronSetupPVAxes : public ViewerTools_TrihedronSetupBase
+{
+public:
+    SVTK_TrihedronSetupPVAxes(salomevtk::vtkPVAxesWidget* trihedron) : myTrihedron(trihedron) {}
+    virtual ~SVTK_TrihedronSetupPVAxes() {}
+
+protected:
+    virtual QFont getDefaultTextFont() const override;
+
+    virtual void setTextFontX(const QFont& font) override;
+    virtual void setTextFontY(const QFont& font) override;
+    virtual void setTextFontZ(const QFont& font) override;
+
+    virtual void setTextColorX(const QColor& color) override;
+    virtual void setTextColorY(const QColor& color) override;
+    virtual void setTextColorZ(const QColor& color) override;
+
+private:
+    salomevtk::vtkPVAxesWidget* myTrihedron = nullptr;
+};
+
+#endif
\ No newline at end of file
index 998464b940c1e7f49f92341277d4613578c17379..9738f34640e35a79129a4feaa714c575ae83010a 100644 (file)
 #include "SVTK_Renderer.h"
 //#include "SVTK_MainWindow.h"
 #include "SVTK_Prs.h"
+#include "SVTK_TrihedronSetup.h"
 
 #include "VTKViewer_Algorithm.h"
 #include "VTKViewer_ViewModel.h"
+#include "VTKViewer_Trihedron.h"
 
 #include "SUIT_ViewModel.h"
 #include "SUIT_ViewManager.h"
@@ -227,6 +229,29 @@ void SVTK_Viewer::setTrihedronSize( const double theSize, const bool theRelative
   }
 }
 
+/*!
+  Set color of trihedron's text of the viewer
+*/
+void SVTK_Viewer::setTrihedronTextColor()
+{
+  const SUIT_ViewManager* aViewManager = getViewManager();
+  if (!aViewManager)
+  {
+    return;
+  }
+
+  const QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
+  for (int i = 0; i < aViews.count(); i++)
+  {
+    if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i)))
+    {
+      VTKViewer_Trihedron* trihedron = aView->GetRenderer()->GetTrihedron();
+      SVTK_TrihedronSetupVTK trihedronSetup(trihedron);
+      trihedronSetup.setTextColor();
+    }
+  }
+}
+
 /*!
   \return visibility status of the static trihedron
 */
@@ -253,6 +278,25 @@ void SVTK_Viewer::setStaticTrihedronVisible( const bool theIsVisible )
   }
 }
 
+/*!
+  Sets static trihedron's text color
+*/
+void SVTK_Viewer::setStaticTrihedronTextColor()
+{
+  const SUIT_ViewManager* aViewManager = getViewManager();
+  if (!aViewManager)
+    return;
+
+  QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
+  for (int i = 0; i < aViews.count(); i++)
+  {
+    if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i)))
+    {
+      aView->setStaticTrihedronTextColor();
+    }      
+  }
+}
+
 /*!
   \return projection mode
 */
@@ -875,4 +919,7 @@ void SVTK_Viewer::onViewCreated( SUIT_ViewWindow* view) {
   if ( SVTK_ViewWindow* svw = dynamic_cast<SVTK_ViewWindow*>( view ) )
     QTimer::singleShot(500, [svw] () { svw->Repaint(); } );
 #endif
+
+  setTrihedronTextColor();
+  setStaticTrihedronTextColor();
 }
index aaea265c514dc5e38dbfca681bc833774a7f5904..1c3614a54bfc1bad09f8527bb3ed14a80e88a29a 100644 (file)
@@ -110,12 +110,18 @@ public:
   //! Set size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize)
   void setTrihedronSize( const double, const bool = true );
 
+  //! Set color of trihedron's text of the viewer
+  void setTrihedronTextColor();
+
   //! Get visibility status of the static trihedron
   bool isStaticTrihedronVisible() const;
 
   //! Set visibility status of the static trihedron
   void setStaticTrihedronVisible( const bool );
 
+  //! Sets static trihedron's text color
+  void setStaticTrihedronTextColor();
+
   //! Gets projection mode
   int projectionMode() const;
 
index 5f09897f39f8bda4584ddedd2dda2de8131fb0bf..ee91c27949561728ed4b98747f9b84923cf645c7 100644 (file)
@@ -95,6 +95,7 @@
 #include "SVTK_Selector.h"
 #include "SVTK_Recorder.h"
 #include "SVTK_RecorderDlg.h"
+#include "SVTK_TrihedronSetup.h"
 
 #include "salomevtkPVAxesWidget.h"
 #include "salomevtkPVAxesActor.h"
@@ -1527,6 +1528,15 @@ void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
   myAxesWidget->SetEnabled( (int)theIsVisible );
 }
 
+/*!
+  Sets static trihedron's text color
+*/
+void SVTK_ViewWindow::setStaticTrihedronTextColor()
+{
+  SVTK_TrihedronSetupPVAxes trihedronSetup(myAxesWidget);
+  trihedronSetup.setTextColor();
+}
+
 /*!
   Performs action
   \param accelAction - action
index 75894a057f22d7f19a1491423fbb5ef7ac189b69..38416ecacf4d9376e16bf0e150d8109b6296b40a 100644 (file)
@@ -278,6 +278,9 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
   //! Set visibility status of the static trihedron
   virtual void SetStaticTrihedronVisible( const bool );
 
+  //! Sets static trihedron's text color
+  virtual void setStaticTrihedronTextColor();
+
   //! Methods to save/restore visual parameters of a view (pan, zoom, etc.)
   virtual QString getVisualParameters();
   
index 9fef8e6a5c92ce6bde8fe8819ecb66d76cc9716f..fe64b80b981b4349f062c91a99816cad096bf0b9 100644 (file)
@@ -305,6 +305,25 @@ void VTKViewer_Axis::SetColor(double theRed, double theGreen, double theBlue)
 #endif
 }
 
+/*! Sets color for myLabelActor
+ */
+void VTKViewer_Axis::SetTextColor(double theRed, double theGreen, double theBlue)
+{
+#ifdef IPAL21440
+  vtkTextProperty* aProperty = vtkTextProperty::New();
+  aProperty->SetColor(theRed, theGreen, theBlue);
+
+  myLabelActor->SetTextProperty(aProperty);
+#else
+  vtkProperty* aProperty = vtkProperty::New();
+  aProperty->SetColor(theRed, theGreen, theBlue);
+
+  myLabelActor->SetProperty(aProperty);
+#endif
+
+aProperty->Delete();
+}
+
 /*! Set size of VTKViewer_Axis
  */
 void VTKViewer_Axis::SetSize(double theSize)
@@ -543,3 +562,14 @@ bool VTKViewer_Trihedron::OwnActor(const vtkActor* theActor)
   }
   return false;
 }
+
+/*! Sets a color to a text for the given axis
+  * \param axis - axis to change a text color
+  * \param theRed - red color component
+  * \param theGreen - green color component
+  * \param theBlue - blue color component
+  */
+void VTKViewer_Trihedron::SetTextColor(Axis axis, double theRed, double theGreen, double theBlue)
+{
+  myAxis[axis]->SetTextColor(theRed, theGreen, theBlue);
+}
index 5fa566a04737038efe1ee36cf0bc9c6bf53c766a..1dfac69e5ae4584c4783157ba9a1fc829590215c 100644 (file)
@@ -143,6 +143,9 @@ protected:
 /*!This class provide support trihedron object in vtk viewer.*/
 class VTKVIEWER_EXPORT VTKViewer_Trihedron : public vtkObject
 {
+public:
+  enum Axis { X = 0, Y, Z };
+
 protected:
   /*!Initialize fields by default values.*/
   VTKViewer_Trihedron();
@@ -205,6 +208,14 @@ public:
    */
   virtual bool        OwnActor(const vtkActor* theActor);
 
+  /*! Sets a color to a text for the given axis
+   * \param axis - axis to change a text color
+   * \param theRed - red color component
+   * \param theGreen - green color component
+   * \param theBlue - blue color component
+   */
+  virtual void        SetTextColor(Axis axis, double theRed, double theGreen, double theBlue);
+
 protected:
   /*! Actor collection*/
   vtkActorCollection* myPresent;
@@ -258,6 +269,13 @@ public:
    * \param theBlue - blue component of the color
    */
   virtual void SetColor(double theRed, double theGreen, double theBlue);
+
+  /*! Sets color for myLabelActor
+   * \param theRed - red component of the color
+   * \param theGreen - green component of the color
+   * \param theBlue - blue component of the color
+   */
+  virtual void SetTextColor(double theRed, double theGreen, double theBlue);
   
   /*! Set size of VTKViewer_Axis
    */
index 4e836a5b3e578a705b894af2849a4bc1741a219c..1fc38e819810e205793386aedab2f59db90dce6a 100644 (file)
@@ -25,13 +25,14 @@ INCLUDE(UseQtExt)
 INCLUDE_DIRECTORIES(
   ${QT_INCLUDES}
   ${PROJECT_SOURCE_DIR}/src/Qtx
+  ${PROJECT_SOURCE_DIR}/src/SUIT
 )
 
 # additional preprocessor / compiler flags
 ADD_DEFINITIONS(${QT_DEFINITIONS})
 
 # libraries to link to
-SET(_link_LIBRARIES ${QT_LIBRARIES} qtx)
+SET(_link_LIBRARIES ${QT_LIBRARIES} qtx suit)
 
 # --- headers ---
 
@@ -43,7 +44,10 @@ SET(_moc_HEADERS
 )
 
 # header files / no moc processing
-SET(_other_HEADERS ViewerTools.h)
+SET(_other_HEADERS
+  ViewerTools.h
+  ViewerTools_TrihedronSetup.h
+)
 
 # header files / to install
 SET(ViewerTools_HEADERS ${_moc_HEADERS} ${_other_HEADERS})
@@ -67,6 +71,7 @@ SET(_other_SOURCES
   ViewerTools_CubeAxesDlgBase.cxx
   ViewerTools_DialogBase.cxx
   ViewerTools_FontWidgetBase.cxx
+  ViewerTools_TrihedronSetup.cxx
 )
 
 # sources / to compile
diff --git a/src/ViewerTools/ViewerTools_TrihedronSetup.cxx b/src/ViewerTools/ViewerTools_TrihedronSetup.cxx
new file mode 100644 (file)
index 0000000..08dd072
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "ViewerTools_TrihedronSetup.h"
+
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+
+#include <QFont>
+#include <QColor>
+
+namespace
+{
+    // Settings names to use with resource manager
+    const char* THE_3DSECTION_TITLE = "3DViewer";
+};
+
+/*!
+ * Class       : ViewerTools_TrihedronSetupBase
+ * Description : Helper class to setup trihedron settings for different viewers
+ */
+
+bool ViewerTools_TrihedronSetupBase::isCustomTextFontOn() const
+{
+    return SUIT_Session::session()->resourceMgr()->booleanValue(
+        THE_3DSECTION_TITLE, "trihedron_text_font_custom", false);
+}
+
+bool ViewerTools_TrihedronSetupBase::isCustomTextColorOn() const
+{
+    return SUIT_Session::session()->resourceMgr()->booleanValue(
+        THE_3DSECTION_TITLE, "trihedron_text_color_custom", false);
+}
+
+void ViewerTools_TrihedronSetupBase::setTextFont()
+{
+    if (isCustomTextFontOn())
+    {
+        const SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+
+        // Set the fonts from application settings
+        setTextFontX(resMgr->fontValue(THE_3DSECTION_TITLE, "trihedron_x_text_font"));
+        setTextFontY(resMgr->fontValue(THE_3DSECTION_TITLE, "trihedron_y_text_font"));
+        setTextFontZ(resMgr->fontValue(THE_3DSECTION_TITLE, "trihedron_z_text_font"));
+    }
+    else
+    {
+        // Set the font defined for trihedron by default
+        setTextFontX(getDefaultTextFont());
+        setTextFontY(getDefaultTextFont());
+        setTextFontZ(getDefaultTextFont());
+    }
+}
+
+void ViewerTools_TrihedronSetupBase::setTextColor()
+{
+    if (isCustomTextColorOn())
+    {
+        const SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+
+        // Set the colors from application settings
+        setTextColorX(resMgr->colorValue(THE_3DSECTION_TITLE, "trihedron_x_text_color"));
+        setTextColorY(resMgr->colorValue(THE_3DSECTION_TITLE, "trihedron_y_text_color"));
+        setTextColorZ(resMgr->colorValue(THE_3DSECTION_TITLE, "trihedron_z_text_color"));
+    }
+    else
+    {
+        // Set the colors defined for trihedron by default
+        static const QColor colorX = QColor(255, 0.0, 0.0);
+        static const QColor colorY = QColor(0.0, 255, 0.0);
+        static const QColor colorZ = QColor(0.0, 0.0, 255);
+
+        setTextColorX(colorX);
+        setTextColorY(colorY);
+        setTextColorZ(colorZ);
+    }
+}
diff --git a/src/ViewerTools/ViewerTools_TrihedronSetup.h b/src/ViewerTools/ViewerTools_TrihedronSetup.h
new file mode 100644 (file)
index 0000000..fc76a49
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef VIEWERTOOLS_TRIHEDRON_SETUP_H
+#define VIEWERTOOLS_TRIHEDRON_SETUP_H
+
+#include "ViewerTools.h"
+
+class QFont;
+class QColor;
+
+/*!
+ * Class       : ViewerTools_TrihedronSetupBase
+ * Description : Helper class to setup trihedron settings for different viewers
+ */
+class VIEWERTOOLS_EXPORT ViewerTools_TrihedronSetupBase
+{
+public:
+    virtual ~ViewerTools_TrihedronSetupBase() {}
+
+    bool isCustomTextFontOn() const;
+    bool isCustomTextColorOn() const;
+
+    virtual void setTextFont();
+    virtual void setTextColor();
+
+protected:
+    // Pure virtual methods should be implemented for each trihedron class
+    virtual QFont getDefaultTextFont() const = 0;
+
+    virtual void setTextFontX(const QFont& font) = 0;
+    virtual void setTextFontY(const QFont& font) = 0;
+    virtual void setTextFontZ(const QFont& font) = 0;
+
+    virtual void setTextColorX(const QColor& color) = 0;
+    virtual void setTextColorY(const QColor& color) = 0;
+    virtual void setTextColorZ(const QColor& color) = 0;
+};
+
+#endif
\ No newline at end of file