/**------------------------------------------------------------------------
 * @file
 *
 * Copyright 2001 by the University of Toronto (UT).
 *
 *                       All Rights Reserved
 * 
 * Permission to copy and modify this software and its documentation 
 * only for internal use in your organization is hereby granted, 
 * provided that this notice is retained thereon and on all copies.  
 * UT makes no representations as to the suitability and operability 
 * of this software for any purpose.  It is provided "as is" without 
 * express or implied warranty.
 *
 * UT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
 * SHALL UT BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * No other rights, including for example, the right to redistribute 
 * this software and its documentation or the right to prepare 
 * derivative works, are granted unless specifically provided in a 
 * separate license agreement.
 *
 * Author: Diego Macrini (dmac@cs.toronto.edu)
 * 
 * $Log: VisualDAG.h,v $
 * Revision 1.2  2002/05/16 22:51:05  dmac
 * Several bugs fixed and a new DAG-derived class added
 *
 * Revision 1.1.1.1  2002/03/10 07:38:07  dmac
 * Imported sources
 *
 *
 *-----------------------------------------------------------------------*/

#ifndef _VISUAL_DAG_H_
#define _VISUAL_DAG_H_

#include <LEDA/graphics/window.h>
#include "DAG.h"
#include "ShockGraph.h"

namespace dml {

class SGMatchWnd 
{
public:
	struct Wnd : public leda_window
	{
		SGMatchWnd* m_pParent;

		static void OnDraw(leda_window* pWnd);
		static void OnShowCoord(leda_window* pBaseWnd, double x, double y);

		Wnd(int w, int h, const char* label, SGMatchWnd* pParent) : leda_window(w, h, label)
		{
			m_pParent = pParent;
			set_redraw(Wnd::OnDraw);
			set_show_coord_handler(Wnd::OnShowCoord);
		}
	};

	struct SGInfo
	{
		//const SGPtr pSG;
		/*const*/ ShockGraph* pSG;
		double delta_x;
		double delta_y;
		double reflex_y;

		// It clones p into pSG. i.e., it makes a copy of *p
		SGInfo(const ShockGraph* p, double dx, double dy, double ry) /*: pSG(*p)*/
		{
			pSG = new ShockGraph();
			*pSG = *p;
			
			// Let's steal the skeleton from p (yes, this IS nasty)
			pSG->SetSkeleton((BlumSkeleton*)p->GetSkeleton());
			((ShockGraph*)p)->SetSkeleton(NULL);

			delta_x = dx;
			delta_y = dy;
			reflex_y = ry;
		}
		~SGInfo() { delete pSG; }
	};

	friend struct Wnd;
	
protected:
	SGInfo*		m_pSGInfo1;
	SGInfo* 	m_pSGInfo2;
	DAGNodeMap	m_matchMap;
	Wnd*		m_pWnd;
	bool		m_bShowLabels;
	bool		m_bShowNodeType;
	int			m_nShowColorLines; //<! 0=all lines. 1, 2, ... only given color
	bool 		m_bShowCoords;

public:
	SGMatchWnd();
	~SGMatchWnd();
	bool Create(const ShockGraph* pSG1, const ShockGraph* pSG2, bool bAsyncMode = true);
	void DrawSG() const;
	void DrawMatchingLines() const;
	void SetMatchMap(const DAGNodeMap& matchMap);
	bool DrawSkeleton(const SGInfo* si) const;
	const SGInfo* GetSGInfo1() const { return m_pSGInfo1; }
	const SGInfo* GetSGInfo2() const { return m_pSGInfo2; }
};

void ShowGraph(DAG& g);

} // namespace dml

#endif //_VISUAL_DAG_H_
