bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, bNode *node, const char *name, ImageFormatData *im_format)
{
	NodeImageMultiFile *nimf = node->storage;
	bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_IN, "", SOCK_RGBA);
	
	/* create format data for the input socket */
	NodeImageMultiFileSocket *sockdata = MEM_callocN(sizeof(NodeImageMultiFileSocket), "socket image format");
	sock->storage = sockdata;
	
	BLI_strncpy_utf8(sockdata->path, name, sizeof(sockdata->path));
	ntreeCompositOutputFileUniquePath(&node->inputs, sock, name, '_');
	BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer));
	ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_');
	
	if (im_format) {
		sockdata->format= *im_format;
		if (BKE_imtype_is_movie(sockdata->format.imtype)) {
			sockdata->format.imtype= R_IMF_IMTYPE_OPENEXR;
		}
	}
	else
		BKE_imformat_defaults(&sockdata->format);
	/* use node data format by default */
	sockdata->use_node_format = TRUE;
	
	nimf->active_input = BLI_findindex(&node->inputs, sock);
	
	return sock;
}
Exemple #2
0
bool ui_but_anim_expression_set(uiBut *but, const char *str)
{
	FCurve *fcu;
	ChannelDriver *driver;
	bool driven, special;

	fcu = ui_but_get_fcurve(but, NULL, NULL, &driven, &special);

	if (fcu && driven) {
		driver = fcu->driver;
		
		if (driver && (driver->type == DRIVER_TYPE_PYTHON)) {
			BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
			
			/* tag driver as needing to be recompiled */
			driver->flag |= DRIVER_FLAG_RECOMPILE;
			
			/* clear invalid flags which may prevent this from working */
			driver->flag &= ~DRIVER_FLAG_INVALID;
			fcu->flag &= ~FCURVE_DISABLED;
			
			/* this notifier should update the Graph Editor and trigger depsgraph refresh? */
			WM_event_add_notifier(but->block->evil_C, NC_ANIMATION | ND_KEYFRAME, NULL);
			
			return true;
		}
	}

	return false;
}
Exemple #3
0
static void rna_Sensor_name_set(PointerRNA *ptr, const char *value)
{
	Object *ob = ptr->id.data;
	bSensor *sens = ptr->data;
	BLI_strncpy_utf8(sens->name, value, sizeof(sens->name));
	BLI_uniquename(&ob->sensors, sens, DATA_("Sensor"), '.', offsetof(bSensor, name), sizeof(sens->name));
}
static int set_engine(int argc, const char **argv, void *data)
{
	bContext *C = data;
	if (argc >= 2) {
		if (!strcmp(argv[1], "help")) {
			RenderEngineType *type = NULL;
			printf("Blender Engine Listing:\n");
			for (type = R_engines.first; type; type = type->next) {
				printf("\t%s\n", type->idname);
			}
			exit(0);
		}
		else {
			Scene *scene = CTX_data_scene(C);
			if (scene) {
				RenderData *rd = &scene->r;

				if (BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) {
					BLI_strncpy_utf8(rd->engine, argv[1], sizeof(rd->engine));
				}
			}
			else {
				printf("\nError: no blend loaded. order the arguments so '-E  / --engine ' is after a blend is loaded.\n");
			}
		}

		return 1;
	}
	else {
		printf("\nEngine not specified, give 'help' for a list of available engines.\n");
		return 0;
	}
}
/* create new expression for button (i.e. a "scripted driver"), if it can be created... */
bool ui_but_anim_expression_create(uiBut *but, const char *str)
{
	bContext *C = but->block->evil_C;
	ID *id;
	FCurve *fcu;
	char *path;
	bool ok = false;
	
	/* button must have RNA-pointer to a numeric-capable property */
	if (ELEM(NULL, but->rnapoin.data, but->rnaprop)) {
		if (G.debug & G_DEBUG)
			printf("ERROR: create expression failed - button has no RNA info attached\n");
		return false;
	}
	
	if (RNA_property_array_check(but->rnaprop) != 0) {
		if (but->rnaindex == -1) {
			if (G.debug & G_DEBUG)
				printf("ERROR: create expression failed - can't create expression for entire array\n");
			return false;
		}
	}
	
	/* make sure we have animdata for this */
	/* FIXME: until materials can be handled by depsgraph, don't allow drivers to be created for them */
	id = (ID *)but->rnapoin.id.data;
	if ((id == NULL) || (GS(id->name) == ID_MA) || (GS(id->name) == ID_TE)) {
		if (G.debug & G_DEBUG)
			printf("ERROR: create expression failed - invalid id-datablock for adding drivers (%p)\n", id);
		return false;
	}
	
	/* get path */
	path = RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
	
	/* create driver */
	fcu = verify_driver_fcurve(id, path, but->rnaindex, 1);
	if (fcu) {
		ChannelDriver *driver = fcu->driver;
		
		if (driver) {
			/* set type of driver */
			driver->type = DRIVER_TYPE_PYTHON;

			/* set the expression */
			/* TODO: need some way of identifying variables used */
			BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));

			/* updates */
			driver->flag |= DRIVER_FLAG_RECOMPILE;
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, NULL);
			ok = true;
		}
	}
	
	MEM_freeN(path);
	
	return ok;
}
Exemple #6
0
static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value)
{
	Object *ob = ptr->id.data;
	bProperty *prop = ptr->data;
	BLI_strncpy_utf8(prop->name, value, sizeof(prop->name));

	BLI_uniquename(&ob->prop, prop, DATA_("Property"), '.', offsetof(bProperty, name), sizeof(prop->name));
}
Exemple #7
0
static TimeMarker *rna_Action_pose_markers_new(bAction *act, const char name[])
{
    TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
    marker->flag = 1;
    marker->frame = 1;
    BLI_strncpy_utf8(marker->name, name, sizeof(marker->name));
    BLI_addtail(&act->markers, marker);
    return marker;
}
Exemple #8
0
static void rna_GPencilLayer_info_set(PointerRNA *ptr, const char *value)
{
	bGPdata *gpd = ptr->id.data;
	bGPDlayer *gpl = ptr->data;

	/* copy the new name into the name slot */
	BLI_strncpy_utf8(gpl->info, value, sizeof(gpl->info));

	BLI_uniquename(&gpd->layers, gpl, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
}
Exemple #9
0
void rna_Sensor_name_set(PointerRNA *ptr, const char *value)
{
	bSensor *sens = (bSensor *)ptr->data;

	BLI_strncpy_utf8(sens->name, value, sizeof(sens->name));

	if (ptr->id.data) {
		Object *ob = (Object *)ptr->id.data;
		BLI_uniquename(&ob->sensors, sens, "Sensor", '.', offsetof(bSensor, name), sizeof(sens->name));
	}
}
Exemple #10
0
void rna_Constroller_name_set(PointerRNA *ptr, const char *value)
{
	bController *cont = (bController *)ptr->data;

	BLI_strncpy_utf8(cont->name, value, sizeof(cont->name));

	if (ptr->id.data) {
		Object *ob = (Object *)ptr->id.data;
		BLI_uniquename(&ob->controllers, cont, "Controller", '.', offsetof(bController, name), sizeof(cont->name));
	}
}
static void rna_Bone_name_set(PointerRNA *ptr, const char *value)
{
	bArmature *arm = (bArmature *)ptr->id.data;
	Bone *bone = (Bone *)ptr->data;
	char oldname[sizeof(bone->name)], newname[sizeof(bone->name)];
	
	/* need to be on the stack */
	BLI_strncpy_utf8(newname, value, sizeof(bone->name));
	BLI_strncpy(oldname, bone->name, sizeof(bone->name));

	ED_armature_bone_rename(arm, oldname, newname);
}
Exemple #12
0
static void rna_NlaStrip_name_set(PointerRNA *ptr, const char *value)
{
	NlaStrip *data = (NlaStrip *)ptr->data;
	
	/* copy the name first */
	BLI_strncpy_utf8(data->name, value, sizeof(data->name));
	
	/* validate if there's enough info to do so */
	if (ptr->id.data) {
		AnimData *adt = BKE_animdata_from_id(ptr->id.data);
		BKE_nlastrip_validate_name(adt, data);
	}
}
Exemple #13
0
static ViewLayer *view_layer_add(const char *name)
{
  if (!name) {
    name = DATA_("View Layer");
  }

  ViewLayer *view_layer = MEM_callocN(sizeof(ViewLayer), "View Layer");
  view_layer->flag = VIEW_LAYER_RENDER | VIEW_LAYER_FREESTYLE;

  BLI_strncpy_utf8(view_layer->name, name, sizeof(view_layer->name));

  /* Pure rendering pipeline settings. */
  view_layer->layflag = 0x7FFF; /* solid ztra halo edge strand */
  view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
  view_layer->pass_alpha_threshold = 0.5f;
  BKE_freestyle_config_init(&view_layer->freestyle_config);

  return view_layer;
}
Exemple #14
0
void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, const char *newname)
{
  char oldname[sizeof(view_layer->name)];

  BLI_strncpy(oldname, view_layer->name, sizeof(view_layer->name));

  BLI_strncpy_utf8(view_layer->name, newname, sizeof(view_layer->name));
  BLI_uniquename(&scene->view_layers,
                 view_layer,
                 DATA_("ViewLayer"),
                 '.',
                 offsetof(ViewLayer, name),
                 sizeof(view_layer->name));

  if (scene->nodetree) {
    bNode *node;
    int index = BLI_findindex(&scene->view_layers, view_layer);

    for (node = scene->nodetree->nodes.first; node; node = node->next) {
      if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
        if (node->custom1 == index) {
          BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR);
        }
      }
    }
  }

  /* Fix all the animation data and windows which may link to this. */
  BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name);

  /* WM can be missing on startup. */
  wmWindowManager *wm = bmain->wm.first;
  if (wm) {
    for (wmWindow *win = wm->windows.first; win; win = win->next) {
      if (win->scene == scene && STREQ(win->view_layer_name, oldname)) {
        STRNCPY(win->view_layer_name, view_layer->name);
      }
    }
  }

  /* Dependency graph uses view layer name based lookups. */
  DEG_id_tag_update(&scene->id, 0);
}
Exemple #15
0
void rna_ShapeKey_name_set(PointerRNA *ptr, const char *value)
{
	KeyBlock *kb= ptr->data;
	char oldname[sizeof(kb->name)];
	
	/* make a copy of the old name first */
	BLI_strncpy(oldname, kb->name, sizeof(kb->name));
	
	/* copy the new name into the name slot */
	BLI_strncpy_utf8(kb->name, value, sizeof(kb->name));
	
	/* make sure the name is truly unique */
	if (ptr->id.data) {
		Key *key= rna_ShapeKey_find_key(ptr->id.data);
		BLI_uniquename(&key->block, kb, "Key", '.', offsetof(KeyBlock, name), sizeof(kb->name));
	}
	
	/* fix all the animation data which may link to this */
	BKE_all_animdata_fix_paths_rename("key_blocks", oldname, kb->name);
}
bool ui_but_anim_expression_set(uiBut *but, const char *str)
{
	FCurve *fcu;
	ChannelDriver *driver;
	bool driven;

	fcu = ui_but_get_fcurve(but, NULL, &driven);

	if (fcu && driven) {
		driver = fcu->driver;
		
		if (driver && driver->type == DRIVER_TYPE_PYTHON) {
			BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
			driver->flag |= DRIVER_FLAG_RECOMPILE;
			WM_event_add_notifier(but->block->evil_C, NC_ANIMATION | ND_KEYFRAME, NULL);
			return true;
		}
	}

	return false;
}
GpencilModifierData *ED_object_gpencil_modifier_add(
    ReportList *reports, Main *bmain, Scene *UNUSED(scene), Object *ob, const char *name, int type)
{
  GpencilModifierData *new_md = NULL;
  const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(type);

  if (ob->type != OB_GPENCIL) {
    BKE_reportf(reports, RPT_WARNING, "Modifiers cannot be added to object '%s'", ob->id.name + 2);
    return NULL;
  }

  if (mti->flags & eGpencilModifierTypeFlag_Single) {
    if (BKE_gpencil_modifiers_findByType(ob, type)) {
      BKE_report(reports, RPT_WARNING, "Only one modifier of this type is allowed");
      return NULL;
    }
  }

  /* get new modifier data to add */
  new_md = BKE_gpencil_modifier_new(type);

  BLI_addtail(&ob->greasepencil_modifiers, new_md);

  if (name) {
    BLI_strncpy_utf8(new_md->name, name, sizeof(new_md->name));
  }

  /* make sure modifier data has unique name */
  BKE_gpencil_modifier_unique_name(&ob->greasepencil_modifiers, new_md);

  bGPdata *gpd = ob->data;
  DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);

  DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
  DEG_relations_tag_update(bmain);

  return new_md;
}
void ntreeCompositOutputFileSetLayer(bNode *node, bNodeSocket *sock, const char *name)
{
	NodeImageMultiFileSocket *sockdata = sock->storage;
	BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer));
	ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_');
}
Exemple #19
0
static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value)
{
	bProperty *prop = (bProperty *)(ptr->data);
	BLI_strncpy_utf8(prop->name, value, sizeof(prop->name));
	BKE_bproperty_unique(NULL, prop, 1);
}
Exemple #20
0
/**
 * \note RNA_struct_property_is_set_ex is used here because we want
 *       the previously used settings to be used here rather then overriding them */
short ED_fileselect_set_params(SpaceFile *sfile)
{
	FileSelectParams *params;
	wmOperator *op = sfile->op;

	/* create new parameters if necessary */
	if (!sfile->params) {
		sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams");
		/* set path to most recently opened .blend */
		BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
		sfile->params->filter_glob[0] = '\0';
		/* set the default thumbnails size */
		sfile->params->thumbnail_size = 128;
	}

	params = sfile->params;

	/* set the parameters from the operator, if it exists */
	if (op) {
		PropertyRNA *prop;
		const bool is_files = (RNA_struct_find_property(op->ptr, "files") != NULL);
		const bool is_filepath = (RNA_struct_find_property(op->ptr, "filepath") != NULL);
		const bool is_filename = (RNA_struct_find_property(op->ptr, "filename") != NULL);
		const bool is_directory = (RNA_struct_find_property(op->ptr, "directory") != NULL);
		const bool is_relative_path = (RNA_struct_find_property(op->ptr, "relative_path") != NULL);

		BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title));

		if ((prop = RNA_struct_find_property(op->ptr, "filemode"))) {
			params->type = RNA_property_int_get(op->ptr, prop);
		}
		else {
			params->type = FILE_SPECIAL;
		}

		if (is_filepath && RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
			char name[FILE_MAX];
			RNA_string_get(op->ptr, "filepath", name);
			if (params->type == FILE_LOADLIB) {
				BLI_strncpy(params->dir, name, sizeof(params->dir));
				sfile->params->file[0] = '\0';
			}
			else {
				BLI_split_dirfile(name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
			}
		}
		else {
			if (is_directory && RNA_struct_property_is_set_ex(op->ptr, "directory", false)) {
				RNA_string_get(op->ptr, "directory", params->dir);
				sfile->params->file[0] = '\0';
			}

			if (is_filename && RNA_struct_property_is_set_ex(op->ptr, "filename", false)) {
				RNA_string_get(op->ptr, "filename", params->file);
			}
		}

		if (params->dir[0]) {
			BLI_cleanup_dir(G.main->name, params->dir);
			BLI_path_abs(params->dir, G.main->name);
		}

		if (is_directory == true && is_filename == false && is_filepath == false && is_files == false) {
			params->flag |= FILE_DIRSEL_ONLY;
		}
		else {
			params->flag &= ~FILE_DIRSEL_ONLY;
		}

		params->filter = 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_blender")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_backup")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER_BACKUP : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_image")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_IMAGE : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_movie")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_MOVIE : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_python")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_PYSCRIPT : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_font")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FTFONT : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_sound")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_SOUND : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_text")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_TEXT : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_folder")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FOLDER : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_btx")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BTX : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_collada")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_COLLADA : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_glob"))) {
			RNA_property_string_get(op->ptr, prop, params->filter_glob);
			params->filter |= (FILE_TYPE_OPERATOR | FILE_TYPE_FOLDER);
		}
		else {
			params->filter_glob[0] = '\0';
		}

		if (params->filter != 0) {
			if (U.uiflag & USER_FILTERFILEEXTS) {
				params->flag |= FILE_FILTER;
			}
			else {
				params->flag &= ~FILE_FILTER;
			}
		}

		if (U.uiflag & USER_HIDE_DOT) {
			params->flag |= FILE_HIDE_DOT;
		}
		else {
			params->flag &= ~FILE_HIDE_DOT;
		}
		

		if (params->type == FILE_LOADLIB) {
			params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0;
			params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0;
			params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0;
		}

		if ((prop = RNA_struct_find_property(op->ptr, "display_type"))) {
			params->display = RNA_property_enum_get(op->ptr, prop);
		}

		if (params->display == FILE_DEFAULTDISPLAY) {
			if (U.uiflag & USER_SHOW_THUMBNAILS) {
				if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE))
					params->display = FILE_IMGDISPLAY;
				else
					params->display = FILE_SHORTDISPLAY;
			}
			else {
				params->display = FILE_SHORTDISPLAY;
			}
		}

		if (is_relative_path) {
			if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
				if (!RNA_property_is_set_ex(op->ptr, prop, false)) {
					RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_RELPATHS) != 0);
				}
			}
		}
	}
	else {
		/* default values, if no operator */
		params->type = FILE_UNIX;
		params->flag |= FILE_HIDE_DOT;
		params->flag &= ~FILE_DIRSEL_ONLY;
		params->display = FILE_SHORTDISPLAY;
		params->filter = 0;
		params->filter_glob[0] = '\0';
	}

	/* operator has no setting for this */
	params->sort = FILE_SORT_ALPHA;
	params->active_file = -1;


	/* initialize the list with previous folders */
	if (!sfile->folders_prev)
		sfile->folders_prev = folderlist_new();

	if (!sfile->params->dir[0]) {
		if (G.main->name[0]) {
			BLI_split_dir_part(G.main->name, sfile->params->dir, sizeof(sfile->params->dir));
		}
		else {
			const char *doc_path = BKE_appdir_folder_default();
			if (doc_path) {
				BLI_strncpy(sfile->params->dir, doc_path, sizeof(sfile->params->dir));
			}
		}
	}

	folderlist_pushdir(sfile->folders_prev, sfile->params->dir);

	/* switching thumbnails needs to recalc layout [#28809] */
	if (sfile->layout) {
		sfile->layout->dirty = true;
	}

	return 1;
}
Exemple #21
0
void rna_ID_name_set(PointerRNA *ptr, const char *value)
{
	ID *id = (ID *)ptr->data;
	BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
	BLI_libblock_ensure_unique_name(G.main, id->name);
}
Exemple #22
0
void rna_ID_name_set(PointerRNA *ptr, const char *value)
{
	ID *id = (ID *)ptr->data;
	BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
	test_idbutton(id->name);
}