[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19239] branches/bmesh/blender/source/ blender/bmesh: split bmesh_operators.h, added (some) docs in comments, and hopefully made it less messy.
Joseph Eagar
joeedh at gmail.com
Mon Mar 9 11:38:36 CET 2009
Revision: 19239
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19239
Author: joeedh
Date: 2009-03-09 11:38:36 +0100 (Mon, 09 Mar 2009)
Log Message:
-----------
split bmesh_operators.h, added (some) docs in comments, and hopefully made it less messy. also added op names and slot names in comments next to their BM_XXXX_XXX definitions in bmesh_operators.h.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/bmesh/bmesh.h
branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
Added Paths:
-----------
branches/bmesh/blender/source/blender/bmesh/bmesh_error.h
branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h
Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h 2009-03-09 09:52:32 UTC (rev 19238)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h 2009-03-09 10:38:36 UTC (rev 19239)
@@ -216,7 +216,9 @@
#include "bmesh_filters.h"
#include "bmesh_iterators.h"
#include "bmesh_marking.h"
+#include "bmesh_operator_api.h"
#include "bmesh_operators.h"
+#include "bmesh_error.h"
#include "bmesh_queries.h"
#include "bmesh_walkers.h"
Added: branches/bmesh/blender/source/blender/bmesh/bmesh_error.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_error.h (rev 0)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_error.h 2009-03-09 10:38:36 UTC (rev 19239)
@@ -0,0 +1,49 @@
+#ifndef _BMESH_ERROR_H
+#define _BMESH_ERROR_H
+
+/*----------- bmop error system ----------*/
+
+/*pushes an error onto the bmesh error stack.
+ if msg is null, then the default message for the errorcode is used.*/
+void BMO_RaiseError(BMesh *bm, BMOperator *owner, int errcode, char *msg);
+
+/*gets the topmost error from the stack.
+ returns error code or 0 if no error.*/
+int BMO_GetError(BMesh *bm, char **msg, BMOperator **op);
+int BMO_HasError(BMesh *bm);
+
+/*same as geterror, only pops the error off the stack as well*/
+int BMO_PopError(BMesh *bm, char **msg, BMOperator **op);
+void BMO_ClearStack(BMesh *bm);
+
+#if 0
+//this is meant for handling errors, like self-intersection test failures.
+//it's dangerous to handle errors in general though, so disabled for now.
+
+/*catches an error raised by the op pointed to by catchop.
+ errorcode is either the errorcode, or BMERR_ALL for any
+ error.*/
+int BMO_CatchOpError(BMesh *bm, BMOperator *catchop, int errorcode, char **msg);
+#endif
+
+/*------ error code defines -------*/
+
+/*error messages*/
+#define BMERR_SELF_INTERSECTING 1
+#define BMERR_DISSOLVEDISK_FAILED 2
+#define BMERR_CONNECTVERT_FAILED 3
+#define BMERR_WALKER_FAILED 4
+#define BMERR_DISSOLVEFACES_FAILED 5
+#define BMERR_DISSOLVEVERTS_FAILED 6
+
+static char *bmop_error_messages[] = {
+ 0,
+ "Self intersection error",
+ "Could not dissolve vert",
+ "Could not connect verts",
+ "Could not traverse mesh",
+ "Could not dissolve faces",
+ "Could not dissolve vertices",
+};
+
+#endif /* _BMESH_ERROR_H */
\ No newline at end of file
Added: branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h (rev 0)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h 2009-03-09 10:38:36 UTC (rev 19239)
@@ -0,0 +1,217 @@
+#ifndef _BMESH_OPERATOR_H
+#define _BMESH_OPERATOR_H
+
+#include "BLI_memarena.h"
+#include "BLI_ghash.h"
+
+#include <stdarg.h>
+
+/*
+operators represent logical, executable mesh modules. all operations
+involving a bmesh has to go through them.
+
+operators are nested, and certain data (e.g. tool flags) are also nested,
+and are private to an operator when it's executed.
+*/
+
+struct GHashIterator;
+
+#define BMOP_OPSLOT_INT 0
+#define BMOP_OPSLOT_FLT 1
+#define BMOP_OPSLOT_PNT 2
+#define BMOP_OPSLOT_VEC 6
+
+/*after BMOP_OPSLOT_VEC, everything is
+ dynamically allocated arrays. we
+ leave a space in the identifiers
+ for future growth.*/
+#define BMOP_OPSLOT_ELEMENT_BUF 7
+#define BMOP_OPSLOT_MAPPING 8
+#define BMOP_OPSLOT_TYPES 9
+
+/*don't access the contents of this directly*/
+typedef struct BMOpSlot{
+ int slottype;
+ int len;
+ int flag;
+ int index; /*index within slot array*/
+ union {
+ int i;
+ float f;
+ void *p;
+ float vec[3];
+ void *buf;
+ GHash *ghash;
+ } data;
+}BMOpSlot;
+
+#define BMOP_MAX_SLOTS 16 /*way more than probably needed*/
+
+typedef struct BMOperator {
+ int type;
+ int slottype;
+ int needflag;
+ struct BMOpSlot slots[BMOP_MAX_SLOTS];
+ void (*exec)(struct BMesh *bm, struct BMOperator *op);
+ MemArena *arena;
+} BMOperator;
+
+#define MAX_SLOTNAME 32
+
+typedef struct slottype {
+ int type;
+ char name[MAX_SLOTNAME];
+} slottype;
+
+typedef struct BMOpDefine {
+ char *name;
+ slottype slottypes[BMOP_MAX_SLOTS];
+ void (*exec)(BMesh *bm, BMOperator *op);
+ int totslot;
+ int flag; /*doesn't do anything right now*/
+} BMOpDefine;
+
+/*------------- Operator API --------------*/
+
+/*data types that use pointers (arrays, etc) should never
+ have it set directly. and never use BMO_Set_Pnt to
+ pass in a list of edges or any arrays, really.*/
+void BMO_Init_Op(struct BMOperator *op, int opcode);
+void BMO_Exec_Op(struct BMesh *bm, struct BMOperator *op);
+void BMO_Finish_Op(struct BMesh *bm, struct BMOperator *op);
+
+/*tool flag API. never, ever ever should tool code put junk in
+ header flags (element->head.flag), nor should they use
+ element->head.eflag1/eflag2. instead, use this api to set
+ flags.
+
+ if you need to store a value per element, use a
+ ghash or a mapping slot to do it.*/
+/*flags 15 and 16 (1<<14 and 1<<15) are reserved for bmesh api use*/
+void BMO_SetFlag(struct BMesh *bm, void *element, int flag);
+void BMO_ClearFlag(struct BMesh *bm, void *element, int flag);
+int BMO_TestFlag(struct BMesh *bm, void *element, int flag);
+int BMO_CountFlag(struct BMesh *bm, int flag, int type);
+
+/*---------formatted operator initialization/execution-----------*/
+/*
+ this system is used to execute or initialize an operator,
+ using a formatted-string system.
+
+ for example, BMO_CallOpf(bm, "del geom=%hf context=%d", BM_SELECT, DEL_FACES);
+ . . .will execute the delete operator, feeding in selected faces, deleting them.
+
+ the basic format for the format string is:
+ [operatorname] [slotname]=%[code] [slotname]=%[code]
+
+ as in printf, you pass in one additional argument to the function
+ for every code.
+
+ the formatting codes are:
+ %d - put int in slot
+ %f - put float in float
+ %h[f/e/v] - put elements with a header flag in slot.
+ the letters after %h define which element types to use,
+ so e.g. %hf will do faces, %hfe will do faces and edges,
+ %hv will do verts, etc. must pass in at least one
+ element type letter.
+ %f[f/e/v] - same as %h.
+*/
+/*executes an operator*/
+int BMO_CallOpf(BMesh *bm, char *fmt, ...);
+
+/*initializes, but doesn't execute an operator*/
+int BMO_InitOpf(BMesh *bm, BMOperator *op, char *fmt, ...);
+
+/*va_list version, used to implement the above two functions,
+ plus EDBM_CallOpf in bmeshutils.c.*/
+int BMO_VInitOpf(BMesh *bm, BMOperator *op, char *fmt, va_list vlist);
+
+
+BMOpSlot *BMO_GetSlot(struct BMOperator *op, int slotcode);
+void BMO_CopySlot(struct BMOperator *source_op, struct BMOperator *dest_op, int src, int dst);
+
+void BMO_Set_Float(struct BMOperator *op, int slotcode, float f);
+void BMO_Set_Int(struct BMOperator *op, int slotcode, int i);
+/*don't pass in arrays that are supposed to map to elements this way.
+
+ so, e.g. passing in list of floats per element in another slot is bad.
+ passing in, e.g. pointer to an editmesh for the conversion operator is fine
+ though.*/
+void BMO_Set_Pnt(struct BMOperator *op, int slotcode, void *p);
+void BMO_Set_Vec(struct BMOperator *op, int slotcode, float *vec);
+
+/*puts every element of type type (which is a bitmask) with tool flag flag,
+ into a slot.*/
+void BMO_Flag_To_Slot(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag, int type);
+void BMO_Flag_Buffer(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag);
+void BMO_Unflag_Buffer(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag);
+
+/*puts every element of type type (which is a bitmask) with header flag
+ flag, into a slot.*/
+void BMO_HeaderFlag_To_Slot(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag, int type);
+int BMO_CountSlotBuf(struct BMesh *bm, struct BMOperator *op, int slotcode);
+
+/*copies data, doesn't store a reference to it.*/
+void BMO_Insert_Mapping(BMesh *bm, BMOperator *op, int slotcode,
+ void *element, void *data, int len);
+void BMO_Insert_MapFloat(BMesh *bm, BMOperator *op, int slotcode,
+ void *element, float val);
+//returns 1 if the specified element is in the map.
+int BMO_InMap(BMesh *bm, BMOperator *op, int slotcode, void *element);
+void *BMO_Get_MapData(BMesh *bm, BMOperator *op, int slotcode, void *element);
+float BMO_Get_MapFloat(BMesh *bm, BMOperator *op, int slotcode, void *element);
+void BMO_Mapping_To_Flag(struct BMesh *bm, struct BMOperator *op,
+ int slotcode, int flag);
+
+/*do NOT use these for non-operator-api-allocated memory! instead
+ use BMO_Get_MapData and BMO_Insert_Mapping, which copies the data.*/
+void BMO_Insert_MapPointer(BMesh *bm, BMOperator *op, int slotcode,
+ void *element, void *val);
+void *BMO_Get_MapPointer(BMesh *bm, BMOperator *op, int slotcode,
+ void *element);
+
+/*contents of this structure are private,
+ don't directly access.*/
+typedef struct BMOIter {
+ BMOpSlot *slot;
+ int cur; //for arrays
+ struct GHashIterator giter;
+ void *val;
+} BMOIter;
+
+/*this part of the API is used to iterate over element buffer or
+ mapping slots.
+
+ for example, iterating over the faces in a slot is:
+
+ BMOIter oiter;
+ BMFace *f;
+
+ f = BMO_IterNew(&oiter, bm, some_operator, SOME_SLOT_CODE);
+ for (; f; f=BMO_IterStep) {
+ /do something with the face
+ }
+
+ another example, iterating over a mapping:
+ BMOIter oiter;
+ void *key;
+ void *val;
+
+ key = BMO_IterNew(&oiter, bm, some_operator, SOME_SLOT_CODE);
+ for (; key; key=BMO_IterStep) {
+ val = BMO_IterMapVal(&oiter);
+ //do something with the key/val pair
+ }
+
+ */
+
+void *BMO_IterNew(BMOIter *iter, BMesh *bm, BMOperator *op,
+ int slotcode);
+void *BMO_IterStep(BMOIter *iter);
+
+/*returns a pointer to the key value when iterating over mappings.
+ remember for pointer maps this will be a pointer to a pointer.*/
+void *BMO_IterMapVal(BMOIter *iter);
+
+#endif /* _BMESH_OPERATOR_H */
\ No newline at end of file
Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h 2009-03-09 09:52:32 UTC (rev 19238)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list