1 // Copyright (C) 2007-2016 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 IMPLEMENT_STANDARD_RTTIEXT( GEOM_Annotation, AIS_InteractiveObject )
57 // =======================================================================
58 // function : Constructor
60 // =======================================================================
61 GEOM_Annotation::GEOM_Annotation() : AIS_InteractiveObject()
63 SetPosition( gp_Pnt( 0.0, 0.0, 0.0 ) );
64 SetIsScreenFixed( Standard_False );
65 SetAttachPoint( gp_Pnt( 0.0, 0.0, 0.0 ) );
67 SetZLayer( Graphic3d_ZLayerId_Default );
68 SetAutoHide( Standard_True );
69 #if OCC_VERSION_LARGE <= 0x07010001
70 SetHilightMode( HighlightAll );
72 SetMutable( Standard_True );
73 SetDepthCulling( Standard_True );
75 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
76 aTextAspect->SetHeight( 20.0 );
77 aTextAspect->SetColor( Quantity_Color( 1.0, 1.0, 1.0, Quantity_TOC_RGB ) );
78 myDrawer->SetTextAspect( aTextAspect );
80 Handle(Prs3d_LineAspect) aLineAspect =
81 new Prs3d_LineAspect( Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0 );
82 myDrawer->SetLineAspect( aLineAspect );
84 Handle(Prs3d_LineAspect) aHiddenLineAspect =
85 new Prs3d_LineAspect( Quantity_NOC_WHITE, Aspect_TOL_DOT, 1.0 );
86 myDrawer->SetHiddenLineAspect( aHiddenLineAspect );
88 Handle(Prs3d_PointAspect) aPointAspect =
89 new Prs3d_PointAspect( Aspect_TOM_POINT, Quantity_NOC_WHITE, 4.0 );
90 myDrawer->SetPointAspect( aPointAspect );
93 // =======================================================================
96 // =======================================================================
97 void GEOM_Annotation::SetText( const TCollection_ExtendedString& theText )
99 if (myText != theText)
107 // =======================================================================
108 // function : SetPosition
110 // =======================================================================
111 void GEOM_Annotation::SetPosition( const gp_Pnt& thePosition )
113 SetPosition( thePosition, Standard_True );
116 // =======================================================================
117 // function : SetPosition
119 // =======================================================================
120 void GEOM_Annotation::SetPosition( const gp_Pnt& thePosition, const Standard_Boolean theUpdateSelection )
122 myPosition = thePosition;
124 if ( !myIsScreenFixed )
126 Handle(Graphic3d_TransformPers) aPersistence =
127 new Graphic3d_TransformPers( Graphic3d_TMF_ZoomRotatePers, thePosition );
129 AIS_InteractiveObject::SetTransformPersistence( aPersistence );
134 if( theUpdateSelection )
140 // =======================================================================
141 // function : SetIsScreenFixed
143 // =======================================================================
144 void GEOM_Annotation::SetIsScreenFixed( const Standard_Boolean theIsFixed )
146 myIsScreenFixed = theIsFixed;
148 Handle(Graphic3d_TransformPers) aPersistence;
150 if (!myIsScreenFixed)
152 aPersistence = new Graphic3d_TransformPers( Graphic3d_TMF_ZoomRotatePers, myPosition );
156 aPersistence = new Graphic3d_TransformPers( Graphic3d_TMF_2d, Aspect_TOTP_CENTER );
159 AIS_InteractiveObject::SetTransformPersistence( aPersistence );
161 SetZLayer( myIsScreenFixed ? Graphic3d_ZLayerId_Topmost : Graphic3d_ZLayerId_Default );
168 // =======================================================================
169 // function : Set2dPosition
171 // =======================================================================
172 void GEOM_Annotation::Set2dPosition( const Handle(V3d_View)& theView )
174 if ( myIsScreenFixed )
179 gp_Pnt aPosition2d = ConvertPosition2d( myPosition, myAttach, theView );
181 SetIsScreenFixed( Standard_True );
183 SetPosition( aPosition2d );
186 // =======================================================================
187 // function : Set3dPosition
189 // =======================================================================
190 void GEOM_Annotation::Set3dPosition( const Handle(V3d_View)& theView )
192 if ( !myIsScreenFixed )
197 gp_Pnt aPosition3d = ConvertPosition3d( myPosition, myAttach, theView );
199 SetIsScreenFixed( Standard_False );
201 SetPosition( aPosition3d );
204 // =======================================================================
205 // function : SetAttachPoint
207 // =======================================================================
208 void GEOM_Annotation::SetAttachPoint( const gp_Pnt& thePoint )
213 // =======================================================================
214 // function : SetHilightShape
215 // purpose : Sets shape (annotated shape) that will be used for hilighting.
216 // =======================================================================
217 void GEOM_Annotation::SetHilightShape( const TopoDS_Shape& theShape )
219 if ( myShape.IsEqual( theShape ) )
229 // =======================================================================
230 // function : SetColor
232 // =======================================================================
233 void GEOM_Annotation::SetColor( const Quantity_Color& theColor )
235 SetTextColor( theColor );
236 SetLineColor( theColor );
239 // =======================================================================
240 // function : SetTextColor
242 // =======================================================================
243 void GEOM_Annotation::SetTextColor( const Quantity_Color& theColor )
245 myDrawer->TextAspect()->SetColor( theColor );
250 // =======================================================================
251 // function : SetLineColor
253 // =======================================================================
254 void GEOM_Annotation::SetLineColor( const Quantity_Color& theColor )
256 myDrawer->LineAspect()->SetColor( theColor );
257 myDrawer->HiddenLineAspect()->SetColor( theColor );
258 myDrawer->PointAspect()->SetColor( theColor );
263 // =======================================================================
264 // function : SetLineWidth
266 // =======================================================================
267 void GEOM_Annotation::SetLineWidth( const Standard_Real theLineWidth )
269 if ( GetLineWidth() != theLineWidth )
271 myDrawer->LineAspect()->SetWidth( theLineWidth );
272 myDrawer->HiddenLineAspect()->SetWidth( theLineWidth );
278 // =======================================================================
279 // function : SetLineStyle
281 // =======================================================================
282 void GEOM_Annotation::SetLineStyle( const Aspect_TypeOfLine theStyle )
284 if ( GetLineStyle() != theStyle )
286 myDrawer->LineAspect()->SetTypeOfLine( theStyle );
292 // =======================================================================
293 // function : SetHiddenLineStyle
295 // =======================================================================
296 void GEOM_Annotation::SetHiddenLineStyle( const Aspect_TypeOfLine theStyle )
298 if ( GetHiddenLineStyle() != theStyle )
300 myDrawer->HiddenLineAspect()->SetTypeOfLine( theStyle );
306 // =======================================================================
307 // function : SetTextHeight
309 // =======================================================================
310 void GEOM_Annotation::SetTextHeight( const Standard_Real theHeight )
312 if ( GetTextHeight() != theHeight )
314 myDrawer->TextAspect()->SetHeight( theHeight );
320 // =======================================================================
321 // function : SetFontAspect
323 // =======================================================================
324 void GEOM_Annotation::SetFontAspect( const Font_FontAspect theFontAspect )
326 if ( GetFontAspect() != theFontAspect )
328 myDrawer->TextAspect()->Aspect()->SetTextFontAspect( theFontAspect );
334 // =======================================================================
335 // function : SetFont
337 // =======================================================================
338 void GEOM_Annotation::SetFont( const TCollection_AsciiString& theFont )
340 if ( GetFont() != theFont )
342 myDrawer->TextAspect()->Aspect()->SetFont( theFont );
348 // =======================================================================
349 // function : SetDepthCulling
351 // =======================================================================
352 void GEOM_Annotation::SetDepthCulling( const Standard_Boolean theToEnable )
354 if ( GetDepthCulling() != theToEnable )
356 myIsDepthCulling = theToEnable;
362 // =======================================================================
363 // function : SetDefaultZLayer
365 // =======================================================================
366 void GEOM_Annotation::SetDefaultZLayer()
368 SetZLayer( myIsScreenFixed ? Graphic3d_ZLayerId_Topmost : Graphic3d_ZLayerId_Default );
373 // =======================================================================
374 // function : GetDefaultPosition
376 // =======================================================================
377 gp_Pnt GEOM_Annotation::GetDefaultPosition( const Standard_Boolean theIsScreenFixed,
378 const gp_Pnt& theAttachPnt,
379 const Standard_Real theOffset,
380 const Handle(V3d_View)& theView )
382 Standard_Integer aWinWidth = 0;
383 Standard_Integer aWinHeight = 0;
384 theView->Window()->Size( aWinWidth, aWinHeight );
386 gp_Pnt aPositionProj = theView->Camera()->Project( theAttachPnt );
387 aPositionProj.SetX( (aPositionProj.X() / 2.) * aWinWidth + theOffset );
388 aPositionProj.SetY( (aPositionProj.Y() / 2.) * aWinHeight + theOffset );
389 aPositionProj.SetZ( 0.0 );
391 if ( theIsScreenFixed )
393 return aPositionProj;
396 gp_Pnt aAttachProj = theView->Camera()->Project ( theAttachPnt );
397 gp_Pnt aPosition3d = theView->Camera()->UnProject ( gp_Pnt ( aPositionProj.X() / aWinWidth * 2.,
398 aPositionProj.Y() / aWinHeight * 2.,
404 // =======================================================================
405 // function : ConvertPosition2d
407 // =======================================================================
408 gp_Pnt GEOM_Annotation::ConvertPosition2d( const gp_Pnt& thePosition,
409 const gp_Pnt& /*theAttach*/,
410 const Handle(V3d_View)& theView )
412 Standard_Integer aWinWidth = 0;
413 Standard_Integer aWinHeight = 0;
414 theView->Window()->Size( aWinWidth, aWinHeight );
416 gp_Pnt aPositionProj = theView->Camera()->Project( thePosition );
417 aPositionProj.SetX( (aPositionProj.X() / 2.) * aWinWidth );
418 aPositionProj.SetY( (aPositionProj.Y() / 2.) * aWinHeight );
419 aPositionProj.SetZ( 0.0 );
420 return aPositionProj;
423 // =======================================================================
424 // function : ConvertPosition3d
426 // =======================================================================
427 gp_Pnt GEOM_Annotation::ConvertPosition3d( const gp_Pnt& thePosition,
428 const gp_Pnt& theAttach,
429 const Handle(V3d_View)& theView )
431 Standard_Integer aWinWidth = 0;
432 Standard_Integer aWinHeight = 0;
433 theView->Window()->Size( aWinWidth, aWinHeight );
435 gp_Pnt aAttachProj = theView->Camera()->Project( theAttach );
436 gp_Pnt aPosition3d = theView->Camera()->UnProject(
437 gp_Pnt ( thePosition.X() / aWinWidth * 2., thePosition.Y() / aWinHeight * 2., aAttachProj.Z() ) );
442 // =======================================================================
443 // function : Compute
445 // =======================================================================
446 void GEOM_Annotation::Compute( const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
447 const Handle(Prs3d_Presentation)& thePresentation,
448 const Standard_Integer theMode )
450 thePresentation->Clear();
457 Handle(OpenGl_Group) aGroup = Handle(OpenGl_Group)::DownCast( Prs3d_Root::NewGroup( thePresentation ) );
463 Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
464 NCollection_String aUtfText( myText.ToExtString() );
465 OpenGl_Annotation* aAnnotationDraw =
466 new OpenGl_Annotation( this, static_cast<Standard_Integer>( anAsp->Height() ), aGroup->GlStruct()->GlDriver() );
468 aAnnotationDraw->SetDepthMode( 0 );
469 aGroup->SetGroupPrimitivesAspect( myDrawer->TextAspect()->Aspect() );
470 aGroup->SetGroupPrimitivesAspect( myDrawer->LineAspect()->Aspect() );
471 aGroup->SetGroupPrimitivesAspect( myDrawer->PointAspect()->Aspect() );
472 aGroup->AddElement( aAnnotationDraw );
474 if ( !myIsDepthCulling )
476 OpenGl_Annotation* aAnnotationDraw =
477 new OpenGl_Annotation( this, static_cast<Standard_Integer>( anAsp->Height() ), aGroup->GlStruct()->GlDriver() );
479 aAnnotationDraw->SetDepthMode( GL_GREATER );
480 aGroup->SetPrimitivesAspect( myDrawer->TextAspect()->Aspect() );
481 aGroup->SetPrimitivesAspect( myDrawer->HiddenLineAspect()->Aspect() );
482 aGroup->SetPrimitivesAspect( myDrawer->PointAspect()->Aspect() );
483 aGroup->AddElement( aAnnotationDraw );
486 Bnd_Box aBox = TextBoundingBox();
487 if ( myIsScreenFixed )
490 aOffset2d.SetTranslation( gp_Vec( myPosition.X(), myPosition.Y(), 0.0 ) );
491 aBox = aBox.Transformed( aOffset2d );
494 const gp_Pnt aBoxMin = aBox.CornerMin();
495 const gp_Pnt aBoxMax = aBox.CornerMax();
496 aGroup->ChangeBoundingBox() = Graphic3d_BndBox4f (
497 Graphic3d_Vec4( static_cast<Standard_ShortReal>( aBoxMin.X() ),
498 static_cast<Standard_ShortReal>( aBoxMin.Y() ),
499 static_cast<Standard_ShortReal>( aBoxMin.Z() ), 1.0F ),
500 Graphic3d_Vec4( static_cast<Standard_ShortReal>( aBoxMax.X() ),
501 static_cast<Standard_ShortReal>( aBoxMax.Y() ),
502 static_cast<Standard_ShortReal>( aBoxMax.Z() ), 1.0F ) );
505 // =======================================================================
506 // function : ComputeSelection
508 // =======================================================================
509 void GEOM_Annotation::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
510 const Standard_Integer theMode )
512 if (theMode != GlobalSelectionMode())
517 theSelection->Clear();
519 Bnd_Box aBox = TextBoundingBox();
520 if ( myIsScreenFixed )
523 aOffset2d.SetTranslation( gp_Vec( myPosition.X(), myPosition.Y(), 0.0 ) );
524 aBox = aBox.Transformed( aOffset2d );
527 const Handle(GEOM_AnnotationOwner) anEntityOwner = new GEOM_AnnotationOwner( myShape, this, 10 );
528 const Handle(GEOM_AnnotationSensEntity) aSensitive =
529 new GEOM_AnnotationSensEntity( anEntityOwner, aBox, myIsDepthCulling );
531 theSelection->Add( aSensitive );
534 // =======================================================================
535 // function : TextBoundingBox
537 // =======================================================================
538 Bnd_Box GEOM_Annotation::TextBoundingBox() const
540 Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
542 unsigned int aResolution = GetContext()->CurrentViewer()->DefaultRenderingParams().Resolution;
543 if ( aFont.Init( anAsp->Aspect()->Font().ToCString(),
544 anAsp->Aspect()->GetTextFontAspect(),
545 (unsigned int)anAsp->Height(),
548 const NCollection_String aText( (Standard_Utf16Char* )myText.ToExtString() );
549 const Font_Rect aFontRect = aFont.BoundingBox( aText, Graphic3d_HTA_CENTER, Graphic3d_VTA_CENTER );
551 aBox.Add( gp_Pnt( aFontRect.Left, aFontRect.Bottom, 0.0 ) );
552 aBox.Add( gp_Pnt( aFontRect.Right, aFontRect.Top, 0.0 ) );
559 // =======================================================================
560 // function : BeginDrag
562 // =======================================================================
563 void GEOM_Annotation::BeginDrag()
565 myStartPosition = myPosition;
568 // =======================================================================
571 // =======================================================================
572 void GEOM_Annotation::Drag( const Standard_Integer theDx,
573 const Standard_Integer theDy,
574 const Handle(V3d_View)& theView )
578 SetPosition( myStartPosition.Translated( gp_Vec( theDx, theDy, 0.0 ) ), Standard_False );
582 Standard_Integer aWidth, aHeight;
583 theView->Window()->Size( aWidth, aHeight );
584 gp_Pnt aNormalized = theView->Camera()->Project( myStartPosition );
585 gp_Pnt aNormalizedDrag =
586 aNormalized.Translated( gp_Vec( static_cast<Standard_Real>(theDx) * 2.0 / aWidth,
587 static_cast<Standard_Real>(theDy) * 2.0 / aHeight,
590 SetPosition( theView->Camera()->UnProject( aNormalizedDrag ), Standard_False );
594 // =======================================================================
595 // function : EndDrag
597 // =======================================================================
598 void GEOM_Annotation::EndDrag()
603 // =======================================================================
604 // function : UndoDrag
606 // =======================================================================
607 void GEOM_Annotation::UndoDrag()
609 SetPosition( myStartPosition, Standard_True );
612 // =======================================================================
613 // subclass : OpenGl_Annotation
614 // function : Constructor
616 // =======================================================================
617 GEOM_Annotation::OpenGl_Annotation::OpenGl_Annotation( GEOM_Annotation* theAnnotation,
618 const Standard_Integer theTextHeight,
619 const OpenGl_GraphicDriver* theDriver )
621 myAISObject( theAnnotation ),
622 myText( theAnnotation->myText.ToExtString() ),
627 // graphical resources for drawing text and underline
628 myTextParams.Height = theTextHeight;
629 myTextParams.HAlign = Graphic3d_HTA_CENTER;
630 myTextParams.VAlign = Graphic3d_VTA_CENTER;
631 myTextDraw = new OpenGl_Text( myText.ToCString(), OpenGl_Vec3(), myTextParams );
632 myTextLineDraw = new OpenGl_PrimitiveArray( theDriver );
634 // graphical resources for drawing extension line and marker
635 Handle(Graphic3d_ArrayOfSegments)
636 aExtVertexArray = new Graphic3d_ArrayOfSegments( 2 );
637 aExtVertexArray->AddVertex( 0.0, 0.0, 0.0 );
638 aExtVertexArray->AddVertex( 0.0, 0.0, 1.0 );
639 myExtLineDraw = new OpenGl_PrimitiveArray( theDriver, Graphic3d_TOPA_SEGMENTS,
640 aExtVertexArray->Indices(), aExtVertexArray->Attributes(), aExtVertexArray->Bounds() );
642 Handle(Graphic3d_ArrayOfPoints)
643 aExtMakerArray = new Graphic3d_ArrayOfPoints( 1 );
644 aExtMakerArray->AddVertex( 0.0, 0.0, 1.0 );
645 myExtMarkerDraw = new OpenGl_PrimitiveArray( theDriver, Graphic3d_TOPA_POINTS,
646 aExtMakerArray->Indices(), aExtMakerArray->Attributes(), aExtMakerArray->Bounds() );
649 // =======================================================================
650 // subclass : OpenGl_Annotation
651 // function : Destructor
653 // =======================================================================
654 GEOM_Annotation::OpenGl_Annotation::~OpenGl_Annotation()
659 // =======================================================================
660 // subclass : OpenGl_Annotation
661 // function : Release
662 // purpose : Releases GL resources with the given GL context.
663 // =======================================================================
664 void GEOM_Annotation::OpenGl_Annotation::Release( OpenGl_Context* theCtx )
668 myTextDraw->Release( theCtx );
669 myTextLineDraw->Release( theCtx );
670 myExtLineDraw->Release( theCtx );
671 myExtMarkerDraw->Release( theCtx );
674 myTextLineDraw = NULL;
675 myExtLineDraw = NULL;
676 myExtMarkerDraw = NULL;
679 // =======================================================================
680 // subclass : OpenGl_Annotation
682 // purpose : Renders the annotation graphical elements.
683 // =======================================================================
684 void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)& theWorkspace ) const
686 const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
688 // ---------------------------------------------------------------------
689 // initialize text's font and configure some properties when DPI changes
690 // ---------------------------------------------------------------------
692 const unsigned int aDPI = theWorkspace->View()->RenderingParams().Resolution;
693 if (myTextDPI != aDPI)
695 const OpenGl_AspectText* anAspect = theWorkspace->AspectText();
697 // getting string size will also initialize font library
698 myTextDraw->StringSize( aContext,
699 myText, *anAspect, myTextParams, aDPI,
700 myTextSize.x, myTextSize.a, myTextSize.d );
703 myTextSize.y = myTextSize.a - myTextSize.d;
704 switch (myTextParams.HAlign)
706 case Graphic3d_HTA_LEFT: myTextUnderline.x() = 0.f; break;
707 case Graphic3d_HTA_CENTER: myTextUnderline.x() = -myTextSize.x / 2.f; break;
708 case Graphic3d_HTA_RIGHT: myTextUnderline.x() = -myTextSize.x; break;
712 switch (myTextParams.VAlign)
714 case Graphic3d_VTA_TOPFIRSTLINE:
715 case Graphic3d_VTA_TOP: myTextUnderline.y() = -myTextSize.y; break;
716 case Graphic3d_VTA_CENTER: myTextUnderline.y() = -myTextSize.y / 2.f; break;
717 case Graphic3d_VTA_BOTTOM: myTextUnderline.y() = myTextSize.d; break;
722 Handle(Graphic3d_ArrayOfSegments)
723 aVertexArray = new Graphic3d_ArrayOfSegments( 2 );
724 aVertexArray->AddVertex( myTextUnderline.x(), myTextUnderline.y(), 0.0f );
725 aVertexArray->AddVertex( myTextUnderline.x() + myTextSize.x, myTextUnderline.y(), 0.0f );
726 myTextLineDraw->InitBuffers( aContext, Graphic3d_TOPA_SEGMENTS,
727 aVertexArray->Indices(), aVertexArray->Attributes(), aVertexArray->Bounds() );
730 // ---------------------------------------------
731 // perform view culling test by attachment point
732 // ---------------------------------------------
734 const OpenGl_Vec4 aAttach( static_cast<float>( myAISObject->myAttach.X() ),
735 static_cast<float>( myAISObject->myAttach.Y() ),
736 static_cast<float>( myAISObject->myAttach.Z() ), 1.F );
738 const Handle(Graphic3d_Camera) aCamera = theWorkspace->View()->Camera();
739 const OpenGl_Mat4& aCameraProjMat = aCamera->ProjectionMatrixF();
740 const OpenGl_Mat4& aCameraViewMat = aCamera->OrientationMatrixF();
741 const OpenGl_Vec4 aAttachView = aCameraViewMat * aAttach;
742 if (myAISObject->myIsAutoHide)
744 const OpenGl_Vec4 aAttachClip = aCameraProjMat * aAttachView;
745 if (Abs( aAttachClip.x() ) > aAttachClip.w()
746 || Abs( aAttachClip.y() ) > aAttachClip.w()
747 || Abs( aAttachClip.z() ) > aAttachClip.w())
752 #if OCC_VERSION_LARGE > 0x07010001
753 const Handle(Graphic3d_PresentationAttributes) aHighlightStyle = theWorkspace->HighlightStyle();
754 if (!aHighlightStyle.IsNull() && myAISObject->myHilightMode == HighlightLabel)
756 Handle(Graphic3d_PresentationAttributes) empty;
757 theWorkspace->SetHighlightStyle(empty);
758 theWorkspace->ApplyAspectLine();
761 const bool toHighlight = theWorkspace->ToHighlight();
763 if (toHighlight && myAISObject->myHilightMode == HighlightLabel)
765 theWorkspace->SetHighlight( false );
766 theWorkspace->ApplyAspectLine();
770 GLint myOldDepthMode = 0;
774 aContext->core11fwd->glGetIntegerv( GL_DEPTH_FUNC, &myOldDepthMode );
775 aContext->core11fwd->glDepthFunc( myDepthMode );
778 // -------------------------------------------------------------
779 // render text label in current persistence matrix and underline
780 // -------------------------------------------------------------
782 if ( myAISObject->myIsScreenFixed )
784 // use text position property instead of matrix setup
785 // to avoid jittering when dragging text
786 myTextDraw->SetPosition( OpenGl_Vec3( static_cast<float>( myAISObject->myPosition.X() ),
787 static_cast<float>( myAISObject->myPosition.Y() ),
788 static_cast<float>( myAISObject->myPosition.Z() ) ) );
791 myTextDraw->Render( theWorkspace );
793 // ------------------------------------------------------------
794 // render annotation text's underline
795 // ------------------------------------------------------------
797 if ( myAISObject->myIsScreenFixed )
799 // setup local transformation (in 2D persistence reference)
800 // to represent position of annotation label on screen
801 const OpenGl_Mat4& aViewMat = aContext->WorldViewState.Current();
802 OpenGl_Mat4 aPositionMat;
803 aPositionMat.SetValue( 0, 3, static_cast<float>( myAISObject->myPosition.X() ) );
804 aPositionMat.SetValue( 1, 3, static_cast<float>( myAISObject->myPosition.Y() ) );
805 aPositionMat.SetValue( 2, 3, static_cast<float>( myAISObject->myPosition.Z() ) );
806 OpenGl_Mat4 aPosViewMat = aViewMat * aPositionMat;
807 aContext->WorldViewState.Push();
808 aContext->WorldViewState.SetCurrent( aPosViewMat );
809 aContext->ApplyModelViewMatrix();
812 myTextLineDraw->Render( theWorkspace );
814 // ------------------------------------------------------------
815 // render dynamic extension line using synthetic transformation
816 // ------------------------------------------------------------
818 OpenGl_Vec4 aCenter (0.f, 0.f, 0.f, 1.f);
819 switch (myTextParams.HAlign)
821 case Graphic3d_HTA_LEFT: aCenter.x() = myTextSize.x / 2.f; break;
822 case Graphic3d_HTA_CENTER: aCenter.x() = 0.f; break;
823 case Graphic3d_HTA_RIGHT: aCenter.x() = -myTextSize.x / 2.f; break;
826 switch (myTextParams.VAlign)
828 case Graphic3d_VTA_TOPFIRSTLINE:
829 case Graphic3d_VTA_TOP: aCenter.y() = -myTextSize.y / 2.f; break;
830 case Graphic3d_VTA_CENTER: aCenter.y() = 0.f; break;
831 case Graphic3d_VTA_BOTTOM: aCenter.y() = myTextSize.y / 2.f; break;
835 // compute label's center in view coordinate space
836 const OpenGl_Mat4& aViewMat = aContext->WorldViewState.Current();
837 const OpenGl_Vec4 aCenterView = aViewMat * aCenter;
839 // the value below defines whether the extension line should be hanging
840 // on the left side of the label or on the right
841 const bool isLeftHanded = aAttachView.x() < aCenterView.x();
843 // compute extension line point at the text label in view coordinate space
844 const OpenGl_Vec4 aHingeView = aViewMat * OpenGl_Vec4(
845 ( isLeftHanded ? myTextUnderline.x() : myTextUnderline.x() + myTextSize.x ), myTextUnderline.y(), 0.0f, 1.0f );
847 // prepare matrix to specify geometry of extension line in view space
848 // by multiplication of unit z coordinate vector on given matrix.
849 OpenGl_Mat4 aExtGeometryMat;
850 aExtGeometryMat.SetColumn( 2, aAttachView - aHingeView );
851 aExtGeometryMat.SetColumn( 3, aHingeView );
854 aContext->ModelWorldState.Push();
855 aContext->ModelWorldState.SetIdentity();
856 aContext->WorldViewState.Push();
857 aContext->WorldViewState.SetCurrent( aExtGeometryMat );
858 aContext->ApplyModelViewMatrix();
860 myExtLineDraw->Render( theWorkspace );
861 myExtMarkerDraw->Render( theWorkspace );
863 // ------------------------------------------------------------
864 // restore original state
865 // ------------------------------------------------------------
867 aContext->ModelWorldState.Pop();
868 aContext->WorldViewState.Pop();
870 if ( myOldDepthMode )
872 aContext->core11fwd->glDepthFunc( myOldDepthMode );
875 if ( myAISObject->myIsScreenFixed )
877 aContext->WorldViewState.Pop();
880 aContext->ApplyModelViewMatrix();
882 #if OCC_VERSION_LARGE > 0x07010001
883 theWorkspace->SetHighlightStyle(aHighlightStyle);
885 if ( toHighlight != theWorkspace->ToHighlight() )
887 theWorkspace->SetHighlight( toHighlight );
892 // =======================================================================
893 // subclass : GEOM_AnnotationOwner
894 // function : HilightWithColor
895 // purpose : Perform highlighting of the presentation.
896 // =======================================================================
897 void GEOM_Annotation::GEOM_AnnotationOwner::HilightWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
898 #if OCC_VERSION_LARGE > 0x07010001
899 const Handle(Prs3d_Drawer)& theStyle,
901 const Handle(Graphic3d_HighlightStyle)& theStyle,
903 const Standard_Integer theMode )
905 if ( myPrsSh.IsNull() )
907 Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer;
908 #if OCC_VERSION_LARGE > 0x07010001
909 aDrawer->Link( theStyle );
911 aDrawer->Link( Selectable()->HilightAttributes() );
913 Handle(Prs3d_IsoAspect) aUIsoAspect = new Prs3d_IsoAspect(
914 aDrawer->UIsoAspect()->Aspect()->Color(),
915 aDrawer->UIsoAspect()->Aspect()->Type(),
916 aDrawer->UIsoAspect()->Aspect()->Width(), 0 );
918 Handle(Prs3d_IsoAspect) aVIsoAspect = new Prs3d_IsoAspect(
919 aDrawer->UIsoAspect()->Aspect()->Color(),
920 aDrawer->UIsoAspect()->Aspect()->Type(),
921 aDrawer->UIsoAspect()->Aspect()->Width(), 0 );
923 aDrawer->SetIsoOnPlane( Standard_False );
924 aDrawer->SetUIsoAspect( aUIsoAspect );
925 aDrawer->SetVIsoAspect( aVIsoAspect );
926 myPrsSh = new StdSelect_Shape( myShape, aDrawer );
929 myPrsSh->SetZLayer ( Selectable()->ZLayer() );
931 thePM->Color( Selectable(), theStyle, theMode, NULL, Graphic3d_ZLayerId_Topmost );
933 thePM->Color( myPrsSh, theStyle, theMode, Selectable(), Graphic3d_ZLayerId_Topmost );
936 // =======================================================================
937 // subclass : GEOM_AnnotationOwner
938 // function : Unhilight
939 // purpose : Removes highlighting from the type of shape.
940 // =======================================================================
941 void GEOM_Annotation::GEOM_AnnotationOwner::Unhilight ( const Handle(PrsMgr_PresentationManager)& thePM,
942 const Standard_Integer theMode )
944 SelectMgr_EntityOwner::Unhilight( thePM, theMode );
946 #if OCC_VERSION_LARGE > 0x07010001
947 thePM->Unhighlight( myPrsSh );
949 thePM->Unhighlight( myPrsSh, theMode );
953 // =======================================================================
954 // subclass : GEOM_AnnotationOwner
956 // purpose : Clears the presentation manager object aPM of all shapes
957 // with the given selection mode.
958 // =======================================================================
959 void GEOM_Annotation::GEOM_AnnotationOwner::Clear ( const Handle(PrsMgr_PresentationManager)& thePM,
960 const Standard_Integer theMode )
962 SelectMgr_EntityOwner::Clear( thePM, theMode );
964 if ( !myPrsSh.IsNull() ) {
965 thePM->Clear( myPrsSh, theMode );