/*******************************************************************************
 *  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.PresentationLUTSequence;
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.EnumPresentationLUTShape;
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 NCreatePresentationLUTAttribute extends Attributes 
{
	
	/**
	 * This is default Constructor for NCreatePresentationLUTAttribute.
	 */
	public NCreatePresentationLUTAttribute() {
		super();
	}
	
	/**
	 * Retrieves pre-initialized object of PresentationLUTSequence.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 PresentationLUTSequence - instance of PresentationLUTSequence.
	 */
	public PresentationLUTSequence getPresentationLUTSequence()
	{
		PresentationLUTSequence objPresentationLUTSequence = (PresentationLUTSequence)getDicomValue(0x2050,0x0010);
		if(objPresentationLUTSequence == 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();
			objPresentationLUTSequence = (PresentationLUTSequence)objDicomV3Factory.createSequence(0x2050,0x0010, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x2050,0x0010, DicomConstants.DCM_DT_SQ, objPresentationLUTSequence.getValue());
		}
		return objPresentationLUTSequence;
	}
	
	/**
	 * Sets a subset of a conceptual Presentation LUT.This Attribute defines an identity transformation or inverse
	 * identity transformation.
	 * Enumerated Values:
	 * IDENTITY - output is in P-Values - shall be
	 * used if Photometric Interpretation
	 * (0028,0004) is MONOCHROME2.
	 * INVERSE - output after inversion is in PValues
	 * - shall be used if Photometric
	 * Interpretation (0028,0004) is
	 * MONOCHROME1.
	 * 
	 * @param enumPresentationLUTShape the enum presentation lut shape
	 */
	public void setPresentationLUTShape(EnumPresentationLUTShape enumPresentationLUTShape)
	{
		/* Accept Presentation LUT Shape 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(0x2050,0x0020, DicomConstants.DCM_DT_CS, enumPresentationLUTShape.getValue());
	}

	/**
	 * Retrieves a subset of a conceptual Presentation LUT.
	 * 
	 * @return - String value of Presentation LUT Shape
	 */
	public String getPresentationLUTShape()
	{
		Object objectValue = getValue(0x2050,0x0020);
		if(objectValue!=null)
			return objectValue.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);
	}
}
