Home
Reply
Contributor
Sarvnaz
Posts: 25

Comparing two .sab files in ACIS programatically

[ Edited ]

One of my customers ran had a question on this subject, so I decided to post the response on this site. Sometimes, there might be a need to compare to .sab files programatically. In that case, you might need to skip over the header information and just compare the rest of the file. In cases like this, it is better to compare these files in memory rather than just diff the files. In order to skip the header information while writing the .sab files, please read the following:

 

In ACIS, we have a class called BinaryFile. The BinaryFile class has a virtual method called write which writes the given data. You can modify this method to skip over the header information. I have shown how this is done in the snippet of code below. After this is done, when writing the 2 .sab files, the header information is skipped and only the rest of the file is written which then can be compared. Note that if the header information changes from ACIS version to version, this code might need to be modified to accomodate the new change.

 

This code is an example straight out of our documentation. I have just modified it to skip the header information.

 

 

class MemoryFile : public BinaryFile {

private:

     char * name; // The name of the part.

     char * data; // The pointer to the data.

     size_t size; // The current size of the data block.

     FilePosition position; // Current read/write position.

public:

     char * get_data( void )

       {

             return data;

       }

     MemoryFile( char * in_name = NULL )

          : name(NULL), data(NULL), size(0), position(0) {

          if( in_name != NULL ) // Copy the input name.

               name = ACIS_STRDUP( in_name);

     }

     ~MemoryFile() {

          if( name != NULL )

               ACIS_FREE( name); // Release the memory

          if( data != NULL )

               ACIS_FREE( data );

          name = NULL; data = NULL; size = 0; position = 0;

     }

     size_t read( void *buffer, size_t length, logical swap ) {

          if( size == 0 )

               length = 0; // Nothing to read.

          if( length > size - position ) // Do not read

               length = size - position; // passed the end.

          if( length ) {

               memcpy( buffer, data + position, length );

               position += length; // Update read position.

          }

          return length;

     }

 

     void write( const void *buffer, size_t length, logical swap ) {

             static int count;

             count++; //skipping over the header info

             if ( count < 15 )

                   return;

          if( size == 0 ) // Initial call, get some memory.

               data = (char*) ACIS_MALLOC( size = 1024 );

          if( length > size - position )

               data = (char*) // We need more memory.

                    ACIS_SAFE_REALLOC( data, size, size *= 2 );

          if( length ) {

               memcpy( data + position, buffer, length );

               position += length; // Update the write position.

          }

             

              

       }

     FilePosition set_mark() { return position; }

     FilePosition goto_mark( FilePosition file_pos ) {

          if( file_pos == -1 || file_pos > size )

               return position = size; // Set to end of data.

          else

               return position = file_pos;

     }

};

 

Contributor
Sarvnaz
Posts: 25

Re: Comparing two .sab files in ACIS programatically

For more information on saving data to media other than steam files, please refer to our documentation here: http://doc.spatial.com/index.php/HowTo:Save_and_Restore_ACIS_Model_Data_to_Media_Other_Than_Stream_F...