//*****************************************************************************************
// Truevision - a 3d modeler for gnome and povray
//
// obj3dcsg.h
//
// Vincent LE PRINCE <vincentleprince@users.sourceforge.net>
// Copyright (C) 2000-2001 Vincent LE PRINCE
// This file is part of the TRUEVISION Package

//   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 2 of the License, or
//   (at your option) 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
//*******************************************************************************************
#ifndef TV_OBJ3DCSG_H
#define TV_OBJ3DCSG_H
using namespace std;
#include "object3d.h"
#include <vector>


// Définition
class ObjCSG : public Object3D_with_material {
	protected:
		ObjParam_point *translation;
		ObjParam_scale *size;
		ObjParam_rotation *rotation;
		TvWidget_bool *node_expanded;
		ObjParam_bool *evaluate;
		vector<Object3D*> children;

	public:
		ObjCSG( app_objs *appref );
		ObjCSG( ObjCSG & ref );
		~ObjCSG();

		virtual void display( glview *view );
		void edit_widget( GtkWidget *wid );
		void destroy_editor();
		void pref_changed();
		virtual void add_to_tree( GtkWidget *tree, GtkCTreeNode *parent, GtkCTreeNode *sibling, const gchar *pixmap = NULL );
		virtual void save_tree();
		void set_layer( ObjectLayer *lay );

		void mouse_drag( struct drag_info *drag );
		float *get_location() { return translation->get(); }
		Rotation *get_rotation() { return rotation->get_rotation(); }

		void add_object( Object3D *obj );
		virtual bool is_group() { return true; }
		virtual void paste_object( Object3D *obj );	
		virtual void remove_object( Object3D *obj );
		virtual void duplicate_object( Object3D *obj );	
		virtual void move_child_up( Object3D *obj );
		virtual void move_child_down( Object3D *obj );
		virtual int get_child_pos( Object3D *obj ) { unsigned int i; for ( i = 0 ; i < children.size() ; i++ ) if ( children[i] == obj ) break; return i; }
		virtual void insert_child( Object3D *obj, int position );
		virtual bool has_as_ancester( Object3D *obj );
		
		void save_children( ofstream & file );
		void load_children( ifstream & file );
		void get_materials( vector<Material*> & mlist ) { for ( unsigned int i = 0 ; i <  children.size() ; i ++ ) children[i]->get_materials( mlist ); }
};


class CsgUnion : public ObjCSG {
	public:
		CsgUnion( app_objs *appref );
		CsgUnion *duplicate_yourself() { CsgUnion *res = new CsgUnion( *this ); return res; }		
		void add_to_tree( GtkWidget *tree, GtkCTreeNode *node, GtkCTreeNode *sibling, const gchar *pix ) { ObjCSG::add_to_tree( tree, node, sibling, "truevision/object_union.xpm" ); }
		void output_to_povray( ofstream & file );
		void save( ofstream & file );
		bool load( ifstream & file, char *tag );
};

class CsgDifference : public ObjCSG {
	private:
		void draw_a( glview *view );
		void draw_b( glview *view );

	public:
		CsgDifference( app_objs *appref );
		CsgDifference *duplicate_yourself() { CsgDifference *res = new CsgDifference( *this ); return res; }		
		void add_to_tree( GtkWidget *tree, GtkCTreeNode *node, GtkCTreeNode *sibling, const gchar *pix ) { ObjCSG::add_to_tree( tree, node, sibling, "truevision/object_diff.xpm" ); }
		void output_to_povray( ofstream & file );
		void save( ofstream & file );
		bool load( ifstream & file, char *tag );
		virtual void display( glview *view );
};

class CsgMerge : public ObjCSG {
	public:
		CsgMerge( app_objs *appref );
		CsgMerge *duplicate_yourself() { CsgMerge *res = new CsgMerge( *this ); return res; }		
		void add_to_tree( GtkWidget *tree, GtkCTreeNode *node, GtkCTreeNode *sibling, const gchar *pix ) { ObjCSG::add_to_tree( tree, node, sibling, "truevision/object_merge.xpm" ); }
		void output_to_povray( ofstream & file )	;
		void save( ofstream & file );
		bool load( ifstream & file, char *tag );
};

class CsgIntersection : public ObjCSG {
	private:
		void draw_a( glview *view );
		void draw_b( glview *view );

	public:
		CsgIntersection( app_objs *appref );
		CsgIntersection *duplicate_yourself() { CsgIntersection *res = new CsgIntersection( *this ); return res; }		
		void add_to_tree( GtkWidget *tree, GtkCTreeNode *node, GtkCTreeNode *sibling, const gchar *pix ) { ObjCSG::add_to_tree( tree, node, sibling, "truevision/object_inter.xpm" ); }
		void output_to_povray( ofstream & file );
		void save( ofstream & file );
		bool load( ifstream & file, char *tag );
		virtual void display( glview *view );
};

#endif
