// 处理过程 BOOL CSDMdlSpecAsmImplicitCheck::DoAction(void *pData, const CheckData &checkData) { ProMdl pMdl = (ProMdl)pData; if (NULL == pMdl) return FALSE; int nCount = (int)checkData.checkResult.arrErrorItems.GetCount(); ProModelitem mdlitem; mdlitem.owner = pMdl; mdlitem.type = PRO_FEATURE; int* parrFeatID = NULL; ProFeatureResumeOptions* parrOpt = NULL; ProArrayAlloc(0, sizeof(int), 1, (ProArray*)&parrFeatID); ProArrayAlloc(0, sizeof(ProFeatureResumeOptions), 1, (ProArray*)&parrOpt); int nID = -1; ProFeatureResumeOptions opt = PRO_FEAT_RESUME_NO_OPTS; for (int i=0; i<nCount; i++) { nID = checkData.checkResult.arrErrorItems[i].nID; ProArrayObjectAdd((ProArray*)&parrFeatID, PRO_VALUE_UNUSED, 1, &nID); ProArrayObjectAdd((ProArray*)&parrOpt, PRO_VALUE_UNUSED, 1, &opt); } ProFeatureResume(ProMdlToSolid(pMdl), parrFeatID, nCount, parrOpt, nCount); ProArrayFree((ProArray *)&parrFeatID); ProArrayFree((ProArray *)&parrOpt); return TRUE; }
/*============================================================================*\ Function: ProUtilMenuStringsAlloc Purpose: Alloc memory for array of wchar_t* used in ProMenu functions \*============================================================================*/ ProError ProUtilMenuStringsAlloc( wchar_t ***w_ptr) { ProError err; static wchar_t w_epmty[] = {'\0'}; wchar_t *w_p = w_epmty; err = ProArrayAlloc(0, sizeof(wchar_t*), 1, (ProArray*)w_ptr); if (err == PRO_TK_NO_ERROR) err = ProArrayObjectAdd((ProArray*)w_ptr, 0, 1, &w_p); return (err); }
/*============================================================================*\ Function: ProUtilMenuStringsWstrAdd Purpose: Alloc memory and add string to MenuStrings array \*============================================================================*/ ProError ProUtilMenuStringsWstrAdd( wchar_t ***w_ptr, wchar_t *w_str) { ProError err; wchar_t *w_p; int len, n_str; len = ProUtilWstrLen(w_str); w_p = (wchar_t*)calloc(len + 1, sizeof(wchar_t)); if (w_p == NULL) return (PRO_TK_GENERAL_ERROR); ProUtilWstrcpy(w_p, w_str); err = ProArraySizeGet((ProArray)*w_ptr, &n_str); err = ProArrayObjectAdd((ProArray*)w_ptr, n_str-1, 1, &w_p); return (err); }
/*============================================================================*\ Function: ProUtilMenuStringsStrAdd Purpose: Alloc memory and add string to MenuStrings array \*============================================================================*/ ProError ProUtilMenuStringsStrAdd( wchar_t ***w_ptr, char *str) { ProError err; wchar_t *w_p; int n_str; int len = static_cast<int>(strlen(str)); w_p = (wchar_t*)calloc(len + 1, sizeof(wchar_t)); if (w_p == NULL) return (PRO_TK_GENERAL_ERROR); ProStringToWstring(w_p, str); err = ProArraySizeGet((ProArray)*w_ptr, &n_str); err = ProArrayObjectAdd((ProArray*)w_ptr, n_str-1, 1, &w_p); return (err); }
// 环边裁剪 void OnTrimByEdgeActFn() { /*if (!QuickCheckValidLicense(SMART_PROFESSIONAL)) return;*/ AFX_MANAGE_STATE(AfxGetStaticModuleState()); DestroyAllDialog(); CancelSelectDialog(); Sleep(50); // 第1步:检查当前模型环境 ProMdl pMdl = GetCurrentMdl(); if (pMdl == NULL) { MessageBox(NULL, L"当前环境未发现模型!", L"提示", MB_OK|MB_ICONWARNING); return; } // 第2步:选择要裁剪的面 ShowMessageTip(L"Tips.选择需要裁剪的面..."); vector<ProSelection> arrSelSrf; ProSelection selSrf = NULL; while (SelectObject(arrSelSrf, "dtmqlt")) { ProSelectionCopy(arrSelSrf[0], &selSrf); // 第3步:暂时隐藏选择的面,选取完成后恢复显示 ProModelitem itemQuilt; ProSelectionModelitemGet(arrSelSrf[0], &itemQuilt); ProModelitemHide(&itemQuilt); // 第4步:选择面上的环(先选取环的一条边) int nEdgeDir = PRO_EDGE_SAME_DIRECTION; ProSelection *pArrSelInit = NULL; ProArrayAlloc(0, sizeof(ProSelection), 1, (ProArray*)&pArrSelInit); vector<ProSelection> arrSelEdge; while (SelectObject(arrSelEdge, "sldedge")) { // 第5步:获取边所在环的全部边 vector<ProSelection> arrSelContourEdges; if (GetContourByEdge(arrSelEdge[0], arrSelContourEdges, nEdgeDir)) { for (int i=0; i<arrSelContourEdges.size(); i++) { ProArrayObjectAdd((ProArray*)&pArrSelInit, 0, 1, &arrSelContourEdges[i]); } break; } else { int nMsgResult = MessageBox(NULL, L"选取的边不是完整环的组成边,是否手动选取?\n是:手动选取;否:重新选取; 取消:退出", L"提示", MB_YESNOCANCEL|MB_ICONWARNING); if (nMsgResult == IDYES) // 手动选择 { ProArrayObjectAdd((ProArray*)&pArrSelInit, 0, 1, &arrSelEdge[0]); break; } else if (nMsgResult == IDCANCEL) // 退出 { ProModelitemUnhide(&itemQuilt); InvalidateDrawing(); return; } } } // 第6步:自动选中对应完整环的全部边 arrSelEdge.clear(); if (SelectObject(arrSelEdge, "edge", MAX_SELECTION, pArrSelInit)) { // 判断面的方向 /*ProQuilt quilt; BOOL bSurfDirOut = FALSE; ProGeomitemToQuilt(&itemQuilt, &quilt); vector<ProSurface> arrSurfaces; ProQuiltSurfaceVisit(quilt, QuiltSurfacesGetAction, NULL, &arrSurfaces); ProGeomitemdata* psrfdata; ProSurfaceDataGet(arrSurfaces[0], &psrfdata); if (psrfdata->data.p_surface_data->orient == PRO_SURF_ORIENT_OUT) bSurfDirOut = TRUE; ProGeomitemdataFree(&psrfdata);*/ // 第7步:修剪曲面 int nFeatID = TrimQuiltByEdgeGroup(pMdl, selSrf, arrSelEdge, nEdgeDir); ProModelitemUnhide(&itemQuilt); SAFE_DELETE_PROARRAY(pArrSelInit); if (nFeatID > 0) { // 第8步:提示是否反向或继续修剪 CDlgConfirm dlg; while (1) { int nResult = (int)dlg.DoModal(); if (nResult == IDOK) { break; } else if (nResult == IDRETRY) { // 修改裁剪方向 ProFeature feat; feat.id = nFeatID; feat.type = PRO_FEATURE; feat.owner = pMdl; ReverseTrimDirection(feat); } else { InvalidateDrawing(); ProMessageClear(); return; } } } else if (MessageBox(NULL, L"裁剪失败,详见模型特征树。是否继续?", L"提示", MB_YESNO) == IDNO) { break; } } else { // 恢复显示 ProModelitemUnhide(&itemQuilt); break; } } InvalidateDrawing(); ProMessageClear(); }
// 加载包覆对象 void OnLoadSolidActFn() { /*if (!QuickCheckValidLicense(SMART_PROFESSIONAL)) return;*/ AFX_MANAGE_STATE(AfxGetStaticModuleState()); DestroyAllDialog(); CancelSelectDialog(); Sleep(50); // 选择一个本地的待包覆模型 ProPath pathSelModel; if (ProFileOpen(L"选择待包覆模型", L"*.prt,*.asm,*.stp,*.stl", NULL, NULL, NULL, NULL, pathSelModel) == PRO_TK_NO_ERROR) { ProPath pathFolder; ProName nameModel, nameExt; int nVersion; ProFilenameParse(pathSelModel, pathFolder, nameModel, nameExt, &nVersion); ProMdl pMdlToCoating; if (CString(nameExt).CompareNoCase(L"stp") == 0 || CString(nameExt).CompareNoCase(L"step") == 0) { LoadStep(CString(pathSelModel), pMdlToCoating); } else { ProMdlLoad(pathSelModel, PRO_MDL_UNUSED, PRO_B_FALSE, &pMdlToCoating); } // 创建一个装配体 CString strSolidName; strSolidName = nameModel; strSolidName.Format(L"%s_3DCoat", strSolidName); ProName nameSolid; wcsncpy_s(nameSolid, PRO_NAME_SIZE, strSolidName, _TRUNCATE); ProSolid solid; ProSolidCreate(nameSolid, PRO_ASSEMBLY, &solid); // 创建默认坐标系 ProError status; ProElement elemTree = NULL; ProElementAlloc(PRO_E_FEATURE_TREE, &elemTree); { // 特征类型PRO_E_FEATURE_TYPE ProElement elemType; status = ProElementAlloc(PRO_E_FEATURE_TYPE, &elemType); status = ProElemtreeElementAdd(elemTree, NULL, elemType); ProValueData valdataType; valdataType.type = PRO_VALUE_TYPE_INT; valdataType.v.i = PRO_FEAT_CSYS; ProValue valueType = NULL; status = ProValueAlloc(&valueType); status = ProValueDataSet(valueType, &valdataType); status = ProElementValueSet(elemType, valueType); } ProModelitem itemAssmble; ProMdlToModelitem(ProAssemblyToMdl(solid), &itemAssmble); ProSelection selAssmble; ProSelectionAlloc(NULL, &itemAssmble, &selAssmble); ProErrorlist errorsList; ProFeatureCreateOptions opts[1] = {PRO_FEAT_CR_NO_OPTS}; ProFeature feat; status = ProFeatureCreate(selAssmble, elemTree, opts, 1, &feat, &errorsList); // 将选择的待装配模型装配到装配体下 ProMatrix initPos = { {1.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 1.0} }; ProAsmcomp comp; ProAsmcompAssemble(ProAssembly(solid), ProMdlToSolid(pMdlToCoating), initPos, &comp); ProAsmcompconstraint compConstr; ProAsmcompconstraintAlloc(&compConstr); ProAsmcompconstraintTypeSet(compConstr, PRO_ASM_DEF_PLACEMENT); ProAsmcompconstraint* compConstrs; ProArrayAlloc (0, sizeof (ProAsmcompconstraint), 1, (ProArray*)&compConstrs); status = ProArrayObjectAdd ((ProArray*)&compConstrs, -1, 1, &compConstr); ProAsmcompConstraintsSet(NULL, &comp, compConstrs); ProMdlDisplay(solid); int nWnd; ProWindowCurrentGet(&nWnd); ProWindowActivate(nWnd); } InvalidateDrawing(); ProMessageClear(); }
/*============================================================================*\ Function: ProUtilMenuStringManySelect Purpose: Select many string from menu with submenu Select All/Unsell All \*============================================================================*/ ProError ProUtilMenuStringManySelect( char *menu_name, /* In : Menu name */ wchar_t **w_menu_buttons, /* In : Menu buttons */ int **output_array, /* Out: ProArray of numbers of selected strings, use ProArrayFree to free memory */ int *p_n_sel) /* Out: Number of selected components */ { int i, n_but, n_sel, menu_id, action; ProError err, ret_status = PRO_TK_USER_ABORT; int *toggle_array; MenuToggleInfo toggle_info; ProCharName name; wchar_t **w_menus; for(n_but=0; w_menu_buttons[n_but][0] != '\0'; n_but++); err = ProArrayAlloc(n_but, sizeof(int), 1, (ProArray*)&toggle_array); toggle_info.w_menu_buttons = w_menu_buttons; toggle_info.button_status = toggle_array; toggle_info.n_buttons = n_but; toggle_info.menu_name = menu_name; err = ProMenuFromStringsRegister ( menu_name, NULL, w_menu_buttons, NULL, NULL, &menu_id); for (i=0; i<n_but; i++) { toggle_array[i] = 0; ProWstringToString(name, w_menu_buttons[i]); err = ProMenubuttonActionSet(menu_name, name, (ProMenubuttonAction)ProUtilMenuToggleOne, &toggle_info, i); } err = ProMenubuttonActionSet(menu_name, menu_name, (ProMenubuttonAction)ProMenuDelete, NULL, 0); err = ProMenuModeSet(menu_name, PROMENUMODE_DATA); err = ProMenuDatamodeSet(menu_name, PRO_B_TRUE ); err = ProMenuCreate(PROMENUTYPE_MAIN, menu_name, &menu_id); err = ProUtilMenuStringsAlloc(&w_menus); err = ProUtilMenuStringsStrAdd(&w_menus, (char *)"Select All"); err = ProUtilMenuStringsStrAdd(&w_menus, (char *)"Unsel All"); err = ProUtilMenuStringsStrAdd(&w_menus, (char *)"Done Sel"); err = ProUtilMenuStringsStrAdd(&w_menus, (char *)"Quit Sel"); ProMenuFromStringsRegister ( (char *)"TkMenuUtilSelect", NULL, w_menus, NULL, NULL, &menu_id); err = ProMenubuttonActionSet((char *)"TkMenuUtilSelect", (char *)"Select All", (ProMenubuttonAction)ProUtilMenuToggleDone, &toggle_info, SELECT_ALL); err = ProMenubuttonActionSet((char *)"TkMenuUtilSelect", (char *)"Unsel All", (ProMenubuttonAction)ProUtilMenuToggleDone, &toggle_info, UNSEL_ALL); err = ProMenubuttonActionSet((char *)"TkMenuUtilSelect", (char *)"Done Sel", (ProMenubuttonAction)ProUtilMenuToggleDone, &toggle_info, DONE_SEL); err = ProMenubuttonActionSet((char *)"TkMenuUtilSelect", (char *)"Quit Sel", (ProMenubuttonAction)ProUtilMenuToggleDone, &toggle_info, QUIT_SEL); err = ProMenubuttonActionSet((char *)"TkMenuUtilSelect", (char *)"TkMenuUtilSelect", (ProMenubuttonAction)ProUtilMenuToggleDone, &toggle_info, QUIT_SEL); err = ProMenuCreate(PROMENUTYPE_SUB, (char *)"TkMenuUtilSelect", &menu_id); err = ProMenuProcess((char *)"TkMenuUtilSelect", &action); if(err == PRO_TK_NO_ERROR && action == DONE_SEL) { err = ProArrayAlloc(0, sizeof(int), 1, (ProArray*)output_array); n_sel = 0; for (i=0; i<n_but; i++) if (toggle_array[i]) { ProArrayObjectAdd((ProArray*)output_array, PRO_VALUE_UNUSED, 1, &i); n_sel++; } if (n_sel>0) { *p_n_sel = n_sel; ret_status = PRO_TK_NO_ERROR; } else err = ProArrayFree((ProArray*)output_array); } err = ProArrayFree((ProArray*)&toggle_array); return (ret_status); }
/*====================================================================*\ FUNCTION : ProUtilElemPrint() PURPOSE : Visit function. \*====================================================================*/ ProError ProUtilElemPrint( ProElement elem_tree, ProElement elem, ProElempath elem_path, FeatureElemPrintData* p_data ) { ProError status; ProElemId elem_id; int dimension_id = -1; ProBoolean is_visible; ProBoolean is_incomplete; ProBoolean is_compound; ProBoolean is_array; ProBoolean is_multival; ProValue* p_values; ProValue value; int array_size; ProValueData value_data; char value_data_str[ 48 ]; int i; ProBoolean flag = PRO_B_TRUE; status = ProElementIdGet( elem, &elem_id ); TEST_CALL_REPORT("ProElementIdGet()", "ProUtilElemPrint()", PRO_TK_NO_ERROR, status != PRO_TK_NO_ERROR); ProTKFprintf( p_data->fp, "Element ID: %d\n", elem_id ); status = ProFeatureElemIsVisible( p_data->p_feature, elem_path, &is_visible ); #if 0 TEST_CALL_REPORT("ProFeatureElemIsVisible()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR ); #else /* This function return PRO_TK_E_NOT_FOUND for Element FEATURE_TYPE, from feature PRO_FEAT_DATUM_QUILT (it's a bug)*/ TEST_CALL_REPORT("ProFeatureElemIsVisible()", "ProUtilElemPrint()", status, 0); #endif status = ProFeatureElemIsIncomplete( p_data->p_feature, elem_path, &is_incomplete ); #if 0 /* spr 751801 */ TEST_CALL_REPORT( "ProFeatureElemIsIncomplete()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR); #else TEST_CALL_REPORT( "ProFeatureElemIsIncomplete()", "ProUtilElemPrint()", status, 0 ); #endif status = ProElementIsCompound( elem, NULL, &is_compound ); TEST_CALL_REPORT("ProElementIsCompound()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR); status = ProElementIsArray(elem, NULL, &is_array ); TEST_CALL_REPORT("ProElementIsArray()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR); ProTKFprintf( p_data->fp, is_visible == PRO_B_TRUE ? "\tVisible\n" : "\tInvisible\n" ); ProTKFprintf( p_data->fp, is_incomplete == PRO_B_TRUE ? "\tIncomplete\n" : "\tComplete\n" ); ProTKFprintf( p_data->fp, is_compound == PRO_B_TRUE ? "\tCompound\n" : (is_array == PRO_B_TRUE ? "\tArray\n" : "\tNeither compound nor array\n")); if( is_compound == PRO_B_TRUE || is_array == PRO_B_TRUE) return PRO_TK_NO_ERROR; status = ProFeatureElemDimensionIdGet( p_data->p_feature, elem_path, &dimension_id ); TEST_CALL_REPORT("ProFeatureElemDimensionIdGet()", "ProUtilElemPrint()", status, (status != PRO_TK_NO_ERROR)&& (status != PRO_TK_E_NOT_FOUND)); if (status != PRO_TK_E_NOT_FOUND) ProTKFprintf( p_data->fp, "\tDimension ID: %d\n", dimension_id ); else ProTKFprintf( p_data->fp, "\tThis element does not contain dimension\n"); status = ProArrayAlloc( 0, sizeof(ProValue), 1, (ProArray*)&p_values ); TEST_CALL_REPORT( "ProArrayAlloc()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR ); status = ProElementIsMultival(elem, NULL, &is_multival); TEST_CALL_REPORT( "ProElementIsMultival", "ProUtilElemPrint", status, status != PRO_TK_NO_ERROR); if (is_multival == PRO_B_TRUE) { status = ProFeatureElemValuesGet( p_data->p_feature, elem_path, &p_values ); #if 0 TEST_CALL_REPORT( "ProFeatureElemValuesGet()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR ); #else /* ProFeatureElemValuesGet() - returns PRO_TK_E_NOT_FOUND in the PIPE mode for Element PRO_E_STD_EDGE_CHAMF_EDGES.(bugminsk1347)*/ TEST_CALL_REPORT( "ProFeatureElemValuesGet()", "ProUtilElemPrint()", status, 0 ); #endif } else { status = ProElementValueGet(elem, &value); TEST_CALL_REPORT( "ProElementValueGet", "ProUtilElemPrint", status, status != PRO_TK_NO_ERROR); status = ProArrayObjectAdd((ProArray*)&p_values, PRO_VALUE_UNUSED, 1, &value); TEST_CALL_REPORT( "ProArrayObjectAdd", "ProUtilElemPrint", status, status != PRO_TK_NO_ERROR); } if (p_values!=NULL){ array_size = 0; status = ProArraySizeGet( (ProArray)p_values, &array_size ); TEST_CALL_REPORT( "ProArraySizeGet()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR ); ProTKFprintf( p_data->fp, "\t%s\n",(i=1)?"Value:":"Values:" ); for( i=0; i<array_size; i++ ) { /*To avoid PRO_E_SKETCHER and PRO_E_PATTERN, following condition is set*/ if(( elem_id == 458) || (elem_id == 27)) flag = PRO_B_FALSE; if(flag == PRO_B_TRUE) { status = ProValueDataGet( p_values[i], &value_data ); TEST_CALL_REPORT( "ProValueDataGet()", "ProUtilElemPrint()", status, status != PRO_TK_NO_ERROR ); switch( value_data.type ) { case PRO_VALUE_TYPE_INT: ProTKSprintf( value_data_str, "%d", value_data.v.i ); break; case PRO_VALUE_TYPE_DOUBLE: ProTKSprintf( value_data_str, "%f", value_data.v.d ); break; case PRO_VALUE_TYPE_POINTER: ProTKSprintf( value_data_str, "Pointer=*", value_data.v.p ); break; case PRO_VALUE_TYPE_STRING: if ( value_data.v.s !=NULL) ProTKSprintf( value_data_str, "%s", value_data.v.s ); else ProTKSprintf( value_data_str,"<NULL>" ); break; case PRO_VALUE_TYPE_WSTRING: /* NOTE - NULL is possible in some element trees (for example, for the element PRO_E_STD_FEATURE_NAME where NULL means that feature has the default name) */ if ( value_data.v.w !=NULL) ProWstringToString( value_data_str, value_data.v.w ); else ProTKSprintf( value_data_str,"<NULL>" ); break; case PRO_VALUE_TYPE_SELECTION: ProTKSprintf( value_data_str, "Selection" ); break; case PRO_VALUE_TYPE_TRANSFORM: ProTKSprintf( value_data_str, "Transformation" ); break; default: ProTKSprintf( value_data_str, "**UNKNOWN**\n" ); } ProTKFprintf( p_data->fp, "\t%s\n", value_data_str ); } } status = ProArrayFree( (ProArray*)&p_values ); TEST_CALL_REPORT( "ProArrayFree()", "ProUtilFeatureElementsDump()", status, status != PRO_TK_NO_ERROR ); } return PRO_TK_NO_ERROR; }