Files
Slnkdwf/SlnkDWFCom/DWFFile.cpp
2020-06-08 16:12:25 +00:00

224 lines
5.0 KiB
C++

// DWFFile.cpp : Implementation of CDWFFile
#include "stdafx.h"
//#include "assert.h"
#include "DWFFile.h"
#include "myEPlotSection.h"
// CDWFFile
STDMETHODIMP CDWFFile::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IDWFFile
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
//CDWFFile::~CDWFFile()
//{
// // It seems we never get here? Use FinalRelease
//};
HRESULT CDWFFile::FinalConstruct()
{
m_EPlotSections.SetParent(this);
m_EPlotSections.SetOuterUnknown(GetControllingUnknown());
return m_EPlotSections.FinalConstruct();
}
// Omdat de tellingen gekoppeld zijn weten we zeker dat de refcount van
// onze eigen objecten ook 0 zal zijn en is het dus veilig ze weg te gooien (toch...?)
void CDWFFile::FinalRelease()
{
m_EPlotSections.FinalRelease();
}
STDMETHODIMP CDWFFile::Open(BSTR DWFPath)
{
if (CString(DWFPath).IsEmpty())
return E_INVALIDARG;
try
{
if (CDWFFileImpl::Open(CString(DWFPath)))
{
return S_OK;
}
else
return E_FAIL;
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)", ex.type(), ex.message(), ex.function(), ex.file(), ex.line());
return myAtlReportError(GetObjectCLSID(), "\nCDWFFile::Open('%s')\n%s", CString(DWFPath), err);
}
catch (CString& e)
{
return myAtlReportError (GetObjectCLSID(), e);
}
}
STDMETHODIMP CDWFFile::Create(BSTR DWFPath, VARIANT EPlotStream)
{
if (EPlotStream.vt==VT_ERROR)
{
if (EPlotStream.scode != DISP_E_PARAMNOTFOUND)
return E_INVALIDARG;
}
else
{
VARIANT *var2 = &EPlotStream;
if (var2->vt==(VT_VARIANT|VT_BYREF)) // ByRef
var2 = (VARIANT *)var2->pvarVal;
if (var2->vt!=VT_DISPATCH)
return E_INVALIDARG;
CComQIPtr<IDWFFile> DWFFile;
DWFFile = var2->pdispVal;
if (!DWFFile)
return E_INVALIDARG;
}
try
{
{
//TODO CDWFFileImpl *epli;
// DWFFile->get_DWFFileImpl((BYTE **)&epli);
if (CDWFFileImpl::Create(CString(DWFPath), /*epli*/NULL))
{
return S_OK;
}
else
return E_FAIL;
}
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)", ex.type(), ex.message(), ex.function(), ex.file(), ex.line());
return myAtlReportError(GetObjectCLSID(), "\nCDWFFile::Create('%s')\n%s", CString(DWFPath), err);
}
catch (CString& e)
{
return myAtlReportError (GetObjectCLSID(), e);
}
return S_OK;
}
// W2DPath bron W2D bestand
// EPlotStream: template waarvan paper settings en zo worden overgenomen
// (in de praktijk zal het bestand onder W2DPath afgeleid zijn van EPlotStream
// in een eerder proces)
STDMETHODIMP CDWFFile::CreateEPlotSection(BSTR W2DPath, VARIANT EPlotStream, LONG *nItem)
{
try
{
if (EPlotStream.vt!=VT_ERROR)
{
VARIANT *var2 = &EPlotStream;
if (var2->vt==(VT_VARIANT|VT_BYREF)) // ByRef
var2 = (VARIANT *)var2->pvarVal;
if (var2->vt==VT_DISPATCH)
{
CComQIPtr<IEPlotSection> EPlotSection;
EPlotSection = var2->pdispVal;
if (!EPlotSection)
return E_INVALIDARG;
else
{
CEPlotSectionImpl *epli;
EPlotSection->get_EPlotSectionImpl((BYTE **)&epli);
*nItem = CDWFFileImpl::CreateEPlotSection(CString(W2DPath), epli);
if (*nItem >=0)
return S_OK;
else
return E_FAIL;
}
}
else
return E_INVALIDARG;
}
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)", ex.type(), ex.message(), ex.function(), ex.file(), ex.line());
return myAtlReportError(GetObjectCLSID(), "\nCDWFFile::CreateEPlotSection('%s')\n%s", CString(W2DPath), err);
}
catch (CString& e)
{
return myAtlReportError (GetObjectCLSID(), e);
}
return S_OK;
}
STDMETHODIMP CDWFFile::Save()
{
myDoTRACE("\nCDWFFile::Save()");
try
{
CDWFFileImpl::Save();
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)", ex.type(), ex.message(), ex.function(), ex.file(), ex.line());
return myAtlReportError(GetObjectCLSID(), "\nCDWFFile::Save()\n%s", err);
}
catch (CString& e)
{
return myAtlReportError (GetObjectCLSID(), e);
}
return S_OK;
}
STDMETHODIMP CDWFFile::get_PropertiesXML(BSTR* pVal)
{
CString s;
try
{
if (CDWFFileImpl::get_PropertiesXML(s))
{
CComBSTR bstrString(s);
return bstrString.CopyTo(pVal);
}
else
return E_FAIL;
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)", ex.type(), ex.message(), ex.function(), ex.file(), ex.line());
return myAtlReportError(GetObjectCLSID(), "\nCDWFFile::get_PropertiesXML()\n%s", err);
}
catch (CString& e)
{
return myAtlReportError(GetObjectCLSID(), e);
}
return S_OK;
}
STDMETHODIMP CDWFFile::get_EPlotSections(IEPlotSections **ppEPlotSections)
{
// if (!m_isOpen)
// return myAtlReportError (GetObjectCLSID(), "\nDWF File is not opened");
return m_EPlotSections.QueryInterface(ppEPlotSections);
}