// Functions used to extract W2D objects. DWFInputStream* g_pDWFInputStream; 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; } // End of Functions used to extract W2D objects. /* Read object information from DWF Package files. */ void CViewerDWFEngine::dwfPackgeParser( DWFToolkit::DWFPackageReader &reader ) { // // 2D/3D identifier. // bool is3DModel = true; // // read and parse the manifest // DWFToolkit::DWFManifest &rManifest = reader.getManifest(); // // obtain the emodel section // DWFToolkit::DWFManifest::SectionIterator *piSections = rManifest.findSectionsByType( _DWF_FORMAT_EMODEL_TYPE_WIDE_STRING ); // // make sure we got a section // if ((piSections == NULL) || (piSections->valid() == false)) { piSections = rManifest.findSectionsByType( _DWF_FORMAT_EPLOT_TYPE_WIDE_STRING ); if ((piSections == NULL) || (piSections->valid() == false)) { if ( piSections != NULL ) { DWFCORE_FREE_OBJECT( piSections ); } OutputDebugStringA( "Malformed or unexpected 3D DWF, cannot continue without an EModel section." ); return ; } else // 2D package { is3DModel = false; } } if( is3DModel ) { } else { DWFToolkit::DWFSection* pSection = NULL; for ( DWFToolkit::DWFManifest::SectionIterator* pSections = rManifest.getSections(); pSections && pSections->valid(); pSections->next() ) { pSection = pSections->get(); if ( pSection->type() == _DWF_FORMAT_EPLOT_TYPE_WIDE_STRING ) { boost::shared_ptr< FX_DWF_2D_Generator> newPage( boost::make_shared< FX_DWF_2D_Generator >() ); for ( DWFToolkit::DWFResourceContainer::ResourceIterator* pResources = pSection->findResourcesByRole( DWFXML::kzRole_Graphics2d ); pResources && pResources->valid(); pResources->next() ) { // assumes above call to valid will return false if get() // would return null 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); newPage->rewriteW2D ( &inputStream); } m_objectList.push_back( newPage ); } } } } WT_Result FX_DWF_2D_Generator::rewriteW2D ( WT_File* pInput ) { WT_Result res = WT_Result::Success; pInput->set_file_mode (WT_File::File_Read); res = pInput->open (); while ( res == WT_Result::Success ) { res = pInput->get_next_object(); if ( res == WT_Result::Success ) { const WT_Object* pObj = pInput->current_object(); generateObject( pObj ); // In generateObject function, I call getUnits and other extraction functions. } } pInput->close(); return res; } /* Generate drawable objects from DWF object. */ void FX_DWF_2D_Generator::generateObject( const WT_Object *obj ) { if( obj == NULL ) { return ; } WT_Object::WT_ID objId = obj->object_id(); switch( objId ) { // Layer information. case WT_Object::Layer_ID: { getLayer( obj ); } break; //end // Common properties. case WT_Object::Units_ID: { getUnits( obj ); } break; case WT_Object::View_ID: { getView( obj ); } break; //end // Shapes case WT_Object::Polyline_ID: { generatePolyLine( obj ); } break; //end default: break; } } void FX_DWF_2D_Generator::getUnits( const WT_Object *obj ) { WT_Units units = *(WT_Units *) obj; const WT_Matrix mat16 = units.application_to_dwf_transform(); m_transformMatDWF = new double[16]; memcpy( m_transformMatDWF, mat16.elements(), sizeof( double ) * 16 ); WT_String str = units.units(); if( str.is_ascii() ) { m_unitType = str.ascii(); } // Set scalar for each axises. if( m_transformMatDWF[0] != 0.0f ) m_xScalar = m_transformMatDWF[0]; if( m_transformMatDWF[5] != 0.0f ) m_yScalar = m_transformMatDWF[5]; } void FX_DWF_2D_Generator::getView( const WT_Object *obj ) { WT_View *viewObj = (WT_View *) obj; WT_Logical_Box viewBox = viewObj->view(); m_viewHeight = viewBox.maxpt().m_y - viewBox.minpt().m_y; m_viewWidth = viewBox.maxpt().m_x - viewBox.minpt().m_x; m_DWF2DView_NLB.x = -m_viewWidth / 2; m_DWF2DView_NLB.y = -m_viewHeight / 2; m_DWF2DView_FRU.x = m_viewWidth / 2; m_DWF2DView_FRU.y = m_viewHeight / 2; m_viewTranslateX = viewBox.minpt().m_x + m_viewWidth / 2; m_viewTranslateY = viewBox.minpt().m_y + m_viewHeight / 2; } void FX_DWF_2D_Generator::generatePolyLine( const WT_Object *obj ) { WT_Polyline *polylineObj = (WT_Polyline *) obj; WT_Logical_Point* points = polylineObj->points(); int count = polylineObj->count(); VM_POINT_3D polyPoint; boost::shared_ptr currentDrawing( boost::make_shared< FX_DWF_Polyline >() ); // Set element type in order to specify drawing method. currentDrawing->m_elemType = FX_Polyline; currentDrawing->m_weight = m_lineWeight; for( int i=0; im_pointList.push_back( polyPoint ); } // Set a specified color to this new object. setObjectColor( currentDrawing ); // Put the new object into drawing stack. insertNewObject( currentDrawing ); }