[Bf-blender-cvs] [7bb90a0] strand_editmode: Moved code for the hair edit data structures to blenkernel.

Lukas Tönne noreply at git.blender.org
Mon Apr 20 14:22:44 CEST 2015


Commit: 7bb90a06e19ec8966f1400931e2111754ff1a1bd
Author: Lukas Tönne
Date:   Tue Nov 25 09:04:09 2014 +0100
Branches: strand_editmode
https://developer.blender.org/rB7bb90a06e19ec8966f1400931e2111754ff1a1bd

Moved code for the hair edit data structures to blenkernel.

This makes it work more like editmesh, and avoid the awkward and
basically bad-level approach in particles, where the edit data is an
anonymous pointer in particle systems together with a callback for
freeing.

Conflicts:
	source/blender/blenkernel/CMakeLists.txt

===================================================================

A	source/blender/blenkernel/BKE_edithair.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/edithair.c
A	source/blender/blenkernel/intern/edithair_particles.c
M	source/blender/editors/hair/CMakeLists.txt
M	source/blender/editors/hair/hair_edit.c
M	source/blender/editors/hair/hair_intern.h
M	source/blender/editors/hair/hair_ops.c
D	source/blender/editors/hair/hair_particles.c

===================================================================

diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/blenkernel/BKE_edithair.h
similarity index 69%
copy from source/blender/editors/hair/hair_intern.h
copy to source/blender/blenkernel/BKE_edithair.h
index d430760..9e265e6 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/blenkernel/BKE_edithair.h
@@ -25,18 +25,15 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/editors/hair/hair_intern.h
- *  \ingroup edhair
- */
+#ifndef __BKE_EDITHAIR_H__
+#define __BKE_EDITHAIR_H__
 
-#ifndef __HAIR_INTERN_H__
-#define __HAIR_INTERN_H__
+/** \file blender/editors/hair/BKE_edithair.h
+ *  \ingroup bke
+ */
 
 #include "DNA_customdata_types.h"
 
-struct Object;
-struct ParticleSystem;
-
 /* hair curve */
 typedef struct HairEditCurve {
 	int start;          /* first vertex index */
@@ -58,22 +55,19 @@ typedef struct HairEditData {
 	CustomData vdata;   /* vertex data */
 } HairEditData;
 
-struct HairEditData *ED_hair_edit_create(void);
-struct HairEditData *ED_hair_edit_copy(struct HairEditData *hedit);
-void ED_hair_edit_free(struct HairEditData *hedit);
+struct HairEditData *BKE_edithair_create(void);
+struct HairEditData *BKE_edithair_copy(struct HairEditData *hedit);
+void BKE_edithair_free(struct HairEditData *hedit);
 
-void ED_hair_edit_clear(struct HairEditData *hedit);
-void ED_hair_edit_reserve(struct HairEditData *hedit, int alloc_curves, int alloc_verts, bool shrink);
+void BKE_edithair_clear(struct HairEditData *hedit);
+void BKE_edithair_reserve(struct HairEditData *hedit, int alloc_curves, int alloc_verts, bool shrink);
 
 /* === particle conversion === */
 
-void hair_edit_from_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
-void hair_edit_to_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
-
-/* === operators === */
-
-struct wmOperatorType;
+struct Object;
+struct ParticleSystem;
 
-void HAIR_OT_hair_edit_toggle(struct wmOperatorType *ot);
+void BKE_edithair_from_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
+void BKE_edithair_to_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
 
 #endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index eea6254..0ac7fe0 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -92,6 +92,8 @@ set(SRC
 	intern/displist.c
 	intern/dynamicpaint.c
 	intern/editderivedmesh.c
+	intern/edithair.c
+	intern/edithair_particles.c
 	intern/editmesh.c
 	intern/editmesh_bvh.c
 	intern/effect.c
@@ -212,6 +214,7 @@ set(SRC
 	BKE_depsgraph.h
 	BKE_displist.h
 	BKE_dynamicpaint.h
+	BKE_edithair.h
 	BKE_editmesh.h
 	BKE_editmesh_bvh.h
 	BKE_effect.h
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/blenkernel/intern/edithair.c
similarity index 88%
copy from source/blender/editors/hair/hair_edit.c
copy to source/blender/blenkernel/intern/edithair.c
index d7491c1..ec229b9 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/blenkernel/intern/edithair.c
@@ -25,23 +25,23 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/editors/hair/hair_edit.c
- *  \ingroup edhair
+/** \file blender/editors/hair/edithair.c
+ *  \ingroup bke
  */
 
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math.h"
 
-#include "hair_intern.h"
+#include "BKE_edithair.h"
 
-HairEditData *ED_hair_edit_create(void)
+HairEditData *BKE_edithair_create(void)
 {
 	HairEditData *hedit = MEM_callocN(sizeof(HairEditData), "hair edit data");
 	return hedit;
 }
 
-HairEditData *ED_hair_edit_copy(HairEditData *hedit)
+HairEditData *BKE_edithair_copy(HairEditData *hedit)
 {
 	HairEditData *thedit = MEM_dupallocN(hedit);
 	
@@ -56,7 +56,7 @@ HairEditData *ED_hair_edit_copy(HairEditData *hedit)
 	return thedit;
 }
 
-void ED_hair_edit_free(HairEditData *hedit)
+void BKE_edithair_free(HairEditData *hedit)
 {
 	if (hedit->curves) {
 		MEM_freeN(hedit->curves);
@@ -69,7 +69,7 @@ void ED_hair_edit_free(HairEditData *hedit)
 	MEM_freeN(hedit);
 }
 
-void ED_hair_edit_clear(HairEditData *hedit)
+void BKE_edithair_clear(HairEditData *hedit)
 {
 	if (hedit->curves) {
 		MEM_freeN(hedit->curves);
@@ -86,7 +86,7 @@ void ED_hair_edit_clear(HairEditData *hedit)
 	hedit->alloc_verts = 0;
 }
 
-void ED_hair_edit_reserve(HairEditData *hedit, int alloc_curves, int alloc_verts, bool shrink)
+void BKE_edithair_reserve(HairEditData *hedit, int alloc_curves, int alloc_verts, bool shrink)
 {
 	if (!hedit)
 		return;
diff --git a/source/blender/editors/hair/hair_particles.c b/source/blender/blenkernel/intern/edithair_particles.c
similarity index 93%
rename from source/blender/editors/hair/hair_particles.c
rename to source/blender/blenkernel/intern/edithair_particles.c
index ef4fe5a..215ba24 100644
--- a/source/blender/editors/hair/hair_particles.c
+++ b/source/blender/blenkernel/intern/edithair_particles.c
@@ -36,10 +36,9 @@
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
 
+#include "BKE_edithair.h"
 #include "BKE_particle.h"
 
-#include "hair_intern.h"
-
 /* ==== convert particle data to hair edit ==== */
 
 static int particle_totverts(ParticleSystem *psys)
@@ -76,7 +75,7 @@ static void copy_edit_curve(HairEditData *hedit, HairEditCurve *curve, ParticleD
 	}
 }
 
-void hair_edit_from_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleSystem *psys)
+void BKE_edithair_from_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleSystem *psys)
 {
 	int totverts = particle_totverts(psys);
 	
@@ -86,9 +85,9 @@ void hair_edit_from_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleS
 	int p;
 	int vert_start;
 	
-	ED_hair_edit_clear(hedit);
+	BKE_edithair_clear(hedit);
 	
-	ED_hair_edit_reserve(hedit, psys->totpart, totverts, true);
+	BKE_edithair_reserve(hedit, psys->totpart, totverts, true);
 	
 	/* TODO we should have a clean input stream API for hair edit data
 	 * to avoid implicit size and index calculations here and make the code
@@ -172,7 +171,7 @@ static void create_particle_data(ParticleSystem *psys, HairEditData *hedit)
 	psys->totpart = hedit->totcurves;
 }
 
-void hair_edit_to_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleSystem *psys)
+void BKE_edithair_to_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleSystem *psys)
 {
 	psys->flag |= PSYS_EDITED;
 	
diff --git a/source/blender/editors/hair/CMakeLists.txt b/source/blender/editors/hair/CMakeLists.txt
index eb57949..22a9d57 100644
--- a/source/blender/editors/hair/CMakeLists.txt
+++ b/source/blender/editors/hair/CMakeLists.txt
@@ -35,7 +35,6 @@ set(INC_SYS
 set(SRC
 	hair_edit.c
 	hair_ops.c
-	hair_particles.c
 
 	hair_intern.h
 )
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/editors/hair/hair_edit.c
index d7491c1..e92d647 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -29,85 +29,116 @@
  *  \ingroup edhair
  */
 
-#include "MEM_guardedalloc.h"
+#include <stdlib.h>
 
-#include "BLI_math.h"
+#include "BLI_utildefines.h"
 
-#include "hair_intern.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_scene_types.h"
 
-HairEditData *ED_hair_edit_create(void)
-{
-	HairEditData *hedit = MEM_callocN(sizeof(HairEditData), "hair edit data");
-	return hedit;
-}
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_edithair.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_object.h"
+#include "ED_physics.h"
+
+#include "hair_intern.h"
 
-HairEditData *ED_hair_edit_copy(HairEditData *hedit)
+static bool has_hair_data(Object *ob)
 {
-	HairEditData *thedit = MEM_dupallocN(hedit);
-	
-	if (hedit->curves) {
-		thedit->curves = MEM_dupallocN(hedit->curves);
-	}
+	ParticleSystem *psys;
 	
-	if (hedit->verts) {
-		thedit->verts = MEM_dupallocN(hedit->verts);
+	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+		if (psys->part->type == PART_HAIR)
+			return true;
 	}
 	
-	return thedit;
+	return false;
 }
 
-void ED_hair_edit_free(HairEditData *hedit)
+static bool init_hair_edit(Object *ob, HairEditData *hedit)
 {
-	if (hedit->curves) {
-		MEM_freeN(hedit->curves);
-	}
+	ParticleSystem *psys;
 	
-	if (hedit->verts) {
-		MEM_freeN(hedit->verts);
+	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+		if (psys->part->type == PART_HAIR) {
+			BKE_edithair_from_particles(hedit, ob, psys);
+			return true;
+		}
 	}
 	
-	MEM_freeN(hedit);
+	return false;
+}
+
+
+/* ==== edit mode toggle ==== */
+
+static int hair_edit_toggle_poll(bContext *C)
+{
+	Object *ob = CTX_data_active_object(C);
+
+	if (ob == NULL)
+		return false;
+	if (!ob->data || ((ID *)ob->data)->lib)
+		return false;
+	if (CTX_data_edit_object(C))
+		return false;
+
+	return has_hair_data(ob);
 }
 
-void ED_hair_edit_clear(HairEditData *hedit)
+static int hair_edit_toggle_exec(bContext *C, wmOperator *op)
 {
-	if (hedit->curves) {
-		MEM_freeN(hedit->curves);
-		hedit->curves = NULL;
+	Object *ob = CTX_data_active_object(C);
+	const int mode_flag = OB_MODE_HAIR_EDIT;
+	const bool is_mode_set = (ob->mode & mode_flag) != 0;
+
+	if (!is_mode_set) {
+		if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
+			return OPERATOR_CANCELLED;
+		}
 	}
-	hedit->totcurves = 0;
-	hedit->alloc_curves = 0;
-	
-	if (hedit->verts) {
-		MEM_freeN(hedit->verts);
-		hedit->verts = NULL;
+
+	if (!is_mode_set) {
+		HairEditData *hedit = BKE_edithair_create();
+		
+		ob->mode |= mode_flag;
+		init_hair_edit(ob, hedit);
+		
+//		toggle_particle_cursor(C, 1);
+		WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_HAIR, NULL);
 	}
-	hedit->totverts = 0;
-	hedit->alloc_verts = 0;
+	else {
+//		hair_edit_to_particles();
+		ob->mode &= ~mode_flag;
+		
+//		toggle_particle_cursor(C, 0);
+		WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_HAIR, NULL);
+	}
+
+	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+
+	return OPERATOR_FINISHED;
 }
 
-void ED_hair_edit_reserve(HairEditData *hedit, int alloc_curves, int alloc_verts, bool shrink)
+void HAIR_OT_hair_edit_toggle(wmOperatorType *ot)
 {
-	if (!hedit)
-		ret

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list