1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM OBJECT : interactive object for Geometry entities visualization
24 // File : GEOM_Annotation.hxx
27 #include <GEOM_Annotation.hxx>
30 #include <AIS_InteractiveContext.hxx>
31 #include <Font_FTFont.hxx>
32 #include <Graphic3d_ArrayOfPoints.hxx>
33 #include <Graphic3d_ArrayOfSegments.hxx>
34 #include <Graphic3d_Camera.hxx>
35 #include <Graphic3d_HorizontalTextAlignment.hxx>
36 #include <Graphic3d_VerticalTextAlignment.hxx>
37 #include <Graphic3d_Vec4.hxx>
38 #include <OpenGl_Context.hxx>
39 #include <OpenGl_GraphicDriver.hxx>
40 #include <OpenGl_Group.hxx>
41 #include <OpenGl_PrimitiveArray.hxx>
42 #include <OpenGl_Structure.hxx>
43 #include <OpenGl_Text.hxx>
44 #include <OpenGl_View.hxx>
45 #include <OpenGl_Workspace.hxx>
46 #include <Prs3d_PointAspect.hxx>
47 #include <Prs3d_Root.hxx>
48 #include <Prs3d_Text.hxx>
49 #include <Prs3d_IsoAspect.hxx>
50 #include <Select3D_SensitiveBox.hxx>
51 #include <SelectMgr_EntityOwner.hxx>
52 #include <V3d_Viewer.hxx>
53 #include <V3d_View.hxx>
55 #include <Basics_OCCTVersion.hxx>
57 IMPLEMENT_STANDARD_RTTIEXT( GEOM_Annotation, AIS_InteractiveObject )
59 // =======================================================================
60 // function : Constructor
62 // =======================================================================
63 GEOM_Annotation::GEOM_Annotation() : AIS_InteractiveObject()
65 SetPosition( gp_Pnt( 0.0, 0.0, 0.0 ) );
66 SetIsScreenFixed( Standard_False );
67 SetAttachPoint( gp_Pnt( 0.0, 0.0, 0.0 ) );
69 SetZLayer( Graphic3d_ZLayerId_Default );
70 SetAutoHide( Standard_True );
71 SetMutable( Standard_True );
72 SetDepthCulling( Standard_True );
74 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
75 aTextAspect->SetHeight( 20.0 );
76 aTextAspect->SetColor( Quantity_Color( 1.0, 1.0, 1.0, Quantity_TOC_RGB ) );
77 myDrawer->SetTextAspect( aTextAspect );
79 Handle(Prs3d_LineAspect) aLineAspect =
80 new Prs3d_LineAspect( Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0 );
81 myDrawer->SetLineAspect( aLineAspect );
83 Handle(Prs3d_LineAspect) aHiddenLineAspect =
84 new Prs3d_LineAspect( Quantity_NOC_WHITE, Aspect_TOL_DOT, 1.0 );
85 myDrawer->SetHiddenLineAspect( aHiddenLineAspect );
87 Handle(Prs3d_PointAspect) aPointAspect =
88 new Prs3d_PointAspect( Aspect_TOM_POINT, Quantity_NOC_WHITE, 4.0 );
89 myDrawer->SetPointAspect( aPointAspect );
92 // =======================================================================
95 // =======================================================================
96 void GEOM_Annotation::SetText( const TCollection_ExtendedString& theText )
98 if (myText != theText)
106 // =======================================================================
107 // function : SetPosition
109 // =======================================================================
110 void GEOM_Annotation::SetPosition( const gp_Pnt& thePosition )
112 SetPosition( thePosition, Standard_True );
115 // =======================================================================
116 // function : SetPosition
118 // =======================================================================
119 void GEOM_Annotation::SetPosition( const gp_Pnt& thePosition, const Standard_Boolean theUpdateSelection )
121 myPosition = thePosition;
123 if ( !myIsScreenFixed )
125 Handle(Graphic3d_TransformPers) aPersistence =
126 new Graphic3d_TransformPers( Graphic3d_TMF_ZoomRotatePers, thePosition );
128 AIS_InteractiveObject::SetTransformPersistence( aPersistence );
133 if( theUpdateSelection )
139 // =======================================================================
140 // function : SetIsScreenFixed
142 // =======================================================================
143 void GEOM_Annotation::SetIsScreenFixed( const Standard_Boolean theIsFixed )
145 myIsScreenFixed = theIsFixed;
147 Handle(Graphic3d_TransformPers) aPersistence;
149 if (!myIsScreenFixed)
151 aPersistence = new Graphic3d_TransformPers( Graphic3d_TMF_ZoomRotatePers, myPosition );
155 aPersistence = new Graphic3d_TransformPers( Graphic3d_TMF_2d, Aspect_TOTP_CENTER );
158 AIS_InteractiveObject::SetTransformPersistence( aPersistence );
160 SetZLayer( myIsScreenFixed ? Graphic3d_ZLayerId_Topmost : Graphic3d_ZLayerId_Default );
167 // =======================================================================
168 // function : Set2dPosition
170 // =======================================================================
171 void GEOM_Annotation::Set2dPosition( const Handle(V3d_View)& theView )
173 if ( myIsScreenFixed )
178 gp_Pnt aPosition2d = ConvertPosition2d( myPosition, myAttach, theView );
180 SetIsScreenFixed( Standard_True );
182 SetPosition( aPosition2d );
185 // =======================================================================
186 // function : Set3dPosition
188 // =======================================================================
189 void GEOM_Annotation::Set3dPosition( const Handle(V3d_View)& theView )
191 if ( !myIsScreenFixed )
196 gp_Pnt aPosition3d = ConvertPosition3d( myPosition, myAttach, theView );
198 SetIsScreenFixed( Standard_False );
200 SetPosition( aPosition3d );
203 // =======================================================================
204 // function : SetAttachPoint
206 // =======================================================================
207 void GEOM_Annotation::SetAttachPoint( const gp_Pnt& thePoint )
212 // =======================================================================
213 // function : SetHilightShape
214 // purpose : Sets shape (annotated shape) that will be used for highlighting.
215 // =======================================================================
216 void GEOM_Annotation::SetHilightShape( const TopoDS_Shape& theShape )
218 if ( myShape.IsEqual( theShape ) )
228 // =======================================================================
229 // function : SetColor
231 // =======================================================================
232 void GEOM_Annotation::SetColor( const Quantity_Color& theColor )
234 SetTextColor( theColor );
235 SetLineColor( theColor );
238 // =======================================================================
239 // function : SetTextColor
241 // =======================================================================
242 void GEOM_Annotation::SetTextColor( const Quantity_Color& theColor )
244 myDrawer->TextAspect()->SetColor( theColor );
249 // =======================================================================
250 // function : SetLineColor
252 // =======================================================================
253 void GEOM_Annotation::SetLineColor( const Quantity_Color& theColor )
255 myDrawer->LineAspect()->SetColor( theColor );
256 myDrawer->HiddenLineAspect()->SetColor( theColor );
257 myDrawer->PointAspect()->SetColor( theColor );
262 // =======================================================================
263 // function : SetLineWidth
265 // =======================================================================
266 void GEOM_Annotation::SetLineWidth( const Standard_Real theLineWidth )
268 if ( GetLineWidth() != theLineWidth )
270 myDrawer->LineAspect()->SetWidth( theLineWidth );
271 myDrawer->HiddenLineAspect()->SetWidth( theLineWidth );
277 // =======================================================================
278 // function : SetLineStyle
280 // =======================================================================
281 void GEOM_Annotation::SetLineStyle( const Aspect_TypeOfLine theStyle )
283 if ( GetLineStyle() != theStyle )
285 myDrawer->LineAspect()->SetTypeOfLine( theStyle );
291 // =======================================================================
292 // function : SetHiddenLineStyle
294 // =======================================================================
295 void GEOM_Annotation::SetHiddenLineStyle( const Aspect_TypeOfLine theStyle )
297 if ( GetHiddenLineStyle() != theStyle )
299 myDrawer->HiddenLineAspect()->SetTypeOfLine( theStyle );
305 // =======================================================================
306 // function : SetTextHeight
308 // =======================================================================
309 void GEOM_Annotation::SetTextHeight( const Standard_Real theHeight )
311 if ( GetTextHeight() != theHeight )
313 myDrawer->TextAspect()->SetHeight( theHeight );
319 // =======================================================================
320 // function : SetFontAspect
322 // =======================================================================
323 void GEOM_Annotation::SetFontAspect( const Font_FontAspect theFontAspect )
325 if ( GetFontAspect() != theFontAspect )
327 myDrawer->TextAspect()->Aspect()->SetTextFontAspect( theFontAspect );
333 // =======================================================================
334 // function : SetFont
336 // =======================================================================
337 void GEOM_Annotation::SetFont( const TCollection_AsciiString& theFont )
339 if ( GetFont() != theFont )
341 myDrawer->TextAspect()->Aspect()->SetFont( theFont );
347 // =======================================================================
348 // function : SetDepthCulling
350 // =======================================================================
351 void GEOM_Annotation::SetDepthCulling( const Standard_Boolean theToEnable )
353 if ( GetDepthCulling() != theToEnable )
355 myIsDepthCulling = theToEnable;
361 // =======================================================================
362 // function : SetDefaultZLayer
364 // =======================================================================
365 void GEOM_Annotation::SetDefaultZLayer()
367 SetZLayer( myIsScreenFixed ? Graphic3d_ZLayerId_Topmost : Graphic3d_ZLayerId_Default );
372 // =======================================================================
373 // function : GetDefaultPosition
375 // =======================================================================
376 gp_Pnt GEOM_Annotation::GetDefaultPosition( const Standard_Boolean theIsScreenFixed,
377 const gp_Pnt& theAttachPnt,
378 const Standard_Real theOffset,
379 const Handle(V3d_View)& theView )
381 Standard_Integer aWinWidth = 0;
382 Standard_Integer aWinHeight = 0;
383 theView->Window()->Size( aWinWidth, aWinHeight );
385 gp_Pnt aPositionProj = theView->Camera()->Project( theAttachPnt );
386 aPositionProj.SetX( (aPositionProj.X() / 2.) * aWinWidth + theOffset );
387 aPositionProj.SetY( (aPositionProj.Y() / 2.) * aWinHeight + theOffset );
388 aPositionProj.SetZ( 0.0 );
390 if ( theIsScreenFixed )
392 return aPositionProj;
395 gp_Pnt aAttachProj = theView->Camera()->Project ( theAttachPnt );
396 gp_Pnt aPosition3d = theView->Camera()->UnProject ( gp_Pnt ( aPositionProj.X() / aWinWidth * 2.,
397 aPositionProj.Y() / aWinHeight * 2.,
403 // =======================================================================
404 // function : ConvertPosition2d
406 // =======================================================================
407 gp_Pnt GEOM_Annotation::ConvertPosition2d( const gp_Pnt& thePosition,
408 const gp_Pnt& /*theAttach*/,
409 const Handle(V3d_View)& theView )
411 Standard_Integer aWinWidth = 0;
412 Standard_Integer aWinHeight = 0;
413 theView->Window()->Size( aWinWidth, aWinHeight );
415 gp_Pnt aPositionProj = theView->Camera()->Project( thePosition );
416 aPositionProj.SetX( (aPositionProj.X() / 2.) * aWinWidth );
417 aPositionProj.SetY( (aPositionProj.Y() / 2.) * aWinHeight );
418 aPositionProj.SetZ( 0.0 );
419 return aPositionProj;
422 // =======================================================================
423 // function : ConvertPosition3d
425 // =======================================================================
426 gp_Pnt GEOM_Annotation::ConvertPosition3d( const gp_Pnt& thePosition,
427 const gp_Pnt& theAttach,
428 const Handle(V3d_View)& theView )
430 Standard_Integer aWinWidth = 0;
431 Standard_Integer aWinHeight = 0;
432 theView->Window()->Size( aWinWidth, aWinHeight );
434 gp_Pnt aAttachProj = theView->Camera()->Project( theAttach );
435 gp_Pnt aPosition3d = theView->Camera()->UnProject(
436 gp_Pnt ( thePosition.X() / aWinWidth * 2., thePosition.Y() / aWinHeight * 2., aAttachProj.Z() ) );
441 // =======================================================================
442 // function : Compute
444 // =======================================================================
445 void GEOM_Annotation::Compute( const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
446 const Handle(Prs3d_Presentation)& thePresentation,
447 const Standard_Integer theMode )
449 thePresentation->Clear();
456 Handle(OpenGl_Group) aGroup = Handle(OpenGl_Group)::DownCast( Prs3d_Root::NewGroup( thePresentation ) );
462 Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
463 NCollection_String aUtfText( myText.ToExtString() );
464 OpenGl_Annotation* aAnnotationDraw =
465 new OpenGl_Annotation( this, static_cast<Standard_Integer>( anAsp->Height() ), aGroup->GlStruct()->GlDriver() );
467 aAnnotationDraw->SetDepthMode( 0 );
468 aGroup->SetGroupPrimitivesAspect( myDrawer->TextAspect()->Aspect() );
469 aGroup->SetGroupPrimitivesAspect( myDrawer->LineAspect()->Aspect() );
470 aGroup->SetGroupPrimitivesAspect( myDrawer->PointAspect()->Aspect() );
471 aGroup->AddElement( aAnnotationDraw );
473 if ( !myIsDepthCulling )
475 OpenGl_Annotation* aAnnotationDraw =
476 new OpenGl_Annotation( this, static_cast<Standard_Integer>( anAsp->Height() ), aGroup->GlStruct()->GlDriver() );
478 aAnnotationDraw->SetDepthMode( GL_GREATER );
479 aGroup->SetPrimitivesAspect( myDrawer->TextAspect()->Aspect() );
480 aGroup->SetPrimitivesAspect( myDrawer->HiddenLineAspect()->Aspect() );
481 aGroup->SetPrimitivesAspect( myDrawer->PointAspect()->Aspect() );
482 aGroup->AddElement( aAnnotationDraw );
485 Bnd_Box aBox = TextBoundingBox();
486 if ( myIsScreenFixed )
489 aOffset2d.SetTranslation( gp_Vec( myPosition.X(), myPosition.Y(), 0.0 ) );
490 aBox = aBox.Transformed( aOffset2d );
493 const gp_Pnt aBoxMin = aBox.CornerMin();
494 const gp_Pnt aBoxMax = aBox.CornerMax();
495 aGroup->ChangeBoundingBox() = Graphic3d_BndBox4f (
496 Graphic3d_Vec4( static_cast<Standard_ShortReal>( aBoxMin.X() ),
497 static_cast<Standard_ShortReal>( aBoxMin.Y() ),
498 static_cast<Standard_ShortReal>( aBoxMin.Z() ), 1.0F ),
499 Graphic3d_Vec4( static_cast<Standard_ShortReal>( aBoxMax.X() ),
500 static_cast<Standard_ShortReal>( aBoxMax.Y() ),
501 static_cast<Standard_ShortReal>( aBoxMax.Z() ), 1.0F ) );
504 // =======================================================================
505 // function : ComputeSelection
507 // =======================================================================
508 void GEOM_Annotation::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
509 const Standard_Integer theMode )
511 if (theMode != GlobalSelectionMode())
516 theSelection->Clear();
518 Bnd_Box aBox = TextBoundingBox();
519 if ( myIsScreenFixed )
522 aOffset2d.SetTranslation( gp_Vec( myPosition.X(), myPosition.Y(), 0.0 ) );
523 aBox = aBox.Transformed( aOffset2d );
526 const Handle(GEOM_AnnotationOwner) anEntityOwner = new GEOM_AnnotationOwner( myShape, this, 10 );
527 const Handle(GEOM_AnnotationSensEntity) aSensitive =
528 new GEOM_AnnotationSensEntity( anEntityOwner, aBox, myIsDepthCulling );
530 theSelection->Add( aSensitive );
533 // =======================================================================
534 // function : TextBoundingBox
536 // =======================================================================
537 Bnd_Box GEOM_Annotation::TextBoundingBox() const
539 Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
541 unsigned int aResolution = GetContext()->CurrentViewer()->DefaultRenderingParams().Resolution;
542 if ( aFont.Init( anAsp->Aspect()->Font().ToCString(),
543 anAsp->Aspect()->GetTextFontAspect(),
544 (unsigned int)anAsp->Height(),
547 const NCollection_String aText( (Standard_Utf16Char* )myText.ToExtString() );
548 const Font_Rect aFontRect = aFont.BoundingBox( aText, Graphic3d_HTA_CENTER, Graphic3d_VTA_CENTER );
550 aBox.Add( gp_Pnt( aFontRect.Left, aFontRect.Bottom, 0.0 ) );
551 aBox.Add( gp_Pnt( aFontRect.Right, aFontRect.Top, 0.0 ) );
558 // =======================================================================
559 // function : BeginDrag
561 // =======================================================================
562 void GEOM_Annotation::BeginDrag()
564 myStartPosition = myPosition;
567 // =======================================================================
570 // =======================================================================
571 void GEOM_Annotation::Drag( const Standard_Integer theDx,
572 const Standard_Integer theDy,
573 const Handle(V3d_View)& theView )
577 SetPosition( myStartPosition.Translated( gp_Vec( theDx, theDy, 0.0 ) ), Standard_False );
581 Standard_Integer aWidth, aHeight;
582 theView->Window()->Size( aWidth, aHeight );
583 gp_Pnt aNormalized = theView->Camera()->Project( myStartPosition );
584 gp_Pnt aNormalizedDrag =
585 aNormalized.Translated( gp_Vec( static_cast<Standard_Real>(theDx) * 2.0 / aWidth,
586 static_cast<Standard_Real>(theDy) * 2.0 / aHeight,
589 SetPosition( theView->Camera()->UnProject( aNormalizedDrag ), Standard_False );
593 // =======================================================================
594 // function : EndDrag
596 // =======================================================================
597 void GEOM_Annotation::EndDrag()
602 // =======================================================================
603 // function : UndoDrag
605 // =======================================================================
606 void GEOM_Annotation::UndoDrag()
608 SetPosition( myStartPosition, Standard_True );
611 // =======================================================================
612 // subclass : OpenGl_Annotation
613 // function : Constructor
615 // =======================================================================
616 GEOM_Annotation::OpenGl_Annotation::OpenGl_Annotation( GEOM_Annotation* theAnnotation,
617 const Standard_Integer theTextHeight,
618 const OpenGl_GraphicDriver* theDriver )
620 myAISObject( theAnnotation ),
621 myText( theAnnotation->myText.ToExtString() ),
626 // graphical resources for drawing text and underline
627 #if OCC_VERSION_LARGE >= 0x07040000
628 myTextParams = new Graphic3d_Text( theTextHeight );
629 myTextParams->SetText( myText.ToCString() );
630 myTextParams->SetHorizontalAlignment ( Graphic3d_HTA_CENTER );
631 myTextParams->SetVerticalAlignment ( Graphic3d_VTA_CENTER );
632 myTextDraw = new OpenGl_Text( myTextParams );
634 myTextParams.Height = theTextHeight;
635 myTextParams.HAlign = Graphic3d_HTA_CENTER;
636 myTextParams.VAlign = Graphic3d_VTA_CENTER;
637 myTextDraw = new OpenGl_Text( myText.ToCString(), OpenGl_Vec3(), myTextParams );
639 myTextLineDraw = new OpenGl_PrimitiveArray( theDriver );
641 // graphical resources for drawing extension line and marker
642 Handle(Graphic3d_ArrayOfSegments)
643 aExtVertexArray = new Graphic3d_ArrayOfSegments( 2 );
644 aExtVertexArray->AddVertex( 0.0, 0.0, 0.0 );
645 aExtVertexArray->AddVertex( 0.0, 0.0, 1.0 );
646 myExtLineDraw = new OpenGl_PrimitiveArray( theDriver, Graphic3d_TOPA_SEGMENTS,
647 aExtVertexArray->Indices(), aExtVertexArray->Attributes(), aExtVertexArray->Bounds() );
649 Handle(Graphic3d_ArrayOfPoints)
650 aExtMakerArray = new Graphic3d_ArrayOfPoints( 1 );
651 aExtMakerArray->AddVertex( 0.0, 0.0, 1.0 );
652 myExtMarkerDraw = new OpenGl_PrimitiveArray( theDriver, Graphic3d_TOPA_POINTS,
653 aExtMakerArray->Indices(), aExtMakerArray->Attributes(), aExtMakerArray->Bounds() );
656 // =======================================================================
657 // subclass : OpenGl_Annotation
658 // function : Destructor
660 // =======================================================================
661 GEOM_Annotation::OpenGl_Annotation::~OpenGl_Annotation()
666 // =======================================================================
667 // subclass : OpenGl_Annotation
668 // function : Release
669 // purpose : Releases GL resources with the given GL context.
670 // =======================================================================
671 void GEOM_Annotation::OpenGl_Annotation::Release( OpenGl_Context* theCtx )
675 myTextDraw->Release( theCtx );
676 myTextLineDraw->Release( theCtx );
677 myExtLineDraw->Release( theCtx );
678 myExtMarkerDraw->Release( theCtx );
681 myTextLineDraw = NULL;
682 myExtLineDraw = NULL;
683 myExtMarkerDraw = NULL;
686 // =======================================================================
687 // subclass : OpenGl_Annotation
689 // purpose : Renders the annotation graphical elements.
690 // =======================================================================
691 void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)& theWorkspace ) const
693 const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
695 // ---------------------------------------------------------------------
696 // initialize text's font and configure some properties when DPI changes
697 // ---------------------------------------------------------------------
699 const unsigned int aDPI = theWorkspace->View()->RenderingParams().Resolution;
700 if (myTextDPI != aDPI)
702 #if OCC_VERSION_LARGE <= 0x07030000
703 const OpenGl_AspectText* anAspect = theWorkspace->AspectText();
705 const OpenGl_Aspects* anAspect = theWorkspace->Aspects();
708 // getting string size will also initialize font library
709 #if OCC_VERSION_LARGE >= 0x07040000
710 myTextDraw->StringSize( aContext,
711 myText, *anAspect, myTextParams->Height(), aDPI,
712 myTextSize.x, myTextSize.a, myTextSize.d );
714 myTextDraw->StringSize( aContext,
715 myText, *anAspect, myTextParams, aDPI,
716 myTextSize.x, myTextSize.a, myTextSize.d );
720 myTextSize.y = myTextSize.a - myTextSize.d;
722 # if OCC_VERSION_LARGE >= 0x07040000
723 switch ( myTextParams->HorizontalAlignment() )
725 switch (myTextParams.HAlign)
728 case Graphic3d_HTA_LEFT: myTextUnderline.x() = 0.f; break;
729 case Graphic3d_HTA_CENTER: myTextUnderline.x() = -myTextSize.x / 2.f; break;
730 case Graphic3d_HTA_RIGHT: myTextUnderline.x() = -myTextSize.x; break;
735 # if OCC_VERSION_LARGE >= 0x07040000
736 switch ( myTextParams->VerticalAlignment() )
738 switch (myTextParams.VAlign)
741 case Graphic3d_VTA_TOPFIRSTLINE:
742 case Graphic3d_VTA_TOP: myTextUnderline.y() = -myTextSize.y; break;
743 case Graphic3d_VTA_CENTER: myTextUnderline.y() = -myTextSize.y / 2.f; break;
744 case Graphic3d_VTA_BOTTOM: myTextUnderline.y() = myTextSize.d; break;
749 Handle(Graphic3d_ArrayOfSegments)
750 aVertexArray = new Graphic3d_ArrayOfSegments( 2 );
751 aVertexArray->AddVertex( myTextUnderline.x(), myTextUnderline.y(), 0.0f );
752 aVertexArray->AddVertex( myTextUnderline.x() + myTextSize.x, myTextUnderline.y(), 0.0f );
753 myTextLineDraw->InitBuffers( aContext, Graphic3d_TOPA_SEGMENTS,
754 aVertexArray->Indices(), aVertexArray->Attributes(), aVertexArray->Bounds() );
757 // ---------------------------------------------
758 // perform view culling test by attachment point
759 // ---------------------------------------------
761 const OpenGl_Vec4 aAttach( static_cast<float>( myAISObject->myAttach.X() ),
762 static_cast<float>( myAISObject->myAttach.Y() ),
763 static_cast<float>( myAISObject->myAttach.Z() ), 1.F );
765 const Handle(Graphic3d_Camera) aCamera = theWorkspace->View()->Camera();
766 const OpenGl_Mat4& aCameraProjMat = aCamera->ProjectionMatrixF();
767 const OpenGl_Mat4& aCameraViewMat = aCamera->OrientationMatrixF();
768 const OpenGl_Vec4 aAttachView = aCameraViewMat * aAttach;
769 if (myAISObject->myIsAutoHide)
771 const OpenGl_Vec4 aAttachClip = aCameraProjMat * aAttachView;
772 if (Abs( aAttachClip.x() ) > aAttachClip.w()
773 || Abs( aAttachClip.y() ) > aAttachClip.w()
774 || Abs( aAttachClip.z() ) > aAttachClip.w())
779 const Handle(Graphic3d_PresentationAttributes) aHighlightStyle = theWorkspace->HighlightStyle();
780 if (!aHighlightStyle.IsNull() && myAISObject->myHilightMode == HighlightLabel)
782 Handle(Graphic3d_PresentationAttributes) empty;
783 theWorkspace->SetHighlightStyle(empty);
784 #if OCC_VERSION_LARGE <= 0x07030000
785 theWorkspace->ApplyAspectLine();
787 theWorkspace->ApplyAspects();
791 GLint myOldDepthMode = 0;
795 aContext->core11fwd->glGetIntegerv( GL_DEPTH_FUNC, &myOldDepthMode );
796 aContext->core11fwd->glDepthFunc( myDepthMode );
799 // -------------------------------------------------------------
800 // render text label in current persistence matrix and underline
801 // -------------------------------------------------------------
803 if ( myAISObject->myIsScreenFixed )
805 // use text position property instead of matrix setup
806 // to avoid jittering when dragging text
807 myTextDraw->SetPosition( OpenGl_Vec3( static_cast<float>( myAISObject->myPosition.X() ),
808 static_cast<float>( myAISObject->myPosition.Y() ),
809 static_cast<float>( myAISObject->myPosition.Z() ) ) );
812 myTextDraw->Render( theWorkspace );
814 // ------------------------------------------------------------
815 // render annotation text's underline
816 // ------------------------------------------------------------
818 if ( myAISObject->myIsScreenFixed )
820 // setup local transformation (in 2D persistence reference)
821 // to represent position of annotation label on screen
822 const OpenGl_Mat4& aViewMat = aContext->WorldViewState.Current();
823 OpenGl_Mat4 aPositionMat;
824 aPositionMat.SetValue( 0, 3, static_cast<float>( myAISObject->myPosition.X() ) );
825 aPositionMat.SetValue( 1, 3, static_cast<float>( myAISObject->myPosition.Y() ) );
826 aPositionMat.SetValue( 2, 3, static_cast<float>( myAISObject->myPosition.Z() ) );
827 OpenGl_Mat4 aPosViewMat = aViewMat * aPositionMat;
828 aContext->WorldViewState.Push();
829 aContext->WorldViewState.SetCurrent( aPosViewMat );
830 aContext->ApplyModelViewMatrix();
833 myTextLineDraw->Render( theWorkspace );
835 // ------------------------------------------------------------
836 // render dynamic extension line using synthetic transformation
837 // ------------------------------------------------------------
839 OpenGl_Vec4 aCenter (0.f, 0.f, 0.f, 1.f);
840 # if OCC_VERSION_LARGE >= 0x07040000
841 switch ( myTextParams->HorizontalAlignment() )
843 switch (myTextParams.HAlign)
846 case Graphic3d_HTA_LEFT: aCenter.x() = myTextSize.x / 2.f; break;
847 case Graphic3d_HTA_CENTER: aCenter.x() = 0.f; break;
848 case Graphic3d_HTA_RIGHT: aCenter.x() = -myTextSize.x / 2.f; break;
851 # if OCC_VERSION_LARGE >= 0x07040000
852 switch ( myTextParams->VerticalAlignment() )
854 switch (myTextParams.VAlign)
857 case Graphic3d_VTA_TOPFIRSTLINE:
858 case Graphic3d_VTA_TOP: aCenter.y() = -myTextSize.y / 2.f; break;
859 case Graphic3d_VTA_CENTER: aCenter.y() = 0.f; break;
860 case Graphic3d_VTA_BOTTOM: aCenter.y() = myTextSize.y / 2.f; break;
864 // compute label's center in view coordinate space
865 const OpenGl_Mat4& aViewMat = aContext->WorldViewState.Current();
866 const OpenGl_Vec4 aCenterView = aViewMat * aCenter;
868 // the value below defines whether the extension line should be hanging
869 // on the left side of the label or on the right
870 const bool isLeftHanded = aAttachView.x() < aCenterView.x();
872 // compute extension line point at the text label in view coordinate space
873 const OpenGl_Vec4 aHingeView = aViewMat * OpenGl_Vec4(
874 ( isLeftHanded ? myTextUnderline.x() : myTextUnderline.x() + myTextSize.x ), myTextUnderline.y(), 0.0f, 1.0f );
876 // prepare matrix to specify geometry of extension line in view space
877 // by multiplication of unit z coordinate vector on given matrix.
878 OpenGl_Mat4 aExtGeometryMat;
879 aExtGeometryMat.SetColumn( 2, aAttachView - aHingeView );
880 aExtGeometryMat.SetColumn( 3, aHingeView );
883 aContext->ModelWorldState.Push();
884 aContext->ModelWorldState.SetIdentity();
885 aContext->WorldViewState.Push();
886 aContext->WorldViewState.SetCurrent( aExtGeometryMat );
887 aContext->ApplyModelViewMatrix();
889 myExtLineDraw->Render( theWorkspace );
890 myExtMarkerDraw->Render( theWorkspace );
892 // ------------------------------------------------------------
893 // restore original state
894 // ------------------------------------------------------------
896 aContext->ModelWorldState.Pop();
897 aContext->WorldViewState.Pop();
899 if ( myOldDepthMode )
901 aContext->core11fwd->glDepthFunc( myOldDepthMode );
904 if ( myAISObject->myIsScreenFixed )
906 aContext->WorldViewState.Pop();
909 aContext->ApplyModelViewMatrix();
911 theWorkspace->SetHighlightStyle(aHighlightStyle);
914 // =======================================================================
915 // subclass : GEOM_AnnotationOwner
916 // function : HilightWithColor
917 // purpose : Perform highlighting of the presentation.
918 // =======================================================================
919 void GEOM_Annotation::GEOM_AnnotationOwner::HilightWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
920 const Handle(Prs3d_Drawer)& theStyle,
921 const Standard_Integer theMode )
923 if ( myPrsSh.IsNull() )
925 Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer;
926 aDrawer->Link( theStyle );
927 Handle(Prs3d_IsoAspect) aUIsoAspect = new Prs3d_IsoAspect(
928 aDrawer->UIsoAspect()->Aspect()->Color(),
929 aDrawer->UIsoAspect()->Aspect()->Type(),
930 aDrawer->UIsoAspect()->Aspect()->Width(), 0 );
932 Handle(Prs3d_IsoAspect) aVIsoAspect = new Prs3d_IsoAspect(
933 aDrawer->UIsoAspect()->Aspect()->Color(),
934 aDrawer->UIsoAspect()->Aspect()->Type(),
935 aDrawer->UIsoAspect()->Aspect()->Width(), 0 );
937 aDrawer->SetIsoOnPlane( Standard_False );
938 aDrawer->SetUIsoAspect( aUIsoAspect );
939 aDrawer->SetVIsoAspect( aVIsoAspect );
940 myPrsSh = new StdSelect_Shape( myShape, aDrawer );
943 myPrsSh->SetZLayer ( Selectable()->ZLayer() );
945 thePM->Color( Selectable(), theStyle, theMode, NULL, Graphic3d_ZLayerId_Topmost );
947 thePM->Color( myPrsSh, theStyle, theMode, Selectable(), Graphic3d_ZLayerId_Topmost );
950 // =======================================================================
951 // subclass : GEOM_AnnotationOwner
952 // function : Unhilight
953 // purpose : Removes highlighting from the type of shape.
954 // =======================================================================
955 void GEOM_Annotation::GEOM_AnnotationOwner::Unhilight ( const Handle(PrsMgr_PresentationManager)& thePM,
956 const Standard_Integer theMode )
958 SelectMgr_EntityOwner::Unhilight( thePM, theMode );
959 thePM->Unhighlight( myPrsSh );
962 // =======================================================================
963 // subclass : GEOM_AnnotationOwner
965 // purpose : Clears the presentation manager object aPM of all shapes
966 // with the given selection mode.
967 // =======================================================================
968 void GEOM_Annotation::GEOM_AnnotationOwner::Clear ( const Handle(PrsMgr_PresentationManager)& thePM,
969 const Standard_Integer theMode )
971 SelectMgr_EntityOwner::Clear( thePM, theMode );
973 if ( !myPrsSh.IsNull() ) {
974 thePM->Clear( myPrsSh, theMode );