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