mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0022785: Draw Harness - add possibility to remove a text drawn by the command vdrawtext
AIS_TextLabel - new public class to display simple text labels (based on MyTextClass private class from Draw Harness). ViewerTest::Display() - add more reliable replacement for VDisplayAISObject() with no viewer update flag. vdrawtext command redesign: - Use new AIS_TextLabel class instead of private MyTextClass. - Take object name and allow to clear labels from the Viewer. - Use parameter name + parameter value syntax instead of strict list of mandatory arguments. - Use [0; 1] range for colors and accept names. - Drop redundant argument "isMultiByte". - Support argument -noupdate to skip Viewer update. Update test cases to new syntax of vdrawtext.
This commit is contained in:
182
src/AIS/AIS_TextLabel.cxx
Normal file
182
src/AIS/AIS_TextLabel.cxx
Normal file
@@ -0,0 +1,182 @@
|
||||
// Created on: 2014-11-10
|
||||
// Copyright (c) 2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <AIS_TextLabel.hxx>
|
||||
|
||||
#include <Graphic3d_AspectText3d.hxx>
|
||||
|
||||
#include <Prs3d_Text.hxx>
|
||||
#include <Prs3d_TextAspect.hxx>
|
||||
|
||||
#include <Select3D_SensitivePoint.hxx>
|
||||
#include <SelectMgr_Selection.hxx>
|
||||
#include <SelectMgr_EntityOwner.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE (AIS_TextLabel, AIS_InteractiveObject)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(AIS_TextLabel, AIS_InteractiveObject)
|
||||
|
||||
//=======================================================================
|
||||
//function : AIS_TextLabel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
AIS_TextLabel::AIS_TextLabel()
|
||||
: myText ("?"),
|
||||
myPosition (0.0, 0.0, 0.0),
|
||||
myFont ("Courier"),
|
||||
myFontAspect (Font_FA_Regular)
|
||||
{
|
||||
myDrawer->SetTextAspect (new Prs3d_TextAspect());
|
||||
|
||||
SetDisplayMode (0);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetColor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetColor (const Quantity_Color& theColor)
|
||||
{
|
||||
hasOwnColor = Standard_True;
|
||||
myOwnColor = theColor;
|
||||
myDrawer->TextAspect()->SetColor (theColor);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetColor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetColor (const Quantity_NameOfColor theColor)
|
||||
{
|
||||
SetColor (Quantity_Color (theColor));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetText
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetText (const TCollection_ExtendedString& theText)
|
||||
{
|
||||
myText = theText;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetPosition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetPosition (const gp_Pnt& thePosition)
|
||||
{
|
||||
myPosition = thePosition;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetHJustification
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetHJustification (const Graphic3d_HorizontalTextAlignment theHJust)
|
||||
{
|
||||
myDrawer->TextAspect()->SetHorizontalJustification (theHJust);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetVJustification
|
||||
//purpose : Setup vertical justification.
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetVJustification (const Graphic3d_VerticalTextAlignment theVJust)
|
||||
{
|
||||
myDrawer->TextAspect()->SetVerticalJustification (theVJust);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetAngle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetAngle (const Standard_Real theAngle)
|
||||
{
|
||||
myDrawer->TextAspect()->Aspect()->SetTextAngle (theAngle * 180.0 / M_PI);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetZoom
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetZoomable (const Standard_Boolean theIsZoomable)
|
||||
{
|
||||
myDrawer->TextAspect()->Aspect()->SetTextZoomable (theIsZoomable);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetHeight
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetHeight (const Standard_Real theHeight)
|
||||
{
|
||||
myDrawer->TextAspect()->SetHeight (theHeight);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetAngle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetFontAspect (const Font_FontAspect theFontAspect)
|
||||
{
|
||||
myDrawer->TextAspect()->Aspect()->SetTextFontAspect (theFontAspect);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetFont
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::SetFont (Standard_CString theFont)
|
||||
{
|
||||
myFont = theFont;
|
||||
myDrawer->TextAspect()->SetFont (myFont.ToCString());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Compute
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
|
||||
const Handle(Prs3d_Presentation)& thePrs,
|
||||
const Standard_Integer theMode)
|
||||
{
|
||||
switch (theMode)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
|
||||
Prs3d_Text::Draw (thePrs, anAsp, myText, myPosition);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ComputeSelection
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AIS_TextLabel::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
|
||||
const Standard_Integer theMode)
|
||||
{
|
||||
switch (theMode)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 10);
|
||||
Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint (anEntityOwner, myPosition);
|
||||
theSelection->Add (aSensitivePoint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
94
src/AIS/AIS_TextLabel.hxx
Normal file
94
src/AIS/AIS_TextLabel.hxx
Normal file
@@ -0,0 +1,94 @@
|
||||
// Created on: 2014-11-10
|
||||
// Copyright (c) 2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _AIS_TextLabel_HeaderFile
|
||||
#define _AIS_TextLabel_HeaderFile
|
||||
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <Graphic3d_VerticalTextAlignment.hxx>
|
||||
#include <Graphic3d_HorizontalTextAlignment.hxx>
|
||||
#include <Font_FontAspect.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
|
||||
//! Presentation of the text.
|
||||
class AIS_TextLabel : public AIS_InteractiveObject
|
||||
{
|
||||
public:
|
||||
|
||||
//! Default constructor
|
||||
Standard_EXPORT AIS_TextLabel();
|
||||
|
||||
//! Setup color of entire text.
|
||||
Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
|
||||
|
||||
//! Setup color of entire text.
|
||||
Standard_EXPORT virtual void SetColor (const Quantity_NameOfColor theColor) Standard_OVERRIDE;
|
||||
|
||||
//! Setup text.
|
||||
Standard_EXPORT void SetText (const TCollection_ExtendedString& theText);
|
||||
|
||||
//! Setup position.
|
||||
Standard_EXPORT void SetPosition (const gp_Pnt& thePosition);
|
||||
|
||||
//! Setup horizontal justification.
|
||||
Standard_EXPORT void SetHJustification (const Graphic3d_HorizontalTextAlignment theHJust);
|
||||
|
||||
//! Setup vertical justification.
|
||||
Standard_EXPORT void SetVJustification (const Graphic3d_VerticalTextAlignment theVJust);
|
||||
|
||||
//! Setup angle.
|
||||
Standard_EXPORT void SetAngle (const Standard_Real theAngle);
|
||||
|
||||
//! Setup zoomable property.
|
||||
Standard_EXPORT void SetZoomable (const Standard_Boolean theIsZoomable);
|
||||
|
||||
//! Setup height.
|
||||
Standard_EXPORT void SetHeight (const Standard_Real theHeight);
|
||||
|
||||
//! Setup font aspect.
|
||||
Standard_EXPORT void SetFontAspect (const Font_FontAspect theFontAspect);
|
||||
|
||||
//! Setup font.
|
||||
Standard_EXPORT void SetFont (Standard_CString theFont);
|
||||
|
||||
private:
|
||||
|
||||
//! Compute
|
||||
Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
|
||||
const Handle(Prs3d_Presentation)& thePresentation,
|
||||
const Standard_Integer theMode) Standard_OVERRIDE;
|
||||
|
||||
//! Compute selection
|
||||
Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
|
||||
const Standard_Integer theMode) Standard_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
||||
TCollection_ExtendedString myText;
|
||||
gp_Pnt myPosition;
|
||||
TCollection_AsciiString myFont;
|
||||
Font_FontAspect myFontAspect;
|
||||
|
||||
public:
|
||||
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(AIS_TextLabel);
|
||||
|
||||
};
|
||||
|
||||
DEFINE_STANDARD_HANDLE(AIS_TextLabel, AIS_InteractiveObject)
|
||||
|
||||
#endif // _AIS_TextLabel_HeaderFile
|
@@ -23,3 +23,5 @@ AIS_RadiusDimension.hxx
|
||||
AIS_RadiusDimension.cxx
|
||||
AIS_PointCloud.hxx
|
||||
AIS_PointCloud.cxx
|
||||
AIS_TextLabel.hxx
|
||||
AIS_TextLabel.cxx
|
||||
|
Reference in New Issue
Block a user