<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: shapetransitionfactory.cxx,v $
 * $Revision: 1.9 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_slideshow.hxx"

#include <canvas/debug.hxx>

#include <comphelper/anytostring.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>

#include <com/sun/star/animations/TransitionType.hpp>
#include <com/sun/star/animations/TransitionSubType.hpp>

#include "transitionfactory.hxx"
#include "transitiontools.hxx"
#include "parametricpolypolygonfactory.hxx"
#include "animationfactory.hxx"
#include "clippingfunctor.hxx"

#include <boost/bind.hpp>

using namespace ::com::sun::star;

namespace slideshow {
namespace internal {

/***************************************************
 ***                                             ***
 ***          Shape Transition Effects           ***
 ***                                             ***
 ***************************************************/

namespace {

class ClippingAnimation : public NumberAnimation
{
public:
    ClippingAnimation(
        const ParametricPolyPolygonSharedPtr&   rPolygon,
        const ShapeManagerSharedPtr&            rShapeManager,
        const TransitionInfo&                   rTransitionInfo,
        bool                                    bDirectionForward,
        bool                                    bModeIn );

    ~ClippingAnimation();

    // Animation interface
    // -------------------
    virtual void prefetch( const AnimatableShapeSharedPtr&     rShape,
                           const ShapeAttributeLayerSharedPtr& rAttrLayer );
    virtual void start( const AnimatableShapeSharedPtr&     rShape,
                        const ShapeAttributeLayerSharedPtr& rAttrLayer );
    virtual void end();

    // NumberAnimation interface
    // -----------------------
    virtual bool operator()( double nValue );
    virtual double getUnderlyingValue() const;

private:
    void end_();

    AnimatableShapeSharedPtr           mpShape;
    ShapeAttributeLayerSharedPtr       mpAttrLayer;
    ShapeManagerSharedPtr              mpShapeManager;
    ClippingFunctor                    maClippingFunctor;
    bool                               mbSpriteActive;
};

ClippingAnimation::ClippingAnimation(
    const ParametricPolyPolygonSharedPtr&   rPolygon,
    const ShapeManagerSharedPtr&            rShapeManager,
    const TransitionInfo&                   rTransitionInfo,
    bool                                    bDirectionForward,
    bool                                    bModeIn ) :
        mpShape(),
        mpAttrLayer(),
        mpShapeManager( rShapeManager ),
        maClippingFunctor( rPolygon,
                           rTransitionInfo,
                           bDirectionForward,
                           bModeIn ),
        mbSpriteActive(false)
{
    ENSURE_AND_THROW(
        rShapeManager,
        "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
}

ClippingAnimation::~ClippingAnimation()
{
    try
    {
        end_();
    }
    catch (uno::Exception &)
    {
        OSL_ENSURE( false, rtl::OUStringToOString(
                        comphelper::anyToString(
                            cppu::getCaughtException() ),
                        RTL_TEXTENCODING_UTF8 ).getStr() );
    }
}

void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr&,
                                  const ShapeAttributeLayerSharedPtr& )
{
}

void ClippingAnimation::start( const AnimatableShapeSharedPtr&      rShape,
                               const ShapeAttributeLayerSharedPtr&  rAttrLayer )
{
    OSL_ENSURE( !mpShape,
                "ClippingAnimation::start(): Shape already set" );
    OSL_ENSURE( !mpAttrLayer,
                "ClippingAnimation::start(): Attribute layer already set" );

    mpShape = rShape;
    mpAttrLayer = rAttrLayer;

    ENSURE_AND_THROW( rShape,
                      "ClippingAnimation::start(): Invalid shape" );
    ENSURE_AND_THROW( rAttrLayer,
                      "ClippingAnimation::start(): Invalid attribute layer" );

    mpShape = rShape;
    mpAttrLayer = rAttrLayer;

    if( !mbSpriteActive )
    {
        mpShapeManager->enterAnimationMode( mpShape );
        mbSpriteActive = true;
    }
}

void ClippingAnimation::end()
{
    end_();
}

void ClippingAnimation::end_()
{
    if( mbSpriteActive )
    {
        mbSpriteActive = false;
        mpShapeManager->leaveAnimationMode( mpShape );

        if( mpShape->isContentChanged() )
            mpShapeManager->notifyShapeUpdate( mpShape );
    }
}

bool ClippingAnimation::operator()( double nValue )
{
    ENSURE_AND_RETURN(
        mpAttrLayer && mpShape,
        "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );

    // set new clip
    mpAttrLayer->setClip( maClippingFunctor( nValue,
                                             mpShape->getDomBounds().getRange() ) );

    if( mpShape->isContentChanged() )
        mpShapeManager->notifyShapeUpdate( mpShape );

    return true;
}

double ClippingAnimation::getUnderlyingValue() const
{
    ENSURE_AND_THROW(
        mpAttrLayer,
        "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );

    return 0.0;     // though this should be used in concert with
                    // ActivitiesFactory::createSimpleActivity, better
                    // explicitely name our start value.
                    // Permissible range for operator() above is [0,1]
}

} // anon namespace

AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
    const ActivitiesFactory::CommonParameters&          rParms,
    const AnimatableShapeSharedPtr&                     rShape,
    const ShapeManagerSharedPtr&                        rShapeManager,
    const ::basegfx::B2DVector&                         rSlideSize,
    uno::Reference< animations::XTransitionFilter > const& xTransition )
{
    return createShapeTransition( rParms,
                                  rShape,
                                  rShapeManager,
                                  rSlideSize,
                                  xTransition,
                                  xTransition->getTransition(),
                                  xTransition->getSubtype() );
}

AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
    const ActivitiesFactory::CommonParameters&              rParms,
    const AnimatableShapeSharedPtr&                         rShape,
    const ShapeManagerSharedPtr&                            rShapeManager,
    const ::basegfx::B2DVector&                             rSlideSize,
    ::com::sun::star::uno::Reference<
        ::com::sun::star::animations::XTransitionFilter > const& xTransition,
    sal_Int16                                               nType,
    sal_Int16                                               nSubType )
{
    ENSURE_AND_THROW(
        xTransition.is(),
        "TransitionFactory::createShapeTransition(): Invalid XTransition" );

    const TransitionInfo* pTransitionInfo(
        getTransitionInfo( nType, nSubType ) );

    AnimationActivitySharedPtr pGeneratedActivity;
    if( pTransitionInfo != NULL )
    {
        switch( pTransitionInfo->meTransitionClass )
        {
            default:
            case TransitionInfo::TRANSITION_INVALID:
                OSL_ENSURE( false,
                            "TransitionFactory::createShapeTransition(): Invalid transition type. "
                            "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
                return AnimationActivitySharedPtr();

            case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON:
            {
                // generate parametric poly-polygon
                ParametricPolyPolygonSharedPtr pPoly(
                    ParametricPolyPolygonFactory::createClipPolyPolygon(
                        nType, nSubType ) );

                // create a clip activity from that
                pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
                    rParms,
                    NumberAnimationSharedPtr(
                        new ClippingAnimation(
                            pPoly,
                            rShapeManager,
                            *pTransitionInfo,
                            xTransition->getDirection(),
                            xTransition->getMode() ) ),
                    true );
            }
            break;

            case TransitionInfo::TRANSITION_SPECIAL:
            {
                switch( nType )
                {
                    case animations::TransitionType::RANDOM:
                    {
                        // select randomly one of the effects from the
                        // TransitionFactoryTable

                        const TransitionInfo* pRandomTransitionInfo( getRandomTransitionInfo() );

                        ENSURE_AND_THROW( pRandomTransitionInfo != NULL,
                                          "TransitionFactory::createShapeTransition(): Got invalid random transition info" );

                        ENSURE_AND_THROW( pRandomTransitionInfo->mnTransitionType != animations::TransitionType::RANDOM,
                                          "TransitionFactory::createShapeTransition(): Got random again for random input!" );

                        // and recurse
                        pGeneratedActivity = createShapeTransition( rParms,
                                                                    rShape,
                                                                    rShapeManager,
                                                                    rSlideSize,
                                                                    xTransition,
                                                                    pRandomTransitionInfo->mnTransitionType,
                                                                    pRandomTransitionInfo->mnTransitionSubType );
                    }
                    break;

                    // TODO(F3): Implement slidewipe for shape
                    case animations::TransitionType::SLIDEWIPE:
                    {
                        sal_Int16 nBarWipeSubType(0);
                        bool      bDirectionForward(true);

                        // map slidewipe to BARWIPE, for now
                        switch( nSubType )
                        {
                            case animations::TransitionSubType::FROMLEFT:
                                nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
                                bDirectionForward = true;
                                break;

                            case animations::TransitionSubType::FROMRIGHT:
                                nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
                                bDirectionForward = false;
                                break;

                            case animations::TransitionSubType::FROMTOP:
                                nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
                                bDirectionForward = true;
                                break;

                            case animations::TransitionSubType::FROMBOTTOM:
                                nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
                                bDirectionForward = false;
                                break;

                            default:
                                ENSURE_AND_THROW( false,
                                                  "TransitionFactory::createShapeTransition(): Unexpected subtype for SLIDEWIPE" );
                                break;
                        }

                        // generate parametric poly-polygon
                        ParametricPolyPolygonSharedPtr pPoly(
                            ParametricPolyPolygonFactory::createClipPolyPolygon(
                                animations::TransitionType::BARWIPE,
                                nBarWipeSubType ) );

                        // create a clip activity from that
                        pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
                            rParms,
                            NumberAnimationSharedPtr(
                                new ClippingAnimation(
                                    pPoly,
                                    rShapeManager,
                                    *getTransitionInfo( animations::TransitionType::BARWIPE,
                                                        nBarWipeSubType ),
                                    bDirectionForward,
                                    xTransition->getMode() ) ),
                            true );
                    }
                    break;

                    default:
                    {
                        // TODO(F1): Check whether there's anything left, anyway,
                        // for _shape_ transitions. AFAIK, there are no special
                        // effects for shapes...

                        // for now, map all to fade effect
                        pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
                            rParms,
                            AnimationFactory::createNumberPropertyAnimation(
                                ::rtl::OUString(
                                    RTL_CONSTASCII_USTRINGPARAM("Opacity") ),
                                rShape,
                                rShapeManager,
                                rSlideSize ),
                            xTransition->getMode() );
                    }
                    break;
                }
            }
            break;
        }
    }

    if( !pGeneratedActivity )
    {
        // No animation generated, maybe no table entry for given
        // transition?
        OSL_TRACE(
            "TransitionFactory::createShapeTransition(): Unknown type/subtype (%d/%d) "
            "combination encountered",
            xTransition->getTransition(),
            xTransition->getSubtype() );
        OSL_ENSURE(
            false,
            "TransitionFactory::createShapeTransition(): Unknown type/subtype "
            "combination encountered" );
    }

    return pGeneratedActivity;
}

}
}
<commit_msg>INTEGRATION: CWS canvas05 (1.8.18); FILE MERGED 2008/04/21 07:53:59 thb 1.8.18.2: RESYNC: (1.8-1.9); FILE MERGED 2007/10/01 13:49:14 thb 1.8.18.1: #i79258# Merge from CWS picom<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: shapetransitionfactory.cxx,v $
 * $Revision: 1.10 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_slideshow.hxx"

#include <canvas/debug.hxx>
#include <tools/diagnose_ex.h>

#include <comphelper/anytostring.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>

#include <com/sun/star/animations/TransitionType.hpp>
#include <com/sun/star/animations/TransitionSubType.hpp>

#include "transitionfactory.hxx"
#include "transitiontools.hxx"
#include "parametricpolypolygonfactory.hxx"
#include "animationfactory.hxx"
#include "clippingfunctor.hxx"

#include <boost/bind.hpp>

using namespace ::com::sun::star;

namespace slideshow {
namespace internal {

/***************************************************
 ***                                             ***
 ***          Shape Transition Effects           ***
 ***                                             ***
 ***************************************************/

namespace {

class ClippingAnimation : public NumberAnimation
{
public:
    ClippingAnimation(
        const ParametricPolyPolygonSharedPtr&   rPolygon,
        const ShapeManagerSharedPtr&            rShapeManager,
        const TransitionInfo&                   rTransitionInfo,
        bool                                    bDirectionForward,
        bool                                    bModeIn );

    ~ClippingAnimation();

    // Animation interface
    // -------------------
    virtual void prefetch( const AnimatableShapeSharedPtr&     rShape,
                           const ShapeAttributeLayerSharedPtr& rAttrLayer );
    virtual void start( const AnimatableShapeSharedPtr&     rShape,
                        const ShapeAttributeLayerSharedPtr& rAttrLayer );
    virtual void end();

    // NumberAnimation interface
    // -----------------------
    virtual bool operator()( double nValue );
    virtual double getUnderlyingValue() const;

private:
    void end_();

    AnimatableShapeSharedPtr           mpShape;
    ShapeAttributeLayerSharedPtr       mpAttrLayer;
    ShapeManagerSharedPtr              mpShapeManager;
    ClippingFunctor                    maClippingFunctor;
    bool                               mbSpriteActive;
};

ClippingAnimation::ClippingAnimation(
    const ParametricPolyPolygonSharedPtr&   rPolygon,
    const ShapeManagerSharedPtr&            rShapeManager,
    const TransitionInfo&                   rTransitionInfo,
    bool                                    bDirectionForward,
    bool                                    bModeIn ) :
        mpShape(),
        mpAttrLayer(),
        mpShapeManager( rShapeManager ),
        maClippingFunctor( rPolygon,
                           rTransitionInfo,
                           bDirectionForward,
                           bModeIn ),
        mbSpriteActive(false)
{
    ENSURE_OR_THROW(
        rShapeManager,
        "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
}

ClippingAnimation::~ClippingAnimation()
{
    try
    {
        end_();
    }
    catch (uno::Exception &)
    {
        OSL_ENSURE( false, rtl::OUStringToOString(
                        comphelper::anyToString(
                            cppu::getCaughtException() ),
                        RTL_TEXTENCODING_UTF8 ).getStr() );
    }
}

void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr&,
                                  const ShapeAttributeLayerSharedPtr& )
{
}

void ClippingAnimation::start( const AnimatableShapeSharedPtr&      rShape,
                               const ShapeAttributeLayerSharedPtr&  rAttrLayer )
{
    OSL_ENSURE( !mpShape,
                "ClippingAnimation::start(): Shape already set" );
    OSL_ENSURE( !mpAttrLayer,
                "ClippingAnimation::start(): Attribute layer already set" );

    mpShape = rShape;
    mpAttrLayer = rAttrLayer;

    ENSURE_OR_THROW( rShape,
                      "ClippingAnimation::start(): Invalid shape" );
    ENSURE_OR_THROW( rAttrLayer,
                      "ClippingAnimation::start(): Invalid attribute layer" );

    mpShape = rShape;
    mpAttrLayer = rAttrLayer;

    if( !mbSpriteActive )
    {
        mpShapeManager->enterAnimationMode( mpShape );
        mbSpriteActive = true;
    }
}

void ClippingAnimation::end()
{
    end_();
}

void ClippingAnimation::end_()
{
    if( mbSpriteActive )
    {
        mbSpriteActive = false;
        mpShapeManager->leaveAnimationMode( mpShape );

        if( mpShape->isContentChanged() )
            mpShapeManager->notifyShapeUpdate( mpShape );
    }
}

bool ClippingAnimation::operator()( double nValue )
{
    ENSURE_OR_RETURN(
        mpAttrLayer && mpShape,
        "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );

    // set new clip
    mpAttrLayer->setClip( maClippingFunctor( nValue,
                                             mpShape->getDomBounds().getRange() ) );

    if( mpShape->isContentChanged() )
        mpShapeManager->notifyShapeUpdate( mpShape );

    return true;
}

double ClippingAnimation::getUnderlyingValue() const
{
    ENSURE_OR_THROW(
        mpAttrLayer,
        "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );

    return 0.0;     // though this should be used in concert with
                    // ActivitiesFactory::createSimpleActivity, better
                    // explicitely name our start value.
                    // Permissible range for operator() above is [0,1]
}

} // anon namespace

AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
    const ActivitiesFactory::CommonParameters&          rParms,
    const AnimatableShapeSharedPtr&                     rShape,
    const ShapeManagerSharedPtr&                        rShapeManager,
    const ::basegfx::B2DVector&                         rSlideSize,
    uno::Reference< animations::XTransitionFilter > const& xTransition )
{
    return createShapeTransition( rParms,
                                  rShape,
                                  rShapeManager,
                                  rSlideSize,
                                  xTransition,
                                  xTransition->getTransition(),
                                  xTransition->getSubtype() );
}

AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
    const ActivitiesFactory::CommonParameters&              rParms,
    const AnimatableShapeSharedPtr&                         rShape,
    const ShapeManagerSharedPtr&                            rShapeManager,
    const ::basegfx::B2DVector&                             rSlideSize,
    ::com::sun::star::uno::Reference<
        ::com::sun::star::animations::XTransitionFilter > const& xTransition,
    sal_Int16                                               nType,
    sal_Int16                                               nSubType )
{
    ENSURE_OR_THROW(
        xTransition.is(),
        "TransitionFactory::createShapeTransition(): Invalid XTransition" );

    const TransitionInfo* pTransitionInfo(
        getTransitionInfo( nType, nSubType ) );

    AnimationActivitySharedPtr pGeneratedActivity;
    if( pTransitionInfo != NULL )
    {
        switch( pTransitionInfo->meTransitionClass )
        {
            default:
            case TransitionInfo::TRANSITION_INVALID:
                OSL_ENSURE( false,
                            "TransitionFactory::createShapeTransition(): Invalid transition type. "
                            "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
                return AnimationActivitySharedPtr();

            case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON:
            {
                // generate parametric poly-polygon
                ParametricPolyPolygonSharedPtr pPoly(
                    ParametricPolyPolygonFactory::createClipPolyPolygon(
                        nType, nSubType ) );

                // create a clip activity from that
                pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
                    rParms,
                    NumberAnimationSharedPtr(
                        new ClippingAnimation(
                            pPoly,
                            rShapeManager,
                            *pTransitionInfo,
                            xTransition->getDirection(),
                            xTransition->getMode() ) ),
                    true );
            }
            break;

            case TransitionInfo::TRANSITION_SPECIAL:
            {
                switch( nType )
                {
                    case animations::TransitionType::RANDOM:
                    {
                        // select randomly one of the effects from the
                        // TransitionFactoryTable

                        const TransitionInfo* pRandomTransitionInfo( getRandomTransitionInfo() );

                        ENSURE_OR_THROW( pRandomTransitionInfo != NULL,
                                          "TransitionFactory::createShapeTransition(): Got invalid random transition info" );

                        ENSURE_OR_THROW( pRandomTransitionInfo->mnTransitionType != animations::TransitionType::RANDOM,
                                          "TransitionFactory::createShapeTransition(): Got random again for random input!" );

                        // and recurse
                        pGeneratedActivity = createShapeTransition( rParms,
                                                                    rShape,
                                                                    rShapeManager,
                                                                    rSlideSize,
                                                                    xTransition,
                                                                    pRandomTransitionInfo->mnTransitionType,
                                                                    pRandomTransitionInfo->mnTransitionSubType );
                    }
                    break;

                    // TODO(F3): Implement slidewipe for shape
                    case animations::TransitionType::SLIDEWIPE:
                    {
                        sal_Int16 nBarWipeSubType(0);
                        bool      bDirectionForward(true);

                        // map slidewipe to BARWIPE, for now
                        switch( nSubType )
                        {
                            case animations::TransitionSubType::FROMLEFT:
                                nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
                                bDirectionForward = true;
                                break;

                            case animations::TransitionSubType::FROMRIGHT:
                                nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
                                bDirectionForward = false;
                                break;

                            case animations::TransitionSubType::FROMTOP:
                                nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
                                bDirectionForward = true;
                                break;

                            case animations::TransitionSubType::FROMBOTTOM:
                                nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
                                bDirectionForward = false;
                                break;

                            default:
                                ENSURE_OR_THROW( false,
                                                  "TransitionFactory::createShapeTransition(): Unexpected subtype for SLIDEWIPE" );
                                break;
                        }

                        // generate parametric poly-polygon
                        ParametricPolyPolygonSharedPtr pPoly(
                            ParametricPolyPolygonFactory::createClipPolyPolygon(
                                animations::TransitionType::BARWIPE,
                                nBarWipeSubType ) );

                        // create a clip activity from that
                        pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
                            rParms,
                            NumberAnimationSharedPtr(
                                new ClippingAnimation(
                                    pPoly,
                                    rShapeManager,
                                    *getTransitionInfo( animations::TransitionType::BARWIPE,
                                                        nBarWipeSubType ),
                                    bDirectionForward,
                                    xTransition->getMode() ) ),
                            true );
                    }
                    break;

                    default:
                    {
                        // TODO(F1): Check whether there's anything left, anyway,
                        // for _shape_ transitions. AFAIK, there are no special
                        // effects for shapes...

                        // for now, map all to fade effect
                        pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
                            rParms,
                            AnimationFactory::createNumberPropertyAnimation(
                                ::rtl::OUString(
                                    RTL_CONSTASCII_USTRINGPARAM("Opacity") ),
                                rShape,
                                rShapeManager,
                                rSlideSize ),
                            xTransition->getMode() );
                    }
                    break;
                }
            }
            break;
        }
    }

    if( !pGeneratedActivity )
    {
        // No animation generated, maybe no table entry for given
        // transition?
        OSL_TRACE(
            "TransitionFactory::createShapeTransition(): Unknown type/subtype (%d/%d) "
            "combination encountered",
            xTransition->getTransition(),
            xTransition->getSubtype() );
        OSL_ENSURE(
            false,
            "TransitionFactory::createShapeTransition(): Unknown type/subtype "
            "combination encountered" );
    }

    return pGeneratedActivity;
}

}
}
<|endoftext|>


<commit_before>//
// App.cpp - Main application class for VTBuilder
//
// Copyright (c) 2001-2005 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "Frame.h"
#include "BuilderView.h"
#include "vtdata/vtLog.h"
#include "vtui/Helper.h"
#include "gdal_priv.h"
#include "App.h"

#define HEAPBUSTER 0

#if HEAPBUSTER
#include "../HeapBuster/HeapBuster.h"
#endif

IMPLEMENT_APP(BuilderApp)

void BuilderApp::Args(int argc, wxChar **argv)
{
	for (int i = 0; i < argc; i++)
	{
		wxString str = argv[i];
		wxCharBuffer cbuf = str.mb_str(wxConvUTF8);
		if (!strncmp(cbuf, "-locale=", 8))
			m_locale_name = (const char *)cbuf + 8;
	}
}

class LogCatcher : public wxLog
{
	void DoLogString(const wxChar *szString, time_t t)
	{
		VTLOG1(" wxLog: ");
		VTLOG1(szString);
		VTLOG1("\n");
	}
};

bool BuilderApp::OnInit()
{
#if WIN32 && defined(_MSC_VER) && DEBUG
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

	VTSTARTLOG("debug.txt");
	VTLOG1(APPNAME);
	VTLOG1("\nBuild:");
#if VTDEBUG
	VTLOG(" Debug");
#else
	VTLOG(" Release");
#endif
#ifdef UNICODE
	VTLOG(" Unicode");
#endif
	VTLOG("\n");
#if WIN32
	VTLOG(" Running on: ");
	LogWindowsVersion();
#endif

	// Redirect the wxWindows log messages to our own logging stream
	wxLog *logger = new LogCatcher();
	wxLog::SetActiveTarget(logger);

	Args(argc, argv);

	SetupLocale();

	VTLOG(" Initializing GDAL.");
	g_GDALWrapper.GuessDataPaths();
	g_GDALWrapper.RequestGDALFormats();

	// Fill list of layer type names
	if (vtLayer::LayerTypeNames.IsEmpty())
	{
		// These must correspond to the order of the LayerType enum!
		vtLayer::LayerTypeNames.Add(_("Raw"));
		vtLayer::LayerTypeNames.Add(_("Elevation"));
		vtLayer::LayerTypeNames.Add(_("Image"));
		vtLayer::LayerTypeNames.Add(_("Road"));
		vtLayer::LayerTypeNames.Add(_("Structure"));
		vtLayer::LayerTypeNames.Add(_("Water"));
		vtLayer::LayerTypeNames.Add(_("Vegetation"));
		vtLayer::LayerTypeNames.Add(_("Transit"));
		vtLayer::LayerTypeNames.Add(_("Utility"));
	}

	VTLOG("Testing ability to allocate a frame object.\n");
	wxFrame *frametest = new wxFrame(NULL, -1, _T("Title"));
	delete frametest;

	VTLOG(" Creating Main Frame Window,");
	wxString title(APPNAME, wxConvUTF8);
	VTLOG(" title '%s'\n", title.mb_str(wxConvUTF8));
	MainFrame* frame = new MainFrame((wxFrame *) NULL, title,
							   wxPoint(50, 50), wxSize(900, 500));

	VTLOG(" Setting up the UI.\n");
	frame->SetupUI();

	VTLOG(" Showing the frame.\n");
	frame->Show(TRUE);

	SetTopWindow(frame);

	VTLOG(" GDAL-supported formats:");
	GDALDriverManager *poDM = GetGDALDriverManager();
	for( int iDriver = 0; iDriver < poDM->GetDriverCount(); iDriver++ )
	{
		if ((iDriver % 13) == 0)
			VTLOG("\n  ");
		GDALDriver *poDriver = poDM->GetDriver( iDriver );
		const char *name = poDriver->GetDescription();
		VTLOG("%s ", name);
	}
	VTLOG("\n");

	// Stuff for testing
//	wxString str("E:/Earth Imagery/NASA BlueMarble/MOD09A1.E.interpol.cyl.retouched.topo.3x00054x00027-N.bmp");
//	wxString str("E:/Data-USA/Elevation/crater_0513.bt");
/*	vtLayer *pLayer = frame->ImportImage(str);
	bool success = frame->AddLayerWithCheck(pLayer, true);
	frame->LoadLayer(str);
*/
//	frame->LoadProject("E:/Locations/Romania/giurgiu.vtb");
//	frame->ImportDataFromFile(LT_ELEVATION, "E:/Earth/NOAA Globe/g10g.hdr", false);
//	wxString str("E:/Data-USA/Terrains/Hawai`i.xml");
//	frame->LoadLayer(str);

//	wxString fname("E:/VTP User's Data/Hangzhou/Data/BuildingData/a-bldgs-18dec-subset1.vtst");
//	frame->LoadLayer(fname);
//	vtStructureLayer *pSL = frame->GetActiveStructureLayer();
//	vtStructure *str = pSL->GetAt(0);
//	str->Select(true);
//	pSL->EditBuildingProperties();
//	wxString fname("E:/Locations-USA/Hawai`i Island Data/DRG/O19154F8.TIF");
//	frame->ImportDataFromFile(LT_IMAGE, fname, true);
//	frame->LoadProject("E:/Locations-USA/Hawai`i Island Content/Honoka`a/latest_temp.vtb");

//	vtString fname = "E:/Locations-Hawai'i/Hawai`i Island Data/SDTS-DLG/waipahu_HI/transportation/852867.RR.sdts.tar.gz";
//	frame->ImportDataFromArchive(LT_ROAD, fname, true);

#if HEAPBUSTER
	// Pull in the heap buster
	g_HeapBusterDummy = -1;
#endif

	return TRUE;
}

int BuilderApp::OnExit()
{
	VTLOG("App Exit\n");
	return wxApp::OnExit();
}

void BuilderApp::SetupLocale()
{
	wxLog::SetVerbose(true);

	// Locale stuff
	int lang = wxLANGUAGE_DEFAULT;
	int default_lang = m_locale.GetSystemLanguage();

	const wxLanguageInfo *info = wxLocale::GetLanguageInfo(default_lang);
	VTLOG("Default language: %d (%s)\n", default_lang,
		(const char *) info->Description.mb_str(wxConvUTF8));

	// After wx2.4.2, wxWidgets looks in the application's directory for
	//  locale catalogs, not the current directory.  Here we force it to
	//  look in the current directory as well.
	wxString cwd = wxGetCwd();
	m_locale.AddCatalogLookupPathPrefix(cwd);

	bool bSuccess=false;
	if (m_locale_name != "")
	{
		VTLOG("Looking up language: %s\n", (const char *) m_locale_name);
		lang = GetLangFromName(wxString(m_locale_name, *wxConvCurrent));
		if (lang == wxLANGUAGE_UNKNOWN)
		{
			VTLOG(" Unknown, falling back on default language.\n");
			lang = wxLANGUAGE_DEFAULT;
		}
		else
		{
			info = m_locale.GetLanguageInfo(lang);
			VTLOG("Initializing locale to language %d, Canonical name '%s', Description: '%s':\n", lang,
				(const char *) info->CanonicalName.mb_str(wxConvUTF8),
				(const char *) info->Description.mb_str(wxConvUTF8));
			bSuccess = m_locale.Init(lang, wxLOCALE_CONV_ENCODING);
		}
	}
	if (lang == wxLANGUAGE_DEFAULT)
	{
		VTLOG("Initializing locale to default language:\n");
		bSuccess = m_locale.Init(wxLANGUAGE_DEFAULT, wxLOCALE_CONV_ENCODING);
		if (bSuccess)
			lang = default_lang;
	}
	if (bSuccess)
		VTLOG(" succeeded.\n");
	else
		VTLOG(" failed.\n");

	if (lang != wxLANGUAGE_ENGLISH_US)
	{
		VTLOG("Attempting to load the 'VTBuilder.mo' catalog for the current locale.\n");
		bSuccess = m_locale.AddCatalog(wxT("VTBuilder"));
		if (bSuccess)
			VTLOG(" succeeded.\n");
		else
			VTLOG(" not found.\n");
		VTLOG("\n");
	}

	// Test it
//	wxString test = _("&File");

	wxLog::SetVerbose(false);
}

<commit_msg>tweaks<commit_after>//
// App.cpp - Main application class for VTBuilder
//
// Copyright (c) 2001-2006 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "Frame.h"
#include "BuilderView.h"
#include "vtdata/vtLog.h"
#include "vtui/Helper.h"
#include "gdal_priv.h"
#include "App.h"

#define HEAPBUSTER 0

#if HEAPBUSTER
#include "../HeapBuster/HeapBuster.h"
#endif

IMPLEMENT_APP(BuilderApp)

void BuilderApp::Args(int argc, wxChar **argv)
{
	for (int i = 0; i < argc; i++)
	{
		wxString str = argv[i];
		wxCharBuffer cbuf = str.mb_str(wxConvUTF8);
		if (!strncmp(cbuf, "-locale=", 8))
			m_locale_name = (const char *)cbuf + 8;
	}
}

class LogCatcher : public wxLog
{
	void DoLogString(const wxChar *szString, time_t t)
	{
		VTLOG1(" wxLog: ");
		VTLOG1(szString);
		VTLOG1("\n");
	}
};

bool BuilderApp::OnInit()
{
#if WIN32 && defined(_MSC_VER) && DEBUG
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

	VTSTARTLOG("debug.txt");
	VTLOG1(APPNAME);
	VTLOG1("\nBuild:");
#if VTDEBUG
	VTLOG(" Debug");
#else
	VTLOG(" Release");
#endif
#ifdef UNICODE
	VTLOG(" Unicode");
#endif
	VTLOG("\n");
#if WIN32
	VTLOG(" Running on: ");
	LogWindowsVersion();
#endif

	// Redirect the wxWindows log messages to our own logging stream
	wxLog *logger = new LogCatcher;
	wxLog::SetActiveTarget(logger);

	Args(argc, argv);

	SetupLocale();

	VTLOG1(" Initializing GDAL.\n");
	g_GDALWrapper.GuessDataPaths();
	g_GDALWrapper.RequestGDALFormats();

	// Fill list of layer type names
	if (vtLayer::LayerTypeNames.IsEmpty())
	{
		// These must correspond to the order of the LayerType enum!
		vtLayer::LayerTypeNames.Add(_("Raw"));
		vtLayer::LayerTypeNames.Add(_("Elevation"));
		vtLayer::LayerTypeNames.Add(_("Image"));
		vtLayer::LayerTypeNames.Add(_("Road"));
		vtLayer::LayerTypeNames.Add(_("Structure"));
		vtLayer::LayerTypeNames.Add(_("Water"));
		vtLayer::LayerTypeNames.Add(_("Vegetation"));
		vtLayer::LayerTypeNames.Add(_("Transit"));
		vtLayer::LayerTypeNames.Add(_("Utility"));
	}

	VTLOG1("Testing ability to allocate a frame object.\n");
	wxFrame *frametest = new wxFrame(NULL, -1, _T("Title"));
	delete frametest;

	wxString title(APPNAME, wxConvUTF8);
	VTLOG(" Creating Main Frame Window, title '%s'\n", title.mb_str(wxConvUTF8));
	MainFrame* frame = new MainFrame((wxFrame *) NULL, title,
							   wxPoint(50, 50), wxSize(900, 500));

	VTLOG1(" Setting up the UI.\n");
	frame->SetupUI();

	VTLOG1(" Showing the frame.\n");
	frame->Show(TRUE);

	SetTopWindow(frame);

	VTLOG1(" GDAL-supported formats:");
	GDALDriverManager *poDM = GetGDALDriverManager();
	for( int iDriver = 0; iDriver < poDM->GetDriverCount(); iDriver++ )
	{
		if ((iDriver % 13) == 0)
			VTLOG("\n  ");
		GDALDriver *poDriver = poDM->GetDriver( iDriver );
		const char *name = poDriver->GetDescription();
		VTLOG(" %s", name);
	}
	VTLOG1("\n");

	// Stuff for testing
//	wxString str("E:/Earth Imagery/NASA BlueMarble/MOD09A1.E.interpol.cyl.retouched.topo.3x00054x00027-N.bmp");
//	wxString str("E:/Data-USA/Elevation/crater_0513.bt");
/*	vtLayer *pLayer = frame->ImportImage(str);
	bool success = frame->AddLayerWithCheck(pLayer, true);
	frame->LoadLayer(str);
*/
//	frame->LoadProject("E:/Locations/Romania/giurgiu.vtb");
//	frame->ImportDataFromFile(LT_ELEVATION, "E:/Earth/NOAA Globe/g10g.hdr", false);
//	wxString str("E:/Data-USA/Terrains/Hawai`i.xml");
//	frame->LoadLayer(str);

//	wxString fname("E:/VTP User's Data/Hangzhou/Data/BuildingData/a-bldgs-18dec-subset1.vtst");
//	frame->LoadLayer(fname);
//	vtStructureLayer *pSL = frame->GetActiveStructureLayer();
//	vtStructure *str = pSL->GetAt(0);
//	str->Select(true);
//	pSL->EditBuildingProperties();
//	wxString fname("E:/Locations-USA/Hawai`i Island Data/DRG/O19154F8.TIF");
//	frame->ImportDataFromFile(LT_IMAGE, fname, true);
//	frame->LoadProject("E:/Locations-USA/Hawai`i Island Content/Honoka`a/latest_temp.vtb");

//	vtString fname = "E:/Locations-Hawai'i/Hawai`i Island Data/SDTS-DLG/waipahu_HI/transportation/852867.RR.sdts.tar.gz";
//	frame->ImportDataFromArchive(LT_ROAD, fname, true);

#if HEAPBUSTER
	// Pull in the heap buster
	g_HeapBusterDummy = -1;
#endif

	return TRUE;
}

int BuilderApp::OnExit()
{
	VTLOG("App Exit\n");
	return wxApp::OnExit();
}

void BuilderApp::SetupLocale()
{
	wxLog::SetVerbose(true);

	// Locale stuff
	int lang = wxLANGUAGE_DEFAULT;
	int default_lang = m_locale.GetSystemLanguage();

	const wxLanguageInfo *info = wxLocale::GetLanguageInfo(default_lang);
	VTLOG("Default language: %d (%s)\n", default_lang,
		(const char *) info->Description.mb_str(wxConvUTF8));

	// After wx2.4.2, wxWidgets looks in the application's directory for
	//  locale catalogs, not the current directory.  Here we force it to
	//  look in the current directory as well.
	wxString cwd = wxGetCwd();
	m_locale.AddCatalogLookupPathPrefix(cwd);

	bool bSuccess=false;
	if (m_locale_name != "")
	{
		VTLOG("Looking up language: %s\n", (const char *) m_locale_name);
		lang = GetLangFromName(wxString(m_locale_name, *wxConvCurrent));
		if (lang == wxLANGUAGE_UNKNOWN)
		{
			VTLOG(" Unknown, falling back on default language.\n");
			lang = wxLANGUAGE_DEFAULT;
		}
		else
		{
			info = m_locale.GetLanguageInfo(lang);
			VTLOG("Initializing locale to language %d, Canonical name '%s', Description: '%s':\n", lang,
				(const char *) info->CanonicalName.mb_str(wxConvUTF8),
				(const char *) info->Description.mb_str(wxConvUTF8));
			bSuccess = m_locale.Init(lang, wxLOCALE_CONV_ENCODING);
		}
	}
	if (lang == wxLANGUAGE_DEFAULT)
	{
		VTLOG("Initializing locale to default language:\n");
		bSuccess = m_locale.Init(wxLANGUAGE_DEFAULT, wxLOCALE_CONV_ENCODING);
		if (bSuccess)
			lang = default_lang;
	}
	if (bSuccess)
		VTLOG(" succeeded.\n");
	else
		VTLOG(" failed.\n");

	if (lang != wxLANGUAGE_ENGLISH_US)
	{
		VTLOG("Attempting to load the 'VTBuilder.mo' catalog for the current locale.\n");
		bSuccess = m_locale.AddCatalog(wxT("VTBuilder"));
		if (bSuccess)
			VTLOG(" succeeded.\n");
		else
			VTLOG(" not found.\n");
		VTLOG("\n");
	}

	// Test it
//	wxString test = _("&File");

	wxLog::SetVerbose(false);
}

<|endoftext|>


<commit_before>#pragma once

#include "../utility/iterator_traits.hpp"
#include "sxml_parse_core.hpp"

namespace SXML
{
    namespace Internal
    {
        template <typename T, typename... L, template <typename...> class ContainerT>
        std::ostream& xml_parse_generic_container(
            ContainerT <T, L...>& value,
            std::string const& name,
            PropertyTree const& object,
            XmlParseOptions options = {},
            typename std::enable_if <
                    has_random_access_iterator <ContainerT, L...>::value
                ||  has_bidirectional_iterator <ContainerT, L...>::value
                ||  has_forward_iterator <ContainerT, L...>::value
            >::type* = nullptr)
        {
            try
            {
                GET_CHILD(name, pt, {});
                for (auto const& i : pt)
                {
                    T temp;
                    xml_parse(temp, "", i.second, options);
                    value.emplace_back(std::move(temp));
                }
            }
            DEFAULT_CATCH({}, {})
        }
    }
}
<commit_msg>Added parsing function for all kinds of containers.<commit_after>#pragma once

#include "../utility/iterator_traits.hpp"
#include "sxml_parse_core.hpp"

namespace SXML
{
    namespace Internal
    {
        template <typename T, typename... L, template <typename...> class ContainerT>
        void xml_parse_generic_container(
            ContainerT <T, L...>& value,
            std::string const& name,
            PropertyTree const& object,
            XmlParseOptions options = {},
            typename std::enable_if <
                    has_random_access_iterator <ContainerT, L...>::value
                ||  has_bidirectional_iterator <ContainerT, L...>::value
                ||  has_forward_iterator <ContainerT, L...>::value
            >::type* = nullptr)
        {
            try
            {
                GET_CHILD(name, pt, {});
                for (auto const& i : pt)
                {
                    T temp;
                    xml_parse(temp, "", i.second, options);
                    value.emplace_back(std::move(temp));
                }
            }
            DEFAULT_CATCH({}, {})
        }
    }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: formenums.cxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: obo $ $Date: 2004-07-05 16:09:05 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _XMLOFF_FORMENUMS_HXX_
#include "formenums.hxx"
#endif
#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif

#ifndef _COM_SUN_STAR_FORM_FORMSUBMITENCODING_HPP_
#include <com/sun/star/form/FormSubmitEncoding.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_FORMSUBMITMETHOD_HPP_
#include <com/sun/star/form/FormSubmitMethod.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
#include <com/sun/star/sdb/CommandType.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_NAVIGATIONBARMODE_HPP_
#include <com/sun/star/form/NavigationBarMode.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_TABULATORCYCLE_HPP_
#include <com/sun/star/form/TabulatorCycle.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_FORMBUTTONTYPE_HPP_
#include <com/sun/star/form/FormButtonType.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_LISTSOURCETYPE_HPP_
#include <com/sun/star/form/ListSourceType.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
#include <com/sun/star/awt/TextAlign.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTWIDTH_HPP_
#include <com/sun/star/awt/FontWidth.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTEMPHASISMARK_HPP_
#include <com/sun/star/awt/FontEmphasisMark.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTRELIEF_HPP_
#include <com/sun/star/awt/FontRelief.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_SCROLLBARORIENTATION_HPP_
#include <com/sun/star/awt/ScrollBarOrientation.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_VISUALEFFECT_HPP_
#include <com/sun/star/awt/VisualEffect.hpp>
#endif
#ifndef _SV_WINTYPES_HXX
#include <vcl/wintypes.hxx>     // for check states
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include "xmltoken.hxx"
#endif

//.........................................................................
namespace xmloff
{
//.........................................................................

    using namespace ::com::sun::star::form;
    using namespace ::com::sun::star::sdb;
    using namespace ::com::sun::star::awt;
    using namespace ::xmloff::token;

    const SvXMLEnumMapEntry*    OEnumMapper::s_pEnumMap[OEnumMapper::KNOWN_ENUM_PROPERTIES] =
    {
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL
    };

    //---------------------------------------------------------------------
    const SvXMLEnumMapEntry*    OEnumMapper::getEnumMap(EnumProperties _eProperty)
    {
        OSL_ENSURE(_eProperty < KNOWN_ENUM_PROPERTIES, "OEnumMapper::getEnumMap: invalid index (this will crash)!");

        const SvXMLEnumMapEntry*& rReturn = s_pEnumMap[_eProperty];
        if (!rReturn)
        {
            // the map for this property is not initialized yet
             switch (_eProperty)
            {
                // FormSubmitEncoding
                case epSubmitEncoding:
                {
                    static SvXMLEnumMapEntry aSubmitEncodingMap[] =
                    {
                        { XML_APPLICATION_X_WWW_FORM_URLENCODED, FormSubmitEncoding_URL },
                        { XML_MULTIPART_FORMDATA, FormSubmitEncoding_MULTIPART },
                        { XML_APPLICATION_TEXT, FormSubmitEncoding_TEXT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aSubmitEncodingMap;
                }
                break;
                // FormSubmitMethod
                case epSubmitMethod:
                {
                    static SvXMLEnumMapEntry aSubmitMethodMap[] =
                    {
                        { XML_GET, FormSubmitMethod_GET },
                        { XML_POST, FormSubmitMethod_POST },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aSubmitMethodMap;
                }
                break;
                // CommandType
                case epCommandType:
                {
                    static SvXMLEnumMapEntry aCommandTypeMap[] =
                    {
                        { XML_TABLE, CommandType::TABLE },
                        { XML_QUERY, CommandType::QUERY },
                        { XML_COMMAND, CommandType::COMMAND },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aCommandTypeMap;
                }
                break;
                // NavigationBarMode
                case epNavigationType:
                {
                    static SvXMLEnumMapEntry aNavigationTypeMap[] =
                    {
                        { XML_NONE, NavigationBarMode_NONE },
                        { XML_CURRENT, NavigationBarMode_CURRENT },
                        { XML_PARENT, NavigationBarMode_PARENT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aNavigationTypeMap;
                };
                break;
                // TabulatorCycle
                case epTabCyle:
                {
                    static SvXMLEnumMapEntry aTabulytorCycleMap[] =
                    {
                        { XML_RECORDS, TabulatorCycle_RECORDS },
                        { XML_CURRENT, TabulatorCycle_CURRENT },
                        { XML_PAGE, TabulatorCycle_PAGE },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aTabulytorCycleMap;
                };
                break;
                // FormButtonType
                case epButtonType:
                {
                    static SvXMLEnumMapEntry aFormButtonTypeMap[] =
                    {
                        { XML_PUSH, FormButtonType_PUSH },
                        { XML_SUBMIT, FormButtonType_SUBMIT },
                        { XML_RESET, FormButtonType_RESET },
                        { XML_URL, FormButtonType_URL },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aFormButtonTypeMap;
                };
                break;
                // ListSourceType
                case epListSourceType:
                {
                    static SvXMLEnumMapEntry aListSourceTypeMap[] =
                    {
                        { XML_VALUE_LIST, ListSourceType_VALUELIST },
                        { XML_TABLE, ListSourceType_TABLE },
                        { XML_QUERY, ListSourceType_QUERY },
                        { XML_SQL, ListSourceType_SQL },
                        { XML_SQL_PASS_THROUGH, ListSourceType_SQLPASSTHROUGH },
                        { XML_TABLE_FIELDS, ListSourceType_TABLEFIELDS },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aListSourceTypeMap;
                };
                break;
                // check state of a checkbox
                case epCheckState:
                {
                    static SvXMLEnumMapEntry aCheckStateMap[] =
                    {
                        { XML_UNCHECKED, STATE_NOCHECK },
                        { XML_CHECKED, STATE_CHECK },
                        { XML_UNKNOWN, STATE_DONTKNOW },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aCheckStateMap;
                };
                break;
                case epTextAlign:
                {
                    static SvXMLEnumMapEntry aTextAlignMap[] =
                    {
                        { XML_START,        TextAlign::LEFT },
                        { XML_CENTER,       TextAlign::CENTER },
                        { XML_END,          TextAlign::RIGHT },
                        { XML_JUSTIFY,      -1 },
                        { XML_JUSTIFIED,    -1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aTextAlignMap;
                };
                break;
                case epBorderWidth:
                {
                    static SvXMLEnumMapEntry aBorderTypeMap[] =
                    {
                        { XML_NONE,     0 },
                        { XML_HIDDEN,   0 },
                        { XML_SOLID,    2 },
                        { XML_DOUBLE,   2 },
                        { XML_DOTTED,   2 },
                        { XML_DASHED,   2 },
                        { XML_GROOVE,   1 },
                        { XML_RIDGE,    1 },
                        { XML_INSET,    1 },
                        { XML_OUTSET,   1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aBorderTypeMap;
                };
                break;

                case epFontEmphasis:
                {
                    static SvXMLEnumMapEntry aFontEmphasisMap[] =
                    {
                        { XML_NONE,     FontEmphasisMark::NONE },
                        { XML_DOT,      FontEmphasisMark::DOT },
                        { XML_CIRCLE,   FontEmphasisMark::CIRCLE },
                        { XML_DISC,     FontEmphasisMark::DISC },
                        { XML_ACCENT,   FontEmphasisMark::ACCENT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aFontEmphasisMap;
                }
                break;

                case epFontRelief:
                {
                    static SvXMLEnumMapEntry aFontReliefMap[] =
                    {
                        { XML_NONE,     FontRelief::NONE },
                        { XML_ENGRAVED, FontRelief::ENGRAVED },
                        { XML_EMBOSSED, FontRelief::EMBOSSED },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aFontReliefMap;
                }
                break;

                case epListLinkageType:
                {
                    static SvXMLEnumMapEntry aListLinkageMap[] =
                    {
                        { XML_SELECTION,            0 },
                        { XML_SELECTION_INDEXES,    1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aListLinkageMap;
                }
                break;

                case epOrientation:
                {
                    static SvXMLEnumMapEntry aOrientationMap[] =
                    {
                        { XML_HORIZONTAL,   ScrollBarOrientation::HORIZONTAL },
                        { XML_VERTICAL,     ScrollBarOrientation::VERTICAL },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aOrientationMap;
                }
                break;

                case epVisualEffect:
                {
                    static SvXMLEnumMapEntry aVisualEffectMap[] =
                    {
                        { XML_NONE, VisualEffect::NONE },
                        { XML_3D,   VisualEffect::LOOK3D },
                        { XML_FLAT, VisualEffect::FLAT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aVisualEffectMap;
                }
                break;

                case epImagePosition:
                {
                    static SvXMLEnumMapEntry aImagePositionMap[] =
                    {
                        { XML_START,  0 },
                        { XML_END,    1 },
                        { XML_TOP,    2 },
                        { XML_BOTTOM, 3 },
                        { XML_CENTER, -1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aImagePositionMap;
                }
                break;

                case epImageAlign:
                {
                    static SvXMLEnumMapEntry aImageAlignMap[] =
                    {
                        { XML_START,  0 },
                        { XML_CENTER, 1 },
                        { XML_END, 2 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aImageAlignMap;
                }
                break;
            }
        }

        return rReturn;
    }

//.........................................................................
}   // namespace xmloff
//.........................................................................

<commit_msg>INTEGRATION: CWS ooo19126 (1.12.302); FILE MERGED 2005/09/05 14:38:58 rt 1.12.302.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: formenums.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 14:09:06 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _XMLOFF_FORMENUMS_HXX_
#include "formenums.hxx"
#endif
#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif

#ifndef _COM_SUN_STAR_FORM_FORMSUBMITENCODING_HPP_
#include <com/sun/star/form/FormSubmitEncoding.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_FORMSUBMITMETHOD_HPP_
#include <com/sun/star/form/FormSubmitMethod.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
#include <com/sun/star/sdb/CommandType.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_NAVIGATIONBARMODE_HPP_
#include <com/sun/star/form/NavigationBarMode.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_TABULATORCYCLE_HPP_
#include <com/sun/star/form/TabulatorCycle.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_FORMBUTTONTYPE_HPP_
#include <com/sun/star/form/FormButtonType.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_LISTSOURCETYPE_HPP_
#include <com/sun/star/form/ListSourceType.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
#include <com/sun/star/awt/TextAlign.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTWIDTH_HPP_
#include <com/sun/star/awt/FontWidth.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTEMPHASISMARK_HPP_
#include <com/sun/star/awt/FontEmphasisMark.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTRELIEF_HPP_
#include <com/sun/star/awt/FontRelief.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_SCROLLBARORIENTATION_HPP_
#include <com/sun/star/awt/ScrollBarOrientation.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_VISUALEFFECT_HPP_
#include <com/sun/star/awt/VisualEffect.hpp>
#endif
#ifndef _SV_WINTYPES_HXX
#include <vcl/wintypes.hxx>     // for check states
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include "xmltoken.hxx"
#endif

//.........................................................................
namespace xmloff
{
//.........................................................................

    using namespace ::com::sun::star::form;
    using namespace ::com::sun::star::sdb;
    using namespace ::com::sun::star::awt;
    using namespace ::xmloff::token;

    const SvXMLEnumMapEntry*    OEnumMapper::s_pEnumMap[OEnumMapper::KNOWN_ENUM_PROPERTIES] =
    {
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL
    };

    //---------------------------------------------------------------------
    const SvXMLEnumMapEntry*    OEnumMapper::getEnumMap(EnumProperties _eProperty)
    {
        OSL_ENSURE(_eProperty < KNOWN_ENUM_PROPERTIES, "OEnumMapper::getEnumMap: invalid index (this will crash)!");

        const SvXMLEnumMapEntry*& rReturn = s_pEnumMap[_eProperty];
        if (!rReturn)
        {
            // the map for this property is not initialized yet
             switch (_eProperty)
            {
                // FormSubmitEncoding
                case epSubmitEncoding:
                {
                    static SvXMLEnumMapEntry aSubmitEncodingMap[] =
                    {
                        { XML_APPLICATION_X_WWW_FORM_URLENCODED, FormSubmitEncoding_URL },
                        { XML_MULTIPART_FORMDATA, FormSubmitEncoding_MULTIPART },
                        { XML_APPLICATION_TEXT, FormSubmitEncoding_TEXT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aSubmitEncodingMap;
                }
                break;
                // FormSubmitMethod
                case epSubmitMethod:
                {
                    static SvXMLEnumMapEntry aSubmitMethodMap[] =
                    {
                        { XML_GET, FormSubmitMethod_GET },
                        { XML_POST, FormSubmitMethod_POST },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aSubmitMethodMap;
                }
                break;
                // CommandType
                case epCommandType:
                {
                    static SvXMLEnumMapEntry aCommandTypeMap[] =
                    {
                        { XML_TABLE, CommandType::TABLE },
                        { XML_QUERY, CommandType::QUERY },
                        { XML_COMMAND, CommandType::COMMAND },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aCommandTypeMap;
                }
                break;
                // NavigationBarMode
                case epNavigationType:
                {
                    static SvXMLEnumMapEntry aNavigationTypeMap[] =
                    {
                        { XML_NONE, NavigationBarMode_NONE },
                        { XML_CURRENT, NavigationBarMode_CURRENT },
                        { XML_PARENT, NavigationBarMode_PARENT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aNavigationTypeMap;
                };
                break;
                // TabulatorCycle
                case epTabCyle:
                {
                    static SvXMLEnumMapEntry aTabulytorCycleMap[] =
                    {
                        { XML_RECORDS, TabulatorCycle_RECORDS },
                        { XML_CURRENT, TabulatorCycle_CURRENT },
                        { XML_PAGE, TabulatorCycle_PAGE },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aTabulytorCycleMap;
                };
                break;
                // FormButtonType
                case epButtonType:
                {
                    static SvXMLEnumMapEntry aFormButtonTypeMap[] =
                    {
                        { XML_PUSH, FormButtonType_PUSH },
                        { XML_SUBMIT, FormButtonType_SUBMIT },
                        { XML_RESET, FormButtonType_RESET },
                        { XML_URL, FormButtonType_URL },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aFormButtonTypeMap;
                };
                break;
                // ListSourceType
                case epListSourceType:
                {
                    static SvXMLEnumMapEntry aListSourceTypeMap[] =
                    {
                        { XML_VALUE_LIST, ListSourceType_VALUELIST },
                        { XML_TABLE, ListSourceType_TABLE },
                        { XML_QUERY, ListSourceType_QUERY },
                        { XML_SQL, ListSourceType_SQL },
                        { XML_SQL_PASS_THROUGH, ListSourceType_SQLPASSTHROUGH },
                        { XML_TABLE_FIELDS, ListSourceType_TABLEFIELDS },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aListSourceTypeMap;
                };
                break;
                // check state of a checkbox
                case epCheckState:
                {
                    static SvXMLEnumMapEntry aCheckStateMap[] =
                    {
                        { XML_UNCHECKED, STATE_NOCHECK },
                        { XML_CHECKED, STATE_CHECK },
                        { XML_UNKNOWN, STATE_DONTKNOW },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aCheckStateMap;
                };
                break;
                case epTextAlign:
                {
                    static SvXMLEnumMapEntry aTextAlignMap[] =
                    {
                        { XML_START,        TextAlign::LEFT },
                        { XML_CENTER,       TextAlign::CENTER },
                        { XML_END,          TextAlign::RIGHT },
                        { XML_JUSTIFY,      -1 },
                        { XML_JUSTIFIED,    -1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aTextAlignMap;
                };
                break;
                case epBorderWidth:
                {
                    static SvXMLEnumMapEntry aBorderTypeMap[] =
                    {
                        { XML_NONE,     0 },
                        { XML_HIDDEN,   0 },
                        { XML_SOLID,    2 },
                        { XML_DOUBLE,   2 },
                        { XML_DOTTED,   2 },
                        { XML_DASHED,   2 },
                        { XML_GROOVE,   1 },
                        { XML_RIDGE,    1 },
                        { XML_INSET,    1 },
                        { XML_OUTSET,   1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aBorderTypeMap;
                };
                break;

                case epFontEmphasis:
                {
                    static SvXMLEnumMapEntry aFontEmphasisMap[] =
                    {
                        { XML_NONE,     FontEmphasisMark::NONE },
                        { XML_DOT,      FontEmphasisMark::DOT },
                        { XML_CIRCLE,   FontEmphasisMark::CIRCLE },
                        { XML_DISC,     FontEmphasisMark::DISC },
                        { XML_ACCENT,   FontEmphasisMark::ACCENT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aFontEmphasisMap;
                }
                break;

                case epFontRelief:
                {
                    static SvXMLEnumMapEntry aFontReliefMap[] =
                    {
                        { XML_NONE,     FontRelief::NONE },
                        { XML_ENGRAVED, FontRelief::ENGRAVED },
                        { XML_EMBOSSED, FontRelief::EMBOSSED },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aFontReliefMap;
                }
                break;

                case epListLinkageType:
                {
                    static SvXMLEnumMapEntry aListLinkageMap[] =
                    {
                        { XML_SELECTION,            0 },
                        { XML_SELECTION_INDEXES,    1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aListLinkageMap;
                }
                break;

                case epOrientation:
                {
                    static SvXMLEnumMapEntry aOrientationMap[] =
                    {
                        { XML_HORIZONTAL,   ScrollBarOrientation::HORIZONTAL },
                        { XML_VERTICAL,     ScrollBarOrientation::VERTICAL },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aOrientationMap;
                }
                break;

                case epVisualEffect:
                {
                    static SvXMLEnumMapEntry aVisualEffectMap[] =
                    {
                        { XML_NONE, VisualEffect::NONE },
                        { XML_3D,   VisualEffect::LOOK3D },
                        { XML_FLAT, VisualEffect::FLAT },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aVisualEffectMap;
                }
                break;

                case epImagePosition:
                {
                    static SvXMLEnumMapEntry aImagePositionMap[] =
                    {
                        { XML_START,  0 },
                        { XML_END,    1 },
                        { XML_TOP,    2 },
                        { XML_BOTTOM, 3 },
                        { XML_CENTER, -1 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aImagePositionMap;
                }
                break;

                case epImageAlign:
                {
                    static SvXMLEnumMapEntry aImageAlignMap[] =
                    {
                        { XML_START,  0 },
                        { XML_CENTER, 1 },
                        { XML_END, 2 },
                        { XML_TOKEN_INVALID, 0 }
                    };
                    rReturn = aImageAlignMap;
                }
                break;
            }
        }

        return rReturn;
    }

//.........................................................................
}   // namespace xmloff
//.........................................................................

<|endoftext|>


<commit_before>/*
 * slave2.cpp - slave2 program for Team Pi
 *
 *
 * by Brian Chen
 * Originally authored in November 2014
 * (C) Team PI 2015
 */

#include <WProgram.h>
#include <t3spi.h>
#include <TSOPS.h>
#include <piCommon.h>
#include <DebugUtils.h>

/**********************************************************/
/*					   General						  */
/**********************************************************/
#define LED 13
uint8_t status = 0;	 // status of program/slave

/**********************************************************/
/*				  Battery monitoring					*/
/**********************************************************/
#define VBAT_LV_PIN A11
#define VBAT_HV_PIN A10

volatile uint8_t vbatLV, vbatHV;
/**********************************************************/
/*						 SPI							*/
/**********************************************************/

T3SPI SPI; // create SPI object
volatile uint8_t dataOut, dataIn; // SPI input/output bytes
volatile uint8_t command = 255;

// blink
elapsedMillis ledElapsedTime;

bool ledState = true;
uint32_t ledBlinkTime = 500;

/**********************************************************/
/*						TSOPS						   */
/**********************************************************/
/* 40kHz Anything lower than 25us is overkill. For some reason though
   it seems like it actually updates every 20uS when I read using
   elapsedMicros */
   // wait
#define ISR_INTERVAL 50
//#define ISR_INTERVAL 2500

#define TSOP_RESOLUTION 255

bool tsopsOn = true;

IntervalTimer TSOP_ISR_Timer;
volatile uint32_t TSOP_ISR_Count = 0;

TSOPS tsops; // TSOPS object
volatile uint8_t tsopAngleByte_vol;
volatile uint8_t tsopStrength_vol;

/* though tsops already has a member for the data, it's continuously
   updated and incomplete this variable array stores the most recent
   tsop data that has been complete (after 255 interrupts) */
uint8_t tsopData[TSOP_COUNT];

inline void initBatReadings();
inline void readBat();
inline void initSPI();
inline void ledBlink();
void TSOP_ISR();

int main(){
	noInterrupts();

	CORE_PIN33_CONFIG = 0;  // completely disables the pin

	pinMode(13, OUTPUT);

	digitalWrite(13, LOW);
	Serial.begin(115200); // nice number but it doesn't actually matter for the Teensy 3.x
	digitalWrite(13, LOW);

	tsops.begin();	 // initialise TSOPS
	tsops.angle = 999; // for debugging purposes, initially set angle as this

	digitalWrite(13, LOW);
	initBatReadings(); // initialise battery readings
	digitalWrite(13, LOW);

	initSPI();		 // initialise SPI slave
	digitalWrite(13, HIGH);
	/* set TSOP ISR priority 0 to 255, 0 being the highest (127 default)
	   we don't want the interrupt to interfer with SPI too much. However */
	TSOP_ISR_Timer.priority(127);
	digitalWrite(13, LOW);
	// attach TSOP ISR
	TSOP_ISR_Timer.begin(TSOP_ISR, ISR_INTERVAL);
	digitalWrite(13, HIGH);
	interrupts();	  // enable interrupts

	while(1){
	}

	return 0;		  // it'll never reach here
}

// Initialise battery readings
inline void initBatReadings(){
	pinMode(VBAT_LV_PIN, INPUT);
	pinMode(VBAT_HV_PIN, INPUT);
	analogReference(EXTERNAL);  // IMPORTANT!
	analogReadResolution(8);	// Don't need more than 8 bits of resolution (they're just batteries)
	analogReadAveraging(32);	// highest averaging as we don't need fast sampling
}

// Simple reading of batteries
inline void readBat(){
	vbatLV = analogRead(VBAT_LV_PIN);
	vbatHV = analogRead(VBAT_HV_PIN);
}

inline void ledBlink(){
	// led blinking
	if (ledElapsedTime > ledBlinkTime){
		if (ledState){
			digitalWriteFast(LED, HIGH);
		}
		else{
			digitalWriteFast(LED, LOW);
		}
		ledState = !ledState;
		ledElapsedTime = 0;
	}
}

// Initialise SPI as slave
inline void initSPI(){
	SPI.begin_SLAVE(ALT_SCK, MOSI, MISO, CS0);
	SPI.setCTAR_SLAVE(8, SPI_MODE0);
	NVIC_SET_PRIORITY(IRQ_SPI0, 127); // set priority
	// Enable the SPI0 Interrupt
	NVIC_ENABLE_IRQ(IRQ_SPI0);
}

/* Interrupt Service Routine to handle incoming data
   For best performance, direct access to hardware SPI registers are used (instead of via lib) */
void spi0_isr(){
	//noInterrupts();
	//SPIRequestTime = millis();
	command = SPI0_POPR;
	switch(command){
		//case 255: command = c; SPI0_PUSHR_SLAVE = 0; break;
		case 0: SPI0_PUSHR_SLAVE = 0; break;
		// case SLAVE2_COMMANDS::SLAVE2_CHECK_STATUS: SPI0_PUSHR_SLAVE = status;				 break;
		// case SLAVE2_COMMANDS::TSOP_DATA0:		   SPI0_PUSHR_SLAVE = tsopData[0];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA1:		   SPI0_PUSHR_SLAVE = tsopData[1];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA2:		   SPI0_PUSHR_SLAVE = tsopData[2];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA3:		   SPI0_PUSHR_SLAVE = tsopData[3];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA4:		   SPI0_PUSHR_SLAVE = tsopData[4];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA5:		   SPI0_PUSHR_SLAVE = tsopData[5];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA6:		   SPI0_PUSHR_SLAVE = tsopData[6];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA7:		   SPI0_PUSHR_SLAVE = tsopData[7];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA8:		   SPI0_PUSHR_SLAVE = tsopData[8];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA9:		   SPI0_PUSHR_SLAVE = tsopData[9];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA10:		   SPI0_PUSHR_SLAVE = tsopData[10];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA11:		   SPI0_PUSHR_SLAVE = tsopData[11];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA12:		   SPI0_PUSHR_SLAVE = tsopData[12];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA13:		   SPI0_PUSHR_SLAVE = tsopData[13];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA14:		   SPI0_PUSHR_SLAVE = tsopData[14];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA15:		   SPI0_PUSHR_SLAVE = tsopData[15];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA16:		   SPI0_PUSHR_SLAVE = tsopData[16];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA17:		   SPI0_PUSHR_SLAVE = tsopData[17];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA18:		   SPI0_PUSHR_SLAVE = tsopData[18];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA19:		   SPI0_PUSHR_SLAVE = tsopData[19];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA20:		   SPI0_PUSHR_SLAVE = tsopData[20];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA21:		   SPI0_PUSHR_SLAVE = tsopData[21];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA22:		   SPI0_PUSHR_SLAVE = tsopData[22];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA23:		   SPI0_PUSHR_SLAVE = tsopData[23];		     break;
		// case SLAVE2_COMMANDS::VBAT_REF_LV:		   SPI0_PUSHR_SLAVE = vbatLV;				 break;
		// case SLAVE2_COMMANDS::VBAT_REF_HV:		   SPI0_PUSHR_SLAVE = vbatHV;				 break;
		// case SLAVE2_COMMANDS::TSOP_ANGLE_HIGH:	   SPI0_PUSHR_SLAVE = highByte(tsops.angle); break;
		// case SLAVE2_COMMANDS::TSOP_ANGLE_LOW:	   SPI0_PUSHR_SLAVE = lowByte(tsops.angle);  break;
		case SLAVE2_COMMANDS::TSOP_ANGLE_BYTE:	   SPI0_PUSHR_SLAVE = tsops.angleByte;		 	 break;
		case SLAVE2_COMMANDS::TSOP_STRENGTH:	   SPI0_PUSHR_SLAVE = tsops.averageStrength; 	 break;
		default:  SPI0_PUSHR_SLAVE = 0;	break;
	}
	ledBlinkTime = 500;
	SPI0_SR |= SPI_SR_RFDF;
	//Serial.println("command"); //interrupts();
}

// Routine to read tsops (as well as batteries)
void TSOP_ISR(){
	TSOP_ISR_Count++;
	if (tsopsOn){
		tsops.read();
	}
	else{
		ledBlinkTime = 50;
		Serial.println(tsops.angle);
	}
	// else, we're in a stage where we're unlocking the tsops.

	if (TSOP_ISR_Count % TSOP_RESOLUTION == 0){
		// TSOP_ISR_Count = 0;

		// if tsops aren't on turn them on
		if (!tsopsOn){
			tsops.on();
			tsopsOn = true;
		}
		else{
			tsops.finishRead(); // call this every time you've finished reading

			tsops.filterData();
			tsops.getStrength();
			tsops.getAngle();

		}
		// unlock tsops and read batteries. Must be a multiple of RESOLUTION!
		if (TSOP_ISR_Count == TSOP_RESOLUTION * 50){
			// 25500 * 25us = 0.6375s
			tsops.off();
			tsopsOn = false; // this tells the program to wait before turning tsops back on
			readBat();	// don't need to read batteries that often
			TSOP_ISR_Count = 0;
		}
	}
	else{
		ledBlink();
	}
}<commit_msg>added printing of tsop strength as well as angle<commit_after>/*
 * slave2.cpp - slave2 program for Team Pi
 *
 *
 * by Brian Chen
 * Originally authored in November 2014
 * (C) Team PI 2015
 */

#include <WProgram.h>
#include <t3spi.h>
#include <TSOPS.h>
#include <piCommon.h>
#include <DebugUtils.h>

/**********************************************************/
/*					   General						  */
/**********************************************************/
#define LED 13
uint8_t status = 0;	 // status of program/slave

/**********************************************************/
/*				  Battery monitoring					*/
/**********************************************************/
#define VBAT_LV_PIN A11
#define VBAT_HV_PIN A10

volatile uint8_t vbatLV, vbatHV;
/**********************************************************/
/*						 SPI							*/
/**********************************************************/

T3SPI SPI; // create SPI object
volatile uint8_t dataOut, dataIn; // SPI input/output bytes
volatile uint8_t command = 255;

// blink
elapsedMillis ledElapsedTime;

bool ledState = true;
uint32_t ledBlinkTime = 500;

/**********************************************************/
/*						TSOPS						   */
/**********************************************************/
/* 40kHz Anything lower than 25us is overkill. For some reason though
   it seems like it actually updates every 20uS when I read using
   elapsedMicros */
   // wait
#define ISR_INTERVAL 50
//#define ISR_INTERVAL 2500

#define TSOP_RESOLUTION 255

bool tsopsOn = true;

IntervalTimer TSOP_ISR_Timer;
volatile uint32_t TSOP_ISR_Count = 0;

TSOPS tsops; // TSOPS object
volatile uint8_t tsopAngleByte_vol;
volatile uint8_t tsopStrength_vol;

/* though tsops already has a member for the data, it's continuously
   updated and incomplete this variable array stores the most recent
   tsop data that has been complete (after 255 interrupts) */
uint8_t tsopData[TSOP_COUNT];

inline void initBatReadings();
inline void readBat();
inline void initSPI();
inline void ledBlink();
void TSOP_ISR();

int main(){
	noInterrupts();

	CORE_PIN33_CONFIG = 0;  // completely disables the pin

	pinMode(13, OUTPUT);

	digitalWrite(13, LOW);
	Serial.begin(115200); // nice number but it doesn't actually matter for the Teensy 3.x
	digitalWrite(13, LOW);

	tsops.begin();	 // initialise TSOPS
	tsops.angle = 999; // for debugging purposes, initially set angle as this

	digitalWrite(13, LOW);
	initBatReadings(); // initialise battery readings
	digitalWrite(13, LOW);

	initSPI();		 // initialise SPI slave
	digitalWrite(13, HIGH);
	/* set TSOP ISR priority 0 to 255, 0 being the highest (127 default)
	   we don't want the interrupt to interfer with SPI too much. However */
	TSOP_ISR_Timer.priority(127);
	digitalWrite(13, LOW);
	// attach TSOP ISR
	TSOP_ISR_Timer.begin(TSOP_ISR, ISR_INTERVAL);
	digitalWrite(13, HIGH);
	interrupts();	  // enable interrupts

	while(1){
	}

	return 0;		  // it'll never reach here
}

// Initialise battery readings
inline void initBatReadings(){
	pinMode(VBAT_LV_PIN, INPUT);
	pinMode(VBAT_HV_PIN, INPUT);
	analogReference(EXTERNAL);  // IMPORTANT!
	analogReadResolution(8);	// Don't need more than 8 bits of resolution (they're just batteries)
	analogReadAveraging(32);	// highest averaging as we don't need fast sampling
}

// Simple reading of batteries
inline void readBat(){
	vbatLV = analogRead(VBAT_LV_PIN);
	vbatHV = analogRead(VBAT_HV_PIN);
}

inline void ledBlink(){
	// led blinking
	if (ledElapsedTime > ledBlinkTime){
		if (ledState){
			digitalWriteFast(LED, HIGH);
		}
		else{
			digitalWriteFast(LED, LOW);
		}
		ledState = !ledState;
		ledElapsedTime = 0;
	}
}

// Initialise SPI as slave
inline void initSPI(){
	SPI.begin_SLAVE(ALT_SCK, MOSI, MISO, CS0);
	SPI.setCTAR_SLAVE(8, SPI_MODE0);
	NVIC_SET_PRIORITY(IRQ_SPI0, 127); // set priority
	// Enable the SPI0 Interrupt
	NVIC_ENABLE_IRQ(IRQ_SPI0);
}

/* Interrupt Service Routine to handle incoming data
   For best performance, direct access to hardware SPI registers are used (instead of via lib) */
void spi0_isr(){
	//noInterrupts();
	//SPIRequestTime = millis();
	command = SPI0_POPR;
	switch(command){
		//case 255: command = c; SPI0_PUSHR_SLAVE = 0; break;
		case 0: SPI0_PUSHR_SLAVE = 0; break;
		// case SLAVE2_COMMANDS::SLAVE2_CHECK_STATUS: SPI0_PUSHR_SLAVE = status;				 break;
		// case SLAVE2_COMMANDS::TSOP_DATA0:		   SPI0_PUSHR_SLAVE = tsopData[0];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA1:		   SPI0_PUSHR_SLAVE = tsopData[1];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA2:		   SPI0_PUSHR_SLAVE = tsopData[2];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA3:		   SPI0_PUSHR_SLAVE = tsopData[3];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA4:		   SPI0_PUSHR_SLAVE = tsopData[4];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA5:		   SPI0_PUSHR_SLAVE = tsopData[5];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA6:		   SPI0_PUSHR_SLAVE = tsopData[6];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA7:		   SPI0_PUSHR_SLAVE = tsopData[7];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA8:		   SPI0_PUSHR_SLAVE = tsopData[8];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA9:		   SPI0_PUSHR_SLAVE = tsopData[9];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA10:		   SPI0_PUSHR_SLAVE = tsopData[10];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA11:		   SPI0_PUSHR_SLAVE = tsopData[11];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA12:		   SPI0_PUSHR_SLAVE = tsopData[12];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA13:		   SPI0_PUSHR_SLAVE = tsopData[13];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA14:		   SPI0_PUSHR_SLAVE = tsopData[14];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA15:		   SPI0_PUSHR_SLAVE = tsopData[15];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA16:		   SPI0_PUSHR_SLAVE = tsopData[16];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA17:		   SPI0_PUSHR_SLAVE = tsopData[17];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA18:		   SPI0_PUSHR_SLAVE = tsopData[18];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA19:		   SPI0_PUSHR_SLAVE = tsopData[19];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA20:		   SPI0_PUSHR_SLAVE = tsopData[20];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA21:		   SPI0_PUSHR_SLAVE = tsopData[21];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA22:		   SPI0_PUSHR_SLAVE = tsopData[22];		     break;
		// case SLAVE2_COMMANDS::TSOP_DATA23:		   SPI0_PUSHR_SLAVE = tsopData[23];		     break;
		// case SLAVE2_COMMANDS::VBAT_REF_LV:		   SPI0_PUSHR_SLAVE = vbatLV;				 break;
		// case SLAVE2_COMMANDS::VBAT_REF_HV:		   SPI0_PUSHR_SLAVE = vbatHV;				 break;
		// case SLAVE2_COMMANDS::TSOP_ANGLE_HIGH:	   SPI0_PUSHR_SLAVE = highByte(tsops.angle); break;
		// case SLAVE2_COMMANDS::TSOP_ANGLE_LOW:	   SPI0_PUSHR_SLAVE = lowByte(tsops.angle);  break;
		case SLAVE2_COMMANDS::TSOP_ANGLE_BYTE:	   SPI0_PUSHR_SLAVE = tsops.angleByte;		 	 break;
		case SLAVE2_COMMANDS::TSOP_STRENGTH:	   SPI0_PUSHR_SLAVE = tsops.averageStrength; 	 break;
		default:  SPI0_PUSHR_SLAVE = 0;	break;
	}
	ledBlinkTime = 500;
	SPI0_SR |= SPI_SR_RFDF;
	//Serial.println("command"); //interrupts();
}

// Routine to read tsops (as well as batteries)
void TSOP_ISR(){
	TSOP_ISR_Count++;
	if (tsopsOn){
		tsops.read();
	}
	else{
		ledBlinkTime = 50;
		Serial.print(tsops.averageStrength);
		Serial.print('\t');
		Serial.println(tsops.angle);
	}
	// else, we're in a stage where we're unlocking the tsops.

	if (TSOP_ISR_Count % TSOP_RESOLUTION == 0){
		// TSOP_ISR_Count = 0;

		// if tsops aren't on turn them on
		if (!tsopsOn){
			tsops.on();
			tsopsOn = true;
		}
		else{
			tsops.finishRead(); // call this every time you've finished reading

			tsops.filterData();
			tsops.getStrength();
			tsops.getAngle();

		}
		// unlock tsops and read batteries. Must be a multiple of RESOLUTION!
		if (TSOP_ISR_Count == TSOP_RESOLUTION * 50){
			// 25500 * 25us = 0.6375s
			tsops.off();
			tsopsOn = false; // this tells the program to wait before turning tsops back on
			readBat();	// don't need to read batteries that often
			TSOP_ISR_Count = 0;
		}
	}
	else{
		ledBlink();
	}
}<|endoftext|>