⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 samp2.c

📁 Pro.TOOLKIT.Wildfire插件设计.配套光盘-141M.zip
💻 C
📖 第 1 页 / 共 2 页
字号:
  
  status = ProElementValueGet (sketch_element, &value);
  
  status = ProValueDataGet (value, &value_data);
  section = (ProSection)value_data.v.p;

/*---------------------------------------------------------------*\
    Create the 3-D Point section and get the section handle 
\*---------------------------------------------------------------*/

  status = UserSectionPointBuild ( ( ProSection )(value_data.v.p), sketch_refs); 
  
/*---------------------------------------------------------------*\
   Redefining the feature to make it complete.
\*---------------------------------------------------------------*/
  opts[0] = PRO_FEAT_CR_DEFINE_MISS_ELEMS;
  status = ProSelectionAsmcomppathGet (model_sel, &comp_path);
  
  status = ProFeatureRedefine (&comp_path, &feature, created_elemtree,
                               opts, 1, &errors);
  
/*---------------------------------------------------------------*\
    Free up the allocated memory.
\*---------------------------------------------------------------*/
  status = ProElementFree (&created_elemtree ); 
  
  status = ProElementFree (&pro_e_feature_tree ); 
  
  return (status);
}

/* =============================================================== *\
   Function: UserSectionPointBuild(ProSection section, ProSelection *sketch_refs)
   Purpose:  Creates a 3D Section consisting of Points
\* =============================================================== */
ProError UserSectionPointBuild(ProSection section, ProSelection *sketch_refs)
{
  int 		status, i, num_errors, err_counter, proj_ids[2];
  int 		point_id; 
  char 		msg[PRO_PATH_SIZE];
  
  Matrix_data 	matrix_data;

  ProSelection 	*proj_ents;
  ProWSecerror 	sec_errors;
  Pro2dPointdef point;
  Pro2dLinedef  *btm_linedef, *left_linedef;
  
  double offsets[2];
  double p3D[3];
  double out3D[4];
  
/* =============================================================== *\
   	Obtain projection entity handles as ProSelection structures
\* =============================================================== */

  status = UserSelectProjectionEntities(&proj_ents);
  
/* =============================================================== *\
    Project reference edges onto section
\* =============================================================== */

  for (i = 0; i < 2; i++)
    {
      status = ProSectionEntityFromProjection(section, proj_ents[i], &proj_ids[i]);
            if (status != PRO_TK_NO_ERROR)
	return(status);
    }
  
/* =============================================================== *\
    Create section csys from edges, and obtion transformation 
	matrix between sketch plane csys and section csys
\* =============================================================== */
  
  status = ProSectionEntityGet(section, proj_ids[0], (Pro2dEntdef **)&btm_linedef);
    
  for (i = 0; i < 2; i++)
    {
      matrix_data.x_axis[0][i] = btm_linedef->end1[i];
      matrix_data.x_axis[1][i] = btm_linedef->end2[i];
      matrix_data.x_axis[i][2] = 0.0; 
    }
  
  status = ProSectionEntityGet(section, proj_ids[1], (Pro2dEntdef **)&left_linedef);
    
  for (i = 0; i < 2; i++)
    {
      matrix_data.y_axis[0][i] = left_linedef->end1[i]; 
      matrix_data.y_axis[1][i] = left_linedef->end2[i];
      matrix_data.y_axis[i][2] = 0.0; 
    }
  
  status = ProSectionLocationGet(section, matrix_data.sk_mtrx);
    
  status = ProSelectionCopy(sketch_refs[0], &(matrix_data.sk_plane));
    
  status = UserCreateTrfMatrix(&matrix_data);
  
/* =============================================================== *\     
     Obtain offset values from projection entities
\* =============================================================== */
  
//status = UserSelectOffsetDistances(offsets);

  status = ProMessageDisplay(UserMsg, "USER Enter offset distance from first projection reference");
  status = ProMessageDoubleRead(NULL, &offsets[0]);
  
  status = ProMessageDisplay(UserMsg, "USER Enter offset distance from second projection reference");
  status = ProMessageDoubleRead(NULL, &offsets[1]);

/* =============================================================== *\
     Add the required point(s)
     Currently only one point is added 
     This may be extended to add any number of points
\* =============================================================== */
  
    point.type    = PRO_2D_POINT;
    point.pnt[0] = offsets[0]; 
    point.pnt[1] = offsets[1]; 
  
    p3D[0] = point.pnt[0];
    p3D[1] = point.pnt[1];
    p3D[2] = 0.0;

	ProPntTrfEval(p3D, matrix_data.sec_trf, out3D);
	ProPntTrfEval(p3D, matrix_data.sec_trf, out3D);

    point.pnt[0] = out3D[0];
    point.pnt[1] = out3D[1];
  
  status = ProSectionEntityAdd (section, (Pro2dEntdef*)&point, &point_id);
  
/* =============================================================== *\
   	Dimension, Solve and regenerate the section
\* =============================================================== */

  status = ProSecerrorAlloc(&sec_errors);
    
  status = ProSectionAutodim(section, &sec_errors);
  
  status = ProSectionRegenerate(section, &sec_errors);
 
  status = ProSelectionFree(&(matrix_data.sk_plane));
    
  free(temp1);
  free(temp2);

  temp1 = NULL;
  temp2 = NULL; 
  
  return(status);
}

ProError UserSelectOffsetDistances(double *offset_vals)
{

  ProError status;

  status = ProMessageDisplay(UserMsg, "USER Enter offset distance from first projection reference");
  status = ProMessageDoubleRead(NULL, &offset_vals[0]);
  
  status = ProMessageDisplay(UserMsg, "USER Enter offset distance from second projection reference");
  status = ProMessageDoubleRead(NULL, &offset_vals[1]);
  
  return(status);

}

ProError UserCreateTrfMatrix(Matrix_data *m_data)
{

  ProPoint3d origin; 
  double sel_pnt[3], proj_sel_pnt[3], sel_vect[3]; 
  double x_plane[3];
  ProVector x, y, sk_plane_norm;
  ProVector d1[2], d2[2], norm;
  int status;
  ProMatrix inv_sk_mtrx;
  ProModelitem sk_modelitem;
  ProSurface sk_surf;
  ProUvParam sk_param;

    Pro2dPointdef point;
      double p3D[3];
    double out3D[4];
  /* =============================================================== *\
   	Project point selected on sketch plane onto section
\* =============================================================== */

  ProUtilMatrixInvert(m_data->sk_mtrx, inv_sk_mtrx);

  status = ProSelectionUvParamGet(m_data->sk_plane, sk_param);
  status = ProSelectionModelitemGet(m_data->sk_plane, &sk_modelitem);
  status = ProGeomitemToSurface((ProGeomitem *)&sk_modelitem, &sk_surf);
  status = ProSurfaceXyzdataEval(sk_surf, sk_param, sel_pnt, d1, d2, norm);
  
  ProUtilPointTrans(inv_sk_mtrx, sel_pnt, proj_sel_pnt);
  proj_sel_pnt[2] = 0.0;

  /* =============================================================== *\
  	Create x and y vectors of transformation matrix such that 
	selected point on sketch plane is in first quadrant
  \* =============================================================== */

  ProUtilLineLineX(m_data->x_axis, m_data->y_axis, origin);

  ProUtilVectorDiff(proj_sel_pnt, origin, sel_vect);
  sel_vect[2] = 0.0;
  ProUtilVectorNormalize(sel_vect, sel_vect);

  ProUtilVectorDiff(m_data->x_axis[0], m_data->x_axis[1], x);
  ProUtilVectorNormalize(x, x);

  ProUtilVectorDiff(m_data->y_axis[0], m_data->y_axis[1], y);
  ProUtilVectorNormalize(y, y);	
	
/* =========  Selected point should be in first quadrant  ======= */

  if ((ProUtilVectorDot(x,sel_vect)) < 0.0)
    ProUtilVectorScale(-1.0, x, x);

  if ((ProUtilVectorDot(y,sel_vect)) < 0.0)
    ProUtilVectorScale(-1.0, y, y);

/* ========= Make sure surface normal is properly oriented   ======= */
/* ========= with respect to x and y   ============================= */


  ProUtilVectorCross(x, y, sk_plane_norm);
  ProUtilVectorTrans(m_data->sk_mtrx, sk_plane_norm, sk_plane_norm);
  ProUtilMatrixCopy(NULL, m_data->sec_trf);

  if ((ProUtilVectorDot(sk_plane_norm, m_data->sk_mtrx[2])) < 0.0)
    {
      ProUtilVectorCopy(y, m_data->sec_trf[0]);
      ProUtilVectorCopy(x, m_data->sec_trf[1]);
      ProUtilVectorCopy(NULL, m_data->sec_trf[2]);
      ProUtilVectorCopy(origin, m_data->sec_trf[3]);
    }

  else
    {
      ProUtilVectorCopy(x, m_data->sec_trf[0]);
      ProUtilVectorCopy(y, m_data->sec_trf[1]);
      ProUtilVectorCopy(NULL, m_data->sec_trf[2]);
      ProUtilVectorCopy(origin, m_data->sec_trf[3]);
    }
		
  m_data->sec_trf[2][2] = m_data->sec_trf[3][3] = 1.0;

/* =============================================================== *\
		Calculate rotation angle  	
\* =============================================================== */
  x_plane[0] = 1.0;
  x_plane[1] = x_plane[2] = 0.0;
  ProUtilVectorCross(x_plane, m_data->sk_mtrx[0], norm);
  ProUtilVectorCross(m_data->sec_trf[0], m_data->sec_trf[1], sk_plane_norm);
  m_data->angle = fabs(acos(ProUtilVectorDot(x_plane, m_data->sec_trf[0])));
  if (ProUtilVectorDot(norm, sk_plane_norm) < 0.0)
    m_data->angle *= -1.0;

/////////////////////////////////////////////////////////////////
  point.type    = PRO_2D_POINT;
  point.pnt[0] = 100; 
  point.pnt[1] = 200; 
  
/* ============================================================================== *\
move the follow codes from subfunction
\* ============================================================================== */

    p3D[0] = point.pnt[0];
    p3D[1] = point.pnt[1];
    p3D[2] = 0.0;

//    ProUtilPointTrans2(m,p3D,out3D);
	ProPntTrfEval(p3D, m_data->sec_trf, out3D);

    point.pnt[0] = out3D[0];
    point.pnt[1] = out3D[1];
////////////////////////////////////////////////////////////////////////////////

  return(status);

}

void ProUtil2DPointTrans(
    double m[4][4],
    double p2D[2],
    double out2D[2])
{
    double p3D[3];
    double out3D[4];

    p3D[0] = p2D[0];
    p3D[1] = p2D[1];
    p3D[2] = 0.0;

	ProPntTrfEval(p3D, m, out3D);

    out2D[0] = out3D[0];
    out2D[1] = out3D[1];
}

/*====================================================================*\
    FUNCTION :	ProUtilPointTrans()
    PURPOSE  :	Transform a 3d point by a matrix
\*====================================================================*/
void ProUtilPointTrans(
    double m[4][4],
    double p[3],
    double output[3])
{
    double buff[4];
    ProError status;

    if(m == NULL)
    {
	ProUtilVectorCopy(p, output);
	return;
    }

    status = ProPntTrfEval(p, m, buff);
    ProUtilVectorCopy(buff, output);

}


/* =============================================================== *\
   Function: UserSelectProjectionEntities
   Purpose: Select projection entity references from existing geometry
\* =============================================================== */

ProError UserSelectProjectionEntities(ProSelection **proj_refs)
{

  ProSelection *sel;
  int num_sel;
  ProError status;

  if (temp2== NULL)
    temp2= (ProSelection *)calloc(2, sizeof(ProSelection));
  /* =============================================================== *\
     Prompt user to select reference geometry
  \* =============================================================== */
  
  status = ProMessageDisplay(UserMsg, "USER Select first projection reference (bottom edge of sketch plane)");
  status = ProSelect("edge", 1, NULL, NULL, NULL, NULL, &sel, &num_sel);
    if (status != PRO_TK_NO_ERROR || num_sel < 1)
    return(status);
  status = ProSelectionCopy(sel[0], &temp2[0]);
  	
  status = ProMessageDisplay(UserMsg, "USER Select second projection reference (left edge of sketch plane)");
  status = ProSelect("edge", 1, NULL, NULL, NULL, NULL, &sel, &num_sel);
  
  if (status != PRO_TK_NO_ERROR || num_sel < 1)
    return(status);
  status = ProSelectionCopy(sel[0], &temp2[1]);
  

  *proj_refs = temp2;

  return(status);

}

/*====================================================================*\
    FUNCTION :	ProUtilLineLineX
    PURPOSE  :	Get the intersection point of two lines
\*====================================================================*/
double *ProUtilLineLineX(
     double l1[2][3],
     double l2[2][3],
     double int_pnt[3])
{
     double v1[3], v2[3], v3[3], v4[4];
     double n[3],n1[3], n2[3];

     /* if lines parallel return NULL */
     if ( ProUtilLinesParallel(l1,l2) )
	 return(NULL);

     ProUtilVectorDiff(l1[0],l1[1],v1);
     ProUtilVectorDiff(l2[0],l2[1],v2);

     if ((fabs(l1[0][0]-l2[0][0])<= EPSM6) &&
         (fabs(l1[0][1]-l2[0][1])<= EPSM6) &&
         (fabs(l1[0][2]-l2[0][2])<= EPSM6))
     {
	 memcpy(int_pnt,l1[0],3*sizeof(double));
	 return(int_pnt);
     }

     if ((fabs(l1[1][0]-l2[1][0])<= EPSM6) &&
         (fabs(l1[1][1]-l2[1][1])<= EPSM6) &&
         (fabs(l1[1][2]-l2[1][2])<= EPSM6))
     {
	 memcpy(int_pnt,l1[1],3*sizeof(double));
	 return(int_pnt);
     }

     ProUtilVectorDiff(l1[0],l2[0],v3);
     ProUtilVectorDiff(l1[1],l2[1],v4);
     ProUtilVectorCross(v1,v2,n1);
     ProUtilVectorCross(v3,v4,n2);
     ProUtilVectorNormalize(n1,n1);
     ProUtilVectorNormalize(n2,n2);

     /* if lines not on same plane return NULL */
     if ( (1.0 - fabs(ProUtilVectorDot(n1,n2))) >= EPSM6 )
	  return(NULL);

     ProUtilVectorNormalize(v1,v1);
     ProUtilVectorNormalize(v2,v2);
     ProUtilVectorCross(n1,v1,n);
     ProUtilPlaneLineX(l1[0],n,l2[0],v2,int_pnt);

     return(int_pnt);

}

/*====================================================================*\
    FUNCTION :	ProUtilLinesParallel
    PURPOSE  :	Check if two lines are parallel (returns 1) to each other
\*====================================================================*/
int ProUtilLinesParallel(double line1[2][3],double line2[2][3])
{
     double vec1[3], vec2[3];

     ProUtilVectorDiff(line1[0],line1[1],vec1);
     ProUtilVectorDiff(line2[0],line2[1],vec2);

     ProUtilVectorNormalize(vec1,vec1);
     ProUtilVectorNormalize(vec2,vec2);

     if ( (1.0-fabs(ProUtilVectorDot(vec1,vec2))) <= EPSM6 )
	  return(1);

     return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -