#include "stdafx.h"
#include "CadFileFormat.h"
#include "string_format.h"

const wchar_t *GetFileFormatText(CadFileFormat fileFormat)
{
  const wchar_t *pFormatText = nullptr;
  switch (fileFormat)
  {
  case FILE_FORMAT_IGES:
    pFormatText = L"IGES";
    break;
  case FILE_FORMAT_STEP:
    pFormatText = L"STEP";
    break;
  case FILE_FORMAT_CATIA4:
    pFormatText = L"CATIA 4";
    break;
  case FILE_FORMAT_CATIA5:
    pFormatText = L"CATIA 5";
    break;
  case FILE_FORMAT_CATIA6:
    pFormatText = L"CATIA 6";
    break;
  case FILE_FORMAT_JT:
    pFormatText = L"JT";
    break;
  case FILE_FORMAT_PARASOLID:
    pFormatText = L"Parasolid";
    break;
  case FILE_FORMAT_PROE:
    pFormatText = L"Creo";
    break;
  case FILE_FORMAT_UG:
    pFormatText = L"NX";
    break;
  case FILE_FORMAT_SOLIDWORKS:
    pFormatText = L"SolidWorks";
    break;
  case FILE_FORMAT_SOLIDEDGE:
    pFormatText = L"Solid Edge";
    break;
  case FILE_FORMAT_INVENTOR:
    pFormatText = L"Inventor";
    break;
  default:
    // unknown file format
    assert(0);
  }
  return pFormatText;
}

const wchar_t *GetFileFilterText(CadFileFormat fileFormat)
{
  const wchar_t *pExtFilterText = nullptr;
  switch (fileFormat)
  {
  case FILE_FORMAT_IGES:
    pExtFilterText = L"*.igs;*.iges";
    break;
  case FILE_FORMAT_STEP:
    pExtFilterText = L"*.stp;*.step";
    break;
  case FILE_FORMAT_CATIA4:
    pExtFilterText = L"*.mod*;*.exp;*.iso;*.cat";
    break;
  case FILE_FORMAT_CATIA5:
    pExtFilterText = L"*.CATPart;*.CATProduct";
    break;
  case FILE_FORMAT_CATIA6:
    pExtFilterText = L"*.3dxml";
    break;
  case FILE_FORMAT_JT:
    pExtFilterText = L"*.jt";
    break;
  case FILE_FORMAT_PARASOLID:
    pExtFilterText = L"*.x_t;*.x_b;*.xmt_txt;*.xmt_bin";
    break;
  case FILE_FORMAT_PROE:
    pExtFilterText = L"*.prt*;*.asm*;*.xpr*;*.xas*";
    break;
  case FILE_FORMAT_UG:
    pExtFilterText = L"*.prt";
    break;
  case FILE_FORMAT_SOLIDWORKS:
    pExtFilterText = L"*.sldprt;*.sldasm";
    break;
  case FILE_FORMAT_SOLIDEDGE:
    pExtFilterText = L"*.par;*.asm;*.psm;*.pwd";
    break;
  case FILE_FORMAT_INVENTOR:
    pExtFilterText = L"*.ipt;*.iam";
    break;
  default:
    // unknown file format
    assert(0);
  }
  return pExtFilterText;
}

bool AddFileFilter(std::wstring &inOutFileFilter, const wchar_t *pTypeText, const wchar_t *pExtFilterText, const wchar_t *pFormatText/* = DefaultFormatText*/)
{
  if (pTypeText == nullptr || pExtFilterText == nullptr || pFormatText == nullptr)
  {
    return false;
  }
  std::wstring filterText;
  string_format(filterText, pFormatText, pTypeText, pExtFilterText);
  inOutFileFilter += filterText + L"|" + pExtFilterText + L"|";
  return true;
}

bool AddFileFormatFilter(std::wstring &inOutFileFilter, CadFileFormat fileFormat, const wchar_t *pFormatText/* = DefaultFormatText*/)
{
  const wchar_t *pTypeText = GetFileFormatText(fileFormat);
  const wchar_t *pExtFilterText = GetFileFilterText(fileFormat);
  return AddFileFilter(inOutFileFilter, pTypeText, pExtFilterText, pFormatText);
}

