svn merge -r39781:39792 https://svn.blender.org/svnroot/bf-blender/trunk/blender...
[blender-staging.git] / source / blender / editors / animation / anim_ipo_utils.c
index 088fddd2e7eed1bd66b75adb3379dedf58866285..9c43671cdf4c4734ecbd208fdbd12442901079c4 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * $Id: 
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -15,7 +13,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/animation/anim_ipo_utils.c
+ *  \ingroup edanimation
+ */
+
+
 /* This file contains code for presenting F-Curves and other animation data
  * in the UI (especially for use in the Animation Editors).
  *
  */
 
 
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_anim_types.h"
-#include "DNA_key_types.h"
-#include "DNA_object_types.h"
-#include "DNA_space_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_view3d_types.h"
 
-#include "BKE_animsys.h"
-#include "BKE_key.h"
-#include "BKE_utildefines.h"
+#include "RNA_access.h"
 
-#include "UI_resources.h"
 #include "ED_anim_api.h"
 
-#include "RNA_access.h"
-#include "RNA_types.h"
-
 /* ----------------------- Getter functions ----------------------- */
 
-/* gets the appropriate icon for the given blocktype */
-// XXX some of these will be depreceated?
-int geticon_anim_blocktype(short blocktype)
-{
-       switch (blocktype) {
-               case ID_OB:
-                       return ICON_OBJECT_DATA;
-               case ID_PO:
-                       return ICON_POSE_HLT;
-               case ID_KE:
-                       return ICON_SHAPEKEY_DATA;
-               case ID_MA:
-                       return ICON_MATERIAL;
-               case ID_WO:
-                       return ICON_WORLD;
-               case ID_CU:
-                       return ICON_CURVE_DATA;
-               case ID_CA:
-                       return ICON_CAMERA;
-               case ID_LA:
-                       return ICON_LAMP;
-               case ID_TE:
-                       return ICON_TEXTURE;
-               case ID_CO:
-                       return ICON_CONSTRAINT;
-               case ID_FLUIDSIM:
-                       return ICON_WORLD; // uggh
-               default:
-                       return 0; // what about blank icon?
-       }
-}
-
-/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings) 
+/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings),
+ * and return the icon used for the struct that this property refers to 
  * WARNING: name buffer we're writing to cannot exceed 256 chars (check anim_channels_defines.c for details)
  */
-void getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
+int getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
 {
+       int icon = 0;
+       
        /* sanity checks */
        if (name == NULL)
-               return;
+               return icon;
        else if ELEM3(NULL, id, fcu, fcu->rna_path) {
                if (fcu == NULL)
                        sprintf(name, "<invalid>");
                else if (fcu->rna_path == NULL)
                        sprintf(name, "<no path>");
                else /* id == NULL */
-                       BLI_snprintf(name, 128, "%s[%d]", fcu->rna_path, fcu->array_index);
+                       BLI_snprintf(name, 256, "%s[%d]", fcu->rna_path, fcu->array_index);
        }
        else {
                PointerRNA id_ptr, ptr;
@@ -118,7 +78,8 @@ void getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
                
                /* try to resolve the path */
                if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) {
-                       char *structname=NULL, *propname=NULL, *arrayname=NULL, arrayindbuf[16];
+                       char *structname=NULL, *propname=NULL, arrayindbuf[16];
+                       const char *arrayname=NULL;
                        short free_structname = 0;
                        
                        /* For now, name will consist of 3 parts: struct-name, property name, array index
@@ -137,10 +98,12 @@ void getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
                         *      - as base, we use a custom name from the structs if one is available 
                         *      - however, if we're showing subdata of bones (probably there will be other exceptions later)
                         *        need to include that info too since it gets confusing otherwise
+                        *      - if a pointer just refers to the ID-block, then don't repeat this info
+                        *        since this just introduces clutter
                         */
-                       if (strstr(fcu->rna_path, "pose_channels") && strstr(fcu->rna_path, "constraints")) {
+                       if (strstr(fcu->rna_path, "bones") && strstr(fcu->rna_path, "constraints")) {
                                /* perform string 'chopping' to get "Bone Name : Constraint Name" */
-                               char *pchanName= BLI_getQuotedStr(fcu->rna_path, "pose_channels[");
+                               char *pchanName= BLI_getQuotedStr(fcu->rna_path, "bones[");
                                char *constName= BLI_getQuotedStr(fcu->rna_path, "constraints[");
                                
                                /* assemble the string to display in the UI... */
@@ -151,7 +114,7 @@ void getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
                                if (pchanName) MEM_freeN(pchanName);
                                if (constName) MEM_freeN(constName);
                        }
-                       else {
+                       else if (ptr.data != ptr.id.data) {
                                PropertyRNA *nameprop= RNA_struct_name_property(ptr.type);
                                if (nameprop) {
                                        /* this gets a string which will need to be freed */
@@ -182,59 +145,52 @@ void getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
                        
                        /* putting this all together into the buffer */
                        // XXX we need to check for invalid names...
-                       BLI_snprintf(name, 128, "%s%s (%s)", arrayname, propname, structname); 
+                       // XXX the name length limit needs to be passed in or as some define
+                       if (structname)
+                               BLI_snprintf(name, 256, "%s%s (%s)", arrayname, propname, structname); 
+                       else
+                               BLI_snprintf(name, 256, "%s%s", arrayname, propname); 
                        
                        /* free temp name if nameprop is set */
                        if (free_structname)
                                MEM_freeN(structname);
+                       
+                       
+                       /* Icon for this property's owner:
+                        *      use the struct's icon if it is set
+                        */
+                       icon= RNA_struct_ui_icon(ptr.type);
                }
                else {
                        /* invalid path */
-                       BLI_snprintf(name, 128, "\"%s[%d]\"", fcu->rna_path, fcu->array_index);
+                       BLI_snprintf(name, 256, "\"%s[%d]\"", fcu->rna_path, fcu->array_index);
+                       
+                       /* icon for this should be the icon for the base ID */
+                       // TODO: or should we just use the error icon?
+                       icon= RNA_struct_ui_icon(id_ptr.type);
+                       
+                       /* tag F-Curve as disabled - as not usable path */
+                       fcu->flag |= FCURVE_DISABLED;
                }
        }
+       
+       /* return the icon that the active data had */
+       return icon;
 }
 
 /* ------------------------------- Color Codes for F-Curve Channels ---------------------------- */
 
-#if 0
-/* used for FCURVE_COLOR_AUTO_RAINBOW */
-// XXX this still doesn't work too great when there are more than 32 curves (which happens most of the time)
-void ipo_rainbow (int cur, int tot, float *out)
-{
-       float dfac, fac, sat;
-       
-       dfac= (float)(1.0/( (float)tot+1.0));
-       
-       /* this calculation makes 2 or 4 different cycles of rainbow colors */
-               // 2 different cycles - for hue
-       if(cur< tot/2) fac= (float)(cur*2.0f*dfac);
-       else fac= (float)((cur-tot/2)*2.0f*dfac +dfac);
-       
-               // third cycle with altered hue
-       if(tot > 32) fac= fac*1.95f;
-               // clamping for excessive ranges
-       if(fac>1.0f) fac-= 1.0f;
-       
-               // saturation adjustments for more visible range
-       if(fac>0.5f && fac<0.8f) sat= 0.5f;
-       else sat= 0.6f;
-       
-       hsv_to_rgb(fac, sat, 1.0f, out, out+1, out+2);
-}
-#endif
-
 /* step between the major distinguishable color bands of the primary colors */
 #define HSV_BANDWIDTH  0.3f
 
-/* testbed for FCURVE_COLOR_AUTO_RAINBOW determination methods */
+/* used to determine the color of F-Curves with FCURVE_COLOR_AUTO_RAINBOW set */
 //void fcurve_rainbow (unsigned int cur, unsigned int tot, float *out)
-void ipo_rainbow (int cur, int tot, float *out)
+void getcolor_fcurve_rainbow (int cur, int tot, float *out)
 {
        float hue, val, sat, fac;
        int grouping;
        
-       /* we try to divide the colours into groupings of n colors,
+       /* we try to divide the color into groupings of n colors,
         * where n is:
         *      3 - for 'odd' numbers of curves - there should be a majority of triplets of curves
         *      4 - for 'even' numbers of curves - there should be a majority of quartets of curves