/*====================================================================*\ FILE : UgSktExtrusionCreate.c PURPOSE : Creating an Extruded Protrusion Base Feature HISTORY.. DATE BUILD AUTHOR MODIFICATIONS 04-Dec-97 H-02-02 Stefan $$1 Created 26-Mar-01 J-01-30 KB $$2 Changed element ids for section depth specification. spr 858688/770177 \*====================================================================*/ /*---------------------- Pro/Toolkit Includes ------------------------*/ #include "ProToolkit.h" #include "ProFeature.h" #include "ProElemId.h" #include "ProExtrude.h" #include "ProModFeat.h" #include "ProStdSection.h" #include "ProElement.h" #include "ProElempath.h" #include "ProFeatType.h" #include "ProFeatForm.h" #include "ProSelection.h" #include "ProSection.h" /*---------------------- Function Prototypes -------------------------*/ ProError ProDemoBaseExtrudeProtrCreate(); ProError ProTestFeatElemAdd(); /*------------------------- External Data ----------------------------*/ ProError ProDemoSectCreate(); /*------------------------- Global Data -----------------------------*/ typedef struct tree_element_data { ProElement tree; ProElement parent_element; ProElemId elem_id; ProValueData value_data; } ProTreeElemdata; /*===============================================================*\ FUNCTION : ProDemoBaseExtrudeProtrCreate PURPOSE : Demonstrates the creation of the extruded protrusion base feature. \*===============================================================*/ ProError ProDemoBaseExtrudeProtrCreate() { ProTreeElemdata elem; ProErrorlist errs; ProMdl model; ProModelitem model_item; ProSelection model_sel; ProFeature feature; ProFeatureCreateOptions opts[1]; ProElempath path; ProElempathItem path_items[2]; ProSection section; ProAsmcomppath comp_path; ProAsmcomppath *p_comp_path = NULL; ProElement parent_elem; ProError err; ProValue value; double width; double height; double bite_radius; double bite_height; char name[PRO_NAME_SIZE]; ProBoolean alloc; /*---------------------------------------------------------------*\ Allocate the element tree. \*---------------------------------------------------------------*/ err = ProElementAlloc (PRO_E_FEATURE_TREE, &(elem.tree)); /*---------------------------------------------------------------*\ Add the feature type element to the tree. \*---------------------------------------------------------------*/ elem.parent_element = elem.tree; elem.elem_id = PRO_E_FEATURE_TYPE; elem.value_data.type = PRO_VALUE_TYPE_INT; elem.value_data.v.i = PRO_FEAT_FIRST_FEAT; err = ProTestFeatElemAdd (&elem); /*---------------------------------------------------------------*\ Add the feature form element to the tree. \*---------------------------------------------------------------*/ elem.parent_element = elem.tree; elem.elem_id = PRO_E_FEATURE_FORM; elem.value_data.type = PRO_VALUE_TYPE_INT; elem.value_data.v.i = PRO_EXTRUDE; err = ProTestFeatElemAdd (&elem); /*---------------------------------------------------------------*\ Add the standard section element to the tree. \*---------------------------------------------------------------*/ elem.parent_element = elem.tree; elem.elem_id = PRO_E_STD_SECTION; elem.value_data.type = -1; elem.value_data.v.i = -1; err = ProTestFeatElemAdd (&elem); /*---------------------------------------------------------------*\ Create the incomplete protrusion in the current model. \*---------------------------------------------------------------*/ err = ProMdlCurrentGet (&model); if ( err != PRO_TK_NO_ERROR ) return ( err ); err = ProMdlToModelitem( model, &model_item ); err = ProSelectionAlloc (p_comp_path, &model_item, &model_sel); opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT; err = ProFeatureCreate (model_sel, elem.tree, opts, 1, &feature, &errs); /*---------------------------------------------------------------*\ Get the initialized section element from the database. \*---------------------------------------------------------------*/ path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID; path_items[0].path_item.elem_id = PRO_E_STD_SECTION; path_items[1].type = PRO_ELEM_PATH_ITEM_TYPE_ID; path_items[1].path_item.elem_id = PRO_E_SKETCHER; err = ProElempathAlloc (&path); err = ProElempathDataSet (path, path_items, 2); err = ProFeatureElemValueGet (&feature, path, &value); err = ProValueDataGet (value, &(elem.value_data)); section = (ProSection)elem.value_data.v.p; /*---------------------------------------------------------------*\ Create the 2-dimensional section and get the section handle \*---------------------------------------------------------------*/ width = 200; height = 150; bite_radius = 20; bite_height = 30; strcpy(name, "2DSection"); alloc = PRO_B_FALSE; err = ProDemoSectCreate( width, height, bite_radius, bite_height, name, alloc, §ion ); /*---------------------------------------------------------------*\ Add the section element to the element tree. \*---------------------------------------------------------------*/ elem.elem_id = PRO_E_SKETCHER; elem.value_data.type = PRO_VALUE_TYPE_POINTER; elem.value_data.v.p = (void *)section; err = ProTestFeatElemAdd (&elem); /*---------------------------------------------------------------*\ Add the section depth elements to the element tree. \*---------------------------------------------------------------*/ elem.parent_element = elem.tree; elem.elem_id = PRO_E_STD_EXT_DEPTH; elem.value_data.type = -1; elem.value_data.v.i = -1; /* Here a problem occurs */ err = ProTestFeatElemAdd (&elem); elem.elem_id = PRO_E_EXT_DEPTH_FROM; elem.value_data.type = -1; elem.value_data.v.i = -1; err = ProTestFeatElemAdd (&elem); parent_elem = elem.parent_element; elem.elem_id = PRO_E_EXT_DEPTH_FROM_TYPE; elem.value_data.type = PRO_VALUE_TYPE_INT; elem.value_data.v.i = PRO_EXT_DEPTH_FROM_BLIND; err = ProTestFeatElemAdd (&elem); elem.parent_element = parent_elem; elem.elem_id = PRO_E_EXT_DEPTH_FROM_VALUE; elem.value_data.type = PRO_VALUE_TYPE_DOUBLE; elem.value_data.v.d = 10.0; err = ProTestFeatElemAdd (&elem); /*---------------------------------------------------------------*\ Redefine the protrusion and complete the feature creation. \*---------------------------------------------------------------*/ opts[0] = PRO_FEAT_CR_DEFINE_MISS_ELEMS; err = ProSelectionAsmcomppathGet (model_sel, &comp_path); err = ProFeatureRedefine (&comp_path, &feature, elem.tree, opts, 1, &errs); /*---------------------------------------------------------------*\ Free up the allocated memory. \*---------------------------------------------------------------*/ err = ProSectionFree (§ion); err = ProElementFree (&elem.tree); return (0); } /*===============================================================*\ FUNCTION : ProTestFeatElemAdd PURPOSE : Adds a generic feature element to the element tree. \*===============================================================*/ ProError ProTestFeatElemAdd (ProTreeElemdata *elem) { ProValue value; ProElement element; ProError err; if (elem->value_data.type != -1) { err = ProValueAlloc (&value); err = ProValueDataSet (value, &elem->value_data); } err = ProElementAlloc (elem->elem_id, &element); if (elem->value_data.type != -1) err = ProElementValueSet (element, value); err = ProElemtreeElementAdd (elem->parent_element, NULL, element); elem->parent_element = element; return (err); }