Salome HOME
Porting Salome to OCCT 7.7.0
[modules/geom.git] / src / OBJECT / GEOM_Annotation.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 1c66c77..42fe984
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -52,6 +52,8 @@
 #include <V3d_Viewer.hxx>
 #include <V3d_View.hxx>
 
+#include <Basics_OCCTVersion.hxx>
+
 IMPLEMENT_STANDARD_RTTIEXT( GEOM_Annotation, AIS_InteractiveObject )
 
 // =======================================================================
@@ -66,9 +68,6 @@ GEOM_Annotation::GEOM_Annotation() : AIS_InteractiveObject()
   SetDisplayMode( 0 );
   SetZLayer( Graphic3d_ZLayerId_Default );
   SetAutoHide( Standard_True );
-#if OCC_VERSION_LARGE <= 0x07010000
-  SetHilightMode( HighlightAll );
-#endif
   SetMutable( Standard_True );
   SetDepthCulling( Standard_True );
 
@@ -212,7 +211,7 @@ void GEOM_Annotation::SetAttachPoint( const gp_Pnt& thePoint )
 
 // =======================================================================
 // function : SetHilightShape
-// purpose  : Sets shape (annotated shape) that will be used for hilighting.
+// purpose  : Sets shape (annotated shape) that will be used for highlighting.
 // =======================================================================
 void GEOM_Annotation::SetHilightShape( const TopoDS_Shape& theShape )
 {
@@ -539,11 +538,20 @@ Bnd_Box GEOM_Annotation::TextBoundingBox() const
 {
   Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
   Font_FTFont aFont;
+#if OCC_VERSION_LARGE >= 0x070400FF
+  Font_FTFontParams aFontParams;
+  aFontParams.PointSize  = (unsigned int)anAsp->Height();
+  aFontParams.Resolution = GetContext()->CurrentViewer()->DefaultRenderingParams().Resolution;
+  if ( aFont.FindAndInit(anAsp->Aspect()->Font().ToCString(),
+                         anAsp->Aspect()->GetTextFontAspect(),
+                         aFontParams) )
+#else
   unsigned int aResolution = GetContext()->CurrentViewer()->DefaultRenderingParams().Resolution;
   if ( aFont.Init( anAsp->Aspect()->Font().ToCString(),
                    anAsp->Aspect()->GetTextFontAspect(),
-                  (unsigned int)anAsp->Height(),
-                  aResolution ) )
+                   (unsigned int)anAsp->Height(),
+                   aResolution ) ) // deprecated API, to be removed (see above)
+#endif
   {
     const NCollection_String aText( (Standard_Utf16Char* )myText.ToExtString() );
     const Font_Rect aFontRect = aFont.BoundingBox( aText, Graphic3d_HTA_CENTER, Graphic3d_VTA_CENTER );
@@ -625,10 +633,18 @@ GEOM_Annotation::OpenGl_Annotation::OpenGl_Annotation( GEOM_Annotation* theAnnot
   myTextDPI( 0 )
 {
   // graphical resources for drawing text and underline
+#if OCC_VERSION_LARGE >= 0x07040000
+  myTextParams = new Graphic3d_Text( theTextHeight );
+  myTextParams->SetText( myText.ToCString() );
+  myTextParams->SetHorizontalAlignment ( Graphic3d_HTA_CENTER );
+  myTextParams->SetVerticalAlignment ( Graphic3d_VTA_CENTER );
+  myTextDraw = new OpenGl_Text( myTextParams );
+#else
   myTextParams.Height = theTextHeight;
   myTextParams.HAlign = Graphic3d_HTA_CENTER;
   myTextParams.VAlign = Graphic3d_VTA_CENTER;
   myTextDraw = new OpenGl_Text( myText.ToCString(), OpenGl_Vec3(), myTextParams );
+#endif
   myTextLineDraw = new OpenGl_PrimitiveArray( theDriver );
 
   // graphical resources for drawing extension line and marker
@@ -692,16 +708,24 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)&
   const unsigned int aDPI = theWorkspace->View()->RenderingParams().Resolution;
   if (myTextDPI != aDPI)
   {
-    const OpenGl_AspectText* anAspect = theWorkspace->AspectText();
+    const OpenGl_Aspects* anAspect = theWorkspace->Aspects();
 
     // getting string size will also initialize font library
+#if OCC_VERSION_LARGE >= 0x07070000
+    Font_Hinting aFH = theWorkspace->View()->RenderingParams().FontHinting;
     myTextDraw->StringSize( aContext,
-      myText, *anAspect, myTextParams, aDPI,
+      myText, *anAspect, myTextParams->Height(), aDPI, aFH,
       myTextSize.x, myTextSize.a, myTextSize.d );
+#else
+    myTextDraw->StringSize( aContext,
+      myText, *anAspect, myTextParams->Height(), aDPI,
+      myTextSize.x, myTextSize.a, myTextSize.d );
+#endif
 
     myTextDPI = aDPI;
     myTextSize.y = myTextSize.a - myTextSize.d;
-    switch (myTextParams.HAlign)
+
+    switch ( myTextParams->HorizontalAlignment() )
     {
       case Graphic3d_HTA_LEFT:   myTextUnderline.x() = 0.f; break;
       case Graphic3d_HTA_CENTER: myTextUnderline.x() = -myTextSize.x / 2.f; break;
@@ -709,7 +733,8 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)&
       default:
         break;
     }
-    switch (myTextParams.VAlign)
+
+    switch ( myTextParams->VerticalAlignment() )
     {
       case Graphic3d_VTA_TOPFIRSTLINE:
       case Graphic3d_VTA_TOP:    myTextUnderline.y() = -myTextSize.y; break;
@@ -749,23 +774,13 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)&
       return;
     }
   }
-#if OCC_VERSION_LARGE > 0x07010000
   const Handle(Graphic3d_PresentationAttributes) aHighlightStyle = theWorkspace->HighlightStyle();
   if (!aHighlightStyle.IsNull() && myAISObject->myHilightMode == HighlightLabel)
   {
     Handle(Graphic3d_PresentationAttributes) empty;
     theWorkspace->SetHighlightStyle(empty);
-    theWorkspace->ApplyAspectLine();
-  }
-#else    
-  const bool toHighlight = theWorkspace->ToHighlight();
-
-  if (toHighlight && myAISObject->myHilightMode == HighlightLabel)
-  {
-    theWorkspace->SetHighlight( false );
-    theWorkspace->ApplyAspectLine();
+    theWorkspace->ApplyAspects();
   }
-#endif
   
   GLint myOldDepthMode = 0;
 
@@ -785,7 +800,7 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)&
     // to avoid jittering when dragging text
     myTextDraw->SetPosition( OpenGl_Vec3( static_cast<float>( myAISObject->myPosition.X() ),
                                           static_cast<float>( myAISObject->myPosition.Y() ),
-                                          static_cast<float>( myAISObject->myPosition.Z() ) ) );
+                                          static_cast<float>( myAISObject->myPosition.Z() ) ) ); // todo: deprecated OCCT API
   }
 
   myTextDraw->Render( theWorkspace );
@@ -816,14 +831,22 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)&
   // ------------------------------------------------------------
 
   OpenGl_Vec4 aCenter (0.f, 0.f, 0.f, 1.f);
+# if OCC_VERSION_LARGE >= 0x07040000
+  switch ( myTextParams->HorizontalAlignment() )
+#else
   switch (myTextParams.HAlign)
+#endif
   {
     case Graphic3d_HTA_LEFT:   aCenter.x() =  myTextSize.x / 2.f; break;
     case Graphic3d_HTA_CENTER: aCenter.x() = 0.f; break;
     case Graphic3d_HTA_RIGHT:  aCenter.x() = -myTextSize.x / 2.f; break;
     default: break;
   }
+# if OCC_VERSION_LARGE >= 0x07040000
+  switch ( myTextParams->VerticalAlignment() )
+#else
   switch (myTextParams.VAlign)
+#endif
   {
     case Graphic3d_VTA_TOPFIRSTLINE:
     case Graphic3d_VTA_TOP:    aCenter.y() = -myTextSize.y / 2.f; break;
@@ -879,14 +902,7 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)&
 
   aContext->ApplyModelViewMatrix();
   
-#if OCC_VERSION_LARGE > 0x07010000
   theWorkspace->SetHighlightStyle(aHighlightStyle);
-#else
-  if ( toHighlight != theWorkspace->ToHighlight() )
-  {
-    theWorkspace->SetHighlight( toHighlight );
-  }
-#endif
 }
 
 // =======================================================================
@@ -895,21 +911,13 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)&
 // purpose  : Perform highlighting of the presentation.
 // =======================================================================
 void GEOM_Annotation::GEOM_AnnotationOwner::HilightWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
-#if OCC_VERSION_LARGE > 0x07010000                     
                                                              const Handle(Prs3d_Drawer)& theStyle,
-#else                  
-                                                             const Handle(Graphic3d_HighlightStyle)& theStyle,
-#endif                 
                                                               const Standard_Integer theMode )
 {
   if ( myPrsSh.IsNull() )
   {
     Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer;
-#if OCC_VERSION_LARGE > 0x07010000
     aDrawer->Link( theStyle );
-#else
-    aDrawer->Link( Selectable()->HilightAttributes() );
-#endif
     Handle(Prs3d_IsoAspect) aUIsoAspect = new Prs3d_IsoAspect(
       aDrawer->UIsoAspect()->Aspect()->Color(),
       aDrawer->UIsoAspect()->Aspect()->Type(),
@@ -942,12 +950,7 @@ void GEOM_Annotation::GEOM_AnnotationOwner::Unhilight ( const Handle(PrsMgr_Pres
                                                         const Standard_Integer theMode )
 {
   SelectMgr_EntityOwner::Unhilight( thePM, theMode );
-  
-#if OCC_VERSION_LARGE > 0x07010000
   thePM->Unhighlight( myPrsSh );
-#else
-  thePM->Unhighlight( myPrsSh, theMode );
-#endif
 }
 
 // =======================================================================