// Copyright (C) 2019 by Joseph Mirabel, LAAS-CNRS.
//
// This file is part of the hpp-corbaserver.
//
// This software is provided "as is" without warranty of any kind,
// either expressed or implied, including but not limited to the
// implied warranties of fitness for a particular purpose.
//
// See the COPYING file for more information.

#ifndef HPP_PINOCCHIO_ROBOTS_IDL
#define HPP_PINOCCHIO_ROBOTS_IDL
#include <hpp/common.idl>

module hpp
{
  module pinocchio_idl {
  interface CenterOfMassComputation
  {
    HPP_EXPOSE_MEMORY_DEALLOCATION(Error)

    void compute () raises (Error);
    floatSeq    com      () raises (Error);
    value_type  mass     () raises (Error);
    floatSeqSeq jacobian () raises (Error);
  };

  interface Device
  {
      HPP_EXPOSE_MEMORY_DEALLOCATION(Error)

      string name () raises (Error);

      floatSeq neutralConfiguration () raises (Error);

      size_type configSize() raises (Error);

      size_type numberDof() raises (Error);

      void integrate(in floatSeq config_in, in floatSeq velocity, out floatSeq result) raises (Error);
      //* hpp::pinocchio::DevicePtr_t d = getT();
      //* hpp::pinocchio::Configuration_t res (d->configSize());
      //* hpp::pinocchio::integrate<false, hpp::pinocchio::DefaultLieGroupMap> (d,
      //*   ::hpp::corbaServer::floatSeqToVector(config_in, d->configSize()),
      //*   ::hpp::corbaServer::floatSeqToVector(velocity , d->numberDof()),
      //*   res);
      //* result = ::hpp::corbaServer::vectorToFloatSeq (res);

      void difference(in floatSeq q1, in floatSeq q2, out floatSeq result) raises (Error);
      //* hpp::pinocchio::DevicePtr_t d = getT();
      //* hpp::pinocchio::Configuration_t res (d->numberDof());
      //* hpp::pinocchio::difference<hpp::pinocchio::DefaultLieGroupMap> (d,
      //*   ::hpp::corbaServer::floatSeqToVector(q1, d->configSize()),
      //*   ::hpp::corbaServer::floatSeqToVector(q2, d->configSize()),
      //*   res);
      //* result = ::hpp::corbaServer::vectorToFloatSeq (res);

      void interpolate(in floatSeq q1, in floatSeq q2, in float u, out floatSeq result) raises (Error);
      //* hpp::pinocchio::DevicePtr_t d = getT();
      //* hpp::pinocchio::Configuration_t res (d->configSize());
      //* hpp::pinocchio::interpolate<hpp::pinocchio::DefaultLieGroupMap> (d,
      //*   ::hpp::corbaServer::floatSeqToVector(q1, d->configSize()),
      //*   ::hpp::corbaServer::floatSeqToVector(q2, d->configSize()),
      //*   u,
      //*   res);
      //* result = ::hpp::corbaServer::vectorToFloatSeq (res);

      void saturate(in floatSeq qin, out floatSeq qout, out boolSeq saturation) raises (Error);
      //* hpp::pinocchio::DevicePtr_t d = getT();
      //* hpp::pinocchio::Configuration_t q (::hpp::corbaServer::floatSeqToVector(qin));
      //* hpp::pinocchio::ArrayXb sat (d->numberDof());
      //* hpp::pinocchio::saturate (d, q, sat);
      //* qout = ::hpp::corbaServer::vectorToFloatSeq (q);
      //* saturation = ::hpp::corbaServer::toBoolSeq(sat.data(), sat.data()+sat.size());

      void replaceGeometryByConvexHull(in Names_t geometryNames) raises (Error);
      //* hpp::pinocchio::DevicePtr_t d = getT();
      //* hpp::pinocchio::replaceGeometryByConvexHull(d->geomModel(),
      //*   ::hpp::corbaServer::toStrings<std::vector<std::string> >(geometryNames));
      //* d->createGeomData();

      floatSeq getCurrentConfiguration () raises (Error);
      //->currentConfiguration

      boolean setCurrentConfiguration (in floatSeq configuration) raises (Error);
      //->currentConfiguration

      floatSeq getCurrentVelocity () raises (Error);
      //->currentVelocity

      boolean setCurrentVelocity (in floatSeq velocity) raises (Error);
      //->currentVelocity

      floatSeq getCurrentAcceleration () raises (Error);
      //->currentAcceleration

      boolean setCurrentAcceleration (in floatSeq acceleration) raises (Error);
      //->currentAcceleration

      short computationFlag() raises (Error);

      void controlComputation(in short flag) raises (Error);
      //* getT()->controlComputation(hpp::pinocchio::Computation_t(flag));

      void computeForwardKinematics(in short computationFlag) raises (Error);

      void computeFramesForwardKinematics () raises (Error);

      void updateGeometryPlacements () raises (Error);

      frame_index getFrameByName (in string name) raises (Error);
      //* return (frame_index) getT()->getFrameByName(name).index();

      Transform_ getFramePosition (in frame_index frame_id) raises (Error);
      //* if (getT()->model().nframes <= (int)frame_id) throw hpp::Error("Index out of range");
      //* hpp::pinocchio::Frame frame(getT(), frame_id);
      //* return hpp::corbaServer::toHppTransform(frame.currentTransformation());

      floatSeqSeq getFrameJacobian (in frame_index frame_id) raises (Error);
      //* if (getT()->model().nframes <= (int)frame_id) throw hpp::Error("Index out of range");
      //* if (!(getT()->computationFlag() & hpp::pinocchio::JACOBIAN))
      //*   throw hpp::Error("Invalid computation flags");
      //* hpp::pinocchio::Frame frame(getT(), frame_id);
      //* return hpp::corbaServer::matrixToFloatSeqSeq(frame.jacobian());

      /// \warning removing joints invalidates joint ids. Use this carefully.
      void removeJoints(in Names_t joints, in floatSeq refConfig) raises (Error);
  };

  interface CollisionObject {
    HPP_EXPOSE_MEMORY_DEALLOCATION(Error)
  }; // interface CollisionObject

  }; // module pinocchio_idl
}; // module hpp
//* #include <hpp/pinocchio/device.hh>
//* #include <hpp/pinocchio/collision-object.hh>
//* #include <hpp/pinocchio/configuration.hh>
//* #include <hpp/pinocchio/liegroup.hh>
//* #include <hpp/pinocchio/center-of-mass-computation.hh>

#endif // HPP_CORE_PATHS_IDL
