/* Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved. */ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include <ProToolkit.h> #include <ProIntfData.h> #include <ProGeomitemdata.h> #include <ProMessage.h> #include <ProMenu.h> #include <ProSelection.h> #include <ProSolid.h> #include <ProUtil.h> #include <ProMode.h> /*--------------------------------------------------------------------*\ Pro/DEVELOP includes \*--------------------------------------------------------------------*/ #include "TestError.h" #include "UtilMenu.h" #include "UtilMessage.h" #include "UtilMatrix.h" #include "UtilCollect.h" #include "UtilString.h" #include <ProTKRunTime.h> #include <ProImportfeat.h> #include <TestDbms.h> /*--------------------------------------------------------------------*\ C System includes \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Application macros \*--------------------------------------------------------------------*/ #define DEFAULT_ANGLE_CONTROL 0.5 #define DEFAULT_CHORD_HEIGHT 0.05 #define DEFAULT_STEP_SIZE 0.5 #define CHORD_HEIGHT 0 #define ANGLE_CONTROL 1 #define JOIN_SURFACES 1 #define MAKE_SOLID 2 #define ADD_SOLID 4 /*--------------------------------------------------------------------*\ Application data types \*--------------------------------------------------------------------*/ typedef struct slice_types { ProImportExportFile type; char *button_name; char *file_extension; } SliceTypes; typedef struct raster_settings { ProRasterDepth depth; ProRasterType type; ProDotsPerInch inch; double size[2]; } RasterSettings; /*--------------------------------------------------------------------*\ Application global/external data \*--------------------------------------------------------------------*/ int ProTestImport(ProAppData p_appdata); int ProTestExport(ProAppData p_appdata); int ProTestExportSlice(ProAppData p_appdata); int ProTestExportFileTypeSet(ProImportExportFile *p_type, ProImportExportFile type_value); ProError ProTestSelectExportType( ProImportExportFile *p_type ); ProError ProTestSelectImportType( ProImportExportFile *p_type ); int ProTestPlotfileWrite ( ProAppData p_appdata); int ProTestExportVRML (ProAppData p_appdata); int ProTestRasterMenu(); int ProTestRedefImpfeat(ProMdl *mdl); ProError ProUtilImportfeatFilter(ProFeature *p_feature); extern ProError ProUtilCollectSolidFeaturesWithFilter( ProSolid p_solid, /* In: The solid handle */ ProFeatureFilterAction filter, /* In: Filter function */ ProFeature **p_features ); static SliceTypes sl_types[] = { {PRO_SLA_ASCII_FILE, (char *)"STL ASCII", (char *)"stl"}, {PRO_SLA_BINARY_FILE, (char *)"STL Binary", (char *)"stl"}, {PRO_RENDER_FILE, (char *)"Render", (char *)"slp"}, {PRO_INVENTOR_FILE, (char *)"Inventor", (char *)"iv"} }; /*============================================================================*\ Function: ProTestInterface Purpose: \*============================================================================*/ int ProTestInterface( ProAppData p_appdata) { ProError status; int menu_id; int action; int ProTestImportfeat(); status = ProMenuPush(); TEST_CALL_REPORT( "ProMenuPush()", "ProTestInterface()", status, status != PRO_TK_NO_ERROR ); status = ProMenuFileRegister( (char*)"TkInterface", (char*)"tkinterface.mnu", &menu_id ); TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTestInterface()", status, status != PRO_TK_NO_ERROR ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Import", (ProMenubuttonAction)ProTestImport, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Export", (ProMenubuttonAction)ProTestExport, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Export PS", (ProMenubuttonAction)ProTestPlotfileWrite, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Export Slice", (ProMenubuttonAction)ProTestExportSlice, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Import feat", (ProMenubuttonAction)ProTestImportfeat, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Redef Impfeat", (ProMenubuttonAction)ProTestRedefImpfeat, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Export VRML", (ProMenubuttonAction)ProTestExportVRML, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"Export Raster", (ProMenubuttonAction)ProTestRasterMenu, NULL, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"TkInterface Done", (ProMenubuttonAction)ProMenuDelete, p_appdata, 0 ); ProMenubuttonActionSet( (char*)"TkInterface", (char*)"TkInterface", (ProMenubuttonAction)ProMenuDelete, p_appdata, 0 ); status = ProMenuCreate( PROMENUTYPE_MAIN, (char*)"TkInterface", &menu_id ); TEST_CALL_REPORT( "ProMenuCreate()", "ProTestInterface()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) { status = ProMenuProcess( (char*)"TkInterface", &action ); TEST_CALL_REPORT( "ProMenuProcess()", "ProTestInterface()", status, status != PRO_TK_NO_ERROR ); } status = ProMenuPop(); TEST_CALL_REPORT( "ProMenuPop()", "ProTestInterface()", status, status != PRO_TK_NO_ERROR ); return 0; } /*============================================================================*\ Function: ProTestImport Purpose: Import current model to the foreign format \*============================================================================*/ int ProTestImport( ProAppData p_appdata) { ProError status; ProMdl p_model; ProName wfilename; ProMode mode; ProImportExportFile import_type; p_model = *((ProMdl*)p_appdata); /* Get Pro/E mode */ status = ProModeCurrentGet( &mode ); TEST_CALL_REPORT( "ProModeCurrentGet()", "ProTestImport()", status, status != PRO_TK_NO_ERROR ); ProTestSelectImportType( &import_type ); switch( import_type ) { case PRO_DWG_SETUP_FILE: if( mode != PRO_MODE_DRAWING ) { status = PRO_TK_GENERAL_ERROR; ProUtilMsgPrint( "gen", "TEST %0s", "Drawing mode is required" ); } break; /* case PRO_RELATION_FILE: case PRO_PROGRAM_FILE: case PRO_IGES_SECTION: */ } if( status == PRO_TK_NO_ERROR ) { ProUtilMsgPrint( "gen", "TEST %0s", "Enter import file name [QUIT]:" ); status = ProMessageStringRead( PRO_NAME_SIZE, wfilename ); TEST_CALL_REPORT( "ProMessageStringRead()", "ProTestImport()", status, status != PRO_TK_NO_ERROR ); if( status != PRO_TK_NO_ERROR ) return -1; status = ProInputFileRead( p_model, wfilename, import_type, NULL, NULL, NULL, NULL ); TEST_CALL_REPORT( "ProInputFileRead()", "ProTestImport()", status, status != PRO_TK_NO_ERROR ); status = ProSolidRegenerate( (ProSolid)p_model, PRO_REGEN_NO_FLAGS ); TEST_CALL_REPORT( "ProSolidRegenerate()", "ProTestImport()", status, status != PRO_TK_NO_ERROR ); } else { ProUtilMsgPrint( "gen", "TEST %0s", "Invalid import type" ); } return 0; } /*============================================================================*\ Function: ProTestSelectImportType Purpose: Select the type of file to import \*============================================================================*/ ProError ProTestSelectImportType( ProImportExportFile *p_type ) { ProError status; int menu_id; int action; if( p_type == NULL ) return PRO_TK_BAD_INPUTS; *p_type = PRO_UNDEFINED_FILE; status = ProMenuFileRegister( (char*)"TkImport", (char*)"tkimport.mnu", &menu_id ); TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTestSelectImportType()", status, status != PRO_TK_NO_ERROR ); ProMenubuttonActionSet( (char*)"TkImport", (char*)"RELATION_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_RELATION_FILE ); ProMenubuttonActionSet( (char*)"TkImport", (char*)"IGES_SECTION", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_IGES_SECTION ); ProMenubuttonActionSet( (char*)"TkImport", (char*)"PROGRAM_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_PROGRAM_FILE ); ProMenubuttonActionSet( (char*)"TkImport", (char*)"CONFIG_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_CONFIG_FILE ); ProMenubuttonActionSet( (char*)"TkImport", (char*)"DWG_SETUP_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_DWG_SETUP_FILE ); ProMenubuttonActionSet( (char*)"TkImport", (char*)"SPOOL_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_SPOOL_FILE ); ProMenubuttonActionSet( (char*)"TkImport" , (char*)"TkImport", (ProMenubuttonAction)ProMenuDelete, p_type, -1 ); status = ProMenuCreate( PROMENUTYPE_MAIN, (char*)"TkImport", &menu_id ); TEST_CALL_REPORT( "ProMenuCreate()", "ProTestSelectImportType()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) { status = ProMenuProcess( (char*)"TkImport", &action ); TEST_CALL_REPORT( "ProMenuProcess()", "ProTestSelectImportType()", status, status != PRO_TK_NO_ERROR ); } if( *p_type == PRO_UNDEFINED_FILE ) status = PRO_TK_GENERAL_ERROR; return status; } /*============================================================================*\ Function: ProTestExport Purpose: Export current model from the foreign format \*============================================================================*/ int ProTestExport( ProAppData p_appdata) { ProError status; ProMdl p_model; ProMdlFileName wfilename; ProMode mode; ProAppData p_arg2; ProAppData p_arg3; ProFeature feature; ProSelection *p_sel; int n_sel; ProImportExportFile export_type; double quality[ 2 ]; ProCGMType cgm_option_1; ProCGMType cgm_option_2; p_model = *((ProMdl*)p_appdata); /* User's input must be here */ ProStringToWstring( wfilename, (char*)"output" ); /* Get Pro/E mode */ status = ProModeCurrentGet( &mode ); TEST_CALL_REPORT( "ProModeCurrentGet()", "ProTestExport()", status, status != PRO_TK_NO_ERROR ); ProTestSelectExportType( &export_type ); p_arg2 = NULL; p_arg3 = NULL; switch( export_type ) { case PRO_IGES_FILE: case PRO_DXF_FILE: case PRO_DWG_SETUP_FILE: if( mode != PRO_MODE_DRAWING ) { status = PRO_TK_GENERAL_ERROR; ProUtilMsgPrint( "gen", "TEST %0s", "Drawing mode is required" ); } break; case PRO_RENDER_FILE: case PRO_SLA_ASCII_FILE: case PRO_SLA_BINARY_FILE: case PRO_INVENTOR_FILE: quality[0] = DEFAULT_CHORD_HEIGHT; quality[1] = DEFAULT_ANGLE_CONTROL; p_arg3 = (ProAppData)quality; break; case PRO_FEAT_INFO: case PRO_FEATURE_INFO: ProUtilMsgPrint( "gen", "TEST %0s", "Select the feature" ); status = ProSelect( (char*)"feature", 1, NULL, NULL, NULL, NULL, &p_sel, &n_sel ); if( (status != PRO_TK_NO_ERROR) || (n_sel < 1) ) break; status = ProSelectionModelitemGet( p_sel[0], &feature ); TEST_CALL_REPORT( "ProSelectionModelitemGet()", "ProTestExport()", status, status != PRO_TK_NO_ERROR ); p_arg2 = (ProAppData)&(feature.id); break; case PRO_MFG_OPER_CL: case PRO_MFG_FEAT_CL: if( mode != PRO_MODE_MANUFACTURE ) { status = PRO_TK_GENERAL_ERROR; ProUtilMsgPrint( "gen", "TEST %0s", "Manufacturing mode is required" ); break; } ProUtilMsgPrint( "gen", "TEST %0s", "Select the feature" ); status = ProSelect( (char*)"feature", 1, NULL, NULL, NULL, NULL, &p_sel, &n_sel ); if( (status != PRO_TK_NO_ERROR) || (n_sel < 1) ) break; status = ProSelectionModelitemGet( p_sel[0], &feature ); TEST_CALL_REPORT( "ProSelectionModelitemGet()", "ProTestExport()", status, status != PRO_TK_NO_ERROR ); p_arg2 = (ProAppData)&(feature.id); break; case PRO_CGM_FILE: cgm_option_1 = PROCGMTYPE_CLEAR_TEXT; cgm_option_2 = PROCGMTYPE_ABSTRACT; p_arg2 = &cgm_option_1; p_arg3 = &cgm_option_2; break; } if( status == PRO_TK_NO_ERROR ) { ProUtilMsgPrint( "gen", "TEST %0s", "Enter export file name [QUIT]:" ); status = ProMessageStringRead( PRO_LINE_SIZE, wfilename ); TEST_CALL_REPORT( "ProMessageStringRead()", "ProTestImport()", status, status != PRO_TK_NO_ERROR ); if( status != PRO_TK_NO_ERROR ) return -1; status = ProOutputFileMdlnameWrite( p_model, wfilename, export_type, NULL, p_arg2, p_arg3, NULL ); TEST_CALL_REPORT( "ProOutputFileMdlnameWrite()", "ProTestExport()", status, status != PRO_TK_NO_ERROR ); } else { ProUtilMsgPrint( "gen", "TEST %0s", "Invalid export type" ); } return 0; } /*============================================================================*\ Function: ProUtilSliceParamInput Purpose: Input Slice export param \*============================================================================*/ int ProUtilSliceParamInput( double *dptr, int action) { ProCharLine line; double drange[2], d; ProError err; d = dptr[0]; if (action == CHORD_HEIGHT) { ProTKSprintf(line, "Enter maximum hord height [%.4f]:", d); drange[0] = 0.0001; drange[1] = 100.0; } else { ProTKSprintf(line, "Enter angle control factor ( 0.0 - 1.0 ) [%.4f]:", d); drange[0] = 0.0; drange[1] = 1.0; } ProUtilMsgPrint("gen", "TEST %0s", line); err = ProMessageDoubleRead(drange, &d); if (err == PRO_TK_NO_ERROR) { dptr[0] = d; } return (0); } /*============================================================================*\ Function: ProUtilSliceSelectCsys Purpose: Select Slice export Csys matr \*============================================================================*/ int ProUtilSliceSelectCsys( ProMatrix matr) { ProSelection *p_sel; int n_sel; ProError err; ProModelitem modelitem; ProAsmcomppath path; ProMatrix asm_matr, prod_matr; ProGeomitemdata *p_data; ProUtilMsgPrint("gen", "TEST %0s", "Select coordinate system."); err = ProSelect((char*)"csys", 1, NULL, NULL, NULL, NULL, &p_sel, &n_sel ); if (err != PRO_TK_NO_ERROR || n_sel != 1) return (0); err = ProSelectionModelitemGet(p_sel[0], &modelitem); TEST_CALL_REPORT( "ProSelectionModelitemGet()", "ProTestExport()", err, err != PRO_TK_NO_ERROR ); err = ProGeomitemdataGet((ProGeomitem*)&modelitem, &p_data); TEST_CALL_REPORT( "ProGeomitemdataGet()", "ProTestExport()", err, err != PRO_TK_NO_ERROR ); err = ProMatrixInit(p_data->data.p_csys_data->x_vector, p_data->data.p_csys_data->y_vector, p_data->data.p_csys_data->z_vector, p_data->data.p_csys_data->origin, matr); TEST_CALL_REPORT( "ProMatrixInit()", "ProTestExport()", err, err != PRO_TK_NO_ERROR ); err = ProGeomitemdataFree(&p_data); TEST_CALL_REPORT( "ProGeomitemdataFree()", "ProTestExport()", err, err != PRO_TK_NO_ERROR ); err = ProSelectionAsmcomppathGet(p_sel[0], &path); TEST_CALL_REPORT( "ProSelectionAsmcomppathGet()", "ProTestExport()", err, err != PRO_TK_NO_ERROR ); if (err == PRO_TK_NO_ERROR) { /* Csys from an assembly component, produce transformation matrix from csys matrix and component matrix */ err = ProAsmcomppathTrfGet(&path, PRO_B_FALSE, asm_matr); TEST_CALL_REPORT( "ProAsmcomppathTrfGet()", "ProTestExport()", err, err != PRO_TK_NO_ERROR ); ProUtilMatrixProduct(asm_matr, matr, prod_matr); ProUtilMatrixCopy(prod_matr, matr); } err = ProMenuDeleteWithStatus(0); return(PRO_TK_NO_ERROR); } /*============================================================================*\ Function: ProUtilSliceParamInput Purpose: Make Slice export Csys matr \*============================================================================*/ int ProUtilSliceCsysGet( ProMatrix matr) { int action; ProError err; ProUtilMsgPrint("gen", "TEST %0s", "Create or select coordinate system."); ProMenuFileRegister( (char*)"TkGet Csys", (char*)"tkgetcsys.mnu", NULL ); ProMenubuttonActionSet( (char*)"TkGet Csys", (char*)"Select", (ProMenubuttonAction)ProUtilSliceSelectCsys, matr, 0); ProMenubuttonActionSet( (char*)"TkGet Csys", (char*)"Default", (ProMenubuttonAction)ProUtilMenubuttonDeleteWithStatus, NULL, 0); ProMenubuttonActionSet( (char*)"TkGet Csys", (char*)"Quit", (ProMenubuttonAction)ProMenuDelete, NULL, 0); ProMenubuttonActionSet( (char*)"TkGet Csys", (char*)"TkGet Csys", (ProMenubuttonAction)ProMenuDelete, NULL, 0); ProMenuCreate(PROMENUTYPE_MAIN, (char*)"TkGet Csys", NULL); err = ProMenuProcess((char*)"TkGet Csys", &action); if (err == PRO_TK_NO_ERROR) { ProMenuDeleteWithStatus(0); ProMenuDeleteWithStatus(0); } return (0); } /*============================================================================*\ Function: ProUtilSliceCompSelect Purpose: Select an assembly component \*============================================================================*/ int ProUtilSliceCompSelect( ProAsmcomppath **p_path) { ProSelection *p_sel; int n_sel; ProError err; ProAsmcomppath path; err = ProSelect((char*)"prt_or_asm", 1, NULL, NULL, NULL, NULL, &p_sel, &n_sel ); if (err == PRO_TK_NO_ERROR && n_sel == 1) { ProUtilMsgPrint("gen", "TEST %0s", "Select an assembly component."); err = ProSelectionAsmcomppathGet(p_sel[0], &path); TEST_CALL_REPORT("ProSelectionAsmcomppathGet()", "ProUtilSliceCompSelect()", err, err != PRO_TK_NO_ERROR); if (err == PRO_TK_NO_ERROR) { if (*p_path == NULL) *p_path = (ProAsmcomppath*)calloc(1, sizeof(ProAsmcomppath)); p_path[0][0] = path; } ProUtilMenubuttonActivate((char*)"TkExportSliceComp", (char*)"Include", 0); } return (0); } /*============================================================================*\ Function: ProTestExportSlice Purpose: Export current model to the one of slice formats \*============================================================================*/ int ProTestExportSlice( ProAppData p_appdata) { ProMdl p_model; ProMdlName w_name; ProMdlFileName w_file_name; char name[PRO_MDLNAME_SIZE]; ProCharLine line; char file_name[PRO_FILE_MDLNAME_SIZE]; ProMatrix matrix; ProAsmcomppath *p_path = NULL; ProError err; ProMdlType mdl_type; int i, n_menus, action; ProImportExportFile type; char *compound[] = {"TkExportSlice", "TkExportSliceComp", ""}; double *quality; int flags = PRO_FACET_STEP_SIZE_DEFAULT | PRO_FACET_CHORD_HEIGHT_DEFAULT | PRO_FACET_ANGLE_CONTROL_DEFAULT; ProArrayAlloc(3, sizeof(double), 1, (ProArray*)&quality); quality[0] = DEFAULT_CHORD_HEIGHT; quality[1] = DEFAULT_ANGLE_CONTROL; quality[2] = DEFAULT_STEP_SIZE; p_model = *((ProMdl*)p_appdata); err = ProMdlTypeGet(p_model, &mdl_type); ProMenuFileRegister( (char*)"TkSlice Type", (char*)"tkslicetype.mnu", NULL ); for (i=0; i<sizeof(sl_types)/sizeof(sl_types[0]); i++) { ProMenubuttonActionSet( (char*)"TkSlice Type", sl_types[i].button_name, (ProMenubuttonAction)ProUtilMenubuttonDeleteWithStatus, NULL, sl_types[i].type); } ProMenubuttonActionSet( (char*)"TkSlice Type", (char*)"TkSlice Type", (ProMenubuttonAction)ProMenuDelete, NULL, 0); ProMenuCreate(PROMENUTYPE_MAIN, (char*)"TkSlice Type", NULL); err = ProMenuProcess((char*)"TkSlice Type", (int*)&type); if (err != PRO_TK_NO_ERROR) return (-1); ProUtilMatrixCopy(NULL, matrix); ProMenuFileRegister( (char*)"TkExportSlice", (char*)"tkexportsl.mnu", NULL); ProMenubuttonActionSet( (char*)"TkExportSlice", (char*)"Chord Height", (ProMenubuttonAction)ProUtilSliceParamInput, &quality[0], CHORD_HEIGHT); ProMenubuttonActionSet( (char*)"TkExportSlice", (char*)"Angle Control", (ProMenubuttonAction)ProUtilSliceParamInput, &quality[1], ANGLE_CONTROL); ProMenubuttonActionSet( (char*)"TkExportSlice", (char*)"Output", (ProMenubuttonAction)ProUtilSliceCsysGet, matrix, 0); ProMenubuttonActionSet( (char*)"TkExportSlice", (char*)"TkExportSlice", (ProMenubuttonAction)ProUtilMenuKill, NULL, 2); ProMenuFileRegister( (char*)"TkExportSliceComp", (char*)"tkexportslc.mnu", NULL); ProMenubuttonActionSet( (char*)"TkExportSliceComp", (char*)"Include", (ProMenubuttonAction)ProUtilSliceCompSelect, &p_path, 0); ProMenubuttonActionSet( (char*)"TkExportSliceComp", (char*)"TkExportSliceComp", (ProMenubuttonAction)ProUtilMenuKill, NULL, 2); err = ProCompoundmenuCreate(compound, &n_menus); TEST_CALL_REPORT("ProCompoundmenuCreate()", "ProTestExportSlice()", err, err != PRO_TK_NO_ERROR); ProUtilMenubuttonActivate((char*)"TkExportSliceComp", (char*)"Include", mdl_type != PRO_MDL_PART); err = ProMenuProcess((char*)"TkExportSlice", &action); if (err != PRO_TK_NO_ERROR) return (0); err = ProMdlMdlnameGet(p_model, w_name); ProWstringToString(name, w_name); ProTKSprintf(line, "Enter output file name [%s] : ", name); ProUtilMsgPrint("gen", "TEST %0s", line); err = ProMessageStringRead(PRO_LINE_SIZE, w_file_name); if (err != PRO_TK_NO_ERROR) ProStringToWstring(w_file_name, name); ProWstringToString(file_name, w_file_name); ProUtilstrcat(file_name, "."); for (i=0; i<sizeof(sl_types)/sizeof(sl_types[0]); i++) { if (sl_types[i].type == type) { ProUtilstrcat(file_name, (const char*)sl_types[i].file_extension); break; } } ProStringToWstring(w_file_name, file_name); err = ProIntfSliceFileWithOptionsMdlnameExport(p_model, w_file_name, type, quality, flags, matrix, p_path); TEST_CALL_REPORT( "ProIntfSliceFileWithOptionsMdlnameExport()", "ProTestExportSlice()", err, err != PRO_TK_NO_ERROR ); if (err == PRO_TK_NO_ERROR) { ProTKSprintf(line, "File %s has written successfully.", file_name); ProUtilMsgPrint( "gen", "TEST %0s", line); } if (p_path != NULL) free(p_path); return 0; } /*============================================================================*\ Function: ProTestSelectExportType Purpose: Select file format to export \*============================================================================*/ ProError ProTestSelectExportType( ProImportExportFile *p_type ) { ProError status; int menu_id; int action; if( p_type == NULL ) return PRO_TK_BAD_INPUTS; *p_type = PRO_UNDEFINED_FILE; status = ProMenuFileRegister( (char*)"TkExport", (char*)"tkexport.mnu", &menu_id ); TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTestSelectExportType()", status, status != PRO_TK_NO_ERROR ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"RELATION_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_RELATION_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"MODEL_INFO", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_MODEL_INFO ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"PROGRAM_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_PROGRAM_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"IGES_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_IGES_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"DXF_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_DXF_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"RENDER_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_RENDER_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"SLA_ASCII_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_SLA_ASCII_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"SLA_BINARY_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_SLA_BINARY_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"BOM_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_BOM_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"DWG_SETUP_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_DWG_SETUP_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"FEAT_INFO", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_FEAT_INFO ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"MFG_OPER_CL", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_MFG_OPER_CL ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"MFG_FEAT_CL", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_MFG_FEAT_CL ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"MATERIAL_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_MATERIAL_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"IGES_3D_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_IGES_3D_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"STEP_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_STEP_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"VDA_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_VDA_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"CGM_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_CGM_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"INVENTOR_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_INVENTOR_FILE ); ProMenubuttonActionSet( (char*)"TkExport", (char*)"FIAT_FILE", (ProMenubuttonAction)ProTestExportFileTypeSet, p_type, PRO_FIAT_FILE ); ProMenubuttonActionSet( (char*)"TkExport" , (char*)"TkExport", (ProMenubuttonAction)ProMenuDelete, p_type, -1 ); status = ProMenuCreate( PROMENUTYPE_MAIN, (char*)"TkExport", &menu_id ); TEST_CALL_REPORT( "ProMenuCreate()", "ProTestSelectExportType()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) { status = ProMenuProcess( (char*)"TkExport", &action ); TEST_CALL_REPORT( "ProMenuProcess()", "ProTestSelectExportType()", status, status != PRO_TK_NO_ERROR ); } if( *p_type == PRO_UNDEFINED_FILE ) status = PRO_TK_GENERAL_ERROR; return status; } /*============================================================================*\ Function: ProTestExportFileTypeSet Purpose: \*============================================================================*/ int ProTestExportFileTypeSet( ProImportExportFile *p_type, ProImportExportFile type_value ) { ProError status; *p_type = type_value; status = ProMenuDelete(); TEST_CALL_REPORT( "ProMenuDelete()", "ProTestExportFileTypeSet()", status, status != PRO_TK_NO_ERROR ); return 0; } #define PRO_YES_TYPE 1 #define PRO_NO_TYPE 0 /*============================================================================*\ Function: ProTestPlotfileWrite Purpose: \*============================================================================*/ int ProTestPlotfileWrite ( ProAppData p_appdata) { static ProPlotOptions poPlotOpt = { "postscript", /* plotter name */ A4_SIZE_PLOT, /* paper size, not used really */ {0,0}, /* not used */ 3, /* ouput quality */ 1, /* user scale */ 1, /* Pen Slew */ {0,0}, /* Pen Velocity */ 2, /* Current page */ {0,0}, /* not used */ PRO_NO_TYPE, /* Segmented output */ PRO_YES_TYPE, /* Label */ PRO_NO_TYPE /* not used */ }; ProError status; ProName wfilename; ProUtilMsgPrint( "gen", "TEST %0s", "Enter export file name [QUIT]:" ); status = ProMessageStringRead( PRO_NAME_SIZE, wfilename ); TEST_CALL_REPORT( "ProMessageStringRead()", "ProTestPlotfileWrite()", status, status != PRO_TK_NO_ERROR ); if( status != PRO_TK_NO_ERROR ) return -1; status = ProPlotfileWrite(*((ProMdl*)p_appdata), wfilename, &poPlotOpt); TEST_CALL_REPORT( "ProPlotfileWrite()", "ProTestPlotfileWrite()", status, status != PRO_TK_NO_ERROR ); return (0); } /*============================================================================*\ Function: ProTestExportVRML Purpose: Export to VRML format \*============================================================================*/ int ProTestExportVRML( ProAppData p_appdata) { ProError err; ProBoolean direct = PRO_B_FALSE; ProPath input_file; ProPath output_path; int act = 0; char file_name[PRO_PATH_SIZE]; static ProUtilMenuButtons export_act[] = { {"VRML", 0, TEST_CALL_PRO_MENU_DELETE}, {"Current",0 , 0}, {"Input file",1 ,0}, {"",0,0} }; ProError ProUtilFileOpen(char *,char *); err = ProUtilMenuIntValueSelect(export_act, &act); TEST_CALL_REPORT("ProUtilMenuIntValueSelect()","ProTestExportVRML()", err, err != PRO_TK_NO_ERROR); if(act) { direct = PRO_B_TRUE; err = ProUtilFileOpen((char*)"*.*", file_name); TEST_CALL_REPORT(" ProUtilFileOpen()","ProTestExport()", err, err != PRO_TK_NO_ERROR); if (err != PRO_TK_NO_ERROR) { ProUtilMsgPrint("gen", "TEST %0s", "Unable open file."); return -1; } } ProStringToWstring(input_file, file_name); ProUtilMsgPrint("gen", "TEST %0s", "Enter output path :"); if( !ProUtilStringGet((wchar_t*)&output_path, NULL, PRO_LINE_SIZE)) return -1; err = ProExportVRML(direct, *((ProMdl*)p_appdata), input_file, output_path); TEST_CALL_REPORT ("ProExportVRML()", "ProTestExport()", err, err != PRO_TK_NO_ERROR); return(0); } /*============================================================================*\ Function: ProTestRasterMenu Purpose: Setup compound menu for choice export options \*============================================================================*/ int ProTestRasterMenu() { RasterSettings set; ProError err; int menu_id; static char *menu[]={"Raster","Type","Inch","Size", "ExportRaster",""}; int ProTestDepthOpt(); int ProTestTypeOpt(); int ProTestInchOpt(); int ProTestSizeOpt(); int ProTestExportRaster(); /* default settings */ set.depth = PRORASTERDEPTH_8; set.type = PRORASTERTYPE_TIFF; set.inch = PRORASTERDPI_100; set.size[0] = 4; set.size[1] = 5; err = ProMenuFileRegister((char*)"Raster", (char*)"tkraster.mnu", &menu_id); err = ProMenubuttonActionSet((char*)"Raster", (char*)"Raster", (ProMenubuttonAction)ProMenuDelete, NULL, 0); err = ProMenubuttonActionSet((char*)"Raster", (char*)"DEPTH_8", (ProMenubuttonAction)ProTestDepthOpt, &set, PRORASTERDEPTH_8); err = ProMenubuttonActionSet((char*)"Raster", (char*)"DEPTH_24", (ProMenubuttonAction)ProTestDepthOpt, &set, PRORASTERDEPTH_24); err = ProMenuFileRegister((char*)"Type", (char*)"tktype.mnu", &menu_id); err = ProMenubuttonActionSet((char*)"Type", (char*)"Type", (ProMenubuttonAction)ProMenuDelete, NULL, 0); err = ProMenubuttonActionSet((char*)"Type", (char*)"TYPE_BMP", (ProMenubuttonAction)ProTestTypeOpt, &set, PRORASTERTYPE_BMP); err = ProMenubuttonActionSet((char*)"Type", (char*)"TYPE_TIFF", (ProMenubuttonAction)ProTestTypeOpt, &set, PRORASTERTYPE_TIFF); err = ProMenubuttonActionSet((char*)"Type", (char*)"TYPE_EPS", (ProMenubuttonAction)ProTestTypeOpt, &set, PRORASTERTYPE_EPS); err = ProMenubuttonActionSet((char*)"Type", (char*)"TYPE_JPEG", (ProMenubuttonAction)ProTestTypeOpt, &set, PRORASTERTYPE_JPEG); err = ProMenuFileRegister((char*)"Inch", (char*)"tkinch.mnu", &menu_id); err = ProMenubuttonActionSet((char*)"Inch", (char*)"Inch", (ProMenubuttonAction)ProMenuDelete, NULL, 0); err = ProMenubuttonActionSet((char*)"Inch", (char*)"DPI_100", (ProMenubuttonAction)ProTestInchOpt, &set, PRORASTERDPI_100); err = ProMenubuttonActionSet((char*)"Inch", (char*)"DPI_200", (ProMenubuttonAction)ProTestInchOpt, &set, PRORASTERDPI_200); err = ProMenubuttonActionSet((char*)"Inch", (char*)"DPI_300", (ProMenubuttonAction)ProTestInchOpt, &set, PRORASTERDPI_300); err = ProMenubuttonActionSet((char*)"Inch", (char*)"DPI_400", (ProMenubuttonAction)ProTestInchOpt, &set, PRORASTERDPI_400); err = ProMenuFileRegister((char*)"Size", (char*)"tksize.mnu", &menu_id); err = ProMenubuttonActionSet((char*)"Size", (char*)"Size", (ProMenubuttonAction)ProMenuDelete, NULL, 0); err = ProMenubuttonActionSet((char*)"Size", (char*)"A", (ProMenubuttonAction)ProTestSizeOpt, &set, A_SIZE_PLOT); err = ProMenubuttonActionSet((char*)"Size", (char*)"B", (ProMenubuttonAction)ProTestSizeOpt, &set, B_SIZE_PLOT); err = ProMenubuttonActionSet((char*)"Size", (char*)"C", (ProMenubuttonAction)ProTestSizeOpt, &set, C_SIZE_PLOT); err = ProMenubuttonActionSet((char*)"Size", (char*)"D", (ProMenubuttonAction)ProTestSizeOpt, &set, D_SIZE_PLOT); err = ProMenubuttonActionSet((char*)"Size", (char*)"E", (ProMenubuttonAction)ProTestSizeOpt, &set, E_SIZE_PLOT); err = ProMenubuttonActionSet((char*)"Size", (char*)"VARIABLE", (ProMenubuttonAction)ProTestSizeOpt, &set, VARIABLE_SIZE_PLOT); err = ProMenuFileRegister((char*)"ExportRaster", (char*)"tkexportraster.mnu", &menu_id); err = ProMenubuttonActionSet((char*)"ExportRaster", (char*)"ExportRaster", (ProMenubuttonAction)ProMenuDelete, NULL, 0); err = ProMenubuttonGenactionSet((char*)"ExportRaster", (char*)"Export", (ProMenubuttonGenaction)ProTestExportRaster, &set, NULL, NULL, NULL, NULL, NULL); err = ProCompoundmenuCreate(menu, &menu_id); ProMenubuttonHighlight((char*)"Type", (char*)"TYPE_BMP"); ProMenubuttonHighlight((char*)"Raster", (char*)"DEPTH_8"); ProMenubuttonHighlight((char*)"Inch", (char*)"DPI_100"); ProMenubuttonHighlight((char*)"Size", (char*)"A"); err = ProMenuProcess(menu[0], &menu_id); return(0); } /*============================================================================*\ Function: ProTestTypeOpt Purpose: Get type options \*============================================================================*/ int ProTestTypeOpt(RasterSettings *set, int opt) { set->type = (ProRasterType)opt; return(0); } /*============================================================================*\ Function: ProTestDepthOpt Purpose: Get depth options \*============================================================================*/ int ProTestDepthOpt(RasterSettings *set, int opt) { set->depth = (ProRasterDepth)opt; return(0); } /*============================================================================*\ Function: ProTestInchOpt Purpose: Get inch options \*============================================================================*/ int ProTestInchOpt(RasterSettings *set, int opt) { set->inch = (ProDotsPerInch)opt; return(0); } /*============================================================================*\ Function: ProTestSizeOpt Purpose: Get size options \*============================================================================*/ int ProTestSizeOpt(RasterSettings *set, int opt) { ProError err; switch(opt) { case A_SIZE_PLOT : set->size[0] = 1.7; set->size[1] = 2.2; break; case B_SIZE_PLOT : set->size[0] = 2.2; set->size[1] = 3.4; break; case C_SIZE_PLOT : set->size[0] = 3.4; set->size[1] = 4.4; break; case D_SIZE_PLOT : set->size[0] = 4.4; set->size[1] = 6.8; break; case E_SIZE_PLOT : set->size[0] = 6.8; set->size[1] = 8.8; break; case F_SIZE_PLOT : set->size[0] = 5.6; set->size[1] = 8; break; case VARIABLE_SIZE_PLOT : ProUtilMsgPrint("gen", "TEST %0s", "Enter width:"); err = ProMessageDoubleRead (NULL, &(set->size[0])); if(err != PRO_TK_NO_ERROR) return -1; ProUtilMsgPrint("gen", "TEST %0s", "Enter height:"); err = ProMessageDoubleRead (NULL, &(set->size[1])); if(err != PRO_TK_NO_ERROR) return -1; break; } return(0); } /*============================================================================*\ Function: ProTestExportRaster Purpose: Export to raster formats \*============================================================================*/ int ProTestExportRaster(RasterSettings *set) { ProError err; int window_id; ProPath output_file; ProUtilMsgPrint("gen", "TEST %0s", "Enter output filename:"); if( !ProUtilStringGet((wchar_t*)&output_file, NULL, PRO_LINE_SIZE)) return -1; err = ProWindowCurrentGet(&window_id); TEST_CALL_REPORT("ProWindowCurrentGet()","ProTestPrint()", err, err != PRO_TK_NO_ERROR); err = ProRasterFileWrite(window_id, set->depth, set->size[0], set->size[1], set->inch, set->type, output_file); TEST_CALL_REPORT ("ProRasterFileWrite()", "ProTestExport()", err, err != PRO_TK_NO_ERROR); return(0); } /*====================================================================*\ FUNCTION : ProTestRedefImpfeat() PURPOSE : Commands for testing import feature in Pro/TOOLKIT \*====================================================================*/ int ProTestRedefImpfeat(ProMdl *mdl) { ProError err; ProFeature *p_feats; ProImportfeatRedefSource redef_source; int menu_id, action; static char *cmpnd_menu[] = {"TkImpfeatAttr","DONE",""}; static ProImportfeatAttr impfeatattr = { 1, 1, 0, 0, PRO_IMPORT_BODY_USE_DEFAULT, NULL}; err = ProUtilCollectSolidFeaturesWithFilter((ProSolid)*mdl, (ProFeatureFilterAction)ProUtilImportfeatFilter, &p_feats); if (err != PRO_TK_NO_ERROR) { ProUtilMsgPrint("gen", "TEST %0s", "No Import feats found."); return (0); } err = ProMenuFileRegister( (char*)"TkImpfeatAttr", (char*)"tkimpfeatattr.mnu", &menu_id ); TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTestRedefImpfeate()", err, err != PRO_TK_NO_ERROR ); ProMenubuttonActionSet( (char*)"TkImpfeatAttr", (char*)"TkImpfeatAttr", (ProMenubuttonAction)ProMenuDelete, NULL, 0); ProMenubuttonActionSet( (char*)"TkImpfeatAttr", (char*)"Join Surfaces", (ProMenubuttonAction)ProTestImpfeatAttrMenuAction, (ProAppData)&impfeatattr, JOIN_SURFACES ); ProMenubuttonActionSet( (char*)"TkImpfeatAttr", (char*)"Make Solid", (ProMenubuttonAction)ProTestImpfeatAttrMenuAction, (ProAppData)&impfeatattr, MAKE_SOLID); ProMenubuttonActionSet( (char*)"TkImpfeatAttr", (char*)"Add Solid", (ProMenubuttonAction)ProTestImpfeatAttrMenuAction, (ProAppData)&impfeatattr, ADD_SOLID); err = ProMenuModeSet ((char*)"TkImpfeatAttr", PROMENUMODE_DATA); TEST_CALL_REPORT( "ProMenuModeSet()", "ProTestRedefImpfeate()", err, err != PRO_TK_NO_ERROR ); err = ProMenuDatamodeSet ((char*)"TkImpfeatAttr", PRO_B_TRUE); TEST_CALL_REPORT( "ProMenuDatamodeSet()", "ProTestRedefImpfeat()", err, err != PRO_TK_NO_ERROR ); err = ProMenuFileRegister((char*)"DONE",(char*)"tketdone.mnu", &menu_id); err = ProMenubuttonActionSet((char*)"DONE",(char*)"-Done", (ProMenubuttonAction)ProUtilMenuKill, NULL, 2); err = ProMenubuttonActionSet((char*)"DONE",(char*)"DONE", (ProMenubuttonAction)ProMenuHold,NULL,0); err = ProCompoundmenuCreate(cmpnd_menu, &menu_id); TEST_CALL_REPORT("ProCompoundmenuCreate()", "ProTestRedefImpfeat()", err, err != PRO_TK_NO_ERROR ); ProUtilMenubuttonHighlight ((char*)"TkImpfeatAttr", (char*)"Join Surfaces", impfeatattr.join_surfaces); ProUtilMenubuttonHighlight ((char*)"TkImpfeatAttr", (char*)"Make Solid", impfeatattr.attempt_make_solid); ProUtilMenubuttonHighlight ((char*)"TkImpfeatAttr", (char*)"Add Solid", impfeatattr.cut_or_add); err = ProMenuProcess( (char*)"TkImpfeatAttr", &action ); TEST_CALL_REPORT( "ProMenuProcess()", "ProTestRedefImpfeat()", err, err != PRO_TK_NO_ERROR ); err = ProImportfeatRedefSourceInit(PRO_IMPORT_FEAT_REDEF_CHANGE_ATTR, (void*)&impfeatattr, &redef_source); TEST_CALL_REPORT("ProImportfeatRedefSourceInit()", "ProTestRedefImpfeat()", err, err != PRO_TK_NO_ERROR ); err = ProImportfeatRedefine(p_feats, &redef_source); TEST_CALL_REPORT("ProImportfeatRedefine()", "ProTestRedefImpfeat()", err, (err != PRO_TK_NO_ERROR)&& (err !=PRO_TK_NOT_IMPLEMENTED)); err = ProArrayFree((ProArray*)&p_feats); TEST_CALL_REPORT("ProArrayFree()", "ProTestRedefImpfeat()", err, err != PRO_TK_NO_ERROR ); return (0); }