xref: /trunk/main/chart2/source/view/main/PlotterBase.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chartview.hxx"
26 #include "PlotterBase.hxx"
27 #include "PlottingPositionHelper.hxx"
28 #include "ShapeFactory.hxx"
29 #include <rtl/math.hxx>
30 #include <com/sun/star/chart2/DataPointLabel.hpp>
31 #include <tools/debug.hxx>
32 
33 //.............................................................................
34 namespace chart
35 {
36 //.............................................................................
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::chart2;
39 
40 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
43 
PlotterBase(sal_Int32 nDimensionCount)44 PlotterBase::PlotterBase( sal_Int32 nDimensionCount )
45         : m_xLogicTarget(NULL)
46         , m_xFinalTarget(NULL)
47         , m_xShapeFactory(NULL)
48         , m_pShapeFactory(NULL)
49         , m_aCID()
50         , m_nDimension(nDimensionCount)
51         , m_pPosHelper(NULL)
52 {
53 }
54 
initPlotter(const uno::Reference<drawing::XShapes> & xLogicTarget,const uno::Reference<drawing::XShapes> & xFinalTarget,const uno::Reference<lang::XMultiServiceFactory> & xShapeFactory,const rtl::OUString & rCID)55 void PlotterBase::initPlotter(  const uno::Reference< drawing::XShapes >& xLogicTarget
56        , const uno::Reference< drawing::XShapes >& xFinalTarget
57        , const uno::Reference< lang::XMultiServiceFactory >& xShapeFactory
58        , const rtl::OUString& rCID )
59 {
60     DBG_ASSERT(xLogicTarget.is()&&xFinalTarget.is()&&xShapeFactory.is(),"no proper initialization parameters");
61     //is only allowed to be called once
62     m_xLogicTarget  = xLogicTarget;
63     m_xFinalTarget  = xFinalTarget;
64     m_xShapeFactory = xShapeFactory;
65     m_pShapeFactory = new ShapeFactory(xShapeFactory);
66     m_aCID = rCID;
67 }
68 
~PlotterBase()69 PlotterBase::~PlotterBase()
70 {
71     delete m_pShapeFactory;
72 }
73 
setScales(const std::vector<ExplicitScaleData> & rScales,bool bSwapXAndYAxis)74 void PlotterBase::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis )
75 {
76     DBG_ASSERT(m_nDimension<=static_cast<sal_Int32>(rScales.size()),"Dimension of Plotter does not fit two dimension of given scale sequence");
77     m_pPosHelper->setScales( rScales, bSwapXAndYAxis );
78 }
79 
80 
setTransformationSceneToScreen(const drawing::HomogenMatrix & rMatrix)81 void PlotterBase::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
82 {
83     DBG_ASSERT(m_nDimension==2,"Set this transformation only in case of 2D");
84     if(m_nDimension!=2)
85         return;
86     m_pPosHelper->setTransformationSceneToScreen( rMatrix );
87 }
88 
createGroupShape(const uno::Reference<drawing::XShapes> & xTarget,::rtl::OUString rName)89 uno::Reference< drawing::XShapes > PlotterBase::createGroupShape(
90             const uno::Reference< drawing::XShapes >& xTarget
91             , ::rtl::OUString rName )
92 {
93     if(!m_xShapeFactory.is())
94         return NULL;
95 
96     if(m_nDimension==2)
97     {
98         //create and add to target
99         return m_pShapeFactory->createGroup2D( xTarget, rName );
100     }
101     else
102     {
103         //create and added to target
104         return m_pShapeFactory->createGroup3D( xTarget, rName );
105     }
106 }
107 
isValidPosition(const drawing::Position3D & rPos)108 bool PlotterBase::isValidPosition( const drawing::Position3D& rPos )
109 {
110     if( ::rtl::math::isNan(rPos.PositionX) )
111         return false;
112     if( ::rtl::math::isNan(rPos.PositionY) )
113         return false;
114     if( ::rtl::math::isNan(rPos.PositionZ) )
115         return false;
116     if( ::rtl::math::isInf(rPos.PositionX) )
117         return false;
118     if( ::rtl::math::isInf(rPos.PositionY) )
119         return false;
120     if( ::rtl::math::isInf(rPos.PositionZ) )
121         return false;
122     return true;
123 }
124 
125 //.............................................................................
126 } //namespace chart
127 //.............................................................................
128