<commit_before>/*************************************************************************
 *
 *  $RCSfile: FilteredContainer.cxx,v $
 *
 *  $Revision: 1.1 $
 *
 *  last change: $Author: oj $ $Date: 2002-08-23 05:55:09 $
 *
 *  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 EXPRESSED 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 DBACCESS_CORE_FILTERED_CONTAINER_HXX
#include "FilteredContainer.hxx"
#endif
#ifndef DBA_CORE_REFRESHLISTENER_HXX
#include "RefreshListener.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
#include <com/sun/star/sdbc/XRow.hpp>
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef _WLDCRD_HXX
#include <tools/wldcrd.hxx>
#endif

namespace dbaccess
{
    using namespace dbtools;
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace ::com::sun::star::sdbc;
    using namespace ::com::sun::star::sdb;
    using namespace ::com::sun::star::sdbcx;
    using namespace ::com::sun::star::util;
    using namespace ::com::sun::star::container;
    using namespace ::osl;
    using namespace ::comphelper;
    using namespace ::cppu;
    using namespace ::connectivity::sdbcx;

    //------------------------------------------------------------------------------
    /** compare two strings
    */
    extern int
    #if defined( WNT )
     __cdecl
    #endif
    #if defined( ICC ) && defined( OS2 )
    _Optlink
    #endif
    NameCompare( const void* pFirst, const void* pSecond)
    {
        return reinterpret_cast< const ::rtl::OUString* >(pFirst)->compareTo(*reinterpret_cast< const ::rtl::OUString* >(pSecond));
    }
    //------------------------------------------------------------------------------
    /** creates a vector of WildCards and reduce the _rTableFilter of the length of WildsCards
    */
    sal_Int32 createWildCardVector(Sequence< ::rtl::OUString >& _rTableFilter, ::std::vector< WildCard >& _rOut)
    {
        // for wildcard search : remove all table filters which are a wildcard expression and build a WilCard
        // for them
        ::rtl::OUString* pTableFilters = _rTableFilter.getArray();
        ::rtl::OUString* pEnd          = pTableFilters + _rTableFilter.getLength();
        sal_Int32 nShiftPos = 0;
        for (sal_Int32 i=0; pEnd != pTableFilters; ++pTableFilters,++i)
        {
            if (pTableFilters->indexOf('%') != -1)
            {
                _rOut.push_back(WildCard(pTableFilters[i].replace('%', '*')));
            }
            else
            {
                if (nShiftPos != i)
                    pTableFilters[nShiftPos] = pTableFilters[i];
                ++nShiftPos;
            }
        }
        // now aTableFilter contains nShiftPos non-wc-strings and aWCSearch all wc-strings
        _rTableFilter.realloc(nShiftPos);
        return nShiftPos;
    }

    //==========================================================================
    //= OViewContainer
    //==========================================================================
    OFilteredContainer::OFilteredContainer(::cppu::OWeakObject& _rParent,
                                 ::osl::Mutex& _rMutex,
                                 const Reference< XConnection >& _xCon,
                                 sal_Bool _bCase,
                                 IRefreshListener*  _pRefreshListener,
                                 IWarningsContainer* _pWarningsContainer)
    :OCollection(_rParent,_bCase,_rMutex,::std::vector< ::rtl::OUString>())
    ,m_bConstructed(sal_False)
    ,m_xConnection(_xCon)
    ,m_pWarningsContainer(_pWarningsContainer)
    ,m_pRefreshListener(_pRefreshListener)
    {
        try
        {
            m_xMetaData = _xCon->getMetaData();
        }
        catch(SQLException&)
        {
        }
    }
    // -------------------------------------------------------------------------
    void OFilteredContainer::construct(const Reference< XNameAccess >& _rxMasterContainer,
                                    const Sequence< ::rtl::OUString >& _rTableFilter,
                                    const Sequence< ::rtl::OUString >& _rTableTypeFilter)
    {
        m_xMasterContainer = _rxMasterContainer;

        if(m_xMasterContainer.is())
        {
            addMasterContainerListener();
            sal_Int32   nTableFilterLen = _rTableFilter.getLength();

            connectivity::TStringVector aTableNames;
            sal_Bool bNoTableFilters = ((nTableFilterLen == 1) && _rTableFilter[0].equalsAsciiL("%", 1));
            if(!bNoTableFilters)
            {
                Sequence< ::rtl::OUString > aTableFilter        = _rTableFilter;
                Sequence< ::rtl::OUString > aTableTypeFilter    = _rTableTypeFilter;
                // build sorted versions of the filter sequences, so the visibility decision is faster
                qsort(aTableFilter.getArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare);

                // as we want to modify nTableFilterLen, remember this

                // for wildcard search : remove all table filters which are a wildcard expression and build a WilCard
                // for them
                ::std::vector< WildCard > aWCSearch; // contains the wildcards for the table filter
                nTableFilterLen = createWildCardVector(aTableFilter,aWCSearch);

                aTableNames.reserve(nTableFilterLen + (aWCSearch.size() * 10));

                Sequence< ::rtl::OUString> aNames = m_xMasterContainer->getElementNames();
                const ::rtl::OUString* pBegin   = aNames.getConstArray();
                const ::rtl::OUString* pEnd     = pBegin + aNames.getLength();
                for(;pBegin != pEnd;++pBegin)
                {
                    if(isNameValid(*pBegin,aTableFilter,aTableTypeFilter,aWCSearch))
                        aTableNames.push_back(*pBegin);
                }
            }
            else
            {
                // no filter so insert all names
                Sequence< ::rtl::OUString> aNames = m_xMasterContainer->getElementNames();
                const ::rtl::OUString* pBegin   = aNames.getConstArray();
                const ::rtl::OUString* pEnd     = pBegin + aNames.getLength();
                aTableNames = connectivity::TStringVector(pBegin,pEnd);
            }
            reFill(aTableNames);
            m_bConstructed = sal_True;
        }
        else
        {
            construct(_rTableFilter,_rTableTypeFilter);
        }
    }
    //------------------------------------------------------------------------------
    void OFilteredContainer::construct(const Sequence< ::rtl::OUString >& _rTableFilter, const Sequence< ::rtl::OUString >& _rTableTypeFilter)
    {
        // build sorted versions of the filter sequences, so the visibility decision is faster
        Sequence< ::rtl::OUString > aTableFilter(_rTableFilter);
        sal_Int32   nTableFilterLen = aTableFilter.getLength();

        if (nTableFilterLen)
            qsort(aTableFilter.getArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare);

        sal_Bool bNoTableFilters = ((nTableFilterLen == 1) && _rTableFilter[0].equalsAsciiL("%", 1));
            // as we want to modify nTableFilterLen, remember this

        // for wildcard search : remove all table filters which are a wildcard expression and build a WilCard
        // for them
        ::std::vector< WildCard > aWCSearch;
        nTableFilterLen = createWildCardVector(aTableFilter,aWCSearch);

        try
        {
            if (m_xMetaData.is())
            {
                static const ::rtl::OUString sAll = ::rtl::OUString::createFromAscii("%");
                Sequence< ::rtl::OUString > sTableTypes = getTableTypeFilter(_rTableTypeFilter);
                if ( m_bConstructed && sTableTypes.getLength() == 0 )
                    return;

                Reference< XResultSet > xTables = m_xMetaData->getTables(Any(), sAll, sAll, sTableTypes);
                Reference< XRow > xCurrentRow(xTables, UNO_QUERY);
                if (xCurrentRow.is())
                {

                        // after creation the set is positioned before the first record, per definitionem

                    ::rtl::OUString sCatalog, sSchema, sName, sType;
                    ::rtl::OUString sComposedName;

                    // we first collect the names and construct the OTable objects later, as the ctor of the table may need
                    // another result set from the connection, and some drivers support only one statement per connection

                    sal_Bool bFilterMatch;
                    while (xTables->next())
                    {
                        sCatalog    = xCurrentRow->getString(1);
                        sSchema     = xCurrentRow->getString(2);
                        sName       = xCurrentRow->getString(3);
                        // we're not interested in the "wasNull", as the getStrings would return an empty string in
                        // that case, which is sufficient here

                        composeTableName(m_xMetaData, sCatalog, sSchema, sName, sComposedName, sal_False);
                        bFilterMatch =  bNoTableFilters
                                    ||  ((nTableFilterLen != 0) && (NULL != bsearch(&sComposedName, aTableFilter.getConstArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare)));
                        // the table is allowed to "pass" if we had no filters at all or any of the non-wildcard filters matches

                        if (!bFilterMatch && aWCSearch.size())
                        {   // or if one of the wildcrad expression matches
                            for (   ::std::vector< WildCard >::const_iterator aLoop = aWCSearch.begin();
                                    aLoop != aWCSearch.end() && !bFilterMatch;
                                    ++aLoop
                                )
                                bFilterMatch = aLoop->Matches(sComposedName);
                        }

                        if (bFilterMatch)
                        {   // the table name is allowed (not filtered out)
                            insertElement(sComposedName,NULL);
                        }
                    }

                    // dispose the tables result set, in case the connection can handle only one concurrent statement
                    // (the table object creation will need it's own statements)
                    disposeComponent(xTables);
                }
                else
                    OSL_ENSURE(0,"OFilteredContainer::construct : did not get a XRow from the tables result set !");
            }
            else
                OSL_ENSURE(0,"OFilteredContainer::construct : no connection meta data !");
        }
        catch (SQLException&)
        {
            OSL_ENSURE(0,"OFilteredContainer::construct : catched an SQL-Exception !");
            disposing();
            return;
        }

        m_bConstructed = sal_True;
    }
    //------------------------------------------------------------------------------
    void OFilteredContainer::disposing()
    {
        OCollection::disposing();
        removeMasterContainerListener();

        m_xMasterContainer  = NULL;
        m_xMetaData         = NULL;
        m_xConnection       = NULL;
        m_pWarningsContainer = NULL;
        m_pRefreshListener  = NULL;
        m_bConstructed      = sal_False;
    }
    // -------------------------------------------------------------------------
    void OFilteredContainer::impl_refresh() throw(RuntimeException)
    {
        if ( m_pRefreshListener )
        {
            m_bConstructed = sal_False;
            Reference<XRefreshable> xRefresh(m_xMasterContainer,UNO_QUERY);
            if ( xRefresh.is() )
                xRefresh->refresh();
            m_pRefreshListener->refresh(this);
        }
    }
    // -------------------------------------------------------------------------
    sal_Bool OFilteredContainer::isNameValid(   const ::rtl::OUString& _rName,
                                            const Sequence< ::rtl::OUString >& _rTableFilter,
                                            const Sequence< ::rtl::OUString >& _rTableTypeFilter,
                                            const ::std::vector< WildCard >& _rWCSearch) const
    {
        sal_Int32 nTableFilterLen = _rTableFilter.getLength();

        sal_Bool bFilterMatch = (NULL != bsearch(&_rName, _rTableFilter.getConstArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare));
        // the table is allowed to "pass" if we had no filters at all or any of the non-wildcard filters matches
        if (!bFilterMatch && _rWCSearch.size())
        {   // or if one of the wildcrad expression matches
            String sWCCompare = (const sal_Unicode*)_rName;
            for (   ::std::vector< WildCard >::const_iterator aLoop = _rWCSearch.begin();
                    aLoop != _rWCSearch.end() && !bFilterMatch;
                    ++aLoop
                )
                bFilterMatch = aLoop->Matches(sWCCompare);
        }

        return bFilterMatch;
    }
    // -------------------------------------------------------------------------
    Reference< XNamed > OFilteredContainer::cloneObject(const Reference< XPropertySet >& _xDescriptor)
    {
        Reference< XNamed > xName(_xDescriptor,UNO_QUERY);
        OSL_ENSURE(xName.is(),"Must be a XName interface here !");
        return xName.is() ? createObject(xName->getName()) : Reference< XNamed >();
    }
    // -----------------------------------------------------------------------------
// ..............................................................................
} // namespace
// ..............................................................................

<commit_msg>#96435# pointer access corrected<commit_after>/*************************************************************************
 *
 *  $RCSfile: FilteredContainer.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: oj $ $Date: 2002-08-26 07:59:23 $
 *
 *  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 EXPRESSED 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 DBACCESS_CORE_FILTERED_CONTAINER_HXX
#include "FilteredContainer.hxx"
#endif
#ifndef DBA_CORE_REFRESHLISTENER_HXX
#include "RefreshListener.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
#include <com/sun/star/sdbc/XRow.hpp>
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef _WLDCRD_HXX
#include <tools/wldcrd.hxx>
#endif

namespace dbaccess
{
    using namespace dbtools;
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace ::com::sun::star::sdbc;
    using namespace ::com::sun::star::sdb;
    using namespace ::com::sun::star::sdbcx;
    using namespace ::com::sun::star::util;
    using namespace ::com::sun::star::container;
    using namespace ::osl;
    using namespace ::comphelper;
    using namespace ::cppu;
    using namespace ::connectivity::sdbcx;

    //------------------------------------------------------------------------------
    /** compare two strings
    */
    extern int
    #if defined( WNT )
     __cdecl
    #endif
    #if defined( ICC ) && defined( OS2 )
    _Optlink
    #endif
    NameCompare( const void* pFirst, const void* pSecond)
    {
        return reinterpret_cast< const ::rtl::OUString* >(pFirst)->compareTo(*reinterpret_cast< const ::rtl::OUString* >(pSecond));
    }
    //------------------------------------------------------------------------------
    /** creates a vector of WildCards and reduce the _rTableFilter of the length of WildsCards
    */
    sal_Int32 createWildCardVector(Sequence< ::rtl::OUString >& _rTableFilter, ::std::vector< WildCard >& _rOut)
    {
        // for wildcard search : remove all table filters which are a wildcard expression and build a WilCard
        // for them
        ::rtl::OUString* pTableFilters = _rTableFilter.getArray();
        ::rtl::OUString* pEnd          = pTableFilters + _rTableFilter.getLength();
        sal_Int32 nShiftPos = 0;
        for (sal_Int32 i=0; pEnd != pTableFilters; ++pTableFilters,++i)
        {
            if (pTableFilters->indexOf('%') != -1)
            {
                _rOut.push_back(WildCard(pTableFilters->replace('%', '*')));
            }
            else
            {
                if (nShiftPos != i)
                {
                    _rTableFilter.getArray()[nShiftPos] = _rTableFilter.getArray()[i];
                }
                ++nShiftPos;
            }
        }
        // now aTableFilter contains nShiftPos non-wc-strings and aWCSearch all wc-strings
        _rTableFilter.realloc(nShiftPos);
        return nShiftPos;
    }

    //==========================================================================
    //= OViewContainer
    //==========================================================================
    OFilteredContainer::OFilteredContainer(::cppu::OWeakObject& _rParent,
                                 ::osl::Mutex& _rMutex,
                                 const Reference< XConnection >& _xCon,
                                 sal_Bool _bCase,
                                 IRefreshListener*  _pRefreshListener,
                                 IWarningsContainer* _pWarningsContainer)
    :OCollection(_rParent,_bCase,_rMutex,::std::vector< ::rtl::OUString>())
    ,m_bConstructed(sal_False)
    ,m_xConnection(_xCon)
    ,m_pWarningsContainer(_pWarningsContainer)
    ,m_pRefreshListener(_pRefreshListener)
    {
        try
        {
            m_xMetaData = _xCon->getMetaData();
        }
        catch(SQLException&)
        {
        }
    }
    // -------------------------------------------------------------------------
    void OFilteredContainer::construct(const Reference< XNameAccess >& _rxMasterContainer,
                                    const Sequence< ::rtl::OUString >& _rTableFilter,
                                    const Sequence< ::rtl::OUString >& _rTableTypeFilter)
    {
        m_xMasterContainer = _rxMasterContainer;

        if(m_xMasterContainer.is())
        {
            addMasterContainerListener();
            sal_Int32   nTableFilterLen = _rTableFilter.getLength();

            connectivity::TStringVector aTableNames;
            sal_Bool bNoTableFilters = ((nTableFilterLen == 1) && _rTableFilter[0].equalsAsciiL("%", 1));
            if(!bNoTableFilters)
            {
                Sequence< ::rtl::OUString > aTableFilter        = _rTableFilter;
                Sequence< ::rtl::OUString > aTableTypeFilter    = _rTableTypeFilter;
                // build sorted versions of the filter sequences, so the visibility decision is faster
                qsort(aTableFilter.getArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare);

                // as we want to modify nTableFilterLen, remember this

                // for wildcard search : remove all table filters which are a wildcard expression and build a WilCard
                // for them
                ::std::vector< WildCard > aWCSearch; // contains the wildcards for the table filter
                nTableFilterLen = createWildCardVector(aTableFilter,aWCSearch);

                aTableNames.reserve(nTableFilterLen + (aWCSearch.size() * 10));

                Sequence< ::rtl::OUString> aNames = m_xMasterContainer->getElementNames();
                const ::rtl::OUString* pBegin   = aNames.getConstArray();
                const ::rtl::OUString* pEnd     = pBegin + aNames.getLength();
                for(;pBegin != pEnd;++pBegin)
                {
                    if(isNameValid(*pBegin,aTableFilter,aTableTypeFilter,aWCSearch))
                        aTableNames.push_back(*pBegin);
                }
            }
            else
            {
                // no filter so insert all names
                Sequence< ::rtl::OUString> aNames = m_xMasterContainer->getElementNames();
                const ::rtl::OUString* pBegin   = aNames.getConstArray();
                const ::rtl::OUString* pEnd     = pBegin + aNames.getLength();
                aTableNames = connectivity::TStringVector(pBegin,pEnd);
            }
            reFill(aTableNames);
            m_bConstructed = sal_True;
        }
        else
        {
            construct(_rTableFilter,_rTableTypeFilter);
        }
    }
    //------------------------------------------------------------------------------
    void OFilteredContainer::construct(const Sequence< ::rtl::OUString >& _rTableFilter, const Sequence< ::rtl::OUString >& _rTableTypeFilter)
    {
        // build sorted versions of the filter sequences, so the visibility decision is faster
        Sequence< ::rtl::OUString > aTableFilter(_rTableFilter);
        sal_Int32   nTableFilterLen = aTableFilter.getLength();

        if (nTableFilterLen)
            qsort(aTableFilter.getArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare);

        sal_Bool bNoTableFilters = ((nTableFilterLen == 1) && _rTableFilter[0].equalsAsciiL("%", 1));
            // as we want to modify nTableFilterLen, remember this

        // for wildcard search : remove all table filters which are a wildcard expression and build a WilCard
        // for them
        ::std::vector< WildCard > aWCSearch;
        nTableFilterLen = createWildCardVector(aTableFilter,aWCSearch);

        try
        {
            if (m_xMetaData.is())
            {
                static const ::rtl::OUString sAll = ::rtl::OUString::createFromAscii("%");
                Sequence< ::rtl::OUString > sTableTypes = getTableTypeFilter(_rTableTypeFilter);
                if ( m_bConstructed && sTableTypes.getLength() == 0 )
                    return;

                Reference< XResultSet > xTables = m_xMetaData->getTables(Any(), sAll, sAll, sTableTypes);
                Reference< XRow > xCurrentRow(xTables, UNO_QUERY);
                if (xCurrentRow.is())
                {

                        // after creation the set is positioned before the first record, per definitionem

                    ::rtl::OUString sCatalog, sSchema, sName, sType;
                    ::rtl::OUString sComposedName;

                    // we first collect the names and construct the OTable objects later, as the ctor of the table may need
                    // another result set from the connection, and some drivers support only one statement per connection

                    sal_Bool bFilterMatch;
                    while (xTables->next())
                    {
                        sCatalog    = xCurrentRow->getString(1);
                        sSchema     = xCurrentRow->getString(2);
                        sName       = xCurrentRow->getString(3);
                        // we're not interested in the "wasNull", as the getStrings would return an empty string in
                        // that case, which is sufficient here

                        composeTableName(m_xMetaData, sCatalog, sSchema, sName, sComposedName, sal_False);
                        bFilterMatch =  bNoTableFilters
                                    ||  ((nTableFilterLen != 0) && (NULL != bsearch(&sComposedName, aTableFilter.getConstArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare)));
                        // the table is allowed to "pass" if we had no filters at all or any of the non-wildcard filters matches

                        if (!bFilterMatch && aWCSearch.size())
                        {   // or if one of the wildcrad expression matches
                            for (   ::std::vector< WildCard >::const_iterator aLoop = aWCSearch.begin();
                                    aLoop != aWCSearch.end() && !bFilterMatch;
                                    ++aLoop
                                )
                                bFilterMatch = aLoop->Matches(sComposedName);
                        }

                        if (bFilterMatch)
                        {   // the table name is allowed (not filtered out)
                            insertElement(sComposedName,NULL);
                        }
                    }

                    // dispose the tables result set, in case the connection can handle only one concurrent statement
                    // (the table object creation will need it's own statements)
                    disposeComponent(xTables);
                }
                else
                    OSL_ENSURE(0,"OFilteredContainer::construct : did not get a XRow from the tables result set !");
            }
            else
                OSL_ENSURE(0,"OFilteredContainer::construct : no connection meta data !");
        }
        catch (SQLException&)
        {
            OSL_ENSURE(0,"OFilteredContainer::construct : catched an SQL-Exception !");
            disposing();
            return;
        }

        m_bConstructed = sal_True;
    }
    //------------------------------------------------------------------------------
    void OFilteredContainer::disposing()
    {
        OCollection::disposing();
        removeMasterContainerListener();

        m_xMasterContainer  = NULL;
        m_xMetaData         = NULL;
        m_xConnection       = NULL;
        m_pWarningsContainer = NULL;
        m_pRefreshListener  = NULL;
        m_bConstructed      = sal_False;
    }
    // -------------------------------------------------------------------------
    void OFilteredContainer::impl_refresh() throw(RuntimeException)
    {
        if ( m_pRefreshListener )
        {
            m_bConstructed = sal_False;
            Reference<XRefreshable> xRefresh(m_xMasterContainer,UNO_QUERY);
            if ( xRefresh.is() )
                xRefresh->refresh();
            m_pRefreshListener->refresh(this);
        }
    }
    // -------------------------------------------------------------------------
    sal_Bool OFilteredContainer::isNameValid(   const ::rtl::OUString& _rName,
                                            const Sequence< ::rtl::OUString >& _rTableFilter,
                                            const Sequence< ::rtl::OUString >& _rTableTypeFilter,
                                            const ::std::vector< WildCard >& _rWCSearch) const
    {
        sal_Int32 nTableFilterLen = _rTableFilter.getLength();

        sal_Bool bFilterMatch = (NULL != bsearch(&_rName, _rTableFilter.getConstArray(), nTableFilterLen, sizeof(::rtl::OUString), NameCompare));
        // the table is allowed to "pass" if we had no filters at all or any of the non-wildcard filters matches
        if (!bFilterMatch && _rWCSearch.size())
        {   // or if one of the wildcrad expression matches
            String sWCCompare = (const sal_Unicode*)_rName;
            for (   ::std::vector< WildCard >::const_iterator aLoop = _rWCSearch.begin();
                    aLoop != _rWCSearch.end() && !bFilterMatch;
                    ++aLoop
                )
                bFilterMatch = aLoop->Matches(sWCCompare);
        }

        return bFilterMatch;
    }
    // -------------------------------------------------------------------------
    Reference< XNamed > OFilteredContainer::cloneObject(const Reference< XPropertySet >& _xDescriptor)
    {
        Reference< XNamed > xName(_xDescriptor,UNO_QUERY);
        OSL_ENSURE(xName.is(),"Must be a XName interface here !");
        return xName.is() ? createObject(xName->getName()) : Reference< XNamed >();
    }
    // -----------------------------------------------------------------------------
// ..............................................................................
} // namespace
// ..............................................................................

<|endoftext|>


<commit_before>#include "rapid_perception/box3d_roi_server.h"

#include <math.h>
#include <string>

#include "boost/bind.hpp"
#include "interactive_markers/interactive_marker_server.h"
#include "rapid_msgs/Roi3D.h"
#include "visualization_msgs/InteractiveMarker.h"
#include "visualization_msgs/InteractiveMarkerControl.h"
#include "visualization_msgs/InteractiveMarkerFeedback.h"
#include "visualization_msgs/Marker.h"

using interactive_markers::InteractiveMarkerServer;
using rapid_msgs::Roi3D;
using visualization_msgs::InteractiveMarker;
using visualization_msgs::InteractiveMarkerControl;
using visualization_msgs::InteractiveMarkerFeedbackConstPtr;
using visualization_msgs::Marker;

namespace rapid {
namespace perception {
Box3DRoiServer::Box3DRoiServer(const std::string& topic)
    : server_(new InteractiveMarkerServer(topic)),
      base_frame_("base_footprint") {}

Box3DRoiServer::~Box3DRoiServer() {
  if (server_ != NULL) {
    delete server_;
  }
}

InteractiveMarker Box3DRoiServer::Box(double x, double y, double z,
                                      double scale_x, double scale_y,
                                      double scale_z) {
  Marker box;
  box.type = Marker::CUBE;
  box.scale.x = scale_x;
  box.scale.y = scale_y;
  box.scale.z = scale_z;
  box.color.r = 0.25;
  box.color.g = 0.25;
  box.color.b = 0.5;
  box.color.a = 0.5;

  InteractiveMarkerControl control;
  control.markers.push_back(box);
  control.always_visible = true;
  control.interaction_mode = InteractiveMarkerControl::NONE;

  InteractiveMarker marker;
  marker.name = "box";
  marker.controls.push_back(control);
  marker.header.frame_id = base_frame_;
  marker.pose.position.x = x;
  marker.pose.position.y = y;
  marker.pose.position.z = z;
  marker.scale = box.scale.x;

  return marker;
}

void Box3DRoiServer::Start() { Start(0.5, 0, 1, 0.3, 0.3, 0.3); }

void Box3DRoiServer::Start(double x, double y, double z, double scale_x,
                           double scale_y, double scale_z) {
  InteractiveMarker box_marker = Box(x, y, z, scale_x, scale_y, scale_z);
  server_->insert(box_marker);
  roi_.transform.translation.x = x;
  roi_.transform.translation.y = y;
  roi_.transform.translation.z = z;
  roi_.transform.rotation.w = 1;
  roi_.dimensions.x = scale_x;
  roi_.dimensions.y = scale_y;
  roi_.dimensions.z = scale_z;

  InteractiveMarker x_marker =
      Arrow("x", "pos", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(x_marker, boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker y_marker =
      Arrow("y", "pos", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(y_marker, boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker z_marker =
      Arrow("z", "pos", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(z_marker, boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker neg_x_marker =
      Arrow("x", "neg", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(neg_x_marker,
                  boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker neg_y_marker =
      Arrow("y", "neg", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(neg_y_marker,
                  boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker neg_z_marker =
      Arrow("z", "neg", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(neg_z_marker,
                  boost::bind(&Box3DRoiServer::Feedback, this, _1));

  server_->applyChanges();
}

void Box3DRoiServer::Stop() {
  server_->erase("box");
  server_->erase("pos_x");
  server_->erase("pos_y");
  server_->erase("pos_z");
  server_->erase("neg_x");
  server_->erase("neg_y");
  server_->erase("neg_z");
  server_->applyChanges();
}

InteractiveMarker Box3DRoiServer::Arrow(const std::string& dim,
                                        const std::string& polarity,
                                        double box_x, double box_y,
                                        double box_z, double box_scale_x,
                                        double box_scale_y,
                                        double box_scale_z) {
  Marker arrow;
  arrow.type = Marker::ARROW;
  arrow.scale.x = 0.05;
  arrow.scale.y = 0.025;
  arrow.scale.z = 0.025;
  if (dim == "x") {
    arrow.color.r = 1;
  } else if (dim == "y") {
    arrow.color.g = 1;
  } else if (dim == "z") {
    arrow.color.b = 1;
  }
  arrow.color.a = 1;

  double sign = 1;
  if (polarity == "neg") {
    sign = -1;
  }

  InteractiveMarkerControl control;
  control.orientation.w = 1;
  arrow.pose.orientation.w = 1;
  if (dim == "x") {
    if (sign == -1) {
      control.orientation.w = 0;
      control.orientation.z = 1;
    }
  } else if (dim == "y") {
    control.orientation.z = sign;
  } else if (dim == "z") {
    control.orientation.y = -sign;
  }
  arrow.pose.orientation = control.orientation;
  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
  control.markers.push_back(arrow);

  InteractiveMarker marker;
  marker.name = polarity + "_" + dim;
  marker.controls.push_back(control);
  marker.header.frame_id = base_frame_;
  marker.pose.position.x = box_x;
  marker.pose.position.y = box_y;
  marker.pose.position.z = box_z;
  marker.pose.orientation.w = 1;
  if (dim == "x") {
    marker.pose.position.x = box_x + sign * box_scale_x / 2 + sign * 0.05;
  } else if (dim == "y") {
    marker.pose.position.y = box_y + sign * box_scale_y / 2 + sign * 0.05;
  } else if (dim == "z") {
    marker.pose.position.z = box_z + sign * box_scale_z / 2 + sign * 0.05;
  }
  marker.scale = 0.05;
  return marker;
}

void Box3DRoiServer::Update(const std::string& dim, const std::string& polarity,
                            const geometry_msgs::Point& point) {
  InteractiveMarker old_box;
  server_->get("box", old_box);
  const geometry_msgs::Point& old_pos = old_box.pose.position;
  const geometry_msgs::Vector3& old_scale =
      old_box.controls[0].markers[0].scale;

  double sign = 1;
  if (polarity == "neg") {
    sign = -1;
  }

  double opposite_pos = 0;  // Position of opposite face.
  double input_pos = 0;     // Position requested by user.
  if (dim == "x") {
    input_pos = point.x - sign * 0.05;
    if (sign == 1) {
      opposite_pos = std::min(old_pos.x - old_scale.x / 2, input_pos - 0.01);
    } else {
      opposite_pos = std::max(old_pos.x + old_scale.x / 2, input_pos + 0.01);
    }
  } else if (dim == "y") {
    input_pos = point.y - sign * 0.05;
    if (sign == 1) {
      opposite_pos = std::min(old_pos.y - old_scale.y / 2, input_pos - 0.01);
    } else {
      opposite_pos = std::max(old_pos.y + old_scale.y / 2, input_pos + 0.01);
    }
  } else if (dim == "z") {
    input_pos = point.z - sign * 0.05;
    if (sign == 1) {
      opposite_pos = std::min(old_pos.z - old_scale.z / 2, input_pos - 0.01);
    } else {
      opposite_pos = std::max(old_pos.z + old_scale.z / 2, input_pos + 0.01);
    }
  }
  double new_scale = sign * (input_pos - opposite_pos);
  double new_pos = (opposite_pos + input_pos) / 2;

  // Update box
  InteractiveMarker box;
  double new_x = old_pos.x;
  double new_y = old_pos.y;
  double new_z = old_pos.z;
  double new_scale_x = old_scale.x;
  double new_scale_y = old_scale.y;
  double new_scale_z = old_scale.z;
  if (dim == "x") {
    new_x = new_pos;
    new_scale_x = new_scale;
  } else if (dim == "y") {
    new_y = new_pos;
    new_scale_y = new_scale;
  } else if (dim == "z") {
    new_z = new_pos;
    new_scale_z = new_scale;
  }
  box = Box(new_x, new_y, new_z, new_scale_x, new_scale_y, new_scale_z);
  server_->insert(box);

  // Update ROI
  roi_.transform.translation.x = new_x;
  roi_.transform.translation.y = new_y;
  roi_.transform.translation.z = new_z;
  roi_.dimensions.x = new_scale_x;
  roi_.dimensions.y = new_scale_y;
  roi_.dimensions.z = new_scale_z;

  // Update arrows
  InteractiveMarker pos_x = Arrow("x", "pos", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("pos_x", pos_x.pose, pos_x.header);
  InteractiveMarker neg_x = Arrow("x", "neg", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("neg_x", neg_x.pose, neg_x.header);

  InteractiveMarker pos_y = Arrow("y", "pos", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("pos_y", pos_y.pose, pos_y.header);
  InteractiveMarker neg_y = Arrow("y", "neg", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("neg_y", neg_y.pose, neg_y.header);

  InteractiveMarker pos_z = Arrow("z", "pos", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("pos_z", pos_z.pose, pos_z.header);
  InteractiveMarker neg_z = Arrow("z", "neg", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("neg_z", neg_z.pose, neg_z.header);

  server_->applyChanges();
}

void Box3DRoiServer::Feedback(
    const InteractiveMarkerFeedbackConstPtr& feedback) {
  const geometry_msgs::Point& point = feedback->pose.position;
  if (feedback->marker_name == "pos_x") {
    Update("x", "pos", point);
  } else if (feedback->marker_name == "pos_y") {
    Update("y", "pos", point);
  } else if (feedback->marker_name == "pos_z") {
    Update("z", "pos", point);
  } else if (feedback->marker_name == "neg_x") {
    Update("x", "neg", point);
  } else if (feedback->marker_name == "neg_y") {
    Update("y", "neg", point);
  } else if (feedback->marker_name == "neg_z") {
    Update("z", "neg", point);
  }
}

rapid_msgs::Roi3D Box3DRoiServer::roi() { return roi_; }

void Box3DRoiServer::set_base_frame(const std::string& base_frame) {
  base_frame_ = base_frame;
}
}  // namespace perception
}  // namespace rapid
<commit_msg>Add outline box to ROI marker.<commit_after>#include "rapid_perception/box3d_roi_server.h"

#include <math.h>
#include <string>

#include "boost/bind.hpp"
#include "geometry_msgs/PoseStamped.h"
#include "geometry_msgs/Vector3.h"
#include "interactive_markers/interactive_marker_server.h"
#include "rapid_msgs/Roi3D.h"
#include "visualization_msgs/InteractiveMarker.h"
#include "visualization_msgs/InteractiveMarkerControl.h"
#include "visualization_msgs/InteractiveMarkerFeedback.h"
#include "visualization_msgs/Marker.h"

#include "rapid_viz/markers.h"

using interactive_markers::InteractiveMarkerServer;
using rapid_msgs::Roi3D;
using visualization_msgs::InteractiveMarker;
using visualization_msgs::InteractiveMarkerControl;
using visualization_msgs::InteractiveMarkerFeedbackConstPtr;
using visualization_msgs::Marker;

namespace rapid {
namespace perception {
Box3DRoiServer::Box3DRoiServer(const std::string& topic)
    : server_(new InteractiveMarkerServer(topic)),
      base_frame_("base_footprint") {}

Box3DRoiServer::~Box3DRoiServer() {
  if (server_ != NULL) {
    delete server_;
  }
}

InteractiveMarker Box3DRoiServer::Box(double x, double y, double z,
                                      double scale_x, double scale_y,
                                      double scale_z) {
  Marker box;
  box.type = Marker::CUBE;
  box.scale.x = scale_x;
  box.scale.y = scale_y;
  box.scale.z = scale_z;
  box.color.r = 0.25;
  box.color.g = 0.25;
  box.color.b = 0.5;
  box.color.a = 0.5;

  geometry_msgs::PoseStamped ps;
  // ps.header.frame_id = base_frame_;
  ps.pose.orientation.w = 1;
  geometry_msgs::Vector3 scale;
  scale.x = scale_x;
  scale.y = scale_y;
  scale.z = scale_z;
  Marker outline_box = rapid::viz::OutlineBox(ps, scale);

  InteractiveMarkerControl control;
  control.markers.push_back(box);
  control.markers.push_back(outline_box);
  control.always_visible = true;
  control.interaction_mode = InteractiveMarkerControl::NONE;

  InteractiveMarker marker;
  marker.name = "box";
  marker.controls.push_back(control);
  marker.header.frame_id = base_frame_;
  marker.pose.position.x = x;
  marker.pose.position.y = y;
  marker.pose.position.z = z;
  marker.scale = box.scale.x;

  return marker;
}

void Box3DRoiServer::Start() { Start(0.5, 0, 1, 0.3, 0.3, 0.3); }

void Box3DRoiServer::Start(double x, double y, double z, double scale_x,
                           double scale_y, double scale_z) {
  InteractiveMarker box_marker = Box(x, y, z, scale_x, scale_y, scale_z);
  server_->insert(box_marker);
  roi_.transform.translation.x = x;
  roi_.transform.translation.y = y;
  roi_.transform.translation.z = z;
  roi_.transform.rotation.w = 1;
  roi_.dimensions.x = scale_x;
  roi_.dimensions.y = scale_y;
  roi_.dimensions.z = scale_z;

  InteractiveMarker x_marker =
      Arrow("x", "pos", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(x_marker, boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker y_marker =
      Arrow("y", "pos", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(y_marker, boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker z_marker =
      Arrow("z", "pos", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(z_marker, boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker neg_x_marker =
      Arrow("x", "neg", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(neg_x_marker,
                  boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker neg_y_marker =
      Arrow("y", "neg", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(neg_y_marker,
                  boost::bind(&Box3DRoiServer::Feedback, this, _1));
  InteractiveMarker neg_z_marker =
      Arrow("z", "neg", x, y, z, scale_x, scale_y, scale_z);
  server_->insert(neg_z_marker,
                  boost::bind(&Box3DRoiServer::Feedback, this, _1));

  server_->applyChanges();
}

void Box3DRoiServer::Stop() {
  server_->erase("box");
  server_->erase("pos_x");
  server_->erase("pos_y");
  server_->erase("pos_z");
  server_->erase("neg_x");
  server_->erase("neg_y");
  server_->erase("neg_z");
  server_->applyChanges();
}

InteractiveMarker Box3DRoiServer::Arrow(const std::string& dim,
                                        const std::string& polarity,
                                        double box_x, double box_y,
                                        double box_z, double box_scale_x,
                                        double box_scale_y,
                                        double box_scale_z) {
  Marker arrow;
  arrow.type = Marker::ARROW;
  arrow.scale.x = 0.05;
  arrow.scale.y = 0.05;
  arrow.scale.z = 0.05;
  if (dim == "x") {
    arrow.color.r = 1;
  } else if (dim == "y") {
    arrow.color.g = 1;
  } else if (dim == "z") {
    arrow.color.b = 1;
  }
  arrow.color.a = 0.9;

  double sign = 1;
  if (polarity == "neg") {
    sign = -1;
  }

  InteractiveMarkerControl control;
  control.orientation.w = 1;
  arrow.pose.orientation.w = 1;
  if (dim == "x") {
    if (sign == -1) {
      control.orientation.w = 0;
      control.orientation.z = 1;
    }
  } else if (dim == "y") {
    control.orientation.z = sign;
  } else if (dim == "z") {
    control.orientation.y = -sign;
  }
  arrow.pose.orientation = control.orientation;
  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
  control.markers.push_back(arrow);

  InteractiveMarker marker;
  marker.name = polarity + "_" + dim;
  marker.controls.push_back(control);
  marker.header.frame_id = base_frame_;
  marker.pose.position.x = box_x;
  marker.pose.position.y = box_y;
  marker.pose.position.z = box_z;
  marker.pose.orientation.w = 1;
  if (dim == "x") {
    marker.pose.position.x = box_x + sign * box_scale_x / 2 + sign * 0.05;
  } else if (dim == "y") {
    marker.pose.position.y = box_y + sign * box_scale_y / 2 + sign * 0.05;
  } else if (dim == "z") {
    marker.pose.position.z = box_z + sign * box_scale_z / 2 + sign * 0.05;
  }
  marker.scale = 0.05;
  return marker;
}

void Box3DRoiServer::Update(const std::string& dim, const std::string& polarity,
                            const geometry_msgs::Point& point) {
  InteractiveMarker old_box;
  server_->get("box", old_box);
  const geometry_msgs::Point& old_pos = old_box.pose.position;
  const geometry_msgs::Vector3& old_scale =
      old_box.controls[0].markers[0].scale;

  double sign = 1;
  if (polarity == "neg") {
    sign = -1;
  }

  double opposite_pos = 0;  // Position of opposite face.
  double input_pos = 0;     // Position requested by user.
  if (dim == "x") {
    input_pos = point.x - sign * 0.05;
    if (sign == 1) {
      opposite_pos = std::min(old_pos.x - old_scale.x / 2, input_pos - 0.01);
    } else {
      opposite_pos = std::max(old_pos.x + old_scale.x / 2, input_pos + 0.01);
    }
  } else if (dim == "y") {
    input_pos = point.y - sign * 0.05;
    if (sign == 1) {
      opposite_pos = std::min(old_pos.y - old_scale.y / 2, input_pos - 0.01);
    } else {
      opposite_pos = std::max(old_pos.y + old_scale.y / 2, input_pos + 0.01);
    }
  } else if (dim == "z") {
    input_pos = point.z - sign * 0.05;
    if (sign == 1) {
      opposite_pos = std::min(old_pos.z - old_scale.z / 2, input_pos - 0.01);
    } else {
      opposite_pos = std::max(old_pos.z + old_scale.z / 2, input_pos + 0.01);
    }
  }
  double new_scale = sign * (input_pos - opposite_pos);
  double new_pos = (opposite_pos + input_pos) / 2;

  // Update box
  InteractiveMarker box;
  double new_x = old_pos.x;
  double new_y = old_pos.y;
  double new_z = old_pos.z;
  double new_scale_x = old_scale.x;
  double new_scale_y = old_scale.y;
  double new_scale_z = old_scale.z;
  if (dim == "x") {
    new_x = new_pos;
    new_scale_x = new_scale;
  } else if (dim == "y") {
    new_y = new_pos;
    new_scale_y = new_scale;
  } else if (dim == "z") {
    new_z = new_pos;
    new_scale_z = new_scale;
  }
  box = Box(new_x, new_y, new_z, new_scale_x, new_scale_y, new_scale_z);
  server_->insert(box);

  // Update ROI
  roi_.transform.translation.x = new_x;
  roi_.transform.translation.y = new_y;
  roi_.transform.translation.z = new_z;
  roi_.dimensions.x = new_scale_x;
  roi_.dimensions.y = new_scale_y;
  roi_.dimensions.z = new_scale_z;

  // Update arrows
  InteractiveMarker pos_x = Arrow("x", "pos", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("pos_x", pos_x.pose, pos_x.header);
  InteractiveMarker neg_x = Arrow("x", "neg", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("neg_x", neg_x.pose, neg_x.header);

  InteractiveMarker pos_y = Arrow("y", "pos", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("pos_y", pos_y.pose, pos_y.header);
  InteractiveMarker neg_y = Arrow("y", "neg", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("neg_y", neg_y.pose, neg_y.header);

  InteractiveMarker pos_z = Arrow("z", "pos", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("pos_z", pos_z.pose, pos_z.header);
  InteractiveMarker neg_z = Arrow("z", "neg", new_x, new_y, new_z, new_scale_x,
                                  new_scale_y, new_scale_z);
  server_->setPose("neg_z", neg_z.pose, neg_z.header);

  server_->applyChanges();
}

void Box3DRoiServer::Feedback(
    const InteractiveMarkerFeedbackConstPtr& feedback) {
  const geometry_msgs::Point& point = feedback->pose.position;
  if (feedback->marker_name == "pos_x") {
    Update("x", "pos", point);
  } else if (feedback->marker_name == "pos_y") {
    Update("y", "pos", point);
  } else if (feedback->marker_name == "pos_z") {
    Update("z", "pos", point);
  } else if (feedback->marker_name == "neg_x") {
    Update("x", "neg", point);
  } else if (feedback->marker_name == "neg_y") {
    Update("y", "neg", point);
  } else if (feedback->marker_name == "neg_z") {
    Update("z", "neg", point);
  }
}

rapid_msgs::Roi3D Box3DRoiServer::roi() { return roi_; }

void Box3DRoiServer::set_base_frame(const std::string& base_frame) {
  base_frame_ = base_frame;
}
}  // namespace perception
}  // namespace rapid
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: AdvancedSettingsDlg.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 07:31:51 $
 *
 *  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
 *
 ************************************************************************/

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

#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _DBAUI_ADVANCEDSETTINGSDLG_HXX
#include "AdvancedSettingsDlg.hxx"
#endif
#ifndef DBAUI_ADVANCEDPAGEDLG_HXX
#include "AdvancedPageDlg.hxx"
#endif

using namespace dbaui;

extern "C" void SAL_CALL createRegistryInfo_OAdvancedSettingsDialog()
{
    static OMultiInstanceAutoRegistration< OAdvancedSettingsDialog > aAutoRegistration;
}

//.........................................................................
namespace dbaui
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;

//=========================================================================
//-------------------------------------------------------------------------
OAdvancedSettingsDialog::OAdvancedSettingsDialog(const Reference< XMultiServiceFactory >& _rxORB)
    :ODatabaseAdministrationDialog(_rxORB)
{
}
//-------------------------------------------------------------------------
Sequence<sal_Int8> SAL_CALL OAdvancedSettingsDialog::getImplementationId(  ) throw(RuntimeException)
{
    static ::cppu::OImplementationId aId;
    return aId.getImplementationId();
}

//-------------------------------------------------------------------------
Reference< XInterface > SAL_CALL OAdvancedSettingsDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
{
    return *(new OAdvancedSettingsDialog(_rxFactory));
}

//-------------------------------------------------------------------------
::rtl::OUString SAL_CALL OAdvancedSettingsDialog::getImplementationName() throw(RuntimeException)
{
    return getImplementationName_Static();
}

//-------------------------------------------------------------------------
::rtl::OUString OAdvancedSettingsDialog::getImplementationName_Static() throw(RuntimeException)
{
    return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.OAdvancedSettingsDialog"));
}

//-------------------------------------------------------------------------
::comphelper::StringSequence SAL_CALL OAdvancedSettingsDialog::getSupportedServiceNames() throw(RuntimeException)
{
    return getSupportedServiceNames_Static();
}

//-------------------------------------------------------------------------
::comphelper::StringSequence OAdvancedSettingsDialog::getSupportedServiceNames_Static() throw(RuntimeException)
{
    ::comphelper::StringSequence aSupported(1);
    aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.AdvancedDatabaseSettingsDialog"));
    return aSupported;
}

//-------------------------------------------------------------------------
Reference<XPropertySetInfo>  SAL_CALL OAdvancedSettingsDialog::getPropertySetInfo() throw(RuntimeException)
{
    Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
    return xInfo;
}

//-------------------------------------------------------------------------
::cppu::IPropertyArrayHelper& OAdvancedSettingsDialog::getInfoHelper()
{
    return *const_cast<OAdvancedSettingsDialog*>(this)->getArrayHelper();
}

//------------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OAdvancedSettingsDialog::createArrayHelper( ) const
{
    Sequence< Property > aProps;
    describeProperties(aProps);
    return new ::cppu::OPropertyArrayHelper(aProps);
}
//------------------------------------------------------------------------------
Dialog* OAdvancedSettingsDialog::createDialog(Window* _pParent)
{
    OAdvancedTabPageDlg* pDlg = new OAdvancedTabPageDlg(_pParent, m_pDatasourceItems, m_xORB,m_aInitialSelection);
    return pDlg;
}

//.........................................................................
}   // namespace dbaui
//.........................................................................

<commit_msg>INTEGRATION: CWS dba24b (1.4.130); FILE MERGED 2007/08/27 10:42:05 fs 1.4.130.1: some re-factoring in preparation of #i80930#: moved declaration from .hxx to .cxx<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: AdvancedSettingsDlg.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2007-11-01 15:38:20 $
 *
 *  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
 *
 ************************************************************************/

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

#include "unoadmin.hxx"
#include "dbu_reghelper.hxx"
#include "advancedsettingsdlg.hxx"

//.........................................................................
namespace dbaui
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;

    //=========================================================================
    //= OAdvancedSettingsDialog
    //=========================================================================
    class OAdvancedSettingsDialog
            :public ODatabaseAdministrationDialog
            ,public ::comphelper::OPropertyArrayUsageHelper< OAdvancedSettingsDialog >
    {

    protected:
        OAdvancedSettingsDialog(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB);

    public:
        // XTypeProvider
        virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId(  ) throw(::com::sun::star::uno::RuntimeException);

        // XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
        virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);

        // XServiceInfo - static methods
        static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
        static ::rtl::OUString getImplementationName_Static(void) throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
                SAL_CALL Create(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >&);

        // XPropertySet
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo>  SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException);
        virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();

        // OPropertyArrayUsageHelper
        virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
    protected:
    // OGenericUnoDialog overridables
        virtual Dialog* createDialog(Window* _pParent);
    };

    //=========================================================================
    //-------------------------------------------------------------------------
    OAdvancedSettingsDialog::OAdvancedSettingsDialog(const Reference< XMultiServiceFactory >& _rxORB)
        :ODatabaseAdministrationDialog(_rxORB)
    {
    }
    //-------------------------------------------------------------------------
    Sequence<sal_Int8> SAL_CALL OAdvancedSettingsDialog::getImplementationId(  ) throw(RuntimeException)
    {
        static ::cppu::OImplementationId aId;
        return aId.getImplementationId();
    }

    //-------------------------------------------------------------------------
    Reference< XInterface > SAL_CALL OAdvancedSettingsDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
    {
        return *(new OAdvancedSettingsDialog(_rxFactory));
    }

    //-------------------------------------------------------------------------
    ::rtl::OUString SAL_CALL OAdvancedSettingsDialog::getImplementationName() throw(RuntimeException)
    {
        return getImplementationName_Static();
    }

    //-------------------------------------------------------------------------
    ::rtl::OUString OAdvancedSettingsDialog::getImplementationName_Static() throw(RuntimeException)
    {
        return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.OAdvancedSettingsDialog"));
    }

    //-------------------------------------------------------------------------
    ::comphelper::StringSequence SAL_CALL OAdvancedSettingsDialog::getSupportedServiceNames() throw(RuntimeException)
    {
        return getSupportedServiceNames_Static();
    }

    //-------------------------------------------------------------------------
    ::comphelper::StringSequence OAdvancedSettingsDialog::getSupportedServiceNames_Static() throw(RuntimeException)
    {
        ::comphelper::StringSequence aSupported(1);
        aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.AdvancedDatabaseSettingsDialog"));
        return aSupported;
    }

    //-------------------------------------------------------------------------
    Reference<XPropertySetInfo>  SAL_CALL OAdvancedSettingsDialog::getPropertySetInfo() throw(RuntimeException)
    {
        Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
        return xInfo;
    }

    //-------------------------------------------------------------------------
    ::cppu::IPropertyArrayHelper& OAdvancedSettingsDialog::getInfoHelper()
    {
        return *const_cast<OAdvancedSettingsDialog*>(this)->getArrayHelper();
    }

    //------------------------------------------------------------------------------
    ::cppu::IPropertyArrayHelper* OAdvancedSettingsDialog::createArrayHelper( ) const
    {
        Sequence< Property > aProps;
        describeProperties(aProps);
        return new ::cppu::OPropertyArrayHelper(aProps);
    }
    //------------------------------------------------------------------------------
    Dialog* OAdvancedSettingsDialog::createDialog(Window* _pParent)
    {
        AdvancedSettingsDialog* pDlg = new AdvancedSettingsDialog(_pParent, m_pDatasourceItems, m_xORB,m_aInitialSelection);
        return pDlg;
    }

//.........................................................................
}   // namespace dbaui
//.........................................................................

extern "C" void SAL_CALL createRegistryInfo_OAdvancedSettingsDialog()
{
    static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OAdvancedSettingsDialog > aAutoRegistration;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: hierarchyservices.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-20 05:29:34 $
 *
 *  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 _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#endif
#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_
#include <com/sun/star/registry/XRegistryKey.hpp>
#endif

#ifndef _HIERARCHYPROVIDER_HXX
#include "hierarchyprovider.hxx"
#endif
#ifndef _HIERARCHYDATASOURCE_HXX
#include "hierarchydatasource.hxx"
#endif

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

//=========================================================================
static sal_Bool writeInfo( void * pRegistryKey,
                           const rtl::OUString & rImplementationName,
                           uno::Sequence< rtl::OUString > const & rServiceNames )
{
    rtl::OUString aKeyName( rtl::OUString::createFromAscii( "/" ) );
    aKeyName += rImplementationName;
    aKeyName += rtl::OUString::createFromAscii( "/UNO/SERVICES" );

    uno::Reference< registry::XRegistryKey > xKey;
    try
    {
        xKey = static_cast< registry::XRegistryKey * >(
                                    pRegistryKey )->createKey( aKeyName );
    }
    catch ( registry::InvalidRegistryException const & )
    {
    }

    if ( !xKey.is() )
        return sal_False;

    sal_Bool bSuccess = sal_True;

    for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n )
    {
        try
        {
            xKey->createKey( rServiceNames[ n ] );
        }
        catch ( registry::InvalidRegistryException const & )
        {
            bSuccess = sal_False;
            break;
        }
    }
    return bSuccess;
}

//=========================================================================
extern "C" void SAL_CALL component_getImplementationEnvironment(
    const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
{
    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}

//=========================================================================
extern "C" sal_Bool SAL_CALL component_writeInfo(
    void * /*pServiceManager*/, void * pRegistryKey )
{
    return pRegistryKey &&

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Content Provider.
    //////////////////////////////////////////////////////////////////////

    writeInfo( pRegistryKey,
               HierarchyContentProvider::getImplementationName_Static(),
               HierarchyContentProvider::getSupportedServiceNames_Static() ) &&

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Data Source.
    //////////////////////////////////////////////////////////////////////

    writeInfo( pRegistryKey,
               HierarchyDataSource::getImplementationName_Static(),
               HierarchyDataSource::getSupportedServiceNames_Static() );
}

//=========================================================================
extern "C" void * SAL_CALL component_getFactory(
    const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
{
    void * pRet = 0;

    uno::Reference< lang::XMultiServiceFactory > xSMgr(
            reinterpret_cast< lang::XMultiServiceFactory * >(
                pServiceManager ) );
    uno::Reference< lang::XSingleServiceFactory > xFactory;

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Content Provider.
    //////////////////////////////////////////////////////////////////////

    if ( HierarchyContentProvider::getImplementationName_Static().
                compareToAscii( pImplName ) == 0 )
    {
        xFactory = HierarchyContentProvider::createServiceFactory( xSMgr );
    }

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Data Source.
    //////////////////////////////////////////////////////////////////////

    else if ( HierarchyDataSource::getImplementationName_Static().
                compareToAscii( pImplName ) == 0 )
    {
        xFactory = HierarchyDataSource::createServiceFactory( xSMgr );
    }

    //////////////////////////////////////////////////////////////////////

    if ( xFactory.is() )
    {
        xFactory->acquire();
        pRet = xFactory.get();
    }

    return pRet;
}

<commit_msg>INTEGRATION: CWS pchfix02 (1.6.20); FILE MERGED 2006/09/01 17:55:47 kaib 1.6.20.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: hierarchyservices.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 13:56:48 $
 *
 *  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
 *
 ************************************************************************/

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

#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#endif
#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_
#include <com/sun/star/registry/XRegistryKey.hpp>
#endif

#ifndef _HIERARCHYPROVIDER_HXX
#include "hierarchyprovider.hxx"
#endif
#ifndef _HIERARCHYDATASOURCE_HXX
#include "hierarchydatasource.hxx"
#endif

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

//=========================================================================
static sal_Bool writeInfo( void * pRegistryKey,
                           const rtl::OUString & rImplementationName,
                           uno::Sequence< rtl::OUString > const & rServiceNames )
{
    rtl::OUString aKeyName( rtl::OUString::createFromAscii( "/" ) );
    aKeyName += rImplementationName;
    aKeyName += rtl::OUString::createFromAscii( "/UNO/SERVICES" );

    uno::Reference< registry::XRegistryKey > xKey;
    try
    {
        xKey = static_cast< registry::XRegistryKey * >(
                                    pRegistryKey )->createKey( aKeyName );
    }
    catch ( registry::InvalidRegistryException const & )
    {
    }

    if ( !xKey.is() )
        return sal_False;

    sal_Bool bSuccess = sal_True;

    for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n )
    {
        try
        {
            xKey->createKey( rServiceNames[ n ] );
        }
        catch ( registry::InvalidRegistryException const & )
        {
            bSuccess = sal_False;
            break;
        }
    }
    return bSuccess;
}

//=========================================================================
extern "C" void SAL_CALL component_getImplementationEnvironment(
    const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
{
    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}

//=========================================================================
extern "C" sal_Bool SAL_CALL component_writeInfo(
    void * /*pServiceManager*/, void * pRegistryKey )
{
    return pRegistryKey &&

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Content Provider.
    //////////////////////////////////////////////////////////////////////

    writeInfo( pRegistryKey,
               HierarchyContentProvider::getImplementationName_Static(),
               HierarchyContentProvider::getSupportedServiceNames_Static() ) &&

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Data Source.
    //////////////////////////////////////////////////////////////////////

    writeInfo( pRegistryKey,
               HierarchyDataSource::getImplementationName_Static(),
               HierarchyDataSource::getSupportedServiceNames_Static() );
}

//=========================================================================
extern "C" void * SAL_CALL component_getFactory(
    const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
{
    void * pRet = 0;

    uno::Reference< lang::XMultiServiceFactory > xSMgr(
            reinterpret_cast< lang::XMultiServiceFactory * >(
                pServiceManager ) );
    uno::Reference< lang::XSingleServiceFactory > xFactory;

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Content Provider.
    //////////////////////////////////////////////////////////////////////

    if ( HierarchyContentProvider::getImplementationName_Static().
                compareToAscii( pImplName ) == 0 )
    {
        xFactory = HierarchyContentProvider::createServiceFactory( xSMgr );
    }

    //////////////////////////////////////////////////////////////////////
    // Hierarchy Data Source.
    //////////////////////////////////////////////////////////////////////

    else if ( HierarchyDataSource::getImplementationName_Static().
                compareToAscii( pImplName ) == 0 )
    {
        xFactory = HierarchyDataSource::createServiceFactory( xSMgr );
    }

    //////////////////////////////////////////////////////////////////////

    if ( xFactory.is() )
    {
        xFactory->acquire();
        pRet = xFactory.get();
    }

    return pRet;
}

<|endoftext|>


<commit_before>/* -------------------------------------------------------------------------- *
 *                    OpenSim:  VisualizeModel.cpp                     *
 * -------------------------------------------------------------------------- *
 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation.  *
 * See http://opensim.stanford.edu and the NOTICE file for more information.  *
 * OpenSim is developed at Stanford University and supported by the US        *
 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA    *
 * through the Warrior Web program.                                           *
 *                                                                            *
 * Copyright (c) 2005-2014 Stanford University and the Authors                *
 * Author(s): Ayman Habib                                                     *
 *                                                                            *
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0.         *
 *                                                                            *
 * Unless required by applicable law or agreed to in writing, software        *
 * distributed under the License is distributed on an "AS IS" BASIS,          *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
 * See the License for the specific language governing permissions and        *
 * limitations under the License.                                             *
 * -------------------------------------------------------------------------- */

/*
 *  Below is an example of an OpenSim application that loads an OpenSim model
 *  and visualize it in the API visualizer.
 */

// Author:  Ayman Habib

//==============================================================================
//==============================================================================
#include <OpenSim/OpenSim.h>

using namespace OpenSim;
using namespace SimTK;
using namespace std;
//______________________________________________________________________________
/**
 * First exercise: create a model that does nothing.
 */
int main(int argc, char **argv)
{
    try {
        // Create an OpenSim model and set its name
        if (argc < 2) {
            string progName = IO::GetFileNameFromURI(argv[0]);
            cout << "Filename needs to be specified or passed in.\n\n";
            return 1;
        }

        std::string modelFile = std::string(argv[1]);
        Model osimModel(modelFile);
        //osimModel.print("updated_" + modelFile);
        osimModel.setUseVisualizer(true);
        osimModel.updDisplayHints().set_show_frames(true);
        SimTK::State& si = osimModel.initSystem();
        osimModel.equilibrateMuscles(si);
        osimModel.getMultibodySystem().realize(si, Stage::Velocity);
        osimModel.getVisualizer().show(si);
        getchar(); // Keep Visualizer from dying until we inspect the visualization window..
    }
    catch (OpenSim::Exception ex)
    {
        std::cout << ex.getMessage() << std::endl;
        return 1;
    }
    catch (std::exception ex)
    {
        std::cout << ex.what() << std::endl;
        return 1;
    }
    catch (...)
    {
        std::cout << "UNRECOGNIZED EXCEPTION" << std::endl;
        return 1;
    }

    return 0;
}
<commit_msg>Don't show Frames by default, they'll be individually controlled.<commit_after>/* -------------------------------------------------------------------------- *
 *                    OpenSim:  VisualizeModel.cpp                     *
 * -------------------------------------------------------------------------- *
 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation.  *
 * See http://opensim.stanford.edu and the NOTICE file for more information.  *
 * OpenSim is developed at Stanford University and supported by the US        *
 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA    *
 * through the Warrior Web program.                                           *
 *                                                                            *
 * Copyright (c) 2005-2014 Stanford University and the Authors                *
 * Author(s): Ayman Habib                                                     *
 *                                                                            *
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0.         *
 *                                                                            *
 * Unless required by applicable law or agreed to in writing, software        *
 * distributed under the License is distributed on an "AS IS" BASIS,          *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
 * See the License for the specific language governing permissions and        *
 * limitations under the License.                                             *
 * -------------------------------------------------------------------------- */

/*
 *  Below is an example of an OpenSim application that loads an OpenSim model
 *  and visualize it in the API visualizer.
 */

// Author:  Ayman Habib

//==============================================================================
//==============================================================================
#include <OpenSim/OpenSim.h>

using namespace OpenSim;
using namespace SimTK;
using namespace std;
//______________________________________________________________________________
/**
 * First exercise: create a model that does nothing.
 */
int main(int argc, char **argv)
{
    try {
        // Create an OpenSim model and set its name
        if (argc < 2) {
            string progName = IO::GetFileNameFromURI(argv[0]);
            cout << "Filename needs to be specified or passed in.\n\n";
            return 1;
        }

        std::string modelFile = std::string(argv[1]);
        Model osimModel(modelFile);
        //osimModel.print("updated_" + modelFile);
        osimModel.setUseVisualizer(true);
        osimModel.updDisplayHints().set_show_frames(false);
        SimTK::State& si = osimModel.initSystem();
        osimModel.equilibrateMuscles(si);
        osimModel.getMultibodySystem().realize(si, Stage::Velocity);
        osimModel.getVisualizer().show(si);
        getchar(); // Keep Visualizer from dying until we inspect the visualization window..
    }
    catch (OpenSim::Exception ex)
    {
        std::cout << ex.getMessage() << std::endl;
        return 1;
    }
    catch (std::exception ex)
    {
        std::cout << ex.what() << std::endl;
        return 1;
    }
    catch (...)
    {
        std::cout << "UNRECOGNIZED EXCEPTION" << std::endl;
        return 1;
    }

    return 0;
}
<|endoftext|>


<commit_before>/*
 * This File is part of Davix, The IO library for HTTP based protocols
 * Copyright (C) 2013  Adrien Devresse <adrien.devresse@cern.ch>, CERN
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
*/

#include "fileproperties.hpp"

namespace Davix {

FileProperties::FileProperties() :
    filename(),
    req_status(0),
    nlink(0),
    uid(0),
    gid(0),
    size(0),
    mode(0),
    atime(0),
    mtime(0),
    ctime(0){

}

} // namespace Davix
<commit_msg>Simplify file properties structure<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: AccessibleOutlineView.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: rt $ $Date: 2007-04-25 14:40:45 $
 *
 *  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 SD_ACCESSIBILITY_ACCESSIBLE_OUTLINE_VIEW_HXX
#define SD_ACCESSIBILITY_ACCESSIBLE_OUTLINE_VIEW_HXX

#ifndef SD_ACCESSIBILITY_ACCESSIBLE_DOCUMENT_VIEW_BASE_HXX
#include "AccessibleDocumentViewBase.hxx"
#endif

#ifndef _SVX_ACCESSILE_TEXT_HELPER_HXX_
#include <svx/AccessibleTextHelper.hxx>
#endif

namespace sd {
class OutlineViewShell;
class Window;
}

namespace accessibility {

/** This class makes the Impress outline view accessible.

    Please see the documentation of the base class for further
    explanations of the individual methods. This class is a mere
    wrapper around the AccessibleTextHelper class; as basically the
    Outline View is a big Outliner.
*/
class AccessibleOutlineView
    : public AccessibleDocumentViewBase
{
public:
    AccessibleOutlineView (
        ::sd::Window* pSdWindow,
        ::sd::OutlineViewShell* pViewShell,
        const ::com::sun::star::uno::Reference<
        ::com::sun::star::frame::XController>& rxController,
        const ::com::sun::star::uno::Reference<
        ::com::sun::star::accessibility::XAccessible>& rxParent);

    virtual ~AccessibleOutlineView  (void);

    /** Complete the initialization begun in the constructor.
    */
    virtual void Init (void);

    //=====  IAccessibleViewForwarderListener  ================================

    virtual void ViewForwarderChanged (ChangeType aChangeType,
        const IAccessibleViewForwarder* pViewForwarder);

    //=====  XAccessibleContext  ==============================================

    virtual sal_Int32 SAL_CALL
        getAccessibleChildCount (void)
        throw (::com::sun::star::uno::RuntimeException);

    virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
        getAccessibleChild (sal_Int32 nIndex)
        throw (::com::sun::star::uno::RuntimeException);

    //=====  XAccessibleEventBroadcaster  ========================================

    virtual void SAL_CALL
        addEventListener (
            const ::com::sun::star::uno::Reference<
                ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
        throw (::com::sun::star::uno::RuntimeException);

    virtual void SAL_CALL
        removeEventListener (
            const ::com::sun::star::uno::Reference<
                ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
        throw (::com::sun::star::uno::RuntimeException);

    using cppu::WeakComponentImplHelperBase::addEventListener;
    using cppu::WeakComponentImplHelperBase::removeEventListener;

    //=====  XServiceInfo  ====================================================

    /** Returns an identifier for the implementation of this object.
    */
    virtual ::rtl::OUString SAL_CALL
        getImplementationName (void)
        throw (::com::sun::star::uno::RuntimeException);

    //=====  lang::XEventListener  ============================================

    virtual void SAL_CALL
        disposing (const ::com::sun::star::lang::EventObject& rEventObject)
        throw (::com::sun::star::uno::RuntimeException);

    //=====  XPropertyChangeListener  =========================================

    virtual void SAL_CALL
        propertyChange (const ::com::sun::star::beans::PropertyChangeEvent& rEventObject)
        throw (::com::sun::star::uno::RuntimeException);

protected:

    // overridden, as we hold the listeners ourselves
    virtual void FireEvent (const ::com::sun::star::accessibility::AccessibleEventObject& aEvent);

    // overridden to detect focus changes
    virtual void Activated (void);

    // overridden to detect focus changes
    virtual void Deactivated (void);

    // declared, but not defined
    AccessibleOutlineView( const AccessibleOutlineView& );
    AccessibleOutlineView& operator= ( const AccessibleOutlineView& );

    // This method is called from the component helper base class while disposing.
    virtual void SAL_CALL disposing (void);

    /// Create an accessible name that contains the current view mode.
    virtual ::rtl::OUString
        CreateAccessibleName ()
        throw (::com::sun::star::uno::RuntimeException);

    /// Create an accessible description that contains the current
    /// view mode.
    virtual ::rtl::OUString
        CreateAccessibleDescription ()
        throw (::com::sun::star::uno::RuntimeException);

private:

    /// Invalidate text helper, updates visible children
    void UpdateChildren();

    AccessibleTextHelper maTextHelper;

};

} // end of namespace accessibility

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.9.222); FILE MERGED 2008/04/01 15:35:00 thb 1.9.222.3: #i85898# Stripping all external header guards 2008/04/01 12:38:58 thb 1.9.222.2: #i85898# Stripping all external header guards 2008/03/31 13:58:08 rt 1.9.222.1: #i87441# Change license header to LPGL v3.<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: AccessibleOutlineView.hxx,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.
 *
 ************************************************************************/

#ifndef SD_ACCESSIBILITY_ACCESSIBLE_OUTLINE_VIEW_HXX
#define SD_ACCESSIBILITY_ACCESSIBLE_OUTLINE_VIEW_HXX

#include "AccessibleDocumentViewBase.hxx"
#include <svx/AccessibleTextHelper.hxx>

namespace sd {
class OutlineViewShell;
class Window;
}

namespace accessibility {

/** This class makes the Impress outline view accessible.

    Please see the documentation of the base class for further
    explanations of the individual methods. This class is a mere
    wrapper around the AccessibleTextHelper class; as basically the
    Outline View is a big Outliner.
*/
class AccessibleOutlineView
    : public AccessibleDocumentViewBase
{
public:
    AccessibleOutlineView (
        ::sd::Window* pSdWindow,
        ::sd::OutlineViewShell* pViewShell,
        const ::com::sun::star::uno::Reference<
        ::com::sun::star::frame::XController>& rxController,
        const ::com::sun::star::uno::Reference<
        ::com::sun::star::accessibility::XAccessible>& rxParent);

    virtual ~AccessibleOutlineView  (void);

    /** Complete the initialization begun in the constructor.
    */
    virtual void Init (void);

    //=====  IAccessibleViewForwarderListener  ================================

    virtual void ViewForwarderChanged (ChangeType aChangeType,
        const IAccessibleViewForwarder* pViewForwarder);

    //=====  XAccessibleContext  ==============================================

    virtual sal_Int32 SAL_CALL
        getAccessibleChildCount (void)
        throw (::com::sun::star::uno::RuntimeException);

    virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
        getAccessibleChild (sal_Int32 nIndex)
        throw (::com::sun::star::uno::RuntimeException);

    //=====  XAccessibleEventBroadcaster  ========================================

    virtual void SAL_CALL
        addEventListener (
            const ::com::sun::star::uno::Reference<
                ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
        throw (::com::sun::star::uno::RuntimeException);

    virtual void SAL_CALL
        removeEventListener (
            const ::com::sun::star::uno::Reference<
                ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
        throw (::com::sun::star::uno::RuntimeException);

    using cppu::WeakComponentImplHelperBase::addEventListener;
    using cppu::WeakComponentImplHelperBase::removeEventListener;

    //=====  XServiceInfo  ====================================================

    /** Returns an identifier for the implementation of this object.
    */
    virtual ::rtl::OUString SAL_CALL
        getImplementationName (void)
        throw (::com::sun::star::uno::RuntimeException);

    //=====  lang::XEventListener  ============================================

    virtual void SAL_CALL
        disposing (const ::com::sun::star::lang::EventObject& rEventObject)
        throw (::com::sun::star::uno::RuntimeException);

    //=====  XPropertyChangeListener  =========================================

    virtual void SAL_CALL
        propertyChange (const ::com::sun::star::beans::PropertyChangeEvent& rEventObject)
        throw (::com::sun::star::uno::RuntimeException);

protected:

    // overridden, as we hold the listeners ourselves
    virtual void FireEvent (const ::com::sun::star::accessibility::AccessibleEventObject& aEvent);

    // overridden to detect focus changes
    virtual void Activated (void);

    // overridden to detect focus changes
    virtual void Deactivated (void);

    // declared, but not defined
    AccessibleOutlineView( const AccessibleOutlineView& );
    AccessibleOutlineView& operator= ( const AccessibleOutlineView& );

    // This method is called from the component helper base class while disposing.
    virtual void SAL_CALL disposing (void);

    /// Create an accessible name that contains the current view mode.
    virtual ::rtl::OUString
        CreateAccessibleName ()
        throw (::com::sun::star::uno::RuntimeException);

    /// Create an accessible description that contains the current
    /// view mode.
    virtual ::rtl::OUString
        CreateAccessibleDescription ()
        throw (::com::sun::star::uno::RuntimeException);

private:

    /// Invalidate text helper, updates visible children
    void UpdateChildren();

    AccessibleTextHelper maTextHelper;

};

} // end of namespace accessibility

#endif
<|endoftext|>