ENH: support text shadow, italic, opacity in runTimePostProcessing

This commit is contained in:
Mark Olesen
2018-12-16 21:50:27 +01:00
parent c3507f74f2
commit 7c556ec275
5 changed files with 119 additions and 13 deletions

View File

@ -25,7 +25,15 @@ Class
Foam::functionObjects::runTimePostPro::geometryBase Foam::functionObjects::runTimePostPro::geometryBase
Description Description
Base class for surface handling Base class for surface, text handling
Dictionary controls
\table
Property | Description | Required | Default
visible | Display the object | yes |
renderMode | Shading (flat/gouraud/phong) | no | gouraud
opacity | Object opacity | no | 1.0
\endtable
SourceFiles SourceFiles
geometryBase.C geometryBase.C

View File

@ -34,6 +34,21 @@ License
#include "vtkTextActor.h" #include "vtkTextActor.h"
#include "vtkTextProperty.h" #include "vtkTextProperty.h"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
const Foam::Enum
<
Foam::functionObjects::runTimePostPro::text::halignType
>
Foam::functionObjects::runTimePostPro::text::halignTypeNames
({
{ halignType::LEFT, "left" },
{ halignType::CENTER, "center" },
{ halignType::CENTER, "centre" },
{ halignType::RIGHT, "right" },
});
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimePostPro::text::text Foam::functionObjects::runTimePostPro::text::text
@ -48,7 +63,13 @@ Foam::functionObjects::runTimePostPro::text::text
position_(), position_(),
size_(dict.get<scalar>("size")), size_(dict.get<scalar>("size")),
colour_(nullptr), colour_(nullptr),
halign_
(
halignTypeNames.lookupOrDefault("halign", dict, halignType::LEFT)
),
bold_(dict.get<bool>("bold")), bold_(dict.get<bool>("bold")),
italic_(dict.lookupOrDefault("italic", false)),
shadow_(dict.lookupOrDefault("shadow", false)),
timeStamp_(dict.lookupOrDefault("timeStamp", false)) timeStamp_(dict.lookupOrDefault("timeStamp", false))
{ {
dict.readEntry("position", position_); dict.readEntry("position", position_);
@ -86,21 +107,28 @@ void Foam::functionObjects::runTimePostPro::text::addGeometryToScene
auto actor = vtkSmartPointer<vtkTextActor>::New(); auto actor = vtkSmartPointer<vtkTextActor>::New();
// Concatenate string with timeStamp if true // Concatenate string with timeStamp if true
string textAndTime = string_; string str = string_;
if (timeStamp_) if (timeStamp_)
{ {
textAndTime = str += " " + geometryBase::parent_.mesh().time().timeName();
textAndTime + " " + geometryBase::parent_.mesh().time().timeName();
} }
actor->SetInput(textAndTime.c_str()); actor->SetInput(str.c_str());
actor->GetTextProperty()->SetFontFamilyToArial();
actor->GetTextProperty()->SetFontSize(size_); vtkTextProperty* prop = actor->GetTextProperty();
actor->GetTextProperty()->SetJustificationToLeft();
actor->GetTextProperty()->SetVerticalJustificationToBottom(); prop->SetFontFamilyToArial();
actor->GetTextProperty()->SetBold(bold_); prop->SetFontSize(size_);
prop->SetJustification(int(halign_));
prop->SetVerticalJustificationToBottom();
prop->SetBold(bold_);
prop->SetItalic(italic_);
prop->SetShadow(shadow_);
const vector colour = colour_->value(position); const vector colour = colour_->value(position);
actor->GetTextProperty()->SetColor(colour[0], colour[1], colour[2]);
prop->SetColor(colour[0], colour[1], colour[2]);
prop->SetOpacity(opacity(position));
actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport(); actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
actor->GetPositionCoordinate()->SetValue actor->GetPositionCoordinate()->SetValue
( (

View File

@ -34,7 +34,11 @@ Description
string "text to display"; string "text to display";
position (0.1 0.05); position (0.1 0.05);
size 18; size 18;
// halign left; // (left | centre | right)
bold yes; bold yes;
// Optional entry
shadow false;
visible yes; visible yes;
// Optionally override default colour // Optionally override default colour
@ -48,15 +52,24 @@ Description
Dictionary controls Dictionary controls
\table \table
Property | Description | Required | Default Property | Description | Required | Default
visible | Display the text | yes |
string | Text to display | yes | string | Text to display | yes |
position | The (x y) viewport position | yes | position | The (x y) viewport position | yes |
size | The font size in points | yes | size | The font size in points | yes |
halign | Text justification (left/centre/ right) | no | left
bold | Use bold font | yes | bold | Use bold font | yes |
italic | Use italic font | no | false
shadow | Add text shadow | no | false
colour | Override default text colour | no | colour | Override default text colour | no |
timeStamp | Append solution timeName to string | no | false timeStamp | Append solution timeName to string | no | false
\endtable \endtable
Inherited controls
\table
Property | Description | Required | Default
visible | Display the object | yes |
opacity | Object opacity | no | 1.0
\endtable
SourceFiles SourceFiles
text.C text.C
@ -88,6 +101,22 @@ class text
: :
public geometryBase public geometryBase
{ {
public:
// Public enumerations
//- Horizontal alignment type
enum halignType
{
LEFT = 0, //!< Left-justified text - default ("left")
CENTER = 1, //!< Centred text ("center", "centre")
RIGHT = 2 //!< Right-justified text ("right")
};
//- Horizontal alignment names (includes "center" and "centre")
static const Enum<halignType> halignTypeNames;
protected: protected:
// Protected Data // Protected Data
@ -104,9 +133,18 @@ protected:
//- Colour //- Colour
autoPtr<Function1<vector>> colour_; autoPtr<Function1<vector>> colour_;
//- Horizontal alignment
halignType halign_;
//- Bold flag //- Bold flag
bool bold_; bool bold_;
//- Italic flag
bool italic_;
//- Shadow flag
bool shadow_;
//- Time stamp flag //- Time stamp flag
bool timeStamp_; bool timeStamp_;

View File

@ -0,0 +1,28 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
numberOfSubdomains 8;
method simple;
coeffs
{
n (4 2 1);
}
// ************************************************************************* //

View File

@ -131,9 +131,13 @@ postPro1
text1 text1
{ {
string "ellipse kkLOmega"; string "ellipse kkLOmega";
position (0.6 0.05); position (0.5 0.15);
halign centre;
size 18; size 18;
opacity 0.4;
bold yes; bold yes;
italic yes;
shadow yes;
visible yes; visible yes;
} }
} }