From: Konstantin Leontev Date: Mon, 2 Oct 2023 21:09:40 +0000 (+0100) Subject: [bos #35155][EDF](2023-T1) Trihedron axes. Added font and color settings in Preferenc... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Ftlpr%2F8%2Fhead;p=modules%2Fgui.git [bos #35155][EDF](2023-T1) Trihedron axes. Added font and color settings in Preferencies dialog. Updated trihedrons text in OCCViewer_Viewer (text font and color, default color for arrows) and SVTK_Viewer (only text color). --- diff --git a/doc/salome/gui/images/pref_salome_3dviewer.png b/doc/salome/gui/images/pref_salome_3dviewer.png index cfdc0be7b..884c0538d 100644 Binary files a/doc/salome/gui/images/pref_salome_3dviewer.png and b/doc/salome/gui/images/pref_salome_3dviewer.png differ diff --git a/doc/salome/gui/input/setting_preferences.rst b/doc/salome/gui/input/setting_preferences.rst index 80f3e6318..90735ccef 100644 --- a/doc/salome/gui/input/setting_preferences.rst +++ b/doc/salome/gui/input/setting_preferences.rst @@ -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 diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 89fb8ec12..a0a8653a9 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -2054,6 +2054,11 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType SVTK_Viewer* vm = dynamic_cast( 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 <> 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 <> @@ -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 + void forEachOcctViewer(const LightApp_Application& app, T functor) + { + QList lst; + + app.viewManagers(OCCViewer_Viewer::Type(), lst); + QListIterator 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 + void forEachVtkViewer(const LightApp_Application& app, T functor) + { + QList lst; + + app.viewManagers(SVTK_Viewer::Type(), lst); + QListIterator itVTK(lst); + while (itVTK.hasNext()) + { + SUIT_ViewModel* vm = itVTK.next()->getViewModel(); + if (!vm || !vm->inherits("SVTK_Viewer")) + continue; + + SVTK_Viewer* vtkVM = dynamic_cast(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 ); diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 0e1c4249e..e3d3ef66a 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -119,6 +119,14 @@
+ + + + + + + + diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index bb72f990a..621dcac81 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -180,6 +180,38 @@ The changes will be applied on the next application session. PREF_TRIHEDRON_SIZE Size + + PREF_TRIHEDRON_TEXT_FONT_CUSTOM + Use Custom Text Font + + + PREF_TRIHEDRON_TEXT_COLOR_CUSTOM + Use Custom Text Color + + + PREF_TRIHEDRON_X_TEXT_FONT + X Text Font + + + PREF_TRIHEDRON_X_TEXT_COLOR + X Text Color + + + PREF_TRIHEDRON_Y_TEXT_FONT + Y Text Font + + + PREF_TRIHEDRON_Y_TEXT_COLOR + Y Text Color + + + PREF_TRIHEDRON_Z_TEXT_FONT + Z Text Font + + + PREF_TRIHEDRON_Z_TEXT_COLOR + Z Text Color + OBJECT_BROWSER Object Browser diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index 00b1bf008..89422b35f 100644 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -180,6 +180,38 @@ Les modifications seront appliquées à la prochaine session. PREF_TRIHEDRON_SIZE Taille + + PREF_TRIHEDRON_TEXT_FONT_CUSTOM + Utiliser une police de texte personnalisée + + + PREF_TRIHEDRON_TEXT_COLOR_CUSTOM + Utiliser une couleur de texte personnalisée + + + PREF_TRIHEDRON_X_TEXT_FONT + X Police du texte + + + PREF_TRIHEDRON_X_TEXT_COLOR + X Couleur du texte + + + PREF_TRIHEDRON_Y_TEXT_FONT + Y Police du texte + + + PREF_TRIHEDRON_Y_TEXT_COLOR + Y Couleur du texte + + + PREF_TRIHEDRON_Z_TEXT_FONT + Z Police du texte + + + PREF_TRIHEDRON_Z_TEXT_COLOR + Z Couleur du texte + OBJECT_BROWSER Arbre d'étude diff --git a/src/LightApp/resources/LightApp_msg_ja.ts b/src/LightApp/resources/LightApp_msg_ja.ts index 99841e9d7..7f86d7b53 100644 --- a/src/LightApp/resources/LightApp_msg_ja.ts +++ b/src/LightApp/resources/LightApp_msg_ja.ts @@ -179,6 +179,38 @@ Pythonファイルは、文字、数字、アンダースコアが含まれて PREF_TRIHEDRON_SIZE サイズ + + PREF_TRIHEDRON_TEXT_FONT_CUSTOM + カスタムテキストフォントを使用する + + + PREF_TRIHEDRON_TEXT_COLOR_CUSTOM + カスタムテキストカラーを使用する + + + PREF_TRIHEDRON_X_TEXT_FONT + X テキストフォント + + + PREF_TRIHEDRON_X_TEXT_COLOR + X テキストの色 + + + PREF_TRIHEDRON_Y_TEXT_FONT + Y テキストフォント + + + PREF_TRIHEDRON_Y_TEXT_COLOR + Y テキストの色 + + + PREF_TRIHEDRON_Z_TEXT_FONT + Z テキストフォント + + + PREF_TRIHEDRON_Z_TEXT_COLOR + Z テキストの色 + OBJECT_BROWSER オブジェクトブラウザー diff --git a/src/OCCViewer/CMakeLists.txt b/src/OCCViewer/CMakeLists.txt index 499577b5c..6497daa52 100644 --- a/src/OCCViewer/CMakeLists.txt +++ b/src/OCCViewer/CMakeLists.txt @@ -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 diff --git a/src/OCCViewer/OCCViewer.cxx b/src/OCCViewer/OCCViewer.cxx index 740501a36..6f69e2ed6 100644 --- a/src/OCCViewer/OCCViewer.cxx +++ b/src/OCCViewer/OCCViewer.cxx @@ -27,11 +27,10 @@ */ 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 index 000000000..09a94de1d --- /dev/null +++ b/src/OCCViewer/OCCViewer_TrihedronSetup.cxx @@ -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 +#include +#include +#include + +#include +#include + + +// 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 index 000000000..715e77343 --- /dev/null +++ b/src/OCCViewer/OCCViewer_TrihedronSetup.h @@ -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 diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 0c05bd6ac..b15572adf 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -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 */ diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index a19659c6f..074bb7b2c 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -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); diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index 49c2250e7..b94982e75 100644 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -25,6 +25,7 @@ #include "OCCViewer_VService.h" #include "OCCViewer_ViewWindow.h" #include "OCCViewer_ViewModel.h" +#include "OCCViewer_TrihedronSetup.h" #include #include @@ -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 */ diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index 834f061bf..6cc6d3194 100644 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -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; diff --git a/src/SVTK/CMakeLists.txt b/src/SVTK/CMakeLists.txt index 91b7dba35..96891bc3d 100644 --- a/src/SVTK/CMakeLists.txt +++ b/src/SVTK/CMakeLists.txt @@ -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 index 000000000..378edbca7 --- /dev/null +++ b/src/SVTK/SVTK_TrihedronSetup.cxx @@ -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 +#include + +// 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 index 000000000..26f975d1a --- /dev/null +++ b/src/SVTK/SVTK_TrihedronSetup.h @@ -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 diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 998464b94..9738f3464 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -36,9 +36,11 @@ #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 aViews = aViewManager->getViews(); + for (int i = 0; i < aViews.count(); i++) + { + if (TViewWindow* aView = dynamic_cast(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 aViews = aViewManager->getViews(); + for (int i = 0; i < aViews.count(); i++) + { + if (TViewWindow* aView = dynamic_cast(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( view ) ) QTimer::singleShot(500, [svw] () { svw->Repaint(); } ); #endif + + setTrihedronTextColor(); + setStaticTrihedronTextColor(); } diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index aaea265c5..1c3614a54 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -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; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 5f09897f3..ee91c2794 100644 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -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 diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 75894a057..38416ecac 100644 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -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(); diff --git a/src/VTKViewer/VTKViewer_Trihedron.cxx b/src/VTKViewer/VTKViewer_Trihedron.cxx index 9fef8e6a5..fe64b80b9 100644 --- a/src/VTKViewer/VTKViewer_Trihedron.cxx +++ b/src/VTKViewer/VTKViewer_Trihedron.cxx @@ -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); +} diff --git a/src/VTKViewer/VTKViewer_Trihedron.h b/src/VTKViewer/VTKViewer_Trihedron.h index 5fa566a04..1dfac69e5 100644 --- a/src/VTKViewer/VTKViewer_Trihedron.h +++ b/src/VTKViewer/VTKViewer_Trihedron.h @@ -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 */ diff --git a/src/ViewerTools/CMakeLists.txt b/src/ViewerTools/CMakeLists.txt index 4e836a5b3..1fc38e819 100644 --- a/src/ViewerTools/CMakeLists.txt +++ b/src/ViewerTools/CMakeLists.txt @@ -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 index 000000000..08dd0720a --- /dev/null +++ b/src/ViewerTools/ViewerTools_TrihedronSetup.cxx @@ -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 +#include + +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 index 000000000..fc76a496a --- /dev/null +++ b/src/ViewerTools/ViewerTools_TrihedronSetup.h @@ -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