
/*
 * Copyright (C) 2002 - 2007 Lehrstuhl Grafische Systeme, BTU Cottbus
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package de.grogra.c4d.model;

import de.grogra.c4d.BaseObject;
import de.grogra.xl.impl.base.Producer;
import de.grogra.xl.query.EdgeDirection;
import de.grogra.xl.query.QueryState;

public class C4DProducer extends Producer
{

	private final Graph graph;

	public C4DProducer (QueryState match)
	{
		super (match);
		graph = (Graph) match.getGraph ();
	}


	public BaseObject producer$getRoot ()
	{
		return (BaseObject) graph.getRoot ();
	}

	public C4DProducer operator$space (BaseObject node)
	{
		addNodeImpl (node, true);
		return this;
	}

	public C4DProducer producer$push ()
	{
		pushImpl ();
		return this;
	}

	public C4DProducer producer$separate ()
	{
		separateImpl ();
		return this;
	}

	public C4DProducer producer$begin ()
	{
		return this;
	}

	public void producer$end ()
	{
	}

	public C4DProducer producer$pop (Object oldProducer)
	{
		popImpl ();
		return this;
	}

	public C4DProducer operator$arrow (BaseObject node, int edge)
	{
		addEdgeImpl (getPreviousNode (), node, edge, EdgeDirection.FORWARD);
		addNodeImpl (node, false);
		return this;
	}

	public C4DProducer operator$leftArrow (BaseObject node, int edge)
	{
		addEdgeImpl (getPreviousNode (), node, edge, EdgeDirection.BACKWARD);
		addNodeImpl (node, false);
		return this;
	}

	public C4DProducer operator$sub (BaseObject node, int edge)
	{
		addEdgeImpl (getPreviousNode (), node, edge, EdgeDirection.UNDIRECTED);
		addNodeImpl (node, false);
		return this;
	}


	public C4DProducer operator$gt (BaseObject node, int edge)
	{
		addEdgeImpl (getPreviousNode (), node, RuntimeModel.SUCCESSOR_EDGE, EdgeDirection.FORWARD);
		addNodeImpl (node, false);
		return this;
	}

	public C4DProducer operator$lt (BaseObject node, int edge)
	{
		addEdgeImpl (getPreviousNode (), node, RuntimeModel.SUCCESSOR_EDGE, EdgeDirection.BACKWARD);
		addNodeImpl (node, false);
		return this;
	}

	public C4DProducer operator$plusArrow (BaseObject node)
	{
		addEdgeImpl (getPreviousNode (), node, RuntimeModel.BRANCH_EDGE, EdgeDirection.FORWARD);
		addNodeImpl (node, false);
		return this;
	}


	public C4DProducer operator$plusLeftArrow (BaseObject node)
	{
		addEdgeImpl (getPreviousNode (), node, RuntimeModel.BRANCH_EDGE, EdgeDirection.BACKWARD);
		addNodeImpl (node, false);
		return this;
	}


	public C4DProducer operator$and (BaseObject node)
	{
		addEdgeImpl (getPreviousNode (), node, RuntimeModel.SIBLING, EdgeDirection.FORWARD);
		addNodeImpl (node, false);
		return this;
	}

}
