Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_buttons/buttons_ops.c')
-rw-r--r--source/blender/editors/space_buttons/buttons_ops.c261
1 files changed, 238 insertions, 23 deletions
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c
index 63469a8294d..6755a2be1b7 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -30,6 +30,7 @@
#include "MEM_guardedalloc.h"
+#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
@@ -37,31 +38,250 @@
#include "DNA_world_types.h"
#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_font.h"
#include "BKE_library.h"
#include "BKE_material.h"
#include "BKE_texture.h"
+#include "BKE_utildefines.h"
#include "BKE_world.h"
+#include "BLI_editVert.h"
+
#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "ED_curve.h"
+#include "ED_mesh.h"
+
#include "buttons_intern.h" // own include
+/********************** material slot operators *********************/
+
+static int material_slot_add_exec(bContext *C, wmOperator *op)
+{
+ Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+
+ if(!ob)
+ return OPERATOR_CANCELLED;
+
+ object_add_material_slot(ob);
+ WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_material_slot_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add Material Slot";
+ ot->idname= "OBJECT_OT_material_slot_add";
+
+ /* api callbacks */
+ ot->exec= material_slot_add_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int material_slot_remove_exec(bContext *C, wmOperator *op)
+{
+ Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+
+ if(!ob)
+ return OPERATOR_CANCELLED;
+
+ object_remove_material_slot(ob);
+ WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_material_slot_remove(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Remove Material Slot";
+ ot->idname= "OBJECT_OT_material_slot_remove";
+
+ /* api callbacks */
+ ot->exec= material_slot_remove_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int material_slot_assign_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene= CTX_data_scene(C);
+ Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+
+ if(!ob)
+ return OPERATOR_CANCELLED;
+
+ if(ob && ob->actcol>0) {
+ if(ob->type == OB_MESH) {
+ EditMesh *em= ((Mesh*)ob->data)->edit_mesh;
+ EditFace *efa;
+
+ if(em) {
+ for(efa= em->faces.first; efa; efa=efa->next)
+ if(efa->f & SELECT)
+ efa->mat_nr= ob->actcol-1;
+ }
+ }
+ else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
+ ListBase *editnurb= ((Curve*)ob->data)->editnurb;
+ Nurb *nu;
+
+ if(editnurb) {
+ for(nu= editnurb->first; nu; nu= nu->next)
+ if(isNurbsel(nu))
+ nu->mat_nr= nu->charidx= ob->actcol-1;
+ }
+ }
+ else if(ob->type == OB_FONT) {
+ EditFont *ef= ((Curve*)ob->data)->editfont;
+ int i, selstart, selend;
+
+ if(ef && BKE_font_getselection(ob, &selstart, &selend)) {
+ for(i=selstart; i<=selend; i++)
+ ef->textbufinfo[i].mat_nr = ob->actcol-1;
+ }
+ }
+ }
+
+ DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_material_slot_assign(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Assign Material Slot";
+ ot->idname= "OBJECT_OT_material_slot_assign";
+
+ /* api callbacks */
+ ot->exec= material_slot_assign_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int material_slot_de_select(bContext *C, int select)
+{
+ Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+
+ if(!ob)
+ return OPERATOR_CANCELLED;
+
+ if(ob->type == OB_MESH) {
+ EditMesh *em= ((Mesh*)ob->data)->edit_mesh;
+
+ if(em) {
+ if(select)
+ EM_select_by_material(em, ob->actcol-1);
+ else
+ EM_deselect_by_material(em, ob->actcol-1);
+ }
+ }
+ else if ELEM(ob->type, OB_CURVE, OB_SURF) {
+ ListBase *editnurb= ((Curve*)ob->data)->editnurb;
+ Nurb *nu;
+ BPoint *bp;
+ BezTriple *bezt;
+ int a;
+
+ for(nu= editnurb->first; nu; nu=nu->next) {
+ if(nu->mat_nr==ob->actcol-1) {
+ if(nu->bezt) {
+ a= nu->pntsu;
+ bezt= nu->bezt;
+ while(a--) {
+ if(bezt->hide==0) {
+ if(select) {
+ bezt->f1 |= SELECT;
+ bezt->f2 |= SELECT;
+ bezt->f3 |= SELECT;
+ }
+ else {
+ bezt->f1 &= ~SELECT;
+ bezt->f2 &= ~SELECT;
+ bezt->f3 &= ~SELECT;
+ }
+ }
+ bezt++;
+ }
+ }
+ else if(nu->bp) {
+ a= nu->pntsu*nu->pntsv;
+ bp= nu->bp;
+ while(a--) {
+ if(bp->hide==0) {
+ if(select) bp->f1 |= SELECT;
+ else bp->f1 &= ~SELECT;
+ }
+ bp++;
+ }
+ }
+ }
+ }
+ }
+
+ WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+static int material_slot_select_exec(bContext *C, wmOperator *op)
+{
+ return material_slot_de_select(C, 1);
+}
+
+void OBJECT_OT_material_slot_select(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Select Material Slot";
+ ot->idname= "OBJECT_OT_material_slot_select";
+
+ /* api callbacks */
+ ot->exec= material_slot_select_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int material_slot_deselect_exec(bContext *C, wmOperator *op)
+{
+ return material_slot_de_select(C, 0);
+}
+
+void OBJECT_OT_material_slot_deselect(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Deselect Material Slot";
+ ot->idname= "OBJECT_OT_material_slot_deselect";
+
+ /* api callbacks */
+ ot->exec= material_slot_deselect_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
/********************** new material operator *********************/
static int new_material_exec(bContext *C, wmOperator *op)
{
- PointerRNA ptr;
- Material *ma;
+ Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
Object *ob;
+ PointerRNA ptr;
int index;
/* add or copy material */
- ptr= CTX_data_pointer_get(C, "material");
- ma= (RNA_struct_is_a(ptr.type, &RNA_Material))? ptr.data: NULL;
-
if(ma)
ma= copy_material(ma);
else
@@ -70,9 +290,9 @@ static int new_material_exec(bContext *C, wmOperator *op)
ma->id.us--; /* compensating for us++ in assign_material */
/* attempt to assign to material slot */
- ptr= CTX_data_pointer_get(C, "material_slot");
+ ptr= CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
- if(RNA_struct_is_a(ptr.type, &RNA_MaterialSlot)) {
+ if(ptr.data) {
ob= ptr.id.data;
index= (Material**)ptr.data - ob->mat;
@@ -80,6 +300,8 @@ static int new_material_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
}
+
+ WM_event_add_notifier(C, NC_MATERIAL|NA_ADDED, ma);
return OPERATOR_FINISHED;
}
@@ -101,15 +323,12 @@ void MATERIAL_OT_new(wmOperatorType *ot)
static int new_texture_exec(bContext *C, wmOperator *op)
{
- PointerRNA ptr;
+ Tex *tex= CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
ID *id;
- Tex *tex;
MTex *mtex;
+ PointerRNA ptr;
/* add or copy texture */
- ptr= CTX_data_pointer_get(C, "texture");
- tex= (RNA_struct_is_a(ptr.type, &RNA_Texture))? ptr.data: NULL;
-
if(tex)
tex= copy_texture(tex);
else
@@ -118,9 +337,9 @@ static int new_texture_exec(bContext *C, wmOperator *op)
id_us_min(&tex->id);
/* attempt to assign to texture slot */
- ptr= CTX_data_pointer_get(C, "texture_slot");
+ ptr= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot);
- if(RNA_struct_is_a(ptr.type, &RNA_TextureSlot)) {
+ if(ptr.data) {
id= ptr.id.data;
mtex= ptr.data;
@@ -133,6 +352,8 @@ static int new_texture_exec(bContext *C, wmOperator *op)
/* XXX nodes, notifier .. */
}
+
+ WM_event_add_notifier(C, NC_TEXTURE|NA_ADDED, tex);
return OPERATOR_FINISHED;
}
@@ -154,27 +375,21 @@ void TEXTURE_OT_new(wmOperatorType *ot)
static int new_world_exec(bContext *C, wmOperator *op)
{
- PointerRNA ptr;
- Scene *scene;
- World *wo;
+ Scene *scene= CTX_data_scene(C);
+ World *wo= CTX_data_pointer_get_type(C, "world", &RNA_World).data;
/* add or copy world */
- ptr= CTX_data_pointer_get(C, "world");
- wo= (RNA_struct_is_a(ptr.type, &RNA_World))? ptr.data: NULL;
-
if(wo)
wo= copy_world(wo);
else
wo= add_world("World");
/* assign to scene */
- scene= CTX_data_scene(C);
-
if(scene->world)
id_us_min(&scene->world->id);
scene->world= wo;
- // XXX notifier
+ WM_event_add_notifier(C, NC_WORLD|NA_ADDED, wo);
return OPERATOR_FINISHED;
}