//drawing:
int CreateDrawingWithTemplFormat(ProMdl model)
{
ProDrawing drawing;
ProModel model_data;
ProMdldata mdl_data;
status = ProMdlDataGet (model, &mdl_data);
char strtmp[PRO_PATH_SIZE];
ProWstringToString(strtmp, mdl_data.name);
ProStringToWstring(model_data.name, strtmp);
ProWstringToString(strtmp, mdl_data.type);
ProStringToWstring(model_data.type, strtmp);
char form_name[PRO_NAME_SIZE] = "templ_form_a4.frm";
char tmplt_name[PRO_NAME_SIZE] = "view_tmplt.drw";
ProName w_form_name;
ProMdl format;
ProStringToWstring(w_form_name, form_name);
status = ProMdlRetrieve(w_form_name, PRO_MDL_DWGFORM, &format);
ProName w_predefined_template;
ProDwgcreateErrs drawing_create_errors;
ProDwgcreateOptions ptions = PRODWGCREATE_SHOW_ERROR_DIALOG;
ProStringToWstring(w_predefined_template, tmplt_name);
status = ProDrawingFromTmpltCreate(w_drawing_name, w_predefined_template, &model_data, options, &drawing, &drawing_create_errors);
int new_win_id;
status = ProObjectwindowCreate(w_drawing_name, PRO_DRAWING, &new_win_id);
status = ProWindowCurrentSet(new_win_id);
status = ProWindowActivate(new_win_id);
status = ProMdlDisplay(drawing);
status = ProDrawingFormatAdd(drawing, -1, (ProSolid)model, format, -1);
double scale = 1.0;
status = ProDrawingScaleSet(drawing, (ProSolid)model, -1, scale);
status = ProDwgDraftRegenerate(drawing);
return 0;
}
int UsrTableTextAdd(ProDwgtable *table, int col, int row, char *text)
{
ProWstring *lines;
ProArrayAlloc(1, sizeof(ProWstring), 1, (ProArray*)&lines);
lines[0] = (wchar_t*)calloc(strlen(text) + 1, sizeof(wchar_t));
ProStringToWstring(lines[0], text);
status = ProDwgtableTextEnter(table, col, row, lines);
ProArrayFree((ProArray*)&lines);
return 0;
}
int CreateMakeContentTalbe(ProDrawing drawing)
{
int num_kezi = 2;
int num_attention = 2;
const int colum = 2;
cosnt int row = 5;
ProVector pos={350,180+13*row,0};
double widths[] = {30, 20};
ProHorzJust justs[] = {PROHORZJUST_LEFT, PROHORZJUST_CENTER};
ProDwgtabledata tdata;
status = ProDwgtabledataAlloc(&tdata);
status = ProDwgtabledataOriginSet(tdata, pos);
status = ProDwgtabledataSizetypeSet(tdata, PRODWGTABLESIZE_CHARACTERS);
status = ProDwgtabledataColumnsSet(tdata, colum, widths, justs);
double *heights;
heights = (double*)calloc(row, sizeof(double));
for(int p=0;p {
heights[p] = 1.0;
}
status = ProDwgtabledataRowsSet(tdata, row, heights);
free(heights);
ProDwgtable table;
status = ProDrawingTableCreate(drawing, tdata, PRO_B_FALSE, &table);
for (int m=0; m<=num_attention; m++)
{
status = ProDwgtableCellsMerge(&table, 1, row-m, 2, row-m, PRO_B_FALSE);
}
for (int k=1; k<=num_kezi; k++)
{
UsrTableTextAdd(&table, 1, k, drawingInfo.dwg_kezi[k-1].keziNote.GetBuffer(0));
if (!drawingInfo.dwg_kezi[k-1].keziValue.IsEmpty())
{
UsrTableTextAdd(&table, 2, k, drawingInfo.dwg_kezi[k-1].keziValue.GetBuffer(0));
}
}
CString markDepth;
markDepth.Format("%.3f mm", drawingInfo.depth);
UsrTableTextAdd(&table, 1, row-num_attention-1, "DEEP OF MARK");
UsrTableTextAdd(&table, 2, row-num_attention-1, markDepth.GetBuffer(0));
UsrTableTextAdd(&table, 1, row-num_attention, "Please pay attention to the direction.");
for (int i=0; i {
UsrTableTextAdd(&table, 1, row-i, drawingInfo.dwg_attention[i].GetBuffer(0));
}
status = ProDwgtableDisplay(&table);
return 0;
}
void SetRadiusLocation(ProPoint3d outline[], ProPoint3d midOutline, ProPoint3d location, double radius)
{
if( location[0] < midOutline[0] ) //left
{
location[0] = location[0] + (radius + 10);
}
else //right
{
location[0] = location[0] - (radius + 10);
}
if( location[1] < midOutline[1]) //bottom
{
location[1] = location[1] + (radius + 10);
}
else //top
{
location[1] = location[1] - (radius + 10);
}
}
void SetPositionLocation(ProPoint3d outline[], ProPoint3d midOutline, ProPoint3d location, bool isHorizontal)
{
if( isHorizontal ) // isHorizontal dimension
{
if( location[1] < midOutline[1] ) //bottom
{
location[1] = outline[0][1] - 5 ;
}
else //top
{
location[1] = outline[1][1] + 5;
}
}
else //vertial
{
if( location[0] < midOutline[0] ) //left
{
location[0] = outline[0][0] - 5 ;
}
else //right
{
location[0] = outline[1][0] + 5 ;
}
}
return 0;
}
int CreateDwgDim()
{
ProSelection *attachments = NULL;
ProDimSense *senses;
ProVector location = {centerViewPnt[0],centerViewPnt[1],0};
//alloc
ProArrayAlloc(2, sizeof(ProSelection), 1, (ProArray*)&attachments);
ProArrayAlloc(2, sizeof(ProDimSense), 1, (ProArray*)&senses);
status = ProSelectionAlloc(&max_plate.compPath, (ProModelitem*)&g_edges[k], &edgeSel);
status = ProSelectionCopy(edgeSel, &attachments[0]);
status = ProSelectionCopy(m_moldCsysSel, &attachments[1]);
status = ProSelectionViewSet(coView, &attachments[0]);
status = ProSelectionViewSet(coView, &attachments[1]);
if( !isPosDim ) //create radius dim
{
senses[0].type = PRO_DIM_SNS_TYP_NONE;
senses[0].sense = PRO_DIM_SNS_TYP_NONE;
senses[0].orient_hint = PRO_DIM_ORNT_ELPS_RAD1;
senses[1].type = PRO_DIM_SNS_TYP_NONE;
senses[1].sense = PRO_DIM_SNS_TYP_NONE;
senses[1].orient_hint = PRO_DIM_ORNT_ELPS_RAD1;
//position
SetRadiusLocation(outline, midOutline, location, radius);
status = ProDrawingDimCreate(drawing, attachments, senses, location,PRO_B_FALSE, &dimension);
//free
ProArrayFree((ProArray*)&attachments);
ProArrayFree((ProArray*)&senses);
status = ProDimensionDecimalsSet(&dimension, 2);
status = ProDimensionShow(&dimension, coView, drawing, NULL);
}
else //create position dim
{
ProPoint3d csys_3dpos={0,0,0};
//horizontal
senses[0].type = PRO_DIM_SNS_TYP_PNT;
senses[0].sense = PRO_POINT_TYP_CENTER;
senses[0].orient_hint = PRO_DIM_ORNT_HORIZ;
senses[1].type = PRO_DIM_SNS_TYP_PNT;
senses[1].sense = PRO_POINT_TYP_CENTER;
senses[1].orient_hint = PRO_DIM_ORNT_NONE;
//position
SetPositionLocation(outline, midOutline, location, true);
status = ProDrawingDimCreate(drawing, attachments, senses, location,PRO_B_FALSE, &dimension);
status = ProDimensionDecimalsSet(&dimension, 2);
status = ProDimensionShow(&dimension, coView, drawing, NULL);
//change to ordinate
if ( view_name == VIEW_CO_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_co_hori);
if (status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_co_hori);
}
}
else if ( view_name = VIEW_CA_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_ca_hori);
if(status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_ca_hori);
}
}
//vertial different position and orient_hint
location[0] = centerViewPnt[0] ;
location[1] = centerViewPnt[1] ;
location[2] = 0;
SetPositionLocation(outline, midOutline, location, false);
//sense change
senses[0].orient_hint = PRO_DIM_ORNT_VERT;
status = ProDrawingDimCreate(drawing, attachments, senses, location,PRO_B_FALSE, &dimension);
ProDimensionDecimalsSet(&dimension, 2);
ProDimensionShow(&dimension, coView, drawing, NULL);
//free
ProArrayFree((ProArray*)&attachments);
ProArrayFree((ProArray*)&senses);
//change to ordinate
if ( view_name == VIEW_CO_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_co_vert);
if (status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_co_vert);
}
}
else if ( view_name = VIEW_CA_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_ca_vert);
if (status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_ca_vert);
}
}
}
}
// quilt solidify
ProError TKSolidifyCreate(ProSelection model_sel, ProSelection p_qiult_sel, int feat_type, ProFeature *feature)
{
ProElement pro_e_feature_tree;
ProElement pro_e_feature_type;
ProElement pro_e_feature_form;
ProElement pro_e_patch_quilt;
ProElement pro_e_patch_type;
ProElement pro_e_patch_material_side;
ProElement pro_e_std_feature_name;
ProError status;
ProValue value;
ProValueData value_data;
ProBoolean is_interactive = PRO_B_TRUE;
//Populating root element PRO_E_FEATURE_TREE
status = ProElementAlloc ( PRO_E_FEATURE_TREE, &pro_e_feature_tree );
//Populating element PRO_E_FEATURE_TYPE
status = ProElementAlloc ( PRO_E_FEATURE_TYPE, &pro_e_feature_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = feat_type; //PRO_FEAT_CUT
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_feature_type, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_type );
//Populating element PRO_E_FEATURE_FORM.
status = ProElementAlloc ( PRO_E_FEATURE_FORM, &pro_e_feature_form. );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_USE_SURFS;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_feature_form, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_form. );
//Populating element PRO_E_PATCH_QUILT
status = ProElementAlloc ( PRO_E_PATCH_QUILT, &pro_e_patch_quilt );
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = p_qiult_sel;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_patch_quilt, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_patch_quilt );
//Populating element PRO_E_PATCH_TYPE
status = ProElementAlloc ( PRO_E_PATCH_TYPE, &pro_e_patch_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = feat_type; //PRO_FEAT_CUT
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_patch_type, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_patch_type );
//Populating element PRO_E_PATCH_MATERIAL_SIDE
status = ProElementAlloc ( PRO_E_PATCH_MATERIAL_SIDE, &pro_e_patch_material_side );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_patch_material_side );
//Populating element PRO_E_STD_FEATURE_NAME
status = ProElementAlloc ( PRO_E_STD_FEATURE_NAME, &pro_e_std_feature_name );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_feature_name);
// create feature
ProErrorlist errors;
ProFeatureCreateOptions opts[1];
opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT;
status = ProFeatureCreate (model_sel, pro_e_feature_tree, opts, 1, feature, &errors);
ProElementFree (&pro_e_feature_tree );
return status;
}
// surface color set
int TKSurfaceColorSet(ProMdl p_model, ProSurface p_surf, double rgb[3])
{
int status;
int surf_id;
Pro_surf_props props;
status = ProSurfaceIdGet(p_surf,&surf_id);
status = prodb_get_surface_props((Prohandle)p_model,SEL_3D_SRF,surf_id,0,&props);
if (status == PRODEV_SURF_PROPS_NOT_SET) {
props.ambient = 0.90;
props.diffuse = 0.90;
props.highlite = 0.99;
props.shininess = 0.50;
props.threshold = 90;
props.transparency = 0.0;
}
props.highlight_color[0] = rgb[0]/255.0;
props.highlight_color[1] = rgb[1]/255.0;
props.highlight_color[2] = rgb[2]/255.0;
props.color_rgb[0] = rgb[0]/255.0;
props.color_rgb[1] = rgb[1]/255.0;
props.color_rgb[2] = rgb[2]/255.0;
status = prodb_set_surface_props((Prohandle)p_model,SEL_3D_SRF,surf_id,0,&props);
return 0;
}
// 輸出STP,IGS檔案
ProIntf3DFileWrite
ProOutputFileWrite
// 輸出PV檔案
ProProductviewExport
// 在關係式中添加自定義函數
ProRelationFunctionRegister
// 擺正視圖
int AjustView()
{
ProMatrix matrix;
status = ProViewMatrixGet(NULL,NULL,matrix);
ProUtilMatrixNormalize(matrix);
// 將視圖矩陣的每一行(前3行)的絕對值最大值設為1/-1(與哪個接近設為哪個)
ResetView(matrix);
status = ProViewMatrixSet(NULL,NULL,matrix);
status = ProViewRefit(NULL, NULL);
status = ProWindowRepaint(-1);
}
// 框選曲面
// 框選其他的物件同此原理,只需將其轉換為點是否在框內
// PART -> SURFACE -> EDGE -> POINT
int UserSurfaceUVPntGet(
ProPart hPart,
ProSurface hSurf,
int iSurfCheckInterval,
ProUvParam uv_point,
ProVector xyz_point)
{
//ProUvParam uv_point;
//ProVector xyz_point;
ProVector srf_deriv1[2],srf_deriv2[2],direction;
ProSrftype surf_type;
ProUvParam uv_min,uv_max;
ProSurfaceOrient surf_orient;
ProSurfaceshapedata surf_shape;
int surf_id;
ProGeomitemdata *gdata;
ProUvStatus uv_status;
ProSurfaceDataGet(hSurf,&gdata);
ProSurfacedataGet(gdata->data.p_surface_data,&surf_type,uv_min,uv_max,&surf_orient,&surf_shape,&surf_id);
ProGeomitemdataFree(&gdata);
uv_point[0] = (uv_max[0] + uv_min[0]) / 2.0;
uv_point[1] = (uv_max[1] + uv_min[1]) / 2.0;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
return 1;
}
int i,j;
for (i=0;i {
uv_point[0] = uv_min[0] + (uv_max[0] - uv_min[0]) * i / iSurfCheckInterval;
for (j=0;j {
uv_point[1] = uv_min[1] + (uv_max[1] - uv_min[1]) * j / iSurfCheckInterval;
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
return 1;
}
}
}
return 0;
}
int UserIsPointOutOfBox(
ProVector pnt,
ProOutline box_outline)
{
if (pnt[0] < box_outline[0][0] ||
pnt[0] > box_outline[1][0] ||
pnt[1] < box_outline[0][1] ||
pnt[1] > box_outline[1][1] )
{
return 1;
}
return 0;
}
int UserIsSurfaceAtFrontFromRay(
ProPart hPart,
ProSurface hSurf,
ProRay ray)
{
ProSelection *hSels;
int nSel;
ProBoolean bIsInactive;
ProQuilt hQuilt;
int k,iFirstIndex;
ProGeomitem gitem;
ProSurface hSurfTmp;
ProEdge hEdge;
status = ProSolidRayIntersectionCompute((ProSolid)hPart,-1,&ray,&hSels,&nSel);
if (nSel <= 0) return 0;
iFirstIndex = -1;
for (k=0;k {
status = ProSelectionVerify(hSels[k]);
if (status != PRO_TK_NO_ERROR) continue;
status = ProSelectionModelitemGet(hSels[k],(ProModelitem *)&gitem);
if (status != PRO_TK_NO_ERROR) continue;
status = ProGeomitemIsInactive(&gitem,&bIsInactive);
if (bIsInactive == PRO_B_TRUE) continue;
status = ProGeomitemToEdge(&gitem,&hEdge);
#if 1
if (status == PRO_TK_NO_ERROR) continue; // not surface, (edge)
#else
if (status == PRO_TK_NO_ERROR)
{
status = ProEdgeNeighborsGet(hEdge,&edge1,&edge2,&face1,&face2);
if (face1 != hSurf && face2 != hSurf)
{
continue;
}
}
#endif
status = ProGeomitemToSurface(&gitem,&hSurfTmp);
status = ProSurfaceQuiltGet((ProPart)hPart,hSurfTmp,&hQuilt);
if (status == PRO_TK_NO_ERROR) continue; // not solid surface, (datum surface)
#if 1
if (hSurfTmp != hSurf) break;
iFirstIndex = k;
break;
#else
if (hSurfTmp == hSurf)
{
iFirstIndex = k;
}
#endif
}
if (iFirstIndex == -1) return 0;
return 1;
}
int UserSurfaceNearPntGetFromUV(
ProPart hPart,
ProSurface hSurf,
ProUvParam uv_min,
ProUvParam uv_max,
ProUvParam uv_point,
int iSurfCheckInterval,
ProUvParam uv_point_out) //out
{
ProUvParam uv_point_tmp[4];
int i;
double duv[2];
ProUvStatus result;
duv[0] = (uv_max[0] - uv_min[0]) / iSurfCheckInterval;
duv[1] = (uv_max[1] - uv_min[1]) / iSurfCheckInterval;
uv_point_tmp[0][0] = uv_point[0] + duv[0];
uv_point_tmp[0][1] = uv_point[1] + duv[1];
uv_point_tmp[1][0] = uv_point[0] - duv[0];
uv_point_tmp[1][1] = uv_point[1] - duv[1];
uv_point_tmp[2][0] = uv_point[0] + duv[0];
uv_point_tmp[2][1] = uv_point[1] - duv[1];
uv_point_tmp[3][0] = uv_point[0] - duv[0];
uv_point_tmp[3][1] = uv_point[1] + duv[1];
for (i=0;i<4;i++)
{
if (uv_point_tmp[i][0] < uv_min[0] ||
uv_point_tmp[i][0] > uv_max[0] ||
uv_point_tmp[i][1] < uv_min[1] ||
uv_point_tmp[i][1] > uv_max[1] ) continue;
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point_tmp[i],&result);
if (status != PRO_TK_NO_ERROR) continue;
if (result == PRO_UV_INSIDE)
{
uv_point_out[0] = uv_point_tmp[i][0];
uv_point_out[1] = uv_point_tmp[i][1];
return 1;
}
}
return 0;
}
int testUVCheck(
ProPart hPart,
ProSurface hSurf,
ProUvParam uv_min,
ProUvParam uv_max,
ProRay *ray,
double u_ratio,
double v_ratio)
{
ProVector xyz_point;
ProVector srf_deriv1[2],srf_deriv2[2],direction;
ProUvStatus uv_status;
int k;
ProUvParam uv_point;
uv_point[0] = uv_min[0] + (uv_max[0] - uv_min[0]) * u_ratio;
uv_point[1] = uv_min[1] + (uv_max[1] - uv_min[1]) * v_ratio;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray->start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,*ray))
{
return 1;
}
}
return 0;
}
int UserIsSurfaceAtBack( // can be seen from back
ProPart hPart,
ProSurface hSurf,
ProVector solidDir,
int iEdgeCheckInterval,
int iSurfCheckInterval)
{
int k;
ProSrftype surf_type;
ProUvParam uv_min,uv_max;
ProSurfaceOrient surf_orient;
ProSurfaceshapedata surf_shape;
int surf_id;
ProGeomitemdata *gdata;
ProRay ray;
for (k=0;k<3;k++) ray.dir_vector[k] = -solidDir[k];
ProSurfaceDataGet(hSurf,&gdata);
ProSurfacedataGet(gdata->data.p_surface_data,&surf_type,uv_min,uv_max,&surf_orient,&surf_shape,&surf_id);
ProGeomitemdataFree(&gdata);
#if 1
// uv: 0.5,0.5
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.5);
if (status) return 1;
// uv: 0.50,0.25
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.25);
if (status) return 1;
// uv: 0.50,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.75);
if (status) return 1;
// uv: 0.25,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.5);
if (status) return 1;
// uv: 0.75,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.5);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.75);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.75);
if (status) return 1;
#else
uv_point[0] = (uv_max[0] + uv_min[0]) / 2.0;
uv_point[1] = (uv_max[1] + uv_min[1]) / 2.0;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE) {
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
return 1;
}
}
#endif
return 0;
}
int UserIsSurfaceAtFront(
ProPart hPart,
ProSurface hSurf,
ProVector solidDir,
int iEdgeCheckInterval,
int iSurfCheckInterval,
int bIsSimpleCheck)
{
int k;
ProUvParam uv_point;
ProVector xyz_point;
ProVector srf_deriv1[2],srf_deriv2[2],direction;
ProSrftype surf_type;
ProUvParam uv_min,uv_max;
ProSurfaceOrient surf_orient;
ProSurfaceshapedata surf_shape;
int surf_id;
ProGeomitemdata *gdata;
ProUvStatus uv_status;
ProRay ray;
for (k=0;k<3;k++) ray.dir_vector[k] = solidDir[k];
ProSurfaceDataGet(hSurf,&gdata);
ProSurfacedataGet(gdata->data.p_surface_data,&surf_type,uv_min,uv_max,&surf_orient,&surf_shape,&surf_id);
ProGeomitemdataFree(&gdata);
#if 0
// uv: 0.5,0.5
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.5);
if (status) return 1;
// uv: 0.50,0.25
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.25);
if (status) return 1;
// uv: 0.50,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.75);
if (status) return 1;
// uv: 0.25,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.5);
if (status) return 1;
// uv: 0.75,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.5);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.75);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.75);
if (status) return 1;
#else
uv_point[0] = (uv_max[0] + uv_min[0]) / 2.0;
uv_point[1] = (uv_max[1] + uv_min[1]) / 2.0;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
return 1;
}
}
#endif
if (bIsSimpleCheck) return 0;
#if 1 // check if there is any visible point by uv along edges
ProEdge *hEdges;
int nEdges;
double edge_param;
ProVector deriv1,deriv2;
int i,j;
int iEdgeInt = iEdgeCheckInterval;
ProUvParam uv_point_out;
status = TKSurfaceEdgeCollect(hSurf,&hEdges,&nEdges);
for (i=0;i {
for (j=0;j {
edge_param = (1.0*j) / iEdgeInt;
status = ProEdgeXyzdataEval(hEdges[i],edge_param,xyz_point,deriv1,deriv2,direction);
status = ProSurfaceParamEval(hPart,hSurf,xyz_point,uv_point);
if (UserSurfaceNearPntGetFromUV(hPart,hSurf,uv_min,uv_max,uv_point,iSurfCheckInterval,uv_point_out))
{
status = ProSurfaceXyzdataEval(hSurf,uv_point_out,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
ProArrayFree((ProArray *)&hEdges);
return 1;
}
}
}
}
ProArrayFree((ProArray *)&hEdges);
#else // check if there is any visible point by uv_min --> uv_max
int i,j;
for (i=0;i {
uv_point[0] = uv_min[0] + (uv_max[0] - uv_min[0]) * i / iSurfCheckInterval;
for (j=0;j {
uv_point[1] = uv_min[1] + (uv_max[1] - uv_min[1]) * j / iSurfCheckInterval;
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
return 1;
}
}
}
}
#endif
return 0;
}
int UserIsSurfaceInBox(
ProPart hPart,
ProSurface hSurf,
ProVector solidDir,
ProMatrix m_solid_to_view,
ProOutline pickOutline_view,
int iEdgeCheckInterval,
int iSurfCheckInterval,
ProSurface **hSurfsLeft //(ProArray *) if not NULL, exclude from all surface
)
{
int j,k;
ProEdge *hEdges;
int nEdges;
ProPoint3d tmpPnt_view;
double edge_param;
ProVector xyz_point,deriv1,deriv2,direction;
ProEnttype edge_type;
status = TKSurfaceEdgeCollect(hSurf,&hEdges,&nEdges);
for (j=0;j {
status = ProEdgeTypeGet(hEdges[j],&edge_type);
if (edge_type == PRO_ENT_LINE)
{
status = ProEdgeXyzdataEval(hEdges[j],0.0,xyz_point,deriv1,deriv2,direction);
ProPntTrfEval(xyz_point,m_solid_to_view,tmpPnt_view);
if (UserIsPointOutOfBox(tmpPnt_view,pickOutline_view))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 0;
}
status = ProEdgeXyzdataEval(hEdges[j],1.0,xyz_point,deriv1,deriv2,direction);
ProPntTrfEval(xyz_point,m_solid_to_view,tmpPnt_view);
if (UserIsPointOutOfBox(tmpPnt_view,pickOutline_view))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 0;
}
}
else
{
for (k=0;k {
edge_param = (1.0*k) / iEdgeCheckInterval;
status = ProEdgeXyzdataEval(hEdges[j],edge_param,xyz_point,deriv1,deriv2,direction);
ProPntTrfEval(xyz_point,m_solid_to_view,tmpPnt_view);
if (UserIsPointOutOfBox(tmpPnt_view,pickOutline_view))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 0;
}
}
}
}
#if 1
ProRay ray;
ProUvParam uv_point;
for (k=0;k<3;k++) ray.dir_vector[k] = solidDir[k];
if (UserSurfaceUVPntGet(hPart,hSurf,iSurfCheckInterval,uv_point,xyz_point))
{
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 1;
}
}
#else
if (UserIsSurfaceAtFront(hPart,hSurf,solidDir,iEdgeCheckInterval,iSurfCheckInterval))
{
ProArrayFree((ProArray *)&hEdges);
return 1;
}
#endif
ProArrayFree((ProArray *)&hEdges);
return 0;
}
// 檔案外形計算
// 通過分析檔案的所有曲面中的3角位置(曲面是由很多小3角形構成的),得到外形尺寸
ProError ModelOutlineCompute(ProMdl model)
{
ProError err;
outline_struct get_outline;
get_outline.max[0]=-100000;
get_outline.max[1]=-100000;
get_outline.max[2]=-100000;
get_outline.min[0]=+100000;
get_outline.min[1]=+100000;
get_outline.min[2]=+100000;
ProMatrix rel_matrix={ {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} };
//ProSelection sel_outline_csys;
char outline_csys_def[PRO_NAME_SIZE] = "PRT_M_CENTER";
ProName csys_def_name;
ProStringToWstring(csys_def_name, outline_csys_def);
ProModelitem csys_gi;
err = ProModelitemByNameInit(model, PRO_CSYS, csys_def_name, &csys_gi);
if (err == PRO_TK_NO_ERROR)
{
ProGeomitemdata *p_csys_daten;
err = ProGeomitemdataGet(&csys_gi,&p_csys_daten);
err = ProMatrixInit(p_csys_daten->data.p_csys_data->x_vector,
p_csys_daten->data.p_csys_data->y_vector,
p_csys_daten->data.p_csys_data->z_vector,
p_csys_daten->data.p_csys_data->origin,
rel_matrix);
err = ProGeomitemdataFree(&p_csys_daten);
}
ProSurfaceTessellationData *tes_data = NULL;
err = ProPartTessellate((ProPart)model,0.1,0,PRO_B_FALSE,&tes_data);
int i, j, SurfCount =0;
ProSurface outlineSurfs[6];
err=ProArraySizeGet((ProArray)tes_data, &SurfCount);
if (err != PRO_TK_NO_ERROR || SurfCount < 1)
{
return err;
}
ProSrftype surfType;
ProSurfaceTessellationData *cylSurfData = NULL;
ProSurfaceTessellationData *notCysSurfData = NULL;
err = ProArrayAlloc(0, sizeof(ProSurfaceTessellationData), 1, (ProArray*)&cylSurfData);
err = ProArrayAlloc(0, sizeof(ProSurfaceTessellationData), 1, (ProArray*)¬CysSurfData);
for (i = 0; i < SurfCount; ++i)
{
err = ProSurfaceTypeGet(tes_data[i].surface, &surfType);
if (surfType == PRO_SRF_CYL)
{
err = ProArrayObjectAdd((ProArray*)&cylSurfData, -1, 1, &tes_data[i]);
}
else
{
err = ProArrayObjectAdd((ProArray*)¬CysSurfData, -1, 1, &tes_data[i]);
}
}
int cylSurfCount = 0;
err = ProArraySizeGet((ProArray)cylSurfData, &cylSurfCount);
for (i = 0; i < cylSurfCount; ++i)
{
tes_data[i] = cylSurfData[i];
}
for (i = 0; i < SurfCount - cylSurfCount; ++i)
{
tes_data[i + cylSurfCount] = notCysSurfData[i];
}
//int face_id=0;
for(i=0; i {
for(j=0; j {
// get extreme vertices
double transformed[3];
ProUtilPointTrans(rel_matrix,tes_data[i].vertices[j],transformed);
if(transformed[0]>get_outline.max[0])
{
get_outline.max[0]=transformed[0];
outlineSurfs[0] = tes_data[i].surface;
}
if(transformed[1]>get_outline.max[1])
{
get_outline.max[1]=transformed[1];
outlineSurfs[1] = tes_data[i].surface;
}
if(transformed[2]>get_outline.max[2])
{
get_outline.max[2]=transformed[2];
outlineSurfs[2] = tes_data[i].surface;
}
if(transformed[0] {
get_outline.min[0]=transformed[0];
outlineSurfs[3] = tes_data[i].surface;
}
if(transformed[1] {
get_outline.min[1]=transformed[1];
outlineSurfs[4] = tes_data[i].surface;
}
if(transformed[2] {
get_outline.min[2]=transformed[2];
outlineSurfs[5] = tes_data[i].surface;
}
}
}
// 判斷當前檔案是否為柱體
// 原理是所有的投影點都落在圓內,則認為是柱體
int is_cylinder=0;
double cyl_comp_tolerance=0.2;
int axis_id=-1;
double check_radius = 0.0;
double virtual_center[3];
for ( i = 0; i < 6; ++i)
{
if (outlineSurfs[i] != NULL)
{
err = ProSurfaceTypeGet(outlineSurfs[i], &surfType);
if (surfType == PRO_SRF_CYL)
{
is_cylinder = 1;
ProGeomitemdata *surfData;
err = ProSurfaceDataGet(outlineSurfs[i], &surfData);
if (surfData->data.p_surface_data->srf_shape.cylinder.radius <= check_radius)
{
continue;
}
check_radius = surfData->data.p_surface_data->srf_shape.cylinder.radius;
ProUtilPointTrans(rel_matrix,surfData->data.p_surface_data->srf_shape.cylinder.origin,virtual_center);
ProVector surfNormal;
ProUtilVectorCopy(surfData->data.p_surface_data->srf_shape.cylinder.e3, surfNormal);
if (fabs(surfNormal[0] - rel_matrix[0][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] - rel_matrix[0][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] - rel_matrix[0][2]) < cyl_comp_tolerance)
{
axis_id = 0;
}
else if (fabs(surfNormal[0] + rel_matrix[0][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] + rel_matrix[0][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] + rel_matrix[0][2]) < cyl_comp_tolerance)
{
axis_id = 0;
}
else if (fabs(surfNormal[0] - rel_matrix[1][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] - rel_matrix[1][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] - rel_matrix[1][2]) < cyl_comp_tolerance)
{
axis_id = 1;
}
else if (fabs(surfNormal[0] + rel_matrix[1][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] + rel_matrix[1][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] + rel_matrix[1][2]) < cyl_comp_tolerance)
{
axis_id = 1;
}
else if (fabs(surfNormal[0] - rel_matrix[2][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] - rel_matrix[2][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] - rel_matrix[2][2]) < cyl_comp_tolerance)
{
axis_id = 2;
}
else if (fabs(surfNormal[0] + rel_matrix[2][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] + rel_matrix[2][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] + rel_matrix[2][2]) < cyl_comp_tolerance)
{
axis_id = 2;
}
}
}
}
if(axis_id!=-1)
{
is_cylinder=1;
for(i=0; i {
for(j=0; j {
double transformed[3];
ProUtilPointTrans(rel_matrix,tes_data[i].vertices[j],transformed);
// check offset from axis
double offset_from_axis;
if(axis_id==2)
{
offset_from_axis=sqrt(((transformed[1]-virtual_center[1])*(transformed[1]-virtual_center[1]))+((transformed[0]-virtual_center[0])*(transformed[0]-virtual_center[0])));
if(check_radius {
is_cylinder=0;
break;
}
}
if(axis_id==1)
{
offset_from_axis=sqrt(((transformed[2]-virtual_center[2])*(transformed[2]-virtual_center[2]))+((transformed[0]-virtual_center[0])*(transformed[0]-virtual_center[0])));
if(check_radius {
is_cylinder=0;
break;
}
}
if(axis_id==0)
{
offset_from_axis=sqrt(((transformed[2]-virtual_center[2])*(transformed[2]-virtual_center[2]))+((transformed[1]-virtual_center[1])*(transformed[1]-virtual_center[1])));
if(check_radius {
is_cylinder=0;
break;
}
}
}
}
}
err=ProPartTessellationFree(&tes_data);
//
double l1=fabs(get_outline.max[0]-get_outline.min[0]);
double l2=fabs(get_outline.max[1]-get_outline.min[1]);
double l3=fabs(get_outline.max[2]-get_outline.min[2]);
double diameter = check_radius * 2;
double cyl_length = fabs(get_outline.max[axis_id]-get_outline.min[axis_id]);
return PRO_TK_NO_ERROR;
}
// 改變窗口背景色
// view -> display settings -> system colors -> scheme -> white on black
ProColormapAlternateschemeSet(PRO_COLORMAP_ALT_WHITE_ON_BLACK);
// 輸出圖片
ProRasterFileWrite
// 按坐標系組裝檔案
int TKCompAssembleByCsys(
ProMdl assy,
ProMdl comp,
ProAsmcomppath *assy_cs_comppath,
ProGeomitem *assy_cs,
ProAsmcomppath *comp_cs_comppath,
ProGeomitem *comp_cs,
ProFeature *comp_created)
{
ProModelitem mdlitem;
ProSelection mdl_sel;
ProElement elem_tree, elem_ftype, elem_model,
elem_cons, elem_con, elem_con_type,
elem_com_ref,elem_asm_ref;
ProValue val;
ProValueData val_data;
ProErrorlist errs;
ProSelection sel_comp,sel_asm;
ProAsmcomppath path;
/*-----------------------------------------------------*\
Create the root of the element tree
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_FEATURE_TREE,&elem_tree);
/*-----------------------------------------------------*\
Set the feature type element
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_FEATURE_TYPE,&elem_ftype);
val_data.type = PRO_VALUE_TYPE_INT;
val_data.v.i = PRO_FEAT_COMPONENT;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_ftype,val);
status = ProElemtreeElementAdd(elem_tree,NULL,elem_ftype);
/*-----------------------------------------------------*\
Set the PRO_E_COMPONENT_MODEL
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_COMPONENT_MODEL,&elem_model);
val_data.type = PRO_VALUE_TYPE_POINTER;
val_data.v.p = comp;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_model,val);
status = ProElemtreeElementAdd(elem_tree,NULL,elem_model);
/*-----------------------------------------------------*\
Add PRO_E_COMPONENT_CONSTRAINTS
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_COMPONENT_CONSTRAINTS,&elem_cons);
status = ProElemtreeElementAdd(elem_tree,NULL,elem_cons);
/* Create the PRO_E_COMPONENT_CONSTRAINT */
status = ProElementAlloc(PRO_E_COMPONENT_CONSTRAINT,&elem_con);
status = ProElemtreeElementAdd(elem_cons,NULL,elem_con);
/* Create the PRO_E_COMPONENT_CONSTR_TYPE */
status = ProElementAlloc(PRO_E_COMPONENT_CONSTR_TYPE,&elem_con_type);
val_data.type = PRO_VALUE_TYPE_INT;
val_data.v.i = PRO_ASM_CSYS;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_con_type,val);
status = ProElemtreeElementAdd(elem_con,NULL,elem_con_type);
/* Create the PRO_E_COMPONENT_COMP_CONSTR_REF */
status = ProElementAlloc(PRO_E_COMPONENT_COMP_CONSTR_REF,&elem_com_ref);
status = ProSelectionAlloc(comp_cs_comppath,comp_cs,&sel_comp);
val_data.type = PRO_VALUE_TYPE_SELECTION;
val_data.v.r = sel_comp;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_com_ref,val);
status = ProElemtreeElementAdd(elem_con,NULL,elem_com_ref);
/* Create the PRO_E_COMPONENT_ASSEM_CONSTR_REF */
status = ProElementAlloc(PRO_E_COMPONENT_ASSEM_CONSTR_REF,&elem_asm_ref);
if (assy_cs_comppath == NULL) {
path.owner = (ProSolid)assy;
path.table_num = 0;
path.comp_id_table[0] = -1;
status = ProSelectionAlloc(&path,assy_cs,&sel_asm);
} else {
status = ProSelectionAlloc(assy_cs_comppath,assy_cs,&sel_asm);
}
val_data.type = PRO_VALUE_TYPE_SELECTION;
val_data.v.r = sel_asm;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_asm_ref,val);
status = ProElemtreeElementAdd(elem_con,NULL,elem_asm_ref);
/*-----------------------------------------------------*\
Identify model in which to create the feature
\*-----------------------------------------------------*/
status = ProMdlToModelitem(assy,&mdlitem);
status = ProSelectionAlloc(NULL,&mdlitem,&mdl_sel);
status = ProFeatureCreate(mdl_sel,elem_tree,NULL,0,comp_created,&errs);
if (status != PRO_TK_NO_ERROR) {
return(status);
}
status = ProElementFree(&elem_tree);
return(0);
}
int CreateDrawingWithTemplFormat(ProMdl model)
{
ProDrawing drawing;
ProModel model_data;
ProMdldata mdl_data;
status = ProMdlDataGet (model, &mdl_data);
char strtmp[PRO_PATH_SIZE];
ProWstringToString(strtmp, mdl_data.name);
ProStringToWstring(model_data.name, strtmp);
ProWstringToString(strtmp, mdl_data.type);
ProStringToWstring(model_data.type, strtmp);
char form_name[PRO_NAME_SIZE] = "templ_form_a4.frm";
char tmplt_name[PRO_NAME_SIZE] = "view_tmplt.drw";
ProName w_form_name;
ProMdl format;
ProStringToWstring(w_form_name, form_name);
status = ProMdlRetrieve(w_form_name, PRO_MDL_DWGFORM, &format);
ProName w_predefined_template;
ProDwgcreateErrs drawing_create_errors;
ProDwgcreateOptions ptions = PRODWGCREATE_SHOW_ERROR_DIALOG;
ProStringToWstring(w_predefined_template, tmplt_name);
status = ProDrawingFromTmpltCreate(w_drawing_name, w_predefined_template, &model_data, options, &drawing, &drawing_create_errors);
int new_win_id;
status = ProObjectwindowCreate(w_drawing_name, PRO_DRAWING, &new_win_id);
status = ProWindowCurrentSet(new_win_id);
status = ProWindowActivate(new_win_id);
status = ProMdlDisplay(drawing);
status = ProDrawingFormatAdd(drawing, -1, (ProSolid)model, format, -1);
double scale = 1.0;
status = ProDrawingScaleSet(drawing, (ProSolid)model, -1, scale);
status = ProDwgDraftRegenerate(drawing);
return 0;
}
int UsrTableTextAdd(ProDwgtable *table, int col, int row, char *text)
{
ProWstring *lines;
ProArrayAlloc(1, sizeof(ProWstring), 1, (ProArray*)&lines);
lines[0] = (wchar_t*)calloc(strlen(text) + 1, sizeof(wchar_t));
ProStringToWstring(lines[0], text);
status = ProDwgtableTextEnter(table, col, row, lines);
ProArrayFree((ProArray*)&lines);
return 0;
}
int CreateMakeContentTalbe(ProDrawing drawing)
{
int num_kezi = 2;
int num_attention = 2;
const int colum = 2;
cosnt int row = 5;
ProVector pos={350,180+13*row,0};
double widths[] = {30, 20};
ProHorzJust justs[] = {PROHORZJUST_LEFT, PROHORZJUST_CENTER};
ProDwgtabledata tdata;
status = ProDwgtabledataAlloc(&tdata);
status = ProDwgtabledataOriginSet(tdata, pos);
status = ProDwgtabledataSizetypeSet(tdata, PRODWGTABLESIZE_CHARACTERS);
status = ProDwgtabledataColumnsSet(tdata, colum, widths, justs);
double *heights;
heights = (double*)calloc(row, sizeof(double));
for(int p=0;p {
heights[p] = 1.0;
}
status = ProDwgtabledataRowsSet(tdata, row, heights);
free(heights);
ProDwgtable table;
status = ProDrawingTableCreate(drawing, tdata, PRO_B_FALSE, &table);
for (int m=0; m<=num_attention; m++)
{
status = ProDwgtableCellsMerge(&table, 1, row-m, 2, row-m, PRO_B_FALSE);
}
for (int k=1; k<=num_kezi; k++)
{
UsrTableTextAdd(&table, 1, k, drawingInfo.dwg_kezi[k-1].keziNote.GetBuffer(0));
if (!drawingInfo.dwg_kezi[k-1].keziValue.IsEmpty())
{
UsrTableTextAdd(&table, 2, k, drawingInfo.dwg_kezi[k-1].keziValue.GetBuffer(0));
}
}
CString markDepth;
markDepth.Format("%.3f mm", drawingInfo.depth);
UsrTableTextAdd(&table, 1, row-num_attention-1, "DEEP OF MARK");
UsrTableTextAdd(&table, 2, row-num_attention-1, markDepth.GetBuffer(0));
UsrTableTextAdd(&table, 1, row-num_attention, "Please pay attention to the direction.");
for (int i=0; i {
UsrTableTextAdd(&table, 1, row-i, drawingInfo.dwg_attention[i].GetBuffer(0));
}
status = ProDwgtableDisplay(&table);
return 0;
}
void SetRadiusLocation(ProPoint3d outline[], ProPoint3d midOutline, ProPoint3d location, double radius)
{
if( location[0] < midOutline[0] ) //left
{
location[0] = location[0] + (radius + 10);
}
else //right
{
location[0] = location[0] - (radius + 10);
}
if( location[1] < midOutline[1]) //bottom
{
location[1] = location[1] + (radius + 10);
}
else //top
{
location[1] = location[1] - (radius + 10);
}
}
void SetPositionLocation(ProPoint3d outline[], ProPoint3d midOutline, ProPoint3d location, bool isHorizontal)
{
if( isHorizontal ) // isHorizontal dimension
{
if( location[1] < midOutline[1] ) //bottom
{
location[1] = outline[0][1] - 5 ;
}
else //top
{
location[1] = outline[1][1] + 5;
}
}
else //vertial
{
if( location[0] < midOutline[0] ) //left
{
location[0] = outline[0][0] - 5 ;
}
else //right
{
location[0] = outline[1][0] + 5 ;
}
}
return 0;
}
int CreateDwgDim()
{
ProSelection *attachments = NULL;
ProDimSense *senses;
ProVector location = {centerViewPnt[0],centerViewPnt[1],0};
//alloc
ProArrayAlloc(2, sizeof(ProSelection), 1, (ProArray*)&attachments);
ProArrayAlloc(2, sizeof(ProDimSense), 1, (ProArray*)&senses);
status = ProSelectionAlloc(&max_plate.compPath, (ProModelitem*)&g_edges[k], &edgeSel);
status = ProSelectionCopy(edgeSel, &attachments[0]);
status = ProSelectionCopy(m_moldCsysSel, &attachments[1]);
status = ProSelectionViewSet(coView, &attachments[0]);
status = ProSelectionViewSet(coView, &attachments[1]);
if( !isPosDim ) //create radius dim
{
senses[0].type = PRO_DIM_SNS_TYP_NONE;
senses[0].sense = PRO_DIM_SNS_TYP_NONE;
senses[0].orient_hint = PRO_DIM_ORNT_ELPS_RAD1;
senses[1].type = PRO_DIM_SNS_TYP_NONE;
senses[1].sense = PRO_DIM_SNS_TYP_NONE;
senses[1].orient_hint = PRO_DIM_ORNT_ELPS_RAD1;
//position
SetRadiusLocation(outline, midOutline, location, radius);
status = ProDrawingDimCreate(drawing, attachments, senses, location,PRO_B_FALSE, &dimension);
//free
ProArrayFree((ProArray*)&attachments);
ProArrayFree((ProArray*)&senses);
status = ProDimensionDecimalsSet(&dimension, 2);
status = ProDimensionShow(&dimension, coView, drawing, NULL);
}
else //create position dim
{
ProPoint3d csys_3dpos={0,0,0};
//horizontal
senses[0].type = PRO_DIM_SNS_TYP_PNT;
senses[0].sense = PRO_POINT_TYP_CENTER;
senses[0].orient_hint = PRO_DIM_ORNT_HORIZ;
senses[1].type = PRO_DIM_SNS_TYP_PNT;
senses[1].sense = PRO_POINT_TYP_CENTER;
senses[1].orient_hint = PRO_DIM_ORNT_NONE;
//position
SetPositionLocation(outline, midOutline, location, true);
status = ProDrawingDimCreate(drawing, attachments, senses, location,PRO_B_FALSE, &dimension);
status = ProDimensionDecimalsSet(&dimension, 2);
status = ProDimensionShow(&dimension, coView, drawing, NULL);
//change to ordinate
if ( view_name == VIEW_CO_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_co_hori);
if (status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_co_hori);
}
}
else if ( view_name = VIEW_CA_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_ca_hori);
if(status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_ca_hori);
}
}
//vertial different position and orient_hint
location[0] = centerViewPnt[0] ;
location[1] = centerViewPnt[1] ;
location[2] = 0;
SetPositionLocation(outline, midOutline, location, false);
//sense change
senses[0].orient_hint = PRO_DIM_ORNT_VERT;
status = ProDrawingDimCreate(drawing, attachments, senses, location,PRO_B_FALSE, &dimension);
ProDimensionDecimalsSet(&dimension, 2);
ProDimensionShow(&dimension, coView, drawing, NULL);
//free
ProArrayFree((ProArray*)&attachments);
ProArrayFree((ProArray*)&senses);
//change to ordinate
if ( view_name == VIEW_CO_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_co_vert);
if (status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_co_vert);
}
}
else if ( view_name = VIEW_CA_2D)
{
status = ProDrawingDimToOrdinate(drawing, &dimension, &m_base_ca_vert);
if (status != PRO_TK_NO_ERROR )
{
status = ProDrawingOrdbaselineCreate (drawing, &dimension, csys_3dpos, &m_base_ca_vert);
}
}
}
}
// quilt solidify
ProError TKSolidifyCreate(ProSelection model_sel, ProSelection p_qiult_sel, int feat_type, ProFeature *feature)
{
ProElement pro_e_feature_tree;
ProElement pro_e_feature_type;
ProElement pro_e_feature_form;
ProElement pro_e_patch_quilt;
ProElement pro_e_patch_type;
ProElement pro_e_patch_material_side;
ProElement pro_e_std_feature_name;
ProError status;
ProValue value;
ProValueData value_data;
ProBoolean is_interactive = PRO_B_TRUE;
//Populating root element PRO_E_FEATURE_TREE
status = ProElementAlloc ( PRO_E_FEATURE_TREE, &pro_e_feature_tree );
//Populating element PRO_E_FEATURE_TYPE
status = ProElementAlloc ( PRO_E_FEATURE_TYPE, &pro_e_feature_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = feat_type; //PRO_FEAT_CUT
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_feature_type, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_type );
//Populating element PRO_E_FEATURE_FORM.
status = ProElementAlloc ( PRO_E_FEATURE_FORM, &pro_e_feature_form. );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_USE_SURFS;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_feature_form, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_form. );
//Populating element PRO_E_PATCH_QUILT
status = ProElementAlloc ( PRO_E_PATCH_QUILT, &pro_e_patch_quilt );
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = p_qiult_sel;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_patch_quilt, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_patch_quilt );
//Populating element PRO_E_PATCH_TYPE
status = ProElementAlloc ( PRO_E_PATCH_TYPE, &pro_e_patch_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = feat_type; //PRO_FEAT_CUT
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_patch_type, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_patch_type );
//Populating element PRO_E_PATCH_MATERIAL_SIDE
status = ProElementAlloc ( PRO_E_PATCH_MATERIAL_SIDE, &pro_e_patch_material_side );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_patch_material_side );
//Populating element PRO_E_STD_FEATURE_NAME
status = ProElementAlloc ( PRO_E_STD_FEATURE_NAME, &pro_e_std_feature_name );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_feature_name);
// create feature
ProErrorlist errors;
ProFeatureCreateOptions opts[1];
opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT;
status = ProFeatureCreate (model_sel, pro_e_feature_tree, opts, 1, feature, &errors);
ProElementFree (&pro_e_feature_tree );
return status;
}
// surface color set
int TKSurfaceColorSet(ProMdl p_model, ProSurface p_surf, double rgb[3])
{
int status;
int surf_id;
Pro_surf_props props;
status = ProSurfaceIdGet(p_surf,&surf_id);
status = prodb_get_surface_props((Prohandle)p_model,SEL_3D_SRF,surf_id,0,&props);
if (status == PRODEV_SURF_PROPS_NOT_SET) {
props.ambient = 0.90;
props.diffuse = 0.90;
props.highlite = 0.99;
props.shininess = 0.50;
props.threshold = 90;
props.transparency = 0.0;
}
props.highlight_color[0] = rgb[0]/255.0;
props.highlight_color[1] = rgb[1]/255.0;
props.highlight_color[2] = rgb[2]/255.0;
props.color_rgb[0] = rgb[0]/255.0;
props.color_rgb[1] = rgb[1]/255.0;
props.color_rgb[2] = rgb[2]/255.0;
status = prodb_set_surface_props((Prohandle)p_model,SEL_3D_SRF,surf_id,0,&props);
return 0;
}
// 輸出STP,IGS檔案
ProIntf3DFileWrite
ProOutputFileWrite
// 輸出PV檔案
ProProductviewExport
// 在關係式中添加自定義函數
ProRelationFunctionRegister
// 擺正視圖
int AjustView()
{
ProMatrix matrix;
status = ProViewMatrixGet(NULL,NULL,matrix);
ProUtilMatrixNormalize(matrix);
// 將視圖矩陣的每一行(前3行)的絕對值最大值設為1/-1(與哪個接近設為哪個)
ResetView(matrix);
status = ProViewMatrixSet(NULL,NULL,matrix);
status = ProViewRefit(NULL, NULL);
status = ProWindowRepaint(-1);
}
// 框選曲面
// 框選其他的物件同此原理,只需將其轉換為點是否在框內
// PART -> SURFACE -> EDGE -> POINT
int UserSurfaceUVPntGet(
ProPart hPart,
ProSurface hSurf,
int iSurfCheckInterval,
ProUvParam uv_point,
ProVector xyz_point)
{
//ProUvParam uv_point;
//ProVector xyz_point;
ProVector srf_deriv1[2],srf_deriv2[2],direction;
ProSrftype surf_type;
ProUvParam uv_min,uv_max;
ProSurfaceOrient surf_orient;
ProSurfaceshapedata surf_shape;
int surf_id;
ProGeomitemdata *gdata;
ProUvStatus uv_status;
ProSurfaceDataGet(hSurf,&gdata);
ProSurfacedataGet(gdata->data.p_surface_data,&surf_type,uv_min,uv_max,&surf_orient,&surf_shape,&surf_id);
ProGeomitemdataFree(&gdata);
uv_point[0] = (uv_max[0] + uv_min[0]) / 2.0;
uv_point[1] = (uv_max[1] + uv_min[1]) / 2.0;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
return 1;
}
int i,j;
for (i=0;i {
uv_point[0] = uv_min[0] + (uv_max[0] - uv_min[0]) * i / iSurfCheckInterval;
for (j=0;j {
uv_point[1] = uv_min[1] + (uv_max[1] - uv_min[1]) * j / iSurfCheckInterval;
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
return 1;
}
}
}
return 0;
}
int UserIsPointOutOfBox(
ProVector pnt,
ProOutline box_outline)
{
if (pnt[0] < box_outline[0][0] ||
pnt[0] > box_outline[1][0] ||
pnt[1] < box_outline[0][1] ||
pnt[1] > box_outline[1][1] )
{
return 1;
}
return 0;
}
int UserIsSurfaceAtFrontFromRay(
ProPart hPart,
ProSurface hSurf,
ProRay ray)
{
ProSelection *hSels;
int nSel;
ProBoolean bIsInactive;
ProQuilt hQuilt;
int k,iFirstIndex;
ProGeomitem gitem;
ProSurface hSurfTmp;
ProEdge hEdge;
status = ProSolidRayIntersectionCompute((ProSolid)hPart,-1,&ray,&hSels,&nSel);
if (nSel <= 0) return 0;
iFirstIndex = -1;
for (k=0;k {
status = ProSelectionVerify(hSels[k]);
if (status != PRO_TK_NO_ERROR) continue;
status = ProSelectionModelitemGet(hSels[k],(ProModelitem *)&gitem);
if (status != PRO_TK_NO_ERROR) continue;
status = ProGeomitemIsInactive(&gitem,&bIsInactive);
if (bIsInactive == PRO_B_TRUE) continue;
status = ProGeomitemToEdge(&gitem,&hEdge);
#if 1
if (status == PRO_TK_NO_ERROR) continue; // not surface, (edge)
#else
if (status == PRO_TK_NO_ERROR)
{
status = ProEdgeNeighborsGet(hEdge,&edge1,&edge2,&face1,&face2);
if (face1 != hSurf && face2 != hSurf)
{
continue;
}
}
#endif
status = ProGeomitemToSurface(&gitem,&hSurfTmp);
status = ProSurfaceQuiltGet((ProPart)hPart,hSurfTmp,&hQuilt);
if (status == PRO_TK_NO_ERROR) continue; // not solid surface, (datum surface)
#if 1
if (hSurfTmp != hSurf) break;
iFirstIndex = k;
break;
#else
if (hSurfTmp == hSurf)
{
iFirstIndex = k;
}
#endif
}
if (iFirstIndex == -1) return 0;
return 1;
}
int UserSurfaceNearPntGetFromUV(
ProPart hPart,
ProSurface hSurf,
ProUvParam uv_min,
ProUvParam uv_max,
ProUvParam uv_point,
int iSurfCheckInterval,
ProUvParam uv_point_out) //out
{
ProUvParam uv_point_tmp[4];
int i;
double duv[2];
ProUvStatus result;
duv[0] = (uv_max[0] - uv_min[0]) / iSurfCheckInterval;
duv[1] = (uv_max[1] - uv_min[1]) / iSurfCheckInterval;
uv_point_tmp[0][0] = uv_point[0] + duv[0];
uv_point_tmp[0][1] = uv_point[1] + duv[1];
uv_point_tmp[1][0] = uv_point[0] - duv[0];
uv_point_tmp[1][1] = uv_point[1] - duv[1];
uv_point_tmp[2][0] = uv_point[0] + duv[0];
uv_point_tmp[2][1] = uv_point[1] - duv[1];
uv_point_tmp[3][0] = uv_point[0] - duv[0];
uv_point_tmp[3][1] = uv_point[1] + duv[1];
for (i=0;i<4;i++)
{
if (uv_point_tmp[i][0] < uv_min[0] ||
uv_point_tmp[i][0] > uv_max[0] ||
uv_point_tmp[i][1] < uv_min[1] ||
uv_point_tmp[i][1] > uv_max[1] ) continue;
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point_tmp[i],&result);
if (status != PRO_TK_NO_ERROR) continue;
if (result == PRO_UV_INSIDE)
{
uv_point_out[0] = uv_point_tmp[i][0];
uv_point_out[1] = uv_point_tmp[i][1];
return 1;
}
}
return 0;
}
int testUVCheck(
ProPart hPart,
ProSurface hSurf,
ProUvParam uv_min,
ProUvParam uv_max,
ProRay *ray,
double u_ratio,
double v_ratio)
{
ProVector xyz_point;
ProVector srf_deriv1[2],srf_deriv2[2],direction;
ProUvStatus uv_status;
int k;
ProUvParam uv_point;
uv_point[0] = uv_min[0] + (uv_max[0] - uv_min[0]) * u_ratio;
uv_point[1] = uv_min[1] + (uv_max[1] - uv_min[1]) * v_ratio;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray->start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,*ray))
{
return 1;
}
}
return 0;
}
int UserIsSurfaceAtBack( // can be seen from back
ProPart hPart,
ProSurface hSurf,
ProVector solidDir,
int iEdgeCheckInterval,
int iSurfCheckInterval)
{
int k;
ProSrftype surf_type;
ProUvParam uv_min,uv_max;
ProSurfaceOrient surf_orient;
ProSurfaceshapedata surf_shape;
int surf_id;
ProGeomitemdata *gdata;
ProRay ray;
for (k=0;k<3;k++) ray.dir_vector[k] = -solidDir[k];
ProSurfaceDataGet(hSurf,&gdata);
ProSurfacedataGet(gdata->data.p_surface_data,&surf_type,uv_min,uv_max,&surf_orient,&surf_shape,&surf_id);
ProGeomitemdataFree(&gdata);
#if 1
// uv: 0.5,0.5
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.5);
if (status) return 1;
// uv: 0.50,0.25
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.25);
if (status) return 1;
// uv: 0.50,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.75);
if (status) return 1;
// uv: 0.25,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.5);
if (status) return 1;
// uv: 0.75,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.5);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.75);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.75);
if (status) return 1;
#else
uv_point[0] = (uv_max[0] + uv_min[0]) / 2.0;
uv_point[1] = (uv_max[1] + uv_min[1]) / 2.0;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE) {
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
return 1;
}
}
#endif
return 0;
}
int UserIsSurfaceAtFront(
ProPart hPart,
ProSurface hSurf,
ProVector solidDir,
int iEdgeCheckInterval,
int iSurfCheckInterval,
int bIsSimpleCheck)
{
int k;
ProUvParam uv_point;
ProVector xyz_point;
ProVector srf_deriv1[2],srf_deriv2[2],direction;
ProSrftype surf_type;
ProUvParam uv_min,uv_max;
ProSurfaceOrient surf_orient;
ProSurfaceshapedata surf_shape;
int surf_id;
ProGeomitemdata *gdata;
ProUvStatus uv_status;
ProRay ray;
for (k=0;k<3;k++) ray.dir_vector[k] = solidDir[k];
ProSurfaceDataGet(hSurf,&gdata);
ProSurfacedataGet(gdata->data.p_surface_data,&surf_type,uv_min,uv_max,&surf_orient,&surf_shape,&surf_id);
ProGeomitemdataFree(&gdata);
#if 0
// uv: 0.5,0.5
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.5);
if (status) return 1;
// uv: 0.50,0.25
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.25);
if (status) return 1;
// uv: 0.50,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.5,0.75);
if (status) return 1;
// uv: 0.25,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.5);
if (status) return 1;
// uv: 0.75,0.50
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.5);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.25,0.75);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.25);
if (status) return 1;
// uv: 0.25,0.75
status = testUVCheck(hPart,hSurf,uv_min,uv_max,&ray,0.75,0.75);
if (status) return 1;
#else
uv_point[0] = (uv_max[0] + uv_min[0]) / 2.0;
uv_point[1] = (uv_max[1] + uv_min[1]) / 2.0;
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
return 1;
}
}
#endif
if (bIsSimpleCheck) return 0;
#if 1 // check if there is any visible point by uv along edges
ProEdge *hEdges;
int nEdges;
double edge_param;
ProVector deriv1,deriv2;
int i,j;
int iEdgeInt = iEdgeCheckInterval;
ProUvParam uv_point_out;
status = TKSurfaceEdgeCollect(hSurf,&hEdges,&nEdges);
for (i=0;i {
for (j=0;j {
edge_param = (1.0*j) / iEdgeInt;
status = ProEdgeXyzdataEval(hEdges[i],edge_param,xyz_point,deriv1,deriv2,direction);
status = ProSurfaceParamEval(hPart,hSurf,xyz_point,uv_point);
if (UserSurfaceNearPntGetFromUV(hPart,hSurf,uv_min,uv_max,uv_point,iSurfCheckInterval,uv_point_out))
{
status = ProSurfaceXyzdataEval(hSurf,uv_point_out,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
ProArrayFree((ProArray *)&hEdges);
return 1;
}
}
}
}
ProArrayFree((ProArray *)&hEdges);
#else // check if there is any visible point by uv_min --> uv_max
int i,j;
for (i=0;i {
uv_point[0] = uv_min[0] + (uv_max[0] - uv_min[0]) * i / iSurfCheckInterval;
for (j=0;j {
uv_point[1] = uv_min[1] + (uv_max[1] - uv_min[1]) * j / iSurfCheckInterval;
status = ProSurfaceUvpntVerify(hPart,hSurf,uv_point,&uv_status);
if (uv_status == PRO_UV_INSIDE)
{
status = ProSurfaceXyzdataEval(hSurf,uv_point,xyz_point,srf_deriv1,srf_deriv2,direction);
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
return 1;
}
}
}
}
#endif
return 0;
}
int UserIsSurfaceInBox(
ProPart hPart,
ProSurface hSurf,
ProVector solidDir,
ProMatrix m_solid_to_view,
ProOutline pickOutline_view,
int iEdgeCheckInterval,
int iSurfCheckInterval,
ProSurface **hSurfsLeft //(ProArray *) if not NULL, exclude from all surface
)
{
int j,k;
ProEdge *hEdges;
int nEdges;
ProPoint3d tmpPnt_view;
double edge_param;
ProVector xyz_point,deriv1,deriv2,direction;
ProEnttype edge_type;
status = TKSurfaceEdgeCollect(hSurf,&hEdges,&nEdges);
for (j=0;j {
status = ProEdgeTypeGet(hEdges[j],&edge_type);
if (edge_type == PRO_ENT_LINE)
{
status = ProEdgeXyzdataEval(hEdges[j],0.0,xyz_point,deriv1,deriv2,direction);
ProPntTrfEval(xyz_point,m_solid_to_view,tmpPnt_view);
if (UserIsPointOutOfBox(tmpPnt_view,pickOutline_view))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 0;
}
status = ProEdgeXyzdataEval(hEdges[j],1.0,xyz_point,deriv1,deriv2,direction);
ProPntTrfEval(xyz_point,m_solid_to_view,tmpPnt_view);
if (UserIsPointOutOfBox(tmpPnt_view,pickOutline_view))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 0;
}
}
else
{
for (k=0;k {
edge_param = (1.0*k) / iEdgeCheckInterval;
status = ProEdgeXyzdataEval(hEdges[j],edge_param,xyz_point,deriv1,deriv2,direction);
ProPntTrfEval(xyz_point,m_solid_to_view,tmpPnt_view);
if (UserIsPointOutOfBox(tmpPnt_view,pickOutline_view))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 0;
}
}
}
}
#if 1
ProRay ray;
ProUvParam uv_point;
for (k=0;k<3;k++) ray.dir_vector[k] = solidDir[k];
if (UserSurfaceUVPntGet(hPart,hSurf,iSurfCheckInterval,uv_point,xyz_point))
{
for (k=0;k<3;k++) ray.start_point[k] = xyz_point[k];
if (UserIsSurfaceAtFrontFromRay(hPart,hSurf,ray))
{
if (hSurfsLeft != NULL) TKSurfaceArrayRemove(hSurfsLeft,hSurf);
ProArrayFree((ProArray *)&hEdges);
return 1;
}
}
#else
if (UserIsSurfaceAtFront(hPart,hSurf,solidDir,iEdgeCheckInterval,iSurfCheckInterval))
{
ProArrayFree((ProArray *)&hEdges);
return 1;
}
#endif
ProArrayFree((ProArray *)&hEdges);
return 0;
}
// 檔案外形計算
// 通過分析檔案的所有曲面中的3角位置(曲面是由很多小3角形構成的),得到外形尺寸
ProError ModelOutlineCompute(ProMdl model)
{
ProError err;
outline_struct get_outline;
get_outline.max[0]=-100000;
get_outline.max[1]=-100000;
get_outline.max[2]=-100000;
get_outline.min[0]=+100000;
get_outline.min[1]=+100000;
get_outline.min[2]=+100000;
ProMatrix rel_matrix={ {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} };
//ProSelection sel_outline_csys;
char outline_csys_def[PRO_NAME_SIZE] = "PRT_M_CENTER";
ProName csys_def_name;
ProStringToWstring(csys_def_name, outline_csys_def);
ProModelitem csys_gi;
err = ProModelitemByNameInit(model, PRO_CSYS, csys_def_name, &csys_gi);
if (err == PRO_TK_NO_ERROR)
{
ProGeomitemdata *p_csys_daten;
err = ProGeomitemdataGet(&csys_gi,&p_csys_daten);
err = ProMatrixInit(p_csys_daten->data.p_csys_data->x_vector,
p_csys_daten->data.p_csys_data->y_vector,
p_csys_daten->data.p_csys_data->z_vector,
p_csys_daten->data.p_csys_data->origin,
rel_matrix);
err = ProGeomitemdataFree(&p_csys_daten);
}
ProSurfaceTessellationData *tes_data = NULL;
err = ProPartTessellate((ProPart)model,0.1,0,PRO_B_FALSE,&tes_data);
int i, j, SurfCount =0;
ProSurface outlineSurfs[6];
err=ProArraySizeGet((ProArray)tes_data, &SurfCount);
if (err != PRO_TK_NO_ERROR || SurfCount < 1)
{
return err;
}
ProSrftype surfType;
ProSurfaceTessellationData *cylSurfData = NULL;
ProSurfaceTessellationData *notCysSurfData = NULL;
err = ProArrayAlloc(0, sizeof(ProSurfaceTessellationData), 1, (ProArray*)&cylSurfData);
err = ProArrayAlloc(0, sizeof(ProSurfaceTessellationData), 1, (ProArray*)¬CysSurfData);
for (i = 0; i < SurfCount; ++i)
{
err = ProSurfaceTypeGet(tes_data[i].surface, &surfType);
if (surfType == PRO_SRF_CYL)
{
err = ProArrayObjectAdd((ProArray*)&cylSurfData, -1, 1, &tes_data[i]);
}
else
{
err = ProArrayObjectAdd((ProArray*)¬CysSurfData, -1, 1, &tes_data[i]);
}
}
int cylSurfCount = 0;
err = ProArraySizeGet((ProArray)cylSurfData, &cylSurfCount);
for (i = 0; i < cylSurfCount; ++i)
{
tes_data[i] = cylSurfData[i];
}
for (i = 0; i < SurfCount - cylSurfCount; ++i)
{
tes_data[i + cylSurfCount] = notCysSurfData[i];
}
//int face_id=0;
for(i=0; i {
for(j=0; j {
// get extreme vertices
double transformed[3];
ProUtilPointTrans(rel_matrix,tes_data[i].vertices[j],transformed);
if(transformed[0]>get_outline.max[0])
{
get_outline.max[0]=transformed[0];
outlineSurfs[0] = tes_data[i].surface;
}
if(transformed[1]>get_outline.max[1])
{
get_outline.max[1]=transformed[1];
outlineSurfs[1] = tes_data[i].surface;
}
if(transformed[2]>get_outline.max[2])
{
get_outline.max[2]=transformed[2];
outlineSurfs[2] = tes_data[i].surface;
}
if(transformed[0] {
get_outline.min[0]=transformed[0];
outlineSurfs[3] = tes_data[i].surface;
}
if(transformed[1] {
get_outline.min[1]=transformed[1];
outlineSurfs[4] = tes_data[i].surface;
}
if(transformed[2] {
get_outline.min[2]=transformed[2];
outlineSurfs[5] = tes_data[i].surface;
}
}
}
// 判斷當前檔案是否為柱體
// 原理是所有的投影點都落在圓內,則認為是柱體
int is_cylinder=0;
double cyl_comp_tolerance=0.2;
int axis_id=-1;
double check_radius = 0.0;
double virtual_center[3];
for ( i = 0; i < 6; ++i)
{
if (outlineSurfs[i] != NULL)
{
err = ProSurfaceTypeGet(outlineSurfs[i], &surfType);
if (surfType == PRO_SRF_CYL)
{
is_cylinder = 1;
ProGeomitemdata *surfData;
err = ProSurfaceDataGet(outlineSurfs[i], &surfData);
if (surfData->data.p_surface_data->srf_shape.cylinder.radius <= check_radius)
{
continue;
}
check_radius = surfData->data.p_surface_data->srf_shape.cylinder.radius;
ProUtilPointTrans(rel_matrix,surfData->data.p_surface_data->srf_shape.cylinder.origin,virtual_center);
ProVector surfNormal;
ProUtilVectorCopy(surfData->data.p_surface_data->srf_shape.cylinder.e3, surfNormal);
if (fabs(surfNormal[0] - rel_matrix[0][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] - rel_matrix[0][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] - rel_matrix[0][2]) < cyl_comp_tolerance)
{
axis_id = 0;
}
else if (fabs(surfNormal[0] + rel_matrix[0][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] + rel_matrix[0][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] + rel_matrix[0][2]) < cyl_comp_tolerance)
{
axis_id = 0;
}
else if (fabs(surfNormal[0] - rel_matrix[1][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] - rel_matrix[1][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] - rel_matrix[1][2]) < cyl_comp_tolerance)
{
axis_id = 1;
}
else if (fabs(surfNormal[0] + rel_matrix[1][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] + rel_matrix[1][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] + rel_matrix[1][2]) < cyl_comp_tolerance)
{
axis_id = 1;
}
else if (fabs(surfNormal[0] - rel_matrix[2][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] - rel_matrix[2][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] - rel_matrix[2][2]) < cyl_comp_tolerance)
{
axis_id = 2;
}
else if (fabs(surfNormal[0] + rel_matrix[2][0]) < cyl_comp_tolerance
&& fabs(surfNormal[1] + rel_matrix[2][1]) < cyl_comp_tolerance
&& fabs(surfNormal[2] + rel_matrix[2][2]) < cyl_comp_tolerance)
{
axis_id = 2;
}
}
}
}
if(axis_id!=-1)
{
is_cylinder=1;
for(i=0; i {
for(j=0; j {
double transformed[3];
ProUtilPointTrans(rel_matrix,tes_data[i].vertices[j],transformed);
// check offset from axis
double offset_from_axis;
if(axis_id==2)
{
offset_from_axis=sqrt(((transformed[1]-virtual_center[1])*(transformed[1]-virtual_center[1]))+((transformed[0]-virtual_center[0])*(transformed[0]-virtual_center[0])));
if(check_radius {
is_cylinder=0;
break;
}
}
if(axis_id==1)
{
offset_from_axis=sqrt(((transformed[2]-virtual_center[2])*(transformed[2]-virtual_center[2]))+((transformed[0]-virtual_center[0])*(transformed[0]-virtual_center[0])));
if(check_radius {
is_cylinder=0;
break;
}
}
if(axis_id==0)
{
offset_from_axis=sqrt(((transformed[2]-virtual_center[2])*(transformed[2]-virtual_center[2]))+((transformed[1]-virtual_center[1])*(transformed[1]-virtual_center[1])));
if(check_radius {
is_cylinder=0;
break;
}
}
}
}
}
err=ProPartTessellationFree(&tes_data);
//
double l1=fabs(get_outline.max[0]-get_outline.min[0]);
double l2=fabs(get_outline.max[1]-get_outline.min[1]);
double l3=fabs(get_outline.max[2]-get_outline.min[2]);
double diameter = check_radius * 2;
double cyl_length = fabs(get_outline.max[axis_id]-get_outline.min[axis_id]);
return PRO_TK_NO_ERROR;
}
// 改變窗口背景色
// view -> display settings -> system colors -> scheme -> white on black
ProColormapAlternateschemeSet(PRO_COLORMAP_ALT_WHITE_ON_BLACK);
// 輸出圖片
ProRasterFileWrite
// 按坐標系組裝檔案
int TKCompAssembleByCsys(
ProMdl assy,
ProMdl comp,
ProAsmcomppath *assy_cs_comppath,
ProGeomitem *assy_cs,
ProAsmcomppath *comp_cs_comppath,
ProGeomitem *comp_cs,
ProFeature *comp_created)
{
ProModelitem mdlitem;
ProSelection mdl_sel;
ProElement elem_tree, elem_ftype, elem_model,
elem_cons, elem_con, elem_con_type,
elem_com_ref,elem_asm_ref;
ProValue val;
ProValueData val_data;
ProErrorlist errs;
ProSelection sel_comp,sel_asm;
ProAsmcomppath path;
/*-----------------------------------------------------*\
Create the root of the element tree
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_FEATURE_TREE,&elem_tree);
/*-----------------------------------------------------*\
Set the feature type element
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_FEATURE_TYPE,&elem_ftype);
val_data.type = PRO_VALUE_TYPE_INT;
val_data.v.i = PRO_FEAT_COMPONENT;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_ftype,val);
status = ProElemtreeElementAdd(elem_tree,NULL,elem_ftype);
/*-----------------------------------------------------*\
Set the PRO_E_COMPONENT_MODEL
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_COMPONENT_MODEL,&elem_model);
val_data.type = PRO_VALUE_TYPE_POINTER;
val_data.v.p = comp;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_model,val);
status = ProElemtreeElementAdd(elem_tree,NULL,elem_model);
/*-----------------------------------------------------*\
Add PRO_E_COMPONENT_CONSTRAINTS
\*-----------------------------------------------------*/
status = ProElementAlloc(PRO_E_COMPONENT_CONSTRAINTS,&elem_cons);
status = ProElemtreeElementAdd(elem_tree,NULL,elem_cons);
/* Create the PRO_E_COMPONENT_CONSTRAINT */
status = ProElementAlloc(PRO_E_COMPONENT_CONSTRAINT,&elem_con);
status = ProElemtreeElementAdd(elem_cons,NULL,elem_con);
/* Create the PRO_E_COMPONENT_CONSTR_TYPE */
status = ProElementAlloc(PRO_E_COMPONENT_CONSTR_TYPE,&elem_con_type);
val_data.type = PRO_VALUE_TYPE_INT;
val_data.v.i = PRO_ASM_CSYS;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_con_type,val);
status = ProElemtreeElementAdd(elem_con,NULL,elem_con_type);
/* Create the PRO_E_COMPONENT_COMP_CONSTR_REF */
status = ProElementAlloc(PRO_E_COMPONENT_COMP_CONSTR_REF,&elem_com_ref);
status = ProSelectionAlloc(comp_cs_comppath,comp_cs,&sel_comp);
val_data.type = PRO_VALUE_TYPE_SELECTION;
val_data.v.r = sel_comp;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_com_ref,val);
status = ProElemtreeElementAdd(elem_con,NULL,elem_com_ref);
/* Create the PRO_E_COMPONENT_ASSEM_CONSTR_REF */
status = ProElementAlloc(PRO_E_COMPONENT_ASSEM_CONSTR_REF,&elem_asm_ref);
if (assy_cs_comppath == NULL) {
path.owner = (ProSolid)assy;
path.table_num = 0;
path.comp_id_table[0] = -1;
status = ProSelectionAlloc(&path,assy_cs,&sel_asm);
} else {
status = ProSelectionAlloc(assy_cs_comppath,assy_cs,&sel_asm);
}
val_data.type = PRO_VALUE_TYPE_SELECTION;
val_data.v.r = sel_asm;
status = ProValueAlloc(&val);
status = ProValueDataSet(val,&val_data);
status = ProElementValueSet(elem_asm_ref,val);
status = ProElemtreeElementAdd(elem_con,NULL,elem_asm_ref);
/*-----------------------------------------------------*\
Identify model in which to create the feature
\*-----------------------------------------------------*/
status = ProMdlToModelitem(assy,&mdlitem);
status = ProSelectionAlloc(NULL,&mdlitem,&mdl_sel);
status = ProFeatureCreate(mdl_sel,elem_tree,NULL,0,comp_created,&errs);
if (status != PRO_TK_NO_ERROR) {
return(status);
}
status = ProElementFree(&elem_tree);
return(0);
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25306814/viewspace-707512/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/25306814/viewspace-707512/