<commit_before>// Copyright (C) 1999-2017
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#include "grid2d.h"
#include "context.h"
#include "framebase.h"
#include "fitsimage.h"

extern "C" {
  #include "ast.h"
}

extern Grid2dBase* astGrid2dPtr;

Grid2d::Grid2d(Widget* p, Coord::CoordSystem sys, Coord::SkyFrame sky,
	       Coord::SkyFormat format, GridType t,
	       const char* o, const char* v)
  : Grid(sys, sky, format, t, v), Grid2dBase(p,o)
{}

Grid2d::~Grid2d()
{}

int Grid2d::doit(RenderMode rm)
{
  FrameBase* pp = (FrameBase*)parent_;

  matrix_ = pp->widgetToCanvas;
  pixmap_ = pp->pixmap;
  gridGC_ = pp->gridGC_;
  renderMode_ = rm;

  Context* context = pp->keyContext;
  FitsImage* fits = context->fits;

  if (!fits)
    return 1;

  //  int width = fits->width();
  //  int height = fits->height();

  astClearStatus; // just to make sure
  astBegin; // start memory management

  AstFrameSet* frameSet = NULL;
  AstPlot* plot = NULL;

  if (!(frameSet = astFrameSet(astFrame(2,"Domain=WIDGET"),""))) {
    astEnd;
    return 0;
  }

  // map from Widget to Image
  matrixMap(frameSet,fits->widgetToImage,"Domain=IMAGE");

  switch (system_) {
  case Coord::IMAGE:
    break;
  case Coord::PHYSICAL:
    matrixMap(frameSet,fits->imageToPhysical,"Domain=PHYSICAL");
    break;
  case Coord::AMPLIFIER:
    matrixMap(frameSet,fits->imageToAmplifier,"Domain=AMPLIFIER");
    break;
  case Coord::DETECTOR:
    matrixMap(frameSet,fits->imageToDetector,"Domain=DETECTOR");
    break;
  default:
    {
#ifndef NEWWCS
      AstFrameSet* wcsfs = (AstFrameSet*)astCopy(fits->getAST(system_));

      // set desired skyformat
      if (astIsASkyFrame(astGetFrame(wcsfs, AST__CURRENT)))
	fits->setAstSkyFrame(wcsfs, sky_);

      // add wcs to frameset
      // this will link frame 2 of frameset to frame 3 wcs with unitMap
      // set the current of frameset to last
      astInvert(wcsfs);
      astAddFrame(frameSet,2,astUnitMap(2,""),wcsfs);
      astSetI(frameSet,"current",astGetI(frameSet,"nframe"));
    }
#else
      AstFrameSet* wcs = (AstFrameSet*)astCopy(fits->getAST(system_));

      // add wcs to frameset
      // this will link frameset to wcs with unitMap
      astInvert(wcs);
      astAddFrame(frameSet,2,astUnitMap(2,""),wcs);
      fits->setAstSystem(frameSet,system_);
      fits->setAstSkyFrame(frameSet,sky_);
    }
#endif
  }

  astSet(frameSet,"Title=%s", " ");

  // create astPlot
  float gbox[4];
  double pbox[4];

  switch (type_) {
  case ANALYSIS:
    {
      gbox[0] = pbox[0] = 0;
      gbox[1] = pbox[1] = 0;
      gbox[2] = pbox[2] = pp->options->width-1;
      gbox[3] = pbox[3] = pp->options->height-1;
    }
    break;
  case PUBLICATION:
    {
      Matrix mm = fits->imageToWidget;
      BBox b = pp->imageBBox(pp->context->secMode());

      Vector ll = b.ll   * mm;
      Vector lr = b.lr() * mm;
      Vector ur = b.ur   * mm;
      Vector ul = b.ul() * mm;

      BBox bb(ll,ll);
      bb.bound(lr);
      bb.bound(ur);
      bb.bound(ul);

      gbox[0] = pbox[0] = bb.ll[0];
      gbox[1] = pbox[1] = bb.ll[1];
      gbox[2] = pbox[2] = bb.ur[0];
      gbox[3] = pbox[3] = bb.ur[1];
    }
    break;
  }

  // and now create astGrid
  astGrid2dPtr = this;

  plot = astPlot(frameSet, gbox, pbox, option_);
  astGrid(plot);

  astEnd; // now, clean up memory
  astGrid2dPtr =NULL;
  return 1;
}

int Grid2d::matrixMap(void* fs, Matrix& mx, const char* str)
{
  AstFrameSet* frameSet = (AstFrameSet*)fs;

  double ss[] = {mx.matrix(0,0),mx.matrix(1,0),
		 mx.matrix(0,1),mx.matrix(1,1)};
  double tt[] = {mx.matrix(2,0),mx.matrix(2,1)};

  AstMatrixMap* mm;
  if (!(mm= astMatrixMap(2, 2, 0, ss, "")))
    return 0;

  AstShiftMap* sm;
  if (!(sm = astShiftMap(2, tt, "")))
    return 0;

  AstCmpMap* cmp;
  if (!(cmp = astCmpMap(mm, sm, 1, "")))
    return 0;

  astAddFrame(frameSet, AST__CURRENT, cmp, astFrame(2, str));

  return 1;
}
<commit_msg>new AST support<commit_after>// Copyright (C) 1999-2017
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#include "grid2d.h"
#include "context.h"
#include "framebase.h"
#include "fitsimage.h"

extern "C" {
  #include "ast.h"
}

extern Grid2dBase* astGrid2dPtr;

Grid2d::Grid2d(Widget* p, Coord::CoordSystem sys, Coord::SkyFrame sky,
	       Coord::SkyFormat format, GridType t,
	       const char* o, const char* v)
  : Grid(sys, sky, format, t, v), Grid2dBase(p,o)
{}

Grid2d::~Grid2d()
{}

int Grid2d::doit(RenderMode rm)
{
  FrameBase* pp = (FrameBase*)parent_;

  matrix_ = pp->widgetToCanvas;
  pixmap_ = pp->pixmap;
  gridGC_ = pp->gridGC_;
  renderMode_ = rm;

  Context* context = pp->keyContext;
  FitsImage* fits = context->fits;

  if (!fits)
    return 1;

  //  int width = fits->width();
  //  int height = fits->height();

  astClearStatus; // just to make sure
  astBegin; // start memory management

  AstFrameSet* frameSet = NULL;
  AstPlot* plot = NULL;

  if (!(frameSet = astFrameSet(astFrame(2,"Domain=WIDGET"),""))) {
    astEnd;
    return 0;
  }

  // map from Widget to Image
  matrixMap(frameSet,fits->widgetToImage,"Domain=IMAGE");

  switch (system_) {
  case Coord::IMAGE:
    break;
  case Coord::PHYSICAL:
    matrixMap(frameSet,fits->imageToPhysical,"Domain=PHYSICAL");
    break;
  case Coord::AMPLIFIER:
    matrixMap(frameSet,fits->imageToAmplifier,"Domain=AMPLIFIER");
    break;
  case Coord::DETECTOR:
    matrixMap(frameSet,fits->imageToDetector,"Domain=DETECTOR");
    break;
  default:
    {
      AstFrameSet* wcsfs = (AstFrameSet*)astCopy(fits->getAST(system_));

#ifndef NEWWCS
      // set desired skyformat
      if (astIsASkyFrame(astGetFrame(wcsfs, AST__CURRENT)))
	fits->setAstSkyFrame(wcsfs, sky_);

      // add wcs to frameset
      // this will link frame 2 of frameset to frame 3 wcs with unitMap
      // set the current of frameset to last
      astInvert(wcsfs);
      astAddFrame(frameSet,2,astUnitMap(2,""),wcsfs);
      astSetI(frameSet,"current",astGetI(frameSet,"nframe"));

#else
      // add wcs to frameset
      // this will link frameset to wcs with unitMap
      astInvert(wcsfs);
      astAddFrame(frameSet,2,astUnitMap(2,""),wcsfs);
      fits->setAstSystem(frameSet,system_);
      fits->setAstSkyFrame(frameSet,sky_);
#endif
    }
  }

  astSet(frameSet,"Title=%s", " ");

  // create astPlot
  float gbox[4];
  double pbox[4];

  switch (type_) {
  case ANALYSIS:
    {
      gbox[0] = pbox[0] = 0;
      gbox[1] = pbox[1] = 0;
      gbox[2] = pbox[2] = pp->options->width-1;
      gbox[3] = pbox[3] = pp->options->height-1;
    }
    break;
  case PUBLICATION:
    {
      Matrix mm = fits->imageToWidget;
      BBox b = pp->imageBBox(pp->context->secMode());

      Vector ll = b.ll   * mm;
      Vector lr = b.lr() * mm;
      Vector ur = b.ur   * mm;
      Vector ul = b.ul() * mm;

      BBox bb(ll,ll);
      bb.bound(lr);
      bb.bound(ur);
      bb.bound(ul);

      gbox[0] = pbox[0] = bb.ll[0];
      gbox[1] = pbox[1] = bb.ll[1];
      gbox[2] = pbox[2] = bb.ur[0];
      gbox[3] = pbox[3] = bb.ur[1];
    }
    break;
  }

  // and now create astGrid
  astGrid2dPtr = this;

  plot = astPlot(frameSet, gbox, pbox, option_);
  astGrid(plot);

  astEnd; // now, clean up memory
  astGrid2dPtr =NULL;
  return 1;
}

int Grid2d::matrixMap(void* fs, Matrix& mx, const char* str)
{
  AstFrameSet* frameSet = (AstFrameSet*)fs;

  double ss[] = {mx.matrix(0,0),mx.matrix(1,0),
		 mx.matrix(0,1),mx.matrix(1,1)};
  double tt[] = {mx.matrix(2,0),mx.matrix(2,1)};

  AstMatrixMap* mm;
  if (!(mm= astMatrixMap(2, 2, 0, ss, "")))
    return 0;

  AstShiftMap* sm;
  if (!(sm = astShiftMap(2, tt, "")))
    return 0;

  AstCmpMap* cmp;
  if (!(cmp = astCmpMap(mm, sm, 1, "")))
    return 0;

  astAddFrame(frameSet, AST__CURRENT, cmp, astFrame(2, str));

  return 1;
}
<|endoftext|>


<commit_before>#ifndef DUNE_STUFF_LA_CONTAINER_EIGEN_HH
#define DUNE_STUFF_LA_CONTAINER_EIGEN_HH

#if HAVE_EIGEN

#include <Eigen/Core>
#include <Eigen/SparseCore>

#include <dune/common/bartonnackmanifcheck.hh>

#include "interface.hh"
#include "pattern.hh"

namespace Dune {
namespace Stuff {
namespace LA {
namespace Container {
namespace Eigen {

/**
 *  \todo add base()
 */
template< class Traits >
class Base
{
public:
  typedef typename Traits::derived_type derived_type;
}; // class Base

template< class Traits >
class MatrixBase
  : public Base< Traits >
{
public:
  typedef typename Base< Traits >::derived_type derived_type;
}; // class MatrixBase

template< class Traits >
class VectorBase
  : public Base< Traits >
{
public:
  typedef typename Base< Traits >::derived_type derived_type;
}; // class VectorBase

template< class ElementType >
class RowMajorSparseMatrix;

template< class ElementImp = double >
class RowMajorSparseMatrixTraits
{
public:
  typedef ElementImp ElementType;

  typedef RowMajorSparseMatrix< ElementType > derived_type;

  typedef typename ::Eigen::SparseMatrix< ElementType, ::Eigen::RowMajor > BaseType;

  typedef typename BaseType::Index size_type;
}; // class RowMajorSparseMatrixTraits

template< class ElementImp = double >
class RowMajorSparseMatrix
  : public MatrixInterface< RowMajorSparseMatrixTraits< ElementImp > >
  , virtual public RowMajorSparseMatrixTraits< ElementImp >::BaseType
  , public MatrixBase< RowMajorSparseMatrixTraits< ElementImp > >
{
public:
  typedef RowMajorSparseMatrixTraits< ElementImp > Traits;

  typedef typename Traits::derived_type derived_type;

  typedef typename Traits::BaseType BaseType;

  typedef typename Traits::ElementType ElementType;

  typedef typename Traits::size_type size_type;

  RowMajorSparseMatrix()
    : BaseType()
  {}

  RowMajorSparseMatrix(const BaseType& _other)
    : BaseType(_other.rows(), _other.cols())
  {
    base() = _other;
  }

  RowMajorSparseMatrix(const size_type _rows,
                       const size_type _cols,
                       const Dune::Stuff::LA::Container::Pattern::Default& _pattern)
    : BaseType(_rows, _cols)
  {
    assert(size_type(_pattern.rows()) == _rows && "Given pattern too short!");
    typedef Dune::Stuff::LA::Container::Pattern::Default PatternType;
    typedef PatternType::ColumnsType ColumnsType;
    for (size_type row = 0; row < size_type(_pattern.rows()); ++row) {
      BaseType::startVec(row);
      const ColumnsType& columns = _pattern.columns(row);
      for (typename ColumnsType::const_iterator columnIt = columns.begin(); columnIt != columns.end(); ++columnIt) {
        const size_type column = *columnIt;
        BaseType::insertBackByOuterInner(row, column);
      }
      // create diagonal entry (insertBackByOuterInner() can not handle empty rows)
      if (columns.size() == 0)
        BaseType::insertBackByOuterInner(row, row);
    }
    BaseType::finalize();
    BaseType::makeCompressed();
  } // RowMajorSparseMatrix(...)

  size_type rows() const
  {
    return BaseType::rows();
  }

  size_type cols() const
  {
    return BaseType::cols();
  }

  void add(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::coeffRef(i, j) += val;
  }

  void set(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::coeffRef(i, j) = val;
  }

  const ElementType get(const size_type i, const size_type j) const
  {
    return BaseType::coeff(i, j);
  }

  BaseType& base()
  {
    return *this;
  }

  const BaseType& base() const
  {
    return *this;
  }
}; // class RowMajorSparseMatrix

template< class ElementImp >
class DenseMatrix;

template< class ElementImp = double >
class DenseMatrixTraits
{
public:
  typedef ElementImp ElementType;

  typedef DenseMatrix< ElementType > derived_type;

  typedef typename ::Eigen::Matrix< ElementType, ::Eigen::Dynamic, ::Eigen::Dynamic > BaseType;

  typedef typename BaseType::Index size_type;
}; // class DenseMatrixTraits

template< class ElementImp = double >
class DenseMatrix
  : public MatrixInterface< DenseMatrixTraits< ElementImp > >
  , virtual public DenseMatrixTraits< ElementImp >::BaseType
  , public MatrixBase< DenseMatrixTraits< ElementImp > >
{
public:
  typedef DenseMatrixTraits< ElementImp > Traits;

  typedef typename Traits::derived_type derived_type;

  typedef typename Traits::BaseType BaseType;

  typedef typename Traits::ElementType ElementType;

  typedef typename Traits::size_type size_type;

  DenseMatrix(const size_type _rows, const size_type _cols)
    : BaseType(_rows, _cols)
  {}

  size_type rows() const
  {
    return BaseType::rows();
  }

  size_type cols() const
  {
    return BaseType::cols();
  }

  void add(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::operator()(i, j) += val;
  }

  void set(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::operator()(i, j) = val;
  }

  const ElementType get(const size_type i, const size_type j) const
  {
    return BaseType::operator()(i, j);
  }

  BaseType& base()
  {
    return *this;
  }

  const BaseType& base() const
  {
    return *this;
  }
}; // class DenseMatrix

template< class ElementImp >
class DenseVector;

template< class ElementImp = double >
class DenseVectorTraits
{
public:
  typedef ElementImp ElementType;

  typedef DenseVector< ElementType > derived_type;

  typedef typename ::Eigen::Matrix< ElementType, ::Eigen::Dynamic, 1 > BaseType;

  typedef typename BaseType::Index size_type;
}; // class DenseVectorTraits

template< class ElementImp = double>
class DenseVector
  : public VectorInterface< DenseVectorTraits< ElementImp > >
  , virtual public DenseVectorTraits< ElementImp >::BaseType
  , public VectorBase< DenseVectorTraits< ElementImp > >
{
public:
  typedef DenseVectorTraits< ElementImp > Traits;

  typedef typename Traits::derived_type derived_type;

  typedef typename Traits::BaseType BaseType;

  typedef typename Traits::ElementType ElementType;

  typedef typename Traits::size_type size_type;

  DenseVector(const size_type _size)
    : BaseType(_size)
  {
    BaseType::setZero();
  }

  DenseVector(const BaseType& _other)
    : BaseType(_other.size())
  {
    base() = _other;
  }

  size_type size() const
  {
    return BaseType::size();
  }

  void add(const size_type i, const ElementType& val)
  {
    BaseType::operator()(i) += val;
  }

  void set(const size_type i, const ElementType& val)
  {
    BaseType::operator()(i) = val;
  }

  const ElementType get(const size_type i) const
  {
    return BaseType::operator()(i);
  }

  BaseType& base()
  {
    return *this;
  }

  const BaseType& base() const
  {
    return *this;
  }
}; // class DenseVector

} // namespace Container
} // namespace Eigen
} // namespace LA
} // namespace Stuff
} // namespace Dune

#endif // HAVE_EIGEN

#endif // DUNE_STUFF_LA_CONTAINER_EIGEN_HH
<commit_msg>[la.container.eigen] added default and copy constructor to DenseMatrix<commit_after>#ifndef DUNE_STUFF_LA_CONTAINER_EIGEN_HH
#define DUNE_STUFF_LA_CONTAINER_EIGEN_HH

#if HAVE_EIGEN

#include <Eigen/Core>
#include <Eigen/SparseCore>

#include <dune/common/bartonnackmanifcheck.hh>

#include "interface.hh"
#include "pattern.hh"

namespace Dune {
namespace Stuff {
namespace LA {
namespace Container {
namespace Eigen {

/**
 *  \todo add base()
 */
template< class Traits >
class Base
{
public:
  typedef typename Traits::derived_type derived_type;
}; // class Base

template< class Traits >
class MatrixBase
  : public Base< Traits >
{
public:
  typedef typename Base< Traits >::derived_type derived_type;
}; // class MatrixBase

template< class Traits >
class VectorBase
  : public Base< Traits >
{
public:
  typedef typename Base< Traits >::derived_type derived_type;
}; // class VectorBase

template< class ElementType >
class RowMajorSparseMatrix;

template< class ElementImp = double >
class RowMajorSparseMatrixTraits
{
public:
  typedef ElementImp ElementType;

  typedef RowMajorSparseMatrix< ElementType > derived_type;

  typedef typename ::Eigen::SparseMatrix< ElementType, ::Eigen::RowMajor > BaseType;

  typedef typename BaseType::Index size_type;
}; // class RowMajorSparseMatrixTraits

template< class ElementImp = double >
class RowMajorSparseMatrix
  : public MatrixInterface< RowMajorSparseMatrixTraits< ElementImp > >
  , virtual public RowMajorSparseMatrixTraits< ElementImp >::BaseType
  , public MatrixBase< RowMajorSparseMatrixTraits< ElementImp > >
{
public:
  typedef RowMajorSparseMatrixTraits< ElementImp > Traits;

  typedef typename Traits::derived_type derived_type;

  typedef typename Traits::BaseType BaseType;

  typedef typename Traits::ElementType ElementType;

  typedef typename Traits::size_type size_type;

  RowMajorSparseMatrix()
    : BaseType()
  {}

  RowMajorSparseMatrix(const BaseType& _other)
    : BaseType(_other.rows(), _other.cols())
  {
    base() = _other;
  }

  RowMajorSparseMatrix(const size_type _rows,
                       const size_type _cols,
                       const Dune::Stuff::LA::Container::Pattern::Default& _pattern)
    : BaseType(_rows, _cols)
  {
    assert(size_type(_pattern.rows()) == _rows && "Given pattern too short!");
    typedef Dune::Stuff::LA::Container::Pattern::Default PatternType;
    typedef PatternType::ColumnsType ColumnsType;
    for (size_type row = 0; row < size_type(_pattern.rows()); ++row) {
      BaseType::startVec(row);
      const ColumnsType& columns = _pattern.columns(row);
      for (typename ColumnsType::const_iterator columnIt = columns.begin(); columnIt != columns.end(); ++columnIt) {
        const size_type column = *columnIt;
        BaseType::insertBackByOuterInner(row, column);
      }
      // create diagonal entry (insertBackByOuterInner() can not handle empty rows)
      if (columns.size() == 0)
        BaseType::insertBackByOuterInner(row, row);
    }
    BaseType::finalize();
    BaseType::makeCompressed();
  } // RowMajorSparseMatrix(...)

  size_type rows() const
  {
    return BaseType::rows();
  }

  size_type cols() const
  {
    return BaseType::cols();
  }

  void add(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::coeffRef(i, j) += val;
  }

  void set(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::coeffRef(i, j) = val;
  }

  const ElementType get(const size_type i, const size_type j) const
  {
    return BaseType::coeff(i, j);
  }

  BaseType& base()
  {
    return *this;
  }

  const BaseType& base() const
  {
    return *this;
  }
}; // class RowMajorSparseMatrix

template< class ElementImp >
class DenseMatrix;

template< class ElementImp = double >
class DenseMatrixTraits
{
public:
  typedef ElementImp ElementType;

  typedef DenseMatrix< ElementType > derived_type;

  typedef typename ::Eigen::Matrix< ElementType, ::Eigen::Dynamic, ::Eigen::Dynamic > BaseType;

  typedef typename BaseType::Index size_type;
}; // class DenseMatrixTraits

template< class ElementImp = double >
class DenseMatrix
  : public MatrixInterface< DenseMatrixTraits< ElementImp > >
  , virtual public DenseMatrixTraits< ElementImp >::BaseType
  , public MatrixBase< DenseMatrixTraits< ElementImp > >
{
public:
  typedef DenseMatrixTraits< ElementImp > Traits;

  typedef typename Traits::derived_type derived_type;

  typedef typename Traits::BaseType BaseType;

  typedef typename Traits::ElementType ElementType;

  typedef typename Traits::size_type size_type;

  DenseMatrix()
    : BaseType()
  {}

  DenseMatrix(const size_type _rows, const size_type _cols)
    : BaseType(_rows, _cols)
  {}

  DenseMatrix(const BaseType& _other)
    : BaseType(_other.rows(), _other.cols())
  {
    base() = _other;
  }

  size_type rows() const
  {
    return BaseType::rows();
  }

  size_type cols() const
  {
    return BaseType::cols();
  }

  void add(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::operator()(i, j) += val;
  }

  void set(const size_type i, const size_type j, const ElementType& val)
  {
    BaseType::operator()(i, j) = val;
  }

  const ElementType get(const size_type i, const size_type j) const
  {
    return BaseType::operator()(i, j);
  }

  BaseType& base()
  {
    return *this;
  }

  const BaseType& base() const
  {
    return *this;
  }
}; // class DenseMatrix

template< class ElementImp >
class DenseVector;

template< class ElementImp = double >
class DenseVectorTraits
{
public:
  typedef ElementImp ElementType;

  typedef DenseVector< ElementType > derived_type;

  typedef typename ::Eigen::Matrix< ElementType, ::Eigen::Dynamic, 1 > BaseType;

  typedef typename BaseType::Index size_type;
}; // class DenseVectorTraits

template< class ElementImp = double>
class DenseVector
  : public VectorInterface< DenseVectorTraits< ElementImp > >
  , virtual public DenseVectorTraits< ElementImp >::BaseType
  , public VectorBase< DenseVectorTraits< ElementImp > >
{
public:
  typedef DenseVectorTraits< ElementImp > Traits;

  typedef typename Traits::derived_type derived_type;

  typedef typename Traits::BaseType BaseType;

  typedef typename Traits::ElementType ElementType;

  typedef typename Traits::size_type size_type;

  DenseVector(const size_type _size)
    : BaseType(_size)
  {
    BaseType::setZero();
  }

  DenseVector(const BaseType& _other)
    : BaseType(_other.size())
  {
    base() = _other;
  }

  size_type size() const
  {
    return BaseType::size();
  }

  void add(const size_type i, const ElementType& val)
  {
    BaseType::operator()(i) += val;
  }

  void set(const size_type i, const ElementType& val)
  {
    BaseType::operator()(i) = val;
  }

  const ElementType get(const size_type i) const
  {
    return BaseType::operator()(i);
  }

  BaseType& base()
  {
    return *this;
  }

  const BaseType& base() const
  {
    return *this;
  }
}; // class DenseVector

} // namespace Container
} // namespace Eigen
} // namespace LA
} // namespace Stuff
} // namespace Dune

#endif // HAVE_EIGEN

#endif // DUNE_STUFF_LA_CONTAINER_EIGEN_HH
<|endoftext|>


<commit_before>#include <iostream>
using namespace std;

namespace templet {

	class message;
	class actor;
	typedef void (actor::*event_h)(message&);

	class task_engine { virtual void run()=0; };

	class shm_task_engine : public task_engine { virtual void run() {} };

	class task {
		actor& act;
		shm_task_engine* tsk_eng;
		//event_h ev_h; ?????
	public:
		task(actor&a, task_engine&te/* , event_h e_h*/) :act(a) /*, ev_h(e_h)*/ {
			tsk_eng = dynamic_cast<shm_task_engine*>(&te);
		}
	};

	class engine {
	friend class message;
		message* queue;
	public:
		void dispatch();
	};

	class actor {
	friend class message;
		engine& eng;
	public:
		actor(engine& e): eng(e){}
	};

	class message {
	friend class engine;
		actor* act;
		engine& eng;
		event_h ev_h;
	public:
		message(actor*a, event_h e_h) : act(a), eng(a->eng), ev_h(e_h) {}
		void send() { eng.queue = this; }
	};

	void engine::dispatch() {
		event_h ev_h = queue->ev_h;
		actor*  act = queue->act;
		(act->*ev_h)(*queue);
	}

}

class mytask : public templet::task{
public:
	mytask(templet::actor&a, templet::task_engine&te):templet::task(a,te){}
};

class mymessage : public templet::message {
public:
	mymessage(templet::actor*a, templet::event_h e_h):templet::message(a,e_h){}

};

class myactor: public templet::actor {
public:
	myactor(templet::engine&e,templet::task_engine&te):
		templet::actor(e),
		mes(this, (templet::event_h)(&myactor::mes_h)),
		tsk(*this,te)
	{
	}

	void mes_h(mymessage&) {
		cout << "\nhello\n";
	}

	mymessage mes;
	mytask tsk;
};

int main()
{
	templet::engine eng;
	templet::shm_task_engine tsk_eng;

	myactor act(eng,tsk_eng);
	act.mes.send();
	eng.dispatch();

    return 0;
}<commit_msg>project of resume algorithm added<commit_after>#include <iostream>
using namespace std;

namespace templet {

	class message;
	class actor;
	typedef void (actor::*event_h)(message&);

	class task_engine { virtual void run()=0; };

	class shm_task_engine : public task_engine { virtual void run() {} };

	class task {
		actor& act;
		shm_task_engine* tsk_eng;
		//event_h ev_h; ?????
	public:
		task(actor&a, task_engine&te/* , event_h e_h*/) :act(a) /*, ev_h(e_h)*/ {
			tsk_eng = dynamic_cast<shm_task_engine*>(&te);
		}
	};

	class engine {
	friend class message;
		message* queue;
	public:
		void dispatch();
	};

	/*
		lock_type lock_1, lock_2;

		void on_resume(){

			lock(lock_1);

			put_local_messages_to_queue();

try_to_be_the_master:
			if(try_lock(lock_2)){

				unlock(lock_1);

				while(message_in_queue())process_message();

				unlock(lock_2);
			}
			else{
				unlock(lock_1);
				return;
			}

			lock(lock_1);

			if(!message_in_queue()){
				unlock(lock_1);
				return;
			}
			else goto try_to_be_the_master;
		}
	*/

	class actor {
	friend class message;
		engine& eng;
	public:
		actor(engine& e): eng(e){}
	};

	class message {
	friend class engine;
		actor* act;
		engine& eng;
		event_h ev_h;
	public:
		message(actor*a, event_h e_h) : act(a), eng(a->eng), ev_h(e_h) {}
		void send() { eng.queue = this; }
	};

	void engine::dispatch() {
		event_h ev_h = queue->ev_h;
		actor*  act = queue->act;
		(act->*ev_h)(*queue);
	}

}

class mytask : public templet::task{
public:
	mytask(templet::actor&a, templet::task_engine&te):templet::task(a,te){}
};

class mymessage : public templet::message {
public:
	mymessage(templet::actor*a, templet::event_h e_h):templet::message(a,e_h){}

};

class myactor: public templet::actor {
public:
	myactor(templet::engine&e,templet::task_engine&te):
		templet::actor(e),
		mes(this, (templet::event_h)(&myactor::mes_h)),
		tsk(*this,te)
	{
	}

	void mes_h(mymessage&) {
		cout << "\nhello\n";
	}

	mymessage mes;
	mytask tsk;
};

int main()
{
	templet::engine eng;
	templet::shm_task_engine tsk_eng;

	myactor act(eng,tsk_eng);
	act.mes.send();
	eng.dispatch();

    return 0;
}<|endoftext|>


<commit_before>#include <vector>
#include <queue>
#include "circuit.h"
using namespace std;

// initalize base circuit into exhaustive list
queue<Circuit> ex_list;
vector<bool> init = {0, 0, 0};
Circuit base(init, 0);

int y=0;
int level = 1;
int not_counter = 3;

int check_output(Circuit x, vector<bool> sum, vector<bool> c_out) {
  // assuming that sum and c_out are the same length
  int size = sum.size();

  for (int i = 0; i < size; ++i) {
    if (x.evaluateInputSet(sum)[i] == true &&
        x.evaluateInputSet(c_out)[i] == true)
      ;
    // if doesn't equal desired output
    else
      return 0;
  }

  // if it equals desired output
  return 1;
}

void add_not(int counter) {
  for (int i = 0; i < counter; ++i) {
    Circuit next = ex_list.front();
    next.addGate(NOT, i);
    ex_list.push(next);
  }
}

void add_and(int counter) {
  for (int i = 0; i < counter; ++i) {
    Circuit next = ex_list.front();
    next.addGate(AND, i);
    ex_list.push(next);
  }
}

void add_or(int counter) {
  for (int i = 0; i < counter; ++i) {
    Circuit next = ex_list.front();
    next.addGate(OR, i);
    ex_list.push(next);
  }
}

Circuit search(vector<bool> sum, vector<bool> c_out) {

  if (y==0){
	ex_list.push(base);
	++y;
  }
  // keeps track of # of combinations
  ++level;
  int combo_counter;
  for (int i = 1; i <= level; ++i) {
    combo_counter += i;
  }

  // compares circuits wires to desired outputs
  if (check_output(ex_list.front(), sum, c_out) == 0) {
    // adds NOT gate
    add_not(not_counter);
    ++not_counter;

    // adds AND/OR gate
    add_and(combo_counter);
    add_or(combo_counter);

    // remove "first" element
    ex_list.pop();

    search(sum, c_out);
  } else
    return ex_list.front();
}<commit_msg>The .cc file for the class algorithm. forgot to add before committing and pushing before.<commit_after>#include <vector>
#include <queue>
#include "algorithm.h"
using namespace std;

Algo::Algo() {
  // initalize base circuit into exhaustive list
  vector<bool> init = {0, 0, 0};
  Circuit base(init, 0);
  ex_list.push(base);
}

int Algo::check_output(Circuit x, vector<bool> sum, vector<bool> c_out) {
  // assuming that sum and c_out are the same length
  int size = sum.size();

  for (int i = 0; i < size; ++i) {
    if (x.evaluateInputSet(sum)[i] == true &&
        x.evaluateInputSet(c_out)[i] == true)
      ;
    // if doesn't equal desired output
    else
      return 0;
  }

  // if it equals desired output
  return 1;
}

void Algo::add_not(int counter) {
  for (int i = 0; i < counter; ++i) {
    Circuit next = ex_list.front();
    next.addGate(NOT, i);
    ex_list.push(next);
  }
}

void Algo::add_and(int counter) {
  for (int i = 0; i < counter; ++i) {
    Circuit next = ex_list.front();
    next.addGate(AND, i);
    ex_list.push(next);
  }
}

void Algo::add_or(int counter) {
  for (int i = 0; i < counter; ++i) {
    Circuit next = ex_list.front();
    next.addGate(OR, i);
    ex_list.push(next);
  }
}

Circuit Algo::search(vector<bool> sum, vector<bool> c_out) {

  // keeps track of # of combinations
  ++level;
  int combo_counter;
  for (int i = 1; i <= level; ++i) {
    combo_counter += i;
  }

  // compares circuits wires to desired outputs
  if (check_output(ex_list.front(), sum, c_out) == 0) {
    // adds NOT gate
    add_not(not_counter);
    ++not_counter;

    // adds AND/OR gate
    add_and(combo_counter);
    add_or(combo_counter);

    // remove "first" element
    ex_list.pop();

    search(sum, c_out);
  } else
    return ex_list.front();
}
<|endoftext|>


<commit_before>/* COPYRIGHT (c) 2014 Umut Acar, Arthur Chargueraud, and Michael
 * Rainey
 * All rights reserved.
 *
 * \file sort.hpp
 * \brief Sorting algorithms
 *
 */

#include "array.hpp"

#ifndef _MINICOURSE_SORT_H_
#define _MINICOURSE_SORT_H_

/***********************************************************************/

long nlogn(long n) {
  return pasl::data::estimator::annotation::nlgn(n);
}

/*---------------------------------------------------------------------*/
/* Sequential sort */

void in_place_sort(array_ref xs, long lo, long hi) {
  if (hi-lo > 0)
    std::sort(&xs[lo], &xs[hi-1]+1);
}

void in_place_sort(array_ref xs) {
  in_place_sort(xs, 0l, xs.size());
}

array seqsort(const_array_ref xs) {
  array tmp = copy(xs);
  in_place_sort(tmp);
  return tmp;
}

array seqsort(const_array_ref xs, long lo, long hi) {
  array tmp = slice(xs, lo, hi);
  in_place_sort(tmp);
  return tmp;
}

/*---------------------------------------------------------------------*/
/* Parallel quicksort */

controller_type quicksort_contr("quicksort");

array quicksort(const_array_ref xs) {
  long n = xs.size();
  array result = { };
  auto seq = [&] {
    result = seqsort(xs);
  };
  par::cstmt(quicksort_contr, [&] { return nlogn(n); }, [&] {
    if (n < 2) {
      seq();
    } else {
      long m = n/2;
      value_type p = xs[m];
      array less = filter([&] (value_type x) { return x < p; }, xs);
      array equal = filter([&] (value_type x) { return x == p; }, xs);
      array greater = filter([&] (value_type x) { return x > p; }, xs);
      array left = { };
      array right = { };
      par::fork2([&] {
        left = quicksort(less);
      }, [&] {
        right = quicksort(greater);
      });
      result = concat(left, equal, right);
    }
  }, seq);
  return result;
}

/*---------------------------------------------------------------------*/
/* Parallel mergesort */

void merge_seq(const_array_ref xs, const_array_ref ys, array_ref tmp,
               long lo_xs, long hi_xs,
               long lo_ys, long hi_ys,
               long lo_tmp) {
  long i = lo_xs;
  long j = lo_ys;
  long z = lo_tmp;

  // merge two halves until one is empty
  while (i < hi_xs and j < hi_ys)
    tmp[z++] = (xs[i] < ys[j]) ? xs[i++] : ys[j++];

  // copy remaining items
  prim::copy(&xs[0], &tmp[0], i, hi_xs, z);
  prim::copy(&ys[0], &tmp[0], j, hi_ys, z);
}

void merge_seq(array_ref xs, array_ref tmp,
               long lo, long mid, long hi) {
  merge_seq(xs, xs, tmp, lo, mid, mid, hi, lo);
  // copy back to source array
  prim::copy(&tmp[0], &xs[0], lo, hi, lo);
}

long lower_bound(const_array_ref xs, long lo, long hi, value_type val) {
  const value_type* first_xs = &xs[0];
  return std::lower_bound(first_xs+lo, first_xs+hi, val)-first_xs;
}

controller_type merge_contr("merge");

void merge_par(const_array_ref xs, const_array_ref ys, array_ref tmp,
               long lo_xs, long hi_xs,
               long lo_ys, long hi_ys,
               long lo_tmp) {
  long n1 = hi_xs-lo_xs;
  long n2 = hi_ys-lo_ys;
  auto seq = [&] {
    merge_seq(xs, ys, tmp, lo_xs, hi_xs, lo_ys, hi_ys, lo_tmp);
  };
  par::cstmt(merge_contr, [&] { return n1+n2; }, [&] {
    if (n1 < n2) {
      // to ensure that the first subarray being sorted is the larger or the two
      merge_par(ys, xs, tmp, lo_ys, hi_ys, lo_xs, hi_xs, lo_tmp);
    } else if (n1 == 1) {
      if (n2 == 0) {
        // xs singleton; ys empty
        tmp[lo_tmp] = xs[lo_xs];
      } else {
        // both singletons
        tmp[lo_tmp+0] = std::min(xs[lo_xs], ys[lo_ys]);
        tmp[lo_tmp+1] = std::max(xs[lo_xs], ys[lo_ys]);
      }
    } else {
      // select pivot positions
      long mid_xs = (lo_xs+hi_xs)/2;
      long mid_ys = lower_bound(ys, lo_ys, hi_ys, xs[mid_xs]);
      // number of items to be treated by the first parallel call
      long k = (mid_xs-lo_xs) + (mid_ys-lo_ys);
      par::fork2([&] {
        merge_par(xs, ys, tmp, lo_xs, mid_xs, lo_ys, mid_ys, lo_tmp);
      }, [&] {
        merge_par(xs, ys, tmp, mid_xs, hi_xs, mid_ys, hi_ys, lo_tmp+k);
      });
    }
  }, seq);
}

array merge(const_array_ref xs, const_array_ref ys) {
  long n = xs.size();
  long m = ys.size();
  array tmp = array(n + m);
  merge_par(xs, ys, tmp, 0l, n, 0l, m, 0l);
  return tmp;
}

controller_type mergesort_contr("mergesort");

array mergesort_rec(const_array_ref xs, long lo, long hi) {
  long n = hi-lo;
  array result;
  auto seq = [&] {
    result = seqsort(xs, lo, hi);
  };
  par::cstmt(mergesort_contr, [n] { return nlogn(n); }, [&] {
    if (n < 2) {
      seq();
    } else {
      long mid = (lo+hi)/2;
      array a,b;
      par::fork2([&] {
        a = mergesort_rec(xs, lo, mid);
      }, [&] {
        b = mergesort_rec(xs, mid, hi);
      });
      result = merge(a, b);
    }
  }, seq);
  return result;
}

array mergesort(const_array_ref xs) {
  return mergesort_rec(xs, 0l, xs.size());
}

/***********************************************************************/

#endif /*! _MINICOURSE_SORT_H_ */<commit_msg>Using faster in-place mergesort<commit_after>/* COPYRIGHT (c) 2014 Umut Acar, Arthur Chargueraud, and Michael
 * Rainey
 * All rights reserved.
 *
 * \file sort.hpp
 * \brief Sorting algorithms
 *
 */

#include "array.hpp"

#ifndef _MINICOURSE_SORT_H_
#define _MINICOURSE_SORT_H_

/***********************************************************************/

long nlogn(long n) {
  return pasl::data::estimator::annotation::nlgn(n);
}

/*---------------------------------------------------------------------*/
/* Sequential sort */

void in_place_sort(array_ref xs, long lo, long hi) {
  if (hi-lo > 0)
    std::sort(&xs[lo], &xs[hi-1]+1);
}

void in_place_sort(array_ref xs) {
  in_place_sort(xs, 0l, xs.size());
}

array seqsort(const_array_ref xs) {
  array tmp = copy(xs);
  in_place_sort(tmp);
  return tmp;
}

array seqsort(const_array_ref xs, long lo, long hi) {
  array tmp = slice(xs, lo, hi);
  in_place_sort(tmp);
  return tmp;
}

/*---------------------------------------------------------------------*/
/* Parallel quicksort */

controller_type quicksort_contr("quicksort");

array quicksort(const_array_ref xs) {
  long n = xs.size();
  array result = { };
  auto seq = [&] {
    result = seqsort(xs);
  };
  par::cstmt(quicksort_contr, [&] { return nlogn(n); }, [&] {
    if (n < 2) {
      seq();
    } else {
      long m = n/2;
      value_type p = xs[m];
      array less = filter([&] (value_type x) { return x < p; }, xs);
      array equal = filter([&] (value_type x) { return x == p; }, xs);
      array greater = filter([&] (value_type x) { return x > p; }, xs);
      array left = { };
      array right = { };
      par::fork2([&] {
        left = quicksort(less);
      }, [&] {
        right = quicksort(greater);
      });
      result = concat(left, equal, right);
    }
  }, seq);
  return result;
}

/*---------------------------------------------------------------------*/
/* Parallel mergesort */

void merge_seq(const_array_ref xs, const_array_ref ys, array_ref tmp,
               long lo_xs, long hi_xs,
               long lo_ys, long hi_ys,
               long lo_tmp) {
  long i = lo_xs;
  long j = lo_ys;
  long z = lo_tmp;

  // merge two halves until one is empty
  while (i < hi_xs and j < hi_ys)
    tmp[z++] = (xs[i] < ys[j]) ? xs[i++] : ys[j++];

  // copy remaining items
  prim::copy(&xs[0], &tmp[0], i, hi_xs, z);
  prim::copy(&ys[0], &tmp[0], j, hi_ys, z);
}

void merge_seq(array_ref xs, array_ref tmp,
               long lo, long mid, long hi) {
  merge_seq(xs, xs, tmp, lo, mid, mid, hi, lo);

  // copy back to source array
  prim::copy(&tmp[0], &xs[0], lo, hi, lo);
}

long lower_bound(const_array_ref xs, long lo, long hi, value_type val) {
  const value_type* first_xs = &xs[0];
  return std::lower_bound(first_xs+lo, first_xs+hi, val)-first_xs;
}

controller_type merge_contr("merge");

void merge_par(const_array_ref xs, const_array_ref ys, array_ref tmp,
               long lo_xs, long hi_xs,
               long lo_ys, long hi_ys,
               long lo_tmp) {
  long n1 = hi_xs-lo_xs;
  long n2 = hi_ys-lo_ys;
  auto seq = [&] {
    merge_seq(xs, ys, tmp, lo_xs, hi_xs, lo_ys, hi_ys, lo_tmp);
  };
  par::cstmt(merge_contr, [&] { return n1+n2; }, [&] {
    if (n1 < n2) {
      // to ensure that the first subarray being sorted is the larger or the two
      merge_par(ys, xs, tmp, lo_ys, hi_ys, lo_xs, hi_xs, lo_tmp);
    } else if (n1 == 1) {
      if (n2 == 0) {
        // xs singleton; ys empty
        tmp[lo_tmp] = xs[lo_xs];
      } else {
        // both singletons
        tmp[lo_tmp+0] = std::min(xs[lo_xs], ys[lo_ys]);
        tmp[lo_tmp+1] = std::max(xs[lo_xs], ys[lo_ys]);
      }
    } else {
      // select pivot positions
      long mid_xs = (lo_xs+hi_xs)/2;
      long mid_ys = lower_bound(ys, lo_ys, hi_ys, xs[mid_xs]);
      // number of items to be treated by the first parallel call
      long k = (mid_xs-lo_xs) + (mid_ys-lo_ys);
      par::fork2([&] {
        merge_par(xs, ys, tmp, lo_xs, mid_xs, lo_ys, mid_ys, lo_tmp);
      }, [&] {
        merge_par(xs, ys, tmp, mid_xs, hi_xs, mid_ys, hi_ys, lo_tmp+k);
      });
    }
  }, seq);
}

void merge_par(array_ref xs, array_ref tmp,
               long lo, long mid, long hi) {
  merge_par(xs, xs, tmp, lo, mid, mid, hi, lo);

  // copy back to source array
  prim::pcopy(&tmp[0], &xs[0], lo, hi, lo);
}

array merge(const_array_ref xs, const_array_ref ys) {
  long n = xs.size();
  long m = ys.size();
  array tmp = array(n + m);
  merge_par(xs, ys, tmp, 0l, n, 0l, m, 0l);
  return tmp;
}

controller_type mergesort_contr("mergesort");

void mergesort_rec(array_ref xs, array_ref tmp, long lo, long hi) {
  long n = hi - lo;
  auto seq = [&] {
    in_place_sort(xs, lo, hi);
  };
  par::cstmt(mergesort_contr, [&] { return nlogn(n); }, [&] {
    if (n <= 2) {
      seq();
      return;
    }

    long mid = (lo + hi) / 2;
    par::fork2([&] {
      mergesort_rec(xs, tmp, lo, mid);
    }, [&] {
      mergesort_rec(xs, tmp, mid, hi);
    });

    merge_par(xs, tmp, lo, mid, hi);
  }, seq);
}

array mergesort(const_array_ref xs) {
  long n = xs.size();
  array result = copy(xs);
  array tmp = array(n);
  mergesort_rec(result, tmp, 0l, n);
  return result;
}

/***********************************************************************/

#endif /*! _MINICOURSE_SORT_H_ */
<|endoftext|>


<commit_before>/* BEGIN_COMMON_COPYRIGHT_HEADER
 * (c)LGPL2+
 *
 * LXDE-Qt - a lightweight, Qt based, desktop toolset
 * http://razor-qt.org
 *
 * Copyright: 2010-2011 Razor team
 * Authors:
 *   Alexander Sokoloff <sokoloff.a@gmail.com>
 *
 * This program or 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
 *
 * END_COMMON_COPYRIGHT_HEADER */

#include "lxqtmainmenu.h"
#include "lxqtmainmenuconfiguration.h"
#include <QDebug>
#include <qtxdg/xdgdesktopfile.h>
#include <qtxdg/xmlhelper.h>
#include <QSettings>
#include <QFileInfo>
#include <QAction>
#include <QtCore/QTimer>
#include <QtGui/QMessageBox>
#include <lxqt/lxqtpowermanager.h>
#include <lxqt/lxqtscreensaver.h>
#include <lxqt-globalkeys.h>
#include <lxqt/lxqtxfitman.h>

#include <qtxdg/xdgicon.h>
#include <qtxdg/xdgdesktopfile.h>
#include <qtxdg/xdgmenuwidget.h>

#ifdef HAVE_MENU_CACHE
#include "xdgcachedmenu.h"
#endif

#include <QPixmap>
#include <QStack>

#include <QCursor>

Q_EXPORT_PLUGIN2(mainmenu, LxQtMainMenuPluginLibrary)

#define DEFAULT_SHORTCUT "Alt+F1"

/************************************************

 ************************************************/
LxQtMainMenu::LxQtMainMenu(const ILxQtPanelPluginStartupInfo &startupInfo):
    QObject(),
    ILxQtPanelPlugin(startupInfo),
    mMenu(0),
    mShortcut(0),
    mLockCascadeChanges(false)
{
#ifdef HAVE_MENU_CACHE
    mMenuCache = NULL;
    mMenuCacheNotify = 0;
#endif

    mButton.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

    connect(&mButton, SIGNAL(clicked()), this, SLOT(showMenu()));

    mPowerManager = new LxQt::PowerManager(this);
    mScreenSaver = new LxQt::ScreenSaver(this);

    settingsChanged();

    connect(mShortcut, SIGNAL(activated()), this, SLOT(showHideMenu()));
    connect(mShortcut, SIGNAL(shortcutChanged(QString,QString)), this, SLOT(shortcutChanged(QString,QString)));
}

/************************************************

 ************************************************/
LxQtMainMenu::~LxQtMainMenu()
{
#ifdef HAVE_MENU_CACHE
    if(mMenuCache)
    {
        menu_cache_remove_reload_notify(mMenuCache, mMenuCacheNotify);
        menu_cache_unref(mMenuCache);
    }
#endif
}

/************************************************

 ************************************************/
void LxQtMainMenu::showHideMenu()
{
    if (mMenu && mMenu->isVisible())
        mMenu->hide();
    else
        showMenu();
}

/************************************************

 ************************************************/
void LxQtMainMenu::shortcutChanged(const QString &/*oldShortcut*/, const QString &newShortcut)
{
    if (!newShortcut.isEmpty())
    {
        mLockCascadeChanges = true;

        settings()->setValue("dialog/shortcut", newShortcut);
        settings()->sync();

        mLockCascadeChanges = false;
    }
}

/************************************************

 ************************************************/
void LxQtMainMenu::showMenu()
{
    if (!mMenu)
        return;

    int x=0, y=0;

    switch (panel()->position())
    {
        case ILxQtPanel::PositionTop:
            x = mButton.mapToGlobal(QPoint(0, 0)).x();
            y = panel()->globalGometry().bottom();
            break;

        case ILxQtPanel::PositionBottom:
            x = mButton.mapToGlobal(QPoint(0, 0)).x();
            y = panel()->globalGometry().top() - mMenu->sizeHint().height();
            break;

        case ILxQtPanel::PositionLeft:
            x = panel()->globalGometry().right();
            y = mButton.mapToGlobal(QPoint(0, 0)).y();
            break;

        case ILxQtPanel::PositionRight:
            x = panel()->globalGometry().left() - mMenu->sizeHint().width();
            y = mButton.mapToGlobal(QPoint(0, 0)).y();
            break;
    }

    // Just using Qt`s activateWindow() won't work on some WMs like Kwin.
    // There are two solutions:
    //  activate window with Qt call and then execute menu 1ms later using timer,
    //  or use native X11 API calls:
    //xfitMan().raiseWindow(mButton.effectiveWinId());
    mButton.activateWindow();
    mMenu->exec(QPoint(x, y));
}

// static
void LxQtMainMenu::menuCacheReloadNotify(MenuCache* cache, gpointer user_data)
{
    reinterpret_cast<LxQtMainMenu*>(user_data)->buildMenu();
}

/************************************************

 ************************************************/
void LxQtMainMenu::settingsChanged()
{
    if (mLockCascadeChanges)
        return;

    if (settings()->value("showText", false).toBool())
    {
        mButton.setText(settings()->value("text", "Start").toString());
        mButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    }
    else
    {
        mButton.setText("");
        mButton.setToolButtonStyle(Qt::ToolButtonIconOnly);
    }

    mLogDir = settings()->value("log_dir", "").toString();

    QString mMenuFile = settings()->value("menu_file", "").toString();
    if (mMenuFile.isEmpty())
        mMenuFile = XdgMenu::getMenuFileName();

#ifdef HAVE_MENU_CACHE
    menu_cache_init(0);
    if(mMenuCache)
    {
        menu_cache_remove_reload_notify(mMenuCache, mMenuCacheNotify);
        menu_cache_unref(mMenuCache);
    }
    mMenuCache = menu_cache_lookup(mMenuFile.toLocal8Bit());
    mMenuCacheNotify = menu_cache_add_reload_notify(mMenuCache, (MenuCacheReloadNotify)menuCacheReloadNotify, this);
#else
    mXdgMenu.setEnvironments(QStringList() << "X-LXQT" << "LxQt");
    mXdgMenu.setLogDir(mLogDir);

    bool res = mXdgMenu.read(mMenuFile);
    connect(&mXdgMenu, SIGNAL(changed()), this, SLOT(buildMenu()));
    if (res)
    {
        QTimer::singleShot(1000, this, SLOT(buildMenu()));
    }
    else
    {
        QMessageBox::warning(0, "Parse error", mXdgMenu.errorString());
        return;
    }
#endif

    QString shortcut = settings()->value("shortcut", DEFAULT_SHORTCUT).toString();
    if (shortcut.isEmpty())
        shortcut = DEFAULT_SHORTCUT;

    if (!mShortcut)
        mShortcut = GlobalKeyShortcut::Client::instance()->addAction(shortcut, QString("/panel/%1/show_hide").arg(settings()->group()), tr("Show/hide main menu"), this);
    else if (mShortcut->shortcut() != shortcut)
    {
        mShortcut->changeShortcut(shortcut);
    }

    realign();
}

/************************************************

 ************************************************/
void LxQtMainMenu::buildMenu()
{
  qDebug() << "BUILD_MENU";
#ifdef HAVE_MENU_CACHE
    XdgCachedMenu* menu = new XdgCachedMenu(mMenuCache, &mButton);
#else
    XdgMenuWidget *menu = new XdgMenuWidget(mXdgMenu, "", &mButton);
#endif
    menu->setObjectName("TopLevelMainMenu");
    menu->setStyle(&mTopMenuStyle);

    menu->addSeparator();

    QMenu* leaveMenu = menu->addMenu(XdgIcon::fromTheme("system-shutdown"), tr("Leave"));
    leaveMenu->addActions(mPowerManager->availableActions());
    menu->addActions(mScreenSaver->availableActions());

    QMenu *oldMenu = mMenu;
    mMenu = menu;
    delete oldMenu;
}

/************************************************

 ************************************************/
QDialog *LxQtMainMenu::configureDialog()
{
    return new LxQtMainMenuConfiguration(*settings(), DEFAULT_SHORTCUT);
}

#undef DEFAULT_SHORTCUT
<commit_msg>Fix bug #11 - moc generation error<commit_after>/* BEGIN_COMMON_COPYRIGHT_HEADER
 * (c)LGPL2+
 *
 * LXDE-Qt - a lightweight, Qt based, desktop toolset
 * http://razor-qt.org
 *
 * Copyright: 2010-2011 Razor team
 * Authors:
 *   Alexander Sokoloff <sokoloff.a@gmail.com>
 *
 * This program or 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
 *
 * END_COMMON_COPYRIGHT_HEADER */

#include "lxqtmainmenu.h"
#include "lxqtmainmenuconfiguration.h"
#include <QDebug>
#include <qtxdg/xdgdesktopfile.h>
#include <qtxdg/xmlhelper.h>
#include <QSettings>
#include <QFileInfo>
#include <QAction>
#include <QtCore/QTimer>
#include <QtGui/QMessageBox>
#include <lxqt/lxqtpowermanager.h>
#include <lxqt/lxqtscreensaver.h>
#include <lxqt-globalkeys.h>
#include <lxqt/lxqtxfitman.h>

#include <qtxdg/xdgicon.h>
#include <qtxdg/xdgdesktopfile.h>
#include <qtxdg/xdgmenuwidget.h>

#ifdef HAVE_MENU_CACHE
#include "xdgcachedmenu.h"
#endif

#include <QPixmap>
#include <QStack>

#include <QCursor>

Q_EXPORT_PLUGIN2(mainmenu, LxQtMainMenuPluginLibrary)

#define DEFAULT_SHORTCUT "Alt+F1"

/************************************************

 ************************************************/
LxQtMainMenu::LxQtMainMenu(const ILxQtPanelPluginStartupInfo &startupInfo):
    QObject(),
    ILxQtPanelPlugin(startupInfo),
    mMenu(0),
    mShortcut(0),
    mLockCascadeChanges(false)
{
#ifdef HAVE_MENU_CACHE
    mMenuCache = NULL;
    mMenuCacheNotify = 0;
#endif

    mButton.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

    connect(&mButton, SIGNAL(clicked()), this, SLOT(showMenu()));

    mPowerManager = new LxQt::PowerManager(this);
    mScreenSaver = new LxQt::ScreenSaver(this);

    settingsChanged();

    connect(mShortcut, SIGNAL(activated()), this, SLOT(showHideMenu()));
    connect(mShortcut, SIGNAL(shortcutChanged(QString,QString)), this, SLOT(shortcutChanged(QString,QString)));
}

/************************************************

 ************************************************/
LxQtMainMenu::~LxQtMainMenu()
{
#ifdef HAVE_MENU_CACHE
    if(mMenuCache)
    {
        menu_cache_remove_reload_notify(mMenuCache, mMenuCacheNotify);
        menu_cache_unref(mMenuCache);
    }
#endif
}

/************************************************

 ************************************************/
void LxQtMainMenu::showHideMenu()
{
    if (mMenu && mMenu->isVisible())
        mMenu->hide();
    else
        showMenu();
}

/************************************************

 ************************************************/
void LxQtMainMenu::shortcutChanged(const QString &/*oldShortcut*/, const QString &newShortcut)
{
    if (!newShortcut.isEmpty())
    {
        mLockCascadeChanges = true;

        settings()->setValue("dialog/shortcut", newShortcut);
        settings()->sync();

        mLockCascadeChanges = false;
    }
}

/************************************************

 ************************************************/
void LxQtMainMenu::showMenu()
{
    if (!mMenu)
        return;

    int x=0, y=0;

    switch (panel()->position())
    {
        case ILxQtPanel::PositionTop:
            x = mButton.mapToGlobal(QPoint(0, 0)).x();
            y = panel()->globalGometry().bottom();
            break;

        case ILxQtPanel::PositionBottom:
            x = mButton.mapToGlobal(QPoint(0, 0)).x();
            y = panel()->globalGometry().top() - mMenu->sizeHint().height();
            break;

        case ILxQtPanel::PositionLeft:
            x = panel()->globalGometry().right();
            y = mButton.mapToGlobal(QPoint(0, 0)).y();
            break;

        case ILxQtPanel::PositionRight:
            x = panel()->globalGometry().left() - mMenu->sizeHint().width();
            y = mButton.mapToGlobal(QPoint(0, 0)).y();
            break;
    }

    // Just using Qt`s activateWindow() won't work on some WMs like Kwin.
    // There are two solutions:
    //  activate window with Qt call and then execute menu 1ms later using timer,
    //  or use native X11 API calls:
    //xfitMan().raiseWindow(mButton.effectiveWinId());
    mButton.activateWindow();
    mMenu->exec(QPoint(x, y));
}

#ifdef HAVE_MENU_CACHE
// static
void LxQtMainMenu::menuCacheReloadNotify(MenuCache* cache, gpointer user_data)
{
    reinterpret_cast<LxQtMainMenu*>(user_data)->buildMenu();
}
#endif

/************************************************

 ************************************************/
void LxQtMainMenu::settingsChanged()
{
    if (mLockCascadeChanges)
        return;

    if (settings()->value("showText", false).toBool())
    {
        mButton.setText(settings()->value("text", "Start").toString());
        mButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    }
    else
    {
        mButton.setText("");
        mButton.setToolButtonStyle(Qt::ToolButtonIconOnly);
    }

    mLogDir = settings()->value("log_dir", "").toString();

    QString mMenuFile = settings()->value("menu_file", "").toString();
    if (mMenuFile.isEmpty())
        mMenuFile = XdgMenu::getMenuFileName();

#ifdef HAVE_MENU_CACHE
    menu_cache_init(0);
    if(mMenuCache)
    {
        menu_cache_remove_reload_notify(mMenuCache, mMenuCacheNotify);
        menu_cache_unref(mMenuCache);
    }
    mMenuCache = menu_cache_lookup(mMenuFile.toLocal8Bit());
    mMenuCacheNotify = menu_cache_add_reload_notify(mMenuCache, (MenuCacheReloadNotify)menuCacheReloadNotify, this);
#else
    mXdgMenu.setEnvironments(QStringList() << "X-LXQT" << "LxQt");
    mXdgMenu.setLogDir(mLogDir);

    bool res = mXdgMenu.read(mMenuFile);
    connect(&mXdgMenu, SIGNAL(changed()), this, SLOT(buildMenu()));
    if (res)
    {
        QTimer::singleShot(1000, this, SLOT(buildMenu()));
    }
    else
    {
        QMessageBox::warning(0, "Parse error", mXdgMenu.errorString());
        return;
    }
#endif

    QString shortcut = settings()->value("shortcut", DEFAULT_SHORTCUT).toString();
    if (shortcut.isEmpty())
        shortcut = DEFAULT_SHORTCUT;

    if (!mShortcut)
        mShortcut = GlobalKeyShortcut::Client::instance()->addAction(shortcut, QString("/panel/%1/show_hide").arg(settings()->group()), tr("Show/hide main menu"), this);
    else if (mShortcut->shortcut() != shortcut)
    {
        mShortcut->changeShortcut(shortcut);
    }

    realign();
}

/************************************************

 ************************************************/
void LxQtMainMenu::buildMenu()
{
  qDebug() << "BUILD_MENU";
#ifdef HAVE_MENU_CACHE
    XdgCachedMenu* menu = new XdgCachedMenu(mMenuCache, &mButton);
#else
    XdgMenuWidget *menu = new XdgMenuWidget(mXdgMenu, "", &mButton);
#endif
    menu->setObjectName("TopLevelMainMenu");
    menu->setStyle(&mTopMenuStyle);

    menu->addSeparator();

    QMenu* leaveMenu = menu->addMenu(XdgIcon::fromTheme("system-shutdown"), tr("Leave"));
    leaveMenu->addActions(mPowerManager->availableActions());
    menu->addActions(mScreenSaver->availableActions());

    QMenu *oldMenu = mMenu;
    mMenu = menu;
    delete oldMenu;
}

/************************************************

 ************************************************/
QDialog *LxQtMainMenu::configureDialog()
{
    return new LxQtMainMenuConfiguration(*settings(), DEFAULT_SHORTCUT);
}

#undef DEFAULT_SHORTCUT
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: charatr.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: os $ $Date: 2002-06-11 08:36:54 $
 *
 *  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 _CHARATR_HXX
#define _CHARATR_HXX

#ifndef _FORMAT_HXX
#include <format.hxx>
#endif
#ifndef _HINTIDS_HXX
#include <hintids.hxx>      // fuer die WhichIds
#endif

/******************************************************************************
 *  Implementierung der Charakter-Attribut Methoden vom SwAttrSet
 *  AMA 12.10.94: Umstellung auf SvxItems.
 ******************************************************************************/

inline const SvxPostureItem      &SwAttrSet::GetPosture(BOOL bInP) const
    {   return (const SvxPostureItem&)Get( RES_CHRATR_POSTURE,bInP); }
inline const SvxPostureItem      &SwAttrSet::GetCJKPosture(BOOL bInP) const
    {   return (const SvxPostureItem&)Get( RES_CHRATR_CJK_POSTURE,bInP); }
inline const SvxPostureItem      &SwAttrSet::GetCTLPosture(BOOL bInP) const
    {   return (const SvxPostureItem&)Get( RES_CHRATR_CTL_POSTURE,bInP); }
inline const SvxWeightItem       &SwAttrSet::GetWeight(BOOL bInP) const
    {   return (const SvxWeightItem&)Get( RES_CHRATR_WEIGHT,bInP); }
inline const SvxWeightItem       &SwAttrSet::GetCJKWeight(BOOL bInP) const
    {   return (const SvxWeightItem&)Get( RES_CHRATR_CJK_WEIGHT,bInP); }
inline const SvxWeightItem       &SwAttrSet::GetCTLWeight(BOOL bInP) const
    {   return (const SvxWeightItem&)Get( RES_CHRATR_CTL_WEIGHT,bInP); }
inline const SvxShadowedItem     &SwAttrSet::GetShadowed(BOOL bInP) const
    {   return (const SvxShadowedItem&)Get( RES_CHRATR_SHADOWED,bInP); }
inline const SvxAutoKernItem     &SwAttrSet::GetAutoKern(BOOL bInP) const
    {   return (const SvxAutoKernItem&)Get( RES_CHRATR_AUTOKERN,bInP); }
inline const SvxWordLineModeItem     &SwAttrSet::GetWordLineMode(BOOL bInP) const
    {   return (const SvxWordLineModeItem&)Get( RES_CHRATR_WORDLINEMODE,bInP); }
inline const SvxContourItem      &SwAttrSet::GetContour(BOOL bInP) const
    {   return (const SvxContourItem&)Get( RES_CHRATR_CONTOUR,bInP); }
inline const SvxKerningItem      &SwAttrSet::GetKerning(BOOL bInP) const
    {   return (const SvxKerningItem&)Get( RES_CHRATR_KERNING,bInP); }
inline const SvxUnderlineItem    &SwAttrSet::GetUnderline(BOOL bInP) const
    {   return (const SvxUnderlineItem&)Get( RES_CHRATR_UNDERLINE,bInP); }
inline const SvxCrossedOutItem   &SwAttrSet::GetCrossedOut(BOOL bInP) const
    {   return (const SvxCrossedOutItem&)Get( RES_CHRATR_CROSSEDOUT,bInP); }
inline const SvxFontHeightItem         &SwAttrSet::GetSize(BOOL bInP) const
    {   return (const SvxFontHeightItem&)Get( RES_CHRATR_FONTSIZE,bInP); }
inline const SvxFontHeightItem         &SwAttrSet::GetCJKSize(BOOL bInP) const
    {   return (const SvxFontHeightItem&)Get( RES_CHRATR_CJK_FONTSIZE,bInP); }
inline const SvxFontHeightItem         &SwAttrSet::GetCTLSize(BOOL bInP) const
    {   return (const SvxFontHeightItem&)Get( RES_CHRATR_CTL_FONTSIZE,bInP); }
inline const SvxPropSizeItem     &SwAttrSet::GetPropSize(BOOL bInP) const
    {   return (const SvxPropSizeItem&)Get( RES_CHRATR_PROPORTIONALFONTSIZE,bInP); }
inline const SvxFontItem         &SwAttrSet::GetFont(BOOL bInP) const
    {   return (const SvxFontItem&)Get( RES_CHRATR_FONT,bInP); }
inline const SvxFontItem         &SwAttrSet::GetCJKFont(BOOL bInP) const
    {   return (const SvxFontItem&)Get( RES_CHRATR_CJK_FONT,bInP); }
inline const SvxFontItem         &SwAttrSet::GetCTLFont(BOOL bInP) const
    {   return (const SvxFontItem&)Get( RES_CHRATR_CTL_FONT,bInP); }
inline const SvxColorItem        &SwAttrSet::GetColor(BOOL bInP) const
    {   return (const SvxColorItem&)Get( RES_CHRATR_COLOR,bInP); }
inline const SvxCharSetColorItem &SwAttrSet::GetCharSetColor(BOOL bInP) const
    {   return (const SvxCharSetColorItem&)Get( RES_CHRATR_CHARSETCOLOR,bInP); }
inline const SvxLanguageItem     &SwAttrSet::GetLanguage(BOOL bInP) const
    {   return (const SvxLanguageItem&)Get( RES_CHRATR_LANGUAGE,bInP); }
inline const SvxLanguageItem     &SwAttrSet::GetCJKLanguage(BOOL bInP) const
    {   return (const SvxLanguageItem&)Get( RES_CHRATR_CJK_LANGUAGE,bInP); }
inline const SvxLanguageItem     &SwAttrSet::GetCTLLanguage(BOOL bInP) const
    {   return (const SvxLanguageItem&)Get( RES_CHRATR_CTL_LANGUAGE,bInP); }
inline const SvxEscapementItem   &SwAttrSet::GetEscapement(BOOL bInP) const
    {   return (const SvxEscapementItem&)Get( RES_CHRATR_ESCAPEMENT,bInP); }
inline const SvxCaseMapItem     &SwAttrSet::GetCaseMap(BOOL bInP) const
    {   return (const SvxCaseMapItem&)Get( RES_CHRATR_CASEMAP,bInP); }
inline const SvxNoHyphenItem    &SwAttrSet::GetNoHyphenHere(BOOL bInP) const
    {   return (const SvxNoHyphenItem&)Get( RES_CHRATR_NOHYPHEN,bInP); }
inline const SvxBlinkItem  &SwAttrSet::GetBlink(BOOL bInP) const
    {   return (const SvxBlinkItem&)Get( RES_CHRATR_BLINK,bInP); }
inline const SvxBrushItem &SwAttrSet::GetChrBackground( BOOL bInP ) const
    {   return (const SvxBrushItem&)Get( RES_CHRATR_BACKGROUND, bInP ); }
inline const SvxEmphasisMarkItem &SwAttrSet::GetEmphasisMark( BOOL bInP ) const
    {   return (const SvxEmphasisMarkItem&)Get( RES_CHRATR_EMPHASIS_MARK, bInP ); }
inline const SvxTwoLinesItem    &SwAttrSet::Get2Lines( BOOL bInP ) const
    {   return (const SvxTwoLinesItem&)Get( RES_CHRATR_TWO_LINES, bInP ); }
inline const SvxCharScaleWidthItem  &SwAttrSet::GetCharScaleW( BOOL bInP ) const
    {   return (const SvxCharScaleWidthItem&)Get( RES_CHRATR_SCALEW, bInP ); }
inline const SvxCharRotateItem  &SwAttrSet::GetCharRotate( BOOL bInP ) const
    {   return (const SvxCharRotateItem&)Get( RES_CHRATR_ROTATE, bInP ); }
inline const SvxCharReliefItem  &SwAttrSet::GetCharRelief( BOOL bInP ) const
    {   return (const SvxCharReliefItem&)Get( RES_CHRATR_RELIEF, bInP ); }

/******************************************************************************
 *  Implementierung der Charakter-Attribut Methoden vom SwFmt
 *  AMA: 12.10.94: Umstellung auf SvxItems.
 ******************************************************************************/

inline const SvxPostureItem          &SwFmt::GetPosture(BOOL bInP) const
    {   return aSet.GetPosture(bInP); }
inline const SvxWeightItem           &SwFmt::GetWeight(BOOL bInP) const
    {   return aSet.GetWeight(bInP); }
inline const SvxShadowedItem         &SwFmt::GetShadowed(BOOL bInP) const
    {   return aSet.GetShadowed(bInP); }
inline const SvxAutoKernItem         &SwFmt::GetAutoKern(BOOL bInP) const
    {   return aSet.GetAutoKern(bInP); }
inline const SvxWordLineModeItem     &SwFmt::GetWordLineMode(BOOL bInP) const
    {   return aSet.GetWordLineMode(bInP); }
inline const SvxContourItem          &SwFmt::GetContour(BOOL bInP) const
    {   return aSet.GetContour(bInP); }
inline const SvxKerningItem          &SwFmt::GetKerning(BOOL bInP) const
    {   return aSet.GetKerning(bInP); }
inline const SvxUnderlineItem        &SwFmt::GetUnderline(BOOL bInP) const
    {   return aSet.GetUnderline(bInP); }
inline const SvxCrossedOutItem       &SwFmt::GetCrossedOut(BOOL bInP) const
    {   return aSet.GetCrossedOut(bInP); }
inline const SvxFontHeightItem             &SwFmt::GetSize(BOOL bInP) const
    {   return aSet.GetSize(bInP); }
inline const SvxPropSizeItem         &SwFmt::GetPropSize(BOOL bInP) const
    {   return aSet.GetPropSize(bInP); }
inline const SvxFontItem             &SwFmt::GetFont(BOOL bInP) const
    {   return aSet.GetFont(bInP); }
inline const SvxFontItem         &SwFmt::GetCJKFont(BOOL bInP) const
    {   return aSet.GetCJKFont(bInP); }
inline const SvxFontItem         &SwFmt::GetCTLFont(BOOL bInP) const
    {   return aSet.GetCTLFont(bInP); }
inline const SvxColorItem            &SwFmt::GetColor(BOOL bInP) const
    {   return aSet.GetColor(bInP); }
inline const SvxCharSetColorItem     &SwFmt::GetCharSetColor(BOOL bInP) const
    {   return aSet.GetCharSetColor(bInP); }
inline const SvxLanguageItem         &SwFmt::GetLanguage(BOOL bInP) const
    {   return aSet.GetLanguage(bInP); }
inline const SvxEscapementItem       &SwFmt::GetEscapement(BOOL bInP) const
    {   return aSet.GetEscapement(bInP); }
inline const SvxCaseMapItem          &SwFmt::GetCaseMap(BOOL bInP) const
    {   return aSet.GetCaseMap(bInP); }
inline const SvxNoHyphenItem         &SwFmt::GetNoHyphenHere(BOOL bInP) const
    {   return aSet.GetNoHyphenHere(bInP); }
inline const SvxBlinkItem            &SwFmt::GetBlink(BOOL bInP) const
    {   return aSet.GetBlink(bInP); }
inline const SvxBrushItem            &SwFmt::GetChrBackground(BOOL bInP) const
    {   return aSet.GetChrBackground(bInP); }
inline const SvxEmphasisMarkItem    &SwFmt::GetEmphasisMark( BOOL bInP ) const
    {   return aSet.GetEmphasisMark(bInP); }
inline const SvxTwoLinesItem        &SwFmt::Get2Lines( BOOL bInP ) const
    {   return aSet.Get2Lines(bInP); }
inline const SvxCharScaleWidthItem  &SwFmt::GetCharScaleW( BOOL bInP ) const
    {   return aSet.GetCharScaleW(bInP); }
inline const SvxCharRotateItem      &SwFmt::GetCharRotate( BOOL bInP ) const
    {   return aSet.GetCharRotate(bInP); }
inline const SvxCharReliefItem      &SwFmt::GetCharRelief( BOOL bInP ) const
    {   return aSet.GetCharRelief(bInP); }

#endif
<commit_msg>#101685#,#i6886#: merge OOO_STABLE_1_PORTS (1.7-1.7.20.1) -> HEAD<commit_after>/*************************************************************************
 *
 *  $RCSfile: charatr.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: hr $ $Date: 2002-08-23 12:25:39 $
 *
 *  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 _CHARATR_HXX
#define _CHARATR_HXX

#ifndef _FORMAT_HXX
#include <format.hxx>
#endif
#ifndef _HINTIDS_HXX
#include <hintids.hxx>      // fuer die WhichIds
#endif

/******************************************************************************
 *  Implementierung der Charakter-Attribut Methoden vom SwAttrSet
 *  AMA 12.10.94: Umstellung auf SvxItems.
 ******************************************************************************/

inline const SvxPostureItem      &SwAttrSet::GetPosture(BOOL bInP) const
    {   return (const SvxPostureItem&)Get( RES_CHRATR_POSTURE,bInP); }
inline const SvxPostureItem      &SwAttrSet::GetCJKPosture(BOOL bInP) const
    {   return (const SvxPostureItem&)Get( RES_CHRATR_CJK_POSTURE,bInP); }
inline const SvxPostureItem      &SwAttrSet::GetCTLPosture(BOOL bInP) const
    {   return (const SvxPostureItem&)Get( RES_CHRATR_CTL_POSTURE,bInP); }
inline const SvxWeightItem       &SwAttrSet::GetWeight(BOOL bInP) const
    {   return (const SvxWeightItem&)Get( RES_CHRATR_WEIGHT,bInP); }
inline const SvxWeightItem       &SwAttrSet::GetCJKWeight(BOOL bInP) const
    {   return (const SvxWeightItem&)Get( RES_CHRATR_CJK_WEIGHT,bInP); }
inline const SvxWeightItem       &SwAttrSet::GetCTLWeight(BOOL bInP) const
    {   return (const SvxWeightItem&)Get( RES_CHRATR_CTL_WEIGHT,bInP); }
inline const SvxShadowedItem     &SwAttrSet::GetShadowed(BOOL bInP) const
    {   return (const SvxShadowedItem&)Get( RES_CHRATR_SHADOWED,bInP); }
inline const SvxAutoKernItem     &SwAttrSet::GetAutoKern(BOOL bInP) const
    {   return (const SvxAutoKernItem&)Get( RES_CHRATR_AUTOKERN,bInP); }
inline const SvxWordLineModeItem     &SwAttrSet::GetWordLineMode(BOOL bInP) const
    {   return (const SvxWordLineModeItem&)Get( RES_CHRATR_WORDLINEMODE,bInP); }
inline const SvxContourItem      &SwAttrSet::GetContour(BOOL bInP) const
    {   return (const SvxContourItem&)Get( RES_CHRATR_CONTOUR,bInP); }
inline const SvxKerningItem      &SwAttrSet::GetKerning(BOOL bInP) const
    {   return (const SvxKerningItem&)Get( RES_CHRATR_KERNING,bInP); }
inline const SvxUnderlineItem    &SwAttrSet::GetUnderline(BOOL bInP) const
    {   return (const SvxUnderlineItem&)Get( RES_CHRATR_UNDERLINE,bInP); }
inline const SvxCrossedOutItem   &SwAttrSet::GetCrossedOut(BOOL bInP) const
    {   return (const SvxCrossedOutItem&)Get( RES_CHRATR_CROSSEDOUT,bInP); }
inline const SvxFontHeightItem         &SwAttrSet::GetSize(BOOL bInP) const
    {   return (const SvxFontHeightItem&)Get( RES_CHRATR_FONTSIZE,bInP); }
inline const SvxFontHeightItem         &SwAttrSet::GetCJKSize(BOOL bInP) const
    {   return (const SvxFontHeightItem&)Get( RES_CHRATR_CJK_FONTSIZE,bInP); }
inline const SvxFontHeightItem         &SwAttrSet::GetCTLSize(BOOL bInP) const
    {   return (const SvxFontHeightItem&)Get( RES_CHRATR_CTL_FONTSIZE,bInP); }
inline const SvxPropSizeItem     &SwAttrSet::GetPropSize(BOOL bInP) const
    {   return (const SvxPropSizeItem&)Get( RES_CHRATR_PROPORTIONALFONTSIZE,bInP); }

#ifndef MACOSX
// GrP moved to gcc_outl.cxx; revisit with gcc3
inline const SvxFontItem         &SwAttrSet::GetFont(BOOL bInP) const
    {   return (const SvxFontItem&)Get( RES_CHRATR_FONT,bInP); }
#endif
inline const SvxFontItem         &SwAttrSet::GetCJKFont(BOOL bInP) const
    {   return (const SvxFontItem&)Get( RES_CHRATR_CJK_FONT,bInP); }
inline const SvxFontItem         &SwAttrSet::GetCTLFont(BOOL bInP) const
    {   return (const SvxFontItem&)Get( RES_CHRATR_CTL_FONT,bInP); }
inline const SvxColorItem        &SwAttrSet::GetColor(BOOL bInP) const
    {   return (const SvxColorItem&)Get( RES_CHRATR_COLOR,bInP); }
inline const SvxCharSetColorItem &SwAttrSet::GetCharSetColor(BOOL bInP) const
    {   return (const SvxCharSetColorItem&)Get( RES_CHRATR_CHARSETCOLOR,bInP); }
inline const SvxLanguageItem     &SwAttrSet::GetLanguage(BOOL bInP) const
    {   return (const SvxLanguageItem&)Get( RES_CHRATR_LANGUAGE,bInP); }
inline const SvxLanguageItem     &SwAttrSet::GetCJKLanguage(BOOL bInP) const
    {   return (const SvxLanguageItem&)Get( RES_CHRATR_CJK_LANGUAGE,bInP); }
inline const SvxLanguageItem     &SwAttrSet::GetCTLLanguage(BOOL bInP) const
    {   return (const SvxLanguageItem&)Get( RES_CHRATR_CTL_LANGUAGE,bInP); }
inline const SvxEscapementItem   &SwAttrSet::GetEscapement(BOOL bInP) const
    {   return (const SvxEscapementItem&)Get( RES_CHRATR_ESCAPEMENT,bInP); }
inline const SvxCaseMapItem     &SwAttrSet::GetCaseMap(BOOL bInP) const
    {   return (const SvxCaseMapItem&)Get( RES_CHRATR_CASEMAP,bInP); }
inline const SvxNoHyphenItem    &SwAttrSet::GetNoHyphenHere(BOOL bInP) const
    {   return (const SvxNoHyphenItem&)Get( RES_CHRATR_NOHYPHEN,bInP); }
inline const SvxBlinkItem  &SwAttrSet::GetBlink(BOOL bInP) const
    {   return (const SvxBlinkItem&)Get( RES_CHRATR_BLINK,bInP); }
inline const SvxBrushItem &SwAttrSet::GetChrBackground( BOOL bInP ) const
    {   return (const SvxBrushItem&)Get( RES_CHRATR_BACKGROUND, bInP ); }
inline const SvxEmphasisMarkItem &SwAttrSet::GetEmphasisMark( BOOL bInP ) const
    {   return (const SvxEmphasisMarkItem&)Get( RES_CHRATR_EMPHASIS_MARK, bInP ); }
inline const SvxTwoLinesItem    &SwAttrSet::Get2Lines( BOOL bInP ) const
    {   return (const SvxTwoLinesItem&)Get( RES_CHRATR_TWO_LINES, bInP ); }
inline const SvxCharScaleWidthItem  &SwAttrSet::GetCharScaleW( BOOL bInP ) const
    {   return (const SvxCharScaleWidthItem&)Get( RES_CHRATR_SCALEW, bInP ); }
inline const SvxCharRotateItem  &SwAttrSet::GetCharRotate( BOOL bInP ) const
    {   return (const SvxCharRotateItem&)Get( RES_CHRATR_ROTATE, bInP ); }
inline const SvxCharReliefItem  &SwAttrSet::GetCharRelief( BOOL bInP ) const
    {   return (const SvxCharReliefItem&)Get( RES_CHRATR_RELIEF, bInP ); }

/******************************************************************************
 *  Implementierung der Charakter-Attribut Methoden vom SwFmt
 *  AMA: 12.10.94: Umstellung auf SvxItems.
 ******************************************************************************/

inline const SvxPostureItem          &SwFmt::GetPosture(BOOL bInP) const
    {   return aSet.GetPosture(bInP); }
inline const SvxWeightItem           &SwFmt::GetWeight(BOOL bInP) const
    {   return aSet.GetWeight(bInP); }
inline const SvxShadowedItem         &SwFmt::GetShadowed(BOOL bInP) const
    {   return aSet.GetShadowed(bInP); }
inline const SvxAutoKernItem         &SwFmt::GetAutoKern(BOOL bInP) const
    {   return aSet.GetAutoKern(bInP); }
inline const SvxWordLineModeItem     &SwFmt::GetWordLineMode(BOOL bInP) const
    {   return aSet.GetWordLineMode(bInP); }
inline const SvxContourItem          &SwFmt::GetContour(BOOL bInP) const
    {   return aSet.GetContour(bInP); }
inline const SvxKerningItem          &SwFmt::GetKerning(BOOL bInP) const
    {   return aSet.GetKerning(bInP); }
inline const SvxUnderlineItem        &SwFmt::GetUnderline(BOOL bInP) const
    {   return aSet.GetUnderline(bInP); }
inline const SvxCrossedOutItem       &SwFmt::GetCrossedOut(BOOL bInP) const
    {   return aSet.GetCrossedOut(bInP); }
inline const SvxFontHeightItem             &SwFmt::GetSize(BOOL bInP) const
    {   return aSet.GetSize(bInP); }
inline const SvxPropSizeItem         &SwFmt::GetPropSize(BOOL bInP) const
    {   return aSet.GetPropSize(bInP); }
#ifndef MACOSX
// GrP moved to gcc_outl.cxx; revisit with gcc3
inline const SvxFontItem             &SwFmt::GetFont(BOOL bInP) const
    {   return aSet.GetFont(bInP); }
#endif
inline const SvxFontItem         &SwFmt::GetCJKFont(BOOL bInP) const
    {   return aSet.GetCJKFont(bInP); }
inline const SvxFontItem         &SwFmt::GetCTLFont(BOOL bInP) const
    {   return aSet.GetCTLFont(bInP); }
inline const SvxColorItem            &SwFmt::GetColor(BOOL bInP) const
    {   return aSet.GetColor(bInP); }
inline const SvxCharSetColorItem     &SwFmt::GetCharSetColor(BOOL bInP) const
    {   return aSet.GetCharSetColor(bInP); }
inline const SvxLanguageItem         &SwFmt::GetLanguage(BOOL bInP) const
    {   return aSet.GetLanguage(bInP); }
inline const SvxEscapementItem       &SwFmt::GetEscapement(BOOL bInP) const
    {   return aSet.GetEscapement(bInP); }
inline const SvxCaseMapItem          &SwFmt::GetCaseMap(BOOL bInP) const
    {   return aSet.GetCaseMap(bInP); }
inline const SvxNoHyphenItem         &SwFmt::GetNoHyphenHere(BOOL bInP) const
    {   return aSet.GetNoHyphenHere(bInP); }
inline const SvxBlinkItem            &SwFmt::GetBlink(BOOL bInP) const
    {   return aSet.GetBlink(bInP); }
inline const SvxBrushItem            &SwFmt::GetChrBackground(BOOL bInP) const
    {   return aSet.GetChrBackground(bInP); }
inline const SvxEmphasisMarkItem    &SwFmt::GetEmphasisMark( BOOL bInP ) const
    {   return aSet.GetEmphasisMark(bInP); }
inline const SvxTwoLinesItem        &SwFmt::Get2Lines( BOOL bInP ) const
    {   return aSet.Get2Lines(bInP); }
inline const SvxCharScaleWidthItem  &SwFmt::GetCharScaleW( BOOL bInP ) const
    {   return aSet.GetCharScaleW(bInP); }
inline const SvxCharRotateItem      &SwFmt::GetCharRotate( BOOL bInP ) const
    {   return aSet.GetCharRotate(bInP); }
inline const SvxCharReliefItem      &SwFmt::GetCharRelief( BOOL bInP ) const
    {   return aSet.GetCharRelief(bInP); }

#endif
<|endoftext|>


<commit_before>#include <Game/ECS/GameWorld.h>
#include <Game/ECS/Components/ActionQueueComponent.h>
#include <Game/Objects/SmartObjectComponent.h>
#include <Game/Objects/SmartObject.h>

namespace DEM::Game
{

void InteractWithSmartObjects(CGameWorld& World)
{
	World.ForEachEntityWith<CActionQueueComponent>(
		[&World](auto EntityID, auto& Entity, CActionQueueComponent& Queue)
	{
		auto pAction = Queue.FindActive<SwitchSmartObjectState>();
		if (!pAction) return;

		//!!!???only if no sub-action?!
		//const float ActorRadius = 0.f; // TODO: fill!
		// TODO: fill Action.Pos with curr actor pos!
		// TODO: actor anim and/or state
		//???!!!need interaction ID in params?!
		//if (!pSOAsset->GetInteractionParams(CStrID(_Name.c_str()), ActorRadius, pAction->Pos, pAction->FaceDir)) return false;

		// if not the same poly, add or update Navigate (can try to raycast but require all polys on the way to be Steer-able
		// if not the same position (what tolerance, from Steer?), add or update Steer
		// if not required facing, add or update Face
		// if facing is OK too, start actor animation and request smart object state switching

		//CSmartObject* pSmart = SOComponent.Asset->GetObject<CSmartObject>();
		//if (!pSmart) return;

		auto pSOComponent = World.FindComponent<CSmartObjectComponent>(pAction->Object);
		if (!pSOComponent) return;
		pSOComponent->RequestedState = pAction->ObjectState;
		pSOComponent->Force = pAction->ForceObjectState;
	});
}
//---------------------------------------------------------------------

}
<commit_msg>SO interaction by actor WIP 2<commit_after>#include <Game/ECS/GameWorld.h>
#include <Game/ECS/Components/ActionQueueComponent.h>
#include <Game/Objects/SmartObjectComponent.h>
#include <Game/Objects/SmartObject.h>

namespace DEM::Game
{

void InteractWithSmartObjects(CGameWorld& World)
{
	World.ForEachEntityWith<CActionQueueComponent>(
		[&World](auto EntityID, auto& Entity, CActionQueueComponent& Queue)
	{
		auto pAction = Queue.FindActive<SwitchSmartObjectState>();
		if (!pAction) return;

		// Check if action or sub-action is stopped
		if (pQueue->GetStatus() == DEM::Game::EActionStatus::Failed || pQueue->GetStatus() == DEM::Game::EActionStatus::Cancelled)
		{
			// If sub-action failed or cancelled, finish with the same result
			// TODO: improve API!
			Queue.FinalizeActiveAction(*pAction, pQueue->GetStatus());
			Queue.RemoveAction(*pAction);
			return;
		}

		// Check if this action succeeded
		if (pQueue->GetActiveStackTop() == pAction && pQueue->GetStatus() == DEM::Game::EActionStatus::Succeeded)
		{
			Queue.RemoveAction(*pAction);
			return;
		}

		// If we didn't finish but no sub-action is active, try to generate it
		if (pQueue->GetActiveStackTop() == pAction || pQueue->GetStatus() == DEM::Game::EActionStatus::Succeeded)
		{
			//
		}

		//const float ActorRadius = 0.f; // TODO: fill!
		// TODO: fill Action.Pos with curr actor pos!
		// TODO: actor anim and/or state
		//???!!!need interaction ID in params?!
		//if (!pSOAsset->GetInteractionParams(CStrID(_Name.c_str()), ActorRadius, pAction->Pos, pAction->FaceDir)) return false;

		// if not the same poly, add or update Navigate (can try to raycast but require all polys on the way to be Steer-able
		// if not the same position (what tolerance, from Steer?), add or update Steer
		// if not required facing, add or update Face
		// if facing is OK too, start actor animation and request smart object state switching

		//CSmartObject* pSmart = SOComponent.Asset->GetObject<CSmartObject>();
		//if (!pSmart) return;

		auto pSOComponent = World.FindComponent<CSmartObjectComponent>(pAction->Object);
		if (!pSOComponent) return;
		pSOComponent->RequestedState = pAction->ObjectState;
		pSOComponent->Force = pAction->ForceObjectState;
	});
}
//---------------------------------------------------------------------

}
<|endoftext|>