widgetmodel/alfwidgetmodel/src/alflinevisualattributesetter.cpp
branchRCL_3
changeset 20 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
19:4ea6f81c838a 20:0e9bb658ef58
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implements attributesetters for linevisual.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //includes
       
    20 
       
    21 //widget model includes
       
    22 #include "alf/alfattributecontainer.h"
       
    23 #include "alf/alfattributevaluetype.h"
       
    24 #include "alf/alfattribute.h"
       
    25 #include "alf/alflinevisualattributesetter.h"
       
    26 #include <alf/alfvisualexception.h>
       
    27 #include <alf/alfdataexception.h>
       
    28 #include <alf/alfattributeexception.h>
       
    29 
       
    30 //osn includes
       
    31 #include <osn/ustring.h>
       
    32 #include <osn/alfptrvector.h>
       
    33 
       
    34 //alf includes
       
    35 #include <alf/alfenv.h>
       
    36 #include <alf/alflinevisual.h>
       
    37 #include <alf/alftexture.h>
       
    38 #include <alf/alfcurvepath.h>
       
    39 
       
    40 //dui includes
       
    41 #include "alf/attrproperty.h"
       
    42 
       
    43 //other includes
       
    44 #include <libc/string.h>
       
    45 #include <utf.h>
       
    46 
       
    47 
       
    48 
       
    49 //namespaces
       
    50 
       
    51 using namespace osncore;
       
    52 
       
    53 using namespace duiuimodel::commonvisualattributes;
       
    54 using namespace duiuimodel::linevisualattributes;
       
    55 using namespace duiuimodel::curvepathattributes;
       
    56 
       
    57 namespace Alf
       
    58     {
       
    59 
       
    60 static void throwIfErr ( int aErr )
       
    61     {
       
    62     if (aErr!=KErrNone)
       
    63         {
       
    64         ALF_THROW ( AlfAttributeException, aErr,
       
    65                     "AlfLineVisualAttributeSetter")
       
    66         }
       
    67     }
       
    68 
       
    69 
       
    70 class AlfLineVisualAttributeSetterImpl
       
    71     {
       
    72 public:
       
    73     AlfLineVisualAttributeSetterImpl();
       
    74     ~AlfLineVisualAttributeSetterImpl();
       
    75 public:
       
    76 
       
    77     // Texture manager doesn't unload the texture from memory untill Env
       
    78     // is deleted. Hence need to unload them once attribute setter is deleted.
       
    79     AlfPtrVector<CAlfTexture> mLoadedTextures;
       
    80     // Env needed to access TextureManager while unloading textures.
       
    81     CAlfEnv* mEnv;
       
    82     };
       
    83 
       
    84 AlfLineVisualAttributeSetterImpl::AlfLineVisualAttributeSetterImpl()
       
    85     {
       
    86     // Do not delete textures here as they may be in use by the visuals
       
    87     // that have not been deleted.
       
    88     mLoadedTextures.setAutoDelete(false);
       
    89     }
       
    90 
       
    91 AlfLineVisualAttributeSetterImpl::~AlfLineVisualAttributeSetterImpl()
       
    92     {
       
    93     // Unload all loaded textures created by this attributesetter to free
       
    94     // up the memory.
       
    95     for (int i =0;i<mLoadedTextures.count();i++)
       
    96         {
       
    97         CAlfTexture* Texture = mLoadedTextures[i];
       
    98         mEnv->TextureManager().UnloadTexture(Texture->Id());
       
    99         }
       
   100     mLoadedTextures.clear();
       
   101     }
       
   102 
       
   103 
       
   104 // ======== MEMBER FUNCTIONS ========
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Constructor.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 OSN_EXPORT AlfLineVisualAttributeSetter::AlfLineVisualAttributeSetter()
       
   111     {
       
   112     mImpl.reset(new (EMM) AlfLineVisualAttributeSetterImpl());
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // Destructor.
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 OSN_EXPORT AlfLineVisualAttributeSetter::~AlfLineVisualAttributeSetter()
       
   120     {
       
   121     }
       
   122 
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // Sets Attribute Value. Delegates based on attribute Category.
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 OSN_EXPORT void AlfLineVisualAttributeSetter::setAttributeValue (
       
   129     CAlfVisual &aVisual,
       
   130     AlfAttributeContainer* aContainer,
       
   131     IAlfMap* aData )
       
   132     {
       
   133     CAlfLineVisual* lineVisual = dynamic_cast<CAlfLineVisual*>( &aVisual);
       
   134 
       
   135     if ( !lineVisual )
       
   136         {
       
   137         ALF_THROW ( AlfVisualException, EInvalidVisual, "AlfLineVisualAttributeSetter" )
       
   138         }
       
   139 
       
   140     CAlfCurvePath* curve = lineVisual->Path();
       
   141     if (curve)
       
   142         {
       
   143         curve->Reset();
       
   144         }
       
   145 
       
   146     AlfCommonVisualAttributeSetter::setAttributeValue(aVisual,
       
   147             aContainer, aData);
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Deprecated
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 OSN_EXPORT TAlfCommand* AlfLineVisualAttributeSetter::createCommand (
       
   155     CAlfVisual& /*aVisual*/,
       
   156     AlfAttributeContainer* /*aContainer*/,
       
   157     IAlfMap* /*aData*/,
       
   158     int /*aTransitionTime*/,
       
   159     CAlfVisual* /*aRefVisual*/ )
       
   160     {
       
   161     //deprecated
       
   162     TAlfCommand* cmd = 0;
       
   163     return cmd;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Sends a command to Env
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 OSN_EXPORT void AlfLineVisualAttributeSetter::createAndSendCommands (
       
   171     CAlfVisual& aVisual,
       
   172     AlfAttributeContainer* aContainer,
       
   173     CAlfVisual* aRefVisual )
       
   174     {
       
   175     // SetOffset in CAlfCurvePath,
       
   176     // SetThickness,SetShadowThickness SetStartPos & SetEndPos
       
   177     // in Line Visual can be sent as a TAlfCustomEventCommand
       
   178     AlfCommonVisualAttributeSetter::createAndSendCommands (
       
   179         aVisual, aContainer, aRefVisual );
       
   180 
       
   181     }
       
   182 
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // Sets dynamic attributes to visual
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void AlfLineVisualAttributeSetter::handleDynamicAttribute (
       
   189     CAlfVisual &aVisual,
       
   190     AlfAttribute& aAttr,
       
   191     AlfAttributeContainer& aContainer)
       
   192     {
       
   193 
       
   194     CAlfLineVisual* lineVisual = dynamic_cast<CAlfLineVisual*>( &aVisual);
       
   195     if ( !lineVisual )
       
   196         {
       
   197         return;
       
   198         }  
       
   199     const char* attrName = aAttr.name();
       
   200 
       
   201     if ( !strcmp ( attrName, KThickness ) )
       
   202         {
       
   203         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   204         tVal.SetTarget ((TReal32)aAttr.getTargetValue()->realValue(),
       
   205                         (TInt) aAttr.getTime());
       
   206         tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   207         tVal.SetMappingFunctionIdentifier (aAttr.getMappingFunctionId());
       
   208 
       
   209         lineVisual->SetThickness(tVal);
       
   210         }
       
   211         
       
   212     else if ( !strcmp ( attrName, KShadowThickness ) )
       
   213         {
       
   214         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   215         tVal.SetTarget ((TReal32)aAttr.getTargetValue()->realValue(),
       
   216                         (TInt) aAttr.getTime());
       
   217         tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   218         tVal.SetMappingFunctionIdentifier (aAttr.getMappingFunctionId());
       
   219 
       
   220         lineVisual->SetShadowThickness(tVal);
       
   221         }
       
   222 
       
   223     else if ( !strcmp ( attrName, KStartPos ) )
       
   224         {
       
   225         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   226         tVal.SetTarget ((TReal32)aAttr.getTargetValue()->realValue(),
       
   227                         (TInt) aAttr.getTime());
       
   228         tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   229         tVal.SetMappingFunctionIdentifier (aAttr.getMappingFunctionId());
       
   230 
       
   231         lineVisual->SetStartPos(tVal);
       
   232         }
       
   233 
       
   234     else if ( !strcmp ( attrName, KEndPos ) )
       
   235         {
       
   236         TAlfTimedValue tVal((TReal32)aAttr.getSourceValue()->realValue());
       
   237         tVal.SetTarget ((TReal32)aAttr.getTargetValue()->realValue(),
       
   238                         (TInt) aAttr.getTime());
       
   239         tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   240         tVal.SetMappingFunctionIdentifier (aAttr.getMappingFunctionId());
       
   241 
       
   242         lineVisual->SetEndPos(tVal);
       
   243         }
       
   244 
       
   245     else if ( !strcmp ( attrName, KOffsetX )||!strcmp ( attrName, KOffsetY ) )
       
   246         {
       
   247         AlfAttribute& offsety = aContainer.getAttributeByName (
       
   248                                     KOffsetY );
       
   249         AlfAttribute& offsetx = aContainer.getAttributeByName (
       
   250                                     KOffsetX );
       
   251         //will throw if attribute is not found
       
   252 
       
   253         TAlfTimedPoint offset((TReal32)offsetx.getSourceValue()->realValue(),
       
   254                               (TReal32)offsety.getSourceValue()->realValue());
       
   255 
       
   256         offset.iX.SetTarget((TReal32)offsetx.getTargetValue()->realValue(),
       
   257                             offsetx.getTime());
       
   258 
       
   259         offset.iY.SetTarget((TReal32)offsety.getTargetValue()->realValue(),
       
   260                             offsety.getTime());
       
   261 
       
   262         offset.iX.SetStyle ( offsetx.getInterpolationStyle() );
       
   263         offset.iY.SetStyle ( offsety.getInterpolationStyle() );
       
   264 
       
   265         offset.iX.SetMappingFunctionIdentifier (
       
   266             offsetx.getMappingFunctionId());
       
   267         offset.iY.SetMappingFunctionIdentifier (
       
   268             offsety.getMappingFunctionId());
       
   269 
       
   270         CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   271         curve->SetOffset ( offset );
       
   272         offsetx.setDirty(false);
       
   273         offsety.setDirty(false);
       
   274         }
       
   275         
       
   276     else
       
   277         {
       
   278         AlfCommonVisualAttributeSetter::handleDynamicAttribute(
       
   279             aVisual, aAttr, aContainer);
       
   280         }
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // Sets static attributes to visual
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void AlfLineVisualAttributeSetter::handleStaticAttribute (
       
   288     CAlfVisual& aVisual,
       
   289     AlfAttribute& aAttr,
       
   290     AlfAttributeContainer& aContainer)
       
   291     {
       
   292 
       
   293     CAlfLineVisual* lineVisual = dynamic_cast<CAlfLineVisual*>( &aVisual);
       
   294     if ( !lineVisual )
       
   295         {
       
   296         return;
       
   297         }  
       
   298     
       
   299     const char* attrName = aAttr.name();
       
   300 
       
   301     if ( !strcmp ( attrName, KImagePath ) )
       
   302         {
       
   303         TPtrC8 src;
       
   304         src.Set((TUint8*)aAttr.stringValue().getUtf8());
       
   305         auto_ptr<HBufC> DesC;
       
   306         TRAPD(err1,
       
   307             DesC.reset(CnvUtfConverter::ConvertToUnicodeFromUtf8L(src)));
       
   308         throwIfErr(err1);
       
   309 
       
   310         if (DesC.get())
       
   311             {
       
   312             CAlfTexture* texture = NULL;
       
   313             TRAPD(err2,texture = &(aVisual.Env().TextureManager().
       
   314                                    LoadTextureL( *(DesC.get()),
       
   315                                        EAlfTextureFlagDefault,
       
   316                                        KAlfAutoGeneratedTextureId)));
       
   317             throwIfErr(err2);
       
   318             lineVisual->SetImage(TAlfImage(*texture));
       
   319             mImpl->mEnv = &aVisual.Env();
       
   320             mImpl->mLoadedTextures.resize(mImpl->mLoadedTextures.count()+1);
       
   321             mImpl->mLoadedTextures.insert(mImpl->mLoadedTextures.count(),
       
   322                                        texture);
       
   323             }
       
   324         }
       
   325 
       
   326     else if ( !strcmp ( attrName, KThickness ) )
       
   327         {
       
   328         TAlfTimedValue val(aAttr.realValue(),0);
       
   329         //static attribute,apply with immidiate effect
       
   330 
       
   331         lineVisual->SetThickness(val);
       
   332         }
       
   333 
       
   334     else if ( !strcmp ( attrName, KShadowThickness ) )
       
   335         {
       
   336         TAlfTimedValue val(aAttr.realValue(),0);
       
   337         //static attribute,apply with immidiate effect
       
   338 
       
   339         lineVisual->SetShadowThickness(val);
       
   340         }
       
   341 
       
   342     else if ( !strcmp ( attrName, KStartPos ) )
       
   343         {
       
   344         TAlfTimedValue val(aAttr.realValue(),0);
       
   345         //static attribute,apply with immidiate effect
       
   346 
       
   347         lineVisual->SetStartPos(val);
       
   348         }
       
   349 
       
   350     else if ( !strcmp ( attrName, KEndPos ) )
       
   351         {
       
   352         TAlfTimedValue val(aAttr.realValue(),0);
       
   353         //static attribute,apply with immidiate effect
       
   354 
       
   355         lineVisual->SetEndPos(val);
       
   356         }
       
   357 
       
   358     else if ( !strcmp ( attrName, KAlphaMappingFunction ) )
       
   359         {
       
   360         // assumption:
       
   361         // The int value-mapping function mapping is the following:
       
   362         // 0 - KConstMappingFunction
       
   363         // 1 - duiuimodel::nodetypes::KLinearMappingFunction
       
   364         // 2 - KSineMappingFunction
       
   365         // 3 - KCosineMappingFunction
       
   366 
       
   367         MAlfMappingFunction* func =  this->getMappingFunction(aAttr,
       
   368                                                lineVisual->Env());
       
   369         if (!func)
       
   370             {
       
   371             ALF_THROW ( AlfAttributeException,
       
   372                         EInvalidAttribute, "AlfLineVisualAttributeSetter")
       
   373             }
       
   374 
       
   375         lineVisual->SetAlphaFunction(func);
       
   376         }
       
   377 
       
   378     else if ( !strcmp ( attrName, KWidthMappingFunction ) )
       
   379         {
       
   380         //assumption:
       
   381         //The int value-mapping function mapping is the following:
       
   382         //0 - KConstMappingFunction
       
   383         //1 - duiuimodel::nodetypes::KLinearMappingFunction
       
   384         //2 - KSineMappingFunction
       
   385         //3 - KCosineMappingFunction
       
   386 
       
   387         MAlfMappingFunction* func =  this->getMappingFunction(aAttr,
       
   388                                      lineVisual->Env());
       
   389         if (!func)
       
   390             {
       
   391             ALF_THROW ( AlfAttributeException,
       
   392                         EInvalidAttribute, "AlfLineVisualAttributeSetter")
       
   393             }
       
   394         lineVisual->SetWidthFunction(func);
       
   395         }
       
   396 
       
   397     else if ( !strcmp ( attrName, KColor ) )
       
   398         {
       
   399         if ( 4 == aAttr.getTargetValueCount() &&
       
   400                 AlfAttributeValueType::EFloat == aAttr.type(0) &&
       
   401                 AlfAttributeValueType::EFloat == aAttr.type(1) &&
       
   402                 AlfAttributeValueType::EFloat == aAttr.type(2) &&
       
   403                 AlfAttributeValueType::EFloat == aAttr.type(3))
       
   404             {
       
   405             TRgb color ( aAttr.realValue(0),
       
   406                          aAttr.realValue(1),
       
   407                          aAttr.realValue(2),
       
   408                          aAttr.realValue(3) );
       
   409             lineVisual->SetColor ( color );
       
   410             }
       
   411         else
       
   412             {
       
   413             ALF_THROW ( AlfAttributeException, EInvalidAttribute,
       
   414                         "AlfLineVisualAttributeSetter")
       
   415             }
       
   416         }
       
   417 
       
   418     else if ( !strcmp ( attrName, KEnableLoop ) )
       
   419         {
       
   420 
       
   421         CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   422 
       
   423         // if value is not int, then use default parameter of EnableLoop
       
   424         if ( AlfAttributeValueType::EInt != aAttr.type() )
       
   425             {
       
   426             curve->EnableLoop ();
       
   427             }
       
   428         else
       
   429             {
       
   430             int enableLoop = aAttr.intValue();
       
   431 
       
   432             TBool flag = ETrue;
       
   433             //Assume true for any non-zero value.
       
   434 
       
   435             if ( 0 == enableLoop )
       
   436                 {
       
   437                 flag = EFalse;
       
   438                 }
       
   439             curve->EnableLoop ( flag );
       
   440             }
       
   441         }
       
   442 
       
   443     else if ( !strcmp ( attrName, KOrigin ) )
       
   444         {
       
   445         CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   446         curve->SetOrigin ( aAttr.realValue() );
       
   447         }
       
   448 
       
   449     else if ( !strcmp ( attrName, KOffsetX )||!strcmp ( attrName, KOffsetY ) )
       
   450         {
       
   451         CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   452         AlfAttribute& offsety = aContainer.getAttributeByName (
       
   453                                                KOffsetY );
       
   454         AlfAttribute& offsetx = aContainer.getAttributeByName (
       
   455                                                KOffsetX );
       
   456         //will throw if attribute is not found
       
   457 
       
   458         TAlfTimedPoint offset( offsetx.realValue(), offsety.realValue());
       
   459         curve->SetOffset ( offset );
       
   460         offsetx.setDirty(false);
       
   461         offsety.setDirty(false);
       
   462         }
       
   463         
       
   464     else if ( !strcmp ( attrName, KLine ) )
       
   465         {
       
   466         CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   467 
       
   468         // This multi-value attribute has to be filled in this order:
       
   469         // startx,starty,endx,endy,linelength
       
   470 
       
   471         if ( 5 != aAttr.getTargetValueCount())
       
   472             {
       
   473             ALF_THROW ( AlfAttributeException, EInvalidAttribute,
       
   474                         "CAlfLineVisualLayoutAttributeSetter" );
       
   475             }
       
   476         float startx = this->floatOrInt( aAttr, 0 );
       
   477         float starty = this->floatOrInt( aAttr, 1 );
       
   478         float endx = this->floatOrInt( aAttr, 2 );
       
   479         float endy = this->floatOrInt( aAttr, 3 );
       
   480         float len = aAttr.realValue(4);
       
   481 
       
   482         TRAPD(err1,
       
   483               curve->AppendLineL ( TAlfRealPoint(startx,starty),
       
   484                                    TAlfRealPoint(endx,endy),len ))
       
   485         throwIfErr(err1);
       
   486         }
       
   487         
       
   488     else if ( !strcmp ( attrName, KArc ) )
       
   489         {
       
   490         CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   491 
       
   492         // This multi-value attribute has to be filled in this order:
       
   493         // arcoriginx,arcoriginy,archorzradius,arcvertradius,
       
   494         // arcstartangle,arcendangle,arclength
       
   495 
       
   496         if ( 7 != aAttr.getTargetValueCount())
       
   497             {
       
   498             ALF_THROW ( AlfAttributeException, EInvalidAttribute,
       
   499                         "CAlfLineVisualLayoutAttributeSetter" );
       
   500             }
       
   501 
       
   502         float originx = this->floatOrInt( aAttr, 0 );
       
   503         float originy = this->floatOrInt( aAttr, 1 );
       
   504         float horzradius = this->floatOrInt( aAttr, 2 );
       
   505         float vertradius = this->floatOrInt( aAttr, 3 );
       
   506         float startangle = aAttr.realValue(4);
       
   507         float endangle = aAttr.realValue(5);
       
   508         float len = aAttr.realValue(6);
       
   509         TRAPD(err1,
       
   510               curve->AppendArcL(TAlfRealPoint(originx,originy),
       
   511                                 TAlfRealSize(horzradius,vertradius),
       
   512                                 startangle, endangle, len))
       
   513         throwIfErr(err1);
       
   514         }
       
   515         
       
   516     else
       
   517         {
       
   518         AlfCommonVisualAttributeSetter::handleStaticAttribute (
       
   519             aVisual, aAttr, aContainer);
       
   520         }
       
   521     }
       
   522 
       
   523 
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // Sets dynamic attributes to visual from data
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void AlfLineVisualAttributeSetter::handleDynamicDataAttribute (
       
   530     CAlfVisual& aVisual,
       
   531     AlfAttribute& aAttr,
       
   532     AlfAttributeContainer& aContainer,
       
   533     IAlfMap* aData )
       
   534     {
       
   535     CAlfLineVisual* lineVisual = dynamic_cast<CAlfLineVisual*>( &aVisual);
       
   536     if ( !lineVisual )
       
   537         {
       
   538         ALF_THROW ( AlfDataException, ECommonError,
       
   539                     "AlfLineVisualAttributeSetter" )
       
   540         }    
       
   541 
       
   542     const char* attrName = aAttr.name();
       
   543 
       
   544     const char* dataField = aAttr.getDataField();
       
   545 
       
   546     if ( !dataField )
       
   547         {
       
   548         ALF_THROW ( AlfDataException, ECommonError,
       
   549                     "AlfLineVisualAttributeSetter")
       
   550         }
       
   551 
       
   552     if (!aData)
       
   553         {
       
   554         ALF_THROW ( AlfDataException, ECommonError,
       
   555                     "AlfLineVisualAttributeSetter" )
       
   556         }
       
   557         
       
   558     IAlfVariantType* data = aData->item ( UString(dataField) );
       
   559     
       
   560     if (data)
       
   561         {
       
   562         const char* attrName = aAttr.name();
       
   563 
       
   564         if ( !strcmp ( attrName, KOffsetX ) )
       
   565             {
       
   566             AlfAttribute& offsety = aContainer.getAttributeByName (
       
   567                                         KOffsetY );
       
   568             //will throw if attribute is not found
       
   569 
       
   570             const char* offsetyDataField = offsety.getDataField();
       
   571             if ( !offsetyDataField )
       
   572                 {
       
   573                 ALF_THROW ( AlfDataException, ECommonError,
       
   574                             "AlfLineVisualAttributeSetter" )
       
   575                 }
       
   576             IAlfVariantType* offsetyData = 
       
   577                                  aData->item ( UString(offsetyDataField) );
       
   578 
       
   579             if ( data->type() == IAlfVariantType::EReal &&
       
   580                     offsetyData && 
       
   581                     offsetyData->type() == IAlfVariantType::EReal)
       
   582                 {
       
   583                 // The time value is in the attribute?
       
   584                 //Is it not part of data as well?
       
   585                 TAlfTimedPoint offset;
       
   586                 offset.iX.SetTarget(data->real(), aAttr.getTime());
       
   587                 offset.iX.SetStyle ( aAttr.getInterpolationStyle() );
       
   588                 offset.iX.SetMappingFunctionIdentifier (
       
   589                     aAttr.getMappingFunctionId());
       
   590                 offset.iY.SetTarget(offsetyData->real(), offsety.getTime());
       
   591                 offset.iY.SetStyle ( offsety.getInterpolationStyle() );
       
   592                 offset.iY.SetMappingFunctionIdentifier (
       
   593                     offsety.getMappingFunctionId());
       
   594                 CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   595                 curve->SetOffset ( offset );
       
   596                 }
       
   597             else
       
   598                 {
       
   599                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   600                 }
       
   601             }
       
   602             
       
   603         else if ( !strcmp ( attrName, KOffsetY ) )
       
   604             {
       
   605             //Make sure X Attribute also exists, but do nothing. Actual values
       
   606             //will be set in the iteration that checks for KOffsetX
       
   607             aContainer.getAttributeByName ( KOffsetX );
       
   608             //will throw if attribute is not found
       
   609             }
       
   610             
       
   611         else if ( !strcmp ( attrName, KThickness ) )
       
   612             {
       
   613             if ( data->type() == IAlfVariantType::EReal)
       
   614                 {
       
   615                 // The time value is in the attribute?
       
   616                 // Is it not part of data as well?
       
   617                 // how is the source value stored in data? policy not clear
       
   618                 TAlfTimedValue tVal;
       
   619                 tVal.SetTarget(data->real(),(TInt) aAttr.getTime());
       
   620                 tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   621                 tVal.SetMappingFunctionIdentifier (
       
   622                     aAttr.getMappingFunctionId());
       
   623                 lineVisual->SetThickness(tVal);
       
   624                 }
       
   625             else
       
   626                 {
       
   627                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   628                 }    
       
   629             }
       
   630             
       
   631         else if ( !strcmp ( attrName, KShadowThickness ) )
       
   632             {
       
   633             if ( data->type() == IAlfVariantType::EReal)
       
   634                 {
       
   635                 // The time value is in the attribute?
       
   636                 // Is it not part of data as well?
       
   637                 // how is the source value stored in data? policy not clear
       
   638                 TAlfTimedValue tVal;
       
   639                 tVal.SetTarget(data->real(),(TInt) aAttr.getTime());
       
   640                 tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   641                 tVal.SetMappingFunctionIdentifier (
       
   642                     aAttr.getMappingFunctionId());
       
   643                 lineVisual->SetShadowThickness(tVal);
       
   644                 }
       
   645             else
       
   646                 {
       
   647                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   648                 }    
       
   649             }
       
   650             
       
   651         else if ( !strcmp ( attrName, KStartPos ) )
       
   652             {
       
   653             if ( data->type() == IAlfVariantType::EReal)
       
   654                 {
       
   655                 // The time value is in the attribute?
       
   656                 // Is it not part of data as well?
       
   657                 // how is the source value stored in data? policy not clear
       
   658                 TAlfTimedValue tVal;
       
   659                 tVal.SetTarget(data->real(),(TInt) aAttr.getTime());
       
   660                 tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   661                 tVal.SetMappingFunctionIdentifier (
       
   662                     aAttr.getMappingFunctionId());
       
   663                 lineVisual->SetStartPos(tVal);
       
   664                 }
       
   665             else
       
   666                 {
       
   667                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   668                 }    
       
   669             }
       
   670             
       
   671         else if ( !strcmp ( attrName, KEndPos ) )
       
   672             {
       
   673             if ( data->type() == IAlfVariantType::EReal)
       
   674                 {
       
   675                 // The time value is in the attribute?
       
   676                 // Is it not part of data as well?
       
   677                 // how is the source value stored in data? policy not clear
       
   678                 TAlfTimedValue tVal;
       
   679                 tVal.SetTarget(data->real(),(TInt) aAttr.getTime());
       
   680                 tVal.SetStyle ( aAttr.getInterpolationStyle() );
       
   681                 tVal.SetMappingFunctionIdentifier (
       
   682                     aAttr.getMappingFunctionId());
       
   683                 lineVisual->SetEndPos(tVal);
       
   684                 }
       
   685             else
       
   686                 {
       
   687                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   688                 }    
       
   689             }
       
   690 
       
   691         else
       
   692             {
       
   693             AlfCommonVisualAttributeSetter::handleDynamicDataAttribute(
       
   694                 aVisual, aAttr, aContainer, aData);
       
   695             }
       
   696         }
       
   697     }
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 // Sets static attributes to visual  from data
       
   701 // ---------------------------------------------------------------------------
       
   702 //
       
   703 void AlfLineVisualAttributeSetter::handleStaticDataAttribute (
       
   704     CAlfVisual &aVisual,
       
   705     AlfAttribute& aAttr,
       
   706     AlfAttributeContainer& aContainer,
       
   707     IAlfMap* aData )
       
   708     {
       
   709 
       
   710     CAlfLineVisual* lineVisual = dynamic_cast<CAlfLineVisual*>( &aVisual);
       
   711     if ( !lineVisual )
       
   712         {
       
   713         ALF_THROW ( AlfDataException, ECommonError,
       
   714                     "AlfLineVisualAttributeSetter" )
       
   715         }  
       
   716 
       
   717     const char* dataField = aAttr.getDataField();
       
   718 
       
   719     if ( !dataField )
       
   720         {
       
   721         ALF_THROW ( AlfDataException, ECommonError,
       
   722                     "AlfLineVisualAttributeSetter" );
       
   723         }
       
   724 
       
   725     if (!aData)
       
   726         {
       
   727         ALF_THROW ( AlfDataException, ECommonError,
       
   728                     "AlfLineVisualAttributeSetter" );
       
   729         }
       
   730 
       
   731     IAlfVariantType* data = aData->item (UString( dataField) );
       
   732 
       
   733     const char* attrName = aAttr.name();
       
   734 
       
   735     if ( data )
       
   736         {
       
   737         if ( !strcmp ( attrName, KImagePath ) )
       
   738             {
       
   739             if (data->type() == IAlfVariantType::EString)
       
   740                 {
       
   741 
       
   742                 TPtrC8 src;
       
   743                 src.Set((TUint8*)data->string().getUtf8());
       
   744                 auto_ptr<HBufC> DesC;
       
   745                 TRAPD(err1,
       
   746                   DesC.reset(CnvUtfConverter::ConvertToUnicodeFromUtf8L(src)));
       
   747                 throwIfErr(err1);
       
   748 
       
   749                 if (DesC.get())
       
   750                     {
       
   751                     CAlfTexture* texture = NULL;
       
   752                     TRAPD(err2,texture = &(aVisual.Env().TextureManager().
       
   753                                            LoadTextureL(*(DesC.get()), 
       
   754                                                EAlfTextureFlagDefault,
       
   755                                                KAlfAutoGeneratedTextureId)));
       
   756                     throwIfErr(err2);
       
   757                     lineVisual->SetImage(TAlfImage(*texture));
       
   758                     mImpl->mEnv = &aVisual.Env();
       
   759                     mImpl->mLoadedTextures.resize(
       
   760                         mImpl->mLoadedTextures.count()+1);
       
   761                     mImpl->mLoadedTextures.insert(
       
   762                         mImpl->mLoadedTextures.count(), texture);
       
   763                     }
       
   764                 }
       
   765             else
       
   766                 {
       
   767                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   768                 }    
       
   769             }
       
   770 
       
   771         else if ( !strcmp ( attrName, KThickness ) )
       
   772             {
       
   773             if (data->type() == IAlfVariantType::EReal)
       
   774                 {
       
   775                 TAlfTimedValue val(data->real(),0);
       
   776                 //static attribute,apply with immidiate effect
       
   777 
       
   778                 lineVisual->SetThickness(val);
       
   779                 }
       
   780             else
       
   781                 {
       
   782                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   783                 }    
       
   784             }
       
   785 
       
   786         else if ( !strcmp ( attrName, KShadowThickness ) )
       
   787             {
       
   788             if (data->type() == IAlfVariantType::EReal)
       
   789                 {
       
   790                 TAlfTimedValue val(data->real(),0);
       
   791                 //static attribute,apply with immidiate effect
       
   792 
       
   793                 lineVisual->SetShadowThickness(val);
       
   794                 }
       
   795             else
       
   796                 {
       
   797                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   798                 }    
       
   799             }
       
   800 
       
   801         else if ( !strcmp ( attrName, KStartPos ) )
       
   802             {
       
   803             if (data->type() == IAlfVariantType::EReal)
       
   804                 {
       
   805                 TAlfTimedValue val(data->real(),0);
       
   806                 //static attribute,apply with immidiate effect
       
   807 
       
   808                 lineVisual->SetStartPos(val);
       
   809                 }
       
   810             }
       
   811 
       
   812         else if ( !strcmp ( attrName, KEndPos ) )
       
   813             {
       
   814             if (data->type() == IAlfVariantType::EReal)
       
   815                 {
       
   816                 TAlfTimedValue val(data->real(),0);
       
   817                 //static attribute,apply with immidiate effect
       
   818 
       
   819                 lineVisual->SetEndPos(val);
       
   820                 }
       
   821             else
       
   822                 {
       
   823                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   824                 }    
       
   825             }
       
   826 
       
   827         else if ( !strcmp ( attrName, KAlphaMappingFunction ) )
       
   828             {
       
   829             //assumption:
       
   830             //The int value-mapping function mapping is the following:
       
   831             //0 - KConstMappingFunction
       
   832             //1 - duiuimodel::nodetypes::KLinearMappingFunction
       
   833             //2 - KSineMappingFunction
       
   834             //3 - KCosineMappingFunction
       
   835             if (data->type() == IAlfVariantType::EContainer )
       
   836                 {
       
   837                 IAlfContainer* dataContainer = data->container();
       
   838                 MAlfMappingFunction* func =
       
   839                     this->getMappingFunctionFromContainer(dataContainer,
       
   840                                                           lineVisual->Env());
       
   841 
       
   842                 if (!func)
       
   843                     {
       
   844                     ALF_THROW ( AlfAttributeException,
       
   845                                 EInvalidAttribute, "AlfLineVisualAttributeSetter")
       
   846                     }
       
   847 
       
   848                 lineVisual->SetAlphaFunction(func);
       
   849                 }
       
   850             else
       
   851                 {
       
   852                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   853                 }
       
   854             }
       
   855             
       
   856         else if ( !strcmp ( attrName, KWidthMappingFunction ) )
       
   857             {
       
   858             //assumption:
       
   859             //The int value-mapping function mapping is the following:
       
   860             //0 - KConstMappingFunction
       
   861             //1 - duiuimodel::nodetypes::KLinearMappingFunction
       
   862             //2 - KSineMappingFunction
       
   863             //3 - KCosineMappingFunction
       
   864 
       
   865             if (data->type() == IAlfVariantType::EContainer )
       
   866                 {
       
   867                 IAlfContainer* dataContainer = data->container();
       
   868                 MAlfMappingFunction* func =
       
   869                     this->getMappingFunctionFromContainer(dataContainer,
       
   870                                                           lineVisual->Env());
       
   871 
       
   872                 if (!func)
       
   873                     {
       
   874                     ALF_THROW ( AlfAttributeException,
       
   875                                 EInvalidAttribute, "AlfLineVisualAttributeSetter")
       
   876                     }
       
   877 
       
   878                 lineVisual->SetWidthFunction(func);
       
   879                 }
       
   880             else
       
   881                 {
       
   882                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   883                 }
       
   884             }
       
   885             
       
   886         else if ( !strcmp ( attrName, KColor ) )
       
   887             {
       
   888             if (data->type() == IAlfVariantType::EContainer )
       
   889                 {
       
   890                 IAlfContainer* dataContainer = data->container();
       
   891 
       
   892                 if ( 4 != dataContainer -> count() )
       
   893                     {
       
   894                     ALF_THROW ( AlfAttributeException,EIncompleteAttributeValues, "AlfLineVisualAttributeSetter")
       
   895                     }
       
   896 
       
   897                 IAlfVariantType* red = dataContainer->item ( 0 );//red
       
   898 
       
   899                 IAlfVariantType* green = dataContainer->item ( 1 );//green
       
   900 
       
   901                 IAlfVariantType* blue = dataContainer->item ( 2 );//blue
       
   902 
       
   903                 IAlfVariantType* alpha = dataContainer->item ( 3 );//alpha
       
   904 
       
   905                 if ( red && IAlfVariantType::EReal == red->type()     &&
       
   906                         green && IAlfVariantType::EReal == green->type() &&
       
   907                         blue && IAlfVariantType::EReal == blue->type()   &&
       
   908                         alpha && IAlfVariantType::EReal == alpha->type() )
       
   909                     {
       
   910                     TRgb color ( red->real(),
       
   911                                  green->real(),
       
   912                                  blue->real(),
       
   913                                  alpha->real() );
       
   914 
       
   915                     lineVisual->SetColor ( color );
       
   916                     }
       
   917                 else
       
   918                     {
       
   919                     ALF_THROW ( AlfAttributeException, EInvalidAttribute,
       
   920                                 "AlfLineVisualAttributeSetter" )
       
   921                     }
       
   922                 }
       
   923             else
       
   924                 {
       
   925                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   926                 }    
       
   927             }
       
   928             
       
   929         else if ( !strcmp ( attrName, KEnableLoop ) )
       
   930             {
       
   931             CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   932 
       
   933             // if value is not bool, then use default parameter of EnableLoop
       
   934             if ( data->type() != IAlfVariantType::EBool )
       
   935                 {
       
   936                 curve->EnableLoop ();
       
   937                 }
       
   938 
       
   939             else
       
   940                 {
       
   941                 curve->EnableLoop ( data->boolean() );
       
   942                 }
       
   943             }
       
   944 
       
   945         else if ( !strcmp ( attrName, KOrigin ) )
       
   946             {
       
   947             CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   948 
       
   949             if ( data->type() == IAlfVariantType::EReal )
       
   950                 {
       
   951                 float origin =  data->real() ;
       
   952                 curve->SetOrigin ( origin );
       
   953                 }
       
   954             else
       
   955                 {
       
   956                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   957                 }    
       
   958             }
       
   959 
       
   960         else if ( !strcmp ( attrName, KOffsetX ) )
       
   961             {
       
   962             CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
   963 
       
   964             AlfAttribute& offsety = aContainer.getAttributeByName (
       
   965                                         KOffsetY );
       
   966 
       
   967             //will throw if attribute is not found
       
   968             const char* offsetyDataField = offsety.getDataField();
       
   969             if ( !offsetyDataField )
       
   970                 {
       
   971                 ALF_THROW ( AlfDataException,
       
   972                             ECommonError,  "AlfLineVisualAttributeSetter" )
       
   973                 }
       
   974 
       
   975             IAlfVariantType* offsetyData = 
       
   976                                  aData->item (UString( offsetyDataField ) );
       
   977 
       
   978             if ( data->type() == IAlfVariantType::EReal &&
       
   979                     offsetyData && 
       
   980                     offsetyData->type() == IAlfVariantType::EReal)
       
   981                 {
       
   982                 TAlfTimedPoint offset( data->real(), offsetyData->real());
       
   983                 curve->SetOffset ( offset );
       
   984                 }
       
   985             else
       
   986                 {
       
   987                 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfLineVisualtAttributeSetter");
       
   988                 }    
       
   989             }
       
   990 
       
   991         else if ( !strcmp ( attrName, KOffsetY ) )
       
   992             {
       
   993             //Make sure X Attribute also exists, but do nothing.
       
   994             //Actual values will be set in the iteration that checks for
       
   995             //KOffsetX
       
   996 
       
   997             aContainer.getAttributeByName ( KOffsetX );
       
   998             //will throw if attribute is not found
       
   999             }
       
  1000 
       
  1001         else if ( !strcmp ( attrName, KLine ) )
       
  1002             {
       
  1003             CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
  1004 
       
  1005             //if not a container, dont proceed
       
  1006             if (!(data->type() == IAlfVariantType::EContainer))
       
  1007                 {
       
  1008                 return;
       
  1009                 }
       
  1010 
       
  1011             IAlfContainer* container = data->container();
       
  1012             //if all item are not present, throw
       
  1013             if (container->count() != 5)
       
  1014                 {
       
  1015                 ALF_THROW ( AlfAttributeException, EInvalidAttribute,
       
  1016                             "AlfLineVisualAttributeSetter" );
       
  1017                 }
       
  1018 
       
  1019             IAlfVariantType* lineStartXvalue = container->item(0);
       
  1020             IAlfVariantType* lineStartYvalue = container->item(1);
       
  1021             IAlfVariantType* lineEndXvalue = container->item(2);
       
  1022             IAlfVariantType* lineEndYvalue = container->item(3);
       
  1023             IAlfVariantType* lineLengthvalue = container->item(4);
       
  1024 
       
  1025             float startx = this->floatOrIntFromData( lineStartXvalue);
       
  1026             float starty = this->floatOrIntFromData( lineStartYvalue);
       
  1027             float endx   = this->floatOrIntFromData( lineEndXvalue  );
       
  1028             float endy   = this->floatOrIntFromData( lineEndYvalue  );
       
  1029             float len    = float(lineLengthvalue->real());
       
  1030             TRAPD(err1,
       
  1031                   curve->AppendLineL ( TAlfRealPoint(startx,starty),
       
  1032                                        TAlfRealPoint(endx,endy),len ))
       
  1033             throwIfErr(err1);
       
  1034             }
       
  1035 
       
  1036         else if ( !strcmp ( attrName, KArc ) )
       
  1037             {
       
  1038             CAlfCurvePath* curve = this->getCurvePath(lineVisual);
       
  1039 
       
  1040             //if not a container, dont proceed
       
  1041             if (!(data->type() == IAlfVariantType::EContainer))
       
  1042                 {
       
  1043                 return;
       
  1044                 }
       
  1045 
       
  1046             IAlfContainer* container = data->container();
       
  1047 
       
  1048             //if all item are not present, throw
       
  1049             if (container->count() != 7)
       
  1050                 {
       
  1051                 ALF_THROW ( AlfAttributeException, EInvalidAttribute,
       
  1052                             "AlfLineVisualAttributeSetter" );
       
  1053                 }
       
  1054                 
       
  1055             IAlfVariantType* arcOriginXValue = container->item(0);
       
  1056             IAlfVariantType* arcOriginYValue = container->item(1);
       
  1057             IAlfVariantType* archorzradiusValue = container->item(2);
       
  1058             IAlfVariantType* arcvertradiusValue = container->item(3);
       
  1059             IAlfVariantType* arcstartangleValue = container->item(4);
       
  1060             IAlfVariantType* arcendangleValue = container->item(5);
       
  1061             IAlfVariantType* arclengthValue = container->item(6);
       
  1062 
       
  1063             float originx    = this->floatOrIntFromData( arcOriginXValue);
       
  1064             float originy    = this->floatOrIntFromData( arcOriginYValue);
       
  1065             float horzradius = this->floatOrIntFromData( archorzradiusValue);
       
  1066             float vertradius = this->floatOrIntFromData( arcvertradiusValue);
       
  1067             float startangle = float(arcstartangleValue->real());
       
  1068             float endangle   = float(arcendangleValue->real());
       
  1069             float len        = float(arclengthValue->real());
       
  1070             TRAPD(err1,
       
  1071                   curve->AppendArcL(TAlfRealPoint(originx,originy),
       
  1072                                     TAlfRealSize(horzradius,vertradius),
       
  1073                                     startangle,endangle,len))
       
  1074 
       
  1075             throwIfErr(err1);
       
  1076             }
       
  1077             
       
  1078         else
       
  1079             {
       
  1080             AlfCommonVisualAttributeSetter::handleStaticDataAttribute(
       
  1081                 aVisual, aAttr, aContainer, aData );
       
  1082             }
       
  1083         }
       
  1084 
       
  1085     }
       
  1086 
       
  1087 
       
  1088 // ---------------------------------------------------------------------------
       
  1089 // Creates and returns a toolkit defined mappping function based on the
       
  1090 // attribute contents
       
  1091 // assumption:
       
  1092 // The int value-mapping function mapping is the following:
       
  1093 // 0 - KConstMappingFunction
       
  1094 // 1 - duiuimodel::nodetypes::KLinearMappingFunction
       
  1095 // 2 - KSineMappingFunction
       
  1096 // 3 - KCosineMappingFunction
       
  1097 // ---------------------------------------------------------------------------
       
  1098 //
       
  1099 MAlfMappingFunction* AlfLineVisualAttributeSetter::getMappingFunction(
       
  1100     AlfAttribute& aAttribute,
       
  1101     CAlfEnv& aEnv)
       
  1102     {
       
  1103     MAlfMappingFunction* func=0;
       
  1104     int intValue = aAttribute.realValue(0);
       
  1105     
       
  1106     switch (intValue)
       
  1107         {
       
  1108         case 0:
       
  1109             {
       
  1110             if (aAttribute.getTargetValueCount() == 2)
       
  1111                 {
       
  1112                 TRAPD(err1,func = CAlfConstantMappingFunction::NewL(aEnv,
       
  1113                                       aAttribute.realValue(1)))
       
  1114                 throwIfErr(err1);
       
  1115                 }
       
  1116 
       
  1117             else
       
  1118                 {
       
  1119                 TRAPD(err1,func = CAlfConstantMappingFunction::NewL(aEnv))
       
  1120                 throwIfErr(err1);
       
  1121                 }
       
  1122             }
       
  1123         break;
       
  1124 
       
  1125         case 1:
       
  1126             {
       
  1127             if (aAttribute.getTargetValueCount() == 3)
       
  1128                 {
       
  1129                 TRAPD(err1,func = CAlfLinearMappingFunction::NewL(aEnv,
       
  1130                                       aAttribute.realValue(1),
       
  1131                                       aAttribute.realValue(2)))
       
  1132                 throwIfErr(err1);
       
  1133                 }
       
  1134 
       
  1135             else if (aAttribute.getTargetValueCount() == 2)
       
  1136                 {
       
  1137                 TRAPD(err1,func = CAlfLinearMappingFunction::NewL(aEnv,
       
  1138                                       aAttribute.realValue(1)))
       
  1139                 throwIfErr(err1);
       
  1140                 }
       
  1141 
       
  1142             else
       
  1143                 {
       
  1144                 TRAPD(err1,func = CAlfLinearMappingFunction::NewL(aEnv))
       
  1145                 throwIfErr(err1);
       
  1146                 }
       
  1147             }
       
  1148         break;
       
  1149 
       
  1150         case 2:
       
  1151             {
       
  1152             if (aAttribute.getTargetValueCount() == 3)
       
  1153                 {
       
  1154                 TRAPD(err1,func = CAlfSineMappingFunction::NewL(aEnv,
       
  1155                                       aAttribute.realValue(1),
       
  1156                                       aAttribute.realValue(2)))
       
  1157                 throwIfErr(err1);
       
  1158                 }
       
  1159 
       
  1160             else if (aAttribute.getTargetValueCount() == 2)
       
  1161                 {
       
  1162                 TRAPD(err1,func = CAlfSineMappingFunction::NewL(aEnv,
       
  1163                                   aAttribute.realValue(1)))
       
  1164                 throwIfErr(err1);
       
  1165                 }
       
  1166 
       
  1167             else
       
  1168                 {
       
  1169                 TRAPD(err1,func = CAlfSineMappingFunction::NewL(aEnv))
       
  1170                 throwIfErr(err1);
       
  1171                 }
       
  1172             }
       
  1173         break;
       
  1174 
       
  1175         case 3:
       
  1176             {
       
  1177             if (aAttribute.getTargetValueCount() == 3)
       
  1178                 {
       
  1179                 TRAPD(err1,func = CAlfCosineMappingFunction::NewL(aEnv,
       
  1180                                       aAttribute.realValue(1),
       
  1181                                       aAttribute.realValue(2)))
       
  1182                 throwIfErr(err1);
       
  1183                 }
       
  1184 
       
  1185             else if (aAttribute.getTargetValueCount() == 2)
       
  1186                 {
       
  1187                 TRAPD(err1,func = CAlfCosineMappingFunction::NewL(aEnv,
       
  1188                                   aAttribute.realValue(1)))
       
  1189                 throwIfErr(err1);
       
  1190                 }
       
  1191 
       
  1192             else
       
  1193                 {
       
  1194                 TRAPD(err1,func = CAlfCosineMappingFunction::NewL(aEnv))
       
  1195                 throwIfErr(err1);
       
  1196                 }
       
  1197             }
       
  1198         break;
       
  1199 
       
  1200         default:
       
  1201             break;
       
  1202 
       
  1203         }
       
  1204 
       
  1205     return func;
       
  1206     }
       
  1207 
       
  1208 
       
  1209 // ---------------------------------------------------------------------------
       
  1210 // Creates and returns a toolkit defined mappping function based on the
       
  1211 // container contents
       
  1212 // assumption:
       
  1213 // The int value-mapping function mapping is the following:
       
  1214 // 0 - KConstMappingFunction
       
  1215 // 1 - duiuimodel::nodetypes::KLinearMappingFunction
       
  1216 // 2 - KSineMappingFunction
       
  1217 // 3 - KCosineMappingFunction
       
  1218 // ---------------------------------------------------------------------------
       
  1219 //
       
  1220 MAlfMappingFunction* AlfLineVisualAttributeSetter::
       
  1221     getMappingFunctionFromContainer(IAlfContainer* aContainer, CAlfEnv& aEnv)
       
  1222     {
       
  1223     MAlfMappingFunction* func=0;
       
  1224 
       
  1225     if (IAlfVariantType::EInt != aContainer->item(0)->type())
       
  1226         {
       
  1227         return func;
       
  1228         }
       
  1229 
       
  1230     switch (aContainer->item(0)->integer())
       
  1231         {
       
  1232         case 0:
       
  1233             {
       
  1234             if (aContainer -> count() == 2)
       
  1235                 {
       
  1236                 TRAPD(err1,func = CAlfConstantMappingFunction::NewL(aEnv,
       
  1237                                   aContainer->item(1)->real()))
       
  1238                 throwIfErr(err1);
       
  1239                 }
       
  1240 
       
  1241             else
       
  1242                 {
       
  1243                 TRAPD(err1,func = CAlfConstantMappingFunction::NewL(aEnv))
       
  1244                 throwIfErr(err1);
       
  1245                 }
       
  1246             }
       
  1247         break;
       
  1248 
       
  1249         case 1:
       
  1250             {
       
  1251             if (aContainer -> count() == 3)
       
  1252                 {
       
  1253                 TRAPD(err1,func = CAlfLinearMappingFunction::NewL(aEnv,
       
  1254                                       aContainer->item(1)->real(),
       
  1255                                       aContainer->item(2)->real()))
       
  1256                 throwIfErr(err1);
       
  1257                 }
       
  1258 
       
  1259             else if (aContainer -> count() == 2)
       
  1260                 {
       
  1261                 TRAPD(err1,func = CAlfLinearMappingFunction::NewL(aEnv,
       
  1262                                   aContainer->item(1)->real()))
       
  1263                 throwIfErr(err1);
       
  1264                 }
       
  1265 
       
  1266             else
       
  1267                 {
       
  1268                 TRAPD(err1,func = CAlfLinearMappingFunction::NewL(aEnv))
       
  1269                 throwIfErr(err1);
       
  1270                 }
       
  1271             }
       
  1272         break;
       
  1273 
       
  1274         case 2:
       
  1275             {
       
  1276             if (aContainer -> count() == 3)
       
  1277                 {
       
  1278                 TRAPD(err1,func = CAlfSineMappingFunction::NewL(aEnv,
       
  1279                                       aContainer->item(1)->real(),
       
  1280                                       aContainer->item(2)->real()))
       
  1281                 throwIfErr(err1);
       
  1282                 }
       
  1283 
       
  1284             else if (aContainer -> count() == 2)
       
  1285                 {
       
  1286                 TRAPD(err1,func = CAlfSineMappingFunction::NewL(aEnv,
       
  1287                                   aContainer->item(1)->real()))
       
  1288                 throwIfErr(err1);
       
  1289                 }
       
  1290 
       
  1291             else
       
  1292                 {
       
  1293                 TRAPD(err1,func = CAlfSineMappingFunction::NewL(aEnv))
       
  1294                 throwIfErr(err1);
       
  1295                 }
       
  1296             }
       
  1297         break;
       
  1298 
       
  1299         case 3:
       
  1300             {
       
  1301             if (aContainer -> count() == 3)
       
  1302                 {
       
  1303                 TRAPD(err1,func = CAlfCosineMappingFunction::NewL(aEnv,
       
  1304                                       aContainer->item(1)->real(),
       
  1305                                       aContainer->item(2)->real()))
       
  1306                 throwIfErr(err1);
       
  1307                 }
       
  1308 
       
  1309             else if (aContainer -> count() == 2)
       
  1310                 {
       
  1311                 TRAPD(err1,func = CAlfCosineMappingFunction::NewL(aEnv,
       
  1312                                   aContainer->item(1)->real()))
       
  1313                 throwIfErr(err1);
       
  1314                 }
       
  1315 
       
  1316             else
       
  1317                 {
       
  1318                 TRAPD(err1,func = CAlfCosineMappingFunction::NewL(aEnv))
       
  1319                 throwIfErr(err1);
       
  1320                 }
       
  1321             }
       
  1322         break;
       
  1323 
       
  1324         default:
       
  1325             break;
       
  1326 
       
  1327         }
       
  1328 
       
  1329     return func;
       
  1330     }
       
  1331 
       
  1332 
       
  1333 // ---------------------------------------------------------------------------
       
  1334 // If the line visual already has a path set to it, it is retrived.
       
  1335 // Else a new instance is created
       
  1336 // ---------------------------------------------------------------------------
       
  1337 //
       
  1338 CAlfCurvePath* AlfLineVisualAttributeSetter::getCurvePath(
       
  1339     CAlfLineVisual* aLineVisual)
       
  1340     {
       
  1341     CAlfCurvePath* curve = 0;
       
  1342     if(aLineVisual)
       
  1343         {
       
  1344         curve = aLineVisual->Path();
       
  1345 
       
  1346         if (!curve)
       
  1347             {
       
  1348             TRAPD(err1,curve = CAlfCurvePath::NewL(aLineVisual->Env()))
       
  1349             throwIfErr(err1);
       
  1350 
       
  1351             aLineVisual->SetPath( curve, EAlfHasOwnership);
       
  1352             }
       
  1353         }
       
  1354     return curve;
       
  1355     }
       
  1356 
       
  1357 // ---------------------------------------------------------------------------
       
  1358 // Check if data in the attribute is int or float.
       
  1359 // Return the value as a float value
       
  1360 // ---------------------------------------------------------------------------
       
  1361 //
       
  1362 float AlfLineVisualAttributeSetter::floatOrInt(
       
  1363     const AlfAttribute& aAttr,
       
  1364     int aIndex)
       
  1365     {
       
  1366     if (aAttr.type(aIndex) == AlfAttributeValueType::EInt)
       
  1367         {
       
  1368         return float(aAttr.intValue(aIndex));
       
  1369         }
       
  1370     else if (aAttr.type(aIndex) == AlfAttributeValueType::EFloat)
       
  1371         {
       
  1372         return aAttr.realValue(aIndex); //will throw an exception i
       
  1373         }
       
  1374     else
       
  1375         {
       
  1376         ALF_THROW ( AlfAttributeException, ECommonError,
       
  1377                     "AlfLineVisualAttributeSetter" );
       
  1378         }
       
  1379     }
       
  1380 
       
  1381 // ---------------------------------------------------------------------------
       
  1382 // Check if data in the variant type is int or float.
       
  1383 // Return the value as a float value
       
  1384 // ---------------------------------------------------------------------------
       
  1385 //
       
  1386 float AlfLineVisualAttributeSetter::floatOrIntFromData(IAlfVariantType* aData)
       
  1387     {
       
  1388     if (IAlfVariantType::EInt == aData->type())
       
  1389         {
       
  1390         return float(aData->integer());
       
  1391         }
       
  1392     else if (IAlfVariantType::EReal == aData->type())
       
  1393         {
       
  1394         return aData->real();; //will throw an exception i
       
  1395         }
       
  1396     else
       
  1397         {
       
  1398         ALF_THROW ( AlfAttributeException, ECommonError,
       
  1399                     "AlfLineVisualAttributeSetter" );
       
  1400         }
       
  1401     }
       
  1402 
       
  1403     }// namespace Alf
       
  1404 // End of file
       
  1405 
       
  1406 
       
  1407 
       
  1408 
       
  1409