[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25523] trunk/blender/source/blender/ editors/uvedit/uvedit_ops.c: select linked and select linked pick working again (wth shift for extend)

Campbell Barton ideasman42 at gmail.com
Tue Dec 22 18:18:33 CET 2009


Revision: 25523
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25523
Author:   campbellbarton
Date:     2009-12-22 18:18:33 +0100 (Tue, 22 Dec 2009)

Log Message:
-----------
select linked and select linked pick working again (wth shift for extend)

Modified Paths:
--------------
    trunk/blender/source/blender/editors/uvedit/uvedit_ops.c

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_ops.c	2009-12-22 16:11:11 UTC (rev 25522)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_ops.c	2009-12-22 17:18:33 UTC (rev 25523)
@@ -835,15 +835,16 @@
 	MTFace *tf;
 	UvVertMap *vmap;
 	UvMapVert *vlist, *iterv, *startv;
-	int a, i, nverts, j, stacksize= 0, *stack;
+	int a, i, nverts, stacksize= 0, *stack;
 	char *flag;
 
-	vmap= EM_make_uv_vert_map(em, 1, 1, limit);
+	EM_init_index_arrays(em, 0, 0, 1); /* we can use this too */
+	vmap= EM_make_uv_vert_map(em, 1, 0, limit);
 	if(vmap == NULL)
 		return;
 
-	stack= MEM_mallocN(sizeof(*stack)* BLI_countlist(&em->faces), "UvLinkStack");
-	flag= MEM_callocN(sizeof(*flag)*BLI_countlist(&em->faces), "UvLinkFlag");
+	stack= MEM_mallocN(sizeof(*stack) * em->totface, "UvLinkStack");
+	flag= MEM_callocN(sizeof(*flag) * em->totface, "UvLinkFlag");
 
 	if(!hit) {
 		for(a=0, efa= em->faces.first; efa; efa= efa->next, a++) {
@@ -872,11 +873,9 @@
 	while(stacksize > 0) {
 		stacksize--;
 		a= stack[stacksize];
-		
-		for(j=0, efa= em->faces.first; efa; efa= efa->next, j++)
-			if(j==a)
-				break;
 
+		efa = EM_get_face_for_index(a);
+
 		nverts= efa->v4? 4: 3;
 
 		for(i=0; i<nverts; i++) {
@@ -897,14 +896,14 @@
 					break;
 				else if(!flag[iterv->f]) {
 					flag[iterv->f]= 1;
-					stack[stacksize]= iterv->f;;
+					stack[stacksize]= iterv->f;
 					stacksize++;
 				}
 			}
 		}
 	}
 
-	if(!extend && hit) {
+	if(!extend) {
 		for(a=0, efa= em->faces.first; efa; efa= efa->next, a++) {
 			tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
 			if(flag[a])
@@ -913,7 +912,7 @@
 				tf->flag &= ~(TF_SEL1|TF_SEL2|TF_SEL3|TF_SEL4);
 		}
 	}
-	else if(extend && hit) {
+	else {
 		for(a=0, efa= em->faces.first; efa; efa= efa->next, a++) {
 			if(flag[a]) {
 				tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
@@ -947,6 +946,7 @@
 	MEM_freeN(stack);
 	MEM_freeN(flag);
 	EM_free_uv_vert_map(vmap);
+	EM_free_index_arrays();
 }
 
 /* ******************** align operator **************** */
@@ -1814,7 +1814,7 @@
 
 /* ******************** linked select operator **************** */
 
-static int select_linked_exec(bContext *C, wmOperator *op)
+static select_linked_internal(bContext *C, wmOperator *op, wmEvent *event, int pick)
 {
 	SpaceImage *sima= CTX_wm_space_image(C);
 	Scene *scene= CTX_data_scene(C);
@@ -1825,6 +1825,8 @@
 	float limit[2];
 	int extend;
 
+	NearestHit hit, *hit_p= NULL;
+
 	if(ts->uv_flag & UV_SYNC_SELECTION) {
 		BKE_report(op->reports, RPT_ERROR, "Can't select linked when sync selection is enabled.");
 		BKE_mesh_end_editmesh(obedit->data, em);
@@ -1833,8 +1835,32 @@
 
 	extend= RNA_boolean_get(op->ptr, "extend");
 	uvedit_pixel_to_float(sima, limit, 0.05f);
-	select_linked(scene, ima, em, limit, NULL, extend);
 
+	if(pick) {
+		float co[2];
+
+		if(event) {
+			/* invoke */
+			ARegion *ar= CTX_wm_region(C);
+			int x, y;
+
+			x= event->x - ar->winrct.xmin;
+			y= event->y - ar->winrct.ymin;
+
+			UI_view2d_region_to_view(&ar->v2d, x, y, &co[0], &co[1]);
+			RNA_float_set_array(op->ptr, "location", co);
+		}
+		else {
+			/* exec */
+			RNA_float_get_array(op->ptr, "location", co);
+		}
+
+		find_nearest_uv_vert(scene, ima, em, co, NULL, &hit);
+		hit_p= &hit;
+	}
+
+	select_linked(scene, ima, em, limit, hit_p, extend);
+
 	DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
 
@@ -1842,6 +1868,11 @@
 	return OPERATOR_FINISHED;
 }
 
+static int select_linked_exec(bContext *C, wmOperator *op)
+{
+	return select_linked_internal(C, op, NULL, 0);
+}
+
 void UV_OT_select_linked(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -1859,6 +1890,37 @@
 		"Extend", "Extend selection rather than clearing the existing selection.");
 }
 
+static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	return select_linked_internal(C, op, event, 1);
+}
+
+static int select_linked_pick_exec(bContext *C, wmOperator *op)
+{
+	return select_linked_internal(C, op, NULL, 1);
+}
+
+void UV_OT_select_linked_pick(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Select Linked Pick";
+	ot->description= "Select all UV vertices linked under the mouse.";
+	ot->idname= "UV_OT_select_linked_pick";
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* api callbacks */
+	ot->invoke= select_linked_pick_invoke;
+	ot->exec= select_linked_pick_exec;
+	ot->poll= ED_operator_uvedit;
+
+	/* properties */
+	RNA_def_boolean(ot->srna, "extend", 0,
+		"Extend", "Extend selection rather than clearing the existing selection.");
+
+	RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
+		"Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds.", -100.0f, 100.0f);
+}
+
 /* ******************** unlink selection operator **************** */
 
 static int unlink_selection_exec(bContext *C, wmOperator *op)
@@ -3101,6 +3163,7 @@
 	WM_operatortype_append(UV_OT_select);
 	WM_operatortype_append(UV_OT_select_loop);
 	WM_operatortype_append(UV_OT_select_linked);
+	WM_operatortype_append(UV_OT_select_linked_pick);
 	WM_operatortype_append(UV_OT_unlink_selection);
 	WM_operatortype_append(UV_OT_select_pinned);
 	WM_operatortype_append(UV_OT_select_border);
@@ -3151,6 +3214,10 @@
 
 	/* selection manipulation */
 	WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
+	WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+	RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "extend", TRUE);
+	RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE);
+
 	WM_keymap_add_item(keymap, "UV_OT_unlink_selection", LKEY, KM_PRESS, KM_ALT, 0);
 	WM_keymap_add_item(keymap, "UV_OT_select_all", AKEY, KM_PRESS, 0, 0);
 	WM_keymap_add_item(keymap, "UV_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);





More information about the Bf-blender-cvs mailing list