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

HOOPS RealDWG Integration

As of HOOPS Visualize v19.30, the RealDWG HIO component has been refactored into a more robust interface called hio_dwg2. The component is still in beta status, but developers are encouraged to experiment with the new interface. Notes specifically related to hio_dwg2 can be found on this page.

Handling DWG Entities

Each DWG entity has a unique handle associated with it. The handle is unique within the database, and is the same session after session. The handle is represented by an unsigned 64-bit integer. Handles exhibit the following relationships:

  • One DWG handle corresponds to one or more HOOPS keys.
  • One HOOPS key corresponds to only one DWG handle.
  • Two different DWG handles cannot refer to the same HOOPS key.

When associating handles to keys, keep the following in mind:

  • every time a piece of HOOPS geometry is inserted, it is opened by key, and a user option containing the DWG handle identifier this piece of geometry belongs to is set on it.
  • a segment called "handles" is created during import and placed directly under the MVO model segment.
  • as geometry is read in, a reference to it is placed in a subsegment of the "handles" segment, named after the DWG handle the geometry belongs to.

To relate a DWG handle to a HOOPS key, you would do the following:

Case A - You have a HOOPS key and wants to obtain the related DWG handle:

  1. Open geometry by key
  2. Use Show_One_User_Data to read the data stored at index 0
  3. The data returned by Show_One_User_Data will contain the DWG handle.

Example:

Adesk::UInt64 handle;
HC_Open_Geometry(key);
HC_Show_One_User_Data(0, &handle, sizeof(handle);
HC_Close_Geometry();

Case B - You have a DWG handle and want to obtain the related HOOPS key(s):

  1. Open the "handles" segment and search for the segment whose name matches the DWG handle.
  2. Search the segment for reference geometry, and obtain its original key

Using a hash to improve speed

Starting with Visualize 19.33, the developer has the option to query DWG handles in an optimized way. The process described in the previous section will always work, however, for large scene graphs, the processing time can be long. Using the HIO connector to associate DWG handles to Visualize keys is faster because it uses a hash lookup instead of searching the segment tree. There is a performance penalty, however, when the hash is generated.

This is how to obtain a connector:

HInputHandler * handler = HDB::GetHIOManager()->GetInputHandler("dwg");
handler->FileInputByKey("filename.dwg", view->GetModelKey(), options);
HIOConnector * connector = HDB::GetHIOManager()->CreateConnector("dwg"); 

All the associated functions (see list, below) have an optional parameter at the end. Passing the model key as that parameter causes the hash to be generated (or regenerated, if the geometry has been modified). Therefore, the first time you use this hash, you should always pass the model key.

The DWG connector can use the following functions:

  1. HC_KEY GetHoopsEntity(void * pKernelEntity, HC_KEY modelKey = INVALID_KEY);

    This function returns a HOOPS key associated with a DWG handle. Causes hash to be regenerated.

    Sample usage:

    unsigned int handle = 570;
    HC_KEY key = connector->GetHoopsEntity((void *)handle, view->GetModelKey()); 
    

  2. void * GetKernelEntity(HC_KEY key, HC_KEY modelKey = INVALID_KEY);

    This function returns a DWG handle associated with a HOOPS key. Causes hash to be regenerated.
    Sample usage:

    void * kernelEntity = connector->GetKernelEntity(key); 
    

  3. bool GetHoopsEntities(void * pKernelEntity, vlist_s *ret_HoopsKeysList, HC_KEY modelKey = INVALID_KEY);

    Same as GetHoopsEntity, but is used in the case when a DWG handle is associated with more than one Visualize key. Causes hash to be regenerated.
    Sample usage:

    vlist_s * hoopsKeyList = new_vlist(malloc, free);
    connector->GetHoopsEntities((void *)myHandle, hoopsKeyList);
    void * item  = vlist_nth_item(hoopsKeyList, 0);
    void * item2 = vlist_nth_item(hoopsKeyList, 1);
    

  4. bool GetKernelEntities(HC_KEY key, vlist_s *ret_KernelEntitiesList, HC_KEY modelKey = INVALID_KEY);

    Same as GetKernelEntity

  5. void AddConnection(HC_KEY key, void* pKernelEntity, HC_KEY modelKey = INVALID_KEY);

    Adds a connection between a key and a handle. Does not cause the has to be regenerated.

Layers and Layouts

Layers are treated as attribute containers. Whatever attributes are in the layer are applied to the geometry with a HOOPS Visualize style. This means that you can open the layer segment and override the attributes. If the geometry has attributes set on it explicitly, then the explicit attributes override the layer attributes. There's a case when the attributes of geometry are inherited from the block reference. Those attributes cannot be overridden by the layer. The layers can be found in the segment "layer table". The layers are URI encoded, to allow unicode characters in the segment names, and are prefixed with an underscore '_' character.

Layouts can be found in the "layouts" segment. The layouts are also URI encoded and prefixed with an underscore. Each layout has user options, "extents_min" and "extents_max" set defining the extents in 2D space. Each layout also sets the heuristic "exclude bounding" and sets the visibility to "off" except for the currently active/visible layout. The currently active/visible layout does not set visibility and does not set the exclude bounding heuristic. Iterating the visibility of the layouts is done by finding the layout that does not set the visibility, then setting the visibility to off, setting the exclude bounding heuristic, then moving on to the next layout segment and unsetting the visibility and unsetting the heuristics.

Object Enablers

HIO DWG2 allows developers to use object enablers starting with Visualize v19.33. Using object enablers, customers can load DWG files which contain custom entities defined in their own .dbx files.

The only requirement for this to work is that the developer must place the .dbx files and associated DLLs into the same folder as the HIO DLL, so that they can be loaded when DWG2 starts up.

Limitations

Dimensions, annotations, and layouts

It is possible for a DWG file to be stored with uninitialized annotations and layouts. These uninitialized structures don't always exist in the DWG file. In this situation, RealDWG returns them as null pointers. Using its own internal logic, AutoCAD is able to load the uninitialized structures from null pointers, however, Visualize cannot. Therefore, we do not support uninitialized annotations or layouts.

Viewports

Viewports within layouts can be in an 'active' or 'inactive' state. RealDWG doesn't provide any mechanism to find which viewports are active.

Rendering

Although we make every effort to duplicate the rendering results of any file loaded using RealDWG, Visualize cannot exactly match AutoCAD in all cases when it comes time to actually draw. AutoCAD uses its own proprietary rendering engine that handles geometry in its own way. Some examples of differences we have noticed include:

  • tessellation values
  • line weights and line styles
  • font handling