/*----------------------------------------------------------------------------- File: UgFundCsysTrf.c Description: demo coordinate transformations PTC File Date Version Author Vers Comment --------- ------- -------- ----- --------------------------------------------- 04-Dec-97 H-02-02 Philippe $$1 created, fixed, error checking, print to file, ... -----------------------------------------------------------------------------*/ /*---------------------- Pro/Toolkit Includes ------------------------*/ #include #include #include #include #include #include /*---------------------- Pro/Develop Includes ------------------------*/ #include /*---------------------- Application Includes ------------------------*/ #include /*---------------------- Function Prototypes -------------------------*/ ProError UserScreen2DrwExample(); ProError UserSolid2ScreenExample(); /*------------------------- External Data ----------------------------*/ extern void UserScreenToDwg(); extern void UserSolidToScreen(); extern int UserMakeSelections(); ProError UserSolid2ScreenExample() { ProError err; ProMdl model; ProMdlType type; ProSurface surface; ProModelitem p_mdl_item; ProPoint3d solid_point, screen_point; ProSolid solid; FILE *fp; ProPath path; /*---------------------------------------------------------------------*\ Get the current model and check if it is a solid \*---------------------------------------------------------------------*/ err = ProMdlCurrentGet( &model ); ERROR_CHECK( "UserSolid2ScreenExample", "ProMdlCurrentGet", err ); if ( err != PRO_TK_NO_ERROR ) return ( err ); err = ProMdlTypeGet( model, &type ); ERROR_CHECK( "UserSolid2ScreenExample", "ProMdlTypeGet", err ); if ( (type != PRO_MDL_PART) && (type != PRO_MDL_ASSEMBLY) ) return ( err ); solid = (ProSolid)model; /*---------------------------------------------------------------------*\ Let the user select a surface and extract the selected point \*---------------------------------------------------------------------*/ UserMakeSelections( &surface, &p_mdl_item, solid_point ); /*---------------------------------------------------------------------*\ Transform from Solid to Screen Coordinates \*---------------------------------------------------------------------*/ UserSolidToScreen( solid, solid_point, screen_point ); /*---------------------------------------------------------------------*\ Write the results to a file and display it \*---------------------------------------------------------------------*/ fp = fopen( "coord_trans.dat", "w" ); if ( fp != NULL ) { fprintf( fp, "You picked a point with these coordinates:\n"); fprintf( fp, "\tX: %f\n", solid_point[0]); fprintf( fp, "\tY: %f\n", solid_point[1]); fprintf( fp, "\tZ: %f\n", solid_point[2]); fprintf( fp, "\n" ); fprintf( fp, "Transformed to screen coordinates:\n"); fprintf( fp, "\tX: %f\n", screen_point[0]); fprintf( fp, "\tY: %f\n", screen_point[1]); fprintf( fp, "\tZ: %f\n", screen_point[2]); fclose (fp); ProStringToWstring( path, "coord_trans.dat" ); err = ProInfoWindowDisplay( path, NULL, NULL ); ERROR_CHECK( "UserScreen2DrwExample", "ProInfoWindowDisplay", err ); } return( PRO_TK_NO_ERROR ); } ProError UserScreen2DrwExample() { ProError err; ProMdl model; ProMdlType type; Prohandle drawing; ProFileName msgfil; ProPoint3d position, drw_point; ProMouseButton button_pressed; FILE *fp; ProPath path; /*---------------------------------------------------------------------*\ Get the current model and check if it is a drawing \*---------------------------------------------------------------------*/ err = ProMdlCurrentGet( &model ); ERROR_CHECK( "UserScreen2DrwExample", "ProMdlCurrentGet", err ); if ( err != PRO_TK_NO_ERROR ) return ( err ); err = ProMdlTypeGet( model, &type ); ERROR_CHECK( "UserScreen2DrwExample", "ProMdlTypeGet", err ); if ( type != PRO_MDL_DRAWING ) return ( err ); drawing = (Prohandle)model; /*---------------------------------------------------------------------*\ Prompt the user for a menu pick and get coordinates \*---------------------------------------------------------------------*/ ProStringToWstring( msgfil, "msg_ugfund.txt" ); err = ProMessageDisplay( msgfil, "USER Pick point on the screen" ); ERROR_CHECK( "UserScreen2DrwExample", "ProMessageDisplay", err ); err = ProMousePickGet( PRO_ANY_BUTTON, &button_pressed, position ); ERROR_CHECK( "UserScreen2DrwExample", "ProMousePickGet", err ); /*---------------------------------------------------------------------*\ Transform the screen coordinates to drawing coordinates \*---------------------------------------------------------------------*/ UserScreenToDwg( drawing, position, drw_point ); /*---------------------------------------------------------------------*\ Write the results to a file and display it \*---------------------------------------------------------------------*/ fp = fopen( "coord_trans.dat", "w" ); if ( fp != NULL ) { fprintf( fp, "You picked a point with these coordinates:\n"); fprintf( fp, "\tX: %f\n", position[0]); fprintf( fp, "\tY: %f\n", position[1]); fprintf( fp, "\tZ: %f\n", position[2]); fprintf( fp, "\n" ); fprintf( fp, "Transformed to drawing coordinates:\n"); fprintf( fp, "\tX: %f\n", drw_point[0]); fprintf( fp, "\tY: %f\n", drw_point[1]); fprintf( fp, "\tZ: %f\n", drw_point[2]); fclose (fp); ProStringToWstring( path, "coord_trans.dat" ); err = ProInfoWindowDisplay( path, NULL, NULL ); ERROR_CHECK( "UserScreen2DrwExample", "ProInfoWindowDisplay", err ); } return ( PRO_TK_NO_ERROR ); }