• Technical Overview
  • Release Notes
  • Reference Manual
  • HOOPS Visualize
TechSoft3d

HOOPS RealDWG Integration

1.0 Using the RealDWG HIO Component

  • 1.1 Rebuilding the HIO Component

2.0 Supported Entities

  • 2.1 DWG Units
  • 2.2 DWG Font Handling

3.0 Input Handler Options

4.0 Integrating Directly with RealDWG

5.0 Mapping Between HOOPS/3dGS and DWG Entities

6.0 Platform Support

7.0 Required Libraries


IMPORTANT NOTE: As of HOOPS Visualize v20.00, the RealDWG HIO component has been refactored into a more robust interface called HIO DWG2 and the DWG interface described on this page has been deprecated. Please see the HIO DWG2 page here.

1.0 Using the RealDWG HIO Component

The RealDWG Libraries are the only native DWG/DXF read/write libraries supplied by Autodesk. To use this integration, developers are required to license the RealDWG Toolkit. Please contact a Tech Soft 3D representative for licensing details.

To use the HOOPS/HIO component for RealDWG, please follow the steps below:

  1. Create a hio_plugins directory in your application's working directory.
  2. Copy the hio_dwg.hio file found in <hoops>/bin/<platform>/hio_plugins/hio_dwg to the hio_plugins directory created in the previous step.
  3. Ensure that the RealDWG SDK is installed on your system and in your path.
  4. Run your application.

During start-up, when HOOPS/MVO finds the RealDWG HIO component in your application's path, it will perform the following steps:

  1. Load in the necessary RealDWG libraries.
  2. Create the appropriate input handler.
  3. Register this handler and the associated file extensions to the HIOManager.

Once the RealDWG HIO component is successfully loaded, your application will be able import RealDWG files without having to recompile HOOPS. To utilize the extensive services available in the RealDWG toolkit, you must compile against the RealDWG libraries directly and follow the steps described in 4.0 Integrating Directly with RealDWG.

1.1 Rebuilding the HIO Component

The RealDWG HIO component was built against against a specific version of RealDWG. If you want your application to run against another version of RealDWG, we recommend that you rebuild the RealDWG HIO component with that version of the library. To do so, simply open the hio_dwg_vc<version>.vcproj project located in the <hoops>/Dev_Tools/hoops_hio/hio_dwg/source. Be sure to set the environment variable REALDWG_SDK_DIR to point to the root of your RealDWG installation before you begin building. Once the project is built against the correct libraries, an .hio file will be created. Note that you may face some obstacles building against a different version of the RealDWG if interfaces are not compatible with the original libraries that the HIO component was built against.

2.0 Supported Entities

All entities found in RealDWG are supported by HOOPS except for:

  • AcDbWipeOut
  • Custom Line Pattern

2.1 DWG Units

When a RealDWG model is imported into HOOPS, the model units are also imported. As of HOOPS version 19.01, this information can be found in the "model_information" segment under the model key as a HOOPS User_Option called "cad units". For example, if the user option value is "cad units =Inches", this means that one unit length of the imported entity is equivalent to one inch. The possible units are as follows:

  • Inches
  • Feet
  • Miles
  • Millimeters
  • Centimeters
  • Meters
  • Kilometers
  • Microinches
  • Mils
  • Yards
  • Angstrom
  • Nanometers
  • Microns
  • Decimeters
  • Dekameters
  • Hectometers
  • Gigameters
  • Astronomical
  • Light Years
  • Parsecs
  • Undefined Units

For backward compatibility with HOOPS versions prior to 19.01, the DWG units information is also stored in a segment underneath the model key, called "info", and is stored in the "dwg_unit" User_Option.

2.2 DWG Font Handling

During the im-port of a DWG that contains text, any fonts specified in the DWG file must be on the system because fonts can not be embedded in a DWG file. If the importer does not find the given font, the text will be drawn with the default HOOPS font. This can be modified using Set_Text_Font.

The ReadDWG HIO component does not import custom AutoCAD fonts (.shx), since RealDWG does not provide any APIs to decode such fonts. DWG text that is specified to use such fonts will also be drawn with the default HOOPS font.

3.0 Input Handler Options

Within HOOPS/MVO, a variety of input options available to facilitate the importing process. For instance, you can determine how DWG visualization information is represented in the HOOPS scene graph with options like HInputHandlerOptions::m_Deviation and HInputHandlerOptions::m_numIsolines.

The HInputHandlerOptions::m_Deviation is the maximum allowable difference in world space between the true mathematical surface being imported and the tesselated surface that will be rendered in HOOPS. For instance, if the deviation is set to 1.0, the surfaces in HOOPS would be comparatively more tesselated than if the deviation was the default value of 10.0. Specifying a value for HInputHandlerOptions::m_numIsolines option lets you determine the number of isolines for surfaces like cylinders, spheres and tori. Setting this option to zero will suppress isolines.

In addition to settings that help determine the representation of your visualization data, there are also options for importing metadata. When the HInputHandlerOptions::m_bImportMetadata flag is set to true, the xdata, including entity, layer and group names, found in your DWG file are imported as user options attached to the associated segment. Some DWG files have large amounts of xdata. Consequently, you might want to load only the metadata that is relevant to your application. To do this, you can populate the HInputHandlerOptions::m_listRegAppNames with a list of registered application names. Thus, only metadata associated with these registered applications are imported. Note that HInputHandlerOptions::m_listRegAppNames is only applicable when HInputHandlerOptions::m_bImportMetadata is true.

For some users, information of interest in a RealDWG is the handle id information associated with every database-resident DWG entity. These handle ids are persistent from session to session. To import handle ids, set the HInputHandlerOptions::m_bAttachDWGHandles flag to true. This will tell HOOPS to import the handle ids as user options and attach them to the associated segment.

Along with metadata information and handle ids, wireframe representations for BREP solids can also be imported. To do this, set the HInputHandlerOptions::m_bImportWireframeForBrep flag to true. The default value for this flag is false.

In RealDWG, models often come with one or more layouts. This information could be useful or even crucial when importing to HOOPS. To enable the importation of layouts, set the HInputHandlerOptions::m_bImportAllLayouts to true. When this flag is enabled, HOOPS imports all Model_Space and Paper_Space layouts. Model_Space will have visibility enabled while all other layouts will have visibility set to off. If you have only interested in importing a limited number of layouts, you can list them in HInputHandlerOptions::m_listDWGLayouts. HOOPS will then only import those layouts. Note that if you have HInputHandlerOptions::m_bImportAllLayouts enable, this will override your HInputHandlerOptions::m_listDWGLayouts list.

When a DWG file is imported into the HOOPS database, the DWG file is opened using the RealDWG toolkit. As the DWG file is being read, HOOPS imports the data into the HOOPS database. For DWG files with a large number of SOLID3D entities, simultaneously reading and importing can consume a significant amount of memory causing your application to appear unresponsive to user interaction. For this situation, HOOPS offers the HInputHandlerOptions::m_bInputViaHSF option. When this flag is set to true, HOOPS imports DWG files in the following way:

  1. Reads the DWG file via the RealDWG toolkit.
  2. Writes the data into an HSF file.
  3. Shuts down the the RealDWG toolkit.
  4. Loads in the HSF file.

Whenever there is an xref, a new hsf file is created. As a result, there is a one to one mapping between the DWG files and the HSF files. HOOPS will attempt to remove any cyclical references and resolve missing locations for any xrefs that are found.

When there is a request to import a DWG file and HOOPS finds that the file has already been imported via HSF, it will compare the timestamp of the HSF file with the DWG file. If the HSF file's timestamp is later, HOOPS will forego re-importation. To force reimportation of a DWG file, set the HInputHandlerOptions::m_bForceReimport flag to true.

The HOOPS RealDWG imported implements the progress and error importing interfaces. Thus, during importation, you can poll using HInputHandler::GetInputProgress to get the current progress information or register as a callback to get this information via HInputHandler::SetInputProgressNoticeCallback.

The following code sample shows how you can set options for the HIOUtilityDWG input handler.

HInputHandlerOptions dwg_input_options;

  dwg_input_options.m_pExtendedData = (void*) p_dwg_textures_dir;
  
  //Importing DWG information into an HSF file before loading it into the HOOPS database
  dwg_input_options.m_bInputViaHSF = true;
  
  //Setting the amount of tesselation for imported surfaces
  dwg_input_options.m_Deviation = 10;
  dwg_input_options.m_bImportMetadata = true;

  //Creating a list of registered applications for metadata importation.
  char* XDataNames[] = 
  {
    "CPM",
    "CPD1",
    "CPD2",
    "CPD3",
    "CPD4",
    "CPD5",
    "CPD6"
  };

  for(int x = 0;x<_countof(XDataNames);x++)
 
  vlist_add_last(dwg_input_options.m_listRegAppNames,(void*)XDataNames[x]);

  dwg_input_options.m_pHBaseView = view;

  view->GetModel()->Read(FileName, 0, true, &dwg_input_options);

4.0 Integrating Directly With RealDWG

The RealDWG HIO component allows developers to easily import visualization information into the HOOPS database. However, DWG files also contain more than just visualization information. If your application needs to access/manipulate the extensive information found in DWG files and/or utilize the full range of the RealDWG library services, you will require a tighter integration than what the RealDWG HIO component can provide.

Before you begin integrating directly with the RealDWG libraries, we recommend that you ensure that have licensed and installed the RealDWG Toolkit on your system. To proceed with the integration, follow the steps below:

  1. Set the REALDWG_SDK_DIR Environment Variable to point to the root of your RealDWG Installation.
  2. Add files HIOUtilityDWG.h/.cpp and HDWGHelper.h/.cpp to your project. These files are located in the Dev_Tools/hoops_hio/hio_dwg/source directory of your HOOPS installation. Refer hio_dwg_vc80.vcproj in Dev_Tools/hoops_hio/hio_dwg/source directory
  3. Add the following directory paths to your additional include folders' list '$(REALDWG_SDK_DIR)/include'.
  4. Add HOOPS_DWG_IO to your preprocessor declarations.
  5. Add '$(REALDWG_SDK_DIR)/lib' to your additional linker directories.
  6. Add rcexelib.obj,acgiapi.lib,acdb17.lib,acge17.lib,rxapi.lib,acismobj17.lib, odbc32.lib,odbccp32.lib,urlmon.lib,wininet.lib as additional dependencies.
  7. Ensure that the '$(REALDWG_SDK_DIR)' is included on your path.

Once you have completed the above steps, you do not need to rely on the RealDWG HIO component anymore. Please remove the associated .hio file from the hio_plugins directory in your application's working directory. Note that in a direct integration, you must register HIOUtilityDWG via HIOManager::RegisterInputHandler so that the HBaseModel::Read function can recognize that the .dwg file format is supported. For more information on HOOPS/MVO file input/output architecture, please see section 4.0 File Input/Output and the I/O Manager of the HOOPS/MVO Programming Guide.

Now you can begin working with HIOUtilityDWG class which is the HOOP/MVO's input handler for RealDWG. The code sample below shows how to instanciate the input handlers and import a DWG file.

HIOUtilityDWG dwg_reader;
HFileInputResult result = dwg_reader.FileInputByKey("c:\\temp\\myFile.dwg", m_pHView->GetModelKey(), NULL);

5.0 Mapping Between HOOPS/3dGS and DWG Entities

It is very important for developers to be able to map between objects within their HOOPS/3dGS database and the corresponding entities within the RealDWG database. To do this, developers should use the HIOConnector class. When you call HIOConnector::GetKernelEntity and pass a HOOPS key, the HIOConnector will return a pointer to the corresponding object in the RealDWG database. Alternatively, if you provide a pointer to a RealDWG object when calling HIOConnector::GetHoopsEntity, the HIOConnector will return the key(s)of object(s) within the HOOPS/3dGS database which are used to represent that object.

Here is some sample code which shows you how to use the HIOConnector capabilities.

    char FileName[1024];

    sprintf(FileName, "%s", "c:\\hoops\\third_party_files\\Small-Metric-Test.dwg");
    HInputHandler * handler = HDB::GetHIOManager()->GetInputHandler("dwg");
    HC_KEY modelkey = m_pHView->GetModelKey();

    HInputHandlerOptions options;
    HIOConnector *connector = HDB::GetHIOManager()->CreateConnector("dwg");
    options.m_pConnector = connector;

    HFileInputResult result = handler->FileInputByKey(FileName, modelkey, &options);

    m_pHView->FitSegment(modelkey);
    m_pHView->Update();

    HC_Open_Segment_By_Key(modelkey);
    HC_Begin_Contents_Search("...", "shells");
    char temp[256];
    HC_KEY key;
    while (HC_Find_Contents(temp, &key))
    {

        void *dwg_entity = connector->GetKernelEntity(key);
        HC_KEY newkey = connector->GetHoopsEntity(dwg_entity);

        if (newkey == key)
            AfxMessageBox(_T("Same Roundtripped Key"));
    }
    HC_End_Contents_Search();
    HC_Close_Segment();

6.0 Platform Support

Our integration is only supported on the platforms supported by the RealDWG Toolkit. Currently, platform support is available for the Windows platform using the Visual Studio 2008 32 and 64 bit. For the most up to date information, please refer to the RealDWG Documentation.

7.0 Required Libraries

For Release 19.0 and 19.1, the RealDWG HIO component requires RealDWG 2012. While we are not officially supporting RealDWG 2011 and thus cannot field any issues logged against it, we have done some testing against that version and it should work correctly. Therefore, developers wishing to use RealDWG 2011 can recompile the RealDWG HIO module.

For Visual Studio 2010, RealDWG 2013 is the supported version.