doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / editors / metaball / mball_edit.c
index 3751f88..13b4535 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -15,7 +15,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.
 #include <math.h>
 #include <string.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_meta_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_windowmanager_types.h"
-#include "DNA_userdef_types.h"
 
 #include "RNA_define.h"
 #include "RNA_access.h"
 
-#include "BKE_utildefines.h"
 #include "BKE_depsgraph.h"
-#include "BKE_object.h"
 #include "BKE_context.h"
+#include "BKE_mball.h"
 
+#include "ED_mball.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
 #include "ED_transform.h"
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "mball_intern.h"
+
 /* This function is used to free all MetaElems from MetaBall */
 void free_editMball(Object *obedit)
 {
+       MetaBall *mb = (MetaBall*)obedit->data;
+
+       mb->editelems= NULL;
+       mb->lastelem= NULL;
 }
 
 /* This function is called, when MetaBall Object is
@@ -87,27 +87,17 @@ void make_editMball(Object *obedit)
 
 /* This function is called, when MetaBall Object switched from
  * edit mode to object mode. List od MetaElements is copied
- * from object->data->edit_elems to to object->data->elems. */
-void load_editMball(Object *obedit)
+ * from object->data->edit_elems to object->data->elems. */
+void load_editMball(Object *UNUSED(obedit))
 {
-       MetaBall *mb = (MetaBall*)obedit->data;
-       
-       mb->editelems= NULL;
-       mb->lastelem= NULL;
 }
 
 /* Add metaelem primitive to metaball object (which is in edit mode) */
-MetaElem *add_metaball_primitive(bContext *C, int type, int newname)
+MetaElem *add_metaball_primitive(bContext *C, float mat[4][4], int type, int UNUSED(newname))
 {
-       Scene *scene= CTX_data_scene(C);
-       View3D *v3d= CTX_wm_view3d(C);
-       RegionView3D *rv3d = CTX_wm_region_view3d(C);
        Object *obedit= CTX_data_edit_object(C);
        MetaBall *mball = (MetaBall*)obedit->data;
        MetaElem *ml;
-       float *curs, mat[3][3], cent[3], imat[3][3], cmat[3][3];
-
-       if(!obedit) return NULL;
 
        /* Deselect all existing metaelems */
        ml= mball->editelems->first;
@@ -115,129 +105,81 @@ MetaElem *add_metaball_primitive(bContext *C, int type, int newname)
                ml->flag &= ~SELECT;
                ml= ml->next;
        }
-
-       copy_m3_m4(mat, obedit->obmat);
-       if(v3d) {
-               curs= give_cursor(scene, v3d);
-               VECCOPY(cent, curs);
-       }
-       else
-               cent[0]= cent[1]= cent[2]= 0.0f;
        
-       cent[0]-= obedit->obmat[3][0];
-       cent[1]-= obedit->obmat[3][1];
-       cent[2]-= obedit->obmat[3][2];
+       ml= add_metaball_element(mball, type);
+       copy_v3_v3(&ml->x, mat[3]);
 
-       if (rv3d) {
-               if (!(newname) || U.flag & USER_ADD_VIEWALIGNED)
-                       copy_m3_m4(imat, rv3d->viewmat);
-               else
-                       unit_m3(imat);
-               mul_m3_v3(imat, cent);
-               mul_m3_m3m3(cmat, imat, mat);
-               invert_m3_m3(imat,cmat);
-               mul_m3_v3(imat, cent);
-       }
-       else
-               unit_m3(imat);
-
-       ml= MEM_callocN(sizeof(MetaElem), "metaelem");
-
-       ml->x= cent[0];
-       ml->y= cent[1];
-       ml->z= cent[2];
-       ml->quat[0]= 1.0;
-       ml->quat[1]= 0.0;
-       ml->quat[2]= 0.0;
-       ml->quat[3]= 0.0;
-       ml->rad= 2.0;
-       ml->s= 2.0;
-       ml->flag= SELECT | MB_SCALE_RAD;
-
-       switch(type) {
-       case MB_BALL:
-               ml->type = MB_BALL;
-               ml->expx= ml->expy= ml->expz= 1.0;
-               break;
-       case MB_TUBE:
-               ml->type = MB_TUBE;
-               ml->expx= ml->expy= ml->expz= 1.0;
-               break;
-       case MB_PLANE:
-               ml->type = MB_PLANE;
-               ml->expx= ml->expy= ml->expz= 1.0;
-               break;
-       case MB_ELIPSOID:
-               ml->type = MB_ELIPSOID;
-               ml->expx= 1.2f;
-               ml->expy= 0.8f;
-               ml->expz= 1.0;
-               break;
-       case MB_CUBE:
-               ml->type = MB_CUBE;
-               ml->expx= ml->expy= ml->expz= 1.0;
-               break;
-       default:
-               break;
-       }
-       
+       ml->flag |= SELECT;
        mball->lastelem= ml;
-       
        return ml;
 }
 
 /***************************** Select/Deselect operator *****************************/
 
 /* Select or deselect all MetaElements */
-static int select_deselect_all_metaelems_exec(bContext *C, wmOperator *op)
+static int select_all_exec(bContext *C, wmOperator *op)
 {
        //Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        MetaBall *mb = (MetaBall*)obedit->data;
        MetaElem *ml;
-       int any_sel= 0;
-       
-       /* Is any metaelem selected? */
+       int action = RNA_enum_get(op->ptr, "action");
+
        ml= mb->editelems->first;
        if(ml) {
-               while(ml) {
-                       if(ml->flag & SELECT) break;
-                       ml= ml->next;
+               if (action == SEL_TOGGLE) {
+                       action = SEL_SELECT;
+                       while(ml) {
+                               if(ml->flag & SELECT) {
+                                       action = SEL_DESELECT;
+                                       break;
+                               }
+                               ml= ml->next;
+                       }
                }
-               if(ml) any_sel= 1;
 
                ml= mb->editelems->first;
                while(ml) {
-                       if(any_sel) ml->flag &= ~SELECT;
-                       else ml->flag |= SELECT;
+                       switch (action) {
+                       case SEL_SELECT:
+                               ml->flag |= SELECT;
+                               break;
+                       case SEL_DESELECT:
+                               ml->flag &= ~SELECT;
+                               break;
+                       case SEL_INVERT:
+                               ml->flag ^= SELECT;
+                               break;
+                       }
                        ml= ml->next;
                }
                WM_event_add_notifier(C, NC_GEOM|ND_SELECT, mb);
-               //DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
        }
 
        return OPERATOR_FINISHED;
 }
 
-void MBALL_OT_select_deselect_all_metaelems(wmOperatorType *ot)
+void MBALL_OT_select_all(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select/Deselect All";
-    ot->description= "(de)select all metaelements.";
-       ot->idname= "MBALL_OT_select_deselect_all_metaelems";
+       ot->name= "Select or Deselect All";
+       ot->description= "Change selection of all meta elements";
+       ot->idname= "MBALL_OT_select_all";
 
        /* callback functions */
-       ot->exec= select_deselect_all_metaelems_exec;
+       ot->exec= select_all_exec;
        ot->poll= ED_operator_editmball;
 
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;  
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       WM_operator_properties_select_all(ot);
 }
 
 /***************************** Select inverse operator *****************************/
 
 /* Invert metaball selection */
-static int select_inverse_metaelems_exec(bContext *C, wmOperator *op)
+static int select_inverse_metaelems_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        MetaBall *mb = (MetaBall*)obedit->data;
@@ -262,7 +204,7 @@ void MBALL_OT_select_inverse_metaelems(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Inverse";
-    ot->description= "Select inverse of (un)selected metaelements.";
+       ot->description= "Select inverse of (un)selected metaelements";
        ot->idname= "MBALL_OT_select_inverse_metaelems";
 
        /* callback functions */
@@ -308,7 +250,7 @@ void MBALL_OT_select_random_metaelems(struct wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Random...";
-    ot->description= "Randomly select metaelements.";
+       ot->description= "Randomly select metaelements";
        ot->idname= "MBALL_OT_select_random_metaelems";
        
        /* callback functions */
@@ -326,7 +268,7 @@ void MBALL_OT_select_random_metaelems(struct wmOperatorType *ot)
 /***************************** Duplicate operator *****************************/
 
 /* Duplicate selected MetaElements */
-static int duplicate_metaelems_exec(bContext *C, wmOperator *op)
+static int duplicate_metaelems_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        MetaBall *mb = (MetaBall*)obedit->data;
@@ -344,19 +286,19 @@ static int duplicate_metaelems_exec(bContext *C, wmOperator *op)
                        ml= ml->prev;
                }
                WM_event_add_notifier(C, NC_GEOM|ND_DATA, mb);
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+               DAG_id_tag_update(obedit->data, 0);
        }
 
        return OPERATOR_FINISHED;
 }
 
-static int duplicate_metaelems_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int duplicate_metaelems_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
        int retv= duplicate_metaelems_exec(C, op);
        
        if (retv == OPERATOR_FINISHED) {
                RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
-               WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
+               WM_operator_name_call(C, "TRANSFORM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
        }
        
        return retv;
@@ -367,7 +309,7 @@ void MBALL_OT_duplicate_metaelems(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Duplicate";
-    ot->description= "Delete selected metaelement(s).";
+       ot->description= "Delete selected metaelement(s)";
        ot->idname= "MBALL_OT_duplicate_metaelems";
 
        /* callback functions */
@@ -385,7 +327,7 @@ void MBALL_OT_duplicate_metaelems(wmOperatorType *ot)
 /***************************** Delete operator *****************************/
 
 /* Delete all selected MetaElems (not MetaBall) */
-static int delete_metaelems_exec(bContext *C, wmOperator *op)
+static int delete_metaelems_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        MetaBall *mb= (MetaBall*)obedit->data;
@@ -403,7 +345,7 @@ static int delete_metaelems_exec(bContext *C, wmOperator *op)
                        ml= next;
                }
                WM_event_add_notifier(C, NC_GEOM|ND_DATA, mb);
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+               DAG_id_tag_update(obedit->data, 0);
        }
 
        return OPERATOR_FINISHED;
@@ -413,7 +355,7 @@ void MBALL_OT_delete_metaelems(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Delete";
-    ot->description= "Delete selected metaelement(s).";
+       ot->description= "Delete selected metaelement(s)";
        ot->idname= "MBALL_OT_delete_metaelems";
 
        /* callback functions */
@@ -453,7 +395,7 @@ static int hide_metaelems_exec(bContext *C, wmOperator *op)
                        }
                }
                WM_event_add_notifier(C, NC_GEOM|ND_DATA, mb);
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+               DAG_id_tag_update(obedit->data, 0);
        }
 
        return OPERATOR_FINISHED;
@@ -463,7 +405,7 @@ void MBALL_OT_hide_metaelems(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Hide";
-    ot->description= "Hide (un)selected metaelement(s).";
+       ot->description= "Hide (un)selected metaelement(s)";
        ot->idname= "MBALL_OT_hide_metaelems";
 
        /* callback functions */
@@ -480,7 +422,7 @@ void MBALL_OT_hide_metaelems(wmOperatorType *ot)
 /***************************** Unhide operator *****************************/
 
 /* Unhide all edited MetaElems */
-static int reveal_metaelems_exec(bContext *C, wmOperator *op)
+static int reveal_metaelems_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        MetaBall *mb= (MetaBall*)obedit->data;
@@ -494,7 +436,7 @@ static int reveal_metaelems_exec(bContext *C, wmOperator *op)
                        ml= ml->next;
                }
                WM_event_add_notifier(C, NC_GEOM|ND_DATA, mb);
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+               DAG_id_tag_update(obedit->data, 0);
        }
        
        return OPERATOR_FINISHED;
@@ -504,7 +446,7 @@ void MBALL_OT_reveal_metaelems(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Reveal";
-    ot->description= "Reveal all hidden metaelements.";
+       ot->description= "Reveal all hidden metaelements";
        ot->idname= "MBALL_OT_reveal_metaelems";
        
        /* callback functions */
@@ -517,7 +459,7 @@ void MBALL_OT_reveal_metaelems(wmOperatorType *ot)
 
 /* Select MetaElement with mouse click (user can select radius circle or
  * stiffness circle) */
-void mouse_mball(bContext *C, short mval[2], int extend)
+int mouse_mball(bContext *C, short mval[2], int extend)
 {
        static MetaElem *startelem=NULL;
        Object *obedit= CTX_data_edit_object(C);
@@ -566,7 +508,7 @@ void mouse_mball(bContext *C, short mval[2], int extend)
                        if(ml==startelem) break;
                }
                
-               /* When some metaelem was found, then it is neccessary to select or
+               /* When some metaelem was found, then it is necessary to select or
                 * deselet it. */
                if(act) {
                        if(extend==0) {
@@ -588,8 +530,12 @@ void mouse_mball(bContext *C, short mval[2], int extend)
                        mb->lastelem= act;
                        
                        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, mb);
+
+                       return 1;
                }
        }
+
+       return 0;
 }
 
 
@@ -662,7 +608,7 @@ static void free_undoMball(void *lbv)
        MEM_freeN(lb);
 }
 
-ListBase *metaball_get_editelems(Object *ob)
+static ListBase *metaball_get_editelems(Object *ob)
 {
        if(ob && ob->type==OB_MBALL) {
                struct MetaBall *mb= (struct MetaBall*)ob->data;
@@ -679,7 +625,7 @@ static void *get_data(bContext *C)
 }
 
 /* this is undo system for MetaBalls */
-void undo_push_mball(bContext *C, char *name)
+void undo_push_mball(bContext *C, const char *name)
 {
        undo_editmode_push(C, name, get_data, free_undoMball, undoMball_to_editMball, editMball_to_undoMball, NULL);
 }