Pro/TOOLKIT sample program (7) getting geometry elements: edge

Posted by Seaholme on Sun, 03 May 2020 11:11:06 +0200

In Pro/TOOLKIT, the type ProEdge represents an edge. ProEdge and ProGeomitem can switch to each other:

  • ProEdge -> ProGeomitem: ProEdgeToGeomitem
  • ProGeomitem -> ProEdge: ProGeomitemToEdge

Proedgetypget is used to get the type of edge. The types of edge are as follows

  • Pro? Ent? Line: straight edge.
  • Pro? Ent? Arc: arc edge.
  • Pro? Ent? Ellipse: elliptical edge.
  • Pro? Ent? Spline: spline edge.
  • Pro ent B spline: B-spline edge.

The function progeomitemdateget is used to get the data of the edge. Note that the function ProGeomitemdataFree is called to release the data after it is used up.
ProCurvedata under ProGeomitemdata is used to store the edge data. For different types of edges, the data is represented by different variables under ProCurvedata type.

typedef struct geom_item_data_struct
{
    ProType     obj_type;
    union
    {
        ProCurvedata     *p_curve_data;
        ProSurfacedata   *p_surface_data;
        ProCsysdata      *p_csys_data;
    }data;
} ProGeomitemdata;

typedef union ptc_curve
{
    ProLinedata           line;      // Straight edge data
    ProArrowdata          arrow;
    ProArcdata            arc;       // Arc edge data
    ProSplinedata         spline;    // Spline edge data
    ProBsplinedata        b_spline;  // B-spline curve edge data
    ProCircledata         circle;
    ProEllipsedata        ellipse;   // Ellipse edge data
    ProPointdata          point;
    ProPolygondata        polygon;
    ProTextdata           text;
    ProCompositeCurvedata  comp_curve;
    ProSurfcurvedata    surf_curve;
} ProCurvedata;

Example code:

// Get data for edge
int TestGetEdgeData(uiCmdCmdId  command,
                    uiCmdValue *p_value,
                    void       *p_push_command_data)
{
    ProError err;

    // Select edge
    ProSelection *sels;
    int nSel = 0;
    err = ProSelect("edge", 1, NULL, NULL, NULL, NULL, &sels, &nSel);
    if (PRO_TK_NO_ERROR != err || 1 != nSel)
    {
        return -1;
    }

    // Get selected edge
    ProGeomitem geomEdge;
    err = ProSelectionModelitemGet(sels[0], &geomEdge);
    ProEdge edge;
    err = ProGeomitemToEdge(&geomEdge, &edge);
    ProEnttype edgeType;
    err = ProEdgeTypeGet(edge, &edgeType);

    // Get data for edge
    ProGeomitemdata* geomdata;
    err = ProGeomitemdataGet(&geomEdge, &geomdata);

    // Output data based on the type of edge
    CStringW cstrInfo;
    switch (edgeType)
    {
        // Straight edge
    case PRO_ENT_LINE:
        {
            CStringW cstrEdgeType = L"Type of edge: Straight edge\n";
            CStringW cstrEndInfo;
            cstrEndInfo.Format(L"Endpoint 1: (%.2f, %.2f, %.2f) \n Endpoint 2: (%.2f, %.2f, %.2f)",
                geomdata->data.p_curve_data->line.end1[0],
                geomdata->data.p_curve_data->line.end1[1],
                geomdata->data.p_curve_data->line.end1[2],
                geomdata->data.p_curve_data->line.end2[0],
                geomdata->data.p_curve_data->line.end2[1],
                geomdata->data.p_curve_data->line.end2[2]);

            cstrInfo = cstrEdgeType + cstrEndInfo;
        }
        break;

        // Arc edge
    case PRO_ENT_ARC:
        {
            CStringW cstrEdgeType = L"Type of edge: Arc edge\n";
            CStringW cstrVector1;
            cstrVector1.Format(L"vector1 = (%.2f, %.2f, %.2f)\n", 
                geomdata->data.p_curve_data->arc.vector1[0],
                geomdata->data.p_curve_data->arc.vector1[1],
                geomdata->data.p_curve_data->arc.vector1[2]);
            CStringW cstrVector2;
            cstrVector2.Format(L"vector2 = (%.2f, %.2f, %.2f)\n", 
                geomdata->data.p_curve_data->arc.vector2[0],
                geomdata->data.p_curve_data->arc.vector2[1],
                geomdata->data.p_curve_data->arc.vector2[2]);
            CStringW cstrArcCenter;
            cstrArcCenter.Format(L"Center of a circle: (%.2f, %.2f, %.2f)\n",
                geomdata->data.p_curve_data->arc.origin[0],
                geomdata->data.p_curve_data->arc.origin[1],
                geomdata->data.p_curve_data->arc.origin[2]);
            CStringW cstrRadius;
            cstrRadius.Format(L"radius: %.2f\n", geomdata->data.p_curve_data->arc.radius);
            CStringW cstrStartEndAngle;
            cstrStartEndAngle.Format(L"Starting angle: %.2f \n Termination angle: %.2f",
                geomdata->data.p_curve_data->arc.start_angle * 180.0 / 3.1415926,
                geomdata->data.p_curve_data->arc.end_angle * 180.0 / 3.1415926);

            cstrInfo = cstrEdgeType + cstrVector1 + cstrVector2 + cstrArcCenter + cstrRadius + cstrStartEndAngle;
        }
        break;

        // Elliptical edge
    case PRO_ENT_ELLIPSE:
        cstrInfo = L"Type of edge: Elliptical edge\n";
        break;

        // Spline edge
    case PRO_ENT_SPLINE:
        cstrInfo = L"Type of edge: Spline edge\n";
        break;

        // BSpline edge
    case PRO_ENT_B_SPLINE:
        cstrInfo = L"Type of edge: B Spline edge\n";
        break;

    default:
        return -1;
        break;
    }
    MessageBoxW(NULL, cstrInfo, L"icaxdev: Sample004", MB_OK);

    // Release data
    err = ProGeomitemdataFree(&geomdata);

    return 0;
}