Examining Annotations (1) example for C++ 5.0 and later

void ExamineAnnotations1(ILEADDicomDSPtr& spPresStateDS)
{
   char szMsg[1024];
   
   // Get the attributes that describe the "Presentation State Module"
   if (spPresStateDS->GetPresStateAttributes (0) == DICOM_SUCCESS)
   {
      IDicomPresStateAttributesPtr spPresStateAttribs = spPresStateDS->PresStateAttributes;

      // Display some
      wsprintf(szMsg,
               "Instance Number: %li\n"
               "Presentation Label: %s\n"
               "Presentation Description: %s\n"
               "Presentation Creator’s Name: %s\n",
               spPresStateAttribs->InstanceNumber,
               spPresStateAttribs->PresLabel.operator char *(),
               spPresStateAttribs->PresDescription.operator char *(),
               spPresStateAttribs->PresCreatorName.operator char *());

      MessageBox(NULL, szMsg, "Presentation State Attributes", MB_OK);
   }
   
   _bstr_t sUID;
   long lCount, i;
   
   // Display the SOP Instance UIDs of all the images referenced in the
   // "Presentation State Module"
   if (spPresStateDS->FindFirstPresStateRefSeriesItem () == DICOM_SUCCESS)
   {
      lstrcpy(szMsg, "");
      
      do
      {
         lCount = spPresStateDS->GetPresStateImageRefCount ();
         for (i = 0; i < lCount; i++)
         {
            sUID = spPresStateDS->GetPresStateImageRefInstanceUID (i);
            wsprintf(szMsg, "%s%s\n", szMsg, sUID.operator char *());
         }

         wsprintf(szMsg, "%s\n", szMsg);

      } while (spPresStateDS->MoveNextPresStateRefSeriesItem () == DICOM_SUCCESS);

      MessageBox(NULL, szMsg, "Referenced SOP Instance UID(s)", MB_OK);
   }
   
   // Enumerate all the layers defined
   lCount = spPresStateDS->LayerCount;
   wsprintf(szMsg, "Layer Count: %li", lCount);
   MessageBox(NULL, szMsg, "Graphic Layers", MB_OK);
   IDicomLayerAttributesPtr spLayerAttribs = spPresStateDS->LayerAttributes;
   for (i = 0; i < lCount; i++)
   {
      // Display some of the attributes
      if (spPresStateDS->GetLayerAttributes (i) == DICOM_SUCCESS)
      {
         wsprintf(szMsg,
                  "Graphic Layer: %s\n"
                  "Graphic Layer Order: %li\n"
                  "Graphic Layer Description: %s",
                  spLayerAttribs->LayerName.operator char *(),
                  spLayerAttribs->LayerOrder,
                  spLayerAttribs->LayerDescription.operator char *());

         MessageBox(NULL, szMsg, "Graphic Layer Attributes", MB_OK);
      }
   }
      
   long lGraphicObjectCount, lTextObjectCount;

   IDicomGraphicObjectAttributesPtr spGraphicObjAttribs;
   spGraphicObjAttribs = spPresStateDS->GraphicObjectAttributes;

   IDicomTextObjectAttributesPtr spTextObjAttribs;
   spTextObjAttribs = spPresStateDS->TextObjectAttributes;
   
   // Enumerate all the Graphic Annotation Items
   if (spPresStateDS->FindFirstGraphicAnnItem () == DICOM_SUCCESS)
   {
      do
      {
         lGraphicObjectCount = spPresStateDS->GetGraphicObjectCount ();
         // Or:
         //lGraphicObjectCount = spPresStateDS->GetLayerGraphicObjectCount ();
         
         lTextObjectCount = spPresStateDS->GetTextObjectCount ();
         // Or:
         //lTextObjectCount = spPresStateDS->GetLayerTextObjectCount ();

         wsprintf(szMsg,
                  "Graphic Layer: %s\n"
                  "Graphic object count: %li\n"
                  "Text object count: %li\n\n",
                  spPresStateDS->GetLayerName ().operator char *(),
                  lGraphicObjectCount,
                  lTextObjectCount);
                
         lCount = spPresStateDS->GetLayerImageRefCount ();
         if (lCount == 0)
         {
            wsprintf(szMsg,
                     "%sThe annotations defined in this Item apply to all the "
                     "images listed in the \"Presentation State Module\".",
                     szMsg);
         }
         else
         {
            wsprintf(szMsg, "%sReferenced SOP Instance UID(s):\n", szMsg);
            for (i = 0; i < lCount; i++)
            {
               sUID = spPresStateDS->GetLayerImageRefInstanceUID (i);
               wsprintf(szMsg, "%s   %s\n", szMsg, sUID.operator char *());
            }
         }

         MessageBox(NULL, szMsg, "Graphic Annotation Item", MB_OK);
         
         // Enumerate all the graphic objects in the current Item
         for (i = 0; i < lGraphicObjectCount; i++)
         {
            spPresStateDS->GetGraphicObjectAttributes (i);
            
            lstrcpy(szMsg, "Graphic Annotation Units: ");
            switch (spGraphicObjAttribs->GetUnits())
            {
            case DICOM_UNIT_PIXEL:
               lstrcat(szMsg, "PIXEL\n");
                  break;
            
            case DICOM_UNIT_DISPLAY:
               lstrcat(szMsg, "DISPLAY\n");
               break;
            }

            lstrcat(szMsg, "Graphic Type: ");
            switch (spGraphicObjAttribs->GetType())
            {
            case DICOM_GRAPHIC_OBJECT_TYPE_POINT:
               lstrcat(szMsg, "POINT\n");
               break;

            case DICOM_GRAPHIC_OBJECT_TYPE_POLYLINE:
               lstrcat(szMsg, "POLYLINE\n");
               break;

            case DICOM_GRAPHIC_OBJECT_TYPE_INTERPOLATED:
               lstrcat(szMsg, "INTERPOLATED\n");
               break;

            case DICOM_GRAPHIC_OBJECT_TYPE_CIRCLE:
               lstrcat(szMsg, "CIRCLE\n");
               break;

            case DICOM_GRAPHIC_OBJECT_TYPE_ELLIPSE:
               lstrcat(szMsg, "ELLIPSE\n");
               break;
            }

            if (spGraphicObjAttribs->Filled)
            {
               lstrcat(szMsg, "Graphic Filled: Y\n");
            }
            else
            {
               lstrcat(szMsg, "Graphic Filled: N\n");
            }
            
            lCount = spGraphicObjAttribs->PointCount;
            wsprintf(szMsg, "%sNumber of Graphic Points: %li\n", szMsg, lCount);
            
            if (lCount < 10)
            {
               lstrcat(szMsg, "Graphic Data: \n");
               for (long j = 0; j < lCount; j++)
               {
                  sprintf(szMsg, "%s   X%i, Y%i = %.2f, %.2f\n", szMsg,
                          j + 1, j + 1,
                          spGraphicObjAttribs->PointsX [j],
                          spGraphicObjAttribs->PointsY [j]);
               }
            }

            MessageBox(NULL, szMsg, "Graphic Annotation Object", MB_OK);
         }
         
         // Enumerate all the text objects in the current Item
         for (i = 0; i < lTextObjectCount; i++)
         {
            spPresStateDS->GetTextObjectAttributes (i);

            if (spTextObjAttribs->BoundingBoxUsed)
            {
               wsprintf(szMsg, "Unformatted Text Value: %s\n",
                        spTextObjAttribs->TextValue.operator char *());

               lstrcat(szMsg, "Bounding Box Annotation Units: ");
               switch(spTextObjAttribs->GetBoundingBoxUnits ())
               {
               case DICOM_UNIT_PIXEL:
                  lstrcat(szMsg, "PIXEL\n");
                  break;

               case DICOM_UNIT_DISPLAY:
                  lstrcat(szMsg, "DISPLAY\n");
                  break;
               }

               sprintf(szMsg, "%sBounding Box Top Left Hand Corner: %.2f, %.2f\n",
                       szMsg,
                       spTextObjAttribs->BoundingBoxTLHCornerX,
                       spTextObjAttribs->BoundingBoxTLHCornerY);
               
               sprintf(szMsg, "%sBounding Box Bottom Right Hand Corner: %.2f, %.2f\n",
                       szMsg,
                       spTextObjAttribs->BoundingBoxBRHCornerX,
                       spTextObjAttribs->BoundingBoxBRHCornerY);

               lstrcat(szMsg, "Bounding Box Text Horizontal Justification: ");
               switch (spTextObjAttribs->GetBoundingBoxTextJustification ())
               {
               case DICOM_TEXT_JUSTIFICATION_LEFT:
                  lstrcat(szMsg, "LEFT\n");
                  break;

               case DICOM_TEXT_JUSTIFICATION_RIGHT:
                  lstrcat(szMsg, "RIGHT\n");
                  break;

               case DICOM_TEXT_JUSTIFICATION_CENTER:
                  lstrcat(szMsg, "CENTER\n");
                  break;
               }
            }
            else
            {
               wsprintf(szMsg, "Unformatted Text Value: %s\n",
                        spTextObjAttribs->TextValue.operator char *());
               
               lstrcat(szMsg, "Anchor Point Annotation Units: ");
               switch (spTextObjAttribs->GetAnchorPointUnits ())
               {
               case DICOM_UNIT_PIXEL:
                  lstrcat(szMsg, "PIXEL\n");
                  break;

               case DICOM_UNIT_DISPLAY:
                  lstrcat(szMsg, "DISPLAY\n");
                  break;
               }

               sprintf(szMsg, "%sAnchor Point: %.2f, %.2f\n",
                       szMsg,
                       spTextObjAttribs->AnchorPointX,
                       spTextObjAttribs->AnchorPointY);
               
               if (spTextObjAttribs->AnchorPointVisible)
               {
                  lstrcat(szMsg, "Anchor Point Visibility: Y");
               }
               else
               {
                  lstrcat(szMsg, "Anchor Point Visibility: N");
               }
            }

            MessageBox(NULL, szMsg, "Text Annotation Object", MB_OK);
         }

      } while (spPresStateDS->MoveNextGraphicAnnItem () == DICOM_SUCCESS);
   }
}