Drawings SDK Developer Guide > Working with .dwg Files > Working with Other File Formats > Exporting to Other Formats > Exporting to a HOOPS Stream Format File
Exporting to a HOOPS Stream Format File (.hsf file)

Exporting to a HOOPS Stream Format File (.hsf file)

HOOPS Stream Format

The HOOPS Stream Format (HSF) is an open file format that can be used for lightweight exchanging of graphical information. HSF has the following advantages:

  • Lossless compression and edge-breaking algorithms: vertices and normals are stored in compression format, so the output file has a significantly smaller size.
  • Extensibility: HOOPS Stream Format supports not only basic read/write operations for predefined primitives, but it also can be extended with user tokens.
  • Subsequent revisiting: entities can be revisited after import or export.
  • Optimized data processing: Using a data dictionary, scene data is written first before writing the geometry data. Such approach allows to read the structure of the scene-graph and then read the required nodes quickly.
  • Entity priority mechanism: primitives can be ranked based on their size and vertex density and effectively processed.
See http://www.techsoft3d.com for additional information about HOOPS.

HOOPS Integration

Drawings SDK supports exporting a .dwg or .dgn file to a HOOPS Stream Format (.hsf file).

HOOPS Export provides direct integration between member applications built with the Drawings SDK and the HOOPS high-performance graphics system from Tech Soft 3D. It requires a separate license from Tech Soft 3D.

HOOPS Export is available in dynamic and static forms for Windows only. Supported platforms are limited by the platforms supported by Tech Soft 3D HOOPS SDK. Please see http://www.techsoft3d.com for more details.

All sources are available in the release packages.

Applications enhanced with HOOPS integration can support:

  • Rich 2D and 3D integrated scene-graph creation and management.
  • Fast interactive on-screen viewing, manipulation, and interaction.
  • Optimal rendering on both OpenGL and Direct3D.
  • High quality text rendering and management.
  • Crisp print and plot output.

The ODA HOOPS Export module provides the following functionality:

  • Part Viewer Plug-in: loads .dwg and .dgn files to the HOOPS Part Viewer (or similar applications).
  • Export to HSF or HMF: converts .dwg and .dgn files to HSF (HOOPS Stream Format) or HMF (HOOPS Metafile Format) for easy integration with applications that already work with these two standard formats.

HOOPS export modules and examples

TD_HoopsExport.tx is a .tx support module for HOOPS export.

Source code location: Kernel\Exports\HoopsExport.

This module should be loaded by the user application to get access to HOOPS export functionality.

HOOPS Export process

Export process consists of several stages:

  1. Create HoopsExportParams class instance.
  2. Set the HOOPS export parameters.
  3. Call the exportHoops() function (it is declared in HoopsExport.h) while sending it the parameters object created in the previous step.
  4. Analyze the result returned by exportHoops() function.

There are code examples that can be used for HOOPS export below:


  HoopsExportParams hoopsParams;
  hoopsParams.strFileName = sInput; //sets the output HOOPS Stream File full name
  hoopsParams.pDb = m_pDb;			//sets the database pointer for exporting drawing
  OdUInt32 errCode = exportHoops(hoopsParams);

The next example shows how layouts can be processed during export to HOOPS Stream File:


  OdStaticRxObject svcs;
  ::odInitialize(&svcs);
  
  try
  {
    OdDbDatabasePtr pDb = svcs.readFile(dwgPath);  //dwgPath contains full path to the input .dwg-file
		
    HoopsExportParams params;

    params.pDb = pDb;
    params.iStartKey = 0;
    params.bSetCamera = false;
    params.bExportCurrentLayout = true;
    params.bResetSystemExport = true;
    params.strFileName = "";
    
    OdDbBaseDatabasePEPtr pDbPE(params.pDb);
    OdRxIteratorPtr pLayIter = pDbPE->layouts(params.pDb);

    while(!pLayIter->done())
    {
      OdRxObjectPtr pCurLayout = pLayIter->object();
      OdDbBaseLayoutPEPtr pLayoutInfo( pCurLayout );

      if( pLayoutInfo.isNull() )
      {
		pLayIter->next();
		continue;
      }

      pDbPE->setCurrentLayout(params.pDb, pLayoutInfo->name(pCurLayout));

      OdString strLayoutName = pLayoutInfo->name(pCurLayout);
      OdUInt32 retValue = exportHoops(params);
      OdAnsiString tmp;
      char *pchLayoutName = new char [ strLayoutName.getLength() + 1];
      char *pchDwgPath = new char [ dwgPath.getLength() + 1];
      wcstombs( pchLayoutName, strLayoutName.c_str(), strLayoutName.getLength() );
      wcstombs( pchDwgPath, dwgPath.c_str(), dwgPath.getLength() );
      pchLayoutName[ strLayoutName.getLength() ] = '\0';
      pchDwgPath[ dwgPath.getLength() ] = '\0';

      if( retValue == ::exOk )
        tmp.format("Success: File \"%s\" layout \"%s\" has been exported to hoops.\r\n", pchDwgPath, pchLayoutName);
      else
      {
        tmp.format("Fail   : File \"%s\" layout \"%s\" hasn't been exported to hoops.\r\n", pchDwgPath, pchLayoutName);
      }
	  
       delete[] pchDwgPath;
       delete[] pchLayoutName;

       printf( "%s", tmp);
       pLayIter->next();
    }
  }
  catch(...)
  {
    ::odUninitialize();
    return 1;
  }

  ::odUninitialize();
  return 0;  

For detailed information about export parameters, see Export parameters.

The exportHoops() function returns an error code that can be used for checking whether the export process successfully finished. Also you can use the exportHoopsErrorCode() function which returns error message text:


OdUInt32 retValue = exportHoops(params);
if (retValue != ::exOk)
{
	OdString errMes = exportHoopsErrorCode(retValue);
	printf("\nexportHoops error returned : 0x%x. \n%s", (unsigned) retValue, (const char*)errMes);
}

Export errors are described below.

Identifier Error code Error description
exOk 0x00000000 Export finished successfully.
exInternalError 0x00010000 Export failed: Internal exception occurred.
exFileSavingError   Export failed: Error occurred while writing to an output .hsf or .hmf file.
exNullDatabase   Export failed: Invalid database pointer.
exOdError 0x00020000 Export failed: ODA base class error occurred.
exLastErrorNum 0xFFFFFFFF Number of the last error that occurred.

Export parameters

The HOOPS export process can be managed with a set of parameters that determine how the export should be executed.

Export parameter Parameter name Description
Database pDb Pointer to drawing database that is to be exported.
Output file name strFileName Full name of the exported .hsf or .hmf file.
HOOPS creating flags flags A set of flags that determine options for the created HOOPS file. These options are not for writing the HOOPS Stream provided by the HOOPS API, but instead they are a set of options for the exported drawing. See Export flags for additional information.
Background color background Background color of the output HOOPS file. White is the default value.
Palette pPalette Palette to be used for the output HOOPS file. If not specified (NULL), one of two default palettes will be used depending on the background color.
Setting camera option bSetCamera Determines whether a camera (viewpoint) is set in the output HOOPS file.
Reset the HOOPS system option bResetSystemExport Used for utility testing and must be omitted in user code.
Current layout export option bExportCurrentLayout Determines whether only the current layout of the input drawing will be exported (true). If it is switched off (false), all layouts are exported.
Key for starting segment of HOOPS file iStartKey Determines a segment that must be opened for writing data during the export process.
Export file type iExportFileType Determines what type of file must be exported: 1 (DWG_FILE_TYPE) for a .dwg file or 2 (DGN_FILE_TYPE) for a .dgn file.

Export flags

HOOPS Export functionality supports several option flags:

  • Exporting True Type Font text as geometry (TTF_TEXT_AS_GEOMETRY, value 1)
  • Exporting SHX font text as geometry (SHX_TEXT_AS_GEOMETRY, value 2)
  • Zoom to Extents mode (ZOOM_TO_EXTENTS, value 4)

There are two font types that can be used for text:

  • TrueType fonts – These fonts are used on Microsoft® Windows® platforms.
  • SHX fonts – Internal font format for .dwg files.
  • Text from the original drawing can be exported to a HOOPS Stream either as geometry (when symbols are drawn as collections of primitives) or using internal facilities of the HOOPS Stream format. The TTF_TEXT_AS_GEOMETRY flag enables True Type font text to geometry conversion, and the SHX_TEXT_AS_GEOMETRY flag enables SHX font text to geometry conversion.

    The ability of setting page parameters for the output PDF document depends on whether Zoom to Extents mode is switched on or off:

  • When Zoom to Extents mode is on, page parameters for the output HOOPS Stream File can be customized, for example, with a Page Setup dialog. So the user can set page size and other page parameters only if the Zoom to Extents mode is switched on.
  • When Zoom to Extents mode is off, the page setup parameters are taken from the layout's properties and the user can't change them.
  • Example applications

    Drawings SDK contains sample applications which show how to use HOOPS export functionality in user applications:

    • OdaHoopsDemo – An application implementing working with HOOPS Stream Format functionality. Export functionality is implemented in loadToHoops() methods for the CDgnDumper and CDwgDumper classes.
      Source files for the OdaHoopsDemo application are located in Drawing\Examples\win\OdaHoopsDemo.
    • OdaMfcApp – A sample application based on the MFC class library, which contains the HOOPS export feature and provides a graphical user interface (GUI) for setting HOOPS export parameters. Export functionality is implemented in the OnExportHoops() method of the COdaMfcAppDoc class.
      Source files for OdaMfcApp are located in Drawing\Examples\win\OdaMfcApp.
    Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.