Update ooo320-m1
[ooovba.git] / chart2 / source / view / axes / VPolarAngleAxis.cxx
blobeb8b768960d5629d8b2064712d0a27da5436a742
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VPolarAngleAxis.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include <basegfx/numeric/ftools.hxx>
35 #include "VPolarAngleAxis.hxx"
36 #include "VPolarGrid.hxx"
37 #include "ShapeFactory.hxx"
38 #include "macros.hxx"
39 #include "chartview/NumberFormatterWrapper.hxx"
40 #include "PolarLabelPositionHelper.hxx"
41 #include <tools/color.hxx>
43 #include <memory>
45 //.............................................................................
46 namespace chart
48 //.............................................................................
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::chart2;
51 using namespace ::rtl::math;
53 VPolarAngleAxis::VPolarAngleAxis( const AxisProperties& rAxisProperties
54 , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier
55 , sal_Int32 nDimensionCount )
56 : VPolarAxis( rAxisProperties, xNumberFormatsSupplier, 0/*nDimensionIndex*/, nDimensionCount )
60 VPolarAngleAxis::~VPolarAngleAxis()
62 delete m_pPosHelper;
63 m_pPosHelper = NULL;
66 bool VPolarAngleAxis::createTextShapes_ForAngleAxis(
67 const uno::Reference< drawing::XShapes >& xTarget
68 , TickIter& rTickIter
69 , AxisLabelProperties& rAxisLabelProperties
70 , double fLogicRadius
71 , double fLogicZ )
73 sal_Int32 nDimensionCount = 2;
74 ShapeFactory aShapeFactory(m_xShapeFactory);
76 FixedNumberFormatter aFixedNumberFormatter(
77 m_xNumberFormatsSupplier, rAxisLabelProperties.nNumberFormatKey );
79 //------------------------------------------------
80 //prepare text properties for multipropertyset-interface of shape
81 tNameSequence aPropNames;
82 tAnySequence aPropValues;
84 uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
85 PropertyMapper::getTextLabelMultiPropertyLists( xProps, aPropNames, aPropValues, false );
86 LabelPositionHelper::doDynamicFontResize( aPropValues, aPropNames, xProps
87 , rAxisLabelProperties.m_aFontReferenceSize );
89 uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,C2U("CharColor"));
90 sal_Int32 nColor = Color( COL_AUTO ).GetColor();
91 if(pColorAny)
92 *pColorAny >>= nColor;
94 const uno::Sequence< rtl::OUString >* pLabels = m_bUseTextLabels? &m_aTextLabels : 0;
96 //------------------------------------------------
98 //TickInfo* pLastVisibleNeighbourTickInfo = NULL;
99 sal_Int32 nTick = 0;
101 for( TickInfo* pTickInfo = rTickIter.firstInfo()
102 ; pTickInfo
103 ; pTickInfo = rTickIter.nextInfo(), nTick++ )
105 //don't create labels which does not fit into the rythm
106 if( nTick%rAxisLabelProperties.nRhythm != 0)
107 continue;
109 //don't create labels for invisible ticks
110 if( !pTickInfo->bPaintIt )
111 continue;
113 //if NO OVERLAP -> don't create labels where the
114 //anchor position is the same as for the last label
115 //@todo
117 if(!pTickInfo->xTextShape.is())
119 //create single label
120 bool bHasExtraColor=false;
121 sal_Int32 nExtraColor=0;
123 rtl::OUString aLabel;
124 if(pLabels)
126 sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->fUnscaledTickValue) - 1; //first category (index 0) matches with real number 1.0
127 if( nIndex>=0 && nIndex<pLabels->getLength() )
128 aLabel = (*pLabels)[nIndex];
130 else
131 aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->fUnscaledTickValue, nExtraColor, bHasExtraColor );
133 if(pColorAny)
134 *pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor);
136 double fLogicAngle = pTickInfo->fUnscaledTickValue;
138 LabelAlignment eLabelAlignment(LABEL_ALIGN_CENTER);
139 PolarLabelPositionHelper aPolarLabelPositionHelper(m_pPosHelper,nDimensionCount,xTarget,&aShapeFactory);
140 sal_Int32 nScreenValueOffsetInRadiusDirection = m_aAxisLabelProperties.m_aMaximumSpaceForLabels.Height/15;
141 awt::Point aAnchorScreenPosition2D( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
142 eLabelAlignment, fLogicAngle, fLogicRadius, fLogicZ, nScreenValueOffsetInRadiusDirection ));
143 LabelPositionHelper::changeTextAdjustment( aPropValues, aPropNames, eLabelAlignment );
145 // #i78696# use mathematically correct rotation now
146 const double fRotationAnglePi(rAxisLabelProperties.fRotationAngleDegree * (F_PI / -180.0));
148 uno::Any aATransformation = ShapeFactory::makeTransformation( aAnchorScreenPosition2D, fRotationAnglePi );
149 rtl::OUString aStackedLabel = ShapeFactory::getStackedString( aLabel, rAxisLabelProperties.bStackCharacters );
151 pTickInfo->xTextShape = aShapeFactory.createText( xTarget, aStackedLabel, aPropNames, aPropValues, aATransformation );
154 //if NO OVERLAP -> remove overlapping shapes
155 //@todo
157 return true;
160 void SAL_CALL VPolarAngleAxis::createMaximumLabels()
162 if( !prepareShapeCreation() )
163 return;
165 createLabels();
168 void SAL_CALL VPolarAngleAxis::updatePositions()
170 //todo: really only update the positions
172 if( !prepareShapeCreation() )
173 return;
175 createLabels();
178 void SAL_CALL VPolarAngleAxis::createLabels()
180 if( !prepareShapeCreation() )
181 return;
183 double fLogicRadius = m_pPosHelper->getOuterLogicRadius();
184 double fLogicZ = -0.5;//as defined
186 if( m_aAxisProperties.m_bDisplayLabels )
188 //-----------------------------------------
189 //get the transformed screen values for all tickmarks in aAllTickInfos
190 std::auto_ptr< TickmarkHelper > apTickmarkHelper( this->createTickmarkHelper() );
192 //create tick mark text shapes
193 //@todo: iterate through all tick depth wich should be labeled
195 TickIter aTickIter( m_aAllTickInfos, m_aIncrement, 0, 0 );
196 this->updateUnscaledValuesAtTicks( aTickIter );
198 TickIter aRemoveIter( m_aAllTickInfos, m_aIncrement, 0, 0 );
199 removeTextShapesFromTicks( aRemoveIter, m_xTextTarget );
201 AxisLabelProperties aAxisLabelProperties( m_aAxisLabelProperties );
202 aAxisLabelProperties.bOverlapAllowed = true;
203 while( !createTextShapes_ForAngleAxis( m_xTextTarget, aTickIter
204 , aAxisLabelProperties
205 , fLogicRadius, fLogicZ
210 //no staggering for polar angle axis
214 void SAL_CALL VPolarAngleAxis::createShapes()
216 if( !prepareShapeCreation() )
217 return;
219 double fLogicRadius = m_pPosHelper->getOuterLogicRadius();
220 double fLogicZ = -0.5;//as defined
222 //-----------------------------------------
223 //create axis main lines
224 drawing::PointSequenceSequence aPoints(1);
225 VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, m_aAllTickInfos, m_aIncrement, m_aScale, m_pPosHelper, fLogicRadius, fLogicZ );
226 uno::Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D(
227 m_xGroupShape_Shapes, aPoints, &m_aAxisProperties.m_aLineProperties );
228 //because of this name this line will be used for marking the axis
229 m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
231 //-----------------------------------------
232 //create labels
233 createLabels();
236 //.............................................................................
237 } //namespace chart
238 //.............................................................................