//
// Copyright (c) 2000 by Tech Soft 3D, LLC.
// The information contained herein is confidential and proprietary to
// Tech Soft 3D, LLC., and considered a trade secret as defined under
// civil and criminal statutes.  Tech Soft 3D shall pursue its civil
// and criminal remedies in the event of unauthorized use or misappropriation
// of its trade secrets.  Use of this information by anyone other than
// authorized employees of Tech Soft 3D, LLC. is granted only under a
// written non-disclosure agreement, expressly prescribing the scope and
// manner of such use.
//
// $Header: /files/homes/master/cvs/hoops_master/docs_hoops/Hoops3DGS/prog_guide/examples/HOpObjectClash.h,v 1.2 2006-08-07 20:39:02 stage Exp $
//

// HOpObjectClash.h : interface of the HOpObjectClash class
// translate items in the selection list of the associated view 
//
// currently supports translation of item if it is a segment

#ifndef _HOPOBJECTCLASH_H
#define _HOPOBJECTCLASH_H

#include "HTools.h"
#include "HBaseOperator.h"
#include "HOpObjectTranslate.h"

class HSelectionSet;

//! The HOpObjectClash class detects and highlights objects that intersect a translated object's bounding box. 
/*!
	HOpObjectClash employs the transform functionality of HOpObjectTranslate to move an object around a scene, and  
	extends two of the mouse event handlers defined on HOpObjectTranslate to perform clash detection. The operation 
	consists of the following steps:
    <ol>
    <li>Left Button Down:				operation initiated, translation object selected
    <li>Left Button Down and Drag:		object translated, highlighting clashed objects
    <li>Left Button Up:					operation ended, clashed objects deselected.
    </ol>
    More Detailed Description: see event methods
*/
class MVO_API HOpObjectClash : public HOpObjectTranslate
{
	/*! Selection can be computed in several different ways.  HOOC_Shell, the default,
	    looks for shells that intersect the faces of the current selection set in HBaseView.
	    HOOC_Screen, computes its selection in screen space, and looks for bounding box intersections.
	    HOOC_World is much the same as HOOC_Screen, but done in world space (prior the camera 
	    transformations).  HOOC_Shell is more accurate, HOOC_Screen/HOOC_World are faster.
	    <br>The modes are activated within OnKeyDown by the following keys.
	    <ol>
		<li>HOOC_World -- 'w' key
		<li>HOOC_Screen -- 'd' key (for 'driver')
		<li>HOOC_Shell -- 's' key
	    </ol>
	*/
	enum HOOC_SelectMode {
		HOOC_World,
		HOOC_Screen,
		HOOC_Shell
	};


protected:
	//!Loop through the selected object and all of the results from HOOPS Find_Related_Selection, and send them to the appropriate HSelectionSet.
	void ProcessSelectionResults();
	//!Get the screen space volume of the given segment, as seen by driver in m_pView
	int GetScreenVolume( HC_KEY seg, HPoint &min, HPoint &max );
	//!Select in screen space.  Selected items will be added to m_pView's selection list and highlighted as usual.
	int SelectByScreenVolume( HC_KEY seg );
	//!Select in world space.  Selected items will be added to m_pView's selection list and highlighted as usual.
	int SelectByWorldVolume( HC_KEY seg );
	/*!Select by shell.  Only shells are selectable in this mode.  After selection, the selection list will
	    contain all shells in the model that intersect the faces of the shells in the segment given by "seg". */
	int SelectByShell( HC_KEY seg );
	//!Sets the selection mode. */
	void SetSelectMode( int mode );
	//!Get the world space volume of the given segment.  Helper function to SelectByWorldVolume.
	int GetWorldVolume( HC_KEY seg, HPoint &min, HPoint &max );
	//!Prints profiling information for the preceeding selection computation.
	void PostSelectionProfile();
	//!"steals" the selection set from the HBaseView and replaces it with a new (empty) one.
	void GrabSelectionSet();
	//!restores the selection set back to the HBaseView
	void RestoreSelectionSet();

	//!the time taken by the last selection computation. HOOC_Shell mode only
	float m_selection_time;
	//!the longest time required for any selection since the last LButtonDown event.. HOOC_Shell mode only
	float m_longest_selection_time;
	//!number of bounding box comparisons during the last selection. HOOC_Shell mode only
	int m_bbox_comparisons;
	//!number of faces compared to each other during the last selection. HOOC_Shell mode only
	int m_face_comparisons;
	//!the number of non-trivial face comparisons.. HOOC_Shell mode only
	int m_extended_face_comparisons;
	//!the set of objects being dragged around
	HSelectionSet *m_pClashSelection;
	//!the method of computing selection.  See the HOOC_SelectMode enum.  set to HOOC_Shell by default.
	int m_SelectMode;
	//!the key to the segment into which the text overlay (with a transparent window) is put.
	HC_KEY m_TempSegKey;

public:
	//!The constructor of this method does something unusual, in that it 'hijacks' the HBaseView's HSelectionSet.  See the description of the m_pClashSelection and m_ReferenceCount variables.
	HOpObjectClash (HBaseView* view, int DoRepeat=0, int DoCapture=1);
	//!The destructor restores the HBaseViews HSelectionSet to its state before this operator was initialized.
	~HOpObjectClash();

	virtual const char * GetName();  

	int OnLButtonDown (HEventInfo &event);
	int OnLButtonDownAndMove(HEventInfo &event);
	int OnLButtonUp (HEventInfo &event);
	//! grabs a few hot keys, passes the rest to HBaseOperator (and from there to the trashcan, probably)
	int OnKeyDown (HEventInfo &event);

	HBaseOperator * Clone();

};


#endif
