Esempio n. 1
0
static int paste_driver_button_exec(bContext *C, wmOperator *op)
{
  PointerRNA ptr = {{NULL}};
  PropertyRNA *prop = NULL;
  short success = 0;
  int index;

  /* try to create driver using property retrieved from UI */
  UI_context_active_but_prop_get(C, &ptr, &prop, &index);

  if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
    char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL);

    if (path) {
      /* only copy the driver for the button that this was involved for */
      success = ANIM_paste_driver(op->reports, ptr.id.data, path, index, 0);

      UI_context_update_anim_flag(C);

      DEG_relations_tag_update(CTX_data_main(C));

      DEG_id_tag_update(ptr.id.data, ID_RECALC_ANIMATION);

      WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);  // XXX

      MEM_freeN(path);
    }
  }

  /* since we're just copying, we don't really need to do anything else...*/
  return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
Esempio n. 2
0
/* Wrapper for creating a driver without knowing what the targets will be yet
 * (i.e. "manual/add later"). */
static int add_driver_button_none(bContext *C, wmOperator *op, short mapping_type)
{
  PointerRNA ptr = {{NULL}};
  PropertyRNA *prop = NULL;
  int index;
  int success = 0;

  UI_context_active_but_prop_get(C, &ptr, &prop, &index);

  if (mapping_type == CREATEDRIVER_MAPPING_NONE_ALL) {
    index = -1;
  }

  if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
    char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL);
    short flags = CREATEDRIVER_WITH_DEFAULT_DVAR;

    if (path) {
      success += ANIM_add_driver(op->reports, ptr.id.data, path, index, flags, DRIVER_TYPE_PYTHON);
      MEM_freeN(path);
    }
  }

  if (success) {
    /* send updates */
    UI_context_update_anim_flag(C);
    DEG_relations_tag_update(CTX_data_main(C));
    WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL);  // XXX

    return OPERATOR_FINISHED;
  }
  else {
    return OPERATOR_CANCELLED;
  }
}
Esempio n. 3
0
static int copy_driver_button_exec(bContext *C, wmOperator *op)
{
  PointerRNA ptr = {{NULL}};
  PropertyRNA *prop = NULL;
  short success = 0;
  int index;

  /* try to create driver using property retrieved from UI */
  UI_context_active_but_prop_get(C, &ptr, &prop, &index);

  if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
    char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL);

    if (path) {
      /* only copy the driver for the button that this was involved for */
      success = ANIM_copy_driver(op->reports, ptr.id.data, path, index, 0);

      UI_context_update_anim_flag(C);

      MEM_freeN(path);
    }
  }

  /* since we're just copying, we don't really need to do anything else...*/
  return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
Esempio n. 4
0
static int remove_driver_button_exec(bContext *C, wmOperator *op)
{
  PointerRNA ptr = {{NULL}};
  PropertyRNA *prop = NULL;
  short success = 0;
  int index;
  const bool all = RNA_boolean_get(op->ptr, "all");

  /* try to find driver using property retrieved from UI */
  UI_context_active_but_prop_get(C, &ptr, &prop, &index);

  if (all) {
    index = -1;
  }

  if (ptr.id.data && ptr.data && prop) {
    char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL);

    if (path) {
      success = ANIM_remove_driver(op->reports, ptr.id.data, path, index, 0);

      MEM_freeN(path);
    }
  }

  if (success) {
    /* send updates */
    UI_context_update_anim_flag(C);
    DEG_relations_tag_update(CTX_data_main(C));
    WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL);  // XXX
  }

  return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
Esempio n. 5
0
static int add_driver_button_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
  PointerRNA ptr = {{NULL}};
  PropertyRNA *prop = NULL;
  int index;

  /* try to find driver using property retrieved from UI */
  UI_context_active_but_prop_get(C, &ptr, &prop, &index);

  if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
    /* 1) Create a new "empty" driver for this property */
    char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL);
    short flags = CREATEDRIVER_WITH_DEFAULT_DVAR;
    short success = 0;

    if (path) {
      success += ANIM_add_driver(op->reports, ptr.id.data, path, index, flags, DRIVER_TYPE_PYTHON);
      MEM_freeN(path);
    }

    if (success) {
      /* send updates */
      UI_context_update_anim_flag(C);
      DEG_id_tag_update(ptr.id.data, ID_RECALC_COPY_ON_WRITE);
      DEG_relations_tag_update(CTX_data_main(C));
      WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL);
    }

    /* 2) Show editing panel for setting up this driver */
    /* TODO: Use a different one from the editing popever, so we can have the single/all toggle? */
    UI_popover_panel_invoke(C, "GRAPH_PT_drivers_popover", true, op->reports);
  }

  return OPERATOR_INTERFACE;
}
Esempio n. 6
0
static int add_driver_button_exec(bContext *C, wmOperator *op)
{
    PointerRNA ptr = {{NULL}};
    PropertyRNA *prop = NULL;
    int success = 0;
    int index;
    const bool all = RNA_boolean_get(op->ptr, "all");

    /* try to create driver using property retrieved from UI */
    UI_context_active_but_prop_get(C, &ptr, &prop, &index);

    if (all)
        index = -1;

    if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
        char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL);
        short flags = CREATEDRIVER_WITH_DEFAULT_DVAR;

        if (path) {
            success += ANIM_add_driver(op->reports, ptr.id.data, path, index, flags, DRIVER_TYPE_PYTHON);

            MEM_freeN(path);
        }
    }

    if (success) {
        /* send updates */
        UI_context_update_anim_flag(C);

        WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX
    }

    return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
Esempio n. 7
0
static void driverdropper_sample(bContext *C, wmOperator *op, const wmEvent *event)
{
	DriverDropper *ddr = (DriverDropper *)op->customdata;
	uiBut *but = eyedropper_get_property_button_under_mouse(C, event);
	
	short mapping_type = RNA_enum_get(op->ptr, "mapping_type");
	short flag = 0;
	
	/* we can only add a driver if we know what RNA property it corresponds to */
	if (but == NULL) {
		return;
	}
	else {
		/* Get paths for src... */
		PointerRNA *target_ptr = &but->rnapoin;
		PropertyRNA *target_prop = but->rnaprop;
		int target_index = but->rnaindex;
		
		char *target_path = RNA_path_from_ID_to_property(target_ptr, target_prop);
		
		/* ... and destination */
		char *dst_path    = BKE_animdata_driver_path_hack(C, &ddr->ptr, ddr->prop, NULL);
		
		/* Now create driver(s) */
		if (target_path && dst_path) {
			int success = ANIM_add_driver_with_target(op->reports,
			                                          ddr->ptr.id.data, dst_path, ddr->index,
			                                          target_ptr->id.data, target_path, target_index,
			                                          flag, DRIVER_TYPE_PYTHON, mapping_type);
			
			if (success) {
				/* send updates */
				UI_context_update_anim_flag(C);
				DAG_relations_tag_update(CTX_data_main(C));
				DAG_id_tag_update(ddr->ptr.id.data, OB_RECALC_OB | OB_RECALC_DATA);
				WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL);  // XXX
			}
		}
		
		/* cleanup */
		if (target_path)
			MEM_freeN(target_path);
		if (dst_path)
			MEM_freeN(dst_path);
	}
}