/*----- PROTECTED REGION ID(PespCCDStage.h) ENABLED START -----*/
//=============================================================================
//
// file :        PespCCDStage.h
//
// description : Include file for the PespCCDStage class
//
// project :     PespCCDStage
//
// This file is part of Tango device class.
// 
// Tango 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
// (at your option) any later version.
// 
// Tango 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 Tango.  If not, see <http://www.gnu.org/licenses/>.
// 
// $Author: abrami $
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#ifndef PespCCDStage_H
#define PespCCDStage_H

#include <tango.h>
#include <itpp/itbase.h>
#include <itpp/itcomm.h>
#include <math.h>




#include "PespStage.h"

#define PI 3.14159265

typedef struct {
	string dev;
	string move_attr;
	string move_dflt;  // default value when dev in not configured
	double move_dflt_value;
	string stop_cmd;
        bool configured;
        Tango::DeviceProxy *dp;
	Tango::DevState state;
        long tmo;
	double m;	// value = m * reading + q
	double q;
} mover_t;


#include "Stage2Filter.h"


/*----- PROTECTED REGION END -----*/	//	PespCCDStage.h

/**
 *  PespCCDStage class description:
 *    
 */

namespace PespCCDStage_ns
{
/*----- PROTECTED REGION ID(PespCCDStage::Additional Class Declarations) ENABLED START -----*/

//	Additional Class Declarations

/*----- PROTECTED REGION END -----*/	//	PespCCDStage::Additional Class Declarations

class PespCCDStage : public TANGO_BASE_CLASS
{

/*----- PROTECTED REGION ID(PespCCDStage::Data Members) ENABLED START -----*/

//	Add your own data members
private:
	PespStage_ns::Stage2Filter* p_stage2flt;
public:
	mover_t ccdstageN;
	mover_t ccdstageL;
	mover_t gridX;
	mover_t gridZ;
	mover_t gridpic;

	itpp::vec chamber; //chamber
	double pitch;
	itpp::vec ccd; //ccd
	itpp::mat rot;
	itpp::vec q; //ccd origin in x,z
	itpp::vec p; //yag center in x,z
	itpp::vec br; //yag center in b,r
	itpp::vec offset; //yag offset in n,l
	itpp::vec r; //retta per centro yag e centro specchio/chamber in x,z
	itpp::mat mr;
	itpp::vec qr;

	PespStage_ns::PespStage *pstage;


	bool first_write_YagSelector;
	bool first_write_BeamOnYagDisplacement;

	bool attr_UpdateOnSelector;

/*----- PROTECTED REGION END -----*/	//	PespCCDStage::Data Members

//	Device property data members
public:
	//	OriginNL:	Coordinate di Q in XZ: x,z
	vector<Tango::DevDouble>	originNL;
	//	YagCenterNL:	Centro Yag in coord. NL
	vector<Tango::DevDouble>	yagCenterNL;
	//	RotationXN:	Angolo (radianti) da N+ a X+
	Tango::DevDouble	rotationXN;
	//	GridChamber:	Device proxy
	//  AttributoX
	//  DefaultX
	//  Device proxy
	//  AttributoZ
	//  DefaultZ
	//  
	//  Coordinata X portareticolo o da device o da default:
	//  device, default
	vector<string>	gridChamber;
	//	GridPitch:	Device proxy
	//  AttributoX
	//  DefaultX
	//  Valore pitch
	vector<string>	gridPitch;
	//	CCDStageAxis:	device proxy
	//  Attributo N
	//  device proxy
	//  Attributo L
	vector<string>	cCDStageAxis;
	//	StageType:	Presto
	//  Tardi
	string	stageType;
	//	YagsCenterOffsets:	Offsets (d) Yag da centro di rotazione tavola lungo retta RQ`
	vector<Tango::DevDouble>	yagsCenterOffsets;
	//	RotationCenterXZ:	Centro di rotazione (del naso) in coord. xOz
	vector<Tango::DevDouble>	rotationCenterXZ;
	//	FilterRpDistance:	Distance between filter axis and rotation point Rp (near ccd)
	Tango::DevDouble	filterRpDistance;

	bool	mandatoryNotDefined;

//	Attribute data members
public:
	Tango::DevString	*attr_StageType_read;
	Tango::DevDouble	*attr_FocusX_read;
	Tango::DevDouble	*attr_FocusZ_read;
	Tango::DevDouble	*attr_FocusDistance_read;
	Tango::DevDouble	*attr_FocusAngle_read;
	Tango::DevDouble	*attr_Pitch_read;
	Tango::DevDouble	*attr_BeamOnYagDisplacement_read;
	Tango::DevBoolean	*attr_UpdateOnDisplacement_read;
	Tango::DevBoolean	*attr_FilterTrackEnable_read;

//	Constructors and destructors
public:
	/**
	 * Constructs a newly device object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	PespCCDStage(Tango::DeviceClass *cl,string &s);
	/**
	 * Constructs a newly device object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	PespCCDStage(Tango::DeviceClass *cl,const char *s);
	/**
	 * Constructs a newly device object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device name
	 *	@param d	Device description.
	 */
	PespCCDStage(Tango::DeviceClass *cl,const char *s,const char *d);
	/**
	 * The device object destructor.
	 */
	~PespCCDStage() {delete_device();};


//	Miscellaneous methods
public:
	/*
	 *	will be called at device destruction or at init command.
	 */
	void delete_device();
	/*
	 *	Initialize the device
	 */
	virtual void init_device();
	/*
	 *	Read the device properties from database
	 */
	void get_device_property();
	/*
	 *	Always executed method before execution command method.
	 */
	virtual void always_executed_hook();

	/*
	 *	Check if mandatory property has been set
	 */
	 void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop);

//	Attribute methods
public:
	//--------------------------------------------------------
	/*
	 *	Method      : PespCCDStage::read_attr_hardware()
	 *	Description : Hardware acquisition for attributes.
	 */
	//--------------------------------------------------------
	virtual void read_attr_hardware(vector<long> &attr_list);
	//--------------------------------------------------------
	/*
	 *	Method      : PespCCDStage::write_attr_hardware()
	 *	Description : Hardware writing for attributes.
	 */
	//--------------------------------------------------------
	virtual void write_attr_hardware(vector<long> &attr_list);

/**
 *	Attribute StageType related methods
 *	Description: 
 *
 *	Data type:	Tango::DevString
 *	Attr type:	Scalar
 */
	virtual void read_StageType(Tango::Attribute &attr);
	virtual bool is_StageType_allowed(Tango::AttReqType type);
/**
 *	Attribute FocusX related methods
 *	Description: 
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
	virtual void read_FocusX(Tango::Attribute &attr);
	virtual void write_FocusX(Tango::WAttribute &attr);
	virtual bool is_FocusX_allowed(Tango::AttReqType type);
/**
 *	Attribute FocusZ related methods
 *	Description: 
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
	virtual void read_FocusZ(Tango::Attribute &attr);
	virtual void write_FocusZ(Tango::WAttribute &attr);
	virtual bool is_FocusZ_allowed(Tango::AttReqType type);
/**
 *	Attribute FocusDistance related methods
 *	Description: 
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
	virtual void read_FocusDistance(Tango::Attribute &attr);
	virtual void write_FocusDistance(Tango::WAttribute &attr);
	virtual bool is_FocusDistance_allowed(Tango::AttReqType type);
/**
 *	Attribute FocusAngle related methods
 *	Description: 
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
	virtual void read_FocusAngle(Tango::Attribute &attr);
	virtual void write_FocusAngle(Tango::WAttribute &attr);
	virtual bool is_FocusAngle_allowed(Tango::AttReqType type);
/**
 *	Attribute Pitch related methods
 *	Description: 
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
	virtual void read_Pitch(Tango::Attribute &attr);
	virtual bool is_Pitch_allowed(Tango::AttReqType type);
/**
 *	Attribute BeamOnYagDisplacement related methods
 *	Description: 
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
	virtual void read_BeamOnYagDisplacement(Tango::Attribute &attr);
	virtual void write_BeamOnYagDisplacement(Tango::WAttribute &attr);
	virtual bool is_BeamOnYagDisplacement_allowed(Tango::AttReqType type);
/**
 *	Attribute UpdateOnDisplacement related methods
 *	Description: 
 *
 *	Data type:	Tango::DevBoolean
 *	Attr type:	Scalar
 */
	virtual void read_UpdateOnDisplacement(Tango::Attribute &attr);
	virtual void write_UpdateOnDisplacement(Tango::WAttribute &attr);
	virtual bool is_UpdateOnDisplacement_allowed(Tango::AttReqType type);
/**
 *	Attribute FilterTrackEnable related methods
 *	Description: 
 *
 *	Data type:	Tango::DevBoolean
 *	Attr type:	Scalar
 */
	virtual void read_FilterTrackEnable(Tango::Attribute &attr);
	virtual void write_FilterTrackEnable(Tango::WAttribute &attr);
	virtual bool is_FilterTrackEnable_allowed(Tango::AttReqType type);

//	Dynamic attribute methods
public:

	/**
	 *	Attribute YagSelector related methods
	 *	Description: 
	 *
	 *	Data type:	Tango::DevUShort
	 *	Attr type:	Scalar
	 */
	virtual void read_YagSelector(Tango::Attribute &attr);
	virtual void write_YagSelector(Tango::WAttribute &attr);
	virtual bool is_YagSelector_allowed(Tango::AttReqType type);
	void add_YagSelector_dynamic_attribute(string attname);
	void remove_YagSelector_dynamic_attribute(string attname);
	Tango::DevUShort *get_YagSelector_data_ptr(string &name);
	map<string,Tango::DevUShort>	   YagSelector_data;

	/**
	 *	Attribute UpdateOnSelector related methods
	 *	Description: 
	 *
	 *	Data type:	Tango::DevBoolean
	 *	Attr type:	Scalar
	 */
	virtual void read_UpdateOnSelector(Tango::Attribute &attr);
	virtual void write_UpdateOnSelector(Tango::WAttribute &attr);
	virtual bool is_UpdateOnSelector_allowed(Tango::AttReqType type);
	void add_UpdateOnSelector_dynamic_attribute(string attname);
	void remove_UpdateOnSelector_dynamic_attribute(string attname);
	Tango::DevBoolean *get_UpdateOnSelector_data_ptr(string &name);
	map<string,Tango::DevBoolean>	   UpdateOnSelector_data;

	//--------------------------------------------------------
	/**
	 *	Method      : PespCCDStage::add_dynamic_attributes()
	 *	Description : Add dynamic attributes if any.
	 */
	//--------------------------------------------------------
	void add_dynamic_attributes();




//	Command related methods
public:
	/**
	 *	Command SetAngleDistance related method
	 *	Description: 
	 *
	 *	@param argin 
	 *	@returns 
	 */
	virtual Tango::DevBoolean set_angle_distance(const Tango::DevVarDoubleArray *argin);
	virtual bool is_SetAngleDistance_allowed(const CORBA::Any &any);
	/**
	 *	Command Stop related method
	 *	Description: 
	 *
	 */
	virtual void stop();
	virtual bool is_Stop_allowed(const CORBA::Any &any);
	/**
	 *	Command GetInstrumentList related method
	 *	Description: Se ritorna ``zero`` stringhe, allora non c`e` nemmeno il corrispondente ``selector``
	 *
	 *	@returns 
	 */
	virtual Tango::DevVarStringArray *get_instrument_list();
	virtual bool is_GetInstrumentList_allowed(const CORBA::Any &any);


	//--------------------------------------------------------
	/**
	 *	Method      : PespCCDStage::add_dynamic_commands()
	 *	Description : Add dynamic commands if any.
	 */
	//--------------------------------------------------------
	void add_dynamic_commands();

/*----- PROTECTED REGION ID(PespCCDStage::Additional Method prototypes) ENABLED START -----*/

//	Additional Method prototypes
protected :	
	//
	
	void updateattributes();
	void updatestatus();

public:
	double filter_distance(); // filter distance from R


/*----- PROTECTED REGION END -----*/	//	PespCCDStage::Additional Method prototypes
};

/*----- PROTECTED REGION ID(PespCCDStage::Additional Classes Definitions) ENABLED START -----*/

//	Additional Classes Definitions

/*----- PROTECTED REGION END -----*/	//	PespCCDStage::Additional Classes Definitions

}	//	End of namespace

#endif   //	PespCCDStage_H