/*
Copyright (c) 2019 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/
/*---------------------- Pro/Toolkit Includes ------------------------*/
#include <ProToolkit.h>
#include <ProSelection.h>
#include <ProGeomitem.h>
#include <ProUtil.h>
#include <ProMessage.h>
#include <ProEdge.h>
/*---------------------- Application Includes ------------------------*/
#include <TestError.h>
/*---------------------- Function Prototypes -------------------------*/
ProError UserArcDiaDisp();
/*============================================================================*\
Function: UserArcDiaDisp()
Purpose: Display Diameter of Selected Arc
\*============================================================================*/
ProError UserArcDiaDisp()
{
int sel_count;
double diameter;
ProError status;
ProModelitem p_mdl_item;
ProFileName msgfile;
ProGeomitemdata *geom_data=NULL;
ProArcdata *p_arc=NULL;
ProEdge edge;
ProEnttype edge_type;
ProSelection *psels=NULL;
/*----------------------------------------------------------------------------*\
Prompt user for selection of arc
\*----------------------------------------------------------------------------*/
ProStringToWstring(msgfile,"msg_uggeom.txt");
status = ProMessageDisplay(msgfile,"USER Select Arc to Evaluate:");
ERROR_CHECK("UserArcDiaDisp","ProMessageDisplay(Select Arc)",status);
if((ProSelect("edge",1,NULL,NULL,NULL,NULL,&psels, &sel_count) !=
PRO_TK_NO_ERROR) || (sel_count < 1))
return((int)PRO_TK_GENERAL_ERROR);
status = ProSelectionModelitemGet(psels[0],&p_mdl_item);
ERROR_CHECK( "UserArcDiaDisp", "ProSelectionModelitemGet", status );
status = ProGeomitemToEdge(&p_mdl_item,&edge);
ERROR_CHECK("UserArcDiaDisp","ProGeomitemToEdge",status);
status = ProEdgeTypeGet(edge,&edge_type);
ERROR_CHECK("UserArcDiaDisp","ProEdgeTypeGet",status);
if((edge_type != PRO_ENT_ARC) && (edge_type != PRO_ENT_CIRCLE))
{
status = ProMessageDisplay(msgfile,"USER Invalid Arc Selection");
ERROR_CHECK("UserArcDiaDisp","ProMessageDisplay(Invalid Arc)",status);
return((int)PRO_TK_GENERAL_ERROR);
}
status = ProGeomitemdataGet(&p_mdl_item,&geom_data);
ERROR_CHECK("UserArcDiaDisp","ProGeomitemdataGet",status);
diameter = geom_data->data.p_curve_data->arc.radius*2.0;
status = ProMessageDisplay(msgfile,"USER Arc Diameter = %0f",&diameter);
ERROR_CHECK("UserArcDiaDisp","ProMessageDisplay(Arc Diameter)",status);
ProGeomitemdataFree(&geom_data);
return((int)status);
}