diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-28 12:15:39 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-28 13:28:10 +0000 |
commit | b17a441912da448ca0c731a015f4221ae264d959 (patch) | |
tree | 40655b8f9fcc832b20925e5b33a1f2f61da1c809 | |
parent | 7fcfc39232d2fea7078c15552ee092b973e9175b (diff) |
move get/setScheme from ThreeDHelper to Diagram
so we can use the get/setFastPropertyValue methods
Change-Id: I2b57212a1d3933cd2825e647f692e2ae3cb8b484
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149647
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx | 4 | ||||
-rw-r--r-- | chart2/source/controller/dialogs/ChartTypeDialogController.cxx | 2 | ||||
-rw-r--r-- | chart2/source/controller/dialogs/DialogModel.cxx | 8 | ||||
-rw-r--r-- | chart2/source/controller/dialogs/tp_3D_SceneAppearance.cxx | 6 | ||||
-rw-r--r-- | chart2/source/controller/dialogs/tp_ChartType.cxx | 6 | ||||
-rw-r--r-- | chart2/source/controller/sidebar/ChartTypePanel.cxx | 7 | ||||
-rw-r--r-- | chart2/source/inc/Diagram.hxx | 4 | ||||
-rw-r--r-- | chart2/source/inc/ThreeDHelper.hxx | 4 | ||||
-rw-r--r-- | chart2/source/model/main/ChartModel_Persistence.cxx | 2 | ||||
-rw-r--r-- | chart2/source/model/main/Diagram.cxx | 235 | ||||
-rw-r--r-- | chart2/source/tools/ThreeDHelper.cxx | 189 |
11 files changed, 256 insertions, 211 deletions
diff --git a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx index a2385ba897b7..d3fb9cdec6ce 100644 --- a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx @@ -1180,7 +1180,7 @@ uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstance( // locked controllers ControllerLockGuardUNO aCtrlLockGuard( xChartDoc ); rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram( xChartDoc ); - ThreeDLookScheme e3DScheme = ThreeDHelper::detectScheme( xDiagram ); + ThreeDLookScheme e3DScheme = xDiagram->detectScheme(); rtl::Reference< ::chart::ChartTypeManager > xTemplateManager = xChartDoc->getTypeManager(); Diagram::tTemplateWithServiceName aTemplateWithService( xDiagram->getTemplate( xTemplateManager )); @@ -1189,7 +1189,7 @@ uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstance( xTemplate->changeDiagram( xDiagram ); if( AllSettings::GetMathLayoutRTL() ) AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) ); - ThreeDHelper::setScheme( xDiagram, e3DScheme ); + xDiagram->setScheme( e3DScheme ); } else { diff --git a/chart2/source/controller/dialogs/ChartTypeDialogController.cxx b/chart2/source/controller/dialogs/ChartTypeDialogController.cxx index d1c6a725decb..c3da09945ac3 100644 --- a/chart2/source/controller/dialogs/ChartTypeDialogController.cxx +++ b/chart2/source/controller/dialogs/ChartTypeDialogController.cxx @@ -323,7 +323,7 @@ void ChartTypeDialogController::commitToModel( const ChartTypeParameter& rParame if( AllSettings::GetMathLayoutRTL() ) AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) ); if( rParameter.b3DLook ) - ThreeDHelper::setScheme( xDiagram, rParameter.eThreeDLookScheme ); + xDiagram->setScheme( rParameter.eThreeDLookScheme ); if (xDiagram.is()) { diff --git a/chart2/source/controller/dialogs/DialogModel.cxx b/chart2/source/controller/dialogs/DialogModel.cxx index c9084ca8f518..032ec26dc912 100644 --- a/chart2/source/controller/dialogs/DialogModel.cxx +++ b/chart2/source/controller/dialogs/DialogModel.cxx @@ -548,7 +548,7 @@ rtl::Reference< ::chart::DataSeries > DialogModel::insertSeriesAfter( try { rtl::Reference< Diagram > xDiagram( m_xChartDocument->getFirstChartDiagram() ); - ThreeDLookScheme e3DScheme = ThreeDHelper::detectScheme( xDiagram ); + ThreeDLookScheme e3DScheme = xDiagram->detectScheme(); sal_Int32 nSeriesInChartType = 0; const sal_Int32 nTotalSeries = countSeries(); @@ -571,7 +571,7 @@ rtl::Reference< ::chart::DataSeries > DialogModel::insertSeriesAfter( if( xNewSeries.is()) addNewSeriesToContainer(xChartType, xSeries, xNewSeries); - ThreeDHelper::setScheme( xDiagram, e3DScheme ); + xDiagram->setScheme( e3DScheme ); } catch( const uno::Exception & ) { @@ -715,7 +715,7 @@ void DialogModel::setData( if( xInterpreter.is()) { rtl::Reference< Diagram > xDiagram( m_xChartDocument->getFirstChartDiagram() ); - ThreeDLookScheme e3DScheme = ThreeDHelper::detectScheme( xDiagram ); + ThreeDLookScheme e3DScheme = xDiagram->detectScheme(); std::vector< rtl::Reference< DataSeries > > aSeriesToReUse = xDiagram->getDataSeries(); @@ -725,7 +725,7 @@ void DialogModel::setData( aSeriesToReUse ), aSeriesToReUse); - ThreeDHelper::setScheme( xDiagram, e3DScheme ); + xDiagram->setScheme( e3DScheme ); } } catch( const uno::Exception & ) diff --git a/chart2/source/controller/dialogs/tp_3D_SceneAppearance.cxx b/chart2/source/controller/dialogs/tp_3D_SceneAppearance.cxx index cd5e9f63db97..53838614c8a9 100644 --- a/chart2/source/controller/dialogs/tp_3D_SceneAppearance.cxx +++ b/chart2/source/controller/dialogs/tp_3D_SceneAppearance.cxx @@ -56,7 +56,7 @@ lcl_ModelProperties lcl_getPropertiesFromModel( rtl::Reference<::chart::ChartMod rtl::Reference< ::chart::Diagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) ); xDiagram->getPropertyValue( "D3DSceneShadeMode" ) >>= aProps.m_aShadeMode; ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines ); - aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram ); + aProps.m_eScheme = xDiagram->detectScheme(); } catch( const uno::Exception & ) { @@ -273,9 +273,9 @@ IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl, weld::ComboBox& rtl::Reference< Diagram > xDiagram = ::chart::ChartModelHelper::findDiagram( m_xChartModel ); if( m_xLB_Scheme->get_active() == POS_3DSCHEME_REALISTIC ) - ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme::ThreeDLookScheme_Realistic ); + xDiagram->setScheme( ThreeDLookScheme::ThreeDLookScheme_Realistic ); else if( m_xLB_Scheme->get_active() == POS_3DSCHEME_SIMPLE ) - ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme::ThreeDLookScheme_Simple ); + xDiagram->setScheme( ThreeDLookScheme::ThreeDLookScheme_Simple ); else { OSL_FAIL( "Invalid Entry selected" ); diff --git a/chart2/source/controller/dialogs/tp_ChartType.cxx b/chart2/source/controller/dialogs/tp_ChartType.cxx index 0e523eb03d65..e34f918e79b0 100644 --- a/chart2/source/controller/dialogs/tp_ChartType.cxx +++ b/chart2/source/controller/dialogs/tp_ChartType.cxx @@ -182,7 +182,7 @@ void ChartTypeTabPage::stateChanged() //detect the new ThreeDLookScheme rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram(m_xChartModel); // tdf#124295 - select always a 3D scheme - if (ThreeDLookScheme aThreeDLookScheme = ThreeDHelper::detectScheme(xDiagram); + if (ThreeDLookScheme aThreeDLookScheme = xDiagram->detectScheme(); aThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Unknown) aParameter.eThreeDLookScheme = aThreeDLookScheme; @@ -245,7 +245,7 @@ void ChartTypeTabPage::selectMainType() m_pCurrentMainType->adjustParameterToMainType( aParameter ); commitToModel( aParameter ); //detect the new ThreeDLookScheme - aParameter.eThreeDLookScheme = ThreeDHelper::detectScheme( ChartModelHelper::findDiagram( m_xChartModel ) ); + aParameter.eThreeDLookScheme = ChartModelHelper::findDiagram( m_xChartModel )->detectScheme(); if (!aParameter.b3DLook && aParameter.eThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Realistic) aParameter.eThreeDLookScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; @@ -325,7 +325,7 @@ void ChartTypeTabPage::initializePage() m_pCurrentMainType = getSelectedMainType(); //set ThreeDLookScheme - aParameter.eThreeDLookScheme = ThreeDHelper::detectScheme( xDiagram ); + aParameter.eThreeDLookScheme = xDiagram->detectScheme(); if (!aParameter.b3DLook && aParameter.eThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Realistic) aParameter.eThreeDLookScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; diff --git a/chart2/source/controller/sidebar/ChartTypePanel.cxx b/chart2/source/controller/sidebar/ChartTypePanel.cxx index 42aac80f9152..fa17c4866751 100644 --- a/chart2/source/controller/sidebar/ChartTypePanel.cxx +++ b/chart2/source/controller/sidebar/ChartTypePanel.cxx @@ -182,7 +182,7 @@ void ChartTypePanel::Initialize() m_pCurrentMainType = getSelectedMainType(); //set ThreeDLookScheme - aParameter.eThreeDLookScheme = ThreeDHelper::detectScheme(xDiagram); + aParameter.eThreeDLookScheme = xDiagram->detectScheme(); if (!aParameter.b3DLook && aParameter.eThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Realistic) aParameter.eThreeDLookScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; @@ -370,7 +370,7 @@ void ChartTypePanel::stateChanged() //detect the new ThreeDLookScheme rtl::Reference<Diagram> xDiagram = ChartModelHelper::findDiagram(m_xChartModel); - aParameter.eThreeDLookScheme = ThreeDHelper::detectScheme(xDiagram); + aParameter.eThreeDLookScheme = xDiagram->detectScheme(); try { xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues; @@ -413,8 +413,7 @@ void ChartTypePanel::selectMainType() m_pCurrentMainType->adjustParameterToMainType(aParameter); commitToModel(aParameter); //detect the new ThreeDLookScheme - aParameter.eThreeDLookScheme - = ThreeDHelper::detectScheme(ChartModelHelper::findDiagram(m_xChartModel)); + aParameter.eThreeDLookScheme = ChartModelHelper::findDiagram(m_xChartModel)->detectScheme(); if (!aParameter.b3DLook && aParameter.eThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Realistic) aParameter.eThreeDLookScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; diff --git a/chart2/source/inc/Diagram.hxx b/chart2/source/inc/Diagram.hxx index 98f0e17ac82b..c66fb139ec34 100644 --- a/chart2/source/inc/Diagram.hxx +++ b/chart2/source/inc/Diagram.hxx @@ -50,6 +50,7 @@ class DataTable; class RegressionCurveModel; enum class StackMode; class Wall; +enum class ThreeDLookScheme; enum class DiagramPositioningMode { @@ -344,6 +345,9 @@ public: void setRotationAngle( double fXAngleRad, double fYAngleRad, double fZAngleRad ); + ThreeDLookScheme detectScheme(); + void setScheme( ThreeDLookScheme aScheme ); + private: // ____ XModifyListener ____ virtual void SAL_CALL modified( diff --git a/chart2/source/inc/ThreeDHelper.hxx b/chart2/source/inc/ThreeDHelper.hxx index 503679e9b56f..74063ab61f37 100644 --- a/chart2/source/inc/ThreeDHelper.hxx +++ b/chart2/source/inc/ThreeDHelper.hxx @@ -95,10 +95,6 @@ public: static CuboidPlanePosition getAutomaticCuboidPlanePositionForStandardBottom(const rtl::Reference< ::chart::Diagram >& xDiagram ); - static ThreeDLookScheme detectScheme( const rtl::Reference< ::chart::Diagram >& xDiagram ); - static void setScheme( const rtl::Reference< ::chart::Diagram >& xDiagram - , ThreeDLookScheme aScheme ); - //sal_Int32 nRoundedEdges: <0 or >100 -> mixed state //sal_Int32 nObjectLines: 0->no lines; 1->all lines on; other->mixed state diff --git a/chart2/source/model/main/ChartModel_Persistence.cxx b/chart2/source/model/main/ChartModel_Persistence.cxx index a98d090a8958..74ae45dff8c2 100644 --- a/chart2/source/model/main/ChartModel_Persistence.cxx +++ b/chart2/source/model/main/ChartModel_Persistence.cxx @@ -428,7 +428,7 @@ void ChartModel::insertDefaultChart() { xDiagram->setPropertyValue( "RightAngledAxes", uno::Any( true )); xDiagram->setPropertyValue( "D3DScenePerspective", uno::Any( drawing::ProjectionMode_PARALLEL )); - ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme::ThreeDLookScheme_Realistic ); + xDiagram->setScheme( ThreeDLookScheme::ThreeDLookScheme_Realistic ); } //set some new 'defaults' for wall and floor diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx index 30cb2d543990..a4af69b7e7bf 100644 --- a/chart2/source/model/main/Diagram.cxx +++ b/chart2/source/model/main/Diagram.cxx @@ -53,11 +53,13 @@ #include <com/sun/star/chart2/RelativeSize.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> #include <com/sun/star/container/NoSuchElementException.hpp> +#include <com/sun/star/drawing/ShadeMode.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/util/CloseVetoException.hpp> #include <cppuhelper/supportsservice.hxx> #include <comphelper/diagnose_ex.hxx> +#include <editeng/unoprnms.hxx> #include <o3tl/safeint.hxx> #include <rtl/math.hxx> #include <tools/helpers.hxx> @@ -1955,6 +1957,239 @@ void Diagram::setRotationAngle( } } +static bool lcl_isEqual( const drawing::Direction3D& rA, const drawing::Direction3D& rB ) +{ + return ::rtl::math::approxEqual(rA.DirectionX, rB.DirectionX) + && ::rtl::math::approxEqual(rA.DirectionY, rB.DirectionY) + && ::rtl::math::approxEqual(rA.DirectionZ, rB.DirectionZ); +} +static bool lcl_isSimpleScheme( drawing::ShadeMode aShadeMode + , sal_Int32 nRoundedEdges + , sal_Int32 nObjectLines + , const rtl::Reference< Diagram >& xDiagram ) +{ + if(aShadeMode!=drawing::ShadeMode_FLAT) + return false; + if(nRoundedEdges!=0) + return false; + if(nObjectLines==0) + { + rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeByIndex( 0 ) ); + return ChartTypeHelper::noBordersForSimpleScheme( xChartType ); + } + if(nObjectLines!=1) + return false; + return true; +} +static bool lcl_isRealisticScheme( drawing::ShadeMode aShadeMode + , sal_Int32 nRoundedEdges + , sal_Int32 nObjectLines ) +{ + if(aShadeMode!=drawing::ShadeMode_SMOOTH) + return false; + if(nRoundedEdges!=5) + return false; + if(nObjectLines!=0) + 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; + // "D3DSceneLightOn2" / UNO_NAME_3D_SCENE_LIGHTON_2 + rDiagram.getFastPropertyValue( PROP_SCENE_LIGHT_ON_2 ) >>= bIsOn; + if(!bIsOn) + return false; + + rtl::Reference< ChartType > xChartType( rDiagram.getChartTypeByIndex( 0 ) ); + + sal_Int32 nColor = 0; + // "D3DSceneLightColor2" / UNO_NAME_3D_SCENE_LIGHTCOLOR_2 + rDiagram.getFastPropertyValue( PROP_SCENE_LIGHT_COLOR_2 ) >>= nColor; + if( nColor != ::chart::ChartTypeHelper::getDefaultDirectLightColor( !bRealistic, xChartType ) ) + return false; + + sal_Int32 nAmbientColor = 0; + // "D3DSceneAmbientColor" / UNO_NAME_3D_SCENE_AMBIENTCOLOR + rDiagram.getFastPropertyValue( PROP_SCENE_AMBIENT_COLOR ) >>= nAmbientColor; + if( nAmbientColor != ::chart::ChartTypeHelper::getDefaultAmbientLightColor( !bRealistic, xChartType ) ) + return false; + + drawing::Direction3D aDirection(0,0,0); + // "D3DSceneLightDirection2" / UNO_NAME_3D_SCENE_LIGHTDIRECTION_2 + rDiagram.getFastPropertyValue( PROP_SCENE_LIGHT_DIRECTION_2 ) >>= aDirection; + + drawing::Direction3D aDefaultDirection( bRealistic + ? ChartTypeHelper::getDefaultRealisticLightDirection(xChartType) + : ChartTypeHelper::getDefaultSimpleLightDirection(xChartType) ); + + //rotate default 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( + rDiagram.getChartTypeByIndex( 0 ) ) ) + { + ::basegfx::B3DHomMatrix aRotation( lcl_getCompleteRotationMatrix( rDiagram ) ); + BaseGFXHelper::ReduceToRotationMatrix( aRotation ); + ::basegfx::B3DVector aLightVector( BaseGFXHelper::Direction3DToB3DVector( aDefaultDirection ) ); + aLightVector = aRotation*aLightVector; + aDefaultDirection = BaseGFXHelper::B3DVectorToDirection3D( aLightVector ); + } + } + } + + return lcl_isEqual( aDirection, aDefaultDirection ); +} +static bool lcl_isRealisticLightScheme( Diagram& rDiagram ) +{ + return lcl_isLightScheme( rDiagram, true /*bRealistic*/ ); +} +static bool lcl_isSimpleLightScheme( Diagram& rDiagram ) +{ + return lcl_isLightScheme( rDiagram, false /*bRealistic*/ ); +} + +ThreeDLookScheme Diagram::detectScheme() +{ + ThreeDLookScheme aScheme = ThreeDLookScheme::ThreeDLookScheme_Unknown; + + sal_Int32 nRoundedEdges; + sal_Int32 nObjectLines; + ThreeDHelper::getRoundedEdgesAndObjectLines( this, nRoundedEdges, nObjectLines ); + + //get shade mode and light settings: + drawing::ShadeMode aShadeMode( drawing::ShadeMode_SMOOTH ); + try + { + getFastPropertyValue( PROP_SCENE_SHADE_MODE )>>= aShadeMode; // "D3DSceneShadeMode" + } + catch( const uno::Exception & ) + { + DBG_UNHANDLED_EXCEPTION("chart2"); + } + + if( lcl_isSimpleScheme( aShadeMode, nRoundedEdges, nObjectLines, this ) ) + { + if( lcl_isSimpleLightScheme(*this) ) + aScheme = ThreeDLookScheme::ThreeDLookScheme_Simple; + } + else if( lcl_isRealisticScheme( aShadeMode, nRoundedEdges, nObjectLines ) ) + { + if( lcl_isRealisticLightScheme(*this) ) + aScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; + } + + return aScheme; +} + +static void lcl_setRealisticScheme( drawing::ShadeMode& rShadeMode + , sal_Int32& rnRoundedEdges + , sal_Int32& rnObjectLines ) +{ + rShadeMode = drawing::ShadeMode_SMOOTH; + rnRoundedEdges = 5; + rnObjectLines = 0; +} + +static void lcl_setSimpleScheme( drawing::ShadeMode& rShadeMode + , sal_Int32& rnRoundedEdges + , sal_Int32& rnObjectLines + , const rtl::Reference< Diagram >& xDiagram ) +{ + rShadeMode = drawing::ShadeMode_FLAT; + rnRoundedEdges = 0; + + 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 ) + return; + + drawing::ShadeMode aShadeMode; + sal_Int32 nRoundedEdges; + sal_Int32 nObjectLines; + + if( aScheme == ThreeDLookScheme::ThreeDLookScheme_Simple ) + lcl_setSimpleScheme(aShadeMode,nRoundedEdges,nObjectLines,this); + else + lcl_setRealisticScheme(aShadeMode,nRoundedEdges,nObjectLines); + + try + { + ThreeDHelper::setRoundedEdgesAndObjectLines( this, nRoundedEdges, nObjectLines ); + + drawing::ShadeMode aOldShadeMode; + if( ! (getFastPropertyValue( PROP_SCENE_SHADE_MODE)>>=aOldShadeMode) || + aOldShadeMode != aShadeMode ) + { + setFastPropertyValue( PROP_SCENE_SHADE_MODE, uno::Any( aShadeMode )); // "D3DSceneShadeMode" + } + + lcl_setLightsForScheme( *this, aScheme ); + } + catch( const uno::Exception & ) + { + DBG_UNHANDLED_EXCEPTION("chart2"); + } + +} + } // namespace chart extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * diff --git a/chart2/source/tools/ThreeDHelper.cxx b/chart2/source/tools/ThreeDHelper.cxx index fb2bc3122665..aa60a51eb1cb 100644 --- a/chart2/source/tools/ThreeDHelper.cxx +++ b/chart2/source/tools/ThreeDHelper.cxx @@ -135,71 +135,6 @@ void lcl_rotateLights( const ::basegfx::B3DHomMatrix& rLightRottion, const Refer return aCompleteRotation; } -bool lcl_isEqual( const drawing::Direction3D& rA, const drawing::Direction3D& rB ) -{ - return ::rtl::math::approxEqual(rA.DirectionX, rB.DirectionX) - && ::rtl::math::approxEqual(rA.DirectionY, rB.DirectionY) - && ::rtl::math::approxEqual(rA.DirectionZ, rB.DirectionZ); -} - -bool lcl_isLightScheme( const rtl::Reference< Diagram >& xDiagram, bool bRealistic ) -{ - if(!xDiagram.is()) - return false; - - bool bIsOn = false; - xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTON_2 ) >>= bIsOn; - if(!bIsOn) - return false; - - rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeByIndex( 0 ) ); - - sal_Int32 nColor = 0; - xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTCOLOR_2 ) >>= nColor; - if( nColor != ::chart::ChartTypeHelper::getDefaultDirectLightColor( !bRealistic, xChartType ) ) - return false; - - sal_Int32 nAmbientColor = 0; - xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_AMBIENTCOLOR ) >>= nAmbientColor; - if( nAmbientColor != ::chart::ChartTypeHelper::getDefaultAmbientLightColor( !bRealistic, xChartType ) ) - return false; - - drawing::Direction3D aDirection(0,0,0); - xDiagram->getPropertyValue( UNO_NAME_3D_SCENE_LIGHTDIRECTION_2 ) >>= aDirection; - - drawing::Direction3D aDefaultDirection( bRealistic - ? ChartTypeHelper::getDefaultRealisticLightDirection(xChartType) - : ChartTypeHelper::getDefaultSimpleLightDirection(xChartType) ); - - //rotate default light direction when right angled axes are off but supported - { - bool bRightAngledAxes = false; - xDiagram->getPropertyValue( "RightAngledAxes") >>= bRightAngledAxes; - if(!bRightAngledAxes) - { - if( ChartTypeHelper::isSupportingRightAngledAxes( - xDiagram->getChartTypeByIndex( 0 ) ) ) - { - ::basegfx::B3DHomMatrix aRotation( lcl_getCompleteRotationMatrix( xDiagram ) ); - BaseGFXHelper::ReduceToRotationMatrix( aRotation ); - ::basegfx::B3DVector aLightVector( BaseGFXHelper::Direction3DToB3DVector( aDefaultDirection ) ); - aLightVector = aRotation*aLightVector; - aDefaultDirection = BaseGFXHelper::B3DVectorToDirection3D( aLightVector ); - } - } - } - - return lcl_isEqual( aDirection, aDefaultDirection ); -} - -bool lcl_isRealisticLightScheme( const rtl::Reference< Diagram >& xDiagram ) -{ - return lcl_isLightScheme( xDiagram, true /*bRealistic*/ ); -} -bool lcl_isSimpleLightScheme( const rtl::Reference< Diagram >& xDiagram ) -{ - return lcl_isLightScheme( xDiagram, false /*bRealistic*/ ); -} void lcl_setLightsForScheme( const rtl::Reference< Diagram >& xDiagram, const ThreeDLookScheme& rScheme ) { if(!xDiagram.is()) @@ -239,59 +174,6 @@ void lcl_setLightsForScheme( const rtl::Reference< Diagram >& xDiagram, const Th xDiagram->setPropertyValue( UNO_NAME_3D_SCENE_AMBIENTCOLOR, uno::Any( nAmbientColor ) ); } -bool lcl_isRealisticScheme( drawing::ShadeMode aShadeMode - , sal_Int32 nRoundedEdges - , sal_Int32 nObjectLines ) -{ - if(aShadeMode!=drawing::ShadeMode_SMOOTH) - return false; - if(nRoundedEdges!=5) - return false; - if(nObjectLines!=0) - return false; - return true; -} - -bool lcl_isSimpleScheme( drawing::ShadeMode aShadeMode - , sal_Int32 nRoundedEdges - , sal_Int32 nObjectLines - , const rtl::Reference< Diagram >& xDiagram ) -{ - if(aShadeMode!=drawing::ShadeMode_FLAT) - return false; - if(nRoundedEdges!=0) - return false; - if(nObjectLines==0) - { - rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeByIndex( 0 ) ); - return ChartTypeHelper::noBordersForSimpleScheme( xChartType ); - } - if(nObjectLines!=1) - return false; - return true; -} - -void lcl_setRealisticScheme( drawing::ShadeMode& rShadeMode - , sal_Int32& rnRoundedEdges - , sal_Int32& rnObjectLines ) -{ - rShadeMode = drawing::ShadeMode_SMOOTH; - rnRoundedEdges = 5; - rnObjectLines = 0; -} - -void lcl_setSimpleScheme( drawing::ShadeMode& rShadeMode - , sal_Int32& rnRoundedEdges - , sal_Int32& rnObjectLines - , const rtl::Reference< Diagram >& xDiagram ) -{ - rShadeMode = drawing::ShadeMode_FLAT; - rnRoundedEdges = 0; - - rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeByIndex( 0 ) ); - rnObjectLines = ChartTypeHelper::noBordersForSimpleScheme( xChartType ) ? 0 : 1; -} - } //end anonymous namespace drawing::CameraGeometry ThreeDHelper::getDefaultCameraGeometry( bool bPie ) @@ -909,77 +791,6 @@ double ThreeDHelper::PerspectiveToCameraDistance( double fPerspective ) return fRet; } -ThreeDLookScheme ThreeDHelper::detectScheme( const rtl::Reference< Diagram >& xDiagram ) -{ - ThreeDLookScheme aScheme = ThreeDLookScheme::ThreeDLookScheme_Unknown; - - sal_Int32 nRoundedEdges; - sal_Int32 nObjectLines; - ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, nRoundedEdges, nObjectLines ); - - //get shade mode and light settings: - drawing::ShadeMode aShadeMode( drawing::ShadeMode_SMOOTH ); - try - { - if( xDiagram.is() ) - xDiagram->getPropertyValue( "D3DSceneShadeMode" )>>= aShadeMode; - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - - if( lcl_isSimpleScheme( aShadeMode, nRoundedEdges, nObjectLines, xDiagram ) ) - { - if( lcl_isSimpleLightScheme(xDiagram) ) - aScheme = ThreeDLookScheme::ThreeDLookScheme_Simple; - } - else if( lcl_isRealisticScheme( aShadeMode, nRoundedEdges, nObjectLines ) ) - { - if( lcl_isRealisticLightScheme(xDiagram) ) - aScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; - } - - return aScheme; -} - -void ThreeDHelper::setScheme( const rtl::Reference< Diagram >& xDiagram, ThreeDLookScheme aScheme ) -{ - if( aScheme == ThreeDLookScheme::ThreeDLookScheme_Unknown ) - return; - - drawing::ShadeMode aShadeMode; - sal_Int32 nRoundedEdges; - sal_Int32 nObjectLines; - - if( aScheme == ThreeDLookScheme::ThreeDLookScheme_Simple ) - lcl_setSimpleScheme(aShadeMode,nRoundedEdges,nObjectLines,xDiagram); - else - lcl_setRealisticScheme(aShadeMode,nRoundedEdges,nObjectLines); - - try - { - ThreeDHelper::setRoundedEdgesAndObjectLines( xDiagram, nRoundedEdges, nObjectLines ); - - if( xDiagram.is() ) - { - drawing::ShadeMode aOldShadeMode; - if( ! ( (xDiagram->getPropertyValue( "D3DSceneShadeMode" )>>=aOldShadeMode) && - aOldShadeMode == aShadeMode )) - { - xDiagram->setPropertyValue( "D3DSceneShadeMode", uno::Any( aShadeMode )); - } - } - - lcl_setLightsForScheme( xDiagram, aScheme ); - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - -} - void ThreeDHelper::set3DSettingsToDefault( const rtl::Reference< Diagram >& xDiagram ) { if(xDiagram.is()) |