1*70f497fbSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*70f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*70f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*70f497fbSAndrew Rist * distributed with this work for additional information 6*70f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*70f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*70f497fbSAndrew Rist * "License"); you may not use this file except in compliance 9*70f497fbSAndrew Rist * with the License. You may obtain a copy of the License at 10*70f497fbSAndrew Rist * 11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*70f497fbSAndrew Rist * 13*70f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*70f497fbSAndrew Rist * software distributed under the License is distributed on an 15*70f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*70f497fbSAndrew Rist * KIND, either express or implied. See the License for the 17*70f497fbSAndrew Rist * specific language governing permissions and limitations 18*70f497fbSAndrew Rist * under the License. 19*70f497fbSAndrew Rist * 20*70f497fbSAndrew Rist *************************************************************/ 21*70f497fbSAndrew Rist 22*70f497fbSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // must be first 28cdf0e10cSrcweir #include <canvas/debug.hxx> 29cdf0e10cSrcweir #include <expressionnodefactory.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 34cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <functional> 37cdf0e10cSrcweir #include <algorithm> 38cdf0e10cSrcweir 39cdf0e10cSrcweir 40cdf0e10cSrcweir /* Implementation of ExpressionNodeFactory class */ 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace slideshow 43cdf0e10cSrcweir { 44cdf0e10cSrcweir namespace internal 45cdf0e10cSrcweir { 46cdf0e10cSrcweir namespace 47cdf0e10cSrcweir { 48cdf0e10cSrcweir class ConstantValueExpression : public ExpressionNode 49cdf0e10cSrcweir { 50cdf0e10cSrcweir public: ConstantValueExpression(double rValue)51cdf0e10cSrcweir ConstantValueExpression( double rValue ) : 52cdf0e10cSrcweir maValue( rValue ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir operator ()(double) const56cdf0e10cSrcweir virtual double operator()( double /*t*/ ) const 57cdf0e10cSrcweir { 58cdf0e10cSrcweir return maValue; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir isConstant() const61cdf0e10cSrcweir virtual bool isConstant() const 62cdf0e10cSrcweir { 63cdf0e10cSrcweir return true; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir private: 67cdf0e10cSrcweir double maValue; 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir 70cdf0e10cSrcweir class TValueExpression : public ExpressionNode 71cdf0e10cSrcweir { 72cdf0e10cSrcweir public: TValueExpression()73cdf0e10cSrcweir TValueExpression() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir operator ()(double t) const77cdf0e10cSrcweir virtual double operator()( double t ) const 78cdf0e10cSrcweir { 79cdf0e10cSrcweir return t; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir isConstant() const82cdf0e10cSrcweir virtual bool isConstant() const 83cdf0e10cSrcweir { 84cdf0e10cSrcweir return false; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir }; 87cdf0e10cSrcweir 88cdf0e10cSrcweir /** Base class for following binary functions (*+-/) 89cdf0e10cSrcweir 90cdf0e10cSrcweir Does not pay off to have all this as a template, since 91cdf0e10cSrcweir we'd have to hold the functor as a member (+33% object 92cdf0e10cSrcweir size). 93cdf0e10cSrcweir */ 94cdf0e10cSrcweir class BinaryExpressionBase : public ExpressionNode 95cdf0e10cSrcweir { 96cdf0e10cSrcweir public: BinaryExpressionBase(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)97cdf0e10cSrcweir BinaryExpressionBase( const ExpressionNodeSharedPtr& rFirstArg, 98cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 99cdf0e10cSrcweir mpFirstArg( rFirstArg ), 100cdf0e10cSrcweir mpSecondArg( rSecondArg ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir } 103cdf0e10cSrcweir isConstant() const104cdf0e10cSrcweir virtual bool isConstant() const 105cdf0e10cSrcweir { 106cdf0e10cSrcweir return 107cdf0e10cSrcweir mpFirstArg->isConstant() && 108cdf0e10cSrcweir mpSecondArg->isConstant(); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir protected: 112cdf0e10cSrcweir ExpressionNodeSharedPtr mpFirstArg; 113cdf0e10cSrcweir ExpressionNodeSharedPtr mpSecondArg; 114cdf0e10cSrcweir }; 115cdf0e10cSrcweir 116cdf0e10cSrcweir class PlusExpression : public BinaryExpressionBase 117cdf0e10cSrcweir { 118cdf0e10cSrcweir public: PlusExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)119cdf0e10cSrcweir PlusExpression( const ExpressionNodeSharedPtr& rFirstArg, 120cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 121cdf0e10cSrcweir BinaryExpressionBase( rFirstArg, rSecondArg ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir } 124cdf0e10cSrcweir operator ()(double t) const125cdf0e10cSrcweir virtual double operator()( double t ) const 126cdf0e10cSrcweir { 127cdf0e10cSrcweir return (*mpFirstArg)(t) + (*mpSecondArg)(t); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir }; 130cdf0e10cSrcweir 131cdf0e10cSrcweir class MinusExpression : public BinaryExpressionBase 132cdf0e10cSrcweir { 133cdf0e10cSrcweir public: MinusExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)134cdf0e10cSrcweir MinusExpression( const ExpressionNodeSharedPtr& rFirstArg, 135cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 136cdf0e10cSrcweir BinaryExpressionBase( rFirstArg, rSecondArg ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir } 139cdf0e10cSrcweir operator ()(double t) const140cdf0e10cSrcweir virtual double operator()( double t ) const 141cdf0e10cSrcweir { 142cdf0e10cSrcweir return (*mpFirstArg)(t) - (*mpSecondArg)(t); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir }; 145cdf0e10cSrcweir 146cdf0e10cSrcweir class MultipliesExpression : public BinaryExpressionBase 147cdf0e10cSrcweir { 148cdf0e10cSrcweir public: MultipliesExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)149cdf0e10cSrcweir MultipliesExpression( const ExpressionNodeSharedPtr& rFirstArg, 150cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 151cdf0e10cSrcweir BinaryExpressionBase( rFirstArg, rSecondArg ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir } 154cdf0e10cSrcweir operator ()(double t) const155cdf0e10cSrcweir virtual double operator()( double t ) const 156cdf0e10cSrcweir { 157cdf0e10cSrcweir return (*mpFirstArg)(t) * (*mpSecondArg)(t); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir }; 160cdf0e10cSrcweir 161cdf0e10cSrcweir class DividesExpression : public BinaryExpressionBase 162cdf0e10cSrcweir { 163cdf0e10cSrcweir public: DividesExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)164cdf0e10cSrcweir DividesExpression( const ExpressionNodeSharedPtr& rFirstArg, 165cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 166cdf0e10cSrcweir BinaryExpressionBase( rFirstArg, rSecondArg ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir } 169cdf0e10cSrcweir operator ()(double t) const170cdf0e10cSrcweir virtual double operator()( double t ) const 171cdf0e10cSrcweir { 172cdf0e10cSrcweir return (*mpFirstArg)(t) / (*mpSecondArg)(t); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir }; 175cdf0e10cSrcweir 176cdf0e10cSrcweir class ComposedExpression : public BinaryExpressionBase 177cdf0e10cSrcweir { 178cdf0e10cSrcweir public: ComposedExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)179cdf0e10cSrcweir ComposedExpression( const ExpressionNodeSharedPtr& rFirstArg, 180cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 181cdf0e10cSrcweir BinaryExpressionBase( rFirstArg, rSecondArg ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir } 184cdf0e10cSrcweir operator ()(double t) const185cdf0e10cSrcweir virtual double operator()( double t ) const 186cdf0e10cSrcweir { 187cdf0e10cSrcweir return (*mpFirstArg)( (*mpSecondArg)(t) ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir }; 190cdf0e10cSrcweir 191cdf0e10cSrcweir class MinExpression : public BinaryExpressionBase 192cdf0e10cSrcweir { 193cdf0e10cSrcweir public: MinExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)194cdf0e10cSrcweir MinExpression( const ExpressionNodeSharedPtr& rFirstArg, 195cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 196cdf0e10cSrcweir BinaryExpressionBase( rFirstArg, rSecondArg ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir } 199cdf0e10cSrcweir operator ()(double t) const200cdf0e10cSrcweir virtual double operator()( double t ) const 201cdf0e10cSrcweir { 202cdf0e10cSrcweir return ::std::min( (*mpFirstArg)(t), (*mpSecondArg)(t) ); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir }; 205cdf0e10cSrcweir 206cdf0e10cSrcweir class MaxExpression : public BinaryExpressionBase 207cdf0e10cSrcweir { 208cdf0e10cSrcweir public: MaxExpression(const ExpressionNodeSharedPtr & rFirstArg,const ExpressionNodeSharedPtr & rSecondArg)209cdf0e10cSrcweir MaxExpression( const ExpressionNodeSharedPtr& rFirstArg, 210cdf0e10cSrcweir const ExpressionNodeSharedPtr& rSecondArg ) : 211cdf0e10cSrcweir BinaryExpressionBase( rFirstArg, rSecondArg ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir } 214cdf0e10cSrcweir operator ()(double t) const215cdf0e10cSrcweir virtual double operator()( double t ) const 216cdf0e10cSrcweir { 217cdf0e10cSrcweir return ::std::max( (*mpFirstArg)(t), (*mpSecondArg)(t) ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir }; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir createConstantValueExpression(double rConstantValue)222cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createConstantValueExpression( double rConstantValue ) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir return ExpressionNodeSharedPtr( new ConstantValueExpression(rConstantValue) ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir createValueTExpression()227cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createValueTExpression() 228cdf0e10cSrcweir { 229cdf0e10cSrcweir return ExpressionNodeSharedPtr( new TValueExpression() ); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir createPlusExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)232cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createPlusExpression( const ExpressionNodeSharedPtr& rLHS, 233cdf0e10cSrcweir const ExpressionNodeSharedPtr& rRHS ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir return ExpressionNodeSharedPtr( new PlusExpression(rLHS, rRHS) ); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir createMinusExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)238cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createMinusExpression( const ExpressionNodeSharedPtr& rLHS, 239cdf0e10cSrcweir const ExpressionNodeSharedPtr& rRHS ) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir return ExpressionNodeSharedPtr( new MinusExpression(rLHS, rRHS) ); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir createMultipliesExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)244cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createMultipliesExpression( const ExpressionNodeSharedPtr& rLHS, 245cdf0e10cSrcweir const ExpressionNodeSharedPtr& rRHS ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir return ExpressionNodeSharedPtr( new MultipliesExpression(rLHS, rRHS) ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir createDividesExpression(const ExpressionNodeSharedPtr & rLHS,const ExpressionNodeSharedPtr & rRHS)250cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createDividesExpression( const ExpressionNodeSharedPtr& rLHS, 251cdf0e10cSrcweir const ExpressionNodeSharedPtr& rRHS ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir return ExpressionNodeSharedPtr( new DividesExpression(rLHS, rRHS) ); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir createComposedExpression(const ExpressionNodeSharedPtr & rOuterFunction,const ExpressionNodeSharedPtr & rInnerFunction)256cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createComposedExpression ( const ExpressionNodeSharedPtr& rOuterFunction, 257cdf0e10cSrcweir const ExpressionNodeSharedPtr& rInnerFunction ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir return ExpressionNodeSharedPtr( new ComposedExpression(rOuterFunction, rInnerFunction) ); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir createMinExpression(const ExpressionNodeSharedPtr & rOuterFunction,const ExpressionNodeSharedPtr & rInnerFunction)262cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createMinExpression ( const ExpressionNodeSharedPtr& rOuterFunction, 263cdf0e10cSrcweir const ExpressionNodeSharedPtr& rInnerFunction ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir return ExpressionNodeSharedPtr( new MinExpression(rOuterFunction, rInnerFunction) ); 266cdf0e10cSrcweir } 267cdf0e10cSrcweir createMaxExpression(const ExpressionNodeSharedPtr & rOuterFunction,const ExpressionNodeSharedPtr & rInnerFunction)268cdf0e10cSrcweir ExpressionNodeSharedPtr ExpressionNodeFactory::createMaxExpression ( const ExpressionNodeSharedPtr& rOuterFunction, 269cdf0e10cSrcweir const ExpressionNodeSharedPtr& rInnerFunction ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir return ExpressionNodeSharedPtr( new MaxExpression(rOuterFunction, rInnerFunction) ); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir } 275cdf0e10cSrcweir } 276