Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
GEOM_Annotation.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // GEOM OBJECT : interactive object for Geometry entities visualization
24 // File : GEOM_Annotation.hxx
25 // Module : GEOM
26 //
27 #ifndef GEOM_Annotation_HeaderFile
28 #define GEOM_Annotation_HeaderFile
29 
30 #include <Basics_OCCTVersion.hxx>
31 
32 #include <AIS_InteractiveObject.hxx>
33 #include <Bnd_Box.hxx>
34 #include <Font_FontAspect.hxx>
35 #include <gp_Pnt.hxx>
36 #include <NCollection_Handle.hxx>
37 #include <NCollection_String.hxx>
38 #include <OpenGl_Element.hxx>
39 #include <OpenGl_TextParam.hxx>
40 #include <Prs3d_Presentation.hxx>
41 #include <Prs3d_LineAspect.hxx>
42 #include <Prs3d_TextAspect.hxx>
43 #include <PrsMgr_PresentationManager3d.hxx>
44 #include <Select3D_SensitiveBox.hxx>
45 #include <SelectMgr_EntityOwner.hxx>
46 #include <StdSelect_Shape.hxx>
47 #include <TCollection_ExtendedString.hxx>
48 
49 class OpenGl_GraphicDriver;
50 class OpenGl_PrimitiveArray;
51 class OpenGl_Text;
52 class V3d_View;
53 
59 {
60 public:
61 
63 
64 
65 
66 
67  enum HighlightMode
68  {
69  HighlightAll = 0,
70  HighlightLabel = 1
71  };
72 
73 public:
74 
76  Standard_EXPORT GEOM_Annotation();
77 
79  virtual ~GEOM_Annotation() {}
80 
83  Standard_EXPORT void SetText( const TCollection_ExtendedString& theText );
84 
86  const TCollection_ExtendedString& GetText() const { return myText; }
87 
94  Standard_EXPORT void SetPosition( const gp_Pnt& thePosition );
95 
97  const gp_Pnt& GetPosition() const { return myPosition; }
98 
103  Standard_EXPORT void SetIsScreenFixed( const Standard_Boolean theIsFixed );
104 
106  Standard_Boolean GetIsScreenFixed() const { return myIsScreenFixed; }
107 
111  Standard_EXPORT void Set2dPosition( const Handle(V3d_View)& theView );
112 
117  Standard_EXPORT void Set3dPosition( const Handle(V3d_View)& theView );
118 
122  Standard_EXPORT void SetAttachPoint( const gp_Pnt& thePoint );
123 
125  const gp_Pnt& GetAttachPoint() const { return myAttach; }
126 
128  Standard_EXPORT void SetHilightShape( const TopoDS_Shape& theShape );
129 
131  const TopoDS_Shape HilightShape() const { return myShape; }
132 
133 public:
134 
136  Standard_EXPORT virtual void SetColor( const Quantity_Color& theColor ) Standard_OVERRIDE;
137 
139  Standard_EXPORT void SetTextColor( const Quantity_Color& theColor );
140 
142  Quantity_Color GetTextColor() const { return myDrawer->TextAspect()->Aspect()->Color(); }
143 
145  Standard_EXPORT void SetLineColor( const Quantity_Color& theColor);
146 
148  Quantity_Color GetLineColor() const { return myDrawer->LineAspect()->Aspect()->Color(); }
149 
151  Standard_EXPORT void SetLineWidth( const Standard_Real theLineWidth );
152 
154  Standard_Real GetLineWidth() const { return myDrawer->LineAspect()->Aspect()->Width(); }
155 
157  Standard_EXPORT void SetLineStyle( const Aspect_TypeOfLine theStyle );
158 
160  Aspect_TypeOfLine GetLineStyle() const { return myDrawer->LineAspect()->Aspect()->Type(); }
161 
163  Standard_EXPORT void SetHiddenLineStyle( const Aspect_TypeOfLine theStyle );
164 
166  Aspect_TypeOfLine GetHiddenLineStyle() const { return myDrawer->HiddenLineAspect()->Aspect()->Type(); }
167 
169  Standard_EXPORT void SetTextHeight( const Standard_Real theHeight );
170 
172  Standard_Real GetTextHeight() const { return myDrawer->TextAspect()->Height(); }
173 
175  Standard_EXPORT void SetFontAspect( const Font_FontAspect theFontAspect );
176 
178  Font_FontAspect GetFontAspect() const { return myDrawer->TextAspect()->Aspect()->GetTextFontAspect(); }
179 
181  Standard_EXPORT void SetFont( const TCollection_AsciiString& theFont );
182 
184  TCollection_AsciiString GetFont() const { return myDrawer->TextAspect()->Aspect()->Font(); }
185 
190  void SetAutoHide( const Standard_Boolean theIsEnable ) { myIsAutoHide = theIsEnable; }
191 
193  Standard_Boolean GetAutoHide() const { return myIsAutoHide; }
194 
197  void SetHighlightMode( const HighlightMode theMode ) { myHilightMode = theMode; }
198 
200  HighlightMode GetHilightMode() const { return myHilightMode; }
201 
207  Standard_EXPORT void SetDepthCulling( const Standard_Boolean theToEnable );
208 
210  Standard_Boolean GetDepthCulling() const { return myIsDepthCulling; }
211 
212 // Helper tools:
213 public:
214 
216  Standard_EXPORT void SetDefaultZLayer();
217 
224  Standard_EXPORT static gp_Pnt GetDefaultPosition( const Standard_Boolean theIsScreenFixed,
225  const gp_Pnt& theAttachPnt,
226  const Standard_Real theOffset,
227  const Handle(V3d_View)& theView );
228 
233  Standard_EXPORT static gp_Pnt ConvertPosition2d( const gp_Pnt& thePosition,
234  const gp_Pnt& theAttach,
235  const Handle(V3d_View)& theView );
236 
241  Standard_EXPORT static gp_Pnt ConvertPosition3d( const gp_Pnt& thePosition,
242  const gp_Pnt& theAttach,
243  const Handle(V3d_View)& theView );
244 
245 // Interactive dragging:
246 public:
247 
249  Standard_EXPORT void BeginDrag();
250 
254  Standard_EXPORT void Drag( const Standard_Integer theDx,
255  const Standard_Integer theDy,
256  const Handle(V3d_View)& theView );
257 
259  Standard_EXPORT void EndDrag();
260 
262  Standard_EXPORT void UndoDrag();
263 
264 private:
265 
266  virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
267  const Handle(Prs3d_Presentation)& thePresentation,
268  const Standard_Integer theMode = 0 ) Standard_OVERRIDE;
269 
270  virtual void ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
271  const Standard_Integer theMode ) Standard_OVERRIDE;
272 
273  virtual void setLocalTransformation( const Handle(Geom_Transformation)& /*theTransformation*/ ) Standard_OVERRIDE {}
274 
275  virtual void SetTransformPersistence( const Handle(Graphic3d_TransformPers)& /*theTrsfPers*/ ) Standard_OVERRIDE {}
276 
277  Bnd_Box TextBoundingBox() const;
278 
279  void SetPosition( const gp_Pnt& thePosition, const Standard_Boolean theUpdateSelection );
280 
281 private:
282 
283  gp_Pnt myAttach;
284  gp_Pnt myPosition;
286  Standard_Boolean myIsScreenFixed;
287  Standard_Boolean myIsAutoHide;
288  Standard_Boolean myIsDepthCulling;
289  HighlightMode myHilightMode;
290  TCollection_ExtendedString myText;
291  TopoDS_Shape myShape;
292 
293 private:
294 
298  {
299  public:
300 
306  OpenGl_Annotation( GEOM_Annotation* theAnnotation,
307  const Standard_Integer theTextHeight,
308  const OpenGl_GraphicDriver* theDriver );
309 
311  virtual ~OpenGl_Annotation();
312 
314  virtual void Release( OpenGl_Context* theCtx ) Standard_OVERRIDE;
315 
317  virtual void Render( const Handle(OpenGl_Workspace)& theWorkspace ) const Standard_OVERRIDE;
318 
319  void SetDepthMode( const int theMode ) { myDepthMode = theMode; }
320 
321  private:
322 
323  struct TextSize {
324  float x; // width
325  float y; // height
326  float a; // ascent
327  float d; // descent
328  };
329 
331  NCollection_String myText;
332  OpenGl_TextParam myTextParams;
333  OpenGl_Text* myTextDraw;
334  OpenGl_PrimitiveArray* myTextLineDraw;
335  OpenGl_PrimitiveArray* myExtLineDraw;
336  OpenGl_PrimitiveArray* myExtMarkerDraw;
338  mutable float myTextLineY;
340  mutable Graphic3d_Vec2 myTextUnderline;
341  mutable unsigned int myTextDPI;
342  };
343 
344  friend class OpenGl_Annotation; // allow opengl element to get private data and invoke callback methods
345 
346 public:
347 
350  {
351  public:
352 
354  GEOM_AnnotationOwner( const TopoDS_Shape& theShape,
355  const Handle(SelectMgr_SelectableObject)& theSelectable,
356  const Standard_Integer thePriority )
357  : SelectMgr_EntityOwner( theSelectable, thePriority ),
358  myShape( theShape ) {}
359 
364  virtual void
365  HilightWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
366 #if OCC_VERSION_LARGE > 0x07010001
367  const Handle(Prs3d_Drawer)& theStyle,
368 #else
369  const Handle(Graphic3d_HighlightStyle)& theStyle,
370 #endif
371  const Standard_Integer theMode = 0 ) Standard_OVERRIDE;
372 
374  virtual void
375  Unhilight ( const Handle(PrsMgr_PresentationManager)& thePM,
376  const Standard_Integer theMode = 0 ) Standard_OVERRIDE;
377 
380  virtual void
381  Clear ( const Handle(PrsMgr_PresentationManager)& thePM,
382  const Standard_Integer theMode = 0 ) Standard_OVERRIDE;
383 
384  private:
385 
386  TopoDS_Shape myShape;
387  Handle(StdSelect_Shape) myPrsSh;
388  };
389 
393  {
394  public:
395 
398  const Bnd_Box& theBox,
399  const Standard_Boolean theIsDepthCulling )
400  : Select3D_SensitiveBox( theOwner, theBox ),
401  myIsDepthCulling( theIsDepthCulling ) {}
402 
404  virtual Standard_Boolean Matches( SelectBasics_SelectingVolumeManager& theMgr,
405  SelectBasics_PickResult& thePickResult ) Standard_OVERRIDE
406  {
407  const Standard_Boolean isMatches = Select3D_SensitiveBox::Matches( theMgr, thePickResult );
408  if ( !myIsDepthCulling )
409  {
410  thePickResult = SelectBasics_PickResult( -DBL_MAX, thePickResult.DistToGeomCenter() );
411  }
412  return isMatches;
413  }
414 
415  private:
416 
417  Standard_Boolean myIsDepthCulling;
418  };
419 };
420 
422 
423 #endif