Ejemplo n.º 1
0
static void file_panel_operator(const bContext *C, Panel *pa)
{
	SpaceFile *sfile = CTX_wm_space_file(C);
	wmOperator *op = sfile->op;

	UI_block_func_set(uiLayoutGetBlock(pa->layout), file_draw_check_cb, NULL, NULL);

	/* Hack: temporary hide.*/
	const char *hide[] = {"filepath", "directory", "filename", "files"};
	for (int i = 0; i < ARRAY_SIZE(hide); i++) {
		PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
		if (prop) {
			RNA_def_property_flag(prop, PROP_HIDDEN);
		}
	}

	uiTemplateOperatorPropertyButs(C, pa->layout, op, '\0', UI_TEMPLATE_OP_PROPS_SHOW_EMPTY);

	for (int i = 0; i < ARRAY_SIZE(hide); i++) {
		PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
		if (prop) {
			RNA_def_property_clear_flag(prop, PROP_HIDDEN);
		}
	}

	UI_block_func_set(uiLayoutGetBlock(pa->layout), NULL, NULL, NULL);
}
Ejemplo n.º 2
0
void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op)
{
	PropertyRNA *prop;

	/* If neither of the above are set, split the filepath back */
	if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
		char filepath[FILE_MAX];
		RNA_property_string_get(op->ptr, prop, filepath);
		BLI_split_dirfile(filepath, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
	}
	else {
		if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
			RNA_property_string_get(op->ptr, prop, sfile->params->file);
		}
		if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
			RNA_property_string_get(op->ptr, prop, sfile->params->dir);
		}
	}
	
	/* we could check for relative_path property which is used when converting
	 * in the other direction but doesnt hurt to do this every time */
	BLI_path_abs(sfile->params->dir, G.main->name);

	/* XXX, files and dirs updates missing, not really so important though */
}
Ejemplo n.º 3
0
void initSnapping(TransInfo *t, wmOperator *op)
{
	ToolSettings *ts = t->settings;
	short snap_target = t->settings->snap_target;
	
	resetSnapping(t);
	
	/* if snap property exists */
	if (op && RNA_struct_find_property(op->ptr, "snap") && RNA_struct_property_is_set(op->ptr, "snap")) {
		if (RNA_boolean_get(op->ptr, "snap")) {
			t->modifiers |= MOD_SNAP;

			if (RNA_struct_property_is_set(op->ptr, "snap_target")) {
				snap_target = RNA_enum_get(op->ptr, "snap_target");
			}
			
			if (RNA_struct_property_is_set(op->ptr, "snap_point")) {
				RNA_float_get_array(op->ptr, "snap_point", t->tsnap.snapPoint);
				t->tsnap.status |= SNAP_FORCED | POINT_INIT;
			}
			
			/* snap align only defined in specific cases */
			if (RNA_struct_find_property(op->ptr, "snap_align")) {
				t->tsnap.align = RNA_boolean_get(op->ptr, "snap_align");
				RNA_float_get_array(op->ptr, "snap_normal", t->tsnap.snapNormal);
				normalize_v3(t->tsnap.snapNormal);
			}

			if (RNA_struct_find_property(op->ptr, "use_snap_project")) {
				t->tsnap.project = RNA_boolean_get(op->ptr, "use_snap_project");
			}

			if (RNA_struct_find_property(op->ptr, "use_snap_self")) {
				t->tsnap.snap_self = RNA_boolean_get(op->ptr, "use_snap_self");
			}
		}
	}
	/* use scene defaults only when transform is modal */
	else if (t->flag & T_MODAL) {
		if (ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE)) {
			if (ts->snap_flag & SCE_SNAP) {
				t->modifiers |= MOD_SNAP;
			}

			t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) != 0);
			t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0);
			t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) != 0);
			t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0);
		}

		/* for now only 3d view (others can be added if we want) */
		if (t->spacetype == SPACE_VIEW3D) {
			t->tsnap.snap_spatial_grid = ((t->settings->snap_flag & SCE_SNAP_ABS_GRID) != 0);
		}
	}
	
	t->tsnap.target = snap_target;

	initSnappingMode(t);
}
void UnitConverter::calculate_scale(Scene &sce)
{
	PointerRNA scene_ptr, unit_settings;
	PropertyRNA *system_ptr, *scale_ptr;
	RNA_id_pointer_create(&sce.id, &scene_ptr);

	unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings");
	system_ptr    = RNA_struct_find_property(&unit_settings, "system");
	scale_ptr     = RNA_struct_find_property(&unit_settings, "scale_length");

	int   type    = RNA_property_enum_get(&unit_settings, system_ptr);

	float bl_scale;

	switch (type) {
		case USER_UNIT_NONE:
			bl_scale = 1.0; // map 1 Blender unit to 1 Meter
			break;

		case USER_UNIT_METRIC:
			bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
			break;

		default :
			bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
			// it looks like the conversion to Imperial is done implicitly.
			// So nothing to do here.
			break;
	}

	float rescale[3];
	rescale[0] = rescale[1] = rescale[2] = getLinearMeter() / bl_scale;

	size_to_mat4(scale_mat4, rescale);
}
Ejemplo n.º 5
0
/**
 * Calculate a rescale factor such that the imported scene's scale
 * is preserved. I.e. 1 meter in the import will also be
 * 1 meter in the current scene.
 * XXX : I am not sure if it is correct to map 1 Blender Unit
 * to 1 Meter for unit type NONE. But it looks reasonable to me.
 */
void bc_match_scale(std::vector<Object *> *objects_done, 
                    Scene &sce,
                    UnitConverter &bc_unit)
{
	Object *ob = NULL;

	PointerRNA scene_ptr, unit_settings;
	PropertyRNA *system_ptr, *scale_ptr;
	RNA_id_pointer_create(&sce.id, &scene_ptr);

	unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings");
	system_ptr = RNA_struct_find_property(&unit_settings, "system");
	scale_ptr = RNA_struct_find_property(&unit_settings, "scale_length");

	int   type  = RNA_property_enum_get(&unit_settings, system_ptr);

	float bl_scale;
	
	switch (type) {
		case USER_UNIT_NONE:
			bl_scale = 1.0; // map 1 Blender unit to 1 Meter
			break;

		case USER_UNIT_METRIC:
			bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
			break;

		default :
			bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
			// it looks like the conversion to Imperial is done implicitly.
			// So nothing to do here.
			break;
	}
	
	float scale_conv = bc_unit.getLinearMeter() / bl_scale;

	float rescale[3];
	rescale[0] = rescale[1] = rescale[2] = scale_conv;

	float size_mat4[4][4];

	float axis_mat4[4][4];
	unit_m4(axis_mat4);

	size_to_mat4(size_mat4, rescale);

	for (std::vector<Object *>::iterator it = objects_done->begin();
			it != objects_done->end();
			++it) 
	{
		ob = *it;
		mult_m4_m4m4(ob->obmat, size_mat4, ob->obmat);
		mult_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
		BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
	}

}
Ejemplo n.º 6
0
static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
	PointerRNA ptr;
	PropertyRNA *prop;
	FileBrowseOp *fbo;
	char *str;

	uiFileBrowseContextProperty(C, &ptr, &prop);

	if(!prop)
		return OPERATOR_CANCELLED;

	str= RNA_property_string_get_alloc(&ptr, prop, NULL, 0);

	/* useful yet irritating feature, Shift+Click to open the file
	 * Alt+Click to browse a folder in the OS's browser */
	if(event->shift || event->alt) {
		PointerRNA props_ptr;

		if(event->alt) {
			char *lslash= BLI_last_slash(str);
			if(lslash)
				*lslash= '\0';
		}


		WM_operator_properties_create(&props_ptr, "WM_OT_path_open");
		RNA_string_set(&props_ptr, "filepath", str);
		WM_operator_name_call(C, "WM_OT_path_open", WM_OP_EXEC_DEFAULT, &props_ptr);
		WM_operator_properties_free(&props_ptr);

		MEM_freeN(str);
		return OPERATOR_CANCELLED;
	}
	else {
		const char *path_prop= RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
		fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
		fbo->ptr= ptr;
		fbo->prop= prop;
		op->customdata= fbo;

		RNA_string_set(op->ptr, path_prop, str);
		MEM_freeN(str);

		if(RNA_struct_find_property(op->ptr, "relative_path")) {
			if(!RNA_property_is_set(op->ptr, "relative_path")) {
				/* annoying exception!, if were dealign with the user prefs, default relative to be off */
				RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS && (ptr.data != &U));
			}
		}
		WM_event_add_fileselect(C, op);

		return OPERATOR_RUNNING_MODAL;
	}
}
Ejemplo n.º 7
0
void ED_view3d_gizmo_mesh_preselect_get_active(bContext *C,
                                               wmGizmo *gz,
                                               Base **r_base,
                                               BMElem **r_ele)
{
  ViewLayer *view_layer = CTX_data_view_layer(C);

  const int object_index = RNA_int_get(gz->ptr, "object_index");

  /* weak, allocate an array just to access the index. */
  Base *base = NULL;
  Object *obedit = NULL;
  {
    uint bases_len;
    Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
        view_layer, CTX_wm_view3d(C), &bases_len);
    if (object_index < bases_len) {
      base = bases[object_index];
      obedit = base->object;
    }
    MEM_freeN(bases);
  }

  *r_base = base;
  *r_ele = NULL;

  if (obedit) {
    BMEditMesh *em = BKE_editmesh_from_object(obedit);
    BMesh *bm = em->bm;
    PropertyRNA *prop;

    /* Ring select only defines edge, check properties exist first. */
    prop = RNA_struct_find_property(gz->ptr, "vert_index");
    const int vert_index = prop ? RNA_property_int_get(gz->ptr, prop) : -1;
    prop = RNA_struct_find_property(gz->ptr, "edge_index");
    const int edge_index = prop ? RNA_property_int_get(gz->ptr, prop) : -1;
    prop = RNA_struct_find_property(gz->ptr, "face_index");
    const int face_index = prop ? RNA_property_int_get(gz->ptr, prop) : -1;

    if (vert_index != -1) {
      *r_ele = (BMElem *)BM_vert_at_index_find(bm, vert_index);
    }
    else if (edge_index != -1) {
      *r_ele = (BMElem *)BM_edge_at_index_find(bm, edge_index);
    }
    else if (face_index != -1) {
      *r_ele = (BMElem *)BM_face_at_index_find(bm, face_index);
    }
  }
}
Ejemplo n.º 8
0
static void object_add_generic_invoke_options(bContext *C, wmOperator *op)
{
	if(RNA_struct_find_property(op->ptr, "enter_editmode")) /* optional */
		if (!RNA_property_is_set(op->ptr, "enter_editmode"))
			RNA_boolean_set(op->ptr, "enter_editmode", U.flag & USER_ADD_EDITMODE);
	
	if(!RNA_property_is_set(op->ptr, "location")) {
		float loc[3];
		
		ED_object_location_from_view(C, loc);
		RNA_float_set_array(op->ptr, "location", loc);
	}
	 
	if(!RNA_property_is_set(op->ptr, "layers")) {
		View3D *v3d = CTX_wm_view3d(C);
		Scene *scene = CTX_data_scene(C);
		int a, values[20], layer;
		
		if(v3d) {
			layer = (v3d->scenelock && !v3d->localvd)? scene->layact: v3d->layact;

			for(a=0; a<20; a++)
				values[a]= (layer & (1<<a));
		}
		else {
			layer = scene->layact;

			for(a=0; a<20; a++)
				values[a]= (layer & (1<<a));
		}
		
		RNA_boolean_set_array(op->ptr, "layers", values);
	}
}
Ejemplo n.º 9
0
static int poselib_remove_exec(bContext *C, wmOperator *op)
{
	Object *ob = get_poselib_object(C);
	bAction *act = (ob) ? ob->poselib : NULL;
	TimeMarker *marker;
	int marker_index;
	FCurve *fcu;
	PropertyRNA *prop;

	/* check if valid poselib */
	if (act == NULL) {
		BKE_report(op->reports, RPT_ERROR, "Object does not have pose lib data");
		return OPERATOR_CANCELLED;
	}

	prop = RNA_struct_find_property(op->ptr, "pose");
	if (RNA_property_is_set(op->ptr, prop)) {
		marker_index = RNA_property_enum_get(op->ptr, prop);
	}
	else {
		marker_index = act->active_marker - 1;
	}

	/* get index (and pointer) of pose to remove */
	marker = BLI_findlink(&act->markers, marker_index);
	if (marker == NULL) {
		BKE_reportf(op->reports, RPT_ERROR, "Invalid pose specified %d", marker_index);
		return OPERATOR_CANCELLED;
	}
	
	/* remove relevant keyframes */
	for (fcu = act->curves.first; fcu; fcu = fcu->next) {
		BezTriple *bezt;
		unsigned int i;
		
		if (fcu->bezt) {
			for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
				/* check if remove */
				if (IS_EQF(bezt->vec[1][0], (float)marker->frame)) {
					delete_fcurve_key(fcu, i, 1);
					break;
				}
			}
		}
	}
	
	/* remove poselib from list */
	BLI_freelinkN(&act->markers, marker);
	
	/* fix active pose number */
	act->active_marker = 0;
	
	/* send notifiers for this - using keyframe editing notifiers, since action 
	 * may be being shown in anim editors as active action 
	 */
	WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
	
	/* done */
	return OPERATOR_FINISHED;
}
Ejemplo n.º 10
0
static int rna_ui_get_enum_icon(bContext *C, PointerRNA *ptr, const char *propname, const char *identifier)
{
	PropertyRNA *prop = NULL;
	EnumPropertyItem *items = NULL, *item;
	bool free;
	int icon = ICON_NONE;

	prop = RNA_struct_find_property(ptr, propname);
	if (!prop || (RNA_property_type(prop) != PROP_ENUM)) {
		RNA_warning("Property not found or not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
		return icon;
	}

	RNA_property_enum_items(C, ptr, prop, &items, NULL, &free);

	if (items) {
		for (item = items; item->identifier; item++) {
			if (item->identifier[0] && STREQ(item->identifier, identifier)) {
				icon = item->icon;
				break;
			}
		}
		if (free) {
			MEM_freeN(items);
		}
	}

	return icon;
}
Ejemplo n.º 11
0
int wm_homefile_read_exec(bContext *C, wmOperator *op)
{
	const bool from_memory = (STREQ(op->type->idname, "WM_OT_read_factory_settings"));
	char filepath_buf[FILE_MAX];
	const char *filepath = NULL;

	if (!from_memory) {
		PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath");

		/* This can be used when loading of a start-up file should only change
		 * the scene content but keep the blender UI as it is. */
		wm_open_init_load_ui(op, true);
		BKE_BIT_TEST_SET(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);

		if (RNA_property_is_set(op->ptr, prop)) {
			RNA_property_string_get(op->ptr, prop, filepath_buf);
			filepath = filepath_buf;
			if (BLI_access(filepath, R_OK)) {
				BKE_reportf(op->reports, RPT_ERROR, "Can't read alternative start-up file: '%s'", filepath);
				return OPERATOR_CANCELLED;
			}
		}
	}
	else {
		/* always load UI for factory settings (prefs will re-init) */
		G.fileflags &= ~G_FILE_NO_UI;
	}

	return wm_homefile_read(C, op->reports, from_memory, filepath) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
Ejemplo n.º 12
0
static void edbm_bevel_update_header(bContext *C, wmOperator *op)
{
	const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Mode: %s (M), Clamp Overlap: %s (C), "
	                         "Vertex Only: %s (V), Profile Control: %s (P), Offset: %s, Segments: %d, Profile: %.3f");

	char msg[UI_MAX_DRAW_STR];
	ScrArea *sa = CTX_wm_area(C);
	Scene *sce = CTX_data_scene(C);

	if (sa) {
		BevelData *opdata = op->customdata;
		char offset_str[NUM_STR_REP_LEN];
		const char *type_str;
		PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");

		if (hasNumInput(&opdata->num_input[OFFSET_VALUE])) {
			outputNumInput(&opdata->num_input[OFFSET_VALUE], offset_str, &sce->unit);
		}
		else {
			BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset"));
		}

		RNA_property_enum_name_gettexted(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &type_str);

		BLI_snprintf(msg, sizeof(msg), str, type_str,
		             WM_bool_as_string(RNA_boolean_get(op->ptr, "clamp_overlap")),
		             WM_bool_as_string(RNA_boolean_get(op->ptr, "vertex_only")),
		             WM_bool_as_string(opdata->value_mode == PROFILE_VALUE),
		             offset_str, RNA_int_get(op->ptr, "segments"), RNA_float_get(op->ptr, "profile"));

		ED_area_headerprint(sa, msg);
	}
}
Ejemplo n.º 13
0
/**
 * Special hack for MESH_OT_loopcut_slide so we get back to the selection mode
 */
static void transformops_loopsel_hack(bContext *C, wmOperator *op)
{
	if (op->type->idname == OP_EDGE_SLIDE) {
		if (op->opm && op->opm->opm && op->opm->opm->prev) {
			wmOperator *op_prev = op->opm->opm->prev;
			Scene *scene = CTX_data_scene(C);
			int mesh_select_mode[3];
			PropertyRNA *prop = RNA_struct_find_property(op_prev->ptr, "mesh_select_mode_init");

			if (prop && RNA_property_is_set(op_prev->ptr, prop)) {
				ToolSettings *ts = scene->toolsettings;
				short selectmode_orig;

				RNA_property_boolean_get_array(op_prev->ptr, prop, mesh_select_mode);
				selectmode_orig = ((mesh_select_mode[0] ? SCE_SELECT_VERTEX : 0) |
				                   (mesh_select_mode[1] ? SCE_SELECT_EDGE   : 0) |
				                   (mesh_select_mode[2] ? SCE_SELECT_FACE   : 0));

				/* still switch if we were originally in face select mode */
				if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
					BMEditMesh *em = BKE_editmesh_from_object(scene->obedit);
					em->selectmode = ts->selectmode = selectmode_orig;
					EDBM_selectmode_set(em);
				}
			}
		}
	}
}
Ejemplo n.º 14
0
static const char *rna_ui_get_enum_description(
        bContext *C, PointerRNA *ptr, const char *propname,
        const char *identifier)
{
	PropertyRNA *prop = NULL;
	const EnumPropertyItem *items = NULL, *item;
	bool free;
	const char *desc = "";

	prop = RNA_struct_find_property(ptr, propname);
	if (!prop || (RNA_property_type(prop) != PROP_ENUM)) {
		RNA_warning("Property not found or not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
		return desc;
	}

	RNA_property_enum_items_gettexted(C, ptr, prop, &items, NULL, &free);

	if (items) {
		for (item = items; item->identifier; item++) {
			if (item->identifier[0] && STREQ(item->identifier, identifier)) {
				desc = item->description;
				break;
			}
		}
		if (free) {
			MEM_freeN((void *)items);
		}
	}

	return desc;
}
Ejemplo n.º 15
0
static void rna_uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, const char *name, const char *text_ctxt,
                        int translate, int icon, int expand, int slider, int toggle, int icon_only, int event,
                        int full_event, int emboss, int index, int icon_value)
{
	PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
	int flag = 0;

	if (!prop) {
		RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
		return;
	}

	if (icon_value && !icon) {
		icon = icon_value;
	}

	/* Get translated name (label). */
	name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);

	flag |= (slider) ? UI_ITEM_R_SLIDER : 0;
	flag |= (expand) ? UI_ITEM_R_EXPAND : 0;
	flag |= (toggle) ? UI_ITEM_R_TOGGLE : 0;
	flag |= (icon_only) ? UI_ITEM_R_ICON_ONLY : 0;
	flag |= (event) ? UI_ITEM_R_EVENT : 0;
	flag |= (full_event) ? UI_ITEM_R_FULL_EVENT : 0;
	flag |= (emboss) ? 0 : UI_ITEM_R_NO_BG;

	uiItemFullR(layout, ptr, prop, index, 0, flag, name, icon);
}
Ejemplo n.º 16
0
/**
 * Invokes a new pie menu for a new level.
 */
static void ui_pie_menu_level_invoke(bContext *C, void *argN, void *arg2)
{
	EnumPropertyItem *item_array = (EnumPropertyItem *)argN;
	PieMenuLevelData *lvl = (PieMenuLevelData *)arg2;
	wmWindow *win = CTX_wm_window(C);

	uiPieMenu *pie = UI_pie_menu_begin(C, IFACE_(lvl->title), lvl->icon, win->eventstate);
	uiLayout *layout = UI_pie_menu_layout(pie);

	layout = uiLayoutRadial(layout);

	PointerRNA ptr;

	WM_operator_properties_create_ptr(&ptr, lvl->ot);
	/* so the context is passed to itemf functions (some need it) */
	WM_operator_properties_sanitize(&ptr, false);
	PropertyRNA *prop = RNA_struct_find_property(&ptr, lvl->propname);

	if (prop) {
		uiItemsFullEnumO_items(
		        layout, lvl->ot, ptr, prop, lvl->properties, lvl->context, lvl->flag,
		        item_array, lvl->totitem);
	}
	else {
		RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), lvl->propname);
	}

	UI_pie_menu_end(C, pie);
}
Ejemplo n.º 17
0
static int node_animation_properties(bNodeTree *ntree, bNode *node)
{
	bNodeSocket *sock;
	const ListBase *lb;
	Link *link;
	PointerRNA ptr;
	PropertyRNA *prop;

	/* check to see if any of the node's properties have fcurves */
	RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr);
	lb = RNA_struct_type_properties(ptr.type);

	for (link = lb->first; link; link = link->next) {
		prop = (PropertyRNA *)link;

		if (RNA_property_animated(&ptr, prop)) {
			nodeUpdate(ntree, node);
			return 1;
		}
	}

	/* now check node sockets */
	for (sock = node->inputs.first; sock; sock = sock->next) {
		RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
		prop = RNA_struct_find_property(&ptr, "default_value");

		if (RNA_property_animated(&ptr, prop)) {
			nodeUpdate(ntree, node);
			return 1;
		}
	}

	return 0;
}
Ejemplo n.º 18
0
/* helper for apply() - perform sliding for custom properties */
static void pose_slide_apply_props(tPoseSlideOp *pso, tPChanFCurveLink *pfl)
{
	PointerRNA ptr = {{NULL}};
	LinkData *ld;
	int len = strlen(pfl->pchan_path);
	
	/* setup pointer RNA for resolving paths */
	RNA_pointer_create(NULL, &RNA_PoseBone, pfl->pchan, &ptr);
	
	/* custom properties are just denoted using ["..."][etc.] after the end of the base path, 
	 * so just check for opening pair after the end of the path
	 */
	for (ld = pfl->fcurves.first; ld; ld = ld->next) {
		FCurve *fcu = (FCurve *)ld->data;
		char *bPtr, *pPtr;
		
		if (fcu->rna_path == NULL)
			continue;
		
		/* do we have a match? 
		 *	- bPtr is the RNA Path with the standard part chopped off
		 *	- pPtr is the chunk of the path which is left over
		 */
		bPtr = strstr(fcu->rna_path, pfl->pchan_path) + len;
		pPtr = strstr(bPtr, "[\"");   /* dummy " for texteditor bugs */
		
		if (pPtr) {
			/* use RNA to try and get a handle on this property, then, assuming that it is just
			 * numerical, try and grab the value as a float for temp editing before setting back
			 */
			PropertyRNA *prop = RNA_struct_find_property(&ptr, pPtr);
			
			if (prop) {
				switch (RNA_property_type(prop)) {
					case PROP_FLOAT:
					{
						float tval = RNA_property_float_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_float_set(&ptr, prop, tval);
						break;
					}
					case PROP_BOOLEAN:
					case PROP_ENUM:
					case PROP_INT:
					{
						float tval = (float)RNA_property_int_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_int_set(&ptr, prop, (int)tval);
						break;
					}
					default:
						/* cannot handle */
						//printf("Cannot Pose Slide non-numerical property\n");
						break;
				}
			}
		}
	}
}
Ejemplo n.º 19
0
static int file_browse_exec(bContext *C, wmOperator *op)
{
	FileBrowseOp *fbo = op->customdata;
	ID *id;
	char *str, path[FILE_MAX];
	const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
	
	if (RNA_struct_property_is_set(op->ptr, path_prop) == 0 || fbo == NULL)
		return OPERATOR_CANCELLED;
	
	str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0);

	/* add slash for directories, important for some properties */
	if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
		int is_relative = RNA_boolean_get(op->ptr, "relative_path");
		id = fbo->ptr.id.data;

		BLI_strncpy(path, str, FILE_MAX);
		BLI_path_abs(path, id ? ID_BLEND_PATH(G.main, id) : G.main->name);
		
		if (BLI_is_dir(path)) {
			/* do this first so '//' isnt converted to '//\' on windows */
			BLI_add_slash(path);
			if (is_relative) {
				BLI_strncpy(path, str, FILE_MAX);
				BLI_path_rel(path, G.main->name);
				str = MEM_reallocN(str, strlen(path) + 2);
				BLI_strncpy(str, path, FILE_MAX);
			}
			else {
				str = MEM_reallocN(str, strlen(str) + 2);
			}
		}
		else {
			char * const lslash = (char *)BLI_last_slash(str);
			if (lslash) lslash[1] = '\0';
		}
	}

	RNA_property_string_set(&fbo->ptr, fbo->prop, str);
	RNA_property_update(C, &fbo->ptr, fbo->prop);
	MEM_freeN(str);


	/* special, annoying exception, filesel on redo panel [#26618] */
	{
		wmOperator *redo_op = WM_operator_last_redo(C);
		if (redo_op) {
			if (fbo->ptr.data == redo_op->ptr->data) {
				ED_undo_operator_repeat(C, redo_op);
			}
		}
	}

	MEM_freeN(op->customdata);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 20
0
static bool wm_stereo3d_set_properties(bContext *UNUSED(C), wmOperator *op)
{
	Stereo3dData *s3dd = op->customdata;
	Stereo3dFormat *s3d = &s3dd->stereo3d_format;
	PropertyRNA *prop;
	bool is_set = false;

	prop = RNA_struct_find_property(op->ptr, "display_mode");
	if (RNA_property_is_set(op->ptr, prop)) {
		s3d->display_mode = RNA_property_enum_get(op->ptr, prop);
		is_set = true;
	}

	prop = RNA_struct_find_property(op->ptr, "anaglyph_type");
	if (RNA_property_is_set(op->ptr, prop)) {
		s3d->anaglyph_type = RNA_property_enum_get(op->ptr, prop);
		is_set = true;
	}

	prop = RNA_struct_find_property(op->ptr, "interlace_type");
	if (RNA_property_is_set(op->ptr, prop)) {
		s3d->interlace_type = RNA_property_enum_get(op->ptr, prop);
		is_set = true;
	}

	prop = RNA_struct_find_property(op->ptr, "use_interlace_swap");
	if (RNA_property_is_set(op->ptr, prop)) {
		if (RNA_property_boolean_get(op->ptr, prop))
			s3d->flag |= S3D_INTERLACE_SWAP;
		else
			s3d->flag &= ~S3D_INTERLACE_SWAP;
		is_set = true;
	}

	prop = RNA_struct_find_property(op->ptr, "use_sidebyside_crosseyed");
	if (RNA_property_is_set(op->ptr, prop)) {
		if (RNA_property_boolean_get(op->ptr, prop))
			s3d->flag |= S3D_SIDEBYSIDE_CROSSEYED;
		else
			s3d->flag &= ~S3D_SIDEBYSIDE_CROSSEYED;
		is_set = true;
	}

	return is_set;
}
Ejemplo n.º 21
0
int ED_object_add_generic_get_opts(bContext *C, wmOperator *op, float *loc, float *rot, int *enter_editmode, unsigned int *layer)
{
	View3D *v3d = CTX_wm_view3d(C);
	int a, layer_values[20];
	int view_align;
	
	*enter_editmode = FALSE;
	if(RNA_struct_find_property(op->ptr, "enter_editmode") && RNA_boolean_get(op->ptr, "enter_editmode")) {
		*enter_editmode = TRUE;
	}

	if(RNA_property_is_set(op->ptr, "layers")) {
		RNA_boolean_get_array(op->ptr, "layers", layer_values);
		*layer= 0;
		for(a=0; a<20; a++) {
			if(layer_values[a])
				*layer |= (1 << a);
			else
				*layer &= ~(1 << a);
		}
	}
	else {
		/* not set, use the scenes layers */
		Scene *scene = CTX_data_scene(C);
		*layer = scene->layact;
	}

	/* in local view we additionally add local view layers,
	   not part of operator properties */
	if(v3d && v3d->localvd)
		*layer |= v3d->lay;

	if(RNA_property_is_set(op->ptr, "rotation"))
		view_align = FALSE;
	else if (RNA_property_is_set(op->ptr, "view_align"))
		view_align = RNA_boolean_get(op->ptr, "view_align");
	else {
		view_align = U.flag & USER_ADD_VIEWALIGNED;
		RNA_boolean_set(op->ptr, "view_align", view_align);
	}
	
	if (view_align)
		ED_object_rotation_from_view(C, rot);
	else
		RNA_float_get_array(op->ptr, "rotation", rot);
	

	RNA_float_get_array(op->ptr, "location", loc);

	if(*layer == 0) {
		BKE_report(op->reports, RPT_ERROR, "Property 'layer' has no values set");
		return 0;
	}

	return 1;
}
Ejemplo n.º 22
0
int file_directory_new_exec(bContext *C, wmOperator *op)
{
	char name[FILE_MAXFILE];
	char path[FILE_MAX];
	int generate_name = 1;

	wmWindowManager *wm = CTX_wm_manager(C);
	SpaceFile *sfile = CTX_wm_space_file(C);
	
	if (!sfile->params) {
		BKE_report(op->reports, RPT_WARNING, "No parent directory given");
		return OPERATOR_CANCELLED;
	}
	
	path[0] = '\0';

	if (RNA_struct_find_property(op->ptr, "directory")) {
		RNA_string_get(op->ptr, "directory", path);
		if (path[0] != '\0') generate_name = 0;
	}

	if (generate_name) {
		/* create a new, non-existing folder name */
		if (!new_folder_path(sfile->params->dir, path, name)) {
			BKE_report(op->reports, RPT_ERROR, "Could not create new folder name");
			return OPERATOR_CANCELLED;
		}
	}

	/* create the file */
	BLI_dir_create_recursive(path);

	if (!BLI_exists(path)) {
		BKE_report(op->reports, RPT_ERROR, "Could not create new folder");
		return OPERATOR_CANCELLED;
	}

	/* now remember file to jump into editing */
	BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);

	/* set timer to smoothly view newly generated file */
	sfile->smoothscroll_timer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER1, 1.0 / 1000.0);  /* max 30 frs/sec */
	sfile->scroll_offset = 0;

	/* reload dir to make sure we're seeing what's in the directory */
	ED_fileselect_clear(wm, sfile);

	if (RNA_boolean_get(op->ptr, "open")) {
		BLI_strncpy(sfile->params->dir, path, sizeof(sfile->params->dir));
		file_change_dir(C, 1);
	}

	WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 23
0
/* invoke callback which presents a list of bone-groups for the user to choose from */
static int pose_groups_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
	Object *ob = ED_pose_object_from_context(C);
	bPose *pose;
	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "type");

	uiPopupMenu *pup;
	uiLayout *layout;
	bActionGroup *grp;
	int i;

	/* only continue if there's an object, and a pose there too */
	if (ELEM(NULL, ob, ob->pose))
		return OPERATOR_CANCELLED;
	pose = ob->pose;

	/* If group index is set, try to use it! */
	if (RNA_property_is_set(op->ptr, prop)) {
		const int num_groups = BLI_listbase_count(&pose->agroups);
		const int group = RNA_property_int_get(op->ptr, prop);

		/* just use the active group index, and call the exec callback for the calling operator */
		if (group > 0 && group <= num_groups) {
			return op->type->exec(C, op);
		}
	}

	/* if there's no active group (or active is invalid), create a new menu to find it */
	if (pose->active_group <= 0) {
		/* create a new menu, and start populating it with group names */
		pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE);
		layout = UI_popup_menu_layout(pup);

		/* special entry - allow to create new group, then use that
		 *	(not to be used for removing though)
		 */
		if (strstr(op->idname, "assign")) {
			uiItemIntO(layout, "New Group", ICON_NONE, op->idname, "type", 0);
			uiItemS(layout);
		}

		/* add entries for each group */
		for (grp = pose->agroups.first, i = 1; grp; grp = grp->next, i++)
			uiItemIntO(layout, grp->name, ICON_NONE, op->idname, "type", i);

		/* finish building the menu, and process it (should result in calling self again) */
		UI_popup_menu_end(C, pup);

		return OPERATOR_INTERFACE;
	}
	else {
		/* just use the active group index, and call the exec callback for the calling operator */
		RNA_int_set(op->ptr, "type", pose->active_group);
		return op->type->exec(C, op);
	}
}
Ejemplo n.º 24
0
static bool render_layer_exclude_animated(Scene *scene, SceneRenderLayer *srl)
{
	PointerRNA ptr;
	PropertyRNA *prop;

	RNA_pointer_create(&scene->id, &RNA_SceneRenderLayer, srl, &ptr);
	prop = RNA_struct_find_property(&ptr, "layers_exclude");

	return RNA_property_animated(&ptr, prop);
}
Ejemplo n.º 25
0
static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr)
{
	bool is_save_internal;
	bScreen *sc = CTX_wm_screen(C);

	bkr->ob = CTX_data_active_object(C);
	bkr->main = CTX_data_main(C);
	bkr->scene = CTX_data_scene(C);
	bkr->sa = sc ? BKE_screen_find_big_area(sc, SPACE_IMAGE, 10) : NULL;

	bkr->pass_type = RNA_enum_get(op->ptr, "type");
	bkr->pass_filter = RNA_enum_get(op->ptr, "pass_filter");
	bkr->margin = RNA_int_get(op->ptr, "margin");

	bkr->save_mode = RNA_enum_get(op->ptr, "save_mode");
	is_save_internal = (bkr->save_mode == R_BAKE_SAVE_INTERNAL);

	bkr->is_clear = RNA_boolean_get(op->ptr, "use_clear");
	bkr->is_split_materials = (!is_save_internal) && RNA_boolean_get(op->ptr, "use_split_materials");
	bkr->is_automatic_name = RNA_boolean_get(op->ptr, "use_automatic_name");
	bkr->is_selected_to_active = RNA_boolean_get(op->ptr, "use_selected_to_active");
	bkr->is_cage = RNA_boolean_get(op->ptr, "use_cage");
	bkr->cage_extrusion = RNA_float_get(op->ptr, "cage_extrusion");

	bkr->normal_space = RNA_enum_get(op->ptr, "normal_space");
	bkr->normal_swizzle[0] = RNA_enum_get(op->ptr, "normal_r");
	bkr->normal_swizzle[1] = RNA_enum_get(op->ptr, "normal_g");
	bkr->normal_swizzle[2] = RNA_enum_get(op->ptr, "normal_b");

	bkr->width = RNA_int_get(op->ptr, "width");
	bkr->height = RNA_int_get(op->ptr, "height");
	bkr->identifier = "";

	RNA_string_get(op->ptr, "uv_layer", bkr->uv_layer);

	RNA_string_get(op->ptr, "cage_object", bkr->custom_cage);

	if ((!is_save_internal) && bkr->is_automatic_name) {
		PropertyRNA *prop = RNA_struct_find_property(op->ptr, "type");
		RNA_property_enum_identifier(C, op->ptr, prop, bkr->pass_type, &bkr->identifier);
	}

	CTX_data_selected_objects(C, &bkr->selected_objects);

	bkr->reports = op->reports;

	bkr->result = OPERATOR_CANCELLED;

	bkr->render = RE_NewSceneRender(bkr->scene);

	/* XXX hack to force saving to always be internal. Whether (and how) to support
	 * external saving will be addressed later */
	bkr->save_mode = R_BAKE_SAVE_INTERNAL;
}
Ejemplo n.º 26
0
void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
{
	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "load_ui");
	if (!RNA_property_is_set(op->ptr, prop)) {
		bool value = use_prefs ?
		             ((U.flag & USER_FILENOUI) == 0) :
		             ((G.fileflags & G_FILE_NO_UI) == 0);

		RNA_property_boolean_set(op->ptr, prop, value);
	}
}
Ejemplo n.º 27
0
static void rna_uiItemPointerR(
        uiLayout *layout, struct PointerRNA *ptr, const char *propname,
        struct PointerRNA *searchptr, const char *searchpropname,
        const char *name, const char *text_ctxt, bool translate, int icon)
{
	PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
	if (!prop) {
		RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
		return;
	}
	PropertyRNA *searchprop = RNA_struct_find_property(searchptr, searchpropname);
	if (!searchprop) {
		RNA_warning("property not found: %s.%s", RNA_struct_identifier(searchptr->type), searchpropname);
		return;
	}

	/* Get translated name (label). */
	name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);

	uiItemPointerR_prop(layout, ptr, prop, searchptr, searchprop, name, icon);
}
Ejemplo n.º 28
0
static void buttons_texture_modifier_foreach(void *userData, Object *ob, ModifierData *md, const char *propname)
{
    PointerRNA ptr;
    PropertyRNA *prop;
    ListBase *users = userData;

    RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
    prop = RNA_struct_find_property(&ptr, propname);

    buttons_texture_user_property_add(users, &ob->id, ptr, prop,
                                      "Modifiers", RNA_struct_ui_icon(ptr.type), md->name);
}
Ejemplo n.º 29
0
static int controller_add_exec(bContext *C, wmOperator *op)
{
	Object *ob;
	bController *cont;
	PointerRNA cont_ptr;
	PropertyRNA *prop;
	const char *cont_name;
	int bit;
	char name[MAX_NAME];
	int type = RNA_enum_get(op->ptr, "type");

	ob = edit_object_property_get(C, op);
	if (!ob)
		return OPERATOR_CANCELLED;
	
	cont = new_controller(type);
	BLI_addtail(&(ob->controllers), cont);
	
	/* set the controller name based on rna type enum */
	RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &cont_ptr);
	prop = RNA_struct_find_property(&cont_ptr, "type");

	RNA_string_get(op->ptr, "name", name);
	if (*name) {
		BLI_strncpy(cont->name, name, sizeof(cont->name));
	}
	else {
		RNA_property_enum_name(C, &cont_ptr, prop, RNA_property_enum_get(&cont_ptr, prop), &cont_name);
		BLI_strncpy(cont->name, cont_name, sizeof(cont->name));
	}

	BLI_uniquename(&ob->controllers, cont, DATA_("Controller"), '.', offsetof(bController, name), sizeof(cont->name));

	/* set the controller state mask from the current object state.
	 * A controller is always in a single state, so select the lowest bit set
	 * from the object state */
	for (bit = 0; bit < OB_MAX_STATES; bit++) {
		if (ob->state & (1 << bit))
			break;
	}
	cont->state_mask = (1 << bit);
	if (cont->state_mask == 0) {
		/* shouldn't happen, object state is never 0 */
		cont->state_mask = 1;
	}
	
	ob->scaflag |= OB_SHOWCONT;
	
	WM_event_add_notifier(C, NC_LOGIC, NULL);
	
	return OPERATOR_FINISHED;
}
Ejemplo n.º 30
0
void wm_open_init_use_scripts(wmOperator *op, bool use_prefs)
{
	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
	if (!RNA_property_is_set(op->ptr, prop)) {
		/* use G_SCRIPT_AUTOEXEC rather than the userpref because this means if
		 * the flag has been disabled from the command line, then opening
		 * from the menu wont enable this setting. */
		bool value = use_prefs ?
		             ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) :
		             ((G.f & G_SCRIPT_AUTOEXEC) != 0);

		RNA_property_boolean_set(op->ptr, prop, value);
	}
}