Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Fox <mfoxdogg@gmail.com>2009-09-03 14:42:53 +0400
committerMichael Fox <mfoxdogg@gmail.com>2009-09-03 14:42:53 +0400
commit78425fb6577e7d1a27e331daacf48c7c53422efd (patch)
treeef325d28e1bdf155a2de82a4e7d182897f78a8b0 /source/blender/editors/object/object_edit.c
parent40c89b5c6ee639539fdc74e669d92152e9e9fc06 (diff)
2.5
***** first commit in a long time, and its great to be back! commited Select Mirror operator for objects eg. L.sword->R.sword added to 3dview select menu aswel the hotkey is shift-ctrl-m (hope its not taken)
Diffstat (limited to 'source/blender/editors/object/object_edit.c')
-rw-r--r--source/blender/editors/object/object_edit.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 04187c93196..33ecb144f13 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -28,6 +28,8 @@
#include <string.h>
#include <math.h>
#include <time.h>
+#include <float.h>
+#include <ctype.h>
#include "MEM_guardedalloc.h"
@@ -2189,6 +2191,165 @@ void OBJECT_OT_select_all_toggle(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+/* ****** select mirror *******/
+/* finds the best possible flipped name. For renaming; check for unique names afterwards */
+/* if strip_number: removes number extensions */
+void object_flip_name (char *name)
+{
+ int len;
+ char prefix[128]={""}; /* The part before the facing */
+ char suffix[128]={""}; /* The part after the facing */
+ char replace[128]={""}; /* The replacement string */
+ char number[128]={""}; /* The number extension string */
+ char *index=NULL;
+
+ len= strlen(name);
+ if(len<3) return; // we don't do names like .R or .L
+
+ /* We first check the case with a .### extension, let's find the last period */
+ if(isdigit(name[len-1])) {
+ index= strrchr(name, '.'); // last occurrance
+ if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever!
+ strcpy(number, index);
+ *index= 0;
+ len= strlen(name);
+ }
+ }
+
+ strcpy (prefix, name);
+
+#define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_')
+
+ /* first case; separator . - _ with extensions r R l L */
+ if( IS_SEPARATOR(name[len-2]) ) {
+ switch(name[len-1]) {
+ case 'l':
+ prefix[len-1]= 0;
+ strcpy(replace, "r");
+ break;
+ case 'r':
+ prefix[len-1]= 0;
+ strcpy(replace, "l");
+ break;
+ case 'L':
+ prefix[len-1]= 0;
+ strcpy(replace, "R");
+ break;
+ case 'R':
+ prefix[len-1]= 0;
+ strcpy(replace, "L");
+ break;
+ }
+ }
+ /* case; beginning with r R l L , with separator after it */
+ else if( IS_SEPARATOR(name[1]) ) {
+ switch(name[0]) {
+ case 'l':
+ strcpy(replace, "r");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ case 'r':
+ strcpy(replace, "l");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ case 'L':
+ strcpy(replace, "R");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ case 'R':
+ strcpy(replace, "L");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ }
+ }
+ else if(len > 5) {
+ /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
+ index = BLI_strcasestr(prefix, "right");
+ if (index==prefix || index==prefix+len-5) {
+ if(index[0]=='r')
+ strcpy (replace, "left");
+ else {
+ if(index[1]=='I')
+ strcpy (replace, "LEFT");
+ else
+ strcpy (replace, "Left");
+ }
+ *index= 0;
+ strcpy (suffix, index+5);
+ }
+ else {
+ index = BLI_strcasestr(prefix, "left");
+ if (index==prefix || index==prefix+len-4) {
+ if(index[0]=='l')
+ strcpy (replace, "right");
+ else {
+ if(index[1]=='E')
+ strcpy (replace, "RIGHT");
+ else
+ strcpy (replace, "Right");
+ }
+ *index= 0;
+ strcpy (suffix, index+4);
+ }
+ }
+ }
+
+#undef IS_SEPARATOR
+
+ sprintf (name, "%s%s%s%s", prefix, replace, suffix, number);
+}
+
+static int object_select_mirror_exec(bContext *C, wmOperator *op)
+{
+ char tmpname[32];
+ short seltype;
+
+ seltype = RNA_enum_get(op->ptr, "seltype");
+
+ CTX_DATA_BEGIN(C, Base*, primbase, selected_bases) {
+
+ strcpy(tmpname, primbase->object->id.name+2);
+ object_flip_name(tmpname);
+
+ CTX_DATA_BEGIN(C, Base*, secbase, visible_bases) {
+ if(!strcmp(secbase->object->id.name+2, tmpname)) {
+ ED_base_object_select(secbase, BA_SELECT);
+ }
+ }
+ CTX_DATA_END;
+
+ if (seltype == 0) ED_base_object_select(primbase, BA_DESELECT);
+
+ }
+ CTX_DATA_END;
+
+ /* undo? */
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_select_mirror(wmOperatorType *ot)
+{
+
+ /* identifiers */
+ ot->name= "Select Mirror";
+ ot->description = "Select the Mirror objects of the selected object eg. L.sword -> R.sword";
+ ot->idname= "OBJECT_OT_select_mirror";
+
+ /* api callbacks */
+ ot->exec= object_select_mirror_exec;
+ ot->poll= ED_operator_scene_editable;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
+}
/* ****** random selection *******/
static int object_select_random_exec(bContext *C, wmOperator *op)