Blender V2.61 - r43446

transform_ops.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): none yet.
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #include "MEM_guardedalloc.h"
00029 
00030 #include "DNA_scene_types.h"
00031 
00032 #include "RNA_access.h"
00033 #include "RNA_define.h"
00034 #include "RNA_enum_types.h"
00035 
00036 #include "BLI_math.h"
00037 #include "BLI_utildefines.h"
00038 
00039 #include "BKE_context.h"
00040 #include "BKE_global.h"
00041 #include "BKE_armature.h"
00042 
00043 #include "WM_api.h"
00044 #include "WM_types.h"
00045 
00046 #include "UI_interface.h"
00047 #include "UI_resources.h"
00048 
00049 #include "ED_screen.h"
00050 
00051 #include "transform.h"
00052 
00053 typedef struct TransformModeItem
00054 {
00055     char *idname;
00056     int     mode;
00057     void (*opfunc)(wmOperatorType*);
00058 } TransformModeItem;
00059 
00060 static float VecOne[3] = {1, 1, 1};
00061 
00062 static char OP_TRANSLATION[] = "TRANSFORM_OT_translate";
00063 static char OP_ROTATION[] = "TRANSFORM_OT_rotate";
00064 static char OP_TOSPHERE[] = "TRANSFORM_OT_tosphere";
00065 static char OP_RESIZE[] = "TRANSFORM_OT_resize";
00066 static char OP_SHEAR[] = "TRANSFORM_OT_shear";
00067 static char OP_WARP[] = "TRANSFORM_OT_warp";
00068 static char OP_SHRINK_FATTEN[] = "TRANSFORM_OT_shrink_fatten";
00069 static char OP_PUSH_PULL[] = "TRANSFORM_OT_push_pull";
00070 static char OP_TILT[] = "TRANSFORM_OT_tilt";
00071 static char OP_TRACKBALL[] = "TRANSFORM_OT_trackball";
00072 static char OP_MIRROR[] = "TRANSFORM_OT_mirror";
00073 static char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide";
00074 static char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease";
00075 static char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide";
00076 
00077 void TRANSFORM_OT_translate(struct wmOperatorType *ot);
00078 void TRANSFORM_OT_rotate(struct wmOperatorType *ot);
00079 void TRANSFORM_OT_tosphere(struct wmOperatorType *ot);
00080 void TRANSFORM_OT_resize(struct wmOperatorType *ot);
00081 void TRANSFORM_OT_shear(struct wmOperatorType *ot);
00082 void TRANSFORM_OT_warp(struct wmOperatorType *ot);
00083 void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot);
00084 void TRANSFORM_OT_push_pull(struct wmOperatorType *ot);
00085 void TRANSFORM_OT_tilt(struct wmOperatorType *ot);
00086 void TRANSFORM_OT_trackball(struct wmOperatorType *ot);
00087 void TRANSFORM_OT_mirror(struct wmOperatorType *ot);
00088 void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot);
00089 void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot);
00090 void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot);
00091 
00092 static TransformModeItem transform_modes[] =
00093 {
00094     {OP_TRANSLATION, TFM_TRANSLATION, TRANSFORM_OT_translate},
00095     {OP_ROTATION, TFM_ROTATION, TRANSFORM_OT_rotate},
00096     {OP_TOSPHERE, TFM_TOSPHERE, TRANSFORM_OT_tosphere},
00097     {OP_RESIZE, TFM_RESIZE, TRANSFORM_OT_resize},
00098     {OP_SHEAR, TFM_SHEAR, TRANSFORM_OT_shear},
00099     {OP_WARP, TFM_WARP, TRANSFORM_OT_warp},
00100     {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN, TRANSFORM_OT_shrink_fatten},
00101     {OP_PUSH_PULL, TFM_PUSHPULL, TRANSFORM_OT_push_pull},
00102     {OP_TILT, TFM_TILT, TRANSFORM_OT_tilt},
00103     {OP_TRACKBALL, TFM_TRACKBALL, TRANSFORM_OT_trackball},
00104     {OP_MIRROR, TFM_MIRROR, TRANSFORM_OT_mirror},
00105     {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide},
00106     {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease},
00107     {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide},
00108     {NULL, 0}
00109 };
00110 
00111 EnumPropertyItem transform_mode_types[] =
00112 {
00113     {TFM_INIT, "INIT", 0, "Init", ""},
00114     {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
00115     {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
00116     {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
00117     {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
00118     {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
00119     {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
00120     {TFM_WARP, "WARP", 0, "Warp", ""},
00121     {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
00122     {TFM_TILT, "TILT", 0, "Tilt", ""},
00123     {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
00124     {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
00125     {TFM_CREASE, "CREASE", 0, "Crease", ""},
00126     {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
00127     {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
00128     {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
00129     {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
00130     {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
00131     {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
00132     {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
00133     {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
00134     {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
00135     {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
00136     {TFM_BEVEL, "BEVEL", 0, "Bevel", ""},
00137     {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
00138     {TFM_ALIGN, "ALIGN", 0, "Align", ""},
00139     {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
00140     {TFM_SEQ_SLIDE, "SEQSLIDE", 0, "Sequence Slide", ""},
00141     {0, NULL, 0, NULL, NULL}
00142 };
00143 
00144 static int snap_type_exec(bContext *C, wmOperator *op)
00145 {
00146     ToolSettings *ts= CTX_data_tool_settings(C);
00147 
00148     ts->snap_mode = RNA_enum_get(op->ptr,"type");
00149 
00150     WM_event_add_notifier(C, NC_SCENE|ND_TOOLSETTINGS, NULL); /* header redraw */
00151 
00152     return OPERATOR_FINISHED;
00153 }
00154 
00155 static void TRANSFORM_OT_snap_type(wmOperatorType *ot)
00156 {
00157     /* identifiers */
00158     ot->name= "Snap Type";
00159     ot->description= "Set the snap element type";
00160     ot->idname= "TRANSFORM_OT_snap_type";
00161 
00162     /* api callbacks */
00163     ot->invoke= WM_menu_invoke;
00164     ot->exec= snap_type_exec;
00165 
00166     ot->poll= ED_operator_areaactive;
00167 
00168     /* flags */
00169     ot->flag= OPTYPE_UNDO;
00170 
00171     /* props */
00172     ot->prop= RNA_def_enum(ot->srna, "type", snap_element_items, 0, "Type", "Set the snap element type");
00173 
00174 }
00175 
00176 static int select_orientation_exec(bContext *C, wmOperator *op)
00177 {
00178     int orientation = RNA_enum_get(op->ptr, "orientation");
00179 
00180     BIF_selectTransformOrientationValue(C, orientation);
00181     
00182     WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
00183 
00184     return OPERATOR_FINISHED;
00185 }
00186 
00187 static int select_orientation_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event))
00188 {
00189     uiPopupMenu *pup;
00190     uiLayout *layout;
00191 
00192     pup= uiPupMenuBegin(C, "Orientation", ICON_NONE);
00193     layout= uiPupMenuLayout(pup);
00194     uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
00195     uiPupMenuEnd(C, pup);
00196 
00197     return OPERATOR_CANCELLED;
00198 }
00199 
00200 static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
00201 {
00202     PropertyRNA *prop;
00203 
00204     /* identifiers */
00205     ot->name   = "Select Orientation";
00206     ot->description= "Select transformation orientation";
00207     ot->idname = "TRANSFORM_OT_select_orientation";
00208     ot->flag   = OPTYPE_UNDO;
00209 
00210     /* api callbacks */
00211     ot->invoke = select_orientation_invoke;
00212     ot->exec   = select_orientation_exec;
00213     ot->poll   = ED_operator_view3d_active;
00214 
00215     prop= RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
00216     RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
00217     RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
00218 }
00219 
00220 
00221 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
00222 {
00223     View3D *v3d = CTX_wm_view3d(C);
00224     int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
00225 
00226     BIF_removeTransformOrientationIndex(C, selected_index);
00227     
00228     WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
00229     WM_event_add_notifier(C, NC_SCENE|NA_EDITED, CTX_data_scene(C));
00230 
00231     return OPERATOR_FINISHED;
00232 }
00233 
00234 static int delete_orientation_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00235 {
00236     return delete_orientation_exec(C, op);
00237 }
00238 
00239 static int delete_orientation_poll(bContext *C)
00240 {
00241     int selected_index = -1;
00242     View3D *v3d = CTX_wm_view3d(C);
00243     
00244     if (ED_operator_areaactive(C) == 0)
00245         return 0;
00246     
00247     
00248     if(v3d) {
00249         selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
00250     }
00251     
00252     return selected_index >= 0;
00253 }
00254 
00255 static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
00256 {
00257     /* identifiers */
00258     ot->name   = "Delete Orientation";
00259     ot->description= "Delete transformation orientation";
00260     ot->idname = "TRANSFORM_OT_delete_orientation";
00261     ot->flag   = OPTYPE_UNDO;
00262 
00263     /* api callbacks */
00264     ot->invoke = delete_orientation_invoke;
00265     ot->exec   = delete_orientation_exec;
00266     ot->poll   = delete_orientation_poll;
00267 }
00268 
00269 static int create_orientation_exec(bContext *C, wmOperator *op)
00270 {
00271     char name[MAX_NAME];
00272     int use = RNA_boolean_get(op->ptr, "use");
00273     int overwrite = RNA_boolean_get(op->ptr, "overwrite");
00274     
00275     RNA_string_get(op->ptr, "name", name);
00276 
00277     BIF_createTransformOrientation(C, op->reports, name, use, overwrite);
00278 
00279     WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
00280     WM_event_add_notifier(C, NC_SCENE|NA_EDITED, CTX_data_scene(C));
00281     
00282     return OPERATOR_FINISHED;
00283 }
00284 
00285 static int create_orientation_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00286 {
00287     return create_orientation_exec(C, op);
00288 }
00289 
00290 static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
00291 {
00292     /* identifiers */
00293     ot->name   = "Create Orientation";
00294     ot->description= "Create transformation orientation from selection";
00295     ot->idname = "TRANSFORM_OT_create_orientation";
00296     ot->flag   = OPTYPE_REGISTER|OPTYPE_UNDO;
00297 
00298     /* api callbacks */
00299     ot->invoke = create_orientation_invoke;
00300     ot->exec   = create_orientation_exec;
00301     ot->poll   = ED_operator_areaactive;
00302     ot->flag   = OPTYPE_REGISTER|OPTYPE_UNDO;
00303 
00304     RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Text to insert at the cursor position");
00305     RNA_def_boolean(ot->srna, "use", 0, "Use after creation", "Select orientation after its creation");
00306     RNA_def_boolean(ot->srna, "overwrite", 0, "Overwrite previous", "Overwrite previously created orientation with same name");
00307 }
00308 
00309 static void transformops_exit(bContext *C, wmOperator *op)
00310 {
00311     saveTransform(C, op->customdata, op);
00312     MEM_freeN(op->customdata);
00313     op->customdata = NULL;
00314     G.moving = 0;
00315 }
00316 
00317 static int transformops_data(bContext *C, wmOperator *op, wmEvent *event)
00318 {
00319     int retval = 1;
00320     if (op->customdata == NULL)
00321     {
00322         TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
00323         TransformModeItem *tmode;
00324         int mode = -1;
00325 
00326         for (tmode = transform_modes; tmode->idname; tmode++)
00327         {
00328             if (op->type->idname == tmode->idname)
00329             {
00330                 mode = tmode->mode;
00331                 break;
00332             }
00333         }
00334 
00335         if (mode == -1)
00336         {
00337             mode = RNA_enum_get(op->ptr, "mode");
00338         }
00339 
00340         retval = initTransform(C, t, op, event, mode);
00341         G.moving = 1;
00342 
00343         /* store data */
00344         if(retval) {
00345             op->customdata = t;
00346         }
00347         else {
00348             MEM_freeN(t);
00349         }
00350     }
00351 
00352     return retval; /* return 0 on error */
00353 }
00354 
00355 static int transform_modal(bContext *C, wmOperator *op, wmEvent *event)
00356 {
00357     int exit_code;
00358 
00359     TransInfo *t = op->customdata;
00360 
00361 #if 0
00362     // stable 2D mouse coords map to different 3D coords while the 3D mouse is active
00363     // in other words, 2D deltas are no longer good enough!
00364     // disable until individual 'transformers' behave better
00365 
00366     if (event->type == NDOF_MOTION)
00367         return OPERATOR_PASS_THROUGH;
00368 #endif
00369 
00370     /* XXX insert keys are called here, and require context */
00371     t->context= C;
00372     exit_code = transformEvent(t, event);
00373     t->context= NULL;
00374 
00375     transformApply(C, t);
00376 
00377     exit_code |= transformEnd(C, t);
00378 
00379     if ((exit_code & OPERATOR_RUNNING_MODAL) == 0)
00380     {
00381         transformops_exit(C, op);
00382         exit_code &= ~OPERATOR_PASS_THROUGH; /* preventively remove passthrough */
00383     }
00384 
00385     return exit_code;
00386 }
00387 
00388 static int transform_cancel(bContext *C, wmOperator *op)
00389 {
00390     TransInfo *t = op->customdata;
00391 
00392     t->state = TRANS_CANCEL;
00393     transformEnd(C, t);
00394     transformops_exit(C, op);
00395 
00396     return OPERATOR_CANCELLED;
00397 }
00398 
00399 static int transform_exec(bContext *C, wmOperator *op)
00400 {
00401     TransInfo *t;
00402 
00403     if (!transformops_data(C, op, NULL))
00404     {
00405         G.moving = 0;
00406         return OPERATOR_CANCELLED;
00407     }
00408 
00409     t = op->customdata;
00410 
00411     t->options |= CTX_AUTOCONFIRM;
00412 
00413     transformApply(C, t);
00414 
00415     transformEnd(C, t);
00416 
00417     transformops_exit(C, op);
00418     
00419     WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
00420 
00421     return OPERATOR_FINISHED;
00422 }
00423 
00424 static int transform_invoke(bContext *C, wmOperator *op, wmEvent *event)
00425 {
00426     if (!transformops_data(C, op, event))
00427     {
00428         G.moving = 0;
00429         return OPERATOR_CANCELLED;
00430     }
00431 
00432     if(RNA_struct_property_is_set(op->ptr, "value")) {
00433         return transform_exec(C, op);
00434     }
00435     else {
00436         /* add temp handler */
00437         WM_event_add_modal_handler(C, op);
00438 
00439         op->flag |= OP_GRAB_POINTER; // XXX maybe we want this with the manipulator only?
00440         return OPERATOR_RUNNING_MODAL;
00441     }
00442 }
00443 
00444 void Transform_Properties(struct wmOperatorType *ot, int flags)
00445 {
00446     PropertyRNA *prop;
00447 
00448     if (flags & P_AXIS)
00449     {
00450         prop= RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
00451         RNA_def_property_array(prop, 3);
00452         /* Make this not hidden when there's a nice axis selection widget */
00453         RNA_def_property_flag(prop, PROP_HIDDEN);
00454         RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
00455 
00456     }
00457 
00458     if (flags & P_CONSTRAINT)
00459     {
00460         RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
00461         prop= RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
00462         RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
00463         RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
00464 
00465         
00466     }
00467 
00468     if (flags & P_MIRROR)
00469     {
00470         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
00471     }
00472 
00473 
00474     if (flags & P_PROPORTIONAL)
00475     {
00476         RNA_def_enum(ot->srna, "proportional", proportional_editing_items, 0, "Proportional Editing", "");
00477         RNA_def_enum(ot->srna, "proportional_edit_falloff", proportional_falloff_items, 0, "Proportional Editing Falloff", "Falloff type for proportional editing mode");
00478         RNA_def_float(ot->srna, "proportional_size", 1, 0.00001f, FLT_MAX, "Proportional Size", "", 0.001, 100);
00479     }
00480 
00481     if (flags & P_SNAP)
00482     {
00483         prop= RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
00484         RNA_def_property_flag(prop, PROP_HIDDEN);
00485 
00486         if (flags & P_GEO_SNAP) {
00487             prop= RNA_def_enum(ot->srna, "snap_target", snap_target_items, 0, "Target", "");
00488             RNA_def_property_flag(prop, PROP_HIDDEN);
00489             prop= RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
00490             RNA_def_property_flag(prop, PROP_HIDDEN);
00491             
00492             if (flags & P_ALIGN_SNAP) {
00493                 prop= RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
00494                 RNA_def_property_flag(prop, PROP_HIDDEN);
00495                 prop= RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
00496                 RNA_def_property_flag(prop, PROP_HIDDEN);
00497             }
00498         }
00499     }
00500     
00501     if (flags & P_OPTIONS)
00502     {
00503         RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Object data texture space", "");
00504     }
00505 
00506     if (flags & P_CORRECT_UV)
00507     {
00508         RNA_def_boolean(ot->srna, "correct_uv", 0, "Correct UV coords when transforming", "");
00509     }
00510 
00511     // Add confirm method all the time. At the end because it's not really that important and should be hidden only in log, not in keymap edit
00512     /*prop =*/ RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
00513     //RNA_def_property_flag(prop, PROP_HIDDEN);
00514 }
00515 
00516 void TRANSFORM_OT_translate(struct wmOperatorType *ot)
00517 {
00518     /* identifiers */
00519     ot->name   = "Translate";
00520     ot->description= "Translate selected items";
00521     ot->idname = OP_TRANSLATION;
00522     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00523 
00524     /* api callbacks */
00525     ot->invoke = transform_invoke;
00526     ot->exec   = transform_exec;
00527     ot->modal  = transform_modal;
00528     ot->cancel  = transform_cancel;
00529     ot->poll   = ED_operator_screenactive;
00530 
00531     RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
00532 
00533     Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_ALIGN_SNAP|P_OPTIONS);
00534 }
00535 
00536 void TRANSFORM_OT_resize(struct wmOperatorType *ot)
00537 {
00538     /* identifiers */
00539     ot->name   = "Resize";
00540     ot->description= "Resize selected items"; 
00541     ot->idname = OP_RESIZE;
00542     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00543 
00544     /* api callbacks */
00545     ot->invoke = transform_invoke;
00546     ot->exec   = transform_exec;
00547     ot->modal  = transform_modal;
00548     ot->cancel  = transform_cancel;
00549     ot->poll   = ED_operator_screenactive;
00550 
00551     RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
00552 
00553     Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_GEO_SNAP|P_OPTIONS);
00554 }
00555 
00556 
00557 void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
00558 {
00559     /* identifiers */
00560     ot->name   = "Trackball";
00561     ot->description= "Trackball style rotation of selected items";
00562     ot->idname = OP_TRACKBALL;
00563     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00564 
00565     /* api callbacks */
00566     ot->invoke = transform_invoke;
00567     ot->exec   = transform_exec;
00568     ot->modal  = transform_modal;
00569     ot->cancel  = transform_cancel;
00570     ot->poll   = ED_operator_screenactive;
00571 
00572     RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "angle", "", -FLT_MAX, FLT_MAX);
00573 
00574     Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
00575 }
00576 
00577 void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
00578 {
00579     /* identifiers */
00580     ot->name   = "Rotate";
00581     ot->description= "Rotate selected items";
00582     ot->idname = OP_ROTATION;
00583     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00584 
00585     /* api callbacks */
00586     ot->invoke = transform_invoke;
00587     ot->exec   = transform_exec;
00588     ot->modal  = transform_modal;
00589     ot->cancel  = transform_cancel;
00590     ot->poll   = ED_operator_screenactive;
00591 
00592     RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
00593 
00594     Transform_Properties(ot, P_AXIS|P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_GEO_SNAP);
00595 }
00596 
00597 void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
00598 {
00599     /* identifiers */
00600     ot->name   = "Tilt";
00601     /*optionals - 
00602         "Tilt selected vertices"
00603         "Specify an extra axis rotation for selected vertices of 3d curve" */
00604     ot->description= "Tilt selected control vertices of 3d curve"; 
00605     ot->idname = OP_TILT;
00606     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00607 
00608     /* api callbacks */
00609     ot->invoke = transform_invoke;
00610     ot->exec   = transform_exec;
00611     ot->modal  = transform_modal;
00612     ot->cancel  = transform_cancel;
00613     ot->poll   = ED_operator_editcurve_3d;
00614 
00615     RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
00616 
00617     Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_SNAP);
00618 }
00619 
00620 void TRANSFORM_OT_warp(struct wmOperatorType *ot)
00621 {
00622     /* identifiers */
00623     ot->name   = "Warp";
00624     ot->description= "Warp selected items around the cursor";
00625     ot->idname = OP_WARP;
00626     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00627 
00628     /* api callbacks */
00629     ot->invoke = transform_invoke;
00630     ot->exec   = transform_exec;
00631     ot->modal  = transform_modal;
00632     ot->cancel  = transform_cancel;
00633     ot->poll   = ED_operator_screenactive;
00634 
00635     RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
00636 
00637     Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
00638     // XXX Warp axis?
00639 }
00640 
00641 void TRANSFORM_OT_shear(struct wmOperatorType *ot)
00642 {
00643     /* identifiers */
00644     ot->name   = "Shear";
00645     ot->description= "Shear selected items along the horizontal screen axis";
00646     ot->idname = OP_SHEAR;
00647     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00648 
00649     /* api callbacks */
00650     ot->invoke = transform_invoke;
00651     ot->exec   = transform_exec;
00652     ot->modal  = transform_modal;
00653     ot->cancel  = transform_cancel;
00654     ot->poll   = ED_operator_screenactive;
00655 
00656     RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
00657 
00658     Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
00659     // XXX Shear axis?
00660 }
00661 
00662 void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
00663 {
00664     /* identifiers */
00665     ot->name   = "Push/Pull";
00666     ot->description= "Push/Pull selected items";
00667     ot->idname = OP_PUSH_PULL;
00668     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00669 
00670     /* api callbacks */
00671     ot->invoke = transform_invoke;
00672     ot->exec   = transform_exec;
00673     ot->modal  = transform_modal;
00674     ot->cancel  = transform_cancel;
00675     ot->poll   = ED_operator_screenactive;
00676 
00677     RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
00678 
00679     Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
00680 }
00681 
00682 void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
00683 {
00684     /* identifiers */
00685     ot->name   = "Shrink/Fatten";
00686     ot->description= "Shrink/fatten selected vertices along normals";
00687     ot->idname = OP_SHRINK_FATTEN;
00688     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00689 
00690     /* api callbacks */
00691     ot->invoke = transform_invoke;
00692     ot->exec   = transform_exec;
00693     ot->modal  = transform_modal;
00694     ot->cancel  = transform_cancel;
00695     ot->poll   = ED_operator_editmesh;
00696 
00697     RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
00698 
00699     Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
00700 }
00701 
00702 void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
00703 {
00704     /* identifiers */
00705     ot->name   = "To Sphere";
00706     //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" 
00707     ot->description= "Move selected vertices outward in a spherical shape around mesh center";
00708     ot->idname = OP_TOSPHERE;
00709     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00710 
00711     /* api callbacks */
00712     ot->invoke = transform_invoke;
00713     ot->exec   = transform_exec;
00714     ot->modal  = transform_modal;
00715     ot->cancel  = transform_cancel;
00716     ot->poll   = ED_operator_screenactive;
00717 
00718     RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
00719 
00720     Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
00721 }
00722 
00723 void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
00724 {
00725     /* identifiers */
00726     ot->name   = "Mirror";
00727     ot->description= "Mirror selected vertices around one or more axes";
00728     ot->idname = OP_MIRROR;
00729     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00730 
00731     /* api callbacks */
00732     ot->invoke = transform_invoke;
00733     ot->exec   = transform_exec;
00734     ot->modal  = transform_modal;
00735     ot->cancel  = transform_cancel;
00736     ot->poll   = ED_operator_screenactive;
00737 
00738     Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL);
00739 }
00740 
00741 void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
00742 {
00743     /* identifiers */
00744     ot->name   = "Edge Slide";
00745     ot->description= "Slide an edge loop along a mesh"; 
00746     ot->idname = OP_EDGE_SLIDE;
00747     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00748 
00749     /* api callbacks */
00750     ot->invoke = transform_invoke;
00751     ot->exec   = transform_exec;
00752     ot->modal  = transform_modal;
00753     ot->cancel  = transform_cancel;
00754     ot->poll   = ED_operator_editmesh;
00755 
00756     RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
00757 
00758     Transform_Properties(ot, P_MIRROR|P_SNAP|P_CORRECT_UV);
00759 }
00760 
00761 void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
00762 {
00763     /* identifiers */
00764     ot->name   = "Edge Crease";
00765     ot->description= "Change the crease of edges";
00766     ot->idname = OP_EDGE_CREASE;
00767     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00768 
00769     /* api callbacks */
00770     ot->invoke = transform_invoke;
00771     ot->exec   = transform_exec;
00772     ot->modal  = transform_modal;
00773     ot->cancel  = transform_cancel;
00774     ot->poll   = ED_operator_editmesh;
00775 
00776     RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
00777 
00778     Transform_Properties(ot, P_SNAP);
00779 }
00780 
00781 void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
00782 {
00783     /* identifiers */
00784     ot->name   = "Sequence Slide";
00785     ot->description= "Slide a sequence strip in time";
00786     ot->idname = OP_SEQ_SLIDE;
00787     ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00788 
00789     /* api callbacks */
00790     ot->invoke = transform_invoke;
00791     ot->exec   = transform_exec;
00792     ot->modal  = transform_modal;
00793     ot->cancel  = transform_cancel;
00794     ot->poll   = ED_operator_sequencer_active;
00795 
00796     RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
00797 
00798     Transform_Properties(ot, P_SNAP);
00799 }
00800 
00801 void TRANSFORM_OT_transform(struct wmOperatorType *ot)
00802 {
00803     PropertyRNA *prop;
00804 
00805     /* identifiers */
00806     ot->name   = "Transform";
00807     ot->description= "Transform selected items by mode type";
00808     ot->idname = "TRANSFORM_OT_transform";
00809     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
00810 
00811     /* api callbacks */
00812     ot->invoke = transform_invoke;
00813     ot->exec   = transform_exec;
00814     ot->modal  = transform_modal;
00815     ot->cancel  = transform_cancel;
00816     ot->poll   = ED_operator_screenactive;
00817 
00818     prop= RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
00819     RNA_def_property_flag(prop, PROP_HIDDEN);
00820 
00821     RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
00822 
00823     Transform_Properties(ot, P_AXIS|P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_ALIGN_SNAP);
00824 }
00825 
00826 void transform_operatortypes(void)
00827 {
00828     TransformModeItem *tmode;
00829 
00830     for (tmode = transform_modes; tmode->idname; tmode++)
00831     {
00832         WM_operatortype_append(tmode->opfunc);
00833     }
00834 
00835     WM_operatortype_append(TRANSFORM_OT_transform);
00836 
00837     WM_operatortype_append(TRANSFORM_OT_select_orientation);
00838     WM_operatortype_append(TRANSFORM_OT_create_orientation);
00839     WM_operatortype_append(TRANSFORM_OT_delete_orientation);
00840 
00841     WM_operatortype_append(TRANSFORM_OT_snap_type);
00842 }
00843 
00844 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
00845 {
00846     wmKeyMapItem *kmi;
00847     wmKeyMap *modalmap;
00848     
00849     /* transform.c, only adds modal map once, checks if it's there */
00850     modalmap = transform_modal_keymap(keyconf);
00851 
00852     /* assign map to operators only the first time */
00853     if (modalmap) {
00854         TransformModeItem *tmode;
00855 
00856         for (tmode = transform_modes; tmode->idname; tmode++)
00857         {
00858             WM_modalkeymap_assign(modalmap, tmode->idname);
00859         }
00860         WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
00861     }
00862     
00863     switch(spaceid)
00864     {
00865         case SPACE_VIEW3D:
00866             WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
00867 
00868             WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
00869 
00870             WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
00871 
00872             WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
00873 
00874             WM_keymap_add_item(keymap, OP_WARP, WKEY, KM_PRESS, KM_SHIFT, 0);
00875 
00876             WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
00877 
00878             WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0);
00879 
00880             WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
00881 
00882             kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
00883             RNA_boolean_set(kmi->ptr, "use", TRUE);
00884 
00885             WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
00886 
00887             kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
00888             RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
00889 
00890             WM_keymap_add_item(keymap, "TRANSFORM_OT_snap_type", TABKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
00891 
00892             kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
00893             RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
00894 
00895             kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
00896             RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
00897 
00898             break;
00899         case SPACE_ACTION:
00900             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
00901             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
00902             
00903             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
00904             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
00905             
00906             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
00907             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
00908             
00909             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
00910             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
00911             
00912             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
00913             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
00914             break;
00915         case SPACE_IPO:
00916             WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
00917             
00918             WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
00919             
00920             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
00921             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
00922             
00923             WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
00924             
00925             WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
00926             break;
00927         case SPACE_NLA:
00928             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
00929             RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
00930             
00931             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
00932             RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
00933             
00934             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
00935             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
00936             
00937             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
00938             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
00939             break;
00940         case SPACE_NODE:
00941             WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
00942 
00943             kmi= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_A, KM_ANY, 0, 0);
00944             RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
00945             kmi= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
00946             RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
00947 
00948             WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
00949 
00950             WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
00951             break;
00952         case SPACE_SEQ:
00953             WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
00954 
00955             WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
00956 
00957             kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
00958             RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
00959             break;
00960         case SPACE_IMAGE:
00961             WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
00962 
00963             WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
00964 
00965             WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
00966 
00967             WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
00968 
00969             WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0);
00970 
00971             WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
00972 
00973             kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
00974             RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
00975             break;
00976         case SPACE_CLIP:
00977             WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
00978             WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
00979             WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
00980             break;
00981         default:
00982             break;
00983     }
00984 }
00985