<commit_before>/*************************************************************************
 *
 *  $RCSfile: setupdate.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: hr $ $Date: 2003-03-19 16:18:37 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#include "setupdate.hxx"

#ifndef CONFIGMGR_API_BASEACCESSIMPL_HXX_
#include "accessimpl.hxx"
#endif
#ifndef CONFIGMGR_API_BASEUPDATEIMPL_HXX_
#include "updateimpl.hxx"
#endif

#ifndef CONFIGMGR_API_NODEUPDATE_HXX_
#include "apinodeupdate.hxx"
#endif
#ifndef CONFIGMGR_API_APITYPES_HXX_
#include "apitypes.hxx"
#endif

#ifndef _CPPUHELPER_QUERYINTERFACE_HXX_
#include <cppuhelper/queryinterface.hxx>
#endif
#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
#include <cppuhelper/typeprovider.hxx>
#endif

namespace configmgr
{
//////////////////////////////////////////////////////////////////////////////////

    using uno::Reference;
    using uno::Sequence;
    using uno::Any;
    using uno::RuntimeException;

//////////////////////////////////////////////////////////////////////////////////
// classes BasicSet / BasicValueSet
//////////////////////////////////////////////////////////////////////////////////

// XInterface joining
//////////////////////////////////////////////////////////////////////////////////
uno::Any SAL_CALL BasicSet::queryInterface( uno::Type const& rType ) throw (uno::RuntimeException )
{
    Any aRet = BasicSetAccess::queryInterface( rType );
    if (!aRet.hasValue())
    {
        aRet = cppu::queryInterface(rType
                    , static_cast< css::container::XNameContainer *>(this)
                    , static_cast< css::container::XNameReplace *>(this)
                    , static_cast< css::lang::XSingleServiceFactory *>(this)
                    );
    }
    return aRet;
}
//..............................................................................

uno::Any SAL_CALL BasicValueSet::queryInterface( uno::Type const& rType ) throw (uno::RuntimeException )
{
    Any aRet = BasicSetAccess::queryInterface( rType );
    if (!aRet.hasValue())
    {
        aRet = cppu::queryInterface(rType
                    , static_cast< css::container::XNameContainer *>(this)
                    , static_cast< css::container::XNameReplace *>(this)
                    );
    }
    return aRet;
}

// XTypeProvider joining
//////////////////////////////////////////////////////////////////////////////////
uno::Sequence< uno::Type > SAL_CALL BasicSet::getTypes( ) throw (uno::RuntimeException )
{
    /*static ?*/
    cppu::OTypeCollection aTypes(
        configapi::getReferenceType(static_cast< css::container::XNameContainer *>(this)),
        configapi::getReferenceType(static_cast< css::container::XNameReplace *>(this)),
        configapi::getReferenceType(static_cast< css::lang::XSingleServiceFactory *>(this)),
        BasicSetAccess::getTypes());

    return aTypes.getTypes();
}
//..............................................................................

uno::Sequence< uno::Type > SAL_CALL BasicValueSet::getTypes( ) throw (uno::RuntimeException )
{
    /*static ?*/
    cppu::OTypeCollection aTypes(
        configapi::getReferenceType(static_cast< css::container::XNameContainer *>(this)),
        configapi::getReferenceType(static_cast< css::container::XNameReplace *>(this)),
        BasicSetAccess::getTypes());

    return aTypes.getTypes();
}

//uno::Sequence< sal_Int8 > SAL_CALL BasicSet::getImplementationId( ) throw (uno::RuntimeException ) = 0;
//uno::Sequence< sal_Int8 > SAL_CALL BasicValueSet::getImplementationId( ) throw (uno::RuntimeException ) = 0;

// safe write access
//////////////////////////////////////////////////////////////////////////////////
configapi::NodeTreeSetAccess& BasicSet::getSetNode()
{
    configapi::NodeTreeSetAccess* pAccess = maybeGetUpdateAccess();
    OSL_ENSURE(pAccess, "Write operation invoked on a read-only node access - failing with RuntimeException");

    if (!pAccess)
    {
        throw uno::RuntimeException(
                OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: Invalid Object - internal update-interface missing.")),
                static_cast< css::container::XNameReplace * >(this)
            );
    }
    return *pAccess;
}

configapi::NodeValueSetAccess& BasicValueSet::getSetNode()
{
    configapi::NodeValueSetAccess* pAccess = maybeGetUpdateAccess();
    OSL_ENSURE(pAccess, "Write operation invoked on a read-only node access - failing with RuntimeException");

    if (!pAccess)
    {
        throw uno::RuntimeException(
                OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: Invalid Object - internal update-interface missing.")),
                static_cast< css::container::XNameReplace* >(this)
            );
    }
    return *pAccess;
}

// New Interface methods
// XNameReplace
//////////////////////////////////////////////////////////////////////////////////
void SAL_CALL BasicSet::replaceByName( const OUString& rName, const uno::Any& rElement )
        throw(css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implReplaceByName( getSetNode(), rName, rElement );
}
//..............................................................................

void SAL_CALL BasicValueSet::replaceByName( const OUString& rName, const uno::Any& rElement )
        throw(css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implReplaceByName( getSetNode(), rName, rElement );
}

// XNameContainer
//////////////////////////////////////////////////////////////////////////////////
void SAL_CALL BasicSet::insertByName( const OUString& rName, const uno::Any& rElement)
        throw(css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implInsertByName( getSetNode(), rName, rElement );
}
//..............................................................................

void SAL_CALL BasicValueSet::insertByName( const OUString& rName, const uno::Any& rElement)
        throw(css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implInsertByName( getSetNode(), rName, rElement );
}

//----------------------------------------------------------------------------------
void SAL_CALL BasicSet::removeByName( const OUString& rName )
        throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implRemoveByName( getSetNode(), rName );
}
//..............................................................................

void SAL_CALL BasicValueSet::removeByName( const OUString& rName )
        throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implRemoveByName( getSetNode(), rName );
}

// XPropertyWithState
//////////////////////////////////////////////////////////////////////////////////

css::beans::PropertyState SAL_CALL BasicSet::getStateAsProperty() throw (uno::RuntimeException)
{
    return configapi::implGetStateAsProperty( getSetNode() );
}
//..............................................................................

css::beans::PropertyState SAL_CALL BasicValueSet::getStateAsProperty() throw (uno::RuntimeException)
{
    return configapi::implGetStateAsProperty( getSetNode() );
}
//-----------------------------------------------------------------------------------

void SAL_CALL BasicSet::setToDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implSetToDefaultAsProperty( getSetNode() );
}
//..............................................................................

void SAL_CALL BasicValueSet::setToDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implSetToDefaultAsProperty( getSetNode() );
}
//-----------------------------------------------------------------------------------

uno::Reference< uno::XInterface > SAL_CALL BasicSet::getDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    return configapi::implGetDefaultAsProperty( getSetNode() );
}
//..............................................................................

uno::Reference< uno::XInterface > SAL_CALL BasicValueSet::getDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    return configapi::implGetDefaultAsProperty( getSetNode() );
}

// XSingleServiceFactory (not for ValueSet)
//////////////////////////////////////////////////////////////////////////////////
uno::Reference< uno::XInterface > SAL_CALL BasicSet::createInstance(  )
        throw(uno::Exception, uno::RuntimeException)
{
    return configapi::implCreateElement( getSetNode() );
}

//----------------------------------------------------------------------------------
uno::Reference< uno::XInterface > SAL_CALL BasicSet::createInstanceWithArguments( const uno::Sequence< uno::Any >& aArguments )
        throw(uno::Exception, uno::RuntimeException)
{
    return configapi::implCreateElement( getSetNode(), aArguments );
}

//-----------------------------------------------------------------------------------
} // namespace configmgr

<commit_msg>INTEGRATION: CWS cfgfix01 (1.3.170); FILE MERGED 2005/02/18 18:23:37 jb 1.3.170.1: #i42900# Enable forgotten XPropertyWithState implementation<commit_after>/*************************************************************************
 *
 *  $RCSfile: setupdate.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2005-03-18 10:35:07 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#include "setupdate.hxx"

#ifndef CONFIGMGR_API_BASEACCESSIMPL_HXX_
#include "accessimpl.hxx"
#endif
#ifndef CONFIGMGR_API_BASEUPDATEIMPL_HXX_
#include "updateimpl.hxx"
#endif

#ifndef CONFIGMGR_API_NODEUPDATE_HXX_
#include "apinodeupdate.hxx"
#endif
#ifndef CONFIGMGR_API_APITYPES_HXX_
#include "apitypes.hxx"
#endif

#ifndef _CPPUHELPER_QUERYINTERFACE_HXX_
#include <cppuhelper/queryinterface.hxx>
#endif
#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
#include <cppuhelper/typeprovider.hxx>
#endif

namespace configmgr
{
//////////////////////////////////////////////////////////////////////////////////

    using uno::Reference;
    using uno::Sequence;
    using uno::Any;
    using uno::RuntimeException;

//////////////////////////////////////////////////////////////////////////////////
// classes BasicSet / BasicValueSet
//////////////////////////////////////////////////////////////////////////////////

// XInterface joining
//////////////////////////////////////////////////////////////////////////////////
uno::Any SAL_CALL BasicSet::queryInterface( uno::Type const& rType ) throw (uno::RuntimeException )
{
    Any aRet = BasicSetAccess::queryInterface( rType );
    if (!aRet.hasValue())
    {
        aRet = cppu::queryInterface(rType
                    , static_cast< css::container::XNameContainer *>(this)
                    , static_cast< css::container::XNameReplace *>(this)
                    , static_cast< css::beans::XPropertyWithState *>(this)
                    , static_cast< css::lang::XSingleServiceFactory *>(this)
                    );
    }
    return aRet;
}
//..............................................................................

uno::Any SAL_CALL BasicValueSet::queryInterface( uno::Type const& rType ) throw (uno::RuntimeException )
{
    Any aRet = BasicSetAccess::queryInterface( rType );
    if (!aRet.hasValue())
    {
        aRet = cppu::queryInterface(rType
                    , static_cast< css::container::XNameContainer *>(this)
                    , static_cast< css::container::XNameReplace *>(this)
                    , static_cast< css::beans::XPropertyWithState *>(this)
                    );
    }
    return aRet;
}

// XTypeProvider joining
//////////////////////////////////////////////////////////////////////////////////
uno::Sequence< uno::Type > SAL_CALL BasicSet::getTypes( ) throw (uno::RuntimeException )
{
    /*static ?*/
    cppu::OTypeCollection aTypes(
        configapi::getReferenceType(static_cast< css::container::XNameContainer *>(this)),
        configapi::getReferenceType(static_cast< css::container::XNameReplace *>(this)),
        configapi::getReferenceType(static_cast< css::beans::XPropertyWithState *>(this)),
        configapi::getReferenceType(static_cast< css::lang::XSingleServiceFactory *>(this)),
        BasicSetAccess::getTypes());

    return aTypes.getTypes();
}
//..............................................................................

uno::Sequence< uno::Type > SAL_CALL BasicValueSet::getTypes( ) throw (uno::RuntimeException )
{
    /*static ?*/
    cppu::OTypeCollection aTypes(
        configapi::getReferenceType(static_cast< css::container::XNameContainer *>(this)),
        configapi::getReferenceType(static_cast< css::container::XNameReplace *>(this)),
        configapi::getReferenceType(static_cast< css::beans::XPropertyWithState *>(this)),
        BasicSetAccess::getTypes());

    return aTypes.getTypes();
}

//uno::Sequence< sal_Int8 > SAL_CALL BasicSet::getImplementationId( ) throw (uno::RuntimeException ) = 0;
//uno::Sequence< sal_Int8 > SAL_CALL BasicValueSet::getImplementationId( ) throw (uno::RuntimeException ) = 0;

// safe write access
//////////////////////////////////////////////////////////////////////////////////
configapi::NodeTreeSetAccess& BasicSet::getSetNode()
{
    configapi::NodeTreeSetAccess* pAccess = maybeGetUpdateAccess();
    OSL_ENSURE(pAccess, "Write operation invoked on a read-only node access - failing with RuntimeException");

    if (!pAccess)
    {
        throw uno::RuntimeException(
                OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: Invalid Object - internal update-interface missing.")),
                static_cast< css::container::XNameReplace * >(this)
            );
    }
    return *pAccess;
}

configapi::NodeValueSetAccess& BasicValueSet::getSetNode()
{
    configapi::NodeValueSetAccess* pAccess = maybeGetUpdateAccess();
    OSL_ENSURE(pAccess, "Write operation invoked on a read-only node access - failing with RuntimeException");

    if (!pAccess)
    {
        throw uno::RuntimeException(
                OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: Invalid Object - internal update-interface missing.")),
                static_cast< css::container::XNameReplace* >(this)
            );
    }
    return *pAccess;
}

// New Interface methods
// XNameReplace
//////////////////////////////////////////////////////////////////////////////////
void SAL_CALL BasicSet::replaceByName( const OUString& rName, const uno::Any& rElement )
        throw(css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implReplaceByName( getSetNode(), rName, rElement );
}
//..............................................................................

void SAL_CALL BasicValueSet::replaceByName( const OUString& rName, const uno::Any& rElement )
        throw(css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implReplaceByName( getSetNode(), rName, rElement );
}

// XNameContainer
//////////////////////////////////////////////////////////////////////////////////
void SAL_CALL BasicSet::insertByName( const OUString& rName, const uno::Any& rElement)
        throw(css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implInsertByName( getSetNode(), rName, rElement );
}
//..............................................................................

void SAL_CALL BasicValueSet::insertByName( const OUString& rName, const uno::Any& rElement)
        throw(css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implInsertByName( getSetNode(), rName, rElement );
}

//----------------------------------------------------------------------------------
void SAL_CALL BasicSet::removeByName( const OUString& rName )
        throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implRemoveByName( getSetNode(), rName );
}
//..............................................................................

void SAL_CALL BasicValueSet::removeByName( const OUString& rName )
        throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implRemoveByName( getSetNode(), rName );
}

// XPropertyWithState
//////////////////////////////////////////////////////////////////////////////////

css::beans::PropertyState SAL_CALL BasicSet::getStateAsProperty() throw (uno::RuntimeException)
{
    return configapi::implGetStateAsProperty( getSetNode() );
}
//..............................................................................

css::beans::PropertyState SAL_CALL BasicValueSet::getStateAsProperty() throw (uno::RuntimeException)
{
    return configapi::implGetStateAsProperty( getSetNode() );
}
//-----------------------------------------------------------------------------------

void SAL_CALL BasicSet::setToDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implSetToDefaultAsProperty( getSetNode() );
}
//..............................................................................

void SAL_CALL BasicValueSet::setToDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    configapi::implSetToDefaultAsProperty( getSetNode() );
}
//-----------------------------------------------------------------------------------

uno::Reference< uno::XInterface > SAL_CALL BasicSet::getDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    return configapi::implGetDefaultAsProperty( getSetNode() );
}
//..............................................................................

uno::Reference< uno::XInterface > SAL_CALL BasicValueSet::getDefaultAsProperty() throw (css::lang::WrappedTargetException, uno::RuntimeException)
{
    return configapi::implGetDefaultAsProperty( getSetNode() );
}

// XSingleServiceFactory (not for ValueSet)
//////////////////////////////////////////////////////////////////////////////////
uno::Reference< uno::XInterface > SAL_CALL BasicSet::createInstance(  )
        throw(uno::Exception, uno::RuntimeException)
{
    return configapi::implCreateElement( getSetNode() );
}

//----------------------------------------------------------------------------------
uno::Reference< uno::XInterface > SAL_CALL BasicSet::createInstanceWithArguments( const uno::Sequence< uno::Any >& aArguments )
        throw(uno::Exception, uno::RuntimeException)
{
    return configapi::implCreateElement( getSetNode(), aArguments );
}

//-----------------------------------------------------------------------------------
} // namespace configmgr

<|endoftext|>


<commit_before>/* $Id$
 * Version: $Name$
 *
 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005 by the deal.II authors
 *
 * This file is subject to QPL and may not be  distributed
 * without copyright and license information. Please refer
 * to the file deal.II/doc/license.html for the  text  and
 * further information on this license.
 */

				 // @sect3{Include files}

                                 // The most fundamental class in the
                                 // library is the ``Triangulation''
                                 // class, which is declared here:
#include <grid/tria.h>
                                 // We need the following two includes
                                 // for loops over cells and/or faces:
#include <grid/tria_accessor.h>
#include <grid/tria_iterator.h>
                                 // Here are some functions to
                                 // generate standard grids:
#include <grid/grid_generator.h>
                                 // We would like to use boundaries
                                 // which are not straight lines, so
                                 // we import some classes which
                                 // predefine some boundary
                                 // descriptions:
#include <grid/tria_boundary_lib.h>
                                 // Output of grids in various
                                 // graphics formats:
#include <grid/grid_out.h>

                                 // This is needed for C++ output:
#include <fstream>
				 // And this for the declarations of the
				 // `sqrt' and `fabs' functions:
#include <cmath>

				 // @sect3{Creating the first mesh}

                                 // In the following, first function, we
                                 // simply use the unit square as
                                 // domain and produce a globally
                                 // refined grid from it.
void first_grid ()
{
                                   // The first thing to do is to
                                   // define an object for a
                                   // triangulation of a
                                   // two-dimensional domain:
  Triangulation<2> triangulation;
				   // Here and in many following
                                   // cases, the string "<2>" after a
                                   // class name indicates that this
                                   // is an object that shall work in
                                   // two space dimensions. Likewise,
                                   // there are versions of the
                                   // triangulation class that are
                                   // working in one ("<1>") and three
                                   // ("<3>") space dimensions. The
                                   // way this works is through some
                                   // template magic that we will
                                   // investigate in some more detail
                                   // in later example programs;
                                   // there, we will also see how to
                                   // write programs in an essentially
                                   // dimension independent way.

                                   // Next, we want to fill the
                                   // triangulation with a single cell
                                   // for a square domain. The
                                   // triangulation is the refined
                                   // four times, to yield 4^4=256
                                   // cells in total:
  GridGenerator::hyper_cube (triangulation);
  triangulation.refine_global (4);

                                   // Now we want to write a graphical
                                   // representation of the mesh to an
                                   // output file. The ``GridOut''
                                   // class of deal.II can do that in
                                   // a number of different output
                                   // formats; here, we choose
                                   // encapsulated postscript (eps)
                                   // format:
  std::ofstream out ("grid-1.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);
}

				 // @sect3{Creating the second mesh}

                                 // The grid in the following, second
                                 // function is slightly more
                                 // complicated in that we use a ring
                                 // domain and refine the result once
                                 // globally.
void second_grid ()
{
                                   // We start again by defining an
                                   // object for a triangulation of a
                                   // two-dimensional domain:
  Triangulation<2> triangulation;

                                   // We then fill it with a ring
                                   // domain. The center of the ring
                                   // shall be the point (1,0), and
                                   // inner and outer radius shall be
                                   // 0.5 and 1. The number of
                                   // circumferential cells could be
                                   // adjusted automatically by this
                                   // function, but we choose to set
                                   // it explicitely to 10 as the last
                                   // argument:
  const Point<2> center (1,0);
  const double inner_radius = 0.5,
               outer_radius = 1.0;
  GridGenerator::hyper_shell (triangulation,
                              center, inner_radius, outer_radius,
			      10);
                                   // By default, the triangulation
                                   // assumes that all boundaries are
                                   // straight and given by the cells
                                   // of the coarse grid (which we
                                   // just created). It uses this
                                   // information when cells at the
                                   // boundary are refined and new
                                   // points need to be introduced on
                                   // the boundary; if the boundary is
                                   // assumed to be straight, then new
                                   // points will simply be in the
                                   // middle of the surrounding ones.
				   //
				   // Here, however, we would like to
                                   // have a curved
                                   // boundary. Fortunately, some good
                                   // soul implemented an object which
                                   // describes the boundary of a ring
                                   // domain; it only needs the center
                                   // of the ring and automatically
                                   // figures out the inner and outer
                                   // radius when needed. Note that we
                                   // associate this boundary object
                                   // with that part of the boundary
                                   // that has the "boundary
                                   // indicator" zero. By default, all
                                   // boundary parts have this number,
                                   // but you can change this number
                                   // for some parts of the
                                   // boundary. In that case, the
                                   // curved boundary thus associated
                                   // with number zero will not apply
                                   // on those parts with a non-zero
                                   // boundary indicator, but other
                                   // boundary description objects can
                                   // be associated with those
                                   // non-zero indicators. If no
                                   // boundary description is
                                   // associated with a particular
                                   // boundary indicator, a straight
                                   // boundary is implied.
  const HyperShellBoundary<2> boundary_description(center);
  triangulation.set_boundary (0, boundary_description);

                                   // In order to demonstrate how to
                                   // write a loop over all cells, we
                                   // will refine the grid in five
                                   // steps towards the inner circle
                                   // of the domain:
  for (unsigned int step=0; step<5; ++step)
    {
                                       // Next, we need an iterator
                                       // which points to a cell and
                                       // which we will move over all
                                       // active cells one by one
                                       // (active cells are those that
                                       // are not further refined, and
                                       // the only ones that can be
                                       // marked for further
                                       // refinement, obviously). By
                                       // convention, we almost always
                                       // use the names ``cell'' and
                                       // ``endc'' for the iterator
                                       // pointing to the present cell
                                       // and to the
                                       // ``one-past-the-end''
                                       // iterator:
      Triangulation<2>::active_cell_iterator
	cell = triangulation.begin_active(),
	endc = triangulation.end();

                                       // The loop over all cells is
                                       // then rather trivial, and
                                       // looks like any loop
                                       // involving pointers instead
                                       // of iterators:
      for (; cell!=endc; ++cell)
                                         // Next, we want to loop over
                                         // all vertices of the
                                         // cells. Since we are in 2d,
                                         // we know that each cell has
                                         // exactly four
                                         // vertices. However, instead
                                         // of penning down a 4 in the
                                         // loop bound, we make a
                                         // first attempt at writing
                                         // it in a
                                         // dimension-independent way
                                         // by which we find out about
                                         // the number of vertices of
                                         // a cell. Using the
                                         // ``GeometryInfo'' class, we
                                         // will later have an easier
                                         // time getting the program
                                         // to also run in 3d: we only
                                         // have to change all
                                         // occurrences of ``<2>'' to
                                         // ``<3>'', and do not have
                                         // to audit our code for the
                                         // hidden appearance of magic
                                         // numbers like a 4 that
                                         // needs to be replaced by an
                                         // 8:
        for (unsigned int vertex=0;
             vertex < GeometryInfo<2>::vertices_per_cell;
             ++vertex)
          {
                                             // If this cell is at the
                                             // inner boundary, then
                                             // at least one of its
                                             // vertices must sit on
                                             // the inner ring and
                                             // therefore have a
                                             // radial distance from
                                             // the center of exactly
                                             // 0.5, up to floating
                                             // point
                                             // accuracy. Compute this
                                             // distance, and if we
                                             // have found a vertex
                                             // with this property
                                             // flag this cell for
                                             // later refinement. We
                                             // can then also break
                                             // the loop over all
                                             // vertices and move on
                                             // to the next cell.
            const double distance_from_center
              = center.distance (cell->vertex(vertex));

            if (std::fabs(distance_from_center - inner_radius) < 1e-10)
              {
                cell->set_refine_flag ();
                break;
              };
          };

                                       // Now that we have marked all
                                       // the cells that we want
                                       // refined, we let the
                                       // triangulation actually do
                                       // this refinement. The
                                       // function that does so owes
                                       // its long name to the fact
                                       // that one can also mark cells
                                       // for coarsening, and the
                                       // function does coarsening and
                                       // refinement all at once:
      triangulation.execute_coarsening_and_refinement ();
    };

                                   // Finally, after these five
                                   // iterations of refinement, we
                                   // want to again write the
                                   // resulting mesh to a file, again
                                   // in eps format. This works just
                                   // as above:
  std::ofstream out ("grid-2.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);

                                   // At this point, all objects
                                   // created in this function will be
                                   // destroyed in reverse
                                   // order. Unfortunately, we defined
                                   // the boundary object after the
                                   // triangulation, which still has a
                                   // pointer to it and the library
                                   // will produce an error if the
                                   // boundary object is destroyed
                                   // before the triangulation. We
                                   // therefore have to release it,
                                   // which can be done as
                                   // follows. Note that this sets the
                                   // boundary object used for part
                                   // "0" of the boundary back to a
                                   // default object, over which the
                                   // triangulation has full control.
  triangulation.set_boundary (0);
				   // An alternative to doing so, and
				   // one that is frequently more
				   // convenient, would have been to
				   // declare the boundary object
				   // before the triangulation
				   // object. In that case, the
				   // triangulation would have let
				   // lose of the boundary object upon
				   // its destruction, and everything
				   // would have been fine.
}

				 // @sect3{The main function}

                                 // Finally, the main function. There
                                 // isn't much to do here, only to
                                 // call the two subfunctions, which
                                 // produce the two grids.
int main ()
{
  first_grid ();
  second_grid ();
}

<commit_msg>Add 2006.<commit_after>/* $Id$
 * Version: $Name$
 *
 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006 by the deal.II authors
 *
 * This file is subject to QPL and may not be  distributed
 * without copyright and license information. Please refer
 * to the file deal.II/doc/license.html for the  text  and
 * further information on this license.
 */

				 // @sect3{Include files}

                                 // The most fundamental class in the
                                 // library is the ``Triangulation''
                                 // class, which is declared here:
#include <grid/tria.h>
                                 // We need the following two includes
                                 // for loops over cells and/or faces:
#include <grid/tria_accessor.h>
#include <grid/tria_iterator.h>
                                 // Here are some functions to
                                 // generate standard grids:
#include <grid/grid_generator.h>
                                 // We would like to use boundaries
                                 // which are not straight lines, so
                                 // we import some classes which
                                 // predefine some boundary
                                 // descriptions:
#include <grid/tria_boundary_lib.h>
                                 // Output of grids in various
                                 // graphics formats:
#include <grid/grid_out.h>

                                 // This is needed for C++ output:
#include <fstream>
				 // And this for the declarations of the
				 // `sqrt' and `fabs' functions:
#include <cmath>

				 // @sect3{Creating the first mesh}

                                 // In the following, first function, we
                                 // simply use the unit square as
                                 // domain and produce a globally
                                 // refined grid from it.
void first_grid ()
{
                                   // The first thing to do is to
                                   // define an object for a
                                   // triangulation of a
                                   // two-dimensional domain:
  Triangulation<2> triangulation;
				   // Here and in many following
                                   // cases, the string "<2>" after a
                                   // class name indicates that this
                                   // is an object that shall work in
                                   // two space dimensions. Likewise,
                                   // there are versions of the
                                   // triangulation class that are
                                   // working in one ("<1>") and three
                                   // ("<3>") space dimensions. The
                                   // way this works is through some
                                   // template magic that we will
                                   // investigate in some more detail
                                   // in later example programs;
                                   // there, we will also see how to
                                   // write programs in an essentially
                                   // dimension independent way.

                                   // Next, we want to fill the
                                   // triangulation with a single cell
                                   // for a square domain. The
                                   // triangulation is the refined
                                   // four times, to yield 4^4=256
                                   // cells in total:
  GridGenerator::hyper_cube (triangulation);
  triangulation.refine_global (4);

                                   // Now we want to write a graphical
                                   // representation of the mesh to an
                                   // output file. The ``GridOut''
                                   // class of deal.II can do that in
                                   // a number of different output
                                   // formats; here, we choose
                                   // encapsulated postscript (eps)
                                   // format:
  std::ofstream out ("grid-1.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);
}

				 // @sect3{Creating the second mesh}

                                 // The grid in the following, second
                                 // function is slightly more
                                 // complicated in that we use a ring
                                 // domain and refine the result once
                                 // globally.
void second_grid ()
{
                                   // We start again by defining an
                                   // object for a triangulation of a
                                   // two-dimensional domain:
  Triangulation<2> triangulation;

                                   // We then fill it with a ring
                                   // domain. The center of the ring
                                   // shall be the point (1,0), and
                                   // inner and outer radius shall be
                                   // 0.5 and 1. The number of
                                   // circumferential cells could be
                                   // adjusted automatically by this
                                   // function, but we choose to set
                                   // it explicitely to 10 as the last
                                   // argument:
  const Point<2> center (1,0);
  const double inner_radius = 0.5,
               outer_radius = 1.0;
  GridGenerator::hyper_shell (triangulation,
                              center, inner_radius, outer_radius,
			      10);
                                   // By default, the triangulation
                                   // assumes that all boundaries are
                                   // straight and given by the cells
                                   // of the coarse grid (which we
                                   // just created). It uses this
                                   // information when cells at the
                                   // boundary are refined and new
                                   // points need to be introduced on
                                   // the boundary; if the boundary is
                                   // assumed to be straight, then new
                                   // points will simply be in the
                                   // middle of the surrounding ones.
				   //
				   // Here, however, we would like to
                                   // have a curved
                                   // boundary. Fortunately, some good
                                   // soul implemented an object which
                                   // describes the boundary of a ring
                                   // domain; it only needs the center
                                   // of the ring and automatically
                                   // figures out the inner and outer
                                   // radius when needed. Note that we
                                   // associate this boundary object
                                   // with that part of the boundary
                                   // that has the "boundary
                                   // indicator" zero. By default, all
                                   // boundary parts have this number,
                                   // but you can change this number
                                   // for some parts of the
                                   // boundary. In that case, the
                                   // curved boundary thus associated
                                   // with number zero will not apply
                                   // on those parts with a non-zero
                                   // boundary indicator, but other
                                   // boundary description objects can
                                   // be associated with those
                                   // non-zero indicators. If no
                                   // boundary description is
                                   // associated with a particular
                                   // boundary indicator, a straight
                                   // boundary is implied.
  const HyperShellBoundary<2> boundary_description(center);
  triangulation.set_boundary (0, boundary_description);

                                   // In order to demonstrate how to
                                   // write a loop over all cells, we
                                   // will refine the grid in five
                                   // steps towards the inner circle
                                   // of the domain:
  for (unsigned int step=0; step<5; ++step)
    {
                                       // Next, we need an iterator
                                       // which points to a cell and
                                       // which we will move over all
                                       // active cells one by one
                                       // (active cells are those that
                                       // are not further refined, and
                                       // the only ones that can be
                                       // marked for further
                                       // refinement, obviously). By
                                       // convention, we almost always
                                       // use the names ``cell'' and
                                       // ``endc'' for the iterator
                                       // pointing to the present cell
                                       // and to the
                                       // ``one-past-the-end''
                                       // iterator:
      Triangulation<2>::active_cell_iterator
	cell = triangulation.begin_active(),
	endc = triangulation.end();

                                       // The loop over all cells is
                                       // then rather trivial, and
                                       // looks like any loop
                                       // involving pointers instead
                                       // of iterators:
      for (; cell!=endc; ++cell)
                                         // Next, we want to loop over
                                         // all vertices of the
                                         // cells. Since we are in 2d,
                                         // we know that each cell has
                                         // exactly four
                                         // vertices. However, instead
                                         // of penning down a 4 in the
                                         // loop bound, we make a
                                         // first attempt at writing
                                         // it in a
                                         // dimension-independent way
                                         // by which we find out about
                                         // the number of vertices of
                                         // a cell. Using the
                                         // ``GeometryInfo'' class, we
                                         // will later have an easier
                                         // time getting the program
                                         // to also run in 3d: we only
                                         // have to change all
                                         // occurrences of ``<2>'' to
                                         // ``<3>'', and do not have
                                         // to audit our code for the
                                         // hidden appearance of magic
                                         // numbers like a 4 that
                                         // needs to be replaced by an
                                         // 8:
        for (unsigned int vertex=0;
             vertex < GeometryInfo<2>::vertices_per_cell;
             ++vertex)
          {
                                             // If this cell is at the
                                             // inner boundary, then
                                             // at least one of its
                                             // vertices must sit on
                                             // the inner ring and
                                             // therefore have a
                                             // radial distance from
                                             // the center of exactly
                                             // 0.5, up to floating
                                             // point
                                             // accuracy. Compute this
                                             // distance, and if we
                                             // have found a vertex
                                             // with this property
                                             // flag this cell for
                                             // later refinement. We
                                             // can then also break
                                             // the loop over all
                                             // vertices and move on
                                             // to the next cell.
            const double distance_from_center
              = center.distance (cell->vertex(vertex));

            if (std::fabs(distance_from_center - inner_radius) < 1e-10)
              {
                cell->set_refine_flag ();
                break;
              };
          };

                                       // Now that we have marked all
                                       // the cells that we want
                                       // refined, we let the
                                       // triangulation actually do
                                       // this refinement. The
                                       // function that does so owes
                                       // its long name to the fact
                                       // that one can also mark cells
                                       // for coarsening, and the
                                       // function does coarsening and
                                       // refinement all at once:
      triangulation.execute_coarsening_and_refinement ();
    };

                                   // Finally, after these five
                                   // iterations of refinement, we
                                   // want to again write the
                                   // resulting mesh to a file, again
                                   // in eps format. This works just
                                   // as above:
  std::ofstream out ("grid-2.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);

                                   // At this point, all objects
                                   // created in this function will be
                                   // destroyed in reverse
                                   // order. Unfortunately, we defined
                                   // the boundary object after the
                                   // triangulation, which still has a
                                   // pointer to it and the library
                                   // will produce an error if the
                                   // boundary object is destroyed
                                   // before the triangulation. We
                                   // therefore have to release it,
                                   // which can be done as
                                   // follows. Note that this sets the
                                   // boundary object used for part
                                   // "0" of the boundary back to a
                                   // default object, over which the
                                   // triangulation has full control.
  triangulation.set_boundary (0);
				   // An alternative to doing so, and
				   // one that is frequently more
				   // convenient, would have been to
				   // declare the boundary object
				   // before the triangulation
				   // object. In that case, the
				   // triangulation would have let
				   // lose of the boundary object upon
				   // its destruction, and everything
				   // would have been fine.
}

				 // @sect3{The main function}

                                 // Finally, the main function. There
                                 // isn't much to do here, only to
                                 // call the two subfunctions, which
                                 // produce the two grids.
int main ()
{
  first_grid ();
  second_grid ();
}

<|endoftext|>


<commit_before>
Int_t events;

RICHmenu(Int_t nev=1)
{

  // static Int_t events;

  //printf("Called for %d events.",events);

  //gAlice=0;
  //char *confi="Config.C";
  //Int_t events=10;

  events=nev;

  char *str="\"Number of events %d\"";

   TControlBar *menu = new TControlBar("vertical","RICH menu");
   menu->AddButton("      Help for RICH      ","RICHHelp()", "Explains how to use RICH menus");
   menu->AddButton("Configure",            "gSystem->Exec(\"rconfig\"); gSystem->Exit(0);","Configure the simulation");
   //menu->AddButton("Run",               "RICHInit(nev)","Process an Alice event - WARNING: Overwrites previous data file!");
   menu->AddButton("Run",               "gAlice->Run(events)","Process an Alice event - WARNING: Overwrites previous data file!");
   menu->AddButton("Run Lego",          ".x RICHRunLego.C","Special runs to generate the radl/absl lego plots");
   menu->AddButton("Digitise Event",             ".x RICHdigit.C(0,events-1)","Digitise event");
   menu->AddButton("Clusterize Event",      ".x RICHrawclusters.C(0,events-1)","Reconstruct clusters");
   // TODO: add the diaglevel here before the script
   menu->AddButton("3D Hough Pat. Rec.",      ".x RICHdetect.C(0,events-1)","Lisbon");
   menu->AddButton("1D Hough Pat. Rec.",      ".x RICHpatrec.C(0,events-1)","Bari");
   menu->AddButton("Diagnostics",       ".x RICHDiagnostics.C(events)","Miscellaneous diagnostics");
   menu->AddButton("Display",           ".x RICHdisplay.C","Display run");
   menu->AddButton("Geometry Browser",           "Gui()","Browse the GEANT geometry - WARNING: Overwrites previous data file!");
   menu->AddButton("File Browser",           "TBrowser new;","Browse data files");
//   menu->AddButton("Test",              ".x RICHtest.C","bla bla");
//   menu->AddButton("Edit Configuration",".x RICHConfig.C","Interactive Configuration");
//   menu->AddButton("Draw",              ".x DrawRICH.C","bla bla");
//   menu->AddButton("View",              ".x ViewRICH.C","does nothing???");
   menu->AddButton("Quit AliRoot",             ".q","Close session");
//   menu->AddButton("Reset",             "RICHReset()","Close and Restart AliRoot");

   //gROOT->SaveContext();

   //gAlice->Init(config);
   //((TGeant3*)gMC)->InitHIGZ();

   menu->Show();
}

void RICHHelp()
{
   gSystem->Exec("xemacs RICHHelp.C &");
}

void RICHInit(Int_t events)
{
  gAlice->Init("Config.C");
  ((TGeant3*)gMC)->InitHIGZ();
  gAlice->Run(events);
}

void Gui()
{
  gAlice->Init("Config.C");
  ((TGeant3*)gMC)->InitHIGZ();
  gROOT->ProcessLine(".x TGeant3GUI.C");
  //printf("Doesn't work yet\n");
}

void RICHReset()
{
//   gSystem->Exec("aliroot mrich.C &");

   // This doesn't work for Win (eheheh) and aliroot must be in the path
   gSystem->Exec("xterm +ls -e aliroot mrich.C &");
   gSystem->Exit(0);
}

<commit_msg>New call to RICHHelp<commit_after>
Int_t events;

RICHmenu(Int_t nev=1)
{

  // static Int_t events;

  //printf("Called for %d events.",events);

  //gAlice=0;
  //char *confi="Config.C";
  //Int_t events=10;

  events=nev;

  char *str="\"Number of events %d\"";

   TControlBar *menu = new TControlBar("vertical","RICH menu");
   menu->AddButton("      Help for RICH      ","gSystem->Exec(\"less RICHHelp.txt\");", "Explains how to use RICH menus");
   menu->AddButton("Configure",            "gSystem->Exec(\"rconfig\"); gSystem->Exit(0);","Configure the simulation");
   //menu->AddButton("Run",               "RICHInit(nev)","Process an Alice event - WARNING: Overwrites previous data file!");
   menu->AddButton("Run",               "gAlice->Run(events)","Process an Alice event - WARNING: Overwrites previous data file!");
   menu->AddButton("Run Lego",          ".x RICHRunLego.C","Special runs to generate the radl/absl lego plots");
   menu->AddButton("Digitise Event",             ".x RICHdigit.C(0,events-1)","Digitise event");
   menu->AddButton("Clusterize Event",      ".x RICHrawclusters.C(0,events-1)","Reconstruct clusters");
   // TODO: add the diaglevel here before the script
   menu->AddButton("3D Hough Pat. Rec.",      ".x RICHdetect.C(0,events-1)","Lisbon");
   menu->AddButton("1D Hough Pat. Rec.",      ".x RICHpatrec.C(0,events-1)","Bari");
   menu->AddButton("Diagnostics",       ".x RICHDiagnostics.C(events)","Miscellaneous diagnostics");
   menu->AddButton("Display",           ".x RICHdisplay.C","Display run");
   menu->AddButton("Geometry Browser",           "Gui()","Browse the GEANT geometry - WARNING: Overwrites previous data file!");
   menu->AddButton("File Browser",           "TBrowser new;","Browse data files");
//   menu->AddButton("Test",              ".x RICHtest.C","bla bla");
//   menu->AddButton("Edit Configuration",".x RICHConfig.C","Interactive Configuration");
//   menu->AddButton("Draw",              ".x DrawRICH.C","bla bla");
//   menu->AddButton("View",              ".x ViewRICH.C","does nothing???");
   menu->AddButton("Quit AliRoot",             ".q","Close session");
//   menu->AddButton("Reset",             "RICHReset()","Close and Restart AliRoot");

   //gROOT->SaveContext();

   //gAlice->Init(config);
   //((TGeant3*)gMC)->InitHIGZ();

   menu->Show();
}

void RICHHelp()
{
   gSystem->Exec("xemacs RICHHelp.C &");
}

void RICHInit(Int_t events)
{
  gAlice->Init("Config.C");
  ((TGeant3*)gMC)->InitHIGZ();
  gAlice->Run(events);
}

void Gui()
{
  gAlice->Init("Config.C");
  ((TGeant3*)gMC)->InitHIGZ();
  gROOT->ProcessLine(".x TGeant3GUI.C");
  //printf("Doesn't work yet\n");
}

void RICHReset()
{
//   gSystem->Exec("aliroot mrich.C &");

   // This doesn't work for Win (eheheh) and aliroot must be in the path
   gSystem->Exec("xterm +ls -e aliroot mrich.C &");
   gSystem->Exit(0);
}

<|endoftext|>


<commit_before>/* $Id$ */
/* Author: Wolfgang Bangerth, University of Heidelberg, 1999 */

/*    $Id$       */
/*    Version: $Name$                                          */
/*                                                                */
/*    Copyright (C) 1999, 2000, 2001, 2002, 2003 by the deal.II authors */
/*                                                                */
/*    This file is subject to QPL and may not be  distributed     */
/*    without copyright and license information. Please refer     */
/*    to the file deal.II/doc/license.html for the  text  and     */
/*    further information on this license.                        */

                                 // The most fundamental class in the
                                 // library is the ``Triangulation''
                                 // class, which is declared here:
#include <grid/tria.h>
                                 // We need the following two includes
                                 // for loops over cells and/or faces:
#include <grid/tria_accessor.h>
#include <grid/tria_iterator.h>
                                 // Here are some functions to
                                 // generate standard grids:
#include <grid/grid_generator.h>
                                 // We would like to use boundaries
                                 // which are not straight lines, so
                                 // we import some classes which
                                 // predefine some boundary
                                 // descriptions:
#include <grid/tria_boundary_lib.h>
                                 // Output of grids in various
                                 // graphics formats:
#include <grid/grid_out.h>

                                 // This is needed for C++ output:
#include <fstream>
				 // And this for the declarations of the
				 // `sqrt' and `fabs' functions:
#include <cmath>

                                 // In the following function, we
                                 // simply use the unit square as
                                 // domain and produce a globally
                                 // refined grid from it.
void first_grid ()
{
                                   // Define an object for a
                                   // triangulation of a
                                   // two-dimensional domain. Here and
                                   // in many following cases, the
                                   // string "<2>" after a class name
                                   // indicates that this is an object
                                   // that shall work in two space
                                   // dimensions. Likewise, there are
                                   // version working in one ("<1>")
                                   // and three ("<3>") space
                                   // dimensions, or for all
                                   // dimensions. We will see such
                                   // constructs in later examples,
                                   // where we show how to program
                                   // dimension independently.
                                   // (At present, only one through
                                   // three space dimensions are
                                   // supported, but that is not a
                                   // restriction. In case someone
                                   // would like to implement four
                                   // dimensional finite elements, for
                                   // example for general relativity,
                                   // this would be a straightforward
                                   // thing.)
  Triangulation<2> triangulation;

                                   // Fill it with a square
  GridGenerator::hyper_cube (triangulation);

                                   // Refine all cells four times, to
                                   // yield 4^4=256 cells in total
  triangulation.refine_global (4);

                                   // Now we want to write it to some
                                   // output, here in postscript
                                   // format
  std::ofstream out ("grid-1.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);
}

                                 // The grid in the following function
                                 // is slightly more complicated in
                                 // that we use a ring domain and
                                 // refine the result once globally
void second_grid ()
{
                                   // Define an object for a
                                   // triangulation of a
                                   // two-dimensional domain
  Triangulation<2> triangulation;

                                   // Fill it with a ring domain. The
                                   // center of the ring shall be the
                                   // point (1,0), and inner and outer
                                   // radius shall be 0.5 and 1. The
                                   // number of circumferential cells
                                   // could be adjusted automatically
                                   // by this function, but we choose
                                   // to set it explicitely as the
                                   // last argument
  const Point<2> center (1,0);
  const double inner_radius = 0.5,
               outer_radius = 1.0;
  GridGenerator::hyper_shell (triangulation,
                              center, inner_radius, outer_radius,
			      10);
                                   // By default, the triangulation
                                   // assumes that all boundaries are
                                   // straight and given by the cells
                                   // of the coarse grid (which we
                                   // just created). Here, however, we
                                   // would like to have a curved
                                   // boundary. Fortunately, some good
                                   // soul implemented an object which
                                   // describes the boundary of a ring
                                   // domain; it only needs the center
                                   // of the ring and automatically
                                   // figures out the inner and outer
                                   // radius when needed. Note that we
                                   // associate this boundary object
                                   // with that part of the boundary
                                   // that has the "boundary number"
                                   // zero. By default, all boundary
                                   // parts have this number, but you
                                   // might want to change this number
                                   // for some parts, and then the
                                   // curved boundary thus associated
                                   // with number zero will not apply
                                   // there.
  const HyperShellBoundary<2> boundary_description(center);
  triangulation.set_boundary (0, boundary_description);

                                   // Now, just for the purpose of
                                   // demonstration and for no
                                   // particular reason, we will
                                   // refine the grid in five steps
                                   // towards the inner circle of the
                                   // domain:
  for (unsigned int step=0; step<5; ++step)
    {
                                       // Get an iterator which points
                                       // to a cell and which we will
                                       // move over all active cells
                                       // one by one. Active cells are
                                       // those that are not further
                                       // refined
      Triangulation<2>::active_cell_iterator cell, endc;
      cell = triangulation.begin_active();
      endc = triangulation.end();

                                       // Now loop over all cells...
      for (; cell!=endc; ++cell)
                                         // ...and over all vertices
                                         // of the cells. Note the
                                         // dimension-independent way
                                         // by which we find out about
                                         // the number of faces of a
                                         // cell
        for (unsigned int vertex=0;
             vertex < GeometryInfo<2>::vertices_per_cell;
             ++vertex)
          {
                                             // If this cell is at the
                                             // inner boundary, then
                                             // at least one of its vertices
                                             // must have a radial
                                             // distance from the center
                                             // of 0.5
            const Point<2> vector_to_center
              = (cell->vertex(vertex) - center);
            const double distance_from_center
              = std::sqrt(vector_to_center.square());

            if (std::fabs(distance_from_center - inner_radius) < 1e-10)
              {
                                                 // Ok, this is one of
                                                 // the cells we were
                                                 // looking for. Flag
                                                 // it for refinement
                                                 // and go to the next
                                                 // cell by breaking
                                                 // the loop over all
                                                 // vertices
                cell->set_refine_flag ();
                break;
              };
          };

                                       // Refine the cells which we
                                       // have marked
      triangulation.execute_coarsening_and_refinement ();
    };

                                   // Now we want to write it to some
                                   // output, here in postscript
                                   // format
  std::ofstream out ("grid-2.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);

                                   // At this point, all objects
                                   // created in this function will be
                                   // destroyed in reverse
                                   // order. Unfortunately, we defined
                                   // the boundary object after the
                                   // triangulation, which still has a
                                   // pointer to it and the library
                                   // will produce an error if the
                                   // boundary object is destroyed
                                   // before the triangulation. We
                                   // therefore have to release it,
                                   // which can be done as
                                   // follows. Note that this sets the
                                   // boundary object used for part
                                   // "0" of the boundary back to a
                                   // default object, over which the
                                   // triangulation has full control.
  triangulation.set_boundary (0);
}

                                 // Main function. Only call the two
                                 // subfunctions, which produce the
                                 // two grids.
int main ()
{
  first_grid ();
  second_grid ();
}

<commit_msg>rename vertex number to something more intuitive to students<commit_after>// $Id$
// Version: $Name$
//
//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.

                                 // The most fundamental class in the
                                 // library is the ``Triangulation''
                                 // class, which is declared here:
#include <grid/tria.h>
                                 // We need the following two includes
                                 // for loops over cells and/or faces:
#include <grid/tria_accessor.h>
#include <grid/tria_iterator.h>
                                 // Here are some functions to
                                 // generate standard grids:
#include <grid/grid_generator.h>
                                 // We would like to use boundaries
                                 // which are not straight lines, so
                                 // we import some classes which
                                 // predefine some boundary
                                 // descriptions:
#include <grid/tria_boundary_lib.h>
                                 // Output of grids in various
                                 // graphics formats:
#include <grid/grid_out.h>

                                 // This is needed for C++ output:
#include <fstream>
				 // And this for the declarations of the
				 // `sqrt' and `fabs' functions:
#include <cmath>

                                 // In the following function, we
                                 // simply use the unit square as
                                 // domain and produce a globally
                                 // refined grid from it.
void first_grid ()
{
                                   // Define an object for a
                                   // triangulation of a
                                   // two-dimensional domain. Here and
                                   // in many following cases, the
                                   // string "<2>" after a class name
                                   // indicates that this is an object
                                   // that shall work in two space
                                   // dimensions. Likewise, there are
                                   // version working in one ("<1>")
                                   // and three ("<3>") space
                                   // dimensions, or for all
                                   // dimensions. We will see such
                                   // constructs in later examples,
                                   // where we show how to program
                                   // dimension independently.
                                   // (At present, only one through
                                   // three space dimensions are
                                   // supported, but that is not a
                                   // restriction. In case someone
                                   // would like to implement four
                                   // dimensional finite elements, for
                                   // example for general relativity,
                                   // this would be a straightforward
                                   // thing.)
  Triangulation<2> triangulation;

                                   // Fill it with a square
  GridGenerator::hyper_cube (triangulation);

                                   // Refine all cells four times, to
                                   // yield 4^4=256 cells in total
  triangulation.refine_global (4);

                                   // Now we want to write it to some
                                   // output, here in postscript
                                   // format
  std::ofstream out ("grid-1.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);
}

                                 // The grid in the following function
                                 // is slightly more complicated in
                                 // that we use a ring domain and
                                 // refine the result once globally
void second_grid ()
{
                                   // Define an object for a
                                   // triangulation of a
                                   // two-dimensional domain
  Triangulation<2> triangulation;

                                   // Fill it with a ring domain. The
                                   // center of the ring shall be the
                                   // point (1,0), and inner and outer
                                   // radius shall be 0.5 and 1. The
                                   // number of circumferential cells
                                   // could be adjusted automatically
                                   // by this function, but we choose
                                   // to set it explicitely as the
                                   // last argument
  const Point<2> center (1,0);
  const double inner_radius = 0.5,
               outer_radius = 1.0;
  GridGenerator::hyper_shell (triangulation,
                              center, inner_radius, outer_radius,
			      10);
                                   // By default, the triangulation
                                   // assumes that all boundaries are
                                   // straight and given by the cells
                                   // of the coarse grid (which we
                                   // just created). Here, however, we
                                   // would like to have a curved
                                   // boundary. Fortunately, some good
                                   // soul implemented an object which
                                   // describes the boundary of a ring
                                   // domain; it only needs the center
                                   // of the ring and automatically
                                   // figures out the inner and outer
                                   // radius when needed. Note that we
                                   // associate this boundary object
                                   // with that part of the boundary
                                   // that has the "boundary number"
                                   // zero. By default, all boundary
                                   // parts have this number, but you
                                   // might want to change this number
                                   // for some parts, and then the
                                   // curved boundary thus associated
                                   // with number zero will not apply
                                   // there.
  const HyperShellBoundary<2> boundary_description(center);
  triangulation.set_boundary (0, boundary_description);

                                   // Now, just for the purpose of
                                   // demonstration and for no
                                   // particular reason, we will
                                   // refine the grid in five steps
                                   // towards the inner circle of the
                                   // domain:
  for (unsigned int step=0; step<5; ++step)
    {
                                       // Get an iterator which points
                                       // to a cell and which we will
                                       // move over all active cells
                                       // one by one. Active cells are
                                       // those that are not further
                                       // refined
      Triangulation<2>::active_cell_iterator cell, endc;
      cell = triangulation.begin_active();
      endc = triangulation.end();

                                       // Now loop over all cells...
      for (; cell!=endc; ++cell)
                                         // ...and over all vertices
                                         // of the cells. Note the
                                         // dimension-independent way
                                         // by which we find out about
                                         // the number of faces of a
                                         // cell
        for (unsigned int ivertex=0;
             ivertex < GeometryInfo<2>::vertices_per_cell;
             ++ivertex)
          {
                                             // If this cell is at the
                                             // inner boundary, then
                                             // at least one of its vertices
                                             // must have a radial
                                             // distance from the center
                                             // of 0.5
            const Point<2> vector_to_center
              = (cell->vertex(ivertex) - center);
            const double distance_from_center
              = std::sqrt(vector_to_center.square());

            if (std::fabs(distance_from_center - inner_radius) < 1e-10)
              {
                                                 // Ok, this is one of
                                                 // the cells we were
                                                 // looking for. Flag
                                                 // it for refinement
                                                 // and go to the next
                                                 // cell by breaking
                                                 // the loop over all
                                                 // vertices
                cell->set_refine_flag ();
                break;
              };
          };

                                       // Refine the cells which we
                                       // have marked
      triangulation.execute_coarsening_and_refinement ();
    };

                                   // Now we want to write it to some
                                   // output, here in postscript
                                   // format
  std::ofstream out ("grid-2.eps");
  GridOut grid_out;
  grid_out.write_eps (triangulation, out);

                                   // At this point, all objects
                                   // created in this function will be
                                   // destroyed in reverse
                                   // order. Unfortunately, we defined
                                   // the boundary object after the
                                   // triangulation, which still has a
                                   // pointer to it and the library
                                   // will produce an error if the
                                   // boundary object is destroyed
                                   // before the triangulation. We
                                   // therefore have to release it,
                                   // which can be done as
                                   // follows. Note that this sets the
                                   // boundary object used for part
                                   // "0" of the boundary back to a
                                   // default object, over which the
                                   // triangulation has full control.
  triangulation.set_boundary (0);
}

                                 // Main function. Only call the two
                                 // subfunctions, which produce the
                                 // two grids.
int main ()
{
  first_grid ();
  second_grid ();
}

<|endoftext|>


<commit_before>/* Copyright 2013 Nikita Batov
 *
 * 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. */

#include "analogSensor.h"

#include "i2cCommunicator.h"

const int analogMax = 1024;  //for all analog sensors
const int analogMin = 0;  //for all analog sensors

using namespace trikControl;

AnalogSensor::AnalogSensor(I2cCommunicator &communicator, int i2cCommandNumber)
	: mCommunicator(communicator)
	, mI2cCommandNumber(i2cCommandNumber)
{
}

int AnalogSensor::read()
{
	QByteArray command(2, '\0');
	command[0] = static_cast<char>(mI2cCommandNumber & 0xFF);

	int value = mCommunicator.read(command);

	value = qMin(value, analogMax);
	value = qMax(value, analogMin);

	double const scale = 100.0 / (static_cast<double>(analogMax - analogMin));

	value = (value - analogMin) * scale;

	return value;
}
<commit_msg>Fixed analog sensor reading<commit_after>/* Copyright 2013 Nikita Batov
 *
 * 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. */

#include "analogSensor.h"

#include "i2cCommunicator.h"

const int analogMax = 1024;  //for all analog sensors
const int analogMin = 0;  //for all analog sensors

using namespace trikControl;

AnalogSensor::AnalogSensor(I2cCommunicator &communicator, int i2cCommandNumber)
	: mCommunicator(communicator)
	, mI2cCommandNumber(i2cCommandNumber)
{
}

int AnalogSensor::read()
{
	QByteArray command(1, '\0');
	command[0] = static_cast<char>(mI2cCommandNumber & 0xFF);

	int value = mCommunicator.read(command);

	value = qMin(value, analogMax);
	value = qMax(value, analogMin);

	double const scale = 100.0 / (static_cast<double>(analogMax - analogMin));

	value = (value - analogMin) * scale;

	return value;
}
<|endoftext|>