diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-28 13:09:53 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-28 15:48:34 +0000 |
commit | 8eb682f932d7feb1db2157e6d522126152de786c (patch) | |
tree | 71784ee6ad0edb225e2ff6a7e0c5853a09f6d81c /chart2 | |
parent | b17a441912da448ca0c731a015f4221ae264d959 (diff) |
move setDefaultRotation from ThreeDHelper to Diagram
so we can use the get/setFastPropertyValue methods
Change-Id: Id9470e5b878ed15e20ca285cacc36cd2e9511365
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149649
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/controller/main/ChartController_Tools.cxx | 2 | ||||
-rw-r--r-- | chart2/source/inc/Diagram.hxx | 2 | ||||
-rw-r--r-- | chart2/source/inc/ThreeDHelper.hxx | 6 | ||||
-rw-r--r-- | chart2/source/model/main/Diagram.cxx | 195 | ||||
-rw-r--r-- | chart2/source/model/template/PieChartTypeTemplate.cxx | 4 | ||||
-rw-r--r-- | chart2/source/tools/ThreeDHelper.cxx | 98 |
6 files changed, 123 insertions, 184 deletions
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index 6240e241be8a..5fcfe2bd4550 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -199,7 +199,7 @@ void ChartController::executeDispatch_NewArrangement() xDiagram->setPropertyToDefault( "PosSizeExcludeAxes"); // 3d rotation - ThreeDHelper::set3DSettingsToDefault( xDiagram ); + xDiagram->set3DSettingsToDefault(); // legend Reference< beans::XPropertyState > xLegendState( xDiagram->getLegend(), uno::UNO_QUERY ); diff --git a/chart2/source/inc/Diagram.hxx b/chart2/source/inc/Diagram.hxx index c66fb139ec34..2365d167c6a2 100644 --- a/chart2/source/inc/Diagram.hxx +++ b/chart2/source/inc/Diagram.hxx @@ -348,6 +348,8 @@ public: ThreeDLookScheme detectScheme(); void setScheme( ThreeDLookScheme aScheme ); + void setDefaultRotation( bool bPieOrDonut ); + private: // ____ XModifyListener ____ virtual void SAL_CALL modified( diff --git a/chart2/source/inc/ThreeDHelper.hxx b/chart2/source/inc/ThreeDHelper.hxx index 74063ab61f37..1969b2305f6f 100644 --- a/chart2/source/inc/ThreeDHelper.hxx +++ b/chart2/source/inc/ThreeDHelper.hxx @@ -82,12 +82,6 @@ public: static double CameraDistanceToPerspective( double fCameraDistance ); static double PerspectiveToCameraDistance( double fPerspective ); - static void set3DSettingsToDefault( const rtl::Reference< ::chart::Diagram >& xSceneProperties ); - static void setDefaultRotation( const rtl::Reference< ::chart::Diagram >& xDiagram ); - static void setDefaultIllumination( const rtl::Reference< ::chart::Diagram >& xDiagram ); - - static void setDefaultRotation( const css::uno::Reference< css::beans::XPropertySet >& xSceneProperties, bool bPieOrDonut ); - static CuboidPlanePosition getAutomaticCuboidPlanePositionForStandardLeftWall( const rtl::Reference< ::chart::Diagram >& xDiagram ); static CuboidPlanePosition getAutomaticCuboidPlanePositionForStandardBackWall(const rtl::Reference< diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx index a4af69b7e7bf..8cbdda41422a 100644 --- a/chart2/source/model/main/Diagram.cxx +++ b/chart2/source/model/main/Diagram.cxx @@ -445,17 +445,118 @@ void SAL_CALL Diagram::setTitleObject( const uno::Reference< chart2::XTitle >& x // ____ X3DDefaultSetter ____ void SAL_CALL Diagram::set3DSettingsToDefault() { - ThreeDHelper::set3DSettingsToDefault( this ); + setPropertyToDefault( "D3DSceneDistance"); + setPropertyToDefault( "D3DSceneFocalLength"); + setDefaultRotation(); + setDefaultIllumination(); } void SAL_CALL Diagram::setDefaultRotation() { - ThreeDHelper::setDefaultRotation( this ); + bool bPieOrDonut( isPieOrDonutChart() ); + setDefaultRotation( bPieOrDonut ); +} + +static ::basegfx::B3DHomMatrix lcl_getCompleteRotationMatrix( Diagram& rDiagram ) +{ + ::basegfx::B3DHomMatrix aCompleteRotation; + double fXAngleRad=0.0; + double fYAngleRad=0.0; + double fZAngleRad=0.0; + rDiagram.getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad ); + aCompleteRotation.rotate( fXAngleRad, fYAngleRad, fZAngleRad ); + return aCompleteRotation; +} +static void lcl_RotateLightSource( Diagram& rDiagram + , int nLightSourceDirectionProp + , int nLightSourceOnProp + , const ::basegfx::B3DHomMatrix& rRotationMatrix ) +{ + bool bLightOn = false; + if( !(rDiagram.getFastPropertyValue( nLightSourceOnProp ) >>= bLightOn) ) + return; + + if( bLightOn ) + { + drawing::Direction3D aLight; + if( rDiagram.getFastPropertyValue( nLightSourceDirectionProp ) >>= aLight ) + { + ::basegfx::B3DVector aLightVector( BaseGFXHelper::Direction3DToB3DVector( aLight ) ); + aLightVector = rRotationMatrix*aLightVector; + + rDiagram.setFastPropertyValue( nLightSourceDirectionProp + , uno::Any( BaseGFXHelper::B3DVectorToDirection3D( aLightVector ) ) ); + } + } +} + +static void lcl_setLightsForScheme( Diagram& rDiagram, const ThreeDLookScheme& rScheme ) +{ + if( rScheme == ThreeDLookScheme::ThreeDLookScheme_Unknown) + return; + + // "D3DSceneLightOn2" / UNO_NAME_3D_SCENE_LIGHTON_2 + rDiagram.setFastPropertyValue( PROP_SCENE_LIGHT_ON_2, uno::Any( true ) ); + + rtl::Reference< ChartType > xChartType( rDiagram.getChartTypeByIndex( 0 ) ); + uno::Any aADirection( rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple + ? ChartTypeHelper::getDefaultSimpleLightDirection(xChartType) + : ChartTypeHelper::getDefaultRealisticLightDirection(xChartType) ); + + // "D3DSceneLightDirection2" / UNO_NAME_3D_SCENE_LIGHTDIRECTION_2 + rDiagram.setFastPropertyValue( PROP_SCENE_LIGHT_DIRECTION_2, aADirection ); + //rotate light direction when right angled axes are off but supported + { + bool bRightAngledAxes = false; + rDiagram.getFastPropertyValue( PROP_DIAGRAM_RIGHT_ANGLED_AXES ) >>= bRightAngledAxes; // "RightAngledAxes" + if(!bRightAngledAxes) + { + if( ChartTypeHelper::isSupportingRightAngledAxes( xChartType ) ) + { + ::basegfx::B3DHomMatrix aRotation( lcl_getCompleteRotationMatrix( rDiagram ) ); + BaseGFXHelper::ReduceToRotationMatrix( aRotation ); + // "D3DSceneLightDirection2", "D3DSceneLightOn2" + lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_2, PROP_SCENE_LIGHT_ON_2, aRotation ); + } + } + } + + sal_Int32 nColor = ::chart::ChartTypeHelper::getDefaultDirectLightColor( + rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple, xChartType); + // "D3DSceneLightColor2" / UNO_NAME_3D_SCENE_LIGHTCOLOR_2 + rDiagram.setFastPropertyValue( PROP_SCENE_LIGHT_COLOR_2, uno::Any( nColor ) ); + + sal_Int32 nAmbientColor = ::chart::ChartTypeHelper::getDefaultAmbientLightColor( + rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple, xChartType); + // "D3DSceneAmbientColor" / UNO_NAME_3D_SCENE_AMBIENTCOLOR + rDiagram.setFastPropertyValue( PROP_SCENE_AMBIENT_COLOR, uno::Any( nAmbientColor ) ); } void SAL_CALL Diagram::setDefaultIllumination() { - ThreeDHelper::setDefaultIllumination( this ); + drawing::ShadeMode aShadeMode( drawing::ShadeMode_SMOOTH ); + try + { + // "D3DSceneShadeMode" + getFastPropertyValue( PROP_SCENE_SHADE_MODE )>>= aShadeMode; + // "D3DSceneLightOn1" / UNO_NAME_3D_SCENE_LIGHTON_1 + setFastPropertyValue( PROP_SCENE_LIGHT_ON_1, uno::Any( false ) ); + setFastPropertyValue( PROP_SCENE_LIGHT_ON_3, uno::Any( false ) ); + setFastPropertyValue( PROP_SCENE_LIGHT_ON_4, uno::Any( false ) ); + setFastPropertyValue( PROP_SCENE_LIGHT_ON_5, uno::Any( false ) ); + setFastPropertyValue( PROP_SCENE_LIGHT_ON_6, uno::Any( false ) ); + setFastPropertyValue( PROP_SCENE_LIGHT_ON_7, uno::Any( false ) ); + setFastPropertyValue( PROP_SCENE_LIGHT_ON_8, uno::Any( false ) ); + } + catch( const uno::Exception & ) + { + DBG_UNHANDLED_EXCEPTION("chart2"); + } + + ThreeDLookScheme aScheme = (aShadeMode == drawing::ShadeMode_FLAT) + ? ThreeDLookScheme::ThreeDLookScheme_Simple + : ThreeDLookScheme::ThreeDLookScheme_Realistic; + lcl_setLightsForScheme( *this, aScheme ); } // ____ XCoordinateSystemContainer ____ @@ -1868,29 +1969,6 @@ static ::basegfx::B3DHomMatrix lcl_getInverseRotationMatrix( Diagram& rDiagram ) return aInverseRotation; } -static void lcl_RotateLightSource( Diagram& rDiagram - , int nLightSourceDirectionProp - , int nLightSourceOnProp - , const ::basegfx::B3DHomMatrix& rRotationMatrix ) -{ - bool bLightOn = false; - if( !(rDiagram.getFastPropertyValue( nLightSourceOnProp ) >>= bLightOn) ) - return; - - if( bLightOn ) - { - drawing::Direction3D aLight; - if( rDiagram.getFastPropertyValue( nLightSourceDirectionProp ) >>= aLight ) - { - ::basegfx::B3DVector aLightVector( BaseGFXHelper::Direction3DToB3DVector( aLight ) ); - aLightVector = rRotationMatrix*aLightVector; - - rDiagram.setFastPropertyValue( nLightSourceDirectionProp - , uno::Any( BaseGFXHelper::B3DVectorToDirection3D( aLightVector ) ) ); - } - } -} - static void lcl_rotateLights( const ::basegfx::B3DHomMatrix& rLightRotation, Diagram& rDiagram ) { ::basegfx::B3DHomMatrix aLightRotation( rLightRotation ); @@ -1993,16 +2071,6 @@ static bool lcl_isRealisticScheme( drawing::ShadeMode aShadeMode return false; return true; } -static ::basegfx::B3DHomMatrix lcl_getCompleteRotationMatrix( Diagram& rDiagram ) -{ - ::basegfx::B3DHomMatrix aCompleteRotation; - double fXAngleRad=0.0; - double fYAngleRad=0.0; - double fZAngleRad=0.0; - rDiagram.getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad ); - aCompleteRotation.rotate( fXAngleRad, fYAngleRad, fZAngleRad ); - return aCompleteRotation; -} static bool lcl_isLightScheme( Diagram& rDiagram, bool bRealistic ) { bool bIsOn = false; @@ -2115,47 +2183,6 @@ static void lcl_setSimpleScheme( drawing::ShadeMode& rShadeMode rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeByIndex( 0 ) ); rnObjectLines = ChartTypeHelper::noBordersForSimpleScheme( xChartType ) ? 0 : 1; } -static void lcl_setLightsForScheme( Diagram& rDiagram, const ThreeDLookScheme& rScheme ) -{ - if( rScheme == ThreeDLookScheme::ThreeDLookScheme_Unknown) - return; - - // "D3DSceneLightOn2" / UNO_NAME_3D_SCENE_LIGHTON_2 - rDiagram.setFastPropertyValue( PROP_SCENE_LIGHT_ON_2, uno::Any( true ) ); - - rtl::Reference< ChartType > xChartType( rDiagram.getChartTypeByIndex( 0 ) ); - uno::Any aADirection( rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple - ? ChartTypeHelper::getDefaultSimpleLightDirection(xChartType) - : ChartTypeHelper::getDefaultRealisticLightDirection(xChartType) ); - - // "D3DSceneLightDirection2" / UNO_NAME_3D_SCENE_LIGHTDIRECTION_2 - rDiagram.setFastPropertyValue( PROP_SCENE_LIGHT_DIRECTION_2, aADirection ); - //rotate light direction when right angled axes are off but supported - { - bool bRightAngledAxes = false; - rDiagram.getFastPropertyValue( PROP_DIAGRAM_RIGHT_ANGLED_AXES ) >>= bRightAngledAxes; // "RightAngledAxes" - if(!bRightAngledAxes) - { - if( ChartTypeHelper::isSupportingRightAngledAxes( xChartType ) ) - { - ::basegfx::B3DHomMatrix aRotation( lcl_getCompleteRotationMatrix( rDiagram ) ); - BaseGFXHelper::ReduceToRotationMatrix( aRotation ); - // "D3DSceneLightDirection2", "D3DSceneLightOn2" - lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_2, PROP_SCENE_LIGHT_ON_2, aRotation ); - } - } - } - - sal_Int32 nColor = ::chart::ChartTypeHelper::getDefaultDirectLightColor( - rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple, xChartType); - rDiagram.setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_2, uno::Any( nColor ) ); - - sal_Int32 nAmbientColor = ::chart::ChartTypeHelper::getDefaultAmbientLightColor( - rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple, xChartType); - // "D3DSceneAmbientColor" / UNO_NAME_3D_SCENE_AMBIENTCOLOR - rDiagram.setFastPropertyValue( PROP_SCENE_AMBIENT_COLOR, uno::Any( nAmbientColor ) ); -} - void Diagram::setScheme( ThreeDLookScheme aScheme ) { if( aScheme == ThreeDLookScheme::ThreeDLookScheme_Unknown ) @@ -2190,6 +2217,20 @@ void Diagram::setScheme( ThreeDLookScheme aScheme ) } +void Diagram::setDefaultRotation( bool bPieOrDonut ) +{ + drawing::CameraGeometry aCameraGeo( ThreeDHelper::getDefaultCameraGeometry( bPieOrDonut ) ); + // "D3DCameraGeometry" + setFastPropertyValue( PROP_SCENE_CAMERA_GEOMETRY, uno::Any( aCameraGeo )); + + ::basegfx::B3DHomMatrix aSceneRotation; + if( bPieOrDonut ) + aSceneRotation.rotate( -M_PI/3.0, 0, 0 ); + // "D3DTransformMatrix" + setFastPropertyValue( PROP_SCENE_TRANSF_MATRIX, + uno::Any( BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aSceneRotation ))); +} + } // namespace chart extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * diff --git a/chart2/source/model/template/PieChartTypeTemplate.cxx b/chart2/source/model/template/PieChartTypeTemplate.cxx index 84e3f1227a07..c14458870d58 100644 --- a/chart2/source/model/template/PieChartTypeTemplate.cxx +++ b/chart2/source/model/template/PieChartTypeTemplate.cxx @@ -545,7 +545,7 @@ void PieChartTypeTemplate::resetStyles2( const rtl::Reference< ::chart::Diagram } //reset scene properties - ThreeDHelper::setDefaultRotation( xDiagram, false ); + xDiagram->setDefaultRotation( false ); } // ____ XChartTypeTemplate ____ @@ -555,7 +555,7 @@ void PieChartTypeTemplate::adaptDiagram( const rtl::Reference< ::chart::Diagram return; //different default for scene geometry: - ThreeDHelper::setDefaultRotation( xDiagram, true ); + xDiagram->setDefaultRotation( true ); } IMPLEMENT_FORWARD_XINTERFACE2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet ) diff --git a/chart2/source/tools/ThreeDHelper.cxx b/chart2/source/tools/ThreeDHelper.cxx index aa60a51eb1cb..13c4ca47af3b 100644 --- a/chart2/source/tools/ThreeDHelper.cxx +++ b/chart2/source/tools/ThreeDHelper.cxx @@ -135,44 +135,6 @@ void lcl_rotateLights( const ::basegfx::B3DHomMatrix& rLightRottion, const Refer return aCompleteRotation; } -void lcl_setLightsForScheme( const rtl::Reference< Diagram >& xDiagram, const ThreeDLookScheme& rScheme ) -{ - if(!xDiagram.is()) - return; - if( rScheme == ThreeDLookScheme::ThreeDLookScheme_Unknown) - return; - - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_2, uno::Any( true ) ); - - rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeByIndex( 0 ) ); - uno::Any aADirection( rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple - ? ChartTypeHelper::getDefaultSimpleLightDirection(xChartType) - : ChartTypeHelper::getDefaultRealisticLightDirection(xChartType) ); - - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_2, aADirection ); - //rotate light direction when right angled axes are off but supported - { - bool bRightAngledAxes = false; - xDiagram->getPropertyValue( "RightAngledAxes") >>= bRightAngledAxes; - if(!bRightAngledAxes) - { - if( ChartTypeHelper::isSupportingRightAngledAxes( xChartType ) ) - { - ::basegfx::B3DHomMatrix aRotation( lcl_getCompleteRotationMatrix( xDiagram ) ); - BaseGFXHelper::ReduceToRotationMatrix( aRotation ); - lcl_RotateLightSource( xDiagram, "D3DSceneLightDirection2", "D3DSceneLightOn2", aRotation ); - } - } - } - - sal_Int32 nColor = ::chart::ChartTypeHelper::getDefaultDirectLightColor( - rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple, xChartType); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_2, uno::Any( nColor ) ); - - sal_Int32 nAmbientColor = ::chart::ChartTypeHelper::getDefaultAmbientLightColor( - rScheme == ThreeDLookScheme::ThreeDLookScheme_Simple, xChartType); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_AMBIENTCOLOR, uno::Any( nAmbientColor ) ); -} } //end anonymous namespace @@ -791,66 +753,6 @@ double ThreeDHelper::PerspectiveToCameraDistance( double fPerspective ) return fRet; } -void ThreeDHelper::set3DSettingsToDefault( const rtl::Reference< Diagram >& xDiagram ) -{ - if(xDiagram.is()) - { - xDiagram->setPropertyToDefault( "D3DSceneDistance"); - xDiagram->setPropertyToDefault( "D3DSceneFocalLength"); - } - ThreeDHelper::setDefaultRotation( xDiagram ); - ThreeDHelper::setDefaultIllumination( xDiagram ); -} - -void ThreeDHelper::setDefaultRotation( const uno::Reference< beans::XPropertySet >& xSceneProperties, bool bPieOrDonut ) -{ - if( !xSceneProperties.is() ) - return; - - drawing::CameraGeometry aCameraGeo( ThreeDHelper::getDefaultCameraGeometry( bPieOrDonut ) ); - xSceneProperties->setPropertyValue( "D3DCameraGeometry", uno::Any( aCameraGeo )); - - ::basegfx::B3DHomMatrix aSceneRotation; - if( bPieOrDonut ) - aSceneRotation.rotate( -M_PI/3.0, 0, 0 ); - xSceneProperties->setPropertyValue( "D3DTransformMatrix", - uno::Any( BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aSceneRotation ))); -} - -void ThreeDHelper::setDefaultRotation( const rtl::Reference< Diagram >& xDiagram ) -{ - bool bPieOrDonut( xDiagram->isPieOrDonutChart() ); - ThreeDHelper::setDefaultRotation( xDiagram, bPieOrDonut ); -} - -void ThreeDHelper::setDefaultIllumination( const rtl::Reference<::chart::Diagram>& xDiagram ) -{ - if( !xDiagram.is() ) - return; - - drawing::ShadeMode aShadeMode( drawing::ShadeMode_SMOOTH ); - try - { - xDiagram->getPropertyValue( "D3DSceneShadeMode" )>>= aShadeMode; - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_1, uno::Any( false ) ); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_3, uno::Any( false ) ); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_4, uno::Any( false ) ); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_5, uno::Any( false ) ); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_6, uno::Any( false ) ); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_7, uno::Any( false ) ); - xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_8, uno::Any( false ) ); - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - - ThreeDLookScheme aScheme = (aShadeMode == drawing::ShadeMode_FLAT) - ? ThreeDLookScheme::ThreeDLookScheme_Simple - : ThreeDLookScheme::ThreeDLookScheme_Realistic; - lcl_setLightsForScheme( xDiagram, aScheme ); -} - void ThreeDHelper::getRoundedEdgesAndObjectLines( const rtl::Reference< Diagram > & xDiagram , sal_Int32& rnRoundedEdges, sal_Int32& rnObjectLines ) |