2.5 / Nodes
authorNathan Letwory <nathan@letworyinteractive.com>
Fri, 2 Jan 2009 23:58:03 +0000 (23:58 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Fri, 2 Jan 2009 23:58:03 +0000 (23:58 +0000)
* add Context accessor for selected nodes
* node translation uses transform code
* put transform defines in an enum (mode and numinput flags)

source/blender/blenkernel/BKE_context.h
source/blender/blenkernel/intern/context.c
source/blender/editors/include/BIF_transform.h
source/blender/editors/space_node/node_ops.c
source/blender/editors/space_node/node_select.c
source/blender/editors/space_node/space_node.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_ops.c

index 88c71a1fe44e95dddaef354183fb7851cb566f3d..ec2024089bd52abeaaa6cfdc07cb4c2f2b4463f0 100644 (file)
@@ -125,6 +125,11 @@ void CTX_data_list_add(bContextDataResult *result, void *data);
                BLI_freelistN(&ctx_data_list); \
        }
 
+#define CTX_DATA_COUNT(C, member, i) \
+       CTX_DATA_BEGIN(C, void*, unused, member) \
+               i++; \
+       CTX_DATA_END
+
 /* Data Context Members */
 
 struct Main *CTX_data_main(const bContext *C);
@@ -144,6 +149,8 @@ struct Object *CTX_data_active_object(const bContext *C);
 struct Base *CTX_data_active_base(const bContext *C);
 struct Object *CTX_data_edit_object(const bContext *C);
 
+int CTX_data_selected_nodes(const bContext *C, ListBase *list);
+
 /* Data Evaluation Context */
 
 float CTX_eval_frame(const bContext *C);
index 1e45c68a0b854e30b066616ae244189370627076..d5e277a8d1f987f32e4e12b463527cbf8a3ee9a4 100644 (file)
@@ -352,6 +352,11 @@ ToolSettings *CTX_data_tool_settings(const bContext *C)
                return NULL;
 }
 
+int CTX_data_selected_nodes(const bContext *C, ListBase *list)
+{
+       return ctx_data_collection_get(C, CTX_data_selected_nodes, list);
+}
+
 int CTX_data_selected_objects(const bContext *C, ListBase *list)
 {
        return ctx_data_collection_get(C, CTX_data_selected_objects, list);
@@ -387,7 +392,6 @@ struct Object *CTX_data_edit_object(const bContext *C)
        return ctx_data_pointer_get(C, CTX_data_edit_object);
 }
 
-
 /* data evaluation */
 
 float CTX_eval_frame(const bContext *C)
index 26b91cedd3b7f757f29840f34446763f4607b538..02e931f4198e74378f3962bda84aef808a9fec9c 100644 (file)
@@ -44,33 +44,36 @@ void transform_operatortypes(void);
 /* ******************** Macros & Prototypes *********************** */
 
 /* MODE AND NUMINPUT FLAGS */
-#define TFM_INIT                       -1
-#define TFM_DUMMY                      0
-#define TFM_TRANSLATION                1
-#define TFM_ROTATION           2
-#define TFM_RESIZE                     3
-#define TFM_TOSPHERE           4
-#define TFM_SHEAR                      5
-#define TFM_WARP                       7
-#define TFM_SHRINKFATTEN       8
-#define TFM_TILT                       9
-#define TFM_LAMP_ENERGY                10
-#define TFM_TRACKBALL          11
-#define TFM_PUSHPULL           12
-#define TFM_CREASE                     13
-#define TFM_MIRROR                     14
-#define TFM_BONESIZE           15
-#define TFM_BONE_ENVELOPE      16
-#define TFM_CURVE_SHRINKFATTEN         17
-#define TFM_BONE_ROLL          18
-#define TFM_TIME_TRANSLATE     19      
-#define TFM_TIME_SLIDE         20
-#define        TFM_TIME_SCALE          21
-#define TFM_TIME_EXTEND                22
-#define TFM_BAKE_TIME          23
-#define TFM_BEVEL                      24
-#define TFM_BWEIGHT                    25
-#define TFM_ALIGN                      26
+enum {
+       TFM_INIT = -1,
+       TFM_DUMMY,
+       TFM_TRANSLATION,
+       TFM_ROTATION,
+       TFM_RESIZE,
+       TFM_TOSPHERE,
+       TFM_SHEAR,
+       TFM_WARP,
+       TFM_SHRINKFATTEN,
+       TFM_TILT,
+       TFM_LAMP_ENERGY,
+       TFM_TRACKBALL,
+       TFM_PUSHPULL,
+       TFM_CREASE,
+       TFM_MIRROR,
+       TFM_BONESIZE,
+       TFM_BONE_ENVELOPE,
+       TFM_CURVE_SHRINKFATTEN,
+       TFM_BONE_ROLL,
+       TFM_TIME_TRANSLATE,
+       TFM_TIME_SLIDE,
+       TFM_TIME_SCALE,
+       TFM_TIME_EXTEND,
+       TFM_BAKE_TIME,
+       TFM_BEVEL,
+       TFM_BWEIGHT,
+       TFM_ALIGN,
+       TFM_NODE_TRANSLATE
+} TfmModesInputFlags;
 
 /* TRANSFORM CONTEXTS */
 #define CTX_NONE                       0
index 937b85beabefb7942ec5446bd900c344504e37b4..dc6f3c77cdfdfdf316f31f3f285cf5b48f7ace83 100644 (file)
@@ -36,6 +36,8 @@
 #include "ED_space_api.h"
 #include "ED_screen.h"
 
+#include "BIF_transform.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 
@@ -60,4 +62,6 @@ void node_keymap(struct wmWindowManager *wm)
        RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_extend_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select_type", NODE_SELECT_MOUSE);
        WM_keymap_add_item(keymap, "NODE_OT_toggle_visibility", ACTIONMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NODE_OT_fit_all", HOMEKEY, KM_PRESS, 0, 0);
+       
+       transform_keymap_for_space(wm, keymap, SPACE_NODE);
 }
index e5a631e2178c46253d3c54190b0abddb3ed6ce46..6623d1fb4f49a8a86184a91b46475aa39bd17ea1 100644 (file)
@@ -53,7 +53,7 @@
  
 #include "node_intern.h"
  
-static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short modifier)
+static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short extend)
 {
        bNode *node;
        float mx, my;
@@ -80,10 +80,10 @@ static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short
                        break;
        }
        if(node) {
-               if((modifier & KM_SHIFT)==0)
+               if((extend & KM_SHIFT)==0)
                        node_deselectall(snode, 0);
                
-               if(modifier & KM_SHIFT) {
+               if(extend & KM_SHIFT) {
                        if(node->flag & SELECT)
                                node->flag &= ~SELECT;
                        else
@@ -95,7 +95,7 @@ static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short
                node_set_active(snode, node);
                
                /* viewer linking */
-               if(modifier & KM_CTRL)
+               if(extend & KM_CTRL)
                        ;//     node_link_viewer(snode, node);
                
                //std_rmouse_transform(node_transform_ext);     /* does undo push for select */
@@ -109,7 +109,7 @@ static int node_select_exec(bContext *C, wmOperator *op)
        ARegion *ar= CTX_wm_region(C);
        int select_type;
        short mval[2];
-       short modifier;
+       short extend;
 
        select_type = RNA_enum_get(op->ptr, "select_type");
        
@@ -117,8 +117,8 @@ static int node_select_exec(bContext *C, wmOperator *op)
                case NODE_SELECT_MOUSE:
                        mval[0] = RNA_int_get(op->ptr, "mx");
                        mval[1] = RNA_int_get(op->ptr, "my");
-                       modifier = RNA_int_get(op->ptr, "modifier");
-                       node_mouse_select(snode, ar, mval, modifier);
+                       extend = RNA_int_get(op->ptr, "extend");
+                       node_mouse_select(snode, ar, mval, extend);
                        break;
        }
        return OPERATOR_FINISHED;
@@ -140,7 +140,7 @@ static int node_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
 static int node_extend_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       RNA_int_set(op->ptr, "modifier", KM_SHIFT);
+       RNA_int_set(op->ptr, "extend", KM_SHIFT);
 
        return node_select_invoke(C, op, event);
 }
@@ -168,7 +168,7 @@ void NODE_OT_extend_select(wmOperatorType *ot)
        
        prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
        prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
-       prop = RNA_def_property(ot->srna, "modifier", PROP_INT, PROP_NONE);
+       prop = RNA_def_property(ot->srna, "extend", PROP_INT, PROP_NONE);
 }
 
 void NODE_OT_select(wmOperatorType *ot)
@@ -188,5 +188,5 @@ void NODE_OT_select(wmOperatorType *ot)
        
        prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
        prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
-       prop = RNA_def_property(ot->srna, "modifier", PROP_INT, PROP_NONE);
+       prop = RNA_def_property(ot->srna, "extend", PROP_INT, PROP_NONE);
 }
index f545ff3492e6d078ee0b70cdfd1751301ce63a71..b632506558464ef41d298ec6034eedcfac92f249 100644 (file)
@@ -197,6 +197,24 @@ static void node_main_area_listener(ARegion *ar, wmNotifier *wmn)
        }
 }
 
+static int node_context(const bContext *C, const bContextDataMember *member, bContextDataResult *result)
+{
+       SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
+       
+       if(member == CTX_data_selected_nodes) {
+               bNode *node;
+               
+               for(next_node(snode->edittree); (node=next_node(NULL));) {
+                       if(node->flag & SELECT) {
+                               CTX_data_list_add(result, node);
+                       }
+               }
+               return 1;
+       }
+       
+       return 0;
+}
+
 /* only called once, from space/spacetypes.c */
 void ED_spacetype_node(void)
 {
@@ -211,6 +229,7 @@ void ED_spacetype_node(void)
        st->duplicate= node_duplicate;
        st->operatortypes= node_operatortypes;
        st->keymap= node_keymap;
+       st->context= node_context;
        
        /* regions: main window */
        art= MEM_callocN(sizeof(ARegionType), "spacetype node region");
index 584e2e9c4c1e916ad62c4ea857c7ee9c225caf6b..af982f6c863d11130f30ac907511c4ebf001cde8 100644 (file)
@@ -332,6 +332,9 @@ static void viewRedrawForce(TransInfo *t)
                else 
                        ED_area_tag_redraw(t->sa);
        }
+       else if(t->spacetype == SPACE_NODE) {
+               ED_area_tag_redraw(t->sa);
+       }
 #if 0 // TRANSFORM_FIX_ME
        else if (t->spacetype==SPACE_IMAGE) {
                if (G.sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
@@ -543,6 +546,8 @@ static char *transform_to_undostr(TransInfo *t)
                        return "Key Time";
                case TFM_MIRROR:
                        return "Mirror";
+               case TFM_NODE_TRANSLATE:
+                       return "Node Translate";
        }
        return "Transform";
 }
@@ -1043,6 +1048,9 @@ void initTransform(bContext *C, TransInfo *t, int mode, int options, wmEvent *ev
        case TFM_ALIGN:
                initAlign(t);
                break;
+       case TFM_NODE_TRANSLATE:
+               initNodeTranslate(t);
+               break;
        }
 }
 
@@ -1085,7 +1093,10 @@ int transformEnd(bContext *C, TransInfo *t)
        {
                /* handle restoring objects */
                if(t->state == TRANS_CANCEL)
-                       restoreTransObjects(t); // calls recalcData()
+                       if(t->spacetype == SPACE_NODE)
+                               restoreTransNodes(t);
+                       else
+                               restoreTransObjects(t); // calls recalcData()
                
                /* free data */
                postTrans(t);
@@ -4525,3 +4536,55 @@ void NDofTransform()
        }
 #endif
 }
+
+/* *** Node translation *** */
+
+void initNodeTranslate(TransInfo *t) 
+{
+       t->mode = TFM_NODE_TRANSLATE;
+       t->transform = NodeTranslate;
+       
+       initMouseInputMode(t, &t->mouse, INPUT_NONE);
+
+       /* num-input has max of (n-1) */
+       t->idx_max = 0;
+       t->num.flag = 0;
+       t->num.idx_max = t->idx_max;
+       
+       /* initialise snap like for everything else */
+       t->snap[0] = 0.0f; 
+       t->snap[1] = t->snap[2] = 1.0f;
+}
+
+static void applyNodeTranslate(TransInfo *t) 
+{
+       TransData2D *td = t->data2d;
+       int i;
+
+       for (i = 0 ; i < t->total; i++, td++) {
+               td->loc2d[0]= td->loc[0]+t->values[0];
+               td->loc2d[1]= td->loc[1]+t->values[1];
+       }
+}
+
+int NodeTranslate(TransInfo *t, short mval[2]) 
+{
+       View2D *v2d = &t->ar->v2d;
+       float cval[2], sval[2];
+       char str[200];
+       
+       /* calculate translation amount from mouse movement - in 'node-grid space' */
+       UI_view2d_region_to_view(v2d, mval[0], mval[1], &cval[0], &cval[1]);
+       UI_view2d_region_to_view(v2d, t->imval[0], t->imval[1], &sval[0], &sval[1]);
+
+       t->values[0] = cval[0] - sval[0];
+       t->values[1] = cval[1] - sval[1];
+               
+       applyNodeTranslate(t);
+
+       recalcData(t);
+       
+       viewRedrawForce(t);
+
+       return 1;
+}
index 96a2e7c52ccd3847891a84e701b90d40992f589a..abbf5e93e020f43fbcc4b52bd1c83fb9099aff57 100644 (file)
@@ -426,6 +426,9 @@ int Mirror(TransInfo *t, short mval[2]);
 void initAlign(TransInfo *t);
 int Align(TransInfo *t, short mval[2]);
 
+void initNodeTranslate(TransInfo *t);
+int NodeTranslate(TransInfo *t, short mval[2]);
+
 /*********************** transform_conversions.c ********** */
 struct ListBase;
 void flushTransGPactionData(TransInfo *t);
@@ -531,6 +534,7 @@ TransDataCurveHandleFlags *initTransDataCurveHandes(TransData *td, struct BezTri
 
 void applyTransObjects(TransInfo *t);
 void restoreTransObjects(TransInfo *t);
+void restoreTransNodes(TransInfo *t);
 void recalcData(TransInfo *t);
 
 void calculateCenter(TransInfo *t);
index 020d5143911e80903ed4ed7802995261ac2a2457..ebac66d6b127c08656f83aea658bf512dc7e8100 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifndef WIN32
 #include <unistd.h>
 #else
@@ -56,6 +52,7 @@
 #include "DNA_meta_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_nla_types.h"
+#include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_object_force.h"
 #include "DNA_particle_types.h"
@@ -4352,6 +4349,32 @@ static void createTransObject(bContext *C, TransInfo *t)
        }
 }
 
+/* transcribe given node into TransData2D for Transforming */
+static void NodeToTransData(bContext *C, TransInfo *t, TransData2D *td, bNode *node) 
+{
+       /* Note: since locx and locy come after each other in bNode struct, this works */
+       td->loc2d = &node->locx;
+       
+       /* initial location */
+       td->loc[0]= node->locx;
+       td->loc[1]= node->locy;
+}
+
+void createTransNodeData(bContext *C, TransInfo *t)
+{
+       TransData2D *td;
+       int i= 0;
+       
+       CTX_DATA_COUNT(C, selected_nodes, t->total)
+       
+       td = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransNode");
+       
+       CTX_DATA_BEGIN(C, bNode *, selnode, selected_nodes)
+               NodeToTransData(C, t, td, selnode);
+               td++;
+       CTX_DATA_END
+}
+
 void createTransData(bContext *C, TransInfo *t) 
 {
        Scene *scene = CTX_data_scene(C);
@@ -4401,6 +4424,10 @@ void createTransData(bContext *C, TransInfo *t)
                        sort_trans_data_dist(t);
                }
        }
+       else if(t->spacetype == SPACE_NODE) {
+               t->flag |= T_2D_EDIT|T_POINTS;
+               createTransNodeData(C, t);
+       }
        else if (t->obedit) {
                t->ext = NULL;
                if (t->obedit->type == OB_MESH) {
index 5d96b16751c305464e4819e0d9da9ec1c705a292..283d59da482a9d739dae9cb10daff85d2e82102d 100644 (file)
@@ -42,6 +42,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_nla_types.h"
+#include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_object_force.h"
 #include "DNA_particle_types.h"
@@ -731,7 +732,7 @@ void initTransInfo (bContext *C, TransInfo *t, wmEvent *event)
                if(v3d->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
                t->around = v3d->around;
        }
-       else if(t->spacetype==SPACE_IMAGE)
+       else if(t->spacetype==SPACE_IMAGE || t->spacetype==SPACE_NODE)
        {
                View2D *v2d = sa->spacedata.first; // XXX no!
 
@@ -879,6 +880,20 @@ static void restoreElement(TransData *td) {
        }
 }
 
+static void restoreNode(TransData2D *td)
+{
+       td->loc2d[0]= td->loc[0];
+       td->loc2d[1]= td->loc[1];
+}
+
+void restoreTransNodes(TransInfo *t)
+{
+       TransData2D *td;
+       for (td = t->data2d; td < t->data2d + t->total; td++) {
+               restoreNode(td);
+       }
+}
+
 void restoreTransObjects(TransInfo *t)
 {
        TransData *td;
@@ -1133,6 +1148,8 @@ void calculatePropRatio(TransInfo *t)
        float dist;
        short connected = t->flag & T_PROP_CONNECTED;
 
+       if (t->spacetype == SPACE_NODE) return;
+       
        if (t->flag & T_PROP_EDIT) {
                for(i = 0 ; i < t->total; i++, td++) {
                        if (td->flag & TD_SELECTED) {
index 0e2e985182149cb07fa8fda765715c220e811bba..c61910aea39511152376f758a60207469c5ca404 100644 (file)
@@ -182,6 +182,9 @@ void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *key
                        
                        km= WM_keymap_add_item(keymap, "TFM_OT_transform", TKEY, KM_PRESS, 0, 0);
                        RNA_int_set(km->ptr, "mode", TFM_TIME_SLIDE);
+               case SPACE_NODE:
+                       km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0);
+                       RNA_int_set(km->ptr, "mode", TFM_NODE_TRANSLATE);
                default:
                        break;
        }