From d07a864e835879ccbbc2a5d21a0ba0ab131c3f36 Mon Sep 17 00:00:00 2001 From: rnv Date: Tue, 17 Dec 2019 22:17:17 +0300 Subject: [PATCH] Porting to OCCT-7.4.0 --- src/Material/Material_Model.cxx | 40 ++++++++++++++++++++++++++++++++- src/OBJECT/GEOM_AISShape.cxx | 10 +++++++-- src/OBJECT/GEOM_Annotation.cxx | 32 ++++++++++++++++++++++++++ src/OBJECT/GEOM_Annotation.hxx | 10 ++++++++- 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/src/Material/Material_Model.cxx b/src/Material/Material_Model.cxx index 0b6792f34..8f66ac34a 100644 --- a/src/Material/Material_Model.cxx +++ b/src/Material/Material_Model.cxx @@ -27,6 +27,8 @@ #include +#include + /*! \brief Constructor @@ -557,17 +559,34 @@ Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect( bool theIsFront ) QColor c; // ambient reflection +#if OCC_VERSION_LARGE >= 0x07040000 + if ( color( Ambient ).isValid() ) { + c = color( Ambient ); + aspect.SetAmbientColor( Quantity_Color( Graphic3d_Vec3( c.redF(), c.greenF(), c.blueF() ) * reflection( Ambient, theIsFront ) ) ); + } + if ( !hasReflection( Ambient ) ) + aspect.SetAmbientColor( Quantity_NOC_BLACK ); +#else if ( color( Ambient ).isValid() ) { c = color( Ambient ); - aspect.SetAmbientColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); + aspect.SetAmbientColor( ( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); } aspect.SetAmbient( reflection( Ambient, theIsFront )); if ( hasReflection( Ambient ) ) aspect.SetReflectionModeOn( Graphic3d_TOR_AMBIENT ); else aspect.SetReflectionModeOff( Graphic3d_TOR_AMBIENT ); +#endif // diffuse reflection +#if OCC_VERSION_LARGE >= 0x07040000 + if ( color( Diffuse ).isValid() ) { + c = color( Diffuse ); + aspect.SetDiffuseColor( Quantity_Color( Graphic3d_Vec3( c.redF(), c.greenF(), c.blueF() ) * reflection( Diffuse, theIsFront ) ) ); + } + if ( !hasReflection( Diffuse ) ) + aspect.SetDiffuseColor( Quantity_NOC_BLACK ); +#else if ( color( Diffuse ).isValid() ) { c = color( Diffuse ); aspect.SetDiffuseColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); @@ -577,8 +596,17 @@ Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect( bool theIsFront ) aspect.SetReflectionModeOn( Graphic3d_TOR_DIFFUSE ); else aspect.SetReflectionModeOff( Graphic3d_TOR_DIFFUSE ); +#endif // specular reflection +#if OCC_VERSION_LARGE >= 0x07040000 + if ( color( Specular ).isValid() ) { + c = color( Specular ); + aspect.SetSpecularColor( Quantity_Color( Graphic3d_Vec3( c.redF(), c.greenF(), c.blueF() ) * reflection( Specular, theIsFront ) ) ); + } + if ( !hasReflection( Specular ) ) + aspect.SetSpecularColor( Quantity_NOC_BLACK ); +#else if ( color( Specular ).isValid() ) { c = color( Specular ); aspect.SetSpecularColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); @@ -588,8 +616,17 @@ Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect( bool theIsFront ) aspect.SetReflectionModeOn( Graphic3d_TOR_SPECULAR ); else aspect.SetReflectionModeOff( Graphic3d_TOR_SPECULAR ); +#endif // emissive reflection +#if OCC_VERSION_LARGE >= 0x07040000 + if ( color( Emissive ).isValid() ) { + c = color( Emissive ); + aspect.SetEmissiveColor( Quantity_Color( Graphic3d_Vec3( c.redF(), c.greenF(), c.blueF() ) * reflection( Emissive, theIsFront ) ) ); + } + if ( !hasReflection( Emissive ) ) + aspect.SetEmissiveColor( Quantity_NOC_BLACK ); +#else if ( color( Emissive ).isValid() ) { c = color( Emissive ); aspect.SetEmissiveColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); @@ -599,6 +636,7 @@ Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect( bool theIsFront ) aspect.SetReflectionModeOn( Graphic3d_TOR_EMISSION ); else aspect.SetReflectionModeOff( Graphic3d_TOR_EMISSION ); +#endif // shininess aspect.SetShininess( shininess( theIsFront ) ); diff --git a/src/OBJECT/GEOM_AISShape.cxx b/src/OBJECT/GEOM_AISShape.cxx index 11ef68e1c..abfab4f73 100644 --- a/src/OBJECT/GEOM_AISShape.cxx +++ b/src/OBJECT/GEOM_AISShape.cxx @@ -161,12 +161,18 @@ GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape, myTopLevel = Standard_False; Graphic3d_MaterialAspect aMatAspect; if ( !HasMaterial() ) { +#if OCC_VERSION_LARGE >= 0x07040000 + aMatAspect.SetAmbientColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) ); + aMatAspect.SetDiffuseColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) ); + aMatAspect.SetEmissiveColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) ); + aMatAspect.SetSpecularColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) ); +#else aMatAspect.SetAmbient( 0.5 ); aMatAspect.SetDiffuse( 0.5 ); aMatAspect.SetEmissive( 0.5 ); - aMatAspect.SetShininess(0.5 ); aMatAspect.SetSpecular( 0.5 ); - +#endif + aMatAspect.SetShininess(0.5 ); myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect); myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect); } diff --git a/src/OBJECT/GEOM_Annotation.cxx b/src/OBJECT/GEOM_Annotation.cxx index 932466d9b..830569b65 100644 --- a/src/OBJECT/GEOM_Annotation.cxx +++ b/src/OBJECT/GEOM_Annotation.cxx @@ -624,10 +624,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 @@ -698,13 +706,24 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)& #endif // getting string size will also initialize font library +#if OCC_VERSION_LARGE >= 0x07040000 + myTextDraw->StringSize( aContext, + myText, *anAspect, myTextParams->Height(), aDPI, + myTextSize.x, myTextSize.a, myTextSize.d ); +#else myTextDraw->StringSize( aContext, myText, *anAspect, myTextParams, aDPI, myTextSize.x, myTextSize.a, myTextSize.d ); +#endif myTextDPI = aDPI; myTextSize.y = myTextSize.a - myTextSize.d; + +# if OCC_VERSION_LARGE >= 0x07040000 + switch ( myTextParams->HorizontalAlignment() ) +#else switch (myTextParams.HAlign) +#endif { case Graphic3d_HTA_LEFT: myTextUnderline.x() = 0.f; break; case Graphic3d_HTA_CENTER: myTextUnderline.x() = -myTextSize.x / 2.f; break; @@ -712,7 +731,12 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)& default: break; } + +# if OCC_VERSION_LARGE >= 0x07040000 + switch ( myTextParams->VerticalAlignment() ) +#else switch (myTextParams.VAlign) +#endif { case Graphic3d_VTA_TOPFIRSTLINE: case Graphic3d_VTA_TOP: myTextUnderline.y() = -myTextSize.y; break; @@ -813,14 +837,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; diff --git a/src/OBJECT/GEOM_Annotation.hxx b/src/OBJECT/GEOM_Annotation.hxx index 5ecb38174..bcc5f0b72 100644 --- a/src/OBJECT/GEOM_Annotation.hxx +++ b/src/OBJECT/GEOM_Annotation.hxx @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -45,6 +44,11 @@ #include #include +#if OCC_VERSION_LARGE >= 0x07040000 +#include +#else +#include +#endif class OpenGl_GraphicDriver; class OpenGl_PrimitiveArray; @@ -329,7 +333,11 @@ private: GEOM_Annotation* myAISObject; //!< Instance of presentation class. NCollection_String myText; //!< Text string of annotation label. +#if OCC_VERSION_LARGE >= 0x07040000 + Handle(Graphic3d_Text) myTextParams; //!< Text draw parameters. +#else OpenGl_TextParam myTextParams; //!< Text draw parameters. +#endif OpenGl_Text* myTextDraw; //!< Text draw element. OpenGl_PrimitiveArray* myTextLineDraw; //!< Text underline draw element. OpenGl_PrimitiveArray* myExtLineDraw; //!< Extension line draw element. -- 2.39.2