added rna property "parent" so nested RNA structs can access their parent RNA struct
This is used for generating docs so a nested RNA struct such as MaterialRaytraceTransparency are listed under Material rather then in the global struct list) These RNA structs are used for grouping properties and don't correspond to a C structure.
This commit is contained in:
@@ -43,6 +43,7 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *
|
||||
void RNA_def_struct_sdna(StructRNA *srna, const char *structname);
|
||||
void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname);
|
||||
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop);
|
||||
void RNA_def_struct_parent(StructRNA *srna, StructRNA *parent);
|
||||
void RNA_def_struct_flag(StructRNA *srna, int flag);
|
||||
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine);
|
||||
void RNA_def_struct_identifier(StructRNA *srna, const char *identifier);
|
||||
|
||||
@@ -883,6 +883,9 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
|
||||
if(srna->from) fprintf(f, "\t&RNA_%s,\n", (char*)srna->from);
|
||||
else fprintf(f, "\tNULL,\n");
|
||||
|
||||
if(srna->parent) fprintf(f, "\t&RNA_%s,\n", (char*)srna->parent);
|
||||
else fprintf(f, "\tNULL,\n");
|
||||
|
||||
fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
|
||||
|
||||
prop= srna->properties.first;
|
||||
|
||||
@@ -516,6 +516,15 @@ void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *pr
|
||||
srna->nameproperty= prop;
|
||||
}
|
||||
|
||||
void RNA_def_struct_parent(StructRNA *srna, StructRNA *parent)
|
||||
{
|
||||
|
||||
if(DefRNA.preprocess)
|
||||
srna->parent= (StructRNA*)parent->identifier;
|
||||
else
|
||||
srna->parent= parent;
|
||||
}
|
||||
|
||||
void RNA_def_struct_flag(StructRNA *srna, int flag)
|
||||
{
|
||||
srna->flag= flag;
|
||||
|
||||
@@ -205,6 +205,8 @@ typedef struct CollectionPropertyRNA {
|
||||
struct StructRNA *structtype;
|
||||
} CollectionPropertyRNA;
|
||||
|
||||
|
||||
/* changes to this struct require updating rna_generate_struct in makesrna.c */
|
||||
struct StructRNA {
|
||||
struct StructRNA *next, *prev;
|
||||
|
||||
@@ -227,6 +229,12 @@ struct StructRNA {
|
||||
/* struct this is derivedfrom */
|
||||
struct StructRNA *from;
|
||||
|
||||
/* only use for nested structs, where both the parent and child access
|
||||
* the same C Struct but nesting is used for grouping properties.
|
||||
* The parent property is used so we know NULL checks are not needed,
|
||||
* and that this struct will never exist without its parent */
|
||||
struct StructRNA *parent;
|
||||
|
||||
/* function to give the more specific type */
|
||||
StructRefineFunc refine;
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ static void rna_def_material_raymirror(BlenderRNA *brna, StructRNA *parent)
|
||||
|
||||
srna= RNA_def_struct(brna, "MaterialRaytraceMirror", NULL);
|
||||
RNA_def_struct_sdna(srna, "Material");
|
||||
RNA_def_struct_parent(srna, parent);
|
||||
RNA_def_struct_ui_text(srna, "Raytrace Mirror", "");
|
||||
|
||||
prop= RNA_def_property(parent, "raytrace_mirror", PROP_POINTER, PROP_NONE);
|
||||
@@ -248,6 +249,7 @@ static void rna_def_material_raytra(BlenderRNA *brna, StructRNA *parent)
|
||||
|
||||
srna= RNA_def_struct(brna, "MaterialRaytraceTransparency", NULL);
|
||||
RNA_def_struct_sdna(srna, "Material");
|
||||
RNA_def_struct_parent(srna, parent);
|
||||
RNA_def_struct_ui_text(srna, "Raytrace Transparency", "");
|
||||
|
||||
prop= RNA_def_property(parent, "raytrace_transparency", PROP_POINTER, PROP_NONE);
|
||||
@@ -334,6 +336,7 @@ static void rna_def_material_halo(BlenderRNA *brna, StructRNA *parent)
|
||||
|
||||
srna= RNA_def_struct(brna, "MaterialHalo", NULL);
|
||||
RNA_def_struct_sdna(srna, "Material");
|
||||
RNA_def_struct_parent(srna, parent);
|
||||
RNA_def_struct_ui_text(srna, "Halo", "");
|
||||
|
||||
prop= RNA_def_property(parent, "halo", PROP_POINTER, PROP_NONE);
|
||||
@@ -472,6 +475,7 @@ static void rna_def_material_sss(BlenderRNA *brna, StructRNA *parent)
|
||||
|
||||
srna= RNA_def_struct(brna, "MaterialSubsurfaceScattering", NULL);
|
||||
RNA_def_struct_sdna(srna, "Material");
|
||||
RNA_def_struct_parent(srna, parent);
|
||||
RNA_def_struct_ui_text(srna, "Subsurface Scattering", "");
|
||||
|
||||
prop= RNA_def_property(parent, "subsurface_scattering", PROP_POINTER, PROP_NONE);
|
||||
|
||||
@@ -69,6 +69,11 @@ static void *rna_Struct_base_get(PointerRNA *ptr)
|
||||
return ((StructRNA*)ptr->data)->from;
|
||||
}
|
||||
|
||||
static void *rna_Struct_parent_get(PointerRNA *ptr)
|
||||
{
|
||||
return ((StructRNA*)ptr->data)->parent;
|
||||
}
|
||||
|
||||
static void *rna_Struct_name_property_get(PointerRNA *ptr)
|
||||
{
|
||||
return ((StructRNA*)ptr->data)->nameproperty;
|
||||
@@ -430,6 +435,12 @@ static void rna_def_struct(BlenderRNA *brna)
|
||||
RNA_def_property_pointer_funcs(prop, "rna_Struct_base_get", NULL, NULL);
|
||||
RNA_def_property_ui_text(prop, "Base", "Struct definition this is derived from.");
|
||||
|
||||
prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
|
||||
RNA_def_property_struct_type(prop, "Struct");
|
||||
RNA_def_property_pointer_funcs(prop, "rna_Struct_parent_get", NULL, NULL);
|
||||
RNA_def_property_ui_text(prop, "Parent", "Parent struct, used only for nested structs.");
|
||||
|
||||
prop= RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
|
||||
RNA_def_property_struct_type(prop, "StringProperty");
|
||||
|
||||
@@ -71,6 +71,7 @@ void rna_def_ambient_occlusion(BlenderRNA *brna, StructRNA *parent)
|
||||
|
||||
srna= RNA_def_struct(brna, "WorldAmbientOcclusion", NULL);
|
||||
RNA_def_struct_sdna(srna, "World");
|
||||
RNA_def_struct_parent(srna, parent);
|
||||
RNA_def_struct_ui_text(srna, "Ambient Occlusion", "DOC_BROKEN");
|
||||
|
||||
prop= RNA_def_property(parent, "ambient_occlusion", PROP_POINTER, PROP_NONE);
|
||||
|
||||
@@ -43,23 +43,23 @@ def rna2epy(target_path):
|
||||
|
||||
|
||||
|
||||
def write_struct(rna_struct):
|
||||
def write_struct(rna_struct, structs, ident):
|
||||
identifier = rna_struct.identifier
|
||||
|
||||
rna_base = rna_struct.base
|
||||
|
||||
if rna_base:
|
||||
out.write('class %s(%s):\n' % (identifier, rna_base.identifier))
|
||||
out.write(ident+ 'class %s(%s):\n' % (identifier, rna_base.identifier))
|
||||
else:
|
||||
out.write('class %s:\n' % identifier)
|
||||
out.write(ident+ 'class %s:\n' % identifier)
|
||||
|
||||
out.write('\t"""\n')
|
||||
out.write(ident+ '\t"""\n')
|
||||
|
||||
title = 'The %s Object' % rna_struct.name
|
||||
|
||||
out.write('\t%s\n' % title)
|
||||
out.write('\t%s\n' % ('=' * len(title)))
|
||||
out.write('\t\t%s\n' % rna_struct.description)
|
||||
out.write(ident+ '\t%s\n' % title)
|
||||
out.write(ident+ '\t%s\n' % ('=' * len(title)))
|
||||
out.write(ident+ '\t\t%s\n' % rna_struct.description)
|
||||
|
||||
for rna_prop_identifier, rna_prop in rna_struct.properties.items():
|
||||
|
||||
@@ -90,24 +90,29 @@ def rna2epy(target_path):
|
||||
else: readonly_str = ' (readonly)'
|
||||
|
||||
if rna_prop_ptr: # Use the pointer type
|
||||
out.write('\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write('\t@type %s: %sL{%s}%s%s\n' % (rna_prop_identifier, collection_str, rna_prop_ptr.identifier, array_str, readonly_str))
|
||||
out.write(ident+ '\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write(ident+ '\t@type %s: %sL{%s}%s%s\n' % (rna_prop_identifier, collection_str, rna_prop_ptr.identifier, array_str, readonly_str))
|
||||
else:
|
||||
if rna_prop_type == 'enum':
|
||||
out.write('\t@ivar %s: %s in (%s)\n' % (rna_prop_identifier, rna_desc, ', '.join(rna_prop.items.keys())))
|
||||
out.write('\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
out.write(ident+ '\t@ivar %s: %s in (%s)\n' % (rna_prop_identifier, rna_desc, ', '.join(rna_prop.items.keys())))
|
||||
out.write(ident+ '\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
elif rna_prop_type == 'int' or rna_prop_type == 'float':
|
||||
out.write('\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write('\t@type %s: %s%s%s in [%s, %s]\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str, range_str(rna_prop.hard_min), range_str(rna_prop.hard_max) ))
|
||||
out.write(ident+ '\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write(ident+ '\t@type %s: %s%s%s in [%s, %s]\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str, range_str(rna_prop.hard_min), range_str(rna_prop.hard_max) ))
|
||||
elif rna_prop_type == 'string':
|
||||
out.write('\t@ivar %s: %s (maximum length of %s)\n' % (rna_prop_identifier, rna_desc, rna_prop.max_length))
|
||||
out.write('\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
out.write(ident+ '\t@ivar %s: %s (maximum length of %s)\n' % (rna_prop_identifier, rna_desc, rna_prop.max_length))
|
||||
out.write(ident+ '\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
else:
|
||||
out.write('\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write('\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
out.write(ident+ '\t@ivar %s: %s\n' % (rna_prop_identifier, rna_desc))
|
||||
out.write(ident+ '\t@type %s: %s%s%s\n' % (rna_prop_identifier, rna_prop_type, array_str, readonly_str))
|
||||
|
||||
|
||||
out.write('\t"""\n\n')
|
||||
out.write(ident+ '\t"""\n\n')
|
||||
|
||||
# Now write children recursively
|
||||
for child in structs:
|
||||
if rna_struct == child.parent:
|
||||
write_struct(child, structs, ident + '\t')
|
||||
|
||||
|
||||
out = open(target_path, 'w')
|
||||
@@ -150,7 +155,11 @@ def rna2epy(target_path):
|
||||
|
||||
|
||||
for rna_struct in structs:
|
||||
write_struct(rna_struct)
|
||||
if rna_struct.parent:
|
||||
continue
|
||||
|
||||
write_struct(rna_struct, structs, '')
|
||||
|
||||
|
||||
out.write('\n')
|
||||
out.close()
|
||||
|
||||
Reference in New Issue
Block a user