API structuring improvements according to design guidelines by Brecht,

for more info see
http://lists.blender.org/pipermail/bf-taskforce25/2009-June/000954.html.

Created *_api.c files in makesrna/intern. Among these only rna_api.c
is compiled on preprocesssing step. It contains code declaring RNA
struct functions, for example RNA_api_mesh declares all functions on
Mesh. The rest *_api.c files contain functions themselves.

Removed interface_api.c and moved its contents to rna_api.c.

Added remove_mesh function on Main.

Replaced copy and copy_mesh on Mesh with make_rendermesh which currently 
does the same as copy_applied did (grasping mesh-related stuff needs 
time).

SConscript tweaking so it builds ok.
This commit is contained in:
Arystanbek Dyussenov 2009-06-18 09:50:34 +00:00
parent 449555315a
commit 29f5694ab8
13 changed files with 173 additions and 59 deletions

@ -3,8 +3,8 @@ Import ('env')
sources = env.Glob('*.c')
for source in env.Glob('*_api.c'):
sources.remove(source)
# for source in env.Glob('*_api.c'):
# sources.remove(source)
incs = '../include ../../blenlib ../../blenfont ../../blenkernel ../../makesdna ../../imbuf'
incs += ' ../../makesrna ../../windowmanager #/intern/guardedalloc'

@ -2028,35 +2028,11 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc)
}
}
/* Python API */
void copy_mesh_data(Mesh *dest, Mesh *src);
Mesh *RNA_api_add_mesh(Main *main, char *name)
{
return add_mesh(name);
}
void RNA_api_mesh_copy(Mesh *me, Mesh *from)
{
copy_mesh_data(me, from);
}
void RNA_api_mesh_copy_applied(Mesh *me, Scene *sce, Object *ob)
{
DerivedMesh *dm= mesh_create_derived_view(sce, ob, CD_MASK_MESH);
DM_to_mesh(dm, me);
dm->release(dm);
}
void RNA_api_mesh_transform(Mesh *me, float **mat)
{
}
/*
* This version of copy_mesh doesn't allocate a new mesh,
* instead it copies data between two existing meshes.
*
* XXX is this already possible with DerivedMesh?
* XXX not used anywhere...
*/
void copy_mesh_data(Mesh *dest, Mesh *src)
{

@ -13,12 +13,17 @@ root_build_dir=normpath(env['BF_BUILDDIR'])
source_files = env.Glob('*.c')
source_files.remove('rna_access.c')
api_runtime_files = env.Glob('*_api.c')
for api_file in api_runtime_files:
source_files.remove(api_file)
generated_files = source_files[:]
generated_files.remove('rna_define.c')
generated_files.remove('makesrna.c')
generated_files = [filename[:-2] + '_gen.c' for filename in generated_files]
source_files.extend(env.Glob('../../editors/*/*_api.c'))
# source_files.extend(env.Glob('../../editors/*/*_api.c'))
source_files.extend(env.Glob('rna_api.c'))
makesrna_tool = env.Clone()
rna = env.Clone()
@ -110,8 +115,9 @@ else:
rna.Command (generated_files, '', root_build_dir+os.sep+"makesrna.exe " + build_dir)
api_runtime_files.remove('rna_api.c')
obj = ['intern/rna_access.c']
for generated_file in generated_files:
for generated_file in generated_files + api_runtime_files:
obj += ['intern/' + generated_file]
Return ('obj')

@ -0,0 +1,26 @@
#include <stdlib.h>
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_library.h"
#include "BLI_listbase.h"
#include "DNA_mesh_types.h"
Mesh *RNA_api_main_add_mesh(Main *main, char *name)
{
return add_mesh(name);
}
void RNA_api_main_remove_mesh(Main *main, Mesh *me)
{
if (BLI_findindex(&main->mesh, me) == -1) {
/* XXX report error */
return;
}
/* XXX correct ? */
if (me->id.us == 1)
free_libblock(&main->mesh, me);
}

@ -0,0 +1,42 @@
#include <stdlib.h>
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "BLI_blenlib.h"
#include "BKE_DerivedMesh.h"
#include "BKE_mesh.h"
/*
void RNA_api_mesh_copy(Mesh *me, Mesh *from)
{
copy_mesh_data(me, from);
}
void RNA_api_mesh_copy_applied(Mesh *me, Scene *sce, Object *ob)
{
DerivedMesh *dm= mesh_create_derived_view(sce, ob, CD_MASK_MESH);
DM_to_mesh(dm, me);
dm->release(dm);
}
*/
/* copied from init_render_mesh (render code) */
void RNA_api_mesh_make_rendermesh(Mesh *me, Scene *sce, Object *ob)
{
CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL;
DerivedMesh *dm= mesh_create_derived_render(sce, ob, mask);
/* XXX report reason */
if(dm==NULL) return;
DM_to_mesh(dm, me);
dm->release(dm);
}
void RNA_api_mesh_transform(Mesh *me, float **mat)
{
}

@ -34,6 +34,66 @@
#include "UI_interface.h"
void RNA_api_main(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *prop;
func= RNA_def_function(srna, "add_mesh", "RNA_api_main_add_mesh");
RNA_def_function_ui_description(func, "Add a new mesh.");
prop= RNA_def_string(func, "name", "", 0, "", "New name for the datablock.");
RNA_def_property_flag(prop, PROP_REQUIRED);
prop= RNA_def_pointer(func, "mesh", "Mesh", "", "A new mesh.");
RNA_def_function_return(func, prop);
func= RNA_def_function(srna, "remove_mesh", "RNA_api_main_remove_mesh");
RNA_def_function_ui_description(func, "Remove a mesh if it has only one user.");
prop= RNA_def_pointer(func, "mesh", "Mesh", "", "A mesh to remove.");
RNA_def_property_flag(prop, PROP_REQUIRED);
}
void RNA_api_mesh(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *prop;
/*
func= RNA_def_function(srna, "copy", "RNA_api_mesh_copy");
RNA_def_function_ui_description(func, "Copy mesh data.");
prop= RNA_def_pointer(func, "src", "Mesh", "", "A mesh to copy data from.");
RNA_def_property_flag(prop, PROP_REQUIRED);*/
func= RNA_def_function(srna, "make_rendermesh", "RNA_api_mesh_make_rendermesh");
RNA_def_function_ui_description(func, "Copy mesh data from object with all modifiers applied.");
prop= RNA_def_pointer(func, "sce", "Scene", "", "Scene.");
RNA_def_property_flag(prop, PROP_REQUIRED);
prop= RNA_def_pointer(func, "ob", "Object", "", "Object to copy data from.");
RNA_def_property_flag(prop, PROP_REQUIRED);
/*
func= RNA_def_function(srna, "add_geom", "RNA_api_mesh_add_geom");
RNA_def_function_ui_description(func, "Add geometry data to mesh.");
prop= RNA_def_collection(func, "verts", "?", "", "Vertices.");
RNA_def_property_flag(prop, PROP_REQUIRED);
prop= RNA_def_collection(func, "faces", "?", "", "Faces.");
RNA_def_property_flag(prop, PROP_REQUIRED);
*/
}
void RNA_api_wm(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *prop;
func= RNA_def_function(srna, "add_fileselect", "RNA_api_wm_add_fileselect");
RNA_def_function_ui_description(func, "Show up the file selector.");
prop= RNA_def_pointer(func, "context", "Context", "", "Context.");
RNA_def_property_flag(prop, PROP_REQUIRED);
prop= RNA_def_pointer(func, "op", "Operator", "", "Operator to call.");
RNA_def_property_flag(prop, PROP_REQUIRED);
}
static void api_ui_item_common(FunctionRNA *func)
{
RNA_def_string(func, "text", "", 0, "", "Override automatic text of the item.");
@ -237,4 +297,3 @@ void RNA_api_ui_layout(StructRNA *srna)
parm= RNA_def_string(func, "property", "", 0, "", "Identifier of pointer property in data.");
RNA_def_property_flag(parm, PROP_REQUIRED);
}

@ -146,11 +146,6 @@ void RNA_def_context(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_struct_type(prop, "Scene");
RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL);
func= RNA_def_function(srna, "add_fileselect", "WM_event_add_fileselect");
RNA_def_function_ui_description(func, "Show up the file selector.");
prop= RNA_def_pointer(func, "op", "Operator", "", "Operator to call.");
RNA_def_property_flag(prop, PROP_REQUIRED);
}
#endif

@ -188,15 +188,29 @@ void rna_object_vcollayer_name_set(struct PointerRNA *ptr, const char *value, ch
/* API functions */
void RNA_api_ui_layout(struct StructRNA *srna);
void RNA_api_mesh(struct StructRNA *srna);
void RNA_api_wm(struct StructRNA *srna);
void RNA_api_main(StructRNA *srna);
#ifdef RNA_RUNTIME
struct wmWindowManager;
struct bContext;
struct wmOperator;
struct Main;
struct Mesh;
struct Scene;
struct Object;
struct Mesh;
void RNA_api_ui_layout(struct StructRNA *srna);
struct Mesh *RNA_api_add_mesh(struct Main *main, char *name);
void RNA_api_mesh_copy(struct Mesh *me, struct Mesh *from);
void RNA_api_mesh_copy_applied(struct Mesh *me, struct Scene *sce, struct Object *ob);
void RNA_api_wm_add_fileselect(struct wmWindowManager *self, struct bContext *C, struct wmOperator *op);
struct Mesh *RNA_api_main_add_mesh(struct Main *main, char *name);
void RNA_api_main_remove_mesh(struct Main *main, struct Mesh *me);
void RNA_api_mesh_make_rendermesh(struct Mesh *me, struct Scene *sce, struct Object *ob);
#endif
/* ID Properties */

@ -33,6 +33,7 @@
#ifdef RNA_RUNTIME
#include "BKE_main.h"
#include "BKE_mesh.h"
/* all the list begin functions are added manually here, Main is not in SDNA */
@ -268,12 +269,7 @@ void RNA_def_main(BlenderRNA *brna)
RNA_def_property_ui_text(prop, lists[i][3], lists[i][4]);
}
func= RNA_def_function(srna, "add_mesh", "RNA_api_add_mesh");
RNA_def_function_ui_description(func, "Add a new mesh.");
prop= RNA_def_string(func, "name", "", 0, "", "New name for the datablock.");
RNA_def_property_flag(prop, PROP_REQUIRED);
prop= RNA_def_pointer(func, "mesh", "Mesh", "", "A new mesh.");
RNA_def_function_return(func, prop);
RNA_api_main(srna);
}
#endif

@ -1071,7 +1071,6 @@ static void rna_def_mesh(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
FunctionRNA *func;
srna= RNA_def_struct(brna, "Mesh", "ID");
RNA_def_struct_ui_text(srna, "Mesh", "Mesh datablock to define geometric surfaces.");
@ -1156,17 +1155,7 @@ static void rna_def_mesh(BlenderRNA *brna)
rna_def_texmat_common(srna, "rna_Mesh_texspace_editable");
func= RNA_def_function(srna, "copy", "RNA_api_mesh_copy");
RNA_def_function_ui_description(func, "Copy mesh data.");
prop= RNA_def_pointer(func, "src", "Mesh", "", "A mesh to copy data from.");
RNA_def_property_flag(prop, PROP_REQUIRED);
func= RNA_def_function(srna, "copy_applied", "RNA_api_mesh_copy_applied");
RNA_def_function_ui_description(func, "Copy mesh data from object with all modifiers applied.");
prop= RNA_def_pointer(func, "sce", "Scene", "", "Scene.");
RNA_def_property_flag(prop, PROP_REQUIRED);
prop= RNA_def_pointer(func, "ob", "Object", "", "Object to copy data from.");
RNA_def_property_flag(prop, PROP_REQUIRED);
RNA_api_mesh(srna);
}
void RNA_def_mesh(BlenderRNA *brna)

@ -160,6 +160,8 @@ static void rna_def_windowmanager(BlenderRNA *brna)
prop= RNA_def_property(srna, "operators", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Operator");
RNA_def_property_ui_text(prop, "Operators", "Operator registry.");
RNA_api_wm(srna);
}
void RNA_def_wm(BlenderRNA *brna)

@ -0,0 +1,9 @@
#include "WM_api.h"
#include "BKE_context.h"
void RNA_api_wm_add_fileselect(wmWindowManager *self, bContext *C, wmOperator *op)
{
WM_event_add_fileselect(C, op);
}

@ -225,7 +225,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
PyObject *ret= NULL, *py_class_instance, *item= NULL;
int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
PointerRNA ptr_context;
PyObject ptr_operator;
PointerRNA ptr_operator;
PyObject *py_operator;
PyGILState_STATE gilstate = PyGILState_Ensure();