22#include <com/sun/star/chart/XChartDocument.hpp>
23#include <com/sun/star/chart/XDiagramPositioning.hpp>
24#include <com/sun/star/chart2/XChartDocument.hpp>
25#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
26#include <com/sun/star/chart2/XDiagram.hpp>
27#include <com/sun/star/drawing/Direction3D.hpp>
28#include <com/sun/star/drawing/ProjectionMode.hpp>
29#include <com/sun/star/drawing/ShadeMode.hpp>
30#include <osl/diagnose.h>
36#include <oox/token/namespaces.hxx>
37#include <oox/token/properties.hxx>
38#include <oox/token/tokens.hxx>
54 typedef ModelMap< sal_Int32, AxisModel > AxisMap;
59 explicit AxesSetModel() {}
66 explicit AxesSetConverter(
const ConverterRoot& rParent, AxesSetModel& rModel );
70 void convertFromModel(
71 const Reference< XDiagram >& rxDiagram,
72 View3DModel& rView3DModel,
73 sal_Int32 nAxesSetIdx,
74 bool bSupportsVaryColorsByPoint,
75 bool bUseFixedInnerSize );
78 const OUString& getAutomaticTitle()
const {
return maAutoTitle; }
80 bool is3dChart()
const {
return mb3dChart; }
93AxesSetConverter::AxesSetConverter(
const ConverterRoot& rParent, AxesSetModel& rModel ) :
101ModelRef< AxisModel > lclGetOrCreateAxis(
const AxesSetModel::AxisMap& rFromAxes, sal_Int32 nAxisIdx, sal_Int32 nDefTypeId,
bool bMSO2007Doc )
103 ModelRef< AxisModel > xAxis = rFromAxes.get( nAxisIdx );
105 xAxis.create( nDefTypeId, bMSO2007Doc ).mbDeleted =
true;
109void AxesSetConverter::convertFromModel(
const Reference< XDiagram >& rxDiagram,
110 View3DModel& rView3DModel, sal_Int32 nAxesSetIdx,
111 bool bSupportsVaryColorsByPoint,
bool bUseFixedInnerSize)
114 typedef RefVector< TypeGroupConverter > TypeGroupConvVector;
115 TypeGroupConvVector aTypeGroups;
116 for (
auto const& typeGroup :
mrModel.maTypeGroups)
117 aTypeGroups.push_back( std::make_shared<TypeGroupConverter>( *
this, *typeGroup ) );
119 OSL_ENSURE( !aTypeGroups.empty(),
"AxesSetConverter::convertFromModel - no type groups in axes set" );
120 if( aTypeGroups.empty() )
126 TypeGroupConverter& rFirstTypeGroup = *aTypeGroups.front();
129 if( aTypeGroups.size() == 1 )
130 maAutoTitle = rFirstTypeGroup.getSingleSeriesTitle();
135 Reference< XCoordinateSystem > xCoordSystem;
136 Reference< XCoordinateSystemContainer > xCoordSystemCont( rxDiagram, UNO_QUERY_THROW );
137 Sequence< Reference< XCoordinateSystem > > aCoordSystems = xCoordSystemCont->getCoordinateSystems();
138 if( aCoordSystems.hasElements() )
140 OSL_ENSURE( aCoordSystems.getLength() == 1,
"AxesSetConverter::convertFromModel - too many coordinate systems" );
141 xCoordSystem = aCoordSystems[ 0 ];
142 OSL_ENSURE( xCoordSystem.is(),
"AxesSetConverter::convertFromModel - invalid coordinate system" );
146 xCoordSystem = rFirstTypeGroup.createCoordinateSystem();
147 if( xCoordSystem.is() )
148 xCoordSystemCont->addCoordinateSystem( xCoordSystem );
157 View3DConverter aView3DConv( *
this, rView3DModel );
158 aView3DConv.convertFromModel( rxDiagram, rFirstTypeGroup );
163 if( xCoordSystem.is() )
165 bool bMSO2007Doc = getFilter().isMSO2007Document();
167 ModelRef< AxisModel > xXAxis = lclGetOrCreateAxis(
mrModel.maAxes,
API_X_AXIS, rFirstTypeGroup.getTypeInfo().mbCategoryAxis ? C_TOKEN( catAx ) : C_TOKEN( valAx ), bMSO2007Doc );
168 ModelRef< AxisModel > xYAxis = lclGetOrCreateAxis(
mrModel.maAxes,
API_Y_AXIS, C_TOKEN( valAx ), bMSO2007Doc );
170 AxisConverter aXAxisConv( *
this, *xXAxis );
171 aXAxisConv.convertFromModel(xCoordSystem, aTypeGroups, xYAxis.get(), nAxesSetIdx,
173 AxisConverter aYAxisConv( *
this, *xYAxis );
174 aYAxisConv.convertFromModel(xCoordSystem, aTypeGroups, xXAxis.get(), nAxesSetIdx,
177 if( rFirstTypeGroup.isDeep3dChart() )
179 ModelRef< AxisModel > xZAxis = lclGetOrCreateAxis(
mrModel.maAxes,
API_Z_AXIS, C_TOKEN( serAx ), bMSO2007Doc );
180 AxisConverter aZAxisConv( *
this, *xZAxis );
181 aZAxisConv.convertFromModel(xCoordSystem, aTypeGroups,
nullptr, nAxesSetIdx,
186 for (
auto const& typeGroup : aTypeGroups)
187 typeGroup->convertFromModel( rxDiagram, xCoordSystem, nAxesSetIdx, bSupportsVaryColorsByPoint );
208 namespace cssd = ::com::sun::star::drawing;
211 sal_Int32 nRotationY = 0;
212 sal_Int32 nRotationX = 0;
213 bool bRightAngled =
false;
214 sal_Int32 nAmbientColor = 0;
215 sal_Int32 nLightColor = 0;
222 nRotationX = getLimitedValue< sal_Int32, sal_Int32 >(
mrModel.
monRotationX.value_or( 15 ), 0, 90 ) - 90;
224 bRightAngled =
false;
226 nAmbientColor = 0xB3B3B3;
228 nLightColor = 0x4C4C4C;
235 nRotationX = getLimitedValue< sal_Int32, sal_Int32 >(
mrModel.
monRotationX.value_or( 15 ), -90, 90 );
239 nAmbientColor = 0xCCCCCC;
241 nLightColor = 0x666666;
249 sal_Int32 nPerspective = getLimitedValue< sal_Int32, sal_Int32 >(
mrModel.
mnPerspective / 2, 0, 100 );
251 bool bParallel = bRightAngled || (nPerspective == 0);
252 cssd::ProjectionMode eProjMode = bParallel ? cssd::ProjectionMode_PARALLEL : cssd::ProjectionMode_PERSPECTIVE;
256 aPropSet.
setProperty( PROP_RotationVertical, nRotationY );
257 aPropSet.
setProperty( PROP_RotationHorizontal, nRotationX );
258 aPropSet.
setProperty( PROP_Perspective, nPerspective );
259 aPropSet.
setProperty( PROP_D3DScenePerspective, eProjMode );
262 aPropSet.
setProperty( PROP_D3DSceneShadeMode, cssd::ShadeMode_FLAT );
263 aPropSet.
setProperty( PROP_D3DSceneAmbientColor, nAmbientColor );
264 aPropSet.
setProperty( PROP_D3DSceneLightOn1,
false );
265 aPropSet.
setProperty( PROP_D3DSceneLightOn2,
true );
266 aPropSet.
setProperty( PROP_D3DSceneLightColor2, nLightColor );
267 aPropSet.
setProperty( PROP_D3DSceneLightDirection2, cssd::Direction3D( 0.2, 0.4, 1.0 ) );
289 default: OSL_FAIL(
"WallFloorConverter::convertFromModel - invalid object type" );
315 xDiagram.set(
createInstance(
"com.sun.star.chart2.Diagram" ), UNO_QUERY_THROW );
325 std::vector<sal_Int32>rValAxisIds;
326 std::vector<sal_Int32>rRealValAxisIds;
330 if (atypeGroup->maAxisIds.size() > 1)
333 rRealValAxisIds.push_back(atypeGroup->maAxisIds[1]);
339 OSL_ENSURE( axis->mnAxisId >= 0,
"PlotAreaConverter::convertFromModel - invalid axis identifier" );
340 OSL_ENSURE( !aAxisMap.has( axis->mnAxisId ),
"PlotAreaConverter::convertFromModel - axis identifiers not unique" );
341 if( axis->mnAxisId != -1 )
342 aAxisMap[ axis->mnAxisId ] = axis;
344 if ( axis->mnAxisId != -1 && axis->mnTypeId == C_TOKEN(valAx) )
346 for (
size_t i = 0;
i < rRealValAxisIds.size();
i++)
348 if (axis->mnAxisId == rRealValAxisIds[
i])
351 rValAxisIds.push_back(axis->mnAxisId);
359 AxesSetVector aAxesSets;
360 sal_Int32 nMaxSeriesIdx = -1;
363 if( !typeGroup->maSeries.empty() )
366 AxesSetModel* pAxesSet =
nullptr;
367 for (
auto const& axesSet : aAxesSets)
369 if( axesSet->maTypeGroups.front()->maAxisIds == typeGroup->maAxisIds )
371 pAxesSet = axesSet.
get();
380 pAxesSet = &aAxesSets.create();
382 const std::vector<sal_Int32>& rAxisIds = typeGroup->maAxisIds;
383 if( !rAxisIds.empty() )
384 pAxesSet->maAxes[
API_X_AXIS ] = aAxisMap.get( rAxisIds[ 0 ] );
385 if( rAxisIds.size() >= 2 )
386 pAxesSet->maAxes[
API_Y_AXIS ] = aAxisMap.get( rAxisIds[ 1 ] );
387 if( rAxisIds.size() >= 3 )
388 pAxesSet->maAxes[
API_Z_AXIS ] = aAxisMap.get( rAxisIds[ 2 ] );
392 pAxesSet->maTypeGroups.push_back( typeGroup );
395 for (
auto const& elemSeries : typeGroup->maSeries)
396 nMaxSeriesIdx = ::std::max( nMaxSeriesIdx, elemSeries->mnIndex );
408 sal_Int32 nStartAxesSetIdx = bIsCombinedChart ? ((rValAxisIds.size() > 1 && aAxesSets.size() > 0 && aAxesSets[0]->maAxes.count(
API_Y_AXIS )
409 && aAxesSets[0]->maAxes[
API_Y_AXIS ]->mnAxisId != rValAxisIds[0] ) ? 1 : 0)
411 sal_Int32 nAxesSetIdx = nStartAxesSetIdx;
413 bool bUseFixedInnerSize =
false;
417 for (
auto const& axesSet : aAxesSets)
419 AxesSetConverter aAxesSetConv(*
this, *axesSet);
420 aAxesSetConv.convertFromModel(xDiagram, rView3DModel, nAxesSetIdx,
421 bSupportsVaryColorsByPoint, bUseFixedInnerSize);
422 if(nAxesSetIdx == nStartAxesSetIdx)
433 nAxesSetIdx = 1 - nAxesSetIdx;
454 awt::Rectangle aDiagramRect;
460 namespace cssc = ::com::sun::star::chart;
468 xPositioning->setDiagramPositionExcludingAxes( aDiagramRect );
471 xPositioning->setDiagramPositionIncludingAxes( aDiagramRect );
474 OSL_FAIL(
"PlotAreaConverter::convertPositionFromModel - unknown positioning target" );
A wrapper for a UNO property set.
void set(const css::uno::Reference< css::beans::XPropertySet > &rxPropSet)
Sets the passed UNO property set and releases the old UNO property set.
bool is() const
Returns true, if the contained XPropertySet interface is valid.
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Puts the passed value into the property set.
value_type get(sal_Int32 nIndex) const
Returns a reference to the object with the passed index, or 0 on error.
bool isMSO2007Document() const
Base class of all converter classes.
::oox::core::XmlFilterBase & getFilter() const
Returns the filter object of the imported/exported document.
css::uno::Reference< css::chart2::XChartDocument > const & getChartDocument() const
Returns the API chart document model.
ObjectFormatter & getFormatter() const
Returns the object formatter.
css::uno::Reference< css::uno::XInterface > createInstance(const OUString &rServiceName) const
Creates an instance for the passed service name, using the process service factory.
Converts the data table element and properties from OOXML model to the internal chart implementation.
void convertFromModel(css::uno::Reference< css::chart2::XDiagram > const &rxDiagram)
Converts the OOXML data table model to a chart2 diagram.
A layout converter calculates positions and sizes for various chart objects.
bool calcAbsRectangle(css::awt::Rectangle &orRect) const
Tries to calculate the absolute position and size from the contained OOXML layout model.
ModelType & getOrCreate()
void convertFromModel(View3DModel &rView3DModel)
Converts the OOXML plot area model to a chart2 diagram.
PlotAreaConverter(const ConverterRoot &rParent, PlotAreaModel &rModel)
virtual ~PlotAreaConverter() override
void convertPositionFromModel()
Converts the manual plot area position and size, if set.
void convertPieRotation(PropertySet &rPropSet, sal_Int32 nOoxAngle) const
Sets the passed OOXML pie rotation at the passed property set.
const TypeGroupInfo & getTypeInfo() const
Returns the type info struct that describes this chart type group.
void convertFromModel(const css::uno::Reference< css::chart2::XDiagram > &rxDiagram, TypeGroupConverter const &rTypeGroup)
Converts the OOXML plot area model to a chart2 diagram.
virtual ~View3DConverter() override
virtual ~WallFloorConverter() override
void convertFromModel(const css::uno::Reference< css::chart2::XDiagram > &rxDiagram, ObjectType eObjType)
Converts the OOXML wall/floor model to a chart2 diagram.
WallFloorConverter(const ConverterRoot &rParent, WallFloorModel &rModel)
std::enable_if< std::is_signed< T >::value, T >::type NormAngle180(T angle)
const sal_Int32 API_Y_AXIS
@ TYPECATEGORY_PIE
Radar charts (linear or filled).
const sal_Int32 API_X_AXIS
ObjectType
Enumerates different object types for specific automatic formatting behaviour.
@ OBJECTTYPE_FLOOR
Background and side wall in 3D charts.
@ OBJECTTYPE_WALL
Plot area containing axes and data series in 3D charts.
@ OBJECTTYPE_PLOTAREA2D
Legend.
const sal_Int32 API_Z_AXIS
AxisMap maAxes
All type groups containing data series.
TypeGroupVector maTypeGroups
sal_Int32 mnTarget
Mode for height.
DataTableRef mxDataTable
Layout/position of the plot area.
TypeGroupVector maTypeGroups
ShapeRef mxShapeProp
All axes contained in the chart.
LayoutRef mxLayout
Plot area frame formatting.
AxisVector maAxes
All chart type groups contained in the chart.
TypeCategory meTypeCategory
Unique chart type identifier.
std::optional< sal_Int32 > monRotationY
Horizontal rotation in degrees.
bool mbRightAngled
Eye distance to the 3D objects.
sal_Int32 mnPerspective
Depth of the 3D view, relative to chart width.
std::optional< sal_Int32 > monRotationX
Height of the 3D view, relative to chart width.
PictureOptionsRef mxPicOptions
Wall/floor frame formatting.
constexpr OUStringLiteral PROP_RightAngledAxes