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_slideshow.hxx"
26 
27 // must be first
28 #include <canvas/debug.hxx>
29 #include <expressionnodefactory.hxx>
30 
31 #include <canvas/verbosetrace.hxx>
32 
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <basegfx/point/b2dpoint.hxx>
35 
36 #include <functional>
37 #include <algorithm>
38 
39 
40 /* Implementation of ExpressionNodeFactory class */
41 
42 namespace slideshow
43 {
44     namespace internal
45     {
46         namespace
47         {
48             class ConstantValueExpression : public ExpressionNode
49             {
50             public:
ConstantValueExpression(double rValue)51                 ConstantValueExpression( double rValue ) :
52                     maValue( rValue )
53                 {
54                 }
55 
operator ()(double) const56                 virtual double operator()( double /*t*/ ) const
57                 {
58                     return maValue;
59                 }
60 
isConstant() const61                 virtual bool isConstant() const
62                 {
63                     return true;
64                 }
65 
66             private:
67                 double	maValue;
68             };
69 
70             class TValueExpression : public ExpressionNode
71             {
72             public:
TValueExpression()73                 TValueExpression()
74                 {
75                 }
76 
operator ()(double t) const77                 virtual double operator()( double t ) const
78                 {
79                     return t;
80                 }
81 
isConstant() const82                 virtual bool isConstant() const
83                 {
84                     return false;
85                 }
86             };
87 
88             /** Base class for following binary functions (*+-/)
89 
90 				Does not pay off to have all this as a template, since
91 				we'd have to hold the functor as a member (+33% object
92 				size).
93              */
94             class BinaryExpressionBase : public ExpressionNode
95             {
96             public:
BinaryExpressionBase(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)97                 BinaryExpressionBase( const ExpressionNodeSharedPtr&	rFirstArg,
98                                       const ExpressionNodeSharedPtr&	rSecondArg ) :
99                     mpFirstArg( rFirstArg ),
100                     mpSecondArg( rSecondArg )
101                 {
102                 }
103 
isConstant() const104                 virtual bool isConstant() const
105                 {
106                     return
107                         mpFirstArg->isConstant() &&
108                         mpSecondArg->isConstant();
109                 }
110 
111             protected:
112                 ExpressionNodeSharedPtr	mpFirstArg;
113                 ExpressionNodeSharedPtr mpSecondArg;
114             };
115 
116             class PlusExpression : public BinaryExpressionBase
117             {
118             public:
PlusExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)119                 PlusExpression( const ExpressionNodeSharedPtr&	rFirstArg,
120                                 const ExpressionNodeSharedPtr&	rSecondArg ) :
121                     BinaryExpressionBase( rFirstArg, rSecondArg )
122                 {
123                 }
124 
operator ()(double t) const125                 virtual double operator()( double t ) const
126                 {
127                     return (*mpFirstArg)(t) + (*mpSecondArg)(t);
128                 }
129             };
130 
131             class MinusExpression : public BinaryExpressionBase
132             {
133             public:
MinusExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)134                 MinusExpression( const ExpressionNodeSharedPtr&	rFirstArg,
135                                  const ExpressionNodeSharedPtr&	rSecondArg ) :
136                     BinaryExpressionBase( rFirstArg, rSecondArg )
137                 {
138                 }
139 
operator ()(double t) const140                 virtual double operator()( double t ) const
141                 {
142                     return (*mpFirstArg)(t) - (*mpSecondArg)(t);
143                 }
144             };
145 
146             class MultipliesExpression : public BinaryExpressionBase
147             {
148             public:
MultipliesExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)149                 MultipliesExpression( const ExpressionNodeSharedPtr&	rFirstArg,
150                                       const ExpressionNodeSharedPtr&	rSecondArg ) :
151                     BinaryExpressionBase( rFirstArg, rSecondArg )
152                 {
153                 }
154 
operator ()(double t) const155                 virtual double operator()( double t ) const
156                 {
157                     return (*mpFirstArg)(t) * (*mpSecondArg)(t);
158                 }
159             };
160 
161             class DividesExpression : public BinaryExpressionBase
162             {
163             public:
DividesExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)164                 DividesExpression( const ExpressionNodeSharedPtr&	rFirstArg,
165                                    const ExpressionNodeSharedPtr&	rSecondArg ) :
166                     BinaryExpressionBase( rFirstArg, rSecondArg )
167                 {
168                 }
169 
operator ()(double t) const170                 virtual double operator()( double t ) const
171                 {
172                     return (*mpFirstArg)(t) / (*mpSecondArg)(t);
173                 }
174             };
175 
176             class ComposedExpression : public BinaryExpressionBase
177             {
178             public:
ComposedExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)179                 ComposedExpression( const ExpressionNodeSharedPtr&	rFirstArg,
180                                     const ExpressionNodeSharedPtr&	rSecondArg ) :
181                     BinaryExpressionBase( rFirstArg, rSecondArg )
182                 {
183                 }
184 
operator ()(double t) const185                 virtual double operator()( double t ) const
186                 {
187                     return (*mpFirstArg)( (*mpSecondArg)(t) );
188                 }
189             };
190 
191             class MinExpression : public BinaryExpressionBase
192             {
193             public:
MinExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)194                 MinExpression( const ExpressionNodeSharedPtr&	rFirstArg,
195                                const ExpressionNodeSharedPtr&	rSecondArg ) :
196                     BinaryExpressionBase( rFirstArg, rSecondArg )
197                 {
198                 }
199 
operator ()(double t) const200                 virtual double operator()( double t ) const
201                 {
202                     return ::std::min( (*mpFirstArg)(t), (*mpSecondArg)(t) );
203                 }
204             };
205 
206             class MaxExpression : public BinaryExpressionBase
207             {
208             public:
MaxExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)209                 MaxExpression( const ExpressionNodeSharedPtr&	rFirstArg,
210                                const ExpressionNodeSharedPtr&	rSecondArg ) :
211                     BinaryExpressionBase( rFirstArg, rSecondArg )
212                 {
213                 }
214 
operator ()(double t) const215                 virtual double operator()( double t ) const
216                 {
217                     return ::std::max( (*mpFirstArg)(t), (*mpSecondArg)(t) );
218                 }
219             };
220         }
221 
createConstantValueExpression(double rConstantValue)222         ExpressionNodeSharedPtr ExpressionNodeFactory::createConstantValueExpression( double rConstantValue )
223         {
224             return ExpressionNodeSharedPtr( new ConstantValueExpression(rConstantValue) );
225         }
226 
createValueTExpression()227         ExpressionNodeSharedPtr ExpressionNodeFactory::createValueTExpression()
228         {
229             return ExpressionNodeSharedPtr( new TValueExpression() );
230         }
231 
createPlusExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)232         ExpressionNodeSharedPtr ExpressionNodeFactory::createPlusExpression( const ExpressionNodeSharedPtr&	rLHS,
233                                                                              const ExpressionNodeSharedPtr&	rRHS )
234         {
235             return ExpressionNodeSharedPtr( new PlusExpression(rLHS, rRHS) );
236         }
237 
createMinusExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)238         ExpressionNodeSharedPtr ExpressionNodeFactory::createMinusExpression( const ExpressionNodeSharedPtr&	rLHS,
239                                                                               const ExpressionNodeSharedPtr&	rRHS )
240         {
241             return ExpressionNodeSharedPtr( new MinusExpression(rLHS, rRHS) );
242         }
243 
createMultipliesExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)244         ExpressionNodeSharedPtr ExpressionNodeFactory::createMultipliesExpression( const ExpressionNodeSharedPtr&	rLHS,
245                                                                                    const ExpressionNodeSharedPtr&	rRHS )
246         {
247             return ExpressionNodeSharedPtr( new MultipliesExpression(rLHS, rRHS) );
248         }
249 
createDividesExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)250         ExpressionNodeSharedPtr ExpressionNodeFactory::createDividesExpression( const ExpressionNodeSharedPtr&	rLHS,
251                                                                                 const ExpressionNodeSharedPtr&	rRHS )
252         {
253             return ExpressionNodeSharedPtr( new DividesExpression(rLHS, rRHS) );
254         }
255 
createComposedExpression(const ExpressionNodeSharedPtr & rOuterFunction,const ExpressionNodeSharedPtr & rInnerFunction)256         ExpressionNodeSharedPtr ExpressionNodeFactory::createComposedExpression	 ( const ExpressionNodeSharedPtr&	rOuterFunction,
257                                                                                    const ExpressionNodeSharedPtr&	rInnerFunction )
258         {
259             return ExpressionNodeSharedPtr( new ComposedExpression(rOuterFunction, rInnerFunction) );
260         }
261 
createMinExpression(const ExpressionNodeSharedPtr & rOuterFunction,const ExpressionNodeSharedPtr & rInnerFunction)262         ExpressionNodeSharedPtr ExpressionNodeFactory::createMinExpression	 ( const ExpressionNodeSharedPtr&	rOuterFunction,
263                                                                                const ExpressionNodeSharedPtr&	rInnerFunction )
264         {
265             return ExpressionNodeSharedPtr( new MinExpression(rOuterFunction, rInnerFunction) );
266         }
267 
createMaxExpression(const ExpressionNodeSharedPtr & rOuterFunction,const ExpressionNodeSharedPtr & rInnerFunction)268         ExpressionNodeSharedPtr ExpressionNodeFactory::createMaxExpression	 ( const ExpressionNodeSharedPtr&	rOuterFunction,
269                                                                                const ExpressionNodeSharedPtr&	rInnerFunction )
270         {
271             return ExpressionNodeSharedPtr( new MaxExpression(rOuterFunction, rInnerFunction) );
272         }
273 
274     }
275 }
276