/*
	Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/


/*-------------------------- Pro/Toolkit includes ---------------------------*/
#include <ProToolkit.h>
#include <ProMdl.h>
#include <ProUtil.h>
#include <ProMessage.h>
#include <ProSolid.h>
#include <ProPattern.h>
#include <ProFeature.h>
#include <ProArray.h>
#include <ProDtlitem.h>
#include <ProDtlentity.h>

/*-------------------------- Application includes ---------------------------*/
#include <TestError.h>
#include <TestFeat.h>
#include <UtilFiles.h>
#include <UtilString.h>
#include <PTApplsUnicodeUtils.h>


static wchar_t PT_MSGFIL[] =
{'f','e','a','t','_','m','s','g','.','t','x','t','\0'};


static ProError status = PRO_TK_NO_ERROR;
static ProError visit_GeomFeat(ProGeomitem *item, ProError stat, ProAppData app_data);

/*================================================================*\
FUNCTION  : ProTestAxisPattern()
PURPOSE   : Creates Axis pattern
\*================================================================*/
      
  
ProError ProTestAxisPattern()
{
	int n_sels, numof_elems;
    ProSelection* sels = NULL;
    ProFeature feature;
    ProElement elem_axis,elem_ref,elem_flip;
	ProElement elem_inc;
    ProElement elem_fdir,elem_inst;
    ProModelitem mdl_item;
	ProElement elem_tree,elem_type,elem_rgn;
	ProGroupStatus grp;
    ProSelection selections;   
    ProReference ref;
    double at_space, space_range[2];
    int num_range[2];

    ProMessageDisplay (PT_MSGFIL, (char*)"Select feature for pattern creation");
    status = ProSelect ((char*)"feature", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &feature);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelectionModelitemGet", status);         
    if ((status != PRO_TK_NO_ERROR) || (feature.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;
            	
	status  = ProFeatureGroupStatusGet(&feature,&grp);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelect", status);
   /*====================================================================*\
      Pattern Root
   \*====================================================================*/  
	status = ProElementAlloc(PRO_E_PATTERN_ROOT,&elem_tree);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);

	status = ProElementAlloc(PRO_E_GENPAT_TYPE,&elem_type);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelect", status);
	status = ProElementIntegerSet(elem_type,PRO_GENPAT_AXIS_DRIVEN);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelect", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_type);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelect", status);

    /*====================================================================*\
       AXIS PATTERN
    \*====================================================================*/

	status = ProElementAlloc(PRO_E_GENPAT_AXIS,&elem_axis);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);
    status = ProElemtreeElementAdd(elem_tree,NULL,elem_axis);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElemtreeElementAdd", status);
    
	status = ProElementAlloc(PRO_E_GENPAT_AXIS_REF,&elem_ref);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);

    ProMessageDisplay (PT_MSGFIL, (char*)"Select axis");  
    status = ProSelect ((char*)"axis", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelect", status); 

    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelectionModelitemGet", status);   
    if ((status != PRO_TK_NO_ERROR) && (mdl_item.type == PRO_AXIS))
      return status;
	
    status = ProSelectionAlloc(NULL,&mdl_item,&selections);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelectionAlloc", status);
	status = ProSelectionToReference(selections,&ref);
    ERROR_CHECK ("ProTestAxisPattern()", "ProSelectionToReference", status);
	status = ProElementReferenceSet(elem_ref,ref);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementReferenceSet", status);
    status = ProElemtreeElementAdd(elem_axis,NULL,elem_ref);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_GENPAT_AXIS1_INC,&elem_inc);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);
  
    space_range[0] = 0;
    space_range[1] = 360;

    ProMessageDisplay (PT_MSGFIL, (char*)"Enter the distance between pattern elements");
    ProMessageDoubleRead(space_range, &at_space);
      
    status = ProElementDoubleSet(elem_inc, at_space);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementDoubleSet", status);
    status = ProElemtreeElementAdd(elem_axis,NULL,elem_inc);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_AXIS_PAT_DIR1_FLIP,&elem_flip);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);
    status = ProElementIntegerSet(elem_flip,1);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementIntegerSet", status);
    status = ProElemtreeElementAdd(elem_axis,NULL,elem_flip);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_GENPAT_DIM_FIRST_DIR,&elem_fdir);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);
    status = ProElemtreeElementAdd(elem_axis,NULL,elem_fdir);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_GENPAT_DIM_FIRST_DIR_NUM_INST,&elem_inst);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);

    num_range[0] = 2;
    num_range[1] = 100;
    ProMessageDisplay (PT_MSGFIL, (char*)"Enter number of elements in pattern");
    ProMessageIntegerRead(num_range, &numof_elems);
        
    status = ProElementIntegerSet(elem_inst,numof_elems);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementIntegerSet", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;   
      
    status = ProElemtreeElementAdd(elem_axis,NULL,elem_inst);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElemtreeElementAdd", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;   
      
    status = ProElementAlloc(PRO_E_GENPAT_REGEN_METHOD,&elem_rgn);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementAlloc", status);
    if ((status != PRO_TK_NO_ERROR))
      return status; 
      
    status = ProElementIntegerSet(elem_rgn,PRO_PAT_GENERAL);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElementIntegerSet", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;   
      
    status = ProElemtreeElementAdd(elem_tree,NULL,elem_rgn);
    ERROR_CHECK ("ProTestAxisPattern()", "ProElemtreeElementAdd", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;   
      	
    status = ProPatternCreate(&feature,PRO_FEAT_PATTERN,elem_tree);
    ERROR_CHECK ("ProTestAxisPattern()", "ProPatternCreate", status);

    if ((status != PRO_TK_NO_ERROR))
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
    
    else
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation successful");
       
  return (status);
}


/*================================================================*\
FUNCTION  : ProTestCurvePattern()
PURPOSE   : Creates curve pattern
\*================================================================*/

ProError ProTestCurvePattern()
{
	ProElement elem_curve;
	ProElement elem_space;
	ProElement elem_sketch,elem_std,elem_method;
    ProFeature feature;
    ProModelitem mdl_item;
	ProElement elem_tree,elem_type;
	ProGroupStatus grp;
    ProSelection selections;   
    ProReference ref;
    double at_space, space_range[2];
    int n_sels;
    ProSelection* sels = NULL;
    
    ProMessageDisplay (PT_MSGFIL, (char*)"Select feature for pattern creation");
    status = ProSelect ((char*)"membfeat", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestCurvePattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;

    status = ProSelectionModelitemGet (sels[0], &feature);
    ERROR_CHECK ("ProTestCurvePattern()", "ProSelectionModelitemGet", status);         
    if ((status != PRO_TK_NO_ERROR) || (feature.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;

	status  = ProFeatureGroupStatusGet(&feature,&grp);
    ERROR_CHECK ("ProTestCurvePattern()", "ProFeatureGroupStatusGet", status);


   /*====================================================================*\
      Pattern Root
   \*====================================================================*/  
	status = ProElementAlloc(PRO_E_PATTERN_ROOT,&elem_tree);
    ERROR_CHECK ("ProTestCurvePattern()", "ProSelectionModelitemGet", status);

	status = ProElementAlloc(PRO_E_GENPAT_TYPE,&elem_type);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_type,PRO_GENPAT_CRV_DRIVEN);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_type);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElemtreeElementAdd", status);

     /*====================================================================*\
        CURVE PATTERN
    \*====================================================================*/
	status = ProElementAlloc(PRO_E_GENPAT_CURVE,&elem_curve);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementAlloc", status);
    status = ProElemtreeElementAdd(elem_tree,NULL,elem_curve);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_CRV_SPACING,&elem_space);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementAlloc", status);

    space_range[0] = 0;
    space_range[1] = 360;

    ProMessageDisplay (PT_MSGFIL, (char*)"Enter the distance between pattern elements");
    ProMessageDoubleRead(space_range, &at_space);
      
    status = ProElementDoubleSet(elem_space, at_space);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_curve,NULL,elem_space);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_STD_SECTION,&elem_std);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_std);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_STD_SEC_METHOD,&elem_method);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_method,0);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_std,NULL,elem_method);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_SEC_USE_SKETCH,&elem_sketch);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementAlloc", status);
    
    ProMessageDisplay (PT_MSGFIL, (char*)"Select curve");
    status = ProSelect ((char*)"curve", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestCurvePattern()", "ProSelect", status); 
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestCurvePattern()", "ProSelectionModelitemGet", status);   
    if ((status != PRO_TK_NO_ERROR) &&(mdl_item.type != PRO_CURVE))
      return status;
	
    status = ProSelectionAlloc(NULL,(ProModelitem*)&mdl_item,&selections);
    ERROR_CHECK ("ProTestCurvePattern()", "ProSelectionAlloc", status);
    status = ProSelectionToReference(selections,&ref);
    ERROR_CHECK ("ProTestCurvePattern()", "ProSelectionToReference", status);
	status = ProElementReferenceSet(elem_sketch,ref);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElementReferenceSet", status);
	status = ProElemtreeElementAdd(elem_std,NULL,elem_sketch);
    ERROR_CHECK ("ProTestCurvePattern()", "ProElemtreeElementAdd", status);

    status = ProPatternCreate(&feature,PRO_FEAT_PATTERN,elem_tree);
    ERROR_CHECK ("ProTestCurvePattern()", "ProPatternCreate", status);

    if ((status != PRO_TK_NO_ERROR))
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
    
    else
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation successful");

  return (status); 
} 


/*================================================================*\
FUNCTION  : ProTestGeneralPattern()
PURPOSE   : Creates general pattern
\*================================================================*/

ProError ProTestGeneralPattern()
{
    ProElement elem_dir,elem_cmpd;
    ProElement elem_dim,elem_var,elem_value,elem_dim1;
    ProElement elem_inst;
    ProFeature feature;
    ProModelitem mdl_item;
	ProElement elem_tree,elem_type,elem_rgn;
    ProSelection selections;   
    ProReference ref;
    double at_space, space_range[2];
    int num_range[2];
    int n_sels, numof_elems;
    ProSelection* sels = NULL;	
	
    ProMessageDisplay (PT_MSGFIL, (char*)"Select feature for pattern creation");
    status = ProSelect ((char*)"membfeat", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;

    status = ProSelectionModelitemGet (sels[0], &feature);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProSelectionModelitemGet", status);         
    if ((status != PRO_TK_NO_ERROR) || (feature.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;

    status = ProElementAlloc(PRO_E_PATTERN_ROOT,&elem_tree);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);

	status = ProElementAlloc(PRO_E_GENPAT_TYPE,&elem_type);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_type,PRO_GENPAT_DIM_DRIVEN);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_type);

    status = ProElementAlloc(PRO_E_GENPAT_REGEN_METHOD,&elem_rgn);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_rgn,PRO_PAT_GENERAL);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_rgn);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_DIM,&elem_dim);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_dim);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_GENPAT_DIM_FIRST_DIR,&elem_dir);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_dim,NULL,elem_dir);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_GENPAT_DIM_DIR_COMPOUND,&elem_cmpd);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_dir,NULL,elem_cmpd);

	status = ProElementAlloc(PRO_E_GENPAT_DIR_DIMENSION,&elem_dim1);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
    
    ProMessageDisplay (PT_MSGFIL, (char*)"Select dimension");    
    status = ProSelect ((char*)"dimension", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProSelect", status); 
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProSelectionModelitemGet", status);   
    if ((status != PRO_TK_NO_ERROR) &&(mdl_item.type != PRO_DIMENSION))
      return status;

	status = ProSelectionAlloc(NULL,&mdl_item,&selections);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProSelectionAlloc", status);
	status = ProSelectionToReference(selections,&ref);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProSelectionToReference", status);
	status = ProElementReferenceSet(elem_dim1,ref);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementReferenceSet", status);
    status = ProElemtreeElementAdd(elem_cmpd,NULL,elem_dim1);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_DIR_VAR_TYPE,&elem_var);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_var,PRO_PAT_VALUE_DRIVEN);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_cmpd,NULL,elem_var);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_DIR_VAR_VALUE,&elem_value);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
    
    space_range[0] = 0;
    space_range[1] = 360;

    ProMessageDisplay (PT_MSGFIL, (char*)"Enter the distance between pattern elements");
    ProMessageDoubleRead(space_range, &at_space);
        
	status = ProElementDoubleSet(elem_value,at_space);
	ERROR_CHECK ("ProTestGeneralPattern()", "ProElementDoubleSet", status);
            
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_cmpd,NULL,elem_value);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_DIM_FIRST_DIR_NUM_INST,&elem_inst);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementAlloc", status);
    
    num_range[0] = 2;
    num_range[1] = 100;
    ProMessageDisplay (PT_MSGFIL, (char*)"Enter number of elements in pattern");
    ProMessageIntegerRead(num_range, &numof_elems);
        
	status = ProElementIntegerSet(elem_inst,numof_elems);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElementIntegerSet", status);
    if ((status != PRO_TK_NO_ERROR))
    {
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
      return status;
    }
    
	status = ProElemtreeElementAdd(elem_dim,NULL,elem_inst);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProElemtreeElementAdd", status);
    if ((status != PRO_TK_NO_ERROR))
    {
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
      return status;
    } 
    
	status = ProPatternCreate(&feature, PRO_FEAT_PATTERN,elem_tree);
    ERROR_CHECK ("ProTestGeneralPattern()", "ProPatternCreate", status);

    if ((status != PRO_TK_NO_ERROR))
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
    
    else
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation successful");

  return (status); 
}


/*================================================================*\
FUNCTION  : ProTestDirectionPattern()
PURPOSE   : Creates direction pattern
\*================================================================*/

ProError ProTestDirectionPattern()  
{

	ProElement elem_dir,elem_opt,elem_dir1,elem_cmpd,elem_ref,elem_flip;
	ProElement elem_dir1_flip,elem_inc;
    ProElement elem_fdir,elem_inst;
    ProFeature feature;
    ProModelitem mdl_item;
	ProElement elem_tree,elem_type,elem_rgn;
	ProGroupStatus grp;
    ProSelection selections;   
    ProReference ref;
    double at_space, space_range[2];
    int num_range[2];
    int n_sels, numof_elems;
    ProSelection* sels = NULL;	
	
    ProMessageDisplay (PT_MSGFIL, (char*)"Select feature for pattern creation");
    status = ProSelect ((char*)"membfeat", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;

    status = ProSelectionModelitemGet (sels[0], &feature);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProSelectionModelitemGet", status);         
    if ((status != PRO_TK_NO_ERROR) || (feature.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;

	status  = ProFeatureGroupStatusGet(&feature,&grp);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProFeatureGroupStatusGet", status);
   /*====================================================================*\
      Pattern Root
   \*====================================================================*/  
	status = ProElementAlloc(PRO_E_PATTERN_ROOT,&elem_tree);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);

	status = ProElementAlloc(PRO_E_GENPAT_TYPE,&elem_type);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_type,PRO_GENPAT_DIR_DRIVEN);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_type);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_REGEN_METHOD,&elem_rgn);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_rgn,PRO_PAT_GENERAL);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_rgn);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

    /*====================================================================*\
       Direction Pattern
    \*====================================================================*/

	status = ProElementAlloc(PRO_E_GENPAT_DIR,&elem_dir);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
        status = ProElemtreeElementAdd(elem_tree,NULL,elem_dir);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);
    
	status = ProElementAlloc(PRO_E_GENPAT_DIR1,&elem_dir1);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_dir,NULL,elem_dir1);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_DIRECTION_COMPOUND,&elem_cmpd);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_dir1,NULL,elem_cmpd);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_DIRECTION_REFERENCE,&elem_ref);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
    
    ProMessageDisplay (PT_MSGFIL, (char*)"Select surface");
    status = ProSelect ((char*)"surface", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProSelectionModelitemGet", status);   
    if ((status != PRO_TK_NO_ERROR) &&(mdl_item.type != PRO_SURFACE))
      return status;
    
	status = ProSelectionAlloc(NULL,&mdl_item,&selections);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProSelectionAlloc", status);
        status = ProSelectionToReference(selections,&ref);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProSelectionToReference", status);
	status = ProElementReferenceSet(elem_ref,ref);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementReferenceSet", status);
        status = ProElemtreeElementAdd(elem_cmpd,NULL,elem_ref);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

        status = ProElementAlloc(PRO_E_DIRECTION_FLIP,&elem_flip);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_flip,1);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_cmpd,NULL,elem_flip);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

        status = ProElementAlloc(PRO_E_GENPAT_DIR1_INC,&elem_inc);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
        
    space_range[0] = 0;
    space_range[1] = 360;

    ProMessageDisplay (PT_MSGFIL, (char*)"Enter the distance between pattern elements");
    ProMessageDoubleRead(space_range, &at_space);
            
        status = ProElementDoubleSet(elem_inc, at_space);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_dir,NULL,elem_inc);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);
    
	status = ProElementAlloc(PRO_E_DIR_PAT_DIR1_FLIP,&elem_dir1_flip);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_dir1_flip,0);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_dir,NULL,elem_dir1_flip);

	status = ProElementAlloc(PRO_E_DIR_PAT_DIR1_OPT,&elem_opt);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_opt,-1);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_dir,NULL,elem_opt);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_DIM_FIRST_DIR,&elem_fdir);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_dir,NULL,elem_fdir);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_DIM_FIRST_DIR_NUM_INST,&elem_inst);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementAlloc", status);
    
    num_range[0] = 2;
    num_range[1] = 100;
    ProMessageDisplay (PT_MSGFIL, (char*)"Enter number of elements in pattern");
    ProMessageIntegerRead(num_range, &numof_elems);
        
        status = ProElementIntegerSet(elem_inst,numof_elems);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_dir,NULL,elem_inst);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProElemtreeElementAdd", status);

	status = ProPatternCreate(&feature,PRO_FEAT_PATTERN,elem_tree);
    ERROR_CHECK ("ProTestDirectionPattern()", "ProPatternCreate", status);

    if ((status != PRO_TK_NO_ERROR))
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
    
    else
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation successful");

  return (status); 
}


/*================================================================*\
FUNCTION  : ProTestFillPattern()
PURPOSE   : Creates Fill pattern 
\*================================================================*/

ProError ProTestFillPattern()
{

	ProElement elem_fill,elem_temp,elem_bord,elem_ang;
	ProElement elem_space,elem_inc2;
	ProElement elem_sketch,elem_std,elem_method;
    ProFeature feature;
    ProModelitem mdl_item;
	ProElement elem_tree,elem_type;
	ProGroupStatus grp;
    ProSelection selections;   
    ProReference ref;
    double at_space, space_range[2];
    int n_sels, sel_type;
    ProSelection* sels = NULL;	
	
    ProMessageDisplay (PT_MSGFIL, (char*)"Select feature for pattern creation");
    status = ProSelect ((char*)"membfeat", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestFillPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;

    status = ProSelectionModelitemGet (sels[0], &feature);
    ERROR_CHECK ("ProTestFillPattern()", "ProSelectionModelitemGet", status);         
    if ((status != PRO_TK_NO_ERROR) || (feature.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;

	status  = ProFeatureGroupStatusGet(&feature,&grp);
    ERROR_CHECK ("ProTestFillPattern()", "ProFeatureGroupStatusGet", status);

     /*====================================================================*\
       Pattern Root
     \*====================================================================*/  
	status = ProElementAlloc(PRO_E_PATTERN_ROOT,&elem_tree);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
	status = ProElementAlloc(PRO_E_GENPAT_TYPE,&elem_type);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_type,PRO_GENPAT_FILL_DRIVEN);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_type);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

     /*====================================================================*\
       FILL PATTERN
    \*====================================================================*/
	status = ProElementAlloc(PRO_E_GENPAT_FILL,&elem_fill);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
        status = ProElemtreeElementAdd(elem_tree,NULL,elem_fill);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_FILL_TEMPLATE_TYPE,&elem_temp);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_temp,13);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_fill,NULL,elem_temp);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_FILL_SPACING,&elem_space);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
    space_range[0] = 0;
    space_range[1] = 100;

    ProMessageDisplay (PT_MSGFIL, (char*)"Enter the distance between pattern elements");
    ProMessageDoubleRead(space_range, &at_space);
        
        status = ProElementDoubleSet(elem_space,at_space);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_fill,NULL,elem_space);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_FILL_BORDERING,&elem_bord);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
	status = ProElementDoubleSet(elem_bord,-10.000);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_fill,NULL,elem_bord);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_FILL_ROT_ANG,&elem_ang);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
    
    space_range[0] = 0;
    space_range[1] = 360;

    ProMessageDisplay (PT_MSGFIL, (char*)"Enter the element angle");
    ProMessageDoubleRead(space_range, &at_space);
        
        status = ProElementDoubleSet(elem_ang,at_space);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_fill,NULL,elem_ang);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

        status = ProElementAlloc(PRO_E_GENPAT_FILL_RADIUS_INC,&elem_inc2);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
	status = ProElementDoubleSet(elem_inc2,25.000);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_fill,NULL,elem_inc2);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);
	
        status = ProElementAlloc(PRO_E_STD_SECTION,&elem_std);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_std);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_STD_SEC_METHOD,&elem_method);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_method,0);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_std,NULL,elem_method);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);


	status = ProElementAlloc(PRO_E_SEC_USE_SKETCH,&elem_sketch);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementAlloc", status);
 
    ProMessageDisplay (PT_MSGFIL, (char*)"Select sketch");
    status = ProSelect ((char*)"feature", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestFillPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestFillPattern()", "ProSelectionModelitemGet", status);   
    
    if ((status != PRO_TK_NO_ERROR) || (mdl_item.type != PRO_FEATURE))
      return status;

    sel_type = PRO_CURVE;
    status = ProFeatureGeomitemVisit(&mdl_item, PRO_CURVE, (ProGeomitemAction)visit_GeomFeat, NULL, (ProAppData)&sel_type);
    ERROR_CHECK ("ProTestPointPattern()", "ProFeatureGeomitemVisit", status); 
    if ((status != PRO_TK_NO_ERROR))
    {
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
      return status;
    }

    status = ProSelectionAlloc(NULL,(ProModelitem*)&mdl_item,&selections);
    ERROR_CHECK ("ProTestFillPattern()", "ProSelectionAlloc", status);
    
    status = ProSelectionToReference(selections,&ref);
    ERROR_CHECK ("ProTestFillPattern()", "ProSelectionToReference", status);
	status = ProElementReferenceSet(elem_sketch,ref);
    ERROR_CHECK ("ProTestFillPattern()", "ProElementReferenceSet", status);
    
	status = ProElemtreeElementAdd(elem_std,NULL,elem_sketch);
    ERROR_CHECK ("ProTestFillPattern()", "ProElemtreeElementAdd", status);

    status = ProPatternCreate(&feature,PRO_FEAT_PATTERN,elem_tree);
    ERROR_CHECK ("ProTestFillPattern()", "ProPatternCreate", status);

    if ((status != PRO_TK_NO_ERROR))
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
    
    else
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation successful");


  return (status); 
}


/*================================================================*\
FUNCTION  : ProTestPointPattern()
PURPOSE   : Creates point pattern
\*================================================================*/

ProError ProTestPointPattern()
{

	ProElement elem_point,elem_temp;
	ProElement elem_point_ref;
    ProFeature feature;
    ProFeature mdl_item;
	ProElement elem_tree,elem_type;
	ProGroupStatus grp;
    ProSelection selections;   
    ProReference ref;
    int n_sels, sel_type;
    ProSelection* sels = NULL;	
    
    ProMessageDisplay (PT_MSGFIL, (char*)"Select feature for pattern creation");
    status = ProSelect ((char*)"membfeat", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestPointPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;

    status = ProSelectionModelitemGet (sels[0], &feature);
    ERROR_CHECK ("ProTestPointPattern()", "ProSelectionModelitemGet", status);         
    if ((status != PRO_TK_NO_ERROR) || (feature.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;

	status  = ProFeatureGroupStatusGet(&feature,&grp);
    ERROR_CHECK ("ProTestPointPattern()", "ProFeatureGroupStatusGet", status);
   /*====================================================================*\
      Pattern Root
   \*====================================================================*/  
	status = ProElementAlloc(PRO_E_PATTERN_ROOT,&elem_tree);
    ERROR_CHECK ("ProTestPointPattern()", "ProElementAlloc", status);

	status = ProElementAlloc(PRO_E_GENPAT_TYPE,&elem_type);
    ERROR_CHECK ("ProTestPointPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_type,PRO_GENPAT_POINT_DRIVEN);
    ERROR_CHECK ("ProTestPointPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_type);
    ERROR_CHECK ("ProTestPointPattern()", "ProElemtreeElementAdd", status);

    /*====================================================================*\
       POINT PATTERN
    \*====================================================================*/
	status = ProElementAlloc(PRO_E_GENPAT_POINT,&elem_point);
    ERROR_CHECK ("ProTestPointPattern()", "ProElementAlloc", status);
    status = ProElemtreeElementAdd(elem_tree,NULL,elem_point);
    ERROR_CHECK ("ProTestPointPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_POINT_REF_TYPE,&elem_temp);
    ERROR_CHECK ("ProTestPointPattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_temp,56);
    ERROR_CHECK ("ProTestPointPattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_point,NULL,elem_temp);
    ERROR_CHECK ("ProTestPointPattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_POINT_REF,&elem_point_ref);
    ERROR_CHECK ("ProTestPointPattern()", "ProElementAlloc", status);

    ProMessageDisplay (PT_MSGFIL, (char*)"Select Point");
    status = ProSelect ((char*)"feature", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestPointPattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestPointPattern()", "ProSelectionModelitemGet", status);   
    if ((status != PRO_TK_NO_ERROR) || (mdl_item.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;
    
    sel_type = PRO_POINT;
    status = ProFeatureGeomitemVisit(&mdl_item, PRO_POINT, (ProGeomitemAction)visit_GeomFeat, NULL, (ProAppData) &sel_type);
    ERROR_CHECK ("ProTestPointPattern()", "ProFeatureGeomitemVisit", status); 
    if ((status != PRO_TK_NO_ERROR))
    {
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
      return status;
    }
      
    status = ProSelectionAlloc(NULL,(ProModelitem*)&mdl_item,&selections);
	ERROR_CHECK ("ProTestPointPattern()", "ProSelectionAlloc", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;  
  
	status = ProSelectionToReference(selections,&ref);
	ERROR_CHECK ("ProTestPointPattern()", "ProSelectionToReference", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
      	
    status = ProElementReferenceSet(elem_point_ref,ref);
	ERROR_CHECK ("ProTestPointPattern()", "ProElementReferenceSet", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
        
    status = ProElemtreeElementAdd(elem_point,NULL,elem_point_ref);
	ERROR_CHECK ("ProTestPointPattern()", "ProElemtreeElementAdd", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
          
    status = ProPatternCreate(&feature,PRO_FEAT_PATTERN,elem_tree);
    ERROR_CHECK ("ProTestPointPattern()", "ProPatternCreate", status);

    if ((status != PRO_TK_NO_ERROR))
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation failed");
    
    else
      ProMessageDisplay (PT_MSGFIL, (char*)"Pattern creation successful");

  return (status); 
}


/*================================================================*\
FUNCTION  : ProTestTablePattern()
PURPOSE   : Creates table pattern
\*================================================================*/

ProError ProTestTablePattern()
{
	ProElement elem_table,elem_table_dims,elem_table_entry;
	ProElement elem_table_dim1,elem_table_dim2;
	ProElement elem_table_list,elem_table_entry1,elem_table_instance1,elem_table_instances,elem_table_instance2;
	ProElement elem_table_instance_ind,elem_table_instance_dim1,elem_table_instance_dim2,elem_table_instance_dim_val1,elem_table_instance_dim_val2;
	ProElement pattern_table_set_active;
    ProFeature feature;
    ProModelitem mdl_item;
	ProElement elem_tree,elem_type;
	ProGroupStatus grp;
    ProSelection selections;   
    ProReference ref;
    int n_sels;
    ProSelection* sels = NULL;	
	
    ProMessageDisplay (PT_MSGFIL, (char*)"Select feature for pattern creation");
    status = ProSelect ((char*)"membfeat", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;

    status = ProSelectionModelitemGet (sels[0], &feature);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelectionModelitemGet", status);         
    if ((status != PRO_TK_NO_ERROR) || (feature.type != PRO_FEATURE))
      return PRO_TK_BAD_INPUTS;

	status  = ProFeatureGroupStatusGet(&feature,&grp);
    ERROR_CHECK ("ProTestTablePattern()", "ProFeatureGroupStatusGet", status);

   /*====================================================================*\
      Pattern Root
   \*====================================================================*/  
	status = ProElementAlloc(PRO_E_PATTERN_ROOT,&elem_tree);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);

	status = ProElementAlloc(PRO_E_GENPAT_TYPE,&elem_type);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_type,PRO_GENPAT_TABLE_DRIVEN);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_tree,NULL,elem_type);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);

    /*====================================================================*\
       TABLE PATTERN
    \*====================================================================*/
	status = ProElementAlloc(PRO_E_GENPAT_TABLE,&elem_table);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
    status = ProElemtreeElementAdd(elem_tree,NULL,elem_table);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);

	status = ProElementAlloc(PRO_E_GENPAT_TABLE_DIMS,&elem_table_dims);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table,NULL,elem_table_dims);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);

	status =ProElementAlloc(PRO_E_GENPAT_TABLE_DIM_ENTRY,&elem_table_entry);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table_dims,NULL,elem_table_entry);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);

    status = ProElementAlloc(PRO_E_GENPAT_TABLE_DIM,&elem_table_dim1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
    
    ProMessageDisplay (PT_MSGFIL, (char*)"Select dimension");
    status = ProSelect ((char*)"dimension", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelectionModelitemGet", status);   
    if ((status != PRO_TK_NO_ERROR) || (mdl_item.type != PRO_DIMENSION))
      return PRO_TK_BAD_INPUTS;

	status = ProSelectionAlloc(NULL,&mdl_item,&selections);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelectionAlloc", status);
	status = ProSelectionToReference(selections,&ref);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelectionToReference", status);
	status = ProElementReferenceSet(elem_table_dim1,ref);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementReferenceSet", status);
    status = ProElemtreeElementAdd(elem_table_entry,NULL,elem_table_dim1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_DIM,&elem_table_dim2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);

    ProMessageDisplay (PT_MSGFIL, (char*)"Select dimension");
    status = ProSelect ((char*)"dimension", 1, NULL, NULL, NULL, NULL, &sels, &n_sels);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelect", status);
    if ((status != PRO_TK_NO_ERROR))
      return status;
      
    status = ProSelectionModelitemGet (sels[0], &mdl_item);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelectionModelitemGet", status);   
    if ((status != PRO_TK_NO_ERROR) || (mdl_item.type != PRO_DIMENSION))
      return PRO_TK_BAD_INPUTS;

    status = ProSelectionAlloc(NULL,&mdl_item,&selections);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelectionAlloc", status);
	status = ProSelectionToReference(selections,&ref);
    ERROR_CHECK ("ProTestTablePattern()", "ProSelectionToReference", status);
	status = ProElementReferenceSet(elem_table_dim2,ref);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementReferenceSet", status);
    status = ProElemtreeElementAdd(elem_table_entry,NULL,elem_table_dim2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_LIST,&elem_table_list);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table,NULL,elem_table_list);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_ENTRY,&elem_table_entry1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table_list,NULL,elem_table_entry1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCES,&elem_table_instances);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table_entry1,NULL,elem_table_instances);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE,&elem_table_instance1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table_instances,NULL,elem_table_instance1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_INDEX,&elem_table_instance_ind);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_table_instance_ind,1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_table_instance1,NULL,elem_table_instance_ind);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_DIMS,&elem_table_instance_dim1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table_instance1,NULL,elem_table_instance_dim1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_DIM_VALUE,&elem_table_instance_dim_val1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElementDoubleSet(elem_table_instance_dim_val1,20);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_table_instance_dim1,NULL,elem_table_instance_dim_val1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
        
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_DIM_VALUE,&elem_table_instance_dim_val2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElementDoubleSet(elem_table_instance_dim_val2,20);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_table_instance_dim1,NULL,elem_table_instance_dim_val2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE,&elem_table_instance2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table_instances,NULL,elem_table_instance2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_INDEX,&elem_table_instance_ind);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElementIntegerSet(elem_table_instance_ind,2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementIntegerSet", status);
	status = ProElemtreeElementAdd(elem_table_instance2,NULL,elem_table_instance_ind);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_DIMS,&elem_table_instance_dim2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElemtreeElementAdd(elem_table_instance2,NULL,elem_table_instance_dim2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status =ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_DIM_VALUE,&elem_table_instance_dim_val1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElementDoubleSet(elem_table_instance_dim_val1,40);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_table_instance_dim2,NULL,elem_table_instance_dim_val1);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc(PRO_E_GENPAT_TABLE_INSTANCE_DIM_VALUE,&elem_table_instance_dim_val2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
	status = ProElementDoubleSet(elem_table_instance_dim_val2,40);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementDoubleSet", status);
	status = ProElemtreeElementAdd(elem_table_instance_dim2,NULL,elem_table_instance_dim_val2);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProElementAlloc (PRO_E_GENPAT_TABLE_SET_ACTIVE,&pattern_table_set_active);
    ERROR_CHECK ("ProTestTablePattern()", "ProElementAlloc", status);
    status = ProElementIntegerSet ( pattern_table_set_active, 0); 
    ERROR_CHECK ("ProTestTablePattern()", "ProElementIntegerSet", status);
    status = ProElemtreeElementAdd (elem_table, NULL, pattern_table_set_active);
    ERROR_CHECK ("ProTestTablePattern()", "ProElemtreeElementAdd", status);
	
	status = ProPatternCreate(&feature,PRO_FEAT_PATTERN,elem_tree);
    ERROR_CHECK ("ProTestTablePattern()", "ProPatternCreate", status);

    if ((status != PRO_TK_NO_ERROR))
      ProMessageDisplay (PT_MSGFIL, (char* )"Pattern creation failed");
    
    else
      ProMessageDisplay (PT_MSGFIL, (char* )"Pattern creation successful");

  return (status); 
}

ProError visit_GeomFeat(ProGeomitem *item, ProError stat, ProAppData app_data)
{
  ProType *sel_type = (ProType *) app_data;
  
  if(item->type == *sel_type)
    return PRO_TK_NO_ERROR;
  else
    return PRO_TK_BAD_INPUTS; 

}