1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "VLegendSymbolFactory.hxx"
27cdf0e10cSrcweir #include "macros.hxx"
28cdf0e10cSrcweir #include "PropertyMapper.hxx"
29cdf0e10cSrcweir #include "ShapeFactory.hxx"
30cdf0e10cSrcweir #include "ObjectIdentifier.hxx"
31cdf0e10cSrcweir #include <com/sun/star/drawing/LineStyle.hpp>
32cdf0e10cSrcweir #include <com/sun/star/chart2/Symbol.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // header for define DBG_ASSERT
35cdf0e10cSrcweir #include <tools/debug.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
39cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace
43cdf0e10cSrcweir {
lcl_setPropetiesToShape(const Reference<beans::XPropertySet> & xProp,const Reference<drawing::XShape> & xShape,::chart::VLegendSymbolFactory::tPropertyType ePropertyType)44cdf0e10cSrcweir void lcl_setPropetiesToShape(
45cdf0e10cSrcweir     const Reference< beans::XPropertySet > & xProp,
46cdf0e10cSrcweir     const Reference< drawing::XShape > & xShape,
47cdf0e10cSrcweir     ::chart::VLegendSymbolFactory::tPropertyType ePropertyType )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
50cdf0e10cSrcweir     const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
51cdf0e10cSrcweir     const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
52cdf0e10cSrcweir     const ::chart::tPropertyNameMap & aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
53cdf0e10cSrcweir     const ::chart::tPropertyNameMap & aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
56cdf0e10cSrcweir     if( xProp.is() && xShapeProp.is() )
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         ::chart::tPropertyNameValueMap aValueMap;
59cdf0e10cSrcweir         switch( ePropertyType )
60cdf0e10cSrcweir         {
61cdf0e10cSrcweir             case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES:
62cdf0e10cSrcweir                 ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
63cdf0e10cSrcweir                 break;
64cdf0e10cSrcweir             case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES:
65cdf0e10cSrcweir                 ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
66cdf0e10cSrcweir                 break;
67cdf0e10cSrcweir             case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE:
68cdf0e10cSrcweir                 ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
69cdf0e10cSrcweir                 break;
70cdf0e10cSrcweir             case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL:
71cdf0e10cSrcweir                 ::chart::PropertyMapper::getValueMap( aValueMap, aFillNameMap, xProp );
72cdf0e10cSrcweir                 break;
73cdf0e10cSrcweir             case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE:
74cdf0e10cSrcweir                 ::chart::PropertyMapper::getValueMap( aValueMap, aFillLineNameMap, xProp );
75cdf0e10cSrcweir                 break;
76cdf0e10cSrcweir         }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         ::chart::tNameSequence aPropNames;
79cdf0e10cSrcweir         ::chart::tAnySequence aPropValues;
80cdf0e10cSrcweir         ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames, aPropValues, aValueMap );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(aPropValues,aPropNames,C2U("LineWidth"));
83cdf0e10cSrcweir         sal_Int32 nLineWidth = 0;
84cdf0e10cSrcweir         if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
85cdf0e10cSrcweir         {
86cdf0e10cSrcweir             const sal_Int32 nMaxLineWidthForLegend = 50;/*1/100 mm*///todo: make this dependent from legend entry height
87cdf0e10cSrcweir             if( nLineWidth>nMaxLineWidthForLegend )
88cdf0e10cSrcweir                 *pLineWidthAny = uno::makeAny( nMaxLineWidthForLegend );
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir } // anonymous namespace
96cdf0e10cSrcweir 
97cdf0e10cSrcweir namespace chart
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 
createSymbol(const awt::Size & rEntryKeyAspectRatio,const Reference<drawing::XShapes> xSymbolContainer,LegendSymbolStyle eStyle,const Reference<lang::XMultiServiceFactory> & xShapeFactory,const Reference<beans::XPropertySet> & xLegendEntryProperties,tPropertyType ePropertyType,const uno::Any & rExplicitSymbol)100cdf0e10cSrcweir Reference< drawing::XShape > VLegendSymbolFactory::createSymbol(
101cdf0e10cSrcweir     const awt::Size& rEntryKeyAspectRatio,
102cdf0e10cSrcweir     const Reference< drawing::XShapes > xSymbolContainer,
103cdf0e10cSrcweir     LegendSymbolStyle eStyle,
104cdf0e10cSrcweir     const Reference< lang::XMultiServiceFactory > & xShapeFactory,
105cdf0e10cSrcweir     const Reference< beans::XPropertySet > & xLegendEntryProperties,
106cdf0e10cSrcweir     tPropertyType ePropertyType, const uno::Any& rExplicitSymbol )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     Reference< drawing::XShape > xResult;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     if( ! (xSymbolContainer.is() && xShapeFactory.is()))
111cdf0e10cSrcweir         return xResult;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     xResult.set( xShapeFactory->createInstance(
114cdf0e10cSrcweir                      C2U( "com.sun.star.drawing.GroupShape" )), uno::UNO_QUERY );
115cdf0e10cSrcweir     xSymbolContainer->add( xResult );
116cdf0e10cSrcweir     Reference< drawing::XShapes > xResultGroup( xResult, uno::UNO_QUERY );
117cdf0e10cSrcweir     if( ! xResultGroup.is())
118cdf0e10cSrcweir         return xResult;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     // add an invisible square box to maintain aspect ratio
121cdf0e10cSrcweir     Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle(
122cdf0e10cSrcweir                 xResultGroup, rEntryKeyAspectRatio  ));
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     // create symbol
125cdf0e10cSrcweir     try
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         if( eStyle == LegendSymbolStyle_LINE )
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             Reference< drawing::XShape > xLine( xShapeFactory->createInstance(
130cdf0e10cSrcweir                     C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY );
131cdf0e10cSrcweir             if( xLine.is())
132cdf0e10cSrcweir             {
133cdf0e10cSrcweir                 xResultGroup->add( xLine );
134cdf0e10cSrcweir                 xLine->setSize(  awt::Size( rEntryKeyAspectRatio.Width, 0 ));
135cdf0e10cSrcweir                 xLine->setPosition( awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
136cdf0e10cSrcweir 
137cdf0e10cSrcweir                 lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType );
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir             Reference< drawing::XShape > xSymbol;
141cdf0e10cSrcweir             const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
142cdf0e10cSrcweir             chart2::Symbol aSymbol;
143cdf0e10cSrcweir             if( rExplicitSymbol >>= aSymbol )
144cdf0e10cSrcweir             {
145cdf0e10cSrcweir                 drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
146cdf0e10cSrcweir                 drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2, rEntryKeyAspectRatio.Height/2, 0 );
147cdf0e10cSrcweir                 ShapeFactory aFactory( xShapeFactory );
148cdf0e10cSrcweir                 if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
149cdf0e10cSrcweir                 {
150cdf0e10cSrcweir                     // take series color as fill color
151cdf0e10cSrcweir                     xLegendEntryProperties->getPropertyValue( C2U("Color")) >>= aSymbol.FillColor;
152cdf0e10cSrcweir                     // border of symbols always same as fill color
153cdf0e10cSrcweir                     aSymbol.BorderColor = aSymbol.FillColor;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir                     xSymbol.set( aFactory.createSymbol2D(
156cdf0e10cSrcweir                                      xResultGroup,
157cdf0e10cSrcweir                                      aPos,
158cdf0e10cSrcweir                                      aSymbolSize,
159cdf0e10cSrcweir                                      aSymbol.StandardSymbol,
160cdf0e10cSrcweir                                      aSymbol.BorderColor,
161cdf0e10cSrcweir                                      aSymbol.FillColor ));
162cdf0e10cSrcweir                 }
163cdf0e10cSrcweir                 else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
164cdf0e10cSrcweir                 {
165cdf0e10cSrcweir                     xSymbol.set( aFactory.createGraphic2D(
166cdf0e10cSrcweir                                      xResultGroup,
167cdf0e10cSrcweir                                      aPos,
168cdf0e10cSrcweir                                      aSymbolSize,
169cdf0e10cSrcweir                                      aSymbol.Graphic ));
170cdf0e10cSrcweir                 }
171cdf0e10cSrcweir                 else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
172cdf0e10cSrcweir                 {
173cdf0e10cSrcweir                     DBG_ERROR("the given parameter is not allowed to contain an automatic symbol style");
174cdf0e10cSrcweir                 }
175cdf0e10cSrcweir             }
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir         else if( eStyle == LegendSymbolStyle_CIRCLE )
178cdf0e10cSrcweir         {
179cdf0e10cSrcweir             Reference< drawing::XShape > xShape( xShapeFactory->createInstance(
180cdf0e10cSrcweir                 C2U( "com.sun.star.drawing.EllipseShape" )), uno::UNO_QUERY );
181cdf0e10cSrcweir             if( xShape.is() )
182cdf0e10cSrcweir             {
183cdf0e10cSrcweir                 xResultGroup->add( xShape );
184cdf0e10cSrcweir                 sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
185cdf0e10cSrcweir                 xShape->setSize( awt::Size( nSize, nSize ) );
186cdf0e10cSrcweir                 xShape->setPosition( awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ) );
187cdf0e10cSrcweir                 lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
188cdf0e10cSrcweir             }
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir         else // eStyle == LegendSymbolStyle_BOX
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             Reference< drawing::XShape > xShape( xShapeFactory->createInstance(
193cdf0e10cSrcweir                 C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY );
194cdf0e10cSrcweir             if( xShape.is() )
195cdf0e10cSrcweir             {
196cdf0e10cSrcweir                 xResultGroup->add( xShape );
197cdf0e10cSrcweir                 xShape->setSize( rEntryKeyAspectRatio );
198cdf0e10cSrcweir                 xShape->setPosition( awt::Point( 0, 0 ) );
199cdf0e10cSrcweir                 lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
200cdf0e10cSrcweir             }
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir     catch( uno::Exception & ex )
204cdf0e10cSrcweir     {
205cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     return xResult;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir } //  namespace chart
212