TUDE#13285 AsDWF Schaal behouden

svn path=/Slnkdwf/trunk/; revision=12484
This commit is contained in:
Jos Groot Lipman
2007-12-19 09:44:56 +00:00
parent bda5588365
commit 6596ce32c5
23 changed files with 403 additions and 77 deletions

View File

@@ -5,6 +5,8 @@
#include "DWFFileImpl.h"
#include "myEPlotSectionImpl.h"
#include "dwfcore/mime.h"
#include "../SLNKDwfCom/SLNKDwfVersion.h"
// CDWFFile
@@ -18,10 +20,175 @@ CDWFFileImpl::~CDWFFileImpl()
if (m_oReader!=NULL)
delete m_oReader;
#ifndef DWFTK_READ_ONLY
if (m_oWriter!=NULL)
delete m_oWriter;
#endif
if (m_DWF!=NULL)
delete m_DWF;
}
#ifndef DWFTK_READ_ONLY
bool CDWFFileImpl::Create(const CString &DWFPath, CDWFFileImpl *DWFFileTemplate)
{
DWFCore::DWFFile oDWF( DWFPath );
m_oWriter = new DWFToolkit::DWFPackageWriter ( oDWF );
return true;
}
// Returns index of created item. -1 is error
// W2DPath wijst naar de W2D die we inlezen
// ePlotTemplate nemen we papier van over
LONG CDWFFileImpl::CreateEPlotSection(const CString &W2DPath,
CEPlotSectionImpl *ePlotTemplate)
{
if (!m_oWriter)
throw CString("DWFFile package must be created first");
// Neem zo veel mogelijk van onze originele EPlotSection over
DWFToolkit::DWFEPlotSection* oldSection = ePlotTemplate->get_Section();
// Maak een nieuwe DWFEPlotSection aan
DWFToolkit::DWFEPlotSection* pPage =
DWFCORE_ALLOC_OBJECT( DWFToolkit::DWFEPlotSection(
oldSection->title(),
oldSection->objectID(), oldSection->order(),
oldSection->source(), oldSection->color(),
oldSection->paper()) );
pPage->addProperty( DWFCORE_ALLOC_OBJECT(DWFToolkit::DWFProperty(L"Version", SLNK_BUILDVERSION, L"SLNKDWF", L"", L"")), true );
// Zoek de originele graphicsResource voor de units e.d.
DWFResourceContainer::ResourceIterator* piResources =
oldSection->findResourcesByRole( DWFXML::kzRole_Graphics2d );
if ((piResources == NULL) || (piResources->valid() == false))
{
if (piResources)
{
DWFCORE_FREE_OBJECT( piResources );
}
myTRACE("%ls", "Illegal EPlot section - no graphics");
return false;
}
//
// get the w2d resource
//
//Since we know it's a Graphics2D role, we should be able to cast
//into an EPlotGraphicResource, otherwise the authoring tool didn't
//read the spec.
DWFToolkit::DWFGraphicResource* pW2D = dynamic_cast<DWFGraphicResource*>(piResources->get());
//
// define the resource - this must be allocated on the heap
//
DWFToolkit::DWFGraphicResource* p2Dgfx =
DWFCORE_ALLOC_OBJECT( DWFGraphicResource(L"SLNKDWF" , // title
DWFXML::kzRole_Graphics2d, // role
DWFMIME::kzMIMEType_W2D, // MIME type
L"Autodesk, Inc.", // author
L"SLNKDWF modfied", // description
L"", // creation time
L"") ); // modification time
if (p2Dgfx == NULL)
{
_DWFCORE_THROW( DWFMemoryException, L"Failed to allocate resource" );
}
//
// configure the resource
//
p2Dgfx->configureGraphic( pW2D->transform(),
NULL,
pW2D->clip() );
//
// most importantly - bind a stream to the resource
// in this case, we have a file on disk so we open the
// file with a streaming descriptor. we will also
// create everything on the heap since the package writer
// will not use the stream immediately, he will need to own
// these resources.
//
DWFCore::DWFFile oW2DFilename( W2DPath );
DWFCore::DWFStreamFileDescriptor* pW2DFile = DWFCORE_ALLOC_OBJECT( DWFStreamFileDescriptor(oW2DFilename, L"rb") );
if (pW2DFile == NULL)
{
DWFCORE_FREE_OBJECT( p2Dgfx );
_DWFCORE_THROW( DWFMemoryException, L"Failed to allocate file descriptor" );
}
DWFCore::DWFFileInputStream* pW2DFilestream = DWFCORE_ALLOC_OBJECT( DWFFileInputStream );
if (pW2DFilestream == NULL)
{
DWFCORE_FREE_OBJECT( p2Dgfx );
DWFCORE_FREE_OBJECT( pW2DFile );
_DWFCORE_THROW( DWFMemoryException, L"Failed to allocate file stream" );
}
//
// open the file and bind it to the stream
//
pW2DFile->open();
pW2DFilestream->attach( pW2DFile, true );
//
// hand the stream off to the resource
// NOTE: since we don't already know the filesize (in the application space - of course we can look on disk...)
// leave the second parameter (nBytes) default as zero, this will tell the package writer
// to use the number of bytes it processed through the stream as the size attribute in the descriptor.
//
p2Dgfx->setInputStream( pW2DFilestream );
//
// finally, drop the resource into the page
//
pPage->addResource( p2Dgfx, true );
///
///
CEPlotSectionImpl *mySection = new CEPlotSectionImpl;
CString s;s.Format("%s (page %d)", "sourceDescription", m_EPlotSections.get_Count());
mySection->Init(pPage, s, true);
m_EPlotSections.Add(mySection);
m_oWriter->addSection( pPage );
// Aan het einde van de packagewriter gebeurt wel een flush...DWFCORE_FREE_OBJECT( pW2DFilestream );
return m_EPlotSections.get_Count()-1;
}
bool CDWFFileImpl::Save()
{
if (!m_oWriter)
throw CString("DWFFile package must be created first");
try
{
m_oWriter->write( L"Dijkoraad IT", L"SLNKDWF", SLNK_BUILDVERSION, // <== Wij
L"Autodesk, Inc", _DWFTK_VERSION_STRING ); // <== Zij
}
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());
throw myCString ("\nCDWFFileImpl::Save()\n%s", err);
}
return true;
}
bool CDWFFileImpl::Open(const CString &DWFPath)
{
if (m_isOpen)
@@ -80,6 +247,7 @@ bool CDWFFileImpl::Open(const CString &DWFPath)
throw myCString ("\nCDWFFileImpl::Open('%s')\n%s", DWFPath, err);
}
}
#endif
#if DESIRED_CODE(WHIP_OUTPUT)
bool CDWFFileImpl::get_PropertiesXML(CString & pVal)

View File

@@ -11,6 +11,12 @@ CEPlotSectionsImpl::~CEPlotSectionsImpl()
delete m_EPlotSections[i];
}
BOOL CEPlotSectionsImpl::Add(CEPlotSectionImpl *pSection)
{
m_EPlotSections.Add(pSection);
return true;
}
// Actually process the EPlotSections and add them to our collection
BOOL CEPlotSectionsImpl::ProcessManifest(DWFManifest& rManifest, CString sourceDescription)
{

View File

@@ -15,7 +15,10 @@ class CDWFFileImpl
{
public:
CDWFFileImpl()
: m_DWF(NULL),m_oReader(NULL), m_isOpen(FALSE)
: m_DWF(NULL),m_oReader(NULL), m_isOpen(FALSE)
#ifndef DWFTK_READ_ONLY
,m_oWriter(NULL)
#endif
{
}
~CDWFFileImpl();
@@ -23,6 +26,11 @@ public:
public:
bool get_PropertiesXML(CString & pVal);
CEPlotSectionsImpl *get_EPlotSections();
#ifndef DWFTK_READ_ONLY
bool Create(const CString &DWFPath, CDWFFileImpl *DWFFileTemplate );
LONG CreateEPlotSection(const CString &W2DPath, CEPlotSectionImpl *ePlotTemplate);
bool Save();
#endif
bool Open(const CString &DWFPath);
public:
@@ -31,6 +39,9 @@ public:
private:
DWFCore::DWFFile *m_DWF;
#ifndef DWFTK_READ_ONLY
DWFToolkit::DWFPackageWriter* m_oWriter;
#endif
DWFToolkit::DWFPackageReader* m_oReader;
WT_File m_DWFFile;

View File

@@ -24,6 +24,7 @@ protected:
public:
BOOL ProcessManifest(DWFToolkit::DWFManifest& rManifest, CString sourceDescription);
BOOL Add(CEPlotSectionImpl *pSection);
long get_Count();
CEPlotSectionImpl *get_Item(LONG i);

View File

@@ -154,6 +154,12 @@ STDMETHODIMP CEPlotSectionImpl::Open(BOOL bForWrite)
//
DWFCORE_FREE_OBJECT( piResources );
if (pW2D == NULL)
{
myTRACE("%ls", L"Type mismatch - not a W2D resource");
return E_FAIL;
}
if (pW2D->mime() != DWFCore::DWFMIME::kzMIMEType_W2D)
{
myDoTRACE("\nMime: %ls", (const wchar_t*)pW2D->mime());
@@ -161,12 +167,6 @@ STDMETHODIMP CEPlotSectionImpl::Open(BOOL bForWrite)
"\nMeasurement/Print disabled?", (const wchar_t*)pW2D->mime());
}
if (pW2D == NULL)
{
myTRACE("%ls", L"Type mismatch - not a W2D resource");
return E_FAIL;
}
//
// get the data stream
//
@@ -202,6 +202,13 @@ const DWFProperty* const CEPlotSectionImpl::findProperty( const DWFString& zName
return m_pSection->findProperty( zName, zCategory);
}
void const CEPlotSectionImpl::addProperty( const DWFString& zCategory,
const DWFString& zName,
const DWFString& zValue )
{
m_pSection->addProperty( DWFCORE_ALLOC_OBJECT(DWFToolkit::DWFProperty(zName, zValue, zCategory, L"", L"")), true );
}
HRESULT CEPlotSectionImpl::Read( void *pv, ULONG cb, ULONG *pcbRead)
{

View File

@@ -45,11 +45,15 @@ public:
const CString get_Name();
const CString get_Title();
STDMETHOD(Open)(BOOL bForWrite);
STDMETHOD(Read) ( void *pv, ULONG cb, ULONG *pcbRead);
STDMETHOD(Seek) ( ULONG cb, ULONG *pcbRead);
const DWFProperty* const findProperty( const DWFString& zName,
const DWFString& zCategory = L"" );
void const addProperty( const DWFString& zCategory,
const DWFString& zName,
const DWFString& zValue );
#ifndef DWFTK_READ_ONLY
bool SaveAs(const CString &destpath);
static bool SaveAsAscii(const CString &srcpath, const CString &destpath);
@@ -58,6 +62,7 @@ public:
#endif
STDMETHOD(Close)(void);
ULONG get_PaperColor();
DWFToolkit::DWFEPlotSection* const get_Section() { return m_pSection; };
STDMETHOD(get_SourceDescription)(CString &pVal);
#ifndef DWFTK_READ_ONLY
STDMETHOD(get_PropertiesXML)(CString & pVal);