1 #ifndef DynamicNodeKit_H 2 #define DynamicNodeKit_H 4 #include <Inventor/nodekits/SoBaseKit.h> 5 #include <Inventor/nodekits/SoSubKit.h> 7 #include <Inventor/fields/SoFieldData.h> 8 #include <Inventor/nodekits/SoNodekitCatalog.h> 10 #include <Inventor/C/XML/parser.h> 11 #include <Inventor/C/XML/document.h> 12 #include <Inventor/C/XML/element.h> 13 #include <Inventor/C/XML/attribute.h> 22 typedef Base inherited;
38 static void atexit_cleanup(
void);
41 static unsigned int classinstances;
42 static void * createInstance(
void);
45 static void atexit_cleanupkit(
void);
62 virtual SoNode *
getAnyPart(
const SbName & partname, SbBool makeifneeded, SbBool leafcheck = 0, SbBool publiccheck = 0);
71 bool addPartsFromXml(cc_xml_elt * element,
const char * parentName,
const char * rightSiblingName);
83 #ifndef DYNAMIC_NODEKIT_NO_GENERATE_FUNCTIONS 107 template <
class Base>
117 template <
class Base>
124 template <
class Base>
131 template <
class Base>
139 template <
class Base>
152 template <
class Base>
163 template <
class Base>
168 return dynamicFieldData;
172 template <
class Base>
177 return this->dynamicCatalog;
180 template <
class Base>
190 SbString classNameString =
"Dynamic";
191 classNameString += parentName;
193 const char * classname = classNameString.
getString();
212 template <
class Base>
219 this->dynamicFieldData->
copy(inherited::getFieldData());
224 this->finished =
false;
225 this->isEditing =
false;
228 template <
class Base>
233 const int n = this->dynamicFieldData->getNumFields();
234 for (
int i = 0; i < n; i++) {
235 SoField * f = this->dynamicFieldData->getField(
this, i);
236 if ((*this->getFieldDataPtr())->getIndex(
this, f) == -1) {
240 delete this->dynamicFieldData;
241 delete this->dynamicCatalog;
244 template <
class Base>
254 for (
int i = 0; i < n; i++) {
255 const SoField * f = src->getField(from, i);
256 if (this->dynamicFieldData->getIndex(
this, f) == -1) {
260 this->dynamicFieldData->addField(
this, src->getFieldName(i), cp);
264 inherited::copyContents(from, copyconn);
267 template <
class Base>
272 if (!this->isEditing){
279 if (defaultValue !=
"") f->
set(defaultValue.
getString());
280 this->dynamicFieldData->addField(
this, name.
getString(), f);
284 template <
class Base>
289 if (!this->isEditing){
294 this->dynamicCatalog->addEntry(name, type, type, isDefaultNull, parentName, rightSiblingName, FALSE,
SoType::badType(),
SoType::badType(), isPublic);
299 this->dynamicFieldData->addField(
this, name.
getString(), f);
303 template <
class Base>
312 this->isEditing =
true;
316 template <
class Base>
321 if (!this->isEditing || this->finished){
325 this->createFieldList();
326 this->createDefaultParts();
328 this->isEditing =
false;
329 this->finished =
true;
333 template <
class Base>
338 if (this->finished || this->isEditing){
342 cc_xml_document * xmldoc = cc_xml_read_buffer(xmlDescription.
getString());
344 cc_xml_element * root = cc_xml_doc_get_root(xmldoc);
345 if (strcmp(cc_xml_elt_get_type(root),
"DynamicNodeKitDescription")){
349 this->startEditing();
351 int numFields = cc_xml_elt_get_num_children_of_type(root,
"Field");
352 for (
int i = 0; i < numFields; i++){
353 cc_xml_element * fieldElement = cc_xml_elt_get_child_of_type(root,
"Field", i);
354 const char * name = cc_xml_attr_get_value(cc_xml_elt_get_attribute(fieldElement,
"name"));
355 const char * type = cc_xml_attr_get_value(cc_xml_elt_get_attribute(fieldElement,
"type"));
356 const char * value = cc_xml_elt_get_cdata(fieldElement);
357 this->addField(name, type, value);
360 this->addPartsFromXml(root,
"this",
"");
361 this->finishEditing();
367 template <
class Base>
372 const char * name = parentName;
373 if (!strcmp(cc_xml_elt_get_type(element),
"Part")){
374 name = cc_xml_attr_get_value(cc_xml_elt_get_attribute(element,
"name"));
375 const char * type = cc_xml_attr_get_value(cc_xml_elt_get_attribute(element,
"type"));
376 cc_xml_attribute * isDefaultNullAttr = cc_xml_elt_get_attribute(element,
"isNullByDefault");
377 const char * isDefaultNull = isDefaultNullAttr ? cc_xml_attr_get_value(isDefaultNullAttr) :
"false";
378 cc_xml_attribute * isPublicAttr = cc_xml_elt_get_attribute(element,
"isPublic");
379 const char * isPublic = isPublicAttr ? cc_xml_attr_get_value(isPublicAttr) :
"false";
380 this->addPart(name, type, strcmp(isDefaultNull,
"false"), parentName, rightSiblingName, strcmp(isPublic,
"false"));
383 int numChildren = cc_xml_elt_get_num_children_of_type(element,
"Part");
384 for (
int i = 0; i < numChildren; i++){
385 cc_xml_element * partElement = cc_xml_elt_get_child_of_type(element,
"Part", i);
386 const char * nextSiblingName =
"";
387 if (i < numChildren - 1){
388 cc_xml_element * siblingElement = cc_xml_elt_get_child_of_type(element,
"Part", i + 1);
389 nextSiblingName = cc_xml_attr_get_value(cc_xml_elt_get_attribute(siblingElement,
"name"));
391 this->addPartsFromXml(partElement, name, nextSiblingName);
397 template <
class Base>
402 return inherited::getAnyPart(partname, makeifneeded, leafcheck, publiccheck);
405 template <
class Base>
410 return inherited::setAnyPart(partname, from, anypart);
413 #endif //SMALLCHANGE_INTERNAL 415 #endif // DynamicNodeKit_H static SoType fromName(const SbName name)
SoType DynamicNodeKit< Base >::classTypeId STATIC_SOTYPE_INIT
Definition: DynamicNodeKit.h:84
SbBool set(const char *valuestring)
void * createInstance(void) const
static const SoNodekitCatalog * getClassNodekitCatalog(void)
Definition: DynamicNodeKit.h:94
DynamicNodeKit(void)
Definition: DynamicNodeKit.h:214
bool startEditing()
Definition: DynamicNodeKit.h:306
virtual const SoFieldData * getFieldData(void) const
Definition: DynamicNodeKit.h:166
static const SoFieldData ** getFieldDataPtr(void)
Definition: DynamicNodeKit.h:134
void copy(const SoFieldData *src)
int getNumFields(void) const
const char * getString(void) const
virtual SbBool setAnyPart(const SbName &partname, SoNode *from, SbBool anypart=1)
Definition: DynamicNodeKit.h:408
bool addPart(SbString name, SbString typeString, SbBool isDefaultNull, SbString parentName, SbString rightSiblingName, SbBool isPublic)
Definition: DynamicNodeKit.h:287
virtual void copyContents(const SoFieldContainer *from, SbBool copyconn)
Definition: DynamicNodeKit.h:247
virtual const SoFieldData * getFieldData(void) const
virtual const SoNodekitCatalog * getNodekitCatalog(void) const
Definition: DynamicNodeKit.h:175
void cc_coin_atexit_static_internal(coin_atexit_f *fp)
static SoType badType(void)
bool finishEditing()
Definition: DynamicNodeKit.h:319
SbBool isOfType(SoType type) const
static const SoType createType(const SoType parent, const SbName name, const instantiationMethod method=NULL, const uint16_t data=0)
void setContainer(SoFieldContainer *cont)
static void initClass(void)
Definition: DynamicNodeKit.h:183
static void incNextActionMethodIndex(void)
virtual SoType getTypeId(void) const=0
void cc_xml_doc_delete_x(cc_xml_doc *doc)
int getFieldType(void) const
SbName getName(void) const
static SoType getClassTypeId(void)
Definition: DynamicNodeKit.h:120
static const SoNodekitCatalog ** getClassNodekitCatalogPtr(void)
Definition: DynamicNodeKit.h:102
virtual ~DynamicNodeKit()
Definition: DynamicNodeKit.h:230
static SbBool removeType(const SbName &name)
SoNodekitCatalog * clone(SoType type) const
virtual SoNode * getAnyPart(const SbName &partname, SbBool makeifneeded, SbBool leafcheck=0, SbBool publiccheck=0)
Definition: DynamicNodeKit.h:400
static SoType getClassTypeId(void)
Definition: DynamicNodeKit.h:21
int getNumEntries(void) const
static int getNextActionMethodIndex(void)
void setFieldType(int type)
virtual SoType getTypeId(void) const
Definition: DynamicNodeKit.h:127
bool setNodekitDescription(SbString xmlDescription)
Definition: DynamicNodeKit.h:336
bool addField(SbString name, SbString typeString, SbString defaultValue)
Definition: DynamicNodeKit.h:270