/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.dcm30_04.baselibs;

import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataElement;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidItemException;
import cdac.medinfo.sdk.dcm30_04.exceptions.MandatoryMissingException;
import cdac.medinfo.sdk.dcm30_04.exceptions.ValidationException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;

/**
* This item class contains the methods to set, get and validate the attribute present in Isocenter Reference System Sequence .
 */

public class IsocenterReferenceSystemSequenceItem extends Item
{

	private static final long serialVersionUID = 1L;

	/**
	 * This constructor creates the item with default TransferSyntax 
	 */
	IsocenterReferenceSystemSequenceItem()
	{
		super();
	}

	/*
	 * This constructor calls the respective superclass constructor
	 * This constructor should throw exception if null TS is tried to be set
	 */
	/**
	 * This constructor creates the item with specified TransferSyntax 
	 * and default DictionaryReader
	 * @param objITransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 */
	IsocenterReferenceSystemSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

	/**
	 * This constructor creates IsocenterReferenceSystemSequenceItem with specified TransferSyntax and
	 * specified DictionaryReader.
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax.
	 * @param objDictionaryReader specifies the DICOM Dictionary reader to be used.
	 */
	IsocenterReferenceSystemSequenceItem(ITransferSyntax objTransferSyntax, IDictionaryReader objDictionaryReader)
	{
		super(objTransferSyntax,objDictionaryReader);
	}

	/*
	 * (non-Javadoc) This method validates the contents of the Item
	 * @see cdac.medinfo.sdk.dcm30_04.commoninterface.IItem#validate()
	 */
	/**
	 * Validates all the attributes in IsocenterReferenceSystemSequenceItem that are present in the DataSet
	 * @return boolean - Success -true, Failure - false
	 * @throws InvalidItemException throws InvalidItemException If Mandatory or Conditional element fails.
	 */
	public boolean validateForModule()  throws InvalidItemException
	{
		try{
			if(!contains(0x0018,0x9463))
				throw new MandatoryMissingException("0018,9463");
			if(!contains(0x0018,0x9464))
				throw new MandatoryMissingException("0018,9464");
			if(!contains(0x0018,0x9465))
				throw new MandatoryMissingException("0018,9465");
			if(!contains(0x0018,0x9466))
				throw new MandatoryMissingException("0018,9466");
			if(!contains(0x0018,0x9467))
				throw new MandatoryMissingException("0018,9467");
			if(!contains(0x0018,0x9468))
				throw new MandatoryMissingException("0018,9468");
			if(!contains(0x0018,0x9469))
				throw new MandatoryMissingException("0018,9469");
			if(!contains(0x0018,0x9470))
				throw new MandatoryMissingException("0018,9470");
			if(!contains(0x0018,0x9471))
				throw new MandatoryMissingException("0018,9471");
		}
		catch(MandatoryMissingException me)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(me.getMessage());
			}
			throw new ValidationException(this.getClass().getSimpleName(),me);
		}
		return true;
	}
	
	/**
	 * Sets Positioner Isocenter Primary Angle.
	 * Position of the X-Ray center beam in the isocenter reference system in the X direction (deg).
	 * @param fPositionerIsocenterPrimaryAngle Float value of Positioner Isocenter Primary Angle
	 */
	public void setPositionerIsocenterPrimaryAngle( float fPositionerIsocenterPrimaryAngle)
	{
		/*
		 * Accept the Positioner Isocenter Primary Angle in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9463, fPositionerIsocenterPrimaryAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9463,DicomConstants.DCM_DT_FL, fPositionerIsocenterPrimaryAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Positioner Isocenter Primary Angle.
	 * Position of the X-Ray center beam in the isocenter reference system in the X direction (deg).
	 * @return float - Float value of Positioner Isocenter Primary Angle
	 */
	public float getPositionerIsocenterPrimaryAngle()
	{
		Object objValue = getValue(0x0018,0x9463);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Positioner Isocenter Secondary Angle.
	 * Position of the X-Ray center beam in the isocenter reference system in the Z direction (deg).
	 * @param fPositionerIsocenterSecondaryAngle Float value of Positioner Isocenter Secondary Angle
	 */
	public void setPositionerIsocenterSecondaryAngle( float fPositionerIsocenterSecondaryAngle)
	{
		/*
		 * Accept the Positioner Isocenter Secondary Angle in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9464, fPositionerIsocenterSecondaryAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9464,DicomConstants.DCM_DT_FL, fPositionerIsocenterSecondaryAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Positioner Isocenter Secondary Angle.
	 * Position of the X-Ray center beam in the isocenter reference system in the Z direction (deg).
	 * @return float - Float value of Positioner Isocenter Secondary Angle
	 */
	public float getPositionerIsocenterSecondaryAngle()
	{
		Object objValue = getValue(0x0018,0x9464);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Positioner Isocenter Detector Rotation Angle.
	 * Rotation of the X-Ray detector plane (deg).
	 * @param fPositionerIsocenterDetectorRotationAngle Float value of Positioner Isocenter Detector Rotation Angle
	 */
	public void setPositionerIsocenterDetectorRotationAngle( float fPositionerIsocenterDetectorRotationAngle)
	{
		/*
		 * Accept the Positioner Isocenter Detector Rotation Angle in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9465, fPositionerIsocenterDetectorRotationAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9465,DicomConstants.DCM_DT_FL, fPositionerIsocenterDetectorRotationAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Positioner Isocenter Detector Rotation Angle.
	 * Rotation of the X-Ray detector plane (deg).
	 * @return float - Float value of Positioner Isocenter Detector Rotation Angle
	 */
	public float getPositionerIsocenterDetectorRotationAngle()
	{
		Object objValue = getValue(0x0018,0x9465);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Table X Position to Isocenter.
	 * X position of the Table Reference Point with respect to the Isocenter (mm).
	 * @param fTableXPositiontoIsocenter Float value of Table X Position to Isocenter
	 */
	public void setTableXPositiontoIsocenter( float fTableXPositiontoIsocenter)
	{
		/*
		 * Accept the Table X Position to Isocenter in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9466, fTableXPositiontoIsocenter,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9466,DicomConstants.DCM_DT_FL, fTableXPositiontoIsocenter);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Table X Position to Isocenter.
	 * X position of the Table Reference Point with respect to the Isocenter (mm).
	 * @return float - Float value of Table X Position to Isocenter
	 */
	public float getTableXPositiontoIsocenter()
	{
		Object objValue = getValue(0x0018,0x9466);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Table Y Position to Isocenter.
	 * Y position of the Table Reference Point with respect to the Isocenter (mm).
	 * @param fTableYPositiontoIsocenter Float value of Table Y Position to Isocenter
	 */
	public void setTableYPositiontoIsocenter( float fTableYPositiontoIsocenter)
	{
		/*
		 * Accept the Table Y Position to Isocenter in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9467, fTableYPositiontoIsocenter,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9467,DicomConstants.DCM_DT_FL, fTableYPositiontoIsocenter);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Table Y Position to Isocenter.
	 * Y position of the Table Reference Point with respect to the Isocenter (mm).
	 * @return float - Float value of Table Y Position to Isocenter
	 */
	public float getTableYPositiontoIsocenter()
	{
		Object objValue = getValue(0x0018,0x9467);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Table Z Position to Isocenter.
	 * Z position of the Table Reference Point with respect to the Isocenter (mm).
	 * @param fTableZPositiontoIsocenter Float value of Table Z Position to Isocenter
	 */
	public void setTableZPositiontoIsocenter( float fTableZPositiontoIsocenter)
	{
		/*
		 * Accept the Table Z Position to Isocenter in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9468, fTableZPositiontoIsocenter,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9468,DicomConstants.DCM_DT_FL, fTableZPositiontoIsocenter);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Table Z Position to Isocenter.
	 * Z position of the Table Reference Point with respect to the Isocenter (mm).
	 * @return float - Float value of Table Z Position to Isocenter
	 */
	public float getTableZPositiontoIsocenter()
	{
		Object objValue = getValue(0x0018,0x9468);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Table Horizontal Rotation Angle.
	 * Rotation of the table in the horizontal plane.
	 * @param fTableHorizontalRotationAngle Float value of Table Horizontal Rotation Angle
	 */
	public void setTableHorizontalRotationAngle( float fTableHorizontalRotationAngle)
	{
		/*
		 * Accept the Table Horizontal Rotation Angle in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9469, fTableHorizontalRotationAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9469,DicomConstants.DCM_DT_FL, fTableHorizontalRotationAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Table Horizontal Rotation Angle.
	 * Rotation of the table in the horizontal plane.
	 * @return float - Float value of Table Horizontal Rotation Angle
	 */
	public float getTableHorizontalRotationAngle()
	{
		Object objValue = getValue(0x0018,0x9469);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Table Head Tilt Angle.
	 * Angle of the head-feet axis of the table in degrees relative to the horizontal plane.
	 * @param fTableHeadTiltAngle Float value of Table Head Tilt Angle
	 */
	public void setTableHeadTiltAngle( float fTableHeadTiltAngle)
	{
		/*
		 * Accept the Table Head Tilt Angle in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9470, fTableHeadTiltAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9470,DicomConstants.DCM_DT_FL, fTableHeadTiltAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Table Head Tilt Angle.
	 * Angle of the head-feet axis of the table in degrees relative to the horizontal plane.
	 * @return float - Float value of Table Head Tilt Angle
	 */
	public float getTableHeadTiltAngle()
	{
		Object objValue = getValue(0x0018,0x9470);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Table Cradle Tilt Angle.
	 * Angle of the left-right axis of the table in degrees relative to the horizontal plane.
	 * @param fTableCradleTiltAngle Float value of Table Cradle Tilt Angle
	 */
	public void setTableCradleTiltAngle( float fTableCradleTiltAngle)
	{
		/*
		 * Accept the Table Cradle Tilt Angle in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0018,0x9471, fTableCradleTiltAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x9471,DicomConstants.DCM_DT_FL, fTableCradleTiltAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Table Cradle Tilt Angle.
	 * Angle of the left-right axis of the table in degrees relative to the horizontal plane.
	 * @return float - Float value of Table Cradle Tilt Angle
	 */
	public float getTableCradleTiltAngle()
	{
		Object objValue = getValue(0x0018,0x9471);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
}
