/*******************************************************************************
 *  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.services.print.printsinkimpl;

import cdac.medinfo.sdk.dcm30_04.baselibs.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.OverlayPixelDataSequence;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.enums.EnumOverlayBackgroundDensity;
import cdac.medinfo.sdk.dcm30_04.enums.EnumOverlayForegroundDensity;
import cdac.medinfo.sdk.dcm30_04.enums.EnumOverlayMagnificationType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumOverlayOrImageMagnification;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;

/**
 *  This class contains the Attributes required for Query Model. Also contains methods to populate and fill dataset of Query Model.
 */
public class NCreatePrintImageOverlayBoxAttribute extends Attributes
{
	
	/**
	 * This is default Constructor for NCreatePrintImageOverlayBoxAttribute.
	 */
	public NCreatePrintImageOverlayBoxAttribute() {
		super();
	}
	
	/**
	 * Retrieves pre-initialized object of Overlay Pixel Data Sequence.If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence
	 * 
	 * @return OverlayPixelDataSequence - instance of Overlay Pixel Data Sequence.
	 */
	public OverlayPixelDataSequence getOverlayPixelDataSequence()
	{
		OverlayPixelDataSequence objOverlayPixelDataSequence = (OverlayPixelDataSequence)getDicomValue(0x2040,0x0020);
		if(objOverlayPixelDataSequence == null)
		{
			/*
			 * If the sequence object is not present in the DataSet, a new sequence object is created and
			 * the TransferSyntax and DictionaryReader is set into it as it is set in the Module. This ensures that 
			 * the DataElements getting added in the DataSet follow the same TransferSyntax and use the same
			 * DictionaryReader object as that of the module.
			 */
			ITransferSyntax objITransferSyntax = getDataSet().getTransferSyntax();
			IDictionaryReader objIDictionaryReader = getDataSet().getDictionaryReader();
			
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objOverlayPixelDataSequence = (OverlayPixelDataSequence)objDicomV3Factory.createSequence(0x2040,0x0020, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x2040,0x0020, DicomConstants.DCM_DT_SQ, objOverlayPixelDataSequence.getValue());
		}
		return objOverlayPixelDataSequence;
	}
	
	/**
	 * Sets magnification of the overlay or image before they are superimposed.
	 * Enumerated Values:
	 * IMAGE = Image is to be magnified
	 * OVERLAY = Overlay is to be magnified.
	 * 
	 * @param enumOverlayOrImageMagnification Enum value of Overlay or Image Magnification.
	 */
	public void setOverlayOrImageMagnification(EnumOverlayOrImageMagnification enumOverlayOrImageMagnification)
	{
		/* Accept Overlay or Image Magnification in String format of type CS.
		 * 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 Hash Map
		 */
		addDataElement(0x2040,0x0072, DicomConstants.DCM_DT_CS, enumOverlayOrImageMagnification.getValue());
	}

	/**
	 * Retrives magnification of the overlay or image before they are superimposed.
	 * 
	 * @return String - String value of Overlay Or Image Magnification.
	 */
	public String getOverlayOrImageMagnification()
	{
		Object objValue = getValue(0x2040,0x0072);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets the number of columns of the overlay or image after magnification.
	 * 
	 * @param shMagnifyToNumberOfColumns short value of Magnify To Number Of Columns.
	 */
	public void setMagnifyToNumberOfColumns(short shMagnifyToNumberOfColumns)
	{
		/* Accept Magnify to Number of Columns in short format of type US.
		 * 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 Hash Map
		 */
		addDataElement(0x2040,0x0074, DicomConstants.DCM_DT_US, shMagnifyToNumberOfColumns);
	}

	/**
	 * Retrives number of columns of the overlay or image after magnification.
	 * 
	 * @return short - short value of Magnify To Number Of Columns.
	 */
	public short getMagnifyToNumberOfColumns()
	{
		Object objValue = getValue(0x2040,0x0074);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * Sets the density for pixels which correspond with overlay bit = 1. The density of the other pixels remain unchanged.
	 * Defined Terms:
	 * BLACK
	 * WHITE
	 * 
	 * @param enumOverlayForegroundDensity Enum value of Overlay Foreground Density.
	 */
	public void setOverlayForegroundDensity(EnumOverlayForegroundDensity enumOverlayForegroundDensity)
	{
		/* Accept Overlay Foreground Density in String format of type CS.
		 * 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 Hash Map
		 */
		addDataElement(0x2040,0x0080, DicomConstants.DCM_DT_CS, enumOverlayForegroundDensity.getValue());
	}

	/**
	 * Retrives the density for pixels which correspond with overlay bit = 1.
	 * 
	 * @return String - String value of Overlay Foreground Density.
	 */
	public String getOverlayForegroundDensity()
	{
		Object objValue = getValue(0x2040,0x0080);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets tthe density for pixels which correspond with overlay bit = 0 that are not superimposed on the image
	 * and Combined Print Image pixels that are not part of the overlay or image
	 * Defined Terms:
	 * BLACK
	 * WHITE.
	 * 
	 * @param enumOverlayBackgroundDensity Enum value of Overlay Background Density.
	 */
	public void setOverlayBackgroundDensity(EnumOverlayBackgroundDensity enumOverlayBackgroundDensity)
	{
		/* Accept Overlay Background Density in String format of type CS.
		 * 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 Hash Map
		 */
		addDataElement(0x2040,0x0082, DicomConstants.DCM_DT_CS, enumOverlayBackgroundDensity.getValue());
	}

	/**
	 * Retrives Overlay Background Density.
	 * 
	 * @return String - String value of Overlay Background Density.
	 */
	public String getOverlayBackgroundDensity()
	{
		Object objValue = getValue(0x2040,0x0082);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets magnification type if the overlay is magnified before being superimposed on the image.
	 * Enumerated Values: REPLICATE,BILINEAR,CUBIC.
	 * 
	 * @param enumOverlayMagnificationType Enum value of Overlay Magnification Type.
	 */
	public void setOverlayMagnificationType(EnumOverlayMagnificationType enumOverlayMagnificationType)
	{
		/* Accept OverlayMagnificationType in String format of type CS.
		 * 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 Hash Map
		 */
		addDataElement(0x2040,0x0060, DicomConstants.DCM_DT_CS, enumOverlayMagnificationType.getValue());
	}

	/**
	 * Retrives Overlay Magnification Type.
	 * 
	 * @return String - String value of Overlay Magnification Type.
	 */
	public String getOverlayMagnificationType()
	{
		Object objValue = getValue(0x2040,0x0060);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets the type of interpolation function; only valid for Overlay Magnification Type 2010,0060 = CUBIC.
	 * 
	 * @param strOverlaySmoothingType the str overlay smoothing type
	 */
	public void setOverlaySmoothingType(String strOverlaySmoothingType)
	{
		/* Accept OverlaySmoothingType in String format of type CS.
		 * 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 Hash Map
		 */
		addDataElement(0x2040,0x0070, DicomConstants.DCM_DT_CS, strOverlaySmoothingType);
	}

	/**
	 * Retrives Overlay Smoothing Type.
	 * 
	 * @return String - String value of Overlay Smoothing Type.
	 */
	public String getOverlaySmoothingType()
	{
		Object objValue = getValue(0x2040,0x0070);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Populates the query Model using filled dataset.
	 */
	public void populate(IDataSet objIDataSet)
	{
		super.populate(objIDataSet);
	}	
	
	/**
	 * Fills the dataset using already populated Query Model.
	 */
	public void fill(IDataSet objIDataSet)
	{
		super.fill(objIDataSet);
	}
}
