// Copyright (c) 2019, LAAS-CNRS
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.


#ifndef HPP_MANIPULATION_GRAPH_IDL
#define HPP_MANIPULATION_GRAPH_IDL

#include "hpp/corbaserver/manipulation/gcommon.idl"
#include <hpp/common.idl>
#include <hpp/constraints_idl/constraints.idl>
#include <hpp/core_idl/steering_methods.idl>
#include <hpp/core_idl/path_validations.idl>

module hpp {
  module constraints_idl {
    interface Implicit;
    interface LockedJoint;
    typedef sequence <LockedJoint> LockedJoints;
  };
  module core_idl {
    interface SteeringMethod;
    interface PathValidation;
  };
  module manipulation_idl {
    module graph_idl {
      typedef unsigned long long size_t;
      interface State;
      typedef sequence<State> States;
      interface Edge;
      typedef sequence<Edge> Edges;
      interface Graph;

      interface GraphComponent {
        string name () raises (Error);
        size_t id () raises (Error);

        Graph parentGraph () raises (Error);

        void addNumericalConstraint (in constraints_idl::Implicit nm) raises (Error);
        void addNumericalCost (in constraints_idl::Implicit nm) raises (Error);

        constraints_idl::Implicits numericalConstraints () raises (Error);

        constraints_idl::Implicits numericalCosts () raises (Error);

        void resetNumericalConstraints () raises (Error);

        void setSolveLevelByLevel(in boolean input) raises(Error);
        //-> solveLevelByLevel
        boolean getSolveLevelByLevel() raises(Error);
        //-> solveLevelByLevel
      }; // interface GraphComponent

      interface StateSelector
      {
        string name () raises (Error);

        Graph parentGraph () raises (Error);

        States getStates () raises (Error);
      }; // interface StateSelector

      interface Graph : GraphComponent
      {
        StateSelector getStateSelector () raises (Error);
        //-> stateSelector
        GraphComponent get (in size_t id) raises (Error);
        size_t nbComponents () raises (Error);
        void initialize () raises (Error);

        State getState (in floatSeq config) raises (Error);
        Edges getEdges (in State from, in State to) raises (Error);
      }; // interface Graph

      interface State : GraphComponent
      {
        boolean contains (in floatSeq config) raises (Error);
        Edge linkTo (in string name, in State to, in size_type weight) raises (Error);

        Edges neighborEdges () raises (Error);
        Edges hiddenNeighbors () raises (Error);

        core_idl::ConstraintSet configConstraint () raises (Error);
      }; // interface State

      interface Edge : GraphComponent
      {
        State stateFrom () raises (Error);
        State stateTo () raises (Error);
        State getState () raises (Error);
        //-> state
        void setState (in State st) raises (Error);
        //-> state
        intSeqSeq getRelativeMotion () raises (Error);
        //* return corbaServer::matrixToIntSeqSeq(getT()->relativeMotion().template cast<CORBA::Long>());
        floatSeqSeq getSecurityMargins () raises (Error);
        //-> securityMargins
        void setSecurityMarginForPair(in size_type row, in size_type col, in value_type margin) raises (Error);
        //-> securityMarginForPair

        boolean generateTargetConfig(in floatSeq qStart, inout floatSeq q)
          raises(Error);

        core_idl::SteeringMethod getSteeringMethod () raises (Error);
        //-> steeringMethod
        core_idl::PathValidation getPathValidation () raises (Error);
        //-> pathValidation

        /// \deprecated renamed to \ref targetConstraint
        core_idl::ConstraintSet configConstraint () raises (Error);
        //-> targetConstraint

        core_idl::ConstraintSet targetConstraint () raises (Error);

        core_idl::ConstraintSet pathConstraint () raises (Error);
      }; // interface Edge

      interface LevelSetEdge : Edge
      {
        constraints_idl::Implicits paramConstraints() raises(Error);
        constraints_idl::Implicits conditionConstraints() raises(Error);
        boolean generateTargetConfigOnLeaf(in floatSeq qStart,
                                           in floatSeq qLeaf,
                                           inout floatSeq q) raises(Error);
      }; // interface LevelSetEdge

      interface Validation
      {
        string str () raises (Error);

        boolean hasErrors () raises (Error);

        boolean hasWarnings () raises (Error);

        stringSeqSeq getCollisionsForNode (in string name) raises (Error);
        //* std::string _name (name);
        //* hpp::stringSeqSeq* __return__ (hpp::corbaServer::vectorToStringSeqSeq(getT()->getCollisionsForNode (_name)));
        //* return __return__;

        boolean validate (in GraphComponent comp) raises (Error);
      }; // interface Validation
    }; // module graph
  }; // module manipulation
}; // module hpp

//* #include <hpp/constraints_idl/constraints.hh>
//* #include <hpp/core_idl/steering_methods.hh>
//* #include <hpp/core_idl/path_validations.hh>
//* #include <hpp/manipulation/graph/edge.hh>
//* #include <hpp/manipulation/graph/graph.hh>
//* #include <hpp/manipulation/graph/state.hh>
//* #include <hpp/manipulation/graph/state-selector.hh>
//* #include <hpp/manipulation/graph/validation.hh>

#endif // HPP_MANIPULATION_STEERING_METHODS_IDL
