/*
  semi-tie-column.cc -- implement Semi_tie_column

  source file of the GNU LilyPond music typesetter

  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>

*/

#include "semi-tie-column.hh"
#include "semi-tie.hh"
#include "grob.hh"
#include "tie-column.hh"
#include "tie.hh"
#include "directional-element-interface.hh"
#include "pointer-group-interface.hh"
#include "staff-symbol-referencer.hh"
#include "item.hh"
#include "tie-formatting-problem.hh"
#include "tie-configuration.hh"
#include "tie-column-format.hh"


ADD_INTERFACE(Semi_tie_column,
	      "semi-tie-column-interface",
	      "The interface for a column of l.v. ties.",

	      /* properties */
	      "positioning-done "
	      "head-direction "
	      "tie-configuration "
	      );
			   


/*
  Cut & paste from tie-column.cc
 */   
MAKE_SCHEME_CALLBACK(Semi_tie_column, calc_positioning_done, 1);
SCM
Semi_tie_column::calc_positioning_done (SCM smob)
{
  Grob *me = unsmob_grob (smob);
  
  extract_grob_set (me, "ties", lv_ro_ties);
  vector<Grob*> lv_ties (lv_ro_ties);

  vector_sort (lv_ties, Semi_tie::less);

  Ties_configuration ties_config;
  

  Tie_formatting_problem problem;
  
  problem.from_semi_ties (lv_ties, to_dir (me->get_property ("head-direction")));

  SCM manual_configs = me->get_property ("tie-configuration");
  problem.set_manual_tie_configuration (manual_configs);

  Ties_configuration base = problem.generate_optimal_chord_configuration ();
  for (vsize i = 0; i < lv_ties.size(); i++)
    {
      Tie::set_control_points (lv_ties[i], problem.common_x_refpoint (), base[i],
			       problem.details_);
      set_grob_direction (lv_ties[i], base[i].dir_);
    }

  return SCM_BOOL_T;
}
  

