Esempio n. 1
0
static void rna_Group_objects_link(Group *group, bContext *C, ReportList *reports, Object *object)
{
	if (!add_to_group(group, object, CTX_data_scene(C), NULL)) {
		BKE_reportf(reports, RPT_ERROR, "Object '%s' already in group '%s'", object->id.name + 2, group->id.name + 2);
		return;
	}

	WM_main_add_notifier(NC_OBJECT | ND_DRAW, &object->id);
}
Esempio n. 2
0
static int editsource_text_edit(bContext *C,
                                wmOperator *op,
                                const char filepath[FILE_MAX],
                                const int line)
{
  struct Main *bmain = CTX_data_main(C);
  Text *text;

  /* Developers may wish to copy-paste to an external editor. */
  printf("%s:%d\n", filepath, line);

  for (text = bmain->texts.first; text; text = text->id.next) {
    if (text->name && BLI_path_cmp(text->name, filepath) == 0) {
      break;
    }
  }

  if (text == NULL) {
    text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
    id_us_ensure_real(&text->id);
  }

  if (text == NULL) {
    BKE_reportf(op->reports, RPT_WARNING, "File '%s' cannot be opened", filepath);
    return OPERATOR_CANCELLED;
  }
  else {
    /* naughty!, find text area to set, not good behavior
     * but since this is a dev tool lets allow it - campbell */
    ScrArea *sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
    if (sa) {
      SpaceText *st = sa->spacedata.first;
      st->text = text;
    }
    else {
      BKE_reportf(op->reports, RPT_INFO, "See '%s' in the text editor", text->id.name + 2);
    }

    txt_move_toline(text, line - 1, false);
    WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
  }

  return OPERATOR_FINISHED;
}
Esempio n. 3
0
static void rna_Action_pose_markers_remove(bAction *act, ReportList *reports, TimeMarker *marker)
{
	if (!BLI_remlink_safe(&act->markers, marker)) {
		BKE_reportf(reports, RPT_ERROR, "TimelineMarker '%s' not found in Action '%s'", marker->name, act->id.name+2);
		return;
	}

	/* XXX, invalidates PyObject */
	MEM_freeN(marker);
}
Esempio n. 4
0
void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object)
{
	if(ID_REAL_USERS(object) <= 0) {
		unlink_object(object); /* needed or ID pointers to this are not cleared */
		free_libblock(&bmain->object, object);
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Object \"%s\" must have zero users to be removed, found %d.", object->id.name+2, ID_REAL_USERS(object));
	}
}
Esempio n. 5
0
static int handle_subversion_warning(Main *main, ReportList *reports)
{
	if(main->minversionfile > BLENDER_VERSION ||
	   (main->minversionfile == BLENDER_VERSION && 
		 main->minsubversionfile > BLENDER_SUBVERSION)) {
		BKE_reportf(reports, RPT_ERROR, "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
	}

	return 1;
}
Esempio n. 6
0
static StructRNA *rna_RenderEngine_register(
        Main *bmain, ReportList *reports, void *data, const char *identifier,
        StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
	RenderEngineType *et, dummyet = {NULL};
	RenderEngine dummyengine = {NULL};
	PointerRNA dummyptr;
	int have_function[7];

	/* setup dummy engine & engine type to store static properties in */
	dummyengine.type = &dummyet;
	dummyet.flag |= RE_USE_SHADING_NODES_CUSTOM;
	RNA_pointer_create(NULL, &RNA_RenderEngine, &dummyengine, &dummyptr);

	/* validate the python class */
	if (validate(&dummyptr, data, have_function) != 0)
		return NULL;

	if (strlen(identifier) >= sizeof(dummyet.idname)) {
		BKE_reportf(reports, RPT_ERROR, "Registering render engine class: '%s' is too long, maximum length is %d",
		            identifier, (int)sizeof(dummyet.idname));
		return NULL;
	}

	/* check if we have registered this engine type before, and remove it */
	for (et = R_engines.first; et; et = et->next) {
		if (STREQ(et->idname, dummyet.idname)) {
			if (et->ext.srna)
				rna_RenderEngine_unregister(bmain, et->ext.srna);
			break;
		}
	}
	
	/* create a new engine type */
	et = MEM_callocN(sizeof(RenderEngineType), "python render engine");
	memcpy(et, &dummyet, sizeof(dummyet));

	et->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, et->idname, &RNA_RenderEngine);
	et->ext.data = data;
	et->ext.call = call;
	et->ext.free = free;
	RNA_struct_blender_type_set(et->ext.srna, et);

	et->update = (have_function[0]) ? engine_update : NULL;
	et->render = (have_function[1]) ? engine_render : NULL;
	et->bake = (have_function[2]) ? engine_bake : NULL;
	et->view_update = (have_function[3]) ? engine_view_update : NULL;
	et->view_draw = (have_function[4]) ? engine_view_draw : NULL;
	et->update_script_node = (have_function[5]) ? engine_update_script_node : NULL;
	et->update_render_passes = (have_function[6]) ? engine_update_render_passes : NULL;

	BLI_addtail(&R_engines, et);

	return et->ext.srna;
}
Esempio n. 7
0
static void rna_Object_ray_cast(
        Object *ob, ReportList *reports,
        float origin[3], float direction[3], float distance,
        int *r_success, float r_location[3], float r_normal[3], int *r_index)
{
	bool success = false;

	if (ob->derivedFinal == NULL) {
		BKE_reportf(reports, RPT_ERROR, "Object '%s' has no mesh data to be used for ray casting", ob->id.name + 2);
		return;
	}

	/* Test BoundBox first (efficiency) */
	BoundBox *bb = BKE_object_boundbox_get(ob);
	float distmin;
	if (!bb || (isect_ray_aabb_v3_simple(origin, direction, bb->vec[0], bb->vec[6], &distmin, NULL) && distmin <= distance)) {

		BVHTreeFromMesh treeData = {NULL};

		/* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
		bvhtree_from_mesh_looptri(&treeData, ob->derivedFinal, 0.0f, 4, 6);

		/* may fail if the mesh has no faces, in that case the ray-cast misses */
		if (treeData.tree != NULL) {
			BVHTreeRayHit hit;

			hit.index = -1;
			hit.dist = distance;

			normalize_v3(direction);


			if (BLI_bvhtree_ray_cast(treeData.tree, origin, direction, 0.0f, &hit,
			                         treeData.raycast_callback, &treeData) != -1)
			{
				if (hit.dist <= distance) {
					*r_success = success = true;

					copy_v3_v3(r_location, hit.co);
					copy_v3_v3(r_normal, hit.no);
					*r_index = dm_looptri_to_poly_index(ob->derivedFinal, &treeData.looptri[hit.index]);
				}
			}

			free_bvhtree_from_mesh(&treeData);
		}
	}
	if (success == false) {
		*r_success = false;

		zero_v3(r_location);
		zero_v3(r_normal);
		*r_index = -1;
	}
}
Esempio n. 8
0
char *unpackFile(ReportList *reports, const char *abs_name, const char *local_name, PackedFile *pf, int how)
{
    char *newname = NULL;
    const char *temp = NULL;

    // char newabs[FILE_MAX];
    // char newlocal[FILE_MAX];

    if (pf != NULL) {
        switch (how) {
        case -1:
        case PF_KEEP:
            break;
        case PF_REMOVE:
            temp = abs_name;
            break;
        case PF_USE_LOCAL:
            /* if file exists use it */
            if (BLI_exists(local_name)) {
                temp = local_name;
                break;
            }
        /* else create it */
        /* fall-through */
        case PF_WRITE_LOCAL:
            if (writePackedFile(reports, local_name, pf, 1) == RET_OK) {
                temp = local_name;
            }
            break;
        case PF_USE_ORIGINAL:
            /* if file exists use it */
            if (BLI_exists(abs_name)) {
                BKE_reportf(reports, RPT_INFO, "Use existing file (instead of packed): %s", abs_name);
                temp = abs_name;
                break;
            }
        /* else create it */
        /* fall-through */
        case PF_WRITE_ORIGINAL:
            if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) {
                temp = abs_name;
            }
            break;
        default:
            printf("unpackFile: unknown return_value %d\n", how);
            break;
        }

        if (temp) {
            newname = BLI_strdup(temp);
        }
    }

    return newname;
}
Esempio n. 9
0
static void rna_Action_pose_markers_remove(bAction *act, ReportList *reports, PointerRNA *marker_ptr)
{
    TimeMarker *marker = marker_ptr->data;
    if (!BLI_remlink_safe(&act->markers, marker)) {
        BKE_reportf(reports, RPT_ERROR, "Timeline marker '%s' not found in action '%s'", marker->name, act->id.name + 2);
        return;
    }

    MEM_freeN(marker);
    RNA_POINTER_INVALIDATE(marker_ptr);
}
Esempio n. 10
0
static void rna_KeyMap_remove(wmKeyConfig *keyconfig, ReportList *reports, PointerRNA *keymap_ptr)
{
  wmKeyMap *keymap = keymap_ptr->data;

  if (WM_keymap_remove(keyconfig, keymap) == false) {
    BKE_reportf(reports, RPT_ERROR, "KeyConfig '%s' cannot be removed", keymap->idname);
    return;
  }

  RNA_POINTER_INVALIDATE(keymap_ptr);
}
Esempio n. 11
0
static void rna_Image_update(Image *image, ReportList *reports)
{
	ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);

	if(ibuf == NULL) {
		BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any image data", image->id.name+2);
		return;
	}

	IMB_rect_from_float(ibuf);
}
Esempio n. 12
0
static void rna_KeyMap_item_remove(wmKeyMap *km, ReportList *reports, PointerRNA *kmi_ptr)
{
	wmKeyMapItem *kmi = kmi_ptr->data;

	if (WM_keymap_remove_item(km, kmi) == false) {
		BKE_reportf(reports, RPT_ERROR, "KeyMapItem '%s' cannot be removed from '%s'", kmi->idname, km->idname);
		return;
	}

	RNA_POINTER_INVALIDATE(kmi_ptr);
}
Esempio n. 13
0
static StructRNA *rna_Header_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
                                      StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
	ARegionType *art;
	HeaderType *ht, dummyht = {NULL};
	Header dummyheader = {NULL};
	PointerRNA dummyhtr;
	int have_function[1];

	/* setup dummy header & header type to store static properties in */
	dummyheader.type = &dummyht;
	RNA_pointer_create(NULL, &RNA_Header, &dummyheader, &dummyhtr);

	/* validate the python class */
	if (validate(&dummyhtr, data, have_function) != 0)
		return NULL;

	if (strlen(identifier) >= sizeof(dummyht.idname)) {
		BKE_reportf(reports, RPT_ERROR, "Registering header class: '%s' is too long, maximum length is %d",
		            identifier, (int)sizeof(dummyht.idname));
		return NULL;
	}

	if (!(art = region_type_find(reports, dummyht.space_type, RGN_TYPE_HEADER)))
		return NULL;

	/* check if we have registered this header type before, and remove it */
	for (ht = art->headertypes.first; ht; ht = ht->next) {
		if (strcmp(ht->idname, dummyht.idname) == 0) {
			if (ht->ext.srna)
				rna_Header_unregister(bmain, ht->ext.srna);
			break;
		}
	}
	
	/* create a new header type */
	ht = MEM_callocN(sizeof(HeaderType), "python buttons header");
	memcpy(ht, &dummyht, sizeof(dummyht));

	ht->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, ht->idname, &RNA_Header);
	ht->ext.data = data;
	ht->ext.call = call;
	ht->ext.free = free;
	RNA_struct_blender_type_set(ht->ext.srna, ht);

	ht->draw = (have_function[0]) ? header_draw : NULL;

	BLI_addtail(&art->headertypes, ht);

	/* update while blender is running */
	WM_main_add_notifier(NC_WINDOW, NULL);
	
	return ht->ext.srna;
}
Esempio n. 14
0
static void rna_KeyConfig_remove(wmWindowManager *wm, ReportList *reports, PointerRNA *keyconf_ptr)
{
  wmKeyConfig *keyconf = keyconf_ptr->data;

  if (WM_keyconfig_remove(wm, keyconf) == false) {
    BKE_reportf(reports, RPT_ERROR, "KeyConfig '%s' cannot be removed", keyconf->idname);
    return;
  }

  RNA_POINTER_INVALIDATE(keyconf_ptr);
}
Esempio n. 15
0
static void rna_NlaStrip_remove(NlaTrack *track, bContext *C, ReportList *reports, NlaStrip *strip)
{
	if(BLI_findindex(&track->strips, strip) == -1) {
		BKE_reportf(reports, RPT_ERROR, "NLA's Strip '%s' not found in track '%s'", strip->name, track->name);
		return;
	}
	else {
		free_nlastrip(&track->strips, strip);
		WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL);
	}
}
Esempio n. 16
0
/* no libraries for now */
void packAll(Main *bmain, ReportList *reports, bool verbose)
{
	Image *ima;
	VFont *vfont;
	bSound *sound;
	int tot = 0;
	
	for (ima = bmain->image.first; ima; ima = ima->id.next) {
		if (BKE_image_has_packedfile(ima) == false && ima->id.lib == NULL) {
			if (ima->source == IMA_SRC_FILE) {
				BKE_image_packfiles(reports, ima, ID_BLEND_PATH(bmain, &ima->id));
				tot ++;
			}
			else if (BKE_image_is_animated(ima) && verbose) {
				BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported",
				            ima->id.name + 2);
			}
		}
	}

	for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) {
		if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == false) {
			vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name);
			tot ++;
		}
	}

	for (sound = bmain->sound.first; sound; sound = sound->id.next) {
		if (sound->packedfile == NULL && sound->id.lib == NULL) {
			sound->packedfile = newPackedFile(reports, sound->name, bmain->name);
			tot++;
		}
	}
	
	if (tot > 0)
		BKE_reportf(reports, RPT_INFO, "Packed %d files", tot);
	else if (verbose)
		BKE_report(reports, RPT_INFO, "No new files have been packed");


}
Esempio n. 17
0
Image *rna_Main_images_load(Main *UNUSED(bmain), ReportList *reports, const char *filepath)
{
	Image *ima;

	errno= 0;
	ima= BKE_add_image_file(filepath);

	if(!ima)
		BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, errno ? strerror(errno) : "Unsupported image format");

	return ima;
}
Esempio n. 18
0
Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *filepath)
{
	Text *txt;

	errno= 0;
	txt= add_text(filepath, bmain->name);

	if(!txt)
		BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, errno ? strerror(errno) : "Unable to load text");

	return txt;
}
Esempio n. 19
0
static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, FCurve *fcu)
{
	if (fcu->grp) {
		if (BLI_findindex(&act->groups, fcu->grp) == -1) {
			BKE_reportf(reports, RPT_ERROR, "F-Curve's ActionGroup '%s' not found in action '%s'", fcu->grp->name, act->id.name+2);
			return;
		}
		
		action_groups_remove_channel(act, fcu);
		free_fcurve(fcu);
	}
	else {
		if (BLI_findindex(&act->curves, fcu) == -1) {
			BKE_reportf(reports, RPT_ERROR, "F-Curve not found in action '%s'", act->id.name+2);
			return;
		}
		
		BLI_remlink(&act->curves, fcu);
		free_fcurve(fcu);
	}
}
Esempio n. 20
0
static int editsource_text_edit(bContext *C, wmOperator *op,
                                char filepath[240], int line)
{
	struct Main *bmain= CTX_data_main(C);
	Text *text;

	for (text=bmain->text.first; text; text=text->id.next) {
		if (text->name && BLI_path_cmp(text->name, filepath) == 0) {
			break;
		}
	}

	if (text == NULL) {
		text= add_text(filepath, bmain->name);
	}

	if (text == NULL) {
		BKE_reportf(op->reports, RPT_WARNING,
		            "file: '%s' can't be opened", filepath);
		return OPERATOR_CANCELLED;
	}
	else {
		/* naughty!, find text area to set, not good behavior
		 * but since this is a dev tool lets allow it - campbell */
		ScrArea *sa= BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
		if(sa) {
			SpaceText *st= sa->spacedata.first;
			st->text= text;
		}
		else {
			BKE_reportf(op->reports, RPT_INFO,
			            "See '%s' in the text editor", text->id.name + 2);
		}

		txt_move_toline(text, line - 1, FALSE);
		WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
	}

	return OPERATOR_FINISHED;
}
Esempio n. 21
0
static StructRNA *rna_KeyingSetInfo_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
                                             StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
	KeyingSetInfo dummyksi = {NULL};
	KeyingSetInfo *ksi;
	PointerRNA dummyptr = {{NULL}};
	int have_function[3];

	/* setup dummy type info to store static properties in */
	/* TODO: perhaps we want to get users to register as if they're using 'KeyingSet' directly instead? */
	RNA_pointer_create(NULL, &RNA_KeyingSetInfo, &dummyksi, &dummyptr);
	
	/* validate the python class */
	if (validate(&dummyptr, data, have_function) != 0)
		return NULL;
	
	if (strlen(identifier) >= sizeof(dummyksi.idname)) {
		BKE_reportf(reports, RPT_ERROR, "Registering keying set info class: '%s' is too long, maximum length is %d",
		            identifier, (int)sizeof(dummyksi.idname));
		return NULL;
	}
	
	/* check if we have registered this info before, and remove it */
	ksi = ANIM_keyingset_info_find_name(dummyksi.idname);
	if (ksi && ksi->ext.srna)
		rna_KeyingSetInfo_unregister(bmain, ksi->ext.srna);
	
	/* create a new KeyingSetInfo type */
	ksi = MEM_callocN(sizeof(KeyingSetInfo), "python keying set info");
	memcpy(ksi, &dummyksi, sizeof(KeyingSetInfo));
	
	/* set RNA-extensions info */
	ksi->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, ksi->idname, &RNA_KeyingSetInfo);
	ksi->ext.data = data;
	ksi->ext.call = call;
	ksi->ext.free = free;
	RNA_struct_blender_type_set(ksi->ext.srna, ksi);
	
	/* set callbacks */
	/* NOTE: we really should have all of these...  */
	ksi->poll = (have_function[0]) ? RKS_POLL_rna_internal : NULL;
	ksi->iter = (have_function[1]) ? RKS_ITER_rna_internal : NULL;
	ksi->generate = (have_function[2]) ? RKS_GEN_rna_internal : NULL;
	
	/* add and register with other info as needed */
	ANIM_keyingset_info_register(ksi);
	
	WM_main_add_notifier(NC_WINDOW, NULL);

	/* return the struct-rna added */
	return ksi->ext.srna;
}
Esempio n. 22
0
Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, const char *name, ID *data)
{
	Object *ob;
	int type= OB_EMPTY;
	if(data) {
		switch(GS(data->name)) {
			case ID_ME:
				type= OB_MESH;
				break;
			case ID_CU:
				type= curve_type((struct Curve *)data);
				break;
			case ID_MB:
				type= OB_MBALL;
				break;
			case ID_LA:
				type= OB_LAMP;
				break;
			case ID_SPK:
				type= OB_SPEAKER;
				break;
			case ID_CA:
				type= OB_CAMERA;
				break;
			case ID_LT:
				type= OB_LATTICE;
				break;
			case ID_AR:
				type= OB_ARMATURE;
				break;
			default:
			{
				const char *idname;
				if(RNA_enum_id_from_value(id_type_items, GS(data->name), &idname) == 0)
					idname= "UNKNOWN";

				BKE_reportf(reports, RPT_ERROR, "ID type '%s' is not valid for a object.", idname);
				return NULL;
			}
		}

		id_us_plus(data);
	}

	ob= add_only_object(type, name);
	id_us_min(&ob->id);

	ob->data= data;
	test_object_materials(ob->data);
	
	return ob;
}
Esempio n. 23
0
static void rna_Depsgraph_debug_stats(Depsgraph *graph, ReportList *reports)
{
	size_t outer, ops, rels;
	
	DEG_stats_simple(graph, &outer, &ops, &rels);
	
	// XXX: report doesn't seem to work
	printf("Approx %lu Operations, %lu Relations, %lu Outer Nodes\n",
	       ops, rels, outer);
		   
	BKE_reportf(reports, RPT_WARNING, "Approx. %lu Operations, %lu Relations, %lu Outer Nodes",
	            ops, rels, outer);
}
Esempio n. 24
0
/* Return the floating point zbuffer */
static void rna_Image_zbuf_blensor(Image *image, bContext *C, ReportList *reports, int *outbuffer_len, float **outbuffer, Scene *scene)
{

    ImBuf *ibuf;
    int idx=0;
    if (scene == NULL) {
        scene = CTX_data_scene(C);
    }


    *outbuffer_len=0;

    ImageUser iuser;
    void *lock;

    iuser.scene = scene;
    iuser.ok = 1;

    ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);

    if (ibuf == NULL) {
        BKE_reportf(reports, RPT_ERROR, "Couldn't acquire buffer from image");
    }
    else {
        *outbuffer = (float *) MEM_mallocN(ibuf->x * ibuf->y * sizeof(float),"rna_Image_zbuf");
        if (*outbuffer == NULL)
        {
            BKE_reportf(reports, RPT_ERROR, "Couldn't allocate buffer for zbuffer output");
        }
        else
        {
            memcpy((void *)*outbuffer, (const void *)ibuf->zbuf_float, ibuf->x * ibuf->y* sizeof(float));
            *outbuffer_len = ibuf->x * ibuf->y;
        }

    }
    BKE_image_release_ibuf(image, ibuf, lock);

}
Esempio n. 25
0
static void rna_Mask_layers_remove(Mask *mask, ReportList *reports, PointerRNA *masklay_ptr)
{
	MaskLayer *masklay = masklay_ptr->data;
	if (BLI_findindex(&mask->masklayers, masklay) == -1) {
		BKE_reportf(reports, RPT_ERROR, "Mask layer '%s' not found in mask '%s'", masklay->name, mask->id.name + 2);
		return;
	}

	BKE_mask_layer_remove(mask, masklay);
	RNA_POINTER_INVALIDATE(masklay_ptr);

	WM_main_add_notifier(NC_MASK | NA_EDITED, mask);
}
Esempio n. 26
0
static void rna_Object_shape_key_remove(
        Object *ob, Main *bmain, ReportList *reports,
        PointerRNA *kb_ptr)
{
	KeyBlock *kb = kb_ptr->data;
	Key *key = BKE_key_from_object(ob);

	if ((key == NULL) || BLI_findindex(&key->block, kb) == -1) {
		BKE_reportf(reports, RPT_ERROR, "ShapeKey not found");
		return;
	}

	if (!BKE_object_shapekey_remove(bmain, ob, kb)) {
		BKE_reportf(reports, RPT_ERROR, "Could not remove ShapeKey");
		return;
	}

	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
	WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);

	RNA_POINTER_INVALIDATE(kb_ptr);
}
Esempio n. 27
0
static void rna_Object_closest_point_on_mesh(Object *ob, ReportList *reports, float point_co[3], float max_dist,
                                             float n_location[3], float n_normal[3], int *index)
{
	BVHTreeFromMesh treeData = {NULL};
	
	if (ob->derivedFinal == NULL) {
		BKE_reportf(reports, RPT_ERROR, "Object '%s' has no mesh data to be used for finding nearest point",
		            ob->id.name + 2);
		return;
	}

	/* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
	bvhtree_from_mesh_faces(&treeData, ob->derivedFinal, 0.0f, 4, 6);

	if (treeData.tree == NULL) {
		BKE_reportf(reports, RPT_ERROR, "Object '%s' could not create internal data for finding nearest point",
		            ob->id.name + 2);
		return;
	}
	else {
		BVHTreeNearest nearest;

		nearest.index = -1;
		nearest.dist_sq = max_dist * max_dist;

		if (BLI_bvhtree_find_nearest(treeData.tree, point_co, &nearest, treeData.nearest_callback, &treeData) != -1) {
			copy_v3_v3(n_location, nearest.co);
			copy_v3_v3(n_normal, nearest.no);
			*index = dm_tessface_to_poly_index(ob->derivedFinal, nearest.index);
			free_bvhtree_from_mesh(&treeData);
			return;
		}
	}

	zero_v3(n_location);
	zero_v3(n_normal);
	*index = -1;
	free_bvhtree_from_mesh(&treeData);
}
Esempio n. 28
0
static void rna_NlaStrip_remove(NlaTrack *track, bContext *C, ReportList *reports, PointerRNA *strip_ptr)
{
	NlaStrip *strip = strip_ptr->data;
	if (BLI_findindex(&track->strips, strip) == -1) {
		BKE_reportf(reports, RPT_ERROR, "NLA strip '%s' not found in track '%s'", strip->name, track->name);
		return;
	}

	BKE_nlastrip_free(&track->strips, strip);
	RNA_POINTER_INVALIDATE(strip_ptr);

	WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_REMOVED, NULL);
}
Esempio n. 29
0
static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id));

		if (BKE_image_has_packedfile(image)) {
			ImagePackedFile *imapf;

			for (imapf = image->packedfiles.first; imapf; imapf = imapf->next) {
				if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) {
					BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'",
					            image->id.name + 2, imapf->filepath);
				}
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
Esempio n. 30
0
VFont *rna_Main_fonts_load(Main *UNUSED(bmain), ReportList *reports, const char *filepath)
{
	VFont *font;

	errno= 0;
	font= load_vfont(filepath);

	if(!font)
		BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, errno ? strerror(errno) : "Unsupported font format");

	return font;

}