Basically, my problem right now is that the prodb_surface_tessellation function call is crashing. I know this is quite a bit of code, but if anyone could point out what is going wrong, it would be greatly appreciated. I do get the assembly features but am ignoring them here. I know I'm not checking return error codes from most of these functions, but I've stepped through the code line-by-line and examined what is returned. So that isn't a problem.
void MainFunction()
{
// Show message
ProError error;
error = ProMessageDisplay(UserMsg, "USER %0s", "User click 2");
ProMessageClear();
// Get the current mode
ProMode mode;
error = ProModeCurrentGet(&mode);
if(mode != PRO_MODE_ASSEMBLY)
{
//Write a message using a "Popup dialog"
ProUIMessageButton *buttons;
ProUIMessageButton user_choice;
ProArrayAlloc(1, sizeof (ProUIMessageButton), 1, (ProArray*)&buttons);
buttons [0] = PRO_UI_MESSAGE_OK;
ProUIMessageDialogDisplay( PROUIMESSAGE_INFO, L"Solid",
L"There is no assembly here!",
buttons, PRO_UI_MESSAGE_OK, &user_choice);
ProArrayFree((ProArray*)&buttons);
return;
}
// Get the current assembly
ProMdl asmm;
ProMdlCurrentGet(&asmm);
// Get data of the current assembly and print them
char assemblyname[PRO_NAME_SIZE];
char type[PRO_TYPE_SIZE];
ProMdldata mdldata;
ProMdlDataGet(asmm, &mdldata);
ProWstringToString(assemblyname, mdldata.name);
ProWstringToString(type, mdldata.type);
// Open the file
char filename[PRO_NAME_SIZE];
FILE *fp;
strcpy(filename, FILENAMEASSMBLY);
fp = fopen(filename, "w");
// Print name and type of the assembly
fprintf(fp, "The name of the assembly is: %s(%s)\n\n", assemblyname, type);
// Initialise global user-defined data
UserGitemdata appdata;
appdata.fp = fp;
appdata.mdlcount = 0;
appdata.p_compmdls = NULL;
appdata.srfcount = 0;
appdata.p_surfaces = NULL;
appdata.level = 0;
//
ProGeomitem *psrf;
error = ProArrayAlloc(0, sizeof(ProGeomitem), 1, (ProArray*)&psrf);
appdata.p_surfaces = psrf;
//
ProMdl *pcompmdl;
error = ProArrayAlloc(0, sizeof(ProMdl), 1, (ProArray*)&pcompmdl);
appdata.p_compmdls = pcompmdl;
// List the assembly members
error = ProSolidFeatVisit((ProSolid)asmm, VisitAsmCompAction,
FilterAsmCompAction, &appdata);
}
/*===========================================================================*\
FUNCTION: FilterAsmCompAction()
PURPOSE: A filter used by ProSolidFeatVisit() of func2() to visit features
that are assembly components
\*===========================================================================*/
ProError FilterAsmCompAction(ProFeature *feature, ProAppData app_data)
{
// Get type of the feature(only select assembly component)
ProError status;
ProFeattype ftype;
status = ProFeatureTypeGet(feature, &ftype);
if (ftype != PRO_FEAT_COMPONENT)
return(PRO_TK_CONTINUE);
// Get visibility of the feature
ProBoolean visible;
status = ProFeatureVisibilityGet(feature, &visible);
if(status == PRO_TK_NO_ERROR)
if(visible == PRO_B_FALSE)
return(PRO_TK_CONTINUE);
// If the feature is not active, skip it
ProFeatStatus fstatus;
status = ProFeatureStatusGet(feature, &fstatus);
if(fstatus != PRO_FEAT_ACTIVE)
return(PRO_TK_CONTINUE);
return(PRO_TK_NO_ERROR);
}
/*================================================================*\
FUNCTION: VisitAsmCompAction()
PURPOSE: Write the information to the file.
\*================================================================*/
ProError VisitAsmCompAction(ProFeature *feature, ProError status,
ProAppData appdata)
{
// Initialise use-defined data
ProError error;
FILE *fp;
ProMdl **mdlarrary;
UserGitemdata *appd;
appd = (UserGitemdata *)appdata;
fp = appd->fp;
mdlarrary = &(appd->p_compmdls);
// Get the model and solid of the assembly component
error = ProAsmcompMdlGet(feature, &(appd->mdl));
//
ProMdl mdl;
error = ProAsmcompMdlGet(feature, &mdl);
ProMdlType type;
ProName name;
ProSolid solid;
error = ProMdlTypeGet((ProMdl)mdl, &type);
error = ProMdlNameGet((ProMdl)mdl, name);
error = ProSolidInit(name, (ProType)type, &solid);
// Get names and typies of the assembly component
ProMdldata mdldata;
char mname[PRO_NAME_SIZE];
char mtype[PRO_TYPE_SIZE];
error = ProMdlDataGet(mdl, &mdldata);
ProWstringToString(mname, mdldata.name);
ProWstringToString(mtype, mdldata.type);
//
if(strncmp(mtype, "ASM", 3) == 0)
{
//ProSolidFeatVisit((ProSolid)mdl, user_action, UserAsmCompFilter, &subappd);
}
else if(strncmp(mtype, "PRT", 3) == 0)
{
// Add part component to arrary
fprintf(fp, "This is a part component here!\n");
error = ProArrayObjectAdd((ProArray*)mdlarrary, -1, 1, &mdl);
(appd->mdlcount)++;
// Visit all the surfaces of the model
fprintf(fp, "This is a component of assembly!\n");
error = ProSolidSurfaceVisit((ProSolid)mdl,
(ProSurfaceVisitAction)SrfVisitAction,
(ProSurfaceFilterAction)SrfFilterAction,
appdata);
fprintf(fp, "\n\n");
}
// Return error
if (feature != NULL)
return(PRO_TK_NO_ERROR);
// Return correctly
return(PRO_TK_CONTINUE);
}
/*===========================================================================*\
FUNCTION:
PURPOSE:
\*===========================================================================*/
ProError SrfFilterAction(ProSurface p_surface, ProAppData app_data)
{
return(PRO_TK_NO_ERROR);
}
/*===========================================================================*\
FUNCTION:
PURPOSE:
\*===========================================================================*/
ProError SrfVisitAction(ProSurface p_surface, ProError status,
ProAppData app_data)
{
// Initialise use-defined data
ProError error;
UserGitemdata *appd;
appd = (UserGitemdata*)app_data;
//
FILE *fp;
fp = appd->fp;
//
ProGeomitem **srfarray;
srfarray = &(appd->p_surfaces);
// Convert the surface to geometry
ProGeomitem geomitem;
error = ProSurfaceToGeomitem((ProSolid)(appd->mdl), p_surface, &geomitem);
ProFeature feature;
error = ProGeomitemFeatureGet(&geomitem, &feature);
ProSolid owner;
error = ProFeatureSolidGet(&feature, &owner);
// Add surface to array
fprintf(fp, "This is a surface here!\n");
error = ProArrayObjectAdd((ProArray*)srfarray, -1, 1, &geomitem);
(appd->srfcount)++;
// Get the tessellation of the surface
int n_verts, n_facets, (*findices)[3];
double (*fverts)[3], (*fnorms)[3];
int srf_id = 0;
error = ProSurfaceIdGet(p_surface, &srf_id);
ProName mdlName;
ProMdlNameGet(owner,mdlName);
int rev = prodb_surface_tessellation((Prohandle)(owner), srf_id, 0.5, 0.5,
NULL, &n_verts, &fverts, &fnorms, NULL,
&n_facets, &findices);
// Return correctly
fprintf(fp, "\n\n");
return(PRO_TK_NO_ERROR);
}