// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
DataContainerArrayProxy DataArraySelectionWidget::generateDCAProxy()
{
  // This will only work for a single selection
  DataContainerArrayProxy dcaProxy;
  QString dcaName = dataContainerCombo->currentText();
  DataContainerProxy dcProxy(dcaName, true);

  QString amName = attributeMatrixCombo->currentText();
  AttributeMatrixProxy amProxy(amName, true);

  QString daName = attributeArrayCombo->currentText();
  DataArrayProxy daProxy(dcaName + "|" + amName, daName, true);
  amProxy.dataArrays.insert(daName, daProxy);
  dcProxy.attributeMatricies.insert(amName, amProxy);
  dcaProxy.dataContainers.insert(dcProxy.name, dcProxy);

  return dcaProxy;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AttributeMatrix::ReadAttributeMatrixStructure(hid_t containerId, DataContainerProxy& dcProxy, QString h5InternalPath)
{
    QList<QString> attributeMatrixNames;
    QH5Utilities::getGroupObjects(containerId, H5Utilities::H5Support_GROUP, attributeMatrixNames);
    foreach(QString attributeMatrixName, attributeMatrixNames)
    {
        if (attributeMatrixName.compare(DREAM3D::Geometry::Geometry) != 0)
        {
            if(__SHOW_DEBUG_MSG__)
            {
                std::cout << "    AttributeMatrix: " << attributeMatrixName.toStdString()  << std::endl;
            }
            hid_t attrMatGid = H5Gopen(containerId, attributeMatrixName.toLatin1().constData(), H5P_DEFAULT);
            if (attrMatGid < 0)
            {
                continue;
            }
            HDF5ScopedGroupSentinel sentinel(&attrMatGid, true);

            AttributeMatrixProxy amProxy(attributeMatrixName);
            amProxy.name = attributeMatrixName;
            amProxy.flag = Qt::Checked;
            herr_t err = QH5Lite::readScalarAttribute(containerId, attributeMatrixName, DREAM3D::StringConstants::AttributeMatrixType, amProxy.amType);
            if(err < 0)
            {
                std::cout << "Error Reading the AttributeMatrix Type for AttributeMatrix " << attributeMatrixName.toStdString() << std::endl;
            }

            QString h5Path = h5InternalPath + "/" + attributeMatrixName;

            // Read in the names of the Data Arrays that make up the AttributeMatrix
            QMap<QString, DataArrayProxy>& daProxies = amProxy.dataArrays;
            DataArrayProxy::ReadDataArrayStructure(attrMatGid, daProxies, h5Path);

            // Insert the AttributeMatrixProxy proxy into the dataContainer proxy
            dcProxy.attributeMatricies.insert(attributeMatrixName, amProxy);
        }
    }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
DataContainerArrayProxy::DataContainerArrayProxy(DataContainerArray* dca)
{

  if(NULL == dca)
  {
    return;
  }

  QList<DataContainer::Pointer> containers = dca->getDataContainers();
  for(int i = 0; i < containers.size(); i++) // Loop on each Data Container
  {
    DataContainer::Pointer container = containers.at(i);
    DataContainerProxy dcProxy(container->getName(), Qt::Checked); // Create a new DataContainerProxy

    // Now loop over each AttributeMatrix in the data container that was selected
    DataContainer::AttributeMatrixMap_t attrMats = container->getAttributeMatrices();
    QMapIterator<QString, AttributeMatrix::Pointer> iter(attrMats);
    while(iter.hasNext())
    {
      iter.next();
      QString amName = iter.key();
      AttributeMatrix::Pointer attrMat = iter.value();
      AttributeMatrixProxy amProxy(amName, Qt::Checked, attrMat->getType());

      QList<QString> attrArrayNames = attrMat->getAttributeArrayNames();
      QListIterator<QString> attrArrayNamesIter(attrArrayNames);
      while(attrArrayNamesIter.hasNext())
      {
        QString aaName = attrArrayNamesIter.next();
        QString daPath = container->getName() + "/" + amName + "/";
        IDataArray::Pointer attrArray = attrMat->getAttributeArray(aaName);
        DataArrayProxy daProxy(daPath, aaName, Qt::Checked, attrArray->getTypeAsString(), attrArray->getClassVersion() );
        amProxy.dataArrays.insert(aaName, daProxy);
      }
      dcProxy.attributeMatricies.insert(amName, amProxy); // Add the new AttributeMatrix to the DataContainerProxy
    }
    dataContainers.insert(dcProxy.name, dcProxy);
  }
}