/* Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved. */ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include <ProToolkit.h> #include <ProToolinput.h> #include <ProElement.h> #include <ProTool.h> #include <ProWcell.h> #include <ProMdl.h> #include <ProMenu.h> #include <ProToolElem.h> #include <ProMessage.h> #include <ProTKRunTime.h> #include <ProUtil.h> /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include "TestMfgNew.h" #include "UtilMfgNew.h" #include "UtilString.h" #include "UtilGeom.h" #include "UtilMenu.h" #include "TestError.h" #include "UtilMessage.h" /*--------------------------------------------------------------------*\ Application data \*--------------------------------------------------------------------*/ struct Pro_TestToolType { ProToolType ToolType; char *ToolTypeName; } ProTestToolType[] ={ {PRO_TOOL_NONE, (char*)"TOOL_NONE"}, {PRO_TOOL_DRILL, (char*)"DRILL"}, {PRO_TOOL_TURN, (char*)"TURN"}, {PRO_TOOL_SAW, (char*)"SAW"}, {PRO_TOOL_MILL, (char*)"MILL"}, {PRO_TOOL_GROOVE, (char*)"GROOVE"}, {PRO_TOOL_NIBBLE, (char*)"NIBBLE"}, {PRO_TOOL_PUNCH, (char*)"PUNCH"}, {PRO_TOOL_AUXILIARY, (char*)"AUXILIARY"}, {PRO_TOOL_FORM, (char*)"FORM"}, {PRO_TOOL_PUNPNT, (char*)"PUNPNT"}, {PRO_TOOL_AREA_NIB, (char*)"AREA_NIB"}, {PRO_TOOL_MFG_REFINE, (char*)"MFG REFINE"}, {PRO_TOOL_BORE, (char*)"BORE"}, {PRO_TOOL_TAP, (char*)"TAP"}, {PRO_TOOL_CSINK, (char*)"CSINK"}, {PRO_TOOL_REAM, (char*)"REAM"}, {PRO_TOOL_CENTER_DRL, (char*)"CDRILL"}, {PRO_TOOL_TURN_GRV, (char*)"TURN_GRV"}, {PRO_TOOL_MILL_THREAD, (char*)"MILL_THRD"}, {PRO_TOOL_TURN_THREAD, (char*)"TURN_THRD"}, {PRO_TOOL_SHEAR, (char*)"SHEAR"}, {PRO_TOOL_SIDE_MILL, (char*)"SIDE MILL"}, {PRO_TOOL_CMM_FIXED, (char*)"CMM FIXED"}, {PRO_TOOL_CMM_ROTATED, (char*)"CMM ROTATED"}, /* 1<<25 */ {PRO_TOOL_BACK, (char*)"BACK"}, /* 1<<27 */ {PRO_TOOL_PLUNGE_MILL, (char*)"PLUNG MILL"}}; /*--------------------------------------------------------------------*\ Function prototypes \*--------------------------------------------------------------------*/ ProError ProUtilToolChoose(ProMfg *p_mfg, ProTool *p_sel_tool); /*====================================================================*\ FUNCTION : ProTestToolRedefine PURPOSE : Redefine tool \*====================================================================*/ ProError ProTestToolRedefine(MfgMenuChoice *obj_action) { ProTool tool; ProToolinputPtr tool_input; ProMfg mfg_model; ProSolid mfg_solid; ProAsmcomppath comp_path; ProToolElem tool_elem; ProErrorlist err_list; ProError status; ProToolType tool_type; ToolCreationType creation_type; char str[PRO_LINE_SIZE]; wchar_t wstr[PRO_LINE_SIZE]; char p_param_file[PRO_LINE_SIZE]; int attrs; status=ProTestGetModels(&mfg_model, &mfg_solid, &comp_path); /*--------------------------------------------------------------------*\ Get tool's name \*--------------------------------------------------------------------*/ status = ProUtilToolChoose(&mfg_model, &tool); if (status != PRO_TK_NO_ERROR) { ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s",(char*)"No Tools available"); return (PRO_TK_NO_ERROR); } status = ProToolVerify (&tool); TEST_CALL_REPORT("ProToolVerify()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); if (status != PRO_TK_NO_ERROR) { ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s", (char*)"Tool is not valid"); return (PRO_TK_NO_ERROR); } status = ProToolTypeGet (&tool, &tool_type); TEST_CALL_REPORT("ProToolTypeGet()", "ProTestToolRedefinel()", status, (status != PRO_TK_NO_ERROR)); status = ProToolinputAlloc(&tool_input); TEST_CALL_REPORT("ProToolinputAlloc()", "ProTestToolRedefine()", status, status != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Query the user the type of creation: from param file or solid part \*--------------------------------------------------------------------*/ creation_type = ProUtilSelectCreationType(); if (creation_type == FROM_PARAMFILE_BY_COPY || creation_type == FROM_PARAMFILE_BY_REF|| creation_type == FROM_SOLID_BY_COPY || creation_type == FROM_SOLID_BY_REF) { status = ProToolAttributesGet (&tool, &attrs); TEST_CALL_REPORT("ProToolAttributesGet()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); switch (creation_type) { case FROM_PARAMFILE_BY_COPY: PRO_TOOL_ATTRIBUTE_RMV (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_PARAMFILE; break; case FROM_PARAMFILE_BY_REF: PRO_TOOL_ATTRIBUTE_ADD (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_PARAMFILE; break; case FROM_SOLID_BY_COPY: PRO_TOOL_ATTRIBUTE_RMV (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_SOLID; break; case FROM_SOLID_BY_REF: PRO_TOOL_ATTRIBUTE_ADD (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_SOLID; break; } status = ProElementAlloc(PRO_E_ATTRIBUTES, &tool_elem); TEST_CALL_REPORT("ProElementAlloc()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); status = ProToolElemAttrSet (tool_elem, attrs); TEST_CALL_REPORT("ProToolElemAttrSet()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); status = ProToolinputElemAdd(tool_input,tool_elem); TEST_CALL_REPORT("ProToolinputElemAdd()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); } switch (creation_type) { case FROM_PARAMFILE : status = ProElementAlloc(PRO_E_PARAMS, &tool_elem); TEST_CALL_REPORT("ProElementAlloc()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); ProTKSprintf(str,(char*)"USER Enter Parameters file name: "); ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s",str); if ( ProUtilStringGet(wstr, NULL,PRO_LINE_SIZE)) ProWstringToString(p_param_file, wstr); status = ProUtilParamFileRead(p_param_file,TOOL,tool_elem); break; case FROM_SOLID: status = ProElementAlloc(PRO_E_TOOL_MODEL, &tool_elem); TEST_CALL_REPORT("ProElementAlloc()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); status = ProUtilToolFromSolidAdd(tool_elem); break; } status = ProToolinputElemAdd(tool_input,tool_elem); TEST_CALL_REPORT("ProToolinputElemAdd()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); status = ProToolinputTypeSet(tool_input,tool_type); TEST_CALL_REPORT("ProToolinputTypeSet()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); status = ProToolRedefine(&tool, tool_input, &err_list); TEST_CALL_REPORT("ProToolRedefine()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); if (status != PRO_TK_NO_ERROR) { ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s", (char*)"Tool redefine failed"); } else { ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s", (char*)"Tool redefine successfully"); } /*--------------------------------------------------------------------*\ Free the input structure \*--------------------------------------------------------------------*/ ProToolinputFreeAllElems (tool_input); status = ProToolinputFree(&tool_input); TEST_CALL_REPORT("ProToolinputFree()", "ProTestToolRedefine()", status, (status != PRO_TK_NO_ERROR)); if (status == PRO_TK_NO_ERROR) { TEST_CALL_REPORT("ProToolinputFreeAllElems()", "ProTestToolRedefine()", PRO_TK_NO_ERROR, 0); } return (PRO_TK_NO_ERROR); } /*====================================================================*\ FUNCTION : ProTestToolTypeGet PURPOSE : Get Tool Type by index \*====================================================================*/ ProError ProTestToolTypeGet ( char ** cToolName, ProToolType * ToolType, int idx) { if (idx >= sizeof (ProTestToolType) /sizeof (ProTestToolType[0])) { return PRO_TK_BAD_INPUTS; } (*cToolName) = ProTestToolType[idx].ToolTypeName; *ToolType = ProTestToolType[idx].ToolType; return PRO_TK_NO_ERROR; } /*====================================================================*\ FUNCTION : ProTestCreateTool PURPOSE : Create tool \*====================================================================*/ ProError ProTestCreateTool( MfgMenuChoice *obj_action) { ProLine tool_id; ProToolType tool_type; char p_param_file[PRO_LINE_SIZE]; ProTool *p_tool; ProToolinputPtr tool_input; ProToolElem tool_elem; ProErrorlist err_list; ProMfg mfg_model; ProSolid mfg_solid; ProAsmcomppath comp_path; ToolCreationType creation_type; char str[PRO_LINE_SIZE]; wchar_t wstr[PRO_LINE_SIZE]; ProError status; int id, attrs = 0; int i; char * cTTypeName; ProToolType ToolType; wchar_t ** ToolTypeNames; int NumTT; /*--------------------------------------------------------------------*\ Get tool's name \*--------------------------------------------------------------------*/ ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s", (char*)"Enter tool name: "); ProMessageStringRead(PRO_LINE_SIZE, tool_id); /*--------------------------------------------------------------------*\ Get tool's type \*--------------------------------------------------------------------*/ NumTT = sizeof (ProTestToolType) /sizeof (ProTestToolType[0]); ToolTypeNames = (wchar_t **) calloc (NumTT+1, sizeof (wchar_t*)); for (i=0; i<NumTT; i++) { ToolTypeNames[i] = (wchar_t*) calloc (PRO_NAME_SIZE, sizeof(wchar_t)); ProTestToolTypeGet (&cTTypeName, &ToolType, i); ProStringToWstring(ToolTypeNames[i], cTTypeName ); } ToolTypeNames[i] = (wchar_t*) calloc (PRO_NAME_SIZE, sizeof(wchar_t)); ProStringToWstring(ToolTypeNames[i], (char*)"" ); status = ProMenuFromStringsRegister((char*)"Tool Type", NULL, ToolTypeNames, NULL, NULL, &id); TEST_CALL_REPORT("ProMenuFromStringsRegister()", "ProTestAsmcompFunc()", status, status != PRO_TK_NO_ERROR); for (i=0; i<NumTT; i++) { ProTestToolTypeGet (&cTTypeName, &ToolType, i); status = ProMenubuttonActionSet((char*)"Tool Type",cTTypeName , (ProMenubuttonAction)ProUtilAssign, &tool_type, ToolType); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProTestCreateTool", status, status != PRO_TK_NO_ERROR); } status = ProMenubuttonActionSet((char*)"Tool Type", (char*)"", (ProMenubuttonAction)ProMenuDelete, &tool_type, 0); for (i=0; i<NumTT; i++) free (ToolTypeNames[i]); free (ToolTypeNames); status = ProMenuCreate(PROMENUTYPE_MAIN, (char*)"Tool Type", &id); TEST_CALL_REPORT ("ProMenuCreate", "ProTestCreateTool", status, status != PRO_TK_NO_ERROR); status = ProMenuProcess((char*)"Tool Type", &id); TEST_CALL_REPORT ("ProMenuProcess", "ProTestCreateTool", status, status != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Allocate space for the tool \*--------------------------------------------------------------------*/ p_tool = (ProTool *) calloc (1, sizeof(ProTool)); /*--------------------------------------------------------------------*\ Get Manufacturing model and its associated solid part \*--------------------------------------------------------------------*/ status=ProTestGetModels(&mfg_model, &mfg_solid, &comp_path); status = ProToolinputAlloc(&tool_input); TEST_CALL_REPORT("ProToolinputAlloc()", "ProTestCreateTool()", status, status != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Set tool parameters and elements \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Query the user the type of creation: from param file or solid part \*--------------------------------------------------------------------*/ creation_type = ProUtilSelectCreationType(); if (creation_type == FROM_PARAMFILE_BY_COPY || creation_type == FROM_PARAMFILE_BY_REF|| creation_type == FROM_SOLID_BY_COPY || creation_type == FROM_SOLID_BY_REF) { switch (creation_type) { case FROM_PARAMFILE_BY_COPY: PRO_TOOL_ATTRIBUTE_RMV (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_PARAMFILE; break; case FROM_PARAMFILE_BY_REF: PRO_TOOL_ATTRIBUTE_ADD (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_PARAMFILE; break; case FROM_SOLID_BY_COPY: PRO_TOOL_ATTRIBUTE_RMV (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_SOLID; break; case FROM_SOLID_BY_REF: PRO_TOOL_ATTRIBUTE_ADD (attrs, PRO_TOOL_BY_REFERENCE); creation_type = FROM_SOLID; break; } status = ProElementAlloc(PRO_E_ATTRIBUTES, &tool_elem); TEST_CALL_REPORT("ProElementAlloc()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); status = ProToolElemAttrSet (tool_elem, attrs); TEST_CALL_REPORT("ProToolElemAttrSet()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); status = ProToolinputElemAdd(tool_input,tool_elem); TEST_CALL_REPORT("ProToolinputElemAdd()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); } switch (creation_type) { case FROM_PARAMFILE : status = ProElementAlloc(PRO_E_PARAMS, &tool_elem); TEST_CALL_REPORT("ProElementAlloc()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); ProTKSprintf(str,(char*)"USER Enter Parameters file name: "); ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s",str); if ( ProUtilStringGet(wstr, NULL,PRO_LINE_SIZE)) ProWstringToString(p_param_file, wstr); status = ProUtilParamFileRead(p_param_file,TOOL,tool_elem); break; case FROM_SOLID: status = ProElementAlloc(PRO_E_TOOL_MODEL, &tool_elem); TEST_CALL_REPORT("ProElementAlloc()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); status = ProUtilToolFromSolidAdd(tool_elem); break; } status = ProToolinputElemAdd(tool_input,tool_elem); TEST_CALL_REPORT("ProToolinputElemAdd()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); status = ProToolinputTypeSet(tool_input,tool_type); TEST_CALL_REPORT("ProToolinputTypeSet()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); /*--------------------------------------------------------------------*\ Create the tool \*--------------------------------------------------------------------*/ status = ProToolInit(tool_id, mfg_model, p_tool); TEST_CALL_REPORT("ProToolInit()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); status = ProToolCreate(p_tool, tool_input, &err_list); TEST_CALL_REPORT("ProToolCreate()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); if (status != PRO_TK_NO_ERROR) { ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s", (char*)"Tool creation failed"); } else { ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s", (char*)"Tool created successfully"); status = ProMenubuttonUnhighlight((char*)"TkMfgDQ",(char*)"Done"); TEST_CALL_REPORT ("ProMenubuttonUnhighlight", "ProTestCreateTool", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActivate((char*)"TkMfgAct",(char*)"-Route"); TEST_CALL_REPORT ("ProMenubuttonActivate", "ProTestCreateTool", status, status != PRO_TK_NO_ERROR); /*---------------------------------------------*\ Update the object list \*---------------------------------------------*/ status = ProTestMfgObjectsCollect(mfg_model,obj_action->mfgobj_list); } /*--------------------------------------------------------------------*\ Free the input structure \*--------------------------------------------------------------------*/ ProToolinputFreeAllElems (tool_input); status = ProToolinputFree(&tool_input); TEST_CALL_REPORT("ProToolinputFree()", "ProTestCreateTool()", status, (status != PRO_TK_NO_ERROR)); if (status == PRO_TK_NO_ERROR) { TEST_CALL_REPORT("ProToolinputFreeAllElems()", "ProTestCreateTool()", PRO_TK_NO_ERROR, 0); } return (PRO_TK_NO_ERROR); } /*====================================================================*\ FUNCTION : ProUtilSelectToolatrr() PURPOSE : Menu to select tool attr \*====================================================================*/ int ProUtilSelectToolatrr(void *app_data, int value) { ProError status; int id; int attr; status = ProMenuFileRegister((char*)"TkToolAttr", (char*)"tktoolattr.mnu", &id); TEST_CALL_REPORT ("ProMenuFileRegister", "ProUtilSelectToolatrr", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet((char*)"TkToolAttr",(char*)"-By Refference", (ProMenubuttonAction)ProUtilAssign, &attr, (int)BY_REF); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProUtilSelectToolatrr", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet((char*)"TkToolAttr",(char*)"-By Copy", (ProMenubuttonAction)ProUtilAssign, &attr, (int)BY_COPY); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProUtilSelectToolatrr", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet((char*)"TkToolAttr",(char*)"TkToolType", (ProMenubuttonAction)ProMenuHold,NULL,0); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProUtilSelectToolatrr", status, status != PRO_TK_NO_ERROR); status = ProMenuCreate(PROMENUTYPE_MAIN,(char*)"TkToolAttr", &id); TEST_CALL_REPORT ("ProMenuCreate", "ProUtilSelectToolatrr", status, status != PRO_TK_NO_ERROR); status = ProMenuProcess((char*)"TkToolAttr", &id); TEST_CALL_REPORT ("ProMenuProcess", "ProUtilSelectToolatrr", status, status != PRO_TK_NO_ERROR); *((int *)app_data) = attr; return attr; } /*====================================================================*\ FUNCTION : ProUtilSelectCreationType() PURPOSE : Menu to select method of tool creation \*====================================================================*/ ToolCreationType ProUtilSelectCreationType() { ToolCreationType value, val1 = FROM_PARAMFILE ; ProError status; int id; status = ProMenuFileRegister((char*)"TkToolType", (char*)"tktooltype.mnu", &id); TEST_CALL_REPORT ("ProMenuFileRegister", "ProUtilSelectCreationType", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet((char*)"TKToolType",(char*)"-Param File", (ProMenubuttonAction)ProUtilAssign, &value, (int)FROM_PARAMFILE); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProUtilSelectCreationType", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet((char*)"TKToolType",(char*)"-Solid", (ProMenubuttonAction)ProUtilAssign, &value, (int)FROM_SOLID); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProUtilSelectCreationType", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet((char*)"TKToolType",(char*)"-Select Attr", (ProMenubuttonAction)ProUtilSelectToolatrr, &val1, (int)FROM_SOLID); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProUtilSelectCreationType", status, status != PRO_TK_NO_ERROR); status = ProMenubuttonActionSet((char*)"TKToolType",(char*)"TkToolType", (ProMenubuttonAction)ProMenuHold,NULL,0); TEST_CALL_REPORT ("ProMenubuttonActionSet", "ProUtilSelectCreationType", status, status != PRO_TK_NO_ERROR); status = ProMenuCreate(PROMENUTYPE_MAIN,(char*)"TKToolType", &id); TEST_CALL_REPORT ("ProMenuCreate", "ProUtilSelectCreationType", status, status != PRO_TK_NO_ERROR); status = ProMenuProcess((char*)"TkToolType", &id); TEST_CALL_REPORT ("ProMenuProcess", "ProUtilSelectCreationType", status, status != PRO_TK_NO_ERROR); if (val1 != FROM_PARAMFILE) { switch (val1) { case BY_COPY: if (value == FROM_SOLID) value = FROM_SOLID_BY_COPY; else value = FROM_PARAMFILE_BY_COPY; break; case BY_REF: if (value == FROM_SOLID) value = FROM_SOLID_BY_REF; else value = FROM_PARAMFILE_BY_REF; break; } } return value; } /*====================================================================*\ FUNCTION : ProUtilToolFromSolidAdd() PURPOSE : Create tool from named part file \*====================================================================*/ ProError ProUtilToolFromSolidAdd( ProToolElem tool_elem) { ProMdl tool_part; wchar_t part_name[PRO_FAMILY_MDLNAME_SIZE]; ProError status; /* Default tool model is "tool.prt" */ ProStringToWstring(part_name, (char*)"tool"); ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s",(char*)"Enter a model name(no type): "); ProUtilStringGet(part_name, NULL,PRO_LINE_SIZE); status = ProMdlnameRetrieve(part_name, (ProMdlfileType)PRO_PART, &tool_part); TEST_CALL_REPORT("ProMdlnameRetrieve()", "ProUtilToolFromSolidAdd()", status, (status != PRO_TK_NO_ERROR)); status = ProToolElemModelSet(tool_elem, tool_part); TEST_CALL_REPORT("ProToolElemModelSet()", "ProUtilToolFromSolidAdd()", status, (status != PRO_TK_NO_ERROR)); return status; }