home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 June
/
CHIPCD_6_2000.iso
/
software
/
cad
/
t425l1e
/
t425l1e.exe
/
_002320_
/
IMPORT_.C
Wrap
C/C++ Source or Header
|
1997-06-14
|
14KB
|
414 lines
//------------------------------------------------------------------------------------------------------
// Name : import_.c
// Date : 05.03.1997 Author : SM System : Win32
//------------------------------------------------------------------------------------------------------
// This file contains the language-independent implementation of the module IMPORT_.DLL. All texts and
// resources that are language-dependent are located in an additional IMPORT.DLL, whose sources can be
// found in the subdirectories \E (for English) and \D (for German).
//------------------------------------------------------------------------------------------------------
#define TOSO_MODULE_VERSION 420 // Required version of Toso Interface
//------------------------------------------------------------------------------------------------------
#define USER_DATA_ID "1.00-1996-11-20"
#define TXT_ID_HEADER "TommySoftware TXT 1.10"
//------------------------------------------------------------------------------------------------------
#include "windows.h"
#include "windowsx.h"
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "e:\release4\tosoapi4.h" // Toso Interface Definitions
#include "dialog.h"
//------------------------------------------------------------------------------------------------------
typedef struct {
STR32 TimeStamp;
FILENAME FileName;
} INF_HEADER;
//------ Language-dependent texts in IMPORT.DLL --------------------------------------------------------
DLL_IMPORT LPSTR
eStartUpText [],
eDialogText [],
eMessageText [];
//------------------------------------------------------------------------------------------------------
static HINSTANCE hInstDLL, // Instance handle of the main DLL
hLanguage, // Instance handle of the language DLL
hGlobalInst; // Instance handle of the serving application
static HWND hGlobalWnd; // Main window handle of the serving application
//------------------------------------------------------------------------------------------------------
static HBITMAP hBitmap;
static INF_HEADER INFHeader;
static int gError; // Current error status ( 0 = OK )
//------------------------------------------------------------------------------------------------------
BOOL ModuleLoadSettings( void )
{
BOOL Result = FALSE;
if( TosoProfileReadKeyOpen( "IMPORT", FALSE ) ) {
if( TosoProfileReadData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
Result = TRUE;
TosoProfileReadKeyClose();
INFHeader.TimeStamp[31] = 0x00;
if( lstrcmp( INFHeader.TimeStamp, USER_DATA_ID ) )
Result = FALSE;
}
if( !Result ) {
lstrcpy( INFHeader.FileName, eDialogText[1] );
}
return( Result );
}
//------------------------------------------------------------------------------------------------------
BOOL ModuleSaveSettings( void )
{
BOOL Result = FALSE;
if( TosoProfileWriteKeyOpen( "IMPORT", FALSE ) ) {
lstrcpy( INFHeader.TimeStamp, USER_DATA_ID );
if( TosoProfileWriteData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
Result = TRUE;
TosoProfileWriteKeyClose();
}
return( Result );
}
//------------------------------------------------------------------------------------------------------
// This procedure reads a single coordinate pair from the current file. If it finds the last line of the
// file (indicated by the DB_END data block identifier), it returns FALSE without setting gError to a
// non-zero value.
BOOL ModuleReadCoordinate( double* x, double* y )
{
DUMMYSTR Text1, Text2;
short Dummy;
if( gError )
return( FALSE );
wsprintf( Text1, eDialogText[3], TosoFileReadCurrentLine() );
wsprintf( Text2, eDialogText[4], ( TosoFileReadCurrentSize() + 1023 ) / 1024 );
TosoDialogUpdateProgress( Text1, Text2, TosoFileReadCurrentSize(), TosoFileReadTotalSize() );
if( TosoDialogIsCanceled() ) {
gError = 999;
return( FALSE );
}
TosoFileReadShort( &Dummy );
if( Dummy == DB_END )
return( FALSE );
TosoFileReadCommaDouble( x );
TosoFileReadCommaDouble( y );
TosoFileReadSemi();
if( TosoFileReadError() ) {
gError = 2;
return( FALSE );
}
return( TRUE );
}
//------------------------------------------------------------------------------------------------------
// This procedure performs the import. It reads all coordinate pairs from the import file and insert a
// marking for each coordinate pair.
// In addition, it initializes and display a progress indicator window to inform the user about the
// current progress and to allow him to cancel the import. Since the final file size is already known
// in advance, the progress indicator does include a percent bar.
void ModuleImport( HANDLE FileHandle, const LPSTR FileName )
{
FILENAME FileName2;
DUMMYSTR DummyStr;
int Count;
double x, y;
gError = 0;
if( !TosoFileReadInitDisk( FileHandle ) )
return;
if( !TosoFileReadLine( DummyStr, 255 ) ) {
gError = 3;
TosoFileReadExit();
return;
}
TosoFileSplitName( FileName, NULL, FileName2 );
wsprintf( DummyStr, eDialogText[2], FileName2 );
TosoDialogShowProgress( eDialogText[0], DummyStr, TRUE );
if( ModuleReadCoordinate( &x, &y ) ) {
Count = 0;
do {
if( Count == 0 )
TosoObjectOpen( OBJ_MARK );
TosoObjectAddPoint( DB_POINT_MARK, x, y );
Count++;
if( Count >= POINTS_PER_OBJECT ) {
if( !TosoObjectFastInsert() ) {
gError = 998;
goto _stop;
}
Count = 0;
}
} while( ModuleReadCoordinate( &x, &y ) );
if( Count > 0 )
if( !TosoObjectFastInsert() )
gError = 998;
TosoFileReadSemi();
}
_stop:
TosoFileReadExit();
TosoDialogHideProgress();
}
//------------------------------------------------------------------------------------------------------
// This DLL entry procedure must exist in any DLL to be used in Win32. Since our DLL does all necessary
// initialization in its TosoModuleInit() procedure, this procedure is quite empty.
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD Reason, LPVOID Dummy )
{
switch( Reason ) {
case DLL_PROCESS_ATTACH:
hInstDLL = hInstance;
break;
case DLL_PROCESS_DETACH:
hInstDLL = NULL;
break;
}
return( TRUE );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when the module is loaded by the serving application. Its main tasks are:
// - Checking whether it is compatible with the given InterfaceVersion
// - Checking whether it is licensed to the given serial number (optional)
// - Storing of the serving application's instance and main windows handle for further use
// - Loading of the language-dependent library
// - Filling in the module ID structure whose address is passed in ModuleID
// - Loading of options from the registry database
// - Loading profiles
// - Allocating any static memory required
DLL_EXPORT int TosoModuleInit( const LPSTR SerialNumber, HINSTANCE hMainInst, HWND hMainWnd,
int InterfaceVersion, MODULE_ID* ModuleID )
{
if( InterfaceVersion < TOSO_MODULE_VERSION ) {
MessageBox( hMainWnd, eMessageText[0], eDialogText[0], MB_OK );
return( 0 );
}
hGlobalInst = hMainInst;
hGlobalWnd = hMainWnd;
hLanguage = LoadLibrary( "IMPORT.DLL" );
hBitmap = LoadBitmap( hLanguage, "IDB_COMMAND" );
ModuleID->OwnerID = DB_OWNER_TOSO;
ModuleID->ModuleID = 0x1000;
ModuleID->ModuleCTRL = MODULECTRL_ALL;
ModuleID->ModuleProc.InputPointInitProc = (TOSOINPUTPOINTINIT_PROC) NULL;
ModuleID->ModuleProc.InputPointMoveProc = (TOSOINPUTPOINTMOVE_PROC) NULL;
ModuleID->ModuleProc.InputPointExitProc = (TOSOINPUTPOINTEXIT_PROC) NULL;
ModuleID->ModuleProc.InputDisplayProc = (TOSOINPUTDISPLAY_PROC) NULL;
ModuleID->ModuleProc.InputParameterProc = (TOSOINPUTPARAMETER_PROC) NULL;
ModuleID->ModuleProc.InputCancelProc = (TOSOINPUTCANCEL_PROC) NULL;
ModuleID->ModuleProc.InputFinishProc = (TOSOINPUTFINISH_PROC) NULL;
ModuleID->ModuleData.Type = MODULETYPE_IMPORT;
ModuleID->ModuleData.InputData.CommandMode = COMMAND_DIRECT;
ModuleID->ModuleData.MenuData.MenuEntry = eStartUpText[1];
ModuleID->ModuleData.MenuData.Description = eStartUpText[2];
ModuleID->ModuleData.IconHandle = hBitmap;
ModuleID->ModuleData.IconXOffset = 0;
ModuleID->ModuleData.IconYOffset = 0;
ModuleID->ModuleData.IconMode = 0;
ModuleID->CommandData = NULL;
ModuleID->VendorData = NULL;
ModuleID->FileType = eStartUpText[4];
ModuleID->FileExtension = eStartUpText[5];
ModuleID->FileDefault = eStartUpText[6];
ModuleLoadSettings();
return( TOSO_MODULE_VERSION );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when the module is removed by the serving application. Its main tasks are:
// - Checking whether anything is to be saved. If so, it should display a message information the user
// about it and allowing him to save those changes.
// - Freeing of all statically allocated memory.
// If this procedure return FALSE, the serving application will not be able to terminate. So please, do
// only return FALSE if shutting down the module now would severely damage or destroy user data.
DLL_EXPORT BOOL TosoModuleExit( void )
{
ModuleSaveSettings();
DeleteBitmap( hBitmap );
return( TRUE );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when the user wants to load a non-TVG drawing using the File>Open command.
// For an import filter, its task is to check whether he knows this type of file, and to load it, if
// possible.
DLL_EXPORT int TosoModuleImport( const LPSTR FileName, BOOL Merge )
{
HANDLE FileHandle;
DUMMYSTR DummyStr;
BOOL Found = FALSE;
SetCursor( LoadCursor( NULL, IDC_WAIT ) );
//
// Step 1: Check whether this file is a valid file containing coordinate pairs.
//
if( TosoFileOpen( &FileHandle, FileName ) ) {
if( !TosoCreationStart() ) {
TosoFileClose( FileHandle );
return( IMPORT_RETURN_ERROR );
}
if( TosoFileRead( FileHandle, DummyStr, TVG_ID_LENGTH + 1 ) == TVG_ID_LENGTH + 1 ) {
DummyStr[TVG_ID_LENGTH] = '\0';
if( !lstrcmpi( DummyStr, TXT_ID_HEADER ) )
Found = TRUE;
}
TosoFileClose( FileHandle );
}
if( !Found )
return( IMPORT_RETURN_UNKNOWN );
//
// Step 2: Try to import the coordinates stored in the file.
//
if( !TosoCreationStart() )
return( IMPORT_RETURN_ERROR );
if( TosoFileOpen( &FileHandle, FileName ) ) {
if( Merge )
TosoUndoInitProcess();
else
TosoDrawingNewFile( TosoDrawingGetActive(), FALSE );
ModuleImport( FileHandle, FileName );
TosoFileClose( FileHandle );
switch( gError ) {
case 999:
MessageBox( hGlobalWnd, eMessageText[2], eDialogText[0], MB_OK );
goto _error;
case 998:
MessageBox( hGlobalWnd, eMessageText[4], eDialogText[0], MB_OK );
goto _error;
case 0:
break;
default:
wsprintf( DummyStr, eMessageText[5], gError, TosoFileReadCurrentLine(), TosoFileReadCurrentSize() );
MessageBox( hGlobalWnd, DummyStr, eDialogText[0], MB_OK );
goto _error;
}
if( Merge )
TosoUndoFinishProcess();
// TosoUndoUpdateLinks(); <- Would only be necessary if blocks or instances had been modified!
TosoDrawWindowAll();
TosoCreationEnd();
return( IMPORT_RETURN_OK );
}
return( IMPORT_RETURN_ERROR );
_error:
if( Merge )
TosoUndoCancelProcess();
else
TosoDrawingNewFile( TosoDrawingGetActive(), FALSE );
TosoCreationEnd();
return( IMPORT_RETURN_ERROR );
}
//------------------------------------------------------------------------------------------------------
// This procedure is called when a module's command is chosen by the user. For an import filter, its
// main tasks are:
// - Parameter editing
// - Help file display
DLL_EXPORT BOOL TosoModuleCommand( int CommandID, int ExecMode )
{
switch( ExecMode ) { // Check which type of action is requested
case MODULEEXEC_HELP: // Display the corresponding help topic
{
FILENAME FileName;
TosoFileApplicationPath( "IMPORT.HLP", FileName );
WinHelp( hGlobalWnd, FileName, HELP_INDEX, 0 );
}
return( TRUE );
case MODULEEXEC_USER: // Edit the options
{
DUMMYSTR Text1, Text2;
TOSO_GET_BUILD_DATE( Text2 );
wsprintf( Text1, eStartUpText[0], Text2 );
MessageBox( GetActiveWindow(), Text1, eDialogText[0], MB_OK );
}
return( TRUE );
case MODULEEXEC_SYSTEM: // Execute the command
// Nothing to do here...
break;
case MODULEEXEC_GET_PROFILE: // Read drawing-dependent data
// Nothing to do here...
break;
case MODULEEXEC_SET_PROFILE: // Write drawing-dependent data
// Nothing to do here...
break;
}
return( FALSE );
}