Performing Basic Print Management Example for C#

//Performing Basic Print Management Example
private void PerformBasicPM()
{
   LTDICPRNSCULib.LEADDicomPrintSCU objPrintSCU = new LTDICPRNSCULib.LEADDicomPrintSCU();
   objPrintSCU.Timeout = 60; // 60 seconds
   objPrintSCU.EnableMethodErrors = false;
   // Establish the Association short
   nRet = 0;
   nRet = objPrintSCU.Associate("10.0.2.20", 7104, "PrintSCP", "PrintSCU", (LTDICPRNSCULib.DicomClassEnum) ( (short)LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS + (short)LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS + (short)LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS + (short)LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS + (short)LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRESENTATION_LUT_SOP_CLASS + (short)LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRINT_JOB_SOP_CLASS + (short)LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRINTER_CONFIGURATION_RETRIEVAL_SOP_CLASS));
   if (nRet == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_ERROR_PRINTSCU_ASSOCIATE_RQ_REJECTED)
   {
      MessageBox.Show("Source = " + objPrintSCU.AssociateRejectSource + ", " + "Reason = " + objPrintSCU.AssociateRejectReason, "Association Request was Rejected");
      return;
   }
   else
   if (nRet != (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      MessageBox.Show("Error code: " + nRet, "Failed to Establish the Association");
      return;
   }
   // Abort the Association if none of the Basic Print Management Meta SOP Classes
   // is supported on the Association
   if (objPrintSCU.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS) == false & objPrintSCU.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS) == false)
   {
      objPrintSCU.AbortAssociation();
      return;
   }
   // Display some printer info
   //GetPrinterInfo objPrintSCU
   // Display some printer configuration info
   //GetPrinterConfigInfo objPrintSCU
   // Create a Film Session
   objPrintSCU.FilmSession.IncludedParameters = 0;
   objPrintSCU.FilmSession.Create(false);
   MessageBox.Show(objPrintSCU.FilmSession.SOPInstanceUID, "Film Session SOP Instance UID");
   // Update the Number of Copies and Print Priority of the Film Session
   objPrintSCU.FilmSession.IncludedParameters = (LTDICPRNSCULib.FilmSessionParameterEnum)((short)LTDICPRNSCULib.FilmSessionParameterEnum.FS_NUMBER_OF_COPIES + (short)LTDICPRNSCULib.FilmSessionParameterEnum.FS_PRINT_PRIORITY);
   objPrintSCU.FilmSession.NumberOfCopies = 1;
   objPrintSCU.FilmSession.PrintPriority = "MED";
   objPrintSCU.FilmSession.Update();
   objPrintSCU.FilmBox.IncludedParameters = 0;
   if (objPrintSCU.FilmBox.MainObject.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS))
   {
      objPrintSCU.FilmBox.IncludedParameters = (LTDICPRNSCULib.FilmBoxParameterEnum)((short)objPrintSCU.FilmBox.IncludedParameters + (short)LTDICPRNSCULib.FilmBoxParameterEnum.FB_ANNOTATION_DISPLAY_FORMAT_ID);
      objPrintSCU.FilmBox.AnnotationDisplayFormatID = "SomeID";
   }
   // Create a Film Box
   objPrintSCU.FilmBox.Create("STANDARD\\1,1");
   MessageBox.Show(objPrintSCU.FilmBox.SOPInstanceUID, "Film Box SOP Instance UID");
   string sPresLUTInstanceUID = null;
   // Create a Presentation LUT
   if (objPrintSCU.PresentationLUT.MainObject.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRESENTATION_LUT_SOP_CLASS))
   {
      if (objPrintSCU.PresentationLUT.Create("C:\\PresLUT.dic","IDENTITY") == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
      {
         sPresLUTInstanceUID = objPrintSCU.PresentationLUT.GetSOPInstanceUID();
         MessageBox.Show(sPresLUTInstanceUID, "Pres LUT SOP Instance UID");
      }
   }
   if (sPresLUTInstanceUID.Length!= 0)
   {
      // Update the Film Box to reference the Presentation LUT we just created
      objPrintSCU.FilmBox.IncludedParameters = LTDICPRNSCULib.FilmBoxParameterEnum.FB_REF_PRES_LUT_INSTANCE_UID;
      objPrintSCU.FilmBox.RefPresLUTInstanceUID = sPresLUTInstanceUID;
      objPrintSCU.FilmBox.Update();
   }
   string sOverlayBoxInstanceUID = null;
   // Create an Image Overlay Box
   if (objPrintSCU.ImageOverlayBox.MainObject.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS))
   {
      objPrintSCU.ImageOverlayBox.OverlayOriginRow = 1;
      objPrintSCU.ImageOverlayBox.OverlayOriginColumn = 1;
      objPrintSCU.ImageOverlayBox.IncludedParameters = 0;
      if (objPrintSCU.ImageOverlayBox.Create("C:\\Overlay.dic") == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
      {
         sOverlayBoxInstanceUID = objPrintSCU.ImageOverlayBox.GetSOPInstanceUID();
         MessageBox.Show(sOverlayBoxInstanceUID, "Image Overlay Box SOP Instance UID");
      }
   }
   // Update the Image Box. Since the Image Display Format of the Film Box was
   // set to "STANDARD\1,1", then we are supposed to have one Image Box created
   // by the Print SCP.
   if (objPrintSCU.ImageBoxes.Count != 0)
   {
      MessageBox.Show(objPrintSCU.ImageBoxes.Item(0).SOPInstanceUID, "Image Box SOP Instance UID");
      objPrintSCU.ImageBoxes.Item(0).IncludedParameters = 0;
      if (sOverlayBoxInstanceUID.Length != 0)
      {
         objPrintSCU.ImageBoxes.Item(0).IncludedParameters = (LTDICPRNSCULib.ImageBoxParameterEnum)((short)objPrintSCU.ImageBoxes.Item(0).IncludedParameters + (short)LTDICPRNSCULib.ImageBoxParameterEnum.IB_REF_IMAGE_OVERLAY_BOX_INSTANCE_UID);
         objPrintSCU.ImageBoxes.Item(0).RefImageOverlayBoxInstanceUID = sOverlayBoxInstanceUID;
      }
      objPrintSCU.ImageBoxes.Item(0).Update("C:\\Image.dic");
   }
   // Update the Annotation Boxes (if there are any)
   foreach (LTDICPRNSCULib.LAnnotationBox AnnBox in objPrintSCU.AnnotationBoxes)
   {
      AnnBox.TextString = "Some Text";
      AnnBox.Update(true);
   }
   // Change the Overlay Origin of the Image Overlay Box referenced by the
   // Image Box
   if (sOverlayBoxInstanceUID.Length != 0 )
   {
      objPrintSCU.ImageOverlayBox.IncludedParameters = LTDICPRNSCULib.OverlayBoxParameterEnum.OB_OVERLAY_ORIGIN;
      objPrintSCU.ImageOverlayBox.OverlayOriginRow = 10;
      objPrintSCU.ImageOverlayBox.OverlayOriginColumn = 10;
      objPrintSCU.ImageOverlayBox.Update(sOverlayBoxInstanceUID, null);
   }
   string sPrintJobInstanceUID = null;
   // Print the Film Session (or the Film Box; there is no difference since we
   // have a single Film Box in the Film Session)
   if (true)
   {
      objPrintSCU.FilmSession.PrintSession();
      sPrintJobInstanceUID = objPrintSCU.FilmSession.PrintJobSOPInstanceUID;
   }
   else
   {
      objPrintSCU.FilmBox.PrintBox();
      sPrintJobInstanceUID = objPrintSCU.FilmBox.PrintJobSOPInstanceUID;
   }
   // Display some info about the Print Job
   if (objPrintSCU.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRINT_JOB_SOP_CLASS))
   {
      //GetPrintJobInfo objPrintSCU, sPrintJobInstanceUID
   }
   // Delete the Film Box (anyway, it would be deleted when the Film Session
   // is deleted)
   objPrintSCU.FilmBox.Delete();
   // Delete the Film Session
   objPrintSCU.FilmSession.Delete();
   // Delete the Presentation LUT
   if (sPresLUTInstanceUID.Length != 0 )
      objPrintSCU.PresentationLUT.Delete(sPresLUTInstanceUID);
   // Delete the Image Overlay Box
   if (sOverlayBoxInstanceUID.Length != 0)
      objPrintSCU.ImageOverlayBox.Delete(sOverlayBoxInstanceUID);
   // Release the Association and close the connection
   objPrintSCU.ReleaseAssociation();
}