/* Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved. */ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include <ProToolkit.h> #include <ProAnalysis.h> #include <ProMenu.h> #include <ProFeatType.h> #include <ProExtdata.h> #include <ProPoint.h> #include <ProSolid.h> #include <ProDtmPnt.h> #include <ProModelitem.h> #include <ProArray.h> #include <ProMessage.h> #include <ProUtil.h> #include <ProFeature.h> #include <ProObjects.h> /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include "TestError.h" #include "TestAnalysis.h" #include "PTApplsUnicodeUtils.h" #include "UtilString.h" #include "UtilCollect.h" static ProFileName msgfil; /*====================================================================*\ FUNCTION : ProTestClassRegister() PURPOSE : Register a data class, if it does not already exist \*====================================================================*/ int ProTestClassRegister( ProMdl model, char *class_name, ProExtdataClass *extdata_class) { ProName cname; ProExtdataErr err; if (!ProTestClassExists(model, class_name, extdata_class)) { ProStringToWstring(cname, class_name); err = ProExtdataClassRegister (model, cname, extdata_class); TEST_CALL_REPORT ("ProExtdataClassRegister()", "ProTestClassRegister()", (ProError)err, err != PRO_TK_NO_ERROR); if (err != PROEXTDATA_TK_NO_ERROR) return(0); } return(1); } /*====================================================================*\ FUNCTION : ProTestIntegerSave() PURPOSE : Utility to save an integer \*====================================================================*/ int ProTestIntegerSave( ProExtdataClass *extdata_class, char *slotname, int i) { ProExtdataSlot slot; ProName sname; ProExtdataErr err; /*--------------------------------------------------------------------*\ If the specified slot does not exist, create it \*--------------------------------------------------------------------*/ ProStringToWstring(sname, slotname); err = ProExtdataSlotCreate(extdata_class, sname, &slot); TEST_CALL_REPORT ("ProExtdataSlotCreate()", "ProTestIntegerSave()", (ProError)err, err != PROEXTDATA_TK_NO_ERROR && err != PROEXTDATA_TK_CLASS_OR_SLOT_EXISTS); if (err != PROEXTDATA_TK_NO_ERROR) { slot.p_class = extdata_class; ProStringToWstring (slot.slot_name, slotname); } /*--------------------------------------------------------------------*\ Write the integer to the data slot \*--------------------------------------------------------------------*/ err = ProExtdataSlotWrite (&slot, KEY_BY_NAME, PRO_INTEGER_TYPE, 0, &i); TEST_CALL_REPORT ("ProExtdataSlotWrite()", "ProTestIntegerSave()", (ProError)err, err != PRO_TK_NO_ERROR); return(1); } /*====================================================================*\ FUNCTION : ProTestIntegerRetrieve() PURPOSE : Retrieve an integer \*====================================================================*/ int ProTestIntegerRetrieve( ProExtdataClass *extdata_class, char *slotname, int *i) { ProExtdataSlot slot; int *data; int size, type; ProExtdataErr err; /*--------------------------------------------------------------------*\ Read the integer from the data slot \*--------------------------------------------------------------------*/ slot.p_class = extdata_class; ProStringToWstring(slot.slot_name, slotname); err = ProExtdataSlotRead (&slot, KEY_BY_NAME, &type, &size, (void**)&data); TEST_CALL_REPORT ("ProExtdataSlotRead()", "ProTestIntegerRetrieve()", (ProError)err, err != PRO_TK_NO_ERROR); if (err != PROEXTDATA_TK_NO_ERROR) return(0); *i = *data; return(1); } /*====================================================================*\ FUNCTION : ProTestClassExists PURPOSE : Check if the specified class exists \*====================================================================*/ int ProTestClassExists( ProMdl model, char *name, ProExtdataClass *extdata_class) { ProExtdataErr err; int n_classes, c; ProName *classes; err = ProExtdataClassNamesList (model, &n_classes, &classes); TEST_CALL_REPORT ("ProExtdataClassNamesList()", "ProTestClassExists()", (ProError)err, err != PRO_TK_NO_ERROR); if (err != PROEXTDATA_TK_NO_ERROR) return(0); for (c = 0; c < n_classes; c++) { if (!ProUtilStrwscmp (name, classes[c])) { extdata_class->p_model = model; ProStringToWstring (extdata_class->class_name, name); ProArrayFree ((ProArray *)&classes); return(1); } } ProArrayFree((ProArray *)&classes); return(0); } /*====================================================================*\ FUNCTION : ProTestAtts PURPOSE : Switch COMPUTE_OFF attribute \*====================================================================*/ int ProTestAtts() { ProSelection *sel; int n_sel; ProFeature feature; ProAnalysis analysis; ProName wname; ProCharName name, type; ProBoolean is_set; ProError err; /* Select an analysis feature, and flip the COMPUTE attribute */ ProMessageDisplay (msgfil, (char *)"USER Selected an exteral analysis feature"); while (1) { err = ProSelect ((char *)"feature", 1, NULL, NULL, NULL, NULL, &sel, &n_sel); if (err != PRO_TK_NO_ERROR || n_sel < 1) break; ProSelectionModelitemGet(sel[0], &feature); if(ProFeatureAnalysisGet(&feature, &analysis) != PRO_TK_NO_ERROR) { ProMessageDisplay (msgfil, (char *) "USER Selected feature contains no external analysis. " "Select again"); continue; } /* Should be QCR output */ ProTKPrintf("analysis = %x\n", analysis); err = ProAnalysisTypeGet (analysis, wname); TEST_CALL_REPORT ("ProAnalysisTypeGet()", "ProTestAtts()", err, err != PRO_TK_NO_ERROR); ProWstringToString(type, wname); ProTKPrintf("Selected feature %d with analysis type %s\n", feature.id, type); err = ProAnalysisAttrIsSet (analysis, PROANALYSIS_COMPUTE_OFF, &is_set); TEST_CALL_REPORT ("ProAnalysisAttrIsSet()", "ProTestAtts()", err, err != PRO_TK_NO_ERROR); ProTKPrintf("COMPUTE_OFF = %d\n", is_set); err = ProAnalysisAttrSet(analysis, PROANALYSIS_COMPUTE_OFF, (ProBoolean)!is_set); TEST_CALL_REPORT ("ProAnalysisAttrSet()", "ProTestAtts()", err, err != PRO_TK_NO_ERROR); } return 0; } /*====================================================================*\ FUNCTION : ProTestOutwardsSave PURPOSE : Save direction in slot \*====================================================================*/ int ProTestOutwardsSave( ProFeature *feature, ProBoolean outwards) { ProExtdataClass extdata_class; ProCharName slotname; if (!ProTestClassRegister (feature->owner, (char *)"SURFCSYS", &extdata_class)) return 0; ProTKSprintf (slotname, "OUTWARDS_%d", feature->id); ProTestIntegerSave (&extdata_class, slotname, (int)outwards); return 1; } /*====================================================================*\ FUNCTION : ProTestOutwardsRetrieve PURPOSE : Retrieve direction from slot \*====================================================================*/ int ProTestOutwardsRetrieve( ProFeature *feature, ProBoolean *outwards) { ProExtdataClass extdata_class; ProCharName slotname; int i; if (!ProTestClassExists (feature->owner, (char *)"SURFCSYS", &extdata_class)) return(0); ProTKSprintf (slotname,"OUTWARDS_%d",feature->id); if (!ProTestIntegerRetrieve(&extdata_class, slotname, &i)) return(0); *outwards = i==0 ? PRO_B_FALSE : PRO_B_TRUE; return(1); } /*====================================================================*\ FUNCTION : ProUtilAnalysisFeatureFilter PURPOSE : Filter to collect analysis features \*====================================================================*/ int ProUtilAnalysisFeatureFilter ( ProFeature* p_feature, ProAppData app_data) { ProFeattype feat_type; ProError err; err = ProFeatureTypeGet (p_feature, &feat_type); TEST_CALL_REPORT ("ProFeatureTypeGet()", "ProUtilAnalysisFeatureFilter()", err, err != PRO_TK_NO_ERROR); if (err != PRO_TK_NO_ERROR || feat_type != PRO_FEAT_ANALYSIS) return PRO_TK_CONTINUE; return PRO_TK_NO_ERROR; } /*====================================================================*\ FUNCTION : ProTestListAnalyses PURPOSE : Make qcr output (info about all analysis features) \*====================================================================*/ int ProTestListAnalyses() { ProError err; ProMdl model; ProAnalysis *analyses, analysis; int na, a, nf, f; ProName wname; ProCharName name, type; ProFeature *feats; const char *fname = "list.txt"; FILE *fp; if ((fp = PTApplsUnicodeFopen (fname, "w")) == NULL) return 0; err = ProMdlCurrentGet (&model); TEST_CALL_REPORT ("ProMdlCurrentGet()", "ProTestListAnalyses()", err, err != PRO_TK_NO_ERROR); /* Analyses */ ProTKFprintf (fp, "Saved analyses in current model...\n"); err = ProUtilCollectSolidAnalysis ((ProSolid)model, &analyses); if (err == PRO_TK_E_NOT_FOUND) { ProTKFprintf (fp, "No analyses found\n"); } else if (err != PRO_TK_NO_ERROR) { ProTKFprintf (fp, "ProUtilCollectSolidAnalysis returns error %d\n", err); fclose (fp); return 0; } ProArraySizeGet (analyses, &na); ProTKFprintf(fp, "%d analyses..\n", na); for (a = 0; a < na; a++) { err = ProAnalysisNameGet (analyses[a], wname); TEST_CALL_REPORT ("ProAnalysisNameGet()", "ProTestListAnalyses()", err, err != PRO_TK_NO_ERROR); ProWstringToString(name, wname); err = ProAnalysisTypeGet (analyses[a], wname); TEST_CALL_REPORT ("ProAnalysisNameGet()", "ProTestListAnalyses()", err, err != PRO_TK_NO_ERROR); ProWstringToString(type, wname); ProTKFprintf(fp, "\tAnalysis %d : name %s, type %s\n", a, name, type); } ProArrayFree ((ProArray*)&analyses); /* Analysis features */ ProTKFprintf (fp, "\nAnalysis features in current model...\n"); err = ProUtilCollectSolidFeaturesWithFilter ((ProSolid)model, (ProFeatureFilterAction)ProUtilAnalysisFeatureFilter, &feats); if (err == PRO_TK_E_NOT_FOUND) { ProTKFprintf (fp, "No analysis features found\n"); fclose (fp); return 0; } else if (err != PRO_TK_NO_ERROR) { ProTKFprintf (fp, "ProUtilCollectSolidFeaturesWithFilter returns error %d\n", err); fclose (fp); return 0; } ProArraySizeGet(feats, &nf); for (f = 0; f < nf; f++) { ProTKFprintf(fp, " Feature id %d\n", feats[f].id); err = ProFeatureAnalysisGet(&feats[f], &analysis); TEST_CALL_REPORT ("ProFeatureAnalysisGet()", "ProTestListAnalyses()", err, err != PRO_TK_NO_ERROR); err = ProAnalysisTypeGet (analysis, wname); TEST_CALL_REPORT ("ProAnalysisTypeGet()", "ProTestListAnalyses()", err, err != PRO_TK_NO_ERROR); ProWstringToString(type, wname); ProTKFprintf(fp, ", type %s\n", type); } fclose(fp); ProArrayFree ((ProArray*)&feats); ProStringToWstring(wname, (char *)fname); ProInfoWindowDisplay(wname, NULL, NULL); return 0; } int ProTestAnalysis () { int menu_id; /*--------------------------------------------------------------------*\ Setup analysis menu \*--------------------------------------------------------------------*/ ProMenuFileRegister ((char *)"-ExtAnalysis", (char *)"extanalysis.mnu", &menu_id); ProMenubuttonActionSet ((char *)"-ExtAnalysis", (char *)"Attributes", (ProMenubuttonAction)ProTestAtts, NULL, 0); ProMenubuttonActionSet ((char *)"-ExtAnalysis", (char *)"List Analyses", (ProMenubuttonAction)ProTestListAnalyses, NULL, 0); ProMenubuttonActionSet ((char *)"-ExtAnalysis", (char *)"-ExtAnalysis", (ProMenubuttonAction)ProMenuDelete, NULL, 0); ProMenuCreate(PROMENUTYPE_MAIN, (char *)"-ExtAnalysis", &menu_id); ProMenuProcess((char *)"", &menu_id); return 0; } /*====================================================================*\ FUNCTION : ProTestAnalysisRegister PURPOSE : Register all analysis features classes \*====================================================================*/ int ProTestAnalysisRegister () { ProError err; ProAnalysisFuncsData analysis_data; int menu_id; ProStringToWstring(msgfil,(char *)"analysis_msg.txt"); /*--------------------------------------------------------------------*\ Build the description of the surface csys analysis feature data, and register it with Pro/E \*--------------------------------------------------------------------*/ memset (&analysis_data, '\0', sizeof(ProAnalysisFuncsData)); ProStringToWstring (analysis_data.type, (char *)"Surface Csys"); analysis_data.ui_action = ProTestSurfcsysUiAction; analysis_data.dims_action = ProTestSurfcsysDimsAction; analysis_data.infoalloc_action = ProTestSurfcsysInfoallocAction; analysis_data.infofree_action = ProTestSurfcsysInfofreeAction; analysis_data.compcheck_action = ProTestSurfcsysCompcheckAction; analysis_data.compute_action = ProTestSurfcsysComputeAction; analysis_data.display_action = ProTestSurfcsysDisplayAction; analysis_data.output_action = ProTestSurfcsysOutputAction; analysis_data.savecheck_action = ProTestSurfcsysSavecheckAction; analysis_data.infosave_action = ProTestSurfcsysInfosaveAction; analysis_data.inforetrieve_action = ProTestSurfcsysInforetrieveAction; analysis_data.infocopy_action = ProTestSurfcsysInfocopyAction; analysis_data.result_action = ProTestSurfcsysResultAction; err = ProAnalysisTypeRegister (&analysis_data); TEST_CALL_REPORT ("ProAnalysisTypeRegister()", "ProTestAnalysisRegister()", err, err != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Build the description of the curve wrap analysis feature data, and register it with Pro/E \*--------------------------------------------------------------------*/ memset (&analysis_data, '\0', sizeof(ProAnalysisFuncsData)); ProStringToWstring (analysis_data.type, (char *)"Curve Wrap"); analysis_data.ui_action = ProTestCurvewrapUiAction; analysis_data.dims_action = ProTestCurvewrapDimsAction; analysis_data.infoalloc_action = ProTestCurvewrapInfoallocAction; analysis_data.infofree_action = ProTestCurvewrapInfofreeAction; analysis_data.compcheck_action = ProTestCurvewrapCompcheckAction; analysis_data.compute_action = ProTestCurvewrapComputeAction; analysis_data.display_action = ProTestCurvewrapDisplayAction; analysis_data.output_action = ProTestCurvewrapOutputAction; analysis_data.savecheck_action = ProTestCurvewrapSavecheckAction; analysis_data.infosave_action = ProTestCurvewrapInfosaveAction; analysis_data.inforetrieve_action = ProTestCurvewrapInforetrieveAction; analysis_data.infocopy_action = ProTestCurvewrapInfocopyAction; analysis_data.result_action = ProTestCurvewrapResultAction; err = ProAnalysisTypeRegister (&analysis_data); TEST_CALL_REPORT ("ProAnalysisTypeRegister()", "ProTestAnalysisRegister()", err, err != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Build the description of the point analysis feature data, and register it with Pro/E \*--------------------------------------------------------------------*/ memset (&analysis_data, '\0', sizeof(ProAnalysisFuncsData)); ProStringToWstring (analysis_data.type, (char *)"Surface Point"); analysis_data.ui_action = ProTestSurfcsysUiAction; analysis_data.dims_action = ProTestSurfcsysDimsAction; analysis_data.infoalloc_action = ProTestSurfcsysInfoallocAction; analysis_data.infofree_action = ProTestSurfcsysInfofreeAction; analysis_data.compcheck_action = ProTestSurfcsysCompcheckAction; analysis_data.compute_action = ProTestSurfcsysComputeAction; analysis_data.display_action = ProTestSurfcsysDisplayAction; analysis_data.output_action = ProTestSurfcsysOutputAction; analysis_data.savecheck_action = ProTestSurfcsysSavecheckAction; analysis_data.infosave_action = ProTestSurfcsysInfosaveAction; analysis_data.inforetrieve_action = ProTestSurfcsysInforetrieveAction; analysis_data.infocopy_action = ProTestSurfcsysInfocopyAction; analysis_data.result_action = ProTestSurfpointResultAction; err = ProAnalysisTypeRegister (&analysis_data); TEST_CALL_REPORT ("ProAnalysisTypeRegister()", "ProTestAnalysisRegister()", err, err != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Build the description of the curve analysis feature data, and register it with Pro/E \*--------------------------------------------------------------------*/ memset (&analysis_data, '\0', sizeof(ProAnalysisFuncsData)); ProStringToWstring (analysis_data.type, (char *)"Curve"); analysis_data.ui_action = ProTestCurveUiAction; analysis_data.dims_action = ProTestCurveDimsAction; analysis_data.infoalloc_action = ProTestCurveInfoallocAction; analysis_data.infofree_action = ProTestCurveInfofreeAction; analysis_data.compcheck_action = ProTestCurveCompcheckAction; analysis_data.compute_action = ProTestCurveComputeAction; analysis_data.display_action = ProTestCurveDisplayAction; analysis_data.output_action = ProTestCurveOutputAction; analysis_data.savecheck_action = ProTestCurveSavecheckAction; analysis_data.infosave_action = ProTestCurveInfosaveAction; analysis_data.inforetrieve_action = ProTestCurveInforetrieveAction; analysis_data.infocopy_action = ProTestCurveInfocopyAction; analysis_data.result_action = ProTestCurveResultAction; err = ProAnalysisTypeRegister (&analysis_data); TEST_CALL_REPORT ("ProAnalysisTypeRegister()", "ProTestAnalysisRegister()", err, err != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Build the description of the surface analysis feature data, and register it with Pro/E \*--------------------------------------------------------------------*/ memset (&analysis_data, '\0', sizeof(ProAnalysisFuncsData)); ProStringToWstring (analysis_data.type, (char *)"Surface"); analysis_data.ui_action = ProTestSurfaceUiAction; analysis_data.dims_action = ProTestSurfaceDimsAction; analysis_data.infoalloc_action = ProTestSurfaceInfoallocAction; analysis_data.infofree_action = ProTestSurfaceInfofreeAction; analysis_data.compcheck_action = ProTestSurfaceCompcheckAction; analysis_data.compute_action = ProTestSurfaceComputeAction; analysis_data.display_action = ProTestSurfaceDisplayAction; analysis_data.output_action = ProTestSurfaceOutputAction; analysis_data.savecheck_action = ProTestSurfaceSavecheckAction; analysis_data.infosave_action = ProTestSurfaceInfosaveAction; analysis_data.inforetrieve_action = ProTestSurfaceInforetrieveAction; analysis_data.infocopy_action = ProTestSurfaceInfocopyAction; analysis_data.result_action = ProTestSurfaceResultAction; err = ProAnalysisTypeRegister (&analysis_data); TEST_CALL_REPORT ("ProAnalysisTypeRegister()", "ProTestAnalysisRegister()", err, err != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Build the description of NURBS surface analysis feature data, and register it with Pro/E \*--------------------------------------------------------------------*/ memset (&analysis_data, '\0', sizeof(ProAnalysisFuncsData)); ProStringToWstring (analysis_data.type, (char *)"NURBS Surface"); analysis_data.ui_action = ProTestSurfaceUiAction; analysis_data.dims_action = ProTestSurfaceDimsAction; analysis_data.infoalloc_action = ProTestSurfaceInfoallocAction; analysis_data.infofree_action = ProTestSurfaceInfofreeAction; analysis_data.compcheck_action = ProTestSurfaceCompcheckAction; analysis_data.compute_action = ProTestSurfaceComputeAction; analysis_data.display_action = ProTestSurfaceDisplayAction; analysis_data.output_action = ProTestSurfaceOutputAction; analysis_data.savecheck_action = ProTestSurfaceSavecheckAction; analysis_data.infosave_action = ProTestSurfaceInfosaveAction; analysis_data.inforetrieve_action = ProTestSurfaceInforetrieveAction; analysis_data.infocopy_action = ProTestSurfaceInfocopyAction; analysis_data.result_action = ProTestNURBSSurfaceResultAction; err = ProAnalysisTypeRegister (&analysis_data); TEST_CALL_REPORT ("ProAnalysisTypeRegister()", "ProTestAnalysisRegister()", err, err != PRO_TK_NO_ERROR); /*--------------------------------------------------------------------*\ Build the description of the composite curve analysis feature data, and register it with Pro/E \*--------------------------------------------------------------------*/ memset (&analysis_data, '\0', sizeof(ProAnalysisFuncsData)); ProStringToWstring (analysis_data.type, (char *)"CompCurve"); analysis_data.ui_action = ProTestCompCurveUiAction; analysis_data.dims_action = ProTestCompCurveDimsAction; analysis_data.infoalloc_action = ProTestCompCurveInfoallocAction; analysis_data.infofree_action = ProTestCompCurveInfofreeAction; analysis_data.compcheck_action = ProTestCompCurveCompcheckAction; analysis_data.compute_action = ProTestCompCurveComputeAction; analysis_data.display_action = ProTestCompCurveDisplayAction; analysis_data.output_action = ProTestCompCurveOutputAction; analysis_data.savecheck_action = ProTestCompCurveSavecheckAction; analysis_data.infosave_action = ProTestCompCurveInfosaveAction; analysis_data.inforetrieve_action = ProTestCompCurveInforetrieveAction; analysis_data.infocopy_action = ProTestCompCurveInfocopyAction; analysis_data.result_action = ProTestCompCurveResultAction; err = ProAnalysisTypeRegister (&analysis_data); TEST_CALL_REPORT ("ProAnalysisTypeRegister()", "ProTestAnalysisRegister()", err, err != PRO_TK_NO_ERROR); return 0; }