The 3D ACIS® Modeler (ACIS) is Spatial’s prominent 3D solid modeling engine. 3D InterOp is a CAD data translation framework (Interoperability)

InterOp:Connect/Translation Basics

From DocR19

Jump to: navigation, search

Contents

Basic Translation

Translation is performed by the SPAIConverter object with specification of source and destination documents.

The source document indicates which model is to be translated. The destination document indicates in which format, and where, the translated model is to be created.

Note: The Connect API handles modeler initialization and shutdown operations when and if needed. No additional calls are required for this purpose.

The following example illustrates how to use the SPAIConverter and SPAIDocument objects for translating a CATIA V5 Part file into an ACIS SAT file:

#include "SPAIConverter.h"
#include "SPAIDocument.h"
 
int main()
{
  SPAIDocument src(L"C:\\model.CATPart");
  SPAIDocument dst(L"C:\\model.sat");
 
  SPAIConverter converter;
  converter.Convert(src, dst);
  return 0;
}

Connect determines the type of document to read or to write using the given file extension. In the above example, .sat and .CATPart are recognized as ACIS and CATIA V5 extensions. In some cases where the document is created without a recognized file extension, the SetType method must be used in order to specify the document type. For instance, the file may have no extension, or the document is specified with a file pointer instead of a file path. Many extensions are automatically recognized by Connect, but some are not. Refer to Format and Version Support for a list of supported extensions and their corresponding document types.

The following example illustrates how to use the SetType method for translating an Inventor Part file into an ACIS SAT file:

#include "SPAIConverter.h"
#include "SPAIDocument.h"
 
void main()
{
  SPAIDocument src(L"C:\\model.ipt");
  src.SetType("Inventor");
  SPAIDocument dst(L"C:\\model.sat");
 
  SPAIConverter converter;
  converter.Convert(src, dst);
}


Simple Sample

This sample demonstrates simple translation from an input file to an output file. The input and output format can be specified with the arguments iformat and oformat, respectively.

Usage

Simple -i file -iformat format -o file -oformat format

Options

-i : input file
-o : output file
-iformat : input format
-oformat : output format
-options : options file

Wide Character Processing

Source and destination documents are specified with the SPAIDocument object. In most cases, a document is a file on the file system specified by a file path or a file pointer. InterOp Connect supports file names in both multibyte character set and wide character encodings. You can enable an application to support files with multibyte characters by setting the locale correctly through the application before a call is made to the Connect APIs. For more information, refer to Setting the Locale to Support Files with Multibyte Characters. This article explains how to use wide character files in InterOp Connect.

Note the use of the 'L' before each filename string in the above examples. This system macro will convert the following text given in double quotes into its wide character form and cause the compiler to use the wchar_t version of the constructor for the SPAIDocument class.

Typically, wide character file names will not be given as string literals as shown here, but rather will be specified by the application through user interaction with a GUI or passed in through the command line. Refer to your GUI framework documentation for how to get wide character text from your users. The process of getting wide character text from the command line differs by platform and is described as follows.

Windows

Use the GetCommandLineW() and CommandLineToArgVW() APIs supplied by Microsoft to extract the wide character arguments from the command line as shown in the following example.

Note: The version of the shell you use will need to be Unicode-enabled for this mechanism to work.

#include "windows.h"
#include "ShellAPI.h"
 
void main()
{
    // Get the wide character version of the command line arguments
    wchar_t* cmdLn = GetCommandLineW();
    int convertedArgC( 0 );
    wchar_t** convertedArgV = CommandLineToArgvW( cmdLn, &convertedArgC );
 
    // Parse and use the command line arguments
    ...
 
    // Free the memory for the command line arguments
    LocalFree( convertedArgV );
}

UNIX and Macintosh

UNIX platforms differ from Windows platforms in that you are able to use Unicode for your text without having to use the wide character form string by specifying a Unicode locale for your program. However, if you are working with both Windows and UNIX-based systems, it can be convenient to process all your localized strings in their wchar_t form. The following example shows how you can convert your MBCS command line arguments to their wide character form.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
 
void main(int argc, char *argv[])
{
    // Remember that both char* and wchar_t* strings in UNIX are 
    // interpreted relative to the current locale, so set the 
    // locale to the default codepage.
    setlocale( LC_ALL, "" );
 
    // Allocate memory for the wide character version of the
    // command line arguments.
    wchar_t** convertedArgV = new wchar_t*[argc];
 
    // Convert the char* arguments to their wide character forms
    for ( int i = 0; i < argc; ++i )
    {
        int argStrLen = strlen( argv[i] ); 
        wchar_t* argStr = new wchar_t[ argStrLen + 1 ];
 
        // The system API mbstowcs() will convert char* data to
        // wchar_t* data based on the current locale.
        size_t convertedChars = mbstowcs(argStr, argv[i], argStrLen );
        if ( convertedChars != -1 )
        {
            convertedArgV[i] = argStr;
        }
    }
 
    // Parse and use the command line arguments
    ...
 
    // Free the memory for the command line arguments
    for ( int j = 0; j < argc; ++j )
    {
        delete[] convertedArgV[j];
    }
    delete[] convertedArgV;
}
Personal tools