DWF

Reply
Contributor
ADringer
Posts: 18
Registered: ‎08-04-2009
Message 1 of 3 (954 Views)

Merging W2D Files

954 Views, 2 Replies
07-06-2010 05:09 AM

Hi 

 

What I am essentially trying to do is create layers of measurements within a DWF file. For instance, the user measures a number of items for one layer, and then measure some more items for another layer. They then have the option of hiding a layer so they only see some of the measurements, or both etc. 

 

I first tried this just opening up a DWF with measurements, and going through each section, finding the kzRole_Graphics2dMarkup resource and then inserting this into a copy of the original DWF, in the same section.

 

This worked fine if the section that I was inserting into didn't have any measurements, but if it did I would get errors when trying to view that section in ADR. From what I can tell, for each section there can only be 1 W2D file per section for displaying measurements? Is this true? 

 

From looking at other discussions, I thought that the proper approach would be to merge the W2D files, so I end up with one. My code opens up the DWF, and for each section gets the Graphics2dMarkup into a stream and then I try writing this out to a new W2D file. However I am getting an error when I try and serialize the object. The object is of type WT_Compressed_Data_Moniker, do I need to uncompress it first, and how? The error I get is: 

 

The assertion 'file.stream_user_data()' failed in ..\..\..\src\dwf\whiptk\file.cpp at line 3361. The last Win32 error code was 3. 

 

My source code is below: 

int main(int argc, wchar_t* argv[])
{   
        // CreateDirectory for the output
      wchar_t* fileName = argv[1] + wcslen (argv[1]);
      while (--fileName > argv[1])
      {
          if ( *fileName == L'\\' )
          {
             fileName++;
              break;
         }
     }
        
     wchar_t* dirName = new wchar_t [ wcslen (fileName) + wcslen(DIR_POSTFIX) + 1];   

    GetW2D((DWFString)argv[1],dirName);   
    return 0;
}

void GetW2D(DWFString File, wchar_t* dir)
{
    DWFFile sourceDWF( File );
    DWFPackageReader sourceReader( sourceDWF );
    DWFPackageReader::tPackageInfo sourceInfo;
    sourceReader.getPackageInfo( sourceInfo );

    DWFManifest& sourceManifest = sourceReader.getManifest();
    DWFSection* sourceSection = NULL;
    DWFManifest::SectionIterator* sourceSections =
          sourceManifest.getSections();
	
    if (sourceSections)
    {
 	for (;sourceSections->valid(); sourceSections->next())
	{
             sourceSection = sourceSections->get();
	    sourceSection->readDescriptor();			
	    for (DWFToolkit::DWFResourceContainer::ResourceIterator* pResources = sourceSection->findResourcesByRole( DWFXML::kzRole_Graphics2dMarkup );pResources && pResources->valid(); pResources->next() )
	    {
	    g_pDWFInputStream = pResources->get()->getInputStream();
	    WT_File inputStream;
             inputStream->set_stream_open_action (&DWFInputStreamOpen);
	    inputStream->set_stream_close_action (&DWFInputStreamClose);
             inputStream->set_stream_read_action (&DWFInputStreamRead);
             inputStream->set_stream_seek_action (&DWFInputStreamSeek);
        inputStream->set_stream_end_seek_action (&DWFInputStreamEndSeek);
	
            WT_File outFile;
            size_t filePathLen = 
                    ( dir ? wcslen(dir) : 0) + wcslen (sourceSection-                     >name()) + 6;
            wchar_t* filePath = new wchar_t[filePathLen];
            if ( !filePath )
                throw E_OUTOFMEMORY;
            outFile.set_filename ((WT_Unsigned_Integer16*)filePath);    
  	   rewriteW2D (&outFile, &inputStream);  
	  }
       }
   }		
}

WT_Result rewriteW2D ( WT_File* pOutput, WT_File* pInput )
{
    WT_Result res = WT_Result::Success;
    pInput->set_file_mode (WT_File::File_Read);
    res = pInput->open ();

    if ( res == WT_Result::Success )
    {
        pOutput->set_file_mode (WT_File::File_Write);
        res == pOutput->open();
        pOutput->heuristics().set_allow_binary_data (pInput->heuristics().allow_binary_data());
        pOutput->heuristics().set_allow_data_compression (pInput->heuristics().allow_data_compression());
        pOutput->heuristics().set_target_version (pInput->heuristics().target_version());
    }

    while ( res == WT_Result::Success )
    {
        res = pInput->get_next_object();		
        if ( res == WT_Result::Success )
        {
            const WT_Object* pObj = pInput->current_object();
            if ( pObj )
            {
                switch ( pObj->object_id() )
                {
                    case WT_Object::DWF_Header_ID :
                    case WT_Object::End_Of_DWF_ID :
                        // do nothing
                        break;

                    default:						
                        pObj->serialize (*pOutput);
                        break;
                }
            }
        }
    }

    pInput->close();
    pOutput->close();

    return res;
}

WT_Result DWFInputStreamOpen(WT_File & file)
{
    file.set_stream_user_data (g_pDWFInputStream);
    return g_pDWFInputStream ? 
        WT_Result::Success : 
        WT_Result::File_Open_Error;
}

WT_Result DWFInputStreamClose (WT_File & file)
{
    return WT_Result::Success;
}

WT_Result DWFInputStreamRead( WT_File & file,
                         int desired_bytes,
                         int & bytes_read,
                         void * buffer)
{
    WT_Result res = WT_Result::Unknown_File_Read_Error;
    if (g_pDWFInputStream)
    {
        bytes_read = (int)g_pDWFInputStream->read (buffer, desired_bytes);
        res = WT_Result::Success;
    }

    return res;
}

WT_Result DWFInputStreamSeek( WT_File & file,
                              int desired_bytes,
                              int &bytes_seeked)
{
    WT_Result res = WT_Result::Unknown_File_Read_Error;
    if (g_pDWFInputStream)
    {
        g_pDWFInputStream->seek (SEEK_SET, desired_bytes);
        bytes_seeked = desired_bytes;
        res = WT_Result::Success;
    }

    return res;
}

WT_Result DWFInputStreamEndSeek (WT_File & file)
{
    WT_Result res = WT_Result::Unknown_File_Read_Error;
    return res;
}

WT_Result DWFStreamTell ( WT_File & file, 
                          unsigned long *current_file_pointer_position )
{
    WT_Result res = WT_Result::Unknown_File_Read_Error;
    if (g_pDWFInputStream)
    {
        *current_file_pointer_position =
            g_pDWFInputStream->seek (SEEK_CUR, 0);
        res = WT_Result::Success;
    }

    return res;
}

 

 

At the moment my code isn't merging the W2D streams, I'm trying to get it to copy a stream from one file to another. 

Many thanks for your help! 

Alex 

                         

Contributor
ADringer
Posts: 18
Registered: ‎08-04-2009
Message 2 of 3 (952 Views)

Re: Merging W2D Files

07-06-2010 08:58 AM in reply to: ADringer

Just noticed a couple of errors with my code. In RewriteW2D(), I had two equal signs in the statement:

res == pOutput->open();

 

I've changed this and set the output filename to something hardcoded i.e. outFile.set_filename("New.w2d").

 

This now creates the w2d, but I think it differs from the original w2d. Also, when added the file as a resource into a dwf it gave me an error saying that the section could not be displayed.

 

Am I going the right way about this?

Employee
SilviaCao
Posts: 136
Registered: ‎06-07-2009
Message 3 of 3 (909 Views)

Re: Merging W2D Files

07-15-2010 10:44 PM in reply to: ADringer

Thank you for your question.

 

You are right to merge the markup W2D files. The W2D files can be created in a temporary folder; then recreate a DWF file and add the W2D file to the new DWF.

 

Please let me know if you have any further questions.

 

Silvia

ADR/DWF Customer Support



Silvia Cao
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.