示例#1
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);
}
示例#2
0
static int workspace_append_activate_exec(bContext *C, wmOperator *op)
{
  Main *bmain = CTX_data_main(C);
  char idname[MAX_ID_NAME - 2], filepath[FILE_MAX];

  if (!RNA_struct_property_is_set(op->ptr, "idname") ||
      !RNA_struct_property_is_set(op->ptr, "filepath")) {
    return OPERATOR_CANCELLED;
  }
  RNA_string_get(op->ptr, "idname", idname);
  RNA_string_get(op->ptr, "filepath", filepath);

  if (workspace_append(C, filepath, idname) != OPERATOR_CANCELLED) {
    WorkSpace *appended_workspace = BLI_findstring(
        &bmain->workspaces, idname, offsetof(ID, name) + 2);
    BLI_assert(appended_workspace != NULL);

    if (appended_workspace) {
      /* Reorder to last position. */
      BKE_id_reorder(&bmain->workspaces, &appended_workspace->id, NULL, true);

      /* Changing workspace changes context. Do delayed! */
      WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_SET, appended_workspace);

      return OPERATOR_FINISHED;
    }
  }

  return OPERATOR_CANCELLED;
}
static void screen_render_scene_layer_set(wmOperator *op, Main *mainp, Scene **scene, SceneRenderLayer **srl)
{
	/* single layer re-render */
	if (RNA_struct_property_is_set(op->ptr, "scene")) {
		Scene *scn;
		char scene_name[MAX_ID_NAME - 2];

		RNA_string_get(op->ptr, "scene", scene_name);
		scn = (Scene *)BLI_findstring(&mainp->scene, scene_name, offsetof(ID, name) + 2);
		
		if (scn) {
			/* camera switch wont have updated */
			scn->r.cfra = (*scene)->r.cfra;
			BKE_scene_camera_switch_update(scn);

			*scene = scn;
		}
	}

	if (RNA_struct_property_is_set(op->ptr, "layer")) {
		SceneRenderLayer *rl;
		char rl_name[RE_MAXNAME];

		RNA_string_get(op->ptr, "layer", rl_name);
		rl = (SceneRenderLayer *)BLI_findstring(&(*scene)->r.layers, rl_name, offsetof(SceneRenderLayer, name));
		
		if (rl)
			*srl = rl;
	}
}
示例#4
0
static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
  if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) {
    RNA_boolean_set(op->ptr, "as_background_job", true);
  }

  RNA_boolean_set(op->ptr, "init_scene_frame_range", true);

  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
    Main *bmain = CTX_data_main(C);
    char filepath[FILE_MAX];

    if (BKE_main_blendfile_path(bmain)[0] == '\0') {
      BLI_strncpy(filepath, "untitled", sizeof(filepath));
    }
    else {
      BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
    }

    BLI_path_extension_replace(filepath, sizeof(filepath), ".abc");
    RNA_string_set(op->ptr, "filepath", filepath);
  }

  WM_event_add_fileselect(C, op);

  return OPERATOR_RUNNING_MODAL;

  UNUSED_VARS(event);
}
示例#5
0
static int open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
	SpaceClip *sc = CTX_wm_space_clip(C);
	char path[FILE_MAX];
	MovieClip *clip = NULL;

	if (sc)
		clip = ED_space_clip_get_clip(sc);

	if (clip) {
		strncpy(path, clip->name, sizeof(path));

		BLI_path_abs(path, G.main->name);
		BLI_parent_dir(path);
	}
	else {
		strncpy(path, U.textudir, sizeof(path));
	}

	if (RNA_struct_property_is_set(op->ptr, "files"))
		return open_exec(C, op);

	if (!RNA_struct_property_is_set(op->ptr, "relative_path"))
		RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);

	open_init(C, op);

	clip_filesel(C, op, path);

	return OPERATOR_RUNNING_MODAL;
}
示例#6
0
void ED_view3d_operator_properties_viewmat_set(bContext *C, wmOperator *op)
{
	ARegion *ar = CTX_wm_region(C);
	RegionView3D *rv3d = ED_view3d_context_rv3d(C);

	if (!RNA_struct_property_is_set(op->ptr, "region_width"))
		RNA_int_set(op->ptr, "region_width", ar->winx);

	if (!RNA_struct_property_is_set(op->ptr, "region_height"))
		RNA_int_set(op->ptr, "region_height", ar->winy);

	if (!RNA_struct_property_is_set(op->ptr, "perspective_matrix"))
		RNA_float_set_array(op->ptr, "perspective_matrix", (float *)rv3d->persmat);
}
示例#7
0
static int rigidbody_world_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
	if (!RNA_struct_property_is_set(op->ptr, "relative_path"))
		RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0);

	if (RNA_struct_property_is_set(op->ptr, "filepath"))
		return rigidbody_world_export_exec(C, op);

	// TODO: use the actual rigidbody world's name + .bullet instead of this temp crap
	RNA_string_set(op->ptr, "filepath", "rigidbodyworld_export.bullet");
	WM_event_add_fileselect(C, op); 

	return OPERATOR_RUNNING_MODAL;
}
示例#8
0
/* op->invoke, opens fileselect if path property not set, otherwise executes */
static int wm_alembic_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
  if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) {
    RNA_boolean_set(op->ptr, "as_background_job", true);
  }
  return WM_operator_filesel(C, op, event);
}
示例#9
0
/* function used for WM_OT_save_mainfile too */
static int wm_collada_import_exec(bContext *C, wmOperator *op)
{
    char filename[FILE_MAX];
    int import_units;
    int find_chains;
    int fix_orientation;
    int  min_chain_length;

    if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
        BKE_report(op->reports, RPT_ERROR, "No filename given");
        return OPERATOR_CANCELLED;
    }

    /* Options panel */
    import_units     = RNA_boolean_get(op->ptr, "import_units");
    find_chains      = RNA_boolean_get(op->ptr, "find_chains");
    fix_orientation  = RNA_boolean_get(op->ptr, "fix_orientation");
    min_chain_length = RNA_int_get(op->ptr, "min_chain_length");

    RNA_string_get(op->ptr, "filepath", filename);
    if (collada_import(
                C, filename,
                import_units,
                find_chains,
                fix_orientation,
                min_chain_length))
    {
        return OPERATOR_FINISHED;
    }
    else {
        BKE_report(op->reports, RPT_ERROR, "Errors found during parsing COLLADA document (see console for details)");
        return OPERATOR_CANCELLED;
    }
}
示例#10
0
static int multires_external_save_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
	Object *ob = ED_object_active_context(C);
	MultiresModifierData *mmd;
	Mesh *me= ob->data;
	char path[FILE_MAX];

	if (!edit_modifier_invoke_properties(C, op))
		return OPERATOR_CANCELLED;
	
	mmd = (MultiresModifierData *)edit_modifier_property_get(op, ob, eModifierType_Multires);
	
	if (!mmd)
		return OPERATOR_CANCELLED;
	
	if(CustomData_external_test(&me->fdata, CD_MDISPS))
		return OPERATOR_CANCELLED;

	if(RNA_struct_property_is_set(op->ptr, "filepath"))
		return multires_external_save_exec(C, op);
	
	op->customdata= me;

	BLI_snprintf(path, sizeof(path), "//%s.btx", me->id.name+2);
	RNA_string_set(op->ptr, "filepath", path);
	
	WM_event_add_fileselect(C, op);

	return OPERATOR_RUNNING_MODAL;
}
示例#11
0
static int wm_alembic_import_exec(bContext *C, wmOperator *op)
{
	if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
		BKE_report(op->reports, RPT_ERROR, "No filename given");
		return OPERATOR_CANCELLED;
	}

	char filename[FILE_MAX];
	RNA_string_get(op->ptr, "filepath", filename);

	const float scale = RNA_float_get(op->ptr, "scale");
	const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence");
	const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range");
	const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
	const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job");

	int offset = 0;
	int sequence_len = 1;

	if (is_sequence) {
		sequence_len = get_sequence_len(filename, &offset);
		if (sequence_len < 0) {
			BKE_report(op->reports, RPT_ERROR, "Unable to determine ABC sequence length");
			return OPERATOR_CANCELLED;
		}
	}

	bool ok = ABC_import(C, filename, scale, is_sequence, set_frame_range,
	                     sequence_len, offset, validate_meshes,
	                     as_background_job);

	return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
示例#12
0
/* note: also check ed_undo_step() in top if you change notifiers */
static int undo_history_exec(bContext *C, wmOperator *op)
{
	if (RNA_struct_property_is_set(op->ptr, "item")) {
		int undosys = get_undo_system(C);
		int item = RNA_int_get(op->ptr, "item");
		
		if (undosys == UNDOSYSTEM_PARTICLE) {
			PE_undo_number(CTX_data_scene(C), item);
		}
		else if (undosys == UNDOSYSTEM_EDITMODE) {
			undo_editmode_number(C, item + 1);
			WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
		}
		else if (undosys == UNDOSYSTEM_IMAPAINT) {
			ED_undo_paint_step_num(C, UNDO_PAINT_IMAGE, item );
		}
		else {
			ED_viewport_render_kill_jobs(C, true);
			BKE_undo_number(C, item);
			WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, CTX_data_scene(C));
		}
		WM_event_add_notifier(C, NC_WINDOW, NULL);
		
		return OPERATOR_FINISHED;
	}
	return OPERATOR_CANCELLED;
}
示例#13
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;
}
示例#14
0
static int apply_solution_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
  SpaceClip *sc = CTX_wm_space_clip(C);
  MovieClip *clip = ED_space_clip_get_clip(sc);
  if (!RNA_struct_property_is_set(op->ptr, "distance")) {
    RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
  }
  return apply_solution_scale_exec(C, op);
}
示例#15
0
static int edit_sensor_invoke_properties(bContext *C, wmOperator *op)
{
    PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);

    if (RNA_struct_property_is_set(op->ptr, "sensor") && RNA_struct_property_is_set(op->ptr, "object") )
        return 1;

    if (ptr.data) {
        bSensor *sens = ptr.data;
        Object *ob = ptr.id.data;

        RNA_string_set(op->ptr, "sensor", sens->name);
        RNA_string_set(op->ptr, "object", ob->id.name + 2);
        return 1;
    }

    return 0;
}
static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	Object *obedit = CTX_data_edit_object(C);
	BMEditMesh *em = BKE_editmesh_from_object(obedit);
	int ret;

	if (em->bm->totedgesel == 0) {
		BKE_report(op->reports, RPT_ERROR, "Selected edges/faces required");
		return OPERATOR_CANCELLED;
	}

	/* if the properties are set or there is no rv3d,
	 * skip model and exec immediately */

	if ((CTX_wm_region_view3d(C) == NULL) ||
	    (RNA_struct_property_is_set(op->ptr, "plane_co") &&
	     RNA_struct_property_is_set(op->ptr, "plane_no")))
	{
		return mesh_bisect_exec(C, op);
	}

	ret = WM_gesture_straightline_invoke(C, op, event);
	if (ret & OPERATOR_RUNNING_MODAL) {
		View3D *v3d = CTX_wm_view3d(C);

		wmGesture *gesture = op->customdata;
		BisectData *opdata;


		opdata = MEM_mallocN(sizeof(BisectData), "inset_operator_data");
		opdata->mesh_backup = EDBM_redo_state_store(em);
		opdata->is_first = true;
		gesture->userdata = opdata;

		/* misc other vars */
		G.moving = G_TRANSFORM_EDIT;
		opdata->twtype = v3d->twtype;
		v3d->twtype = 0;

		/* initialize modal callout */
		ED_area_headerprint(CTX_wm_area(C), IFACE_("LMB: Click and drag to draw cut line"));
	}
	return ret;
}
示例#17
0
static int paintcurve_add_point_exec(bContext *C, wmOperator *op)
{
  int loc[2];

  if (RNA_struct_property_is_set(op->ptr, "location")) {
    RNA_int_get_array(op->ptr, "location", loc);
    paintcurve_point_add(C, op, loc);
    return OPERATOR_FINISHED;
  }

  return OPERATOR_CANCELLED;
}
示例#18
0
static int screenshot_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
	if(screenshot_data_create(C, op)) {
		if(RNA_struct_property_is_set(op->ptr, "filepath"))
			return screenshot_exec(C, op);
		
		RNA_string_set(op->ptr, "filepath", G.ima);
		
		WM_event_add_fileselect(C, op);
	
		return OPERATOR_RUNNING_MODAL;
	}	
	return OPERATOR_CANCELLED;
}
示例#19
0
static int paintcurve_select_point_exec(bContext *C, wmOperator *op)
{
	int loc[2];

	if (RNA_struct_property_is_set(op->ptr, "location")) {
		bool toggle = RNA_boolean_get(op->ptr, "toggle");
		bool extend = RNA_boolean_get(op->ptr, "extend");
		RNA_int_get_array(op->ptr, "location", loc);
		if (paintcurve_point_select(C, op, loc, toggle, extend))
			return OPERATOR_FINISHED;
	}

	return OPERATOR_CANCELLED;
}
示例#20
0
static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
    if (screenshot_data_create(C, op)) {
        if (RNA_struct_property_is_set(op->ptr, "filepath"))
            return screenshot_exec(C, op);

        /* extension is added by 'screenshot_check' after */
        RNA_string_set(op->ptr, "filepath", G.relbase_valid ? G.main->name : "//screen");

        WM_event_add_fileselect(C, op);

        return OPERATOR_RUNNING_MODAL;
    }
    return OPERATOR_CANCELLED;
}
示例#21
0
static int edit_modifier_invoke_properties(bContext *C, wmOperator *op)
{
	PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier);
	ModifierData *md;
	
	if (RNA_struct_property_is_set(op->ptr, "modifier"))
		return 1;
	
	if (ptr.data) {
		md = ptr.data;
		RNA_string_set(op->ptr, "modifier", md->name);
		return 1;
	}
	
	return 0;
}
示例#22
0
/* function used for WM_OT_save_mainfile too */
static int wm_collada_import_exec(bContext *C, wmOperator *op)
{
	char filename[FILE_MAX];
	
	if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
		BKE_report(op->reports, RPT_ERROR, "No filename given");
		return OPERATOR_CANCELLED;
	}

	RNA_string_get(op->ptr, "filepath", filename);
	if (collada_import(C, filename)) return OPERATOR_FINISHED;
	
	BKE_report(op->reports, RPT_ERROR, "Errors found during parsing COLLADA document. Please see console for error log.");
	
	return OPERATOR_FINISHED;
}
示例#23
0
static int wm_alembic_import_exec(bContext *C, wmOperator *op)
{
  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
    BKE_report(op->reports, RPT_ERROR, "No filename given");
    return OPERATOR_CANCELLED;
  }

  char filename[FILE_MAX];
  RNA_string_get(op->ptr, "filepath", filename);

  const float scale = RNA_float_get(op->ptr, "scale");
  const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence");
  const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range");
  const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
  const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job");

  int offset = 0;
  int sequence_len = 1;

  if (is_sequence) {
    sequence_len = get_sequence_len(filename, &offset);
    if (sequence_len < 0) {
      BKE_report(op->reports, RPT_ERROR, "Unable to determine ABC sequence length");
      return OPERATOR_CANCELLED;
    }
  }

  /* Switch out of edit mode to avoid being stuck in it (T54326). */
  Object *obedit = CTX_data_edit_object(C);
  if (obedit) {
    ED_object_mode_toggle(C, OB_MODE_EDIT);
  }

  bool ok = ABC_import(C,
                       filename,
                       scale,
                       is_sequence,
                       set_frame_range,
                       sequence_len,
                       offset,
                       validate_meshes,
                       as_background_job);

  return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
示例#24
0
static int gpencil_edit_modifier_invoke_properties(bContext *C, wmOperator *op)
{
  GpencilModifierData *md;

  if (RNA_struct_property_is_set(op->ptr, "modifier")) {
    return true;
  }
  else {
    PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_GpencilModifier);
    if (ptr.data) {
      md = ptr.data;
      RNA_string_set(op->ptr, "modifier", md->name);
      return true;
    }
  }

  return false;
}
示例#25
0
static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	if (!transformops_data(C, op, event)) {
		G.moving = 0;
		return OPERATOR_CANCELLED;
	}

	if (RNA_struct_property_is_set(op->ptr, "value")) {
		return transform_exec(C, op);
	}
	else {
		/* add temp handler */
		WM_event_add_modal_handler(C, op);

		op->flag |= OP_IS_MODAL_GRAB_CURSOR; // XXX maybe we want this with the manipulator only?
		return OPERATOR_RUNNING_MODAL;
	}
}
示例#26
0
static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
    if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
        char filepath[FILE_MAX];

        if (G.main->name[0] == 0)
            BLI_strncpy(filepath, "untitled", sizeof(filepath));
        else
            BLI_strncpy(filepath, G.main->name, sizeof(filepath));

        BLI_replace_extension(filepath, sizeof(filepath), ".dae");
        RNA_string_set(op->ptr, "filepath", filepath);
    }

    WM_event_add_fileselect(C, op);

    return OPERATOR_RUNNING_MODAL;
}
示例#27
0
static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
  if (screenshot_data_create(C, op)) {
    if (RNA_struct_property_is_set(op->ptr, "filepath")) {
      return screenshot_exec(C, op);
    }

    /* extension is added by 'screenshot_check' after */
    char filepath[FILE_MAX] = "//screen";
    if (G.relbase_valid) {
      BLI_strncpy(filepath, BKE_main_blendfile_path_from_global(), sizeof(filepath));
      BLI_path_extension_replace(filepath, sizeof(filepath), ""); /* strip '.blend' */
    }
    RNA_string_set(op->ptr, "filepath", filepath);

    WM_event_add_fileselect(C, op);

    return OPERATOR_RUNNING_MODAL;
  }
  return OPERATOR_CANCELLED;
}
示例#28
0
static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
		Main *bmain = CTX_data_main(C);
		char filepath[FILE_MAX];

		if (bmain->name[0] == '\0') {
			BLI_strncpy(filepath, "untitled", sizeof(filepath));
		}
		else {
			BLI_strncpy(filepath, bmain->name, sizeof(filepath));
		}

		BLI_replace_extension(filepath, sizeof(filepath), ".abc");
		RNA_string_set(op->ptr, "filepath", filepath);
	}

	WM_event_add_fileselect(C, op);

	return OPERATOR_RUNNING_MODAL;

	UNUSED_VARS(event);
}
/* using context, starts job */
static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	/* new render clears all callbacks */
	Main *mainp;
	Scene *scene = CTX_data_scene(C);
	SceneRenderLayer *srl = NULL;
	View3D *v3d = CTX_wm_view3d(C);
	Render *re;
	wmJob *wm_job;
	RenderJob *rj;
	Image *ima;
	int jobflag;
	const short is_animation = RNA_boolean_get(op->ptr, "animation");
	const short is_write_still = RNA_boolean_get(op->ptr, "write_still");
	struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL;
	const char *name;
	Object *active_object = CTX_data_active_object(C);
	
	/* only one render job at a time */
	if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER))
		return OPERATOR_CANCELLED;

	if (!RE_is_rendering_allowed(scene, camera_override, op->reports)) {
		return OPERATOR_CANCELLED;
	}

	if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) {
		BKE_report(op->reports, RPT_ERROR, "Cannot write a single file with an animation format selected");
		return OPERATOR_CANCELLED;
	}
	
	/* stop all running jobs, except screen one. currently previews frustrate Render */
	WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C));

	/* get main */
	if (G.debug_value == 101) {
		/* thread-safety experiment, copy main from the undo buffer */
		mainp = BKE_undo_get_main(&scene);
	}
	else
		mainp = CTX_data_main(C);

	/* cancel animation playback */
	if (ED_screen_animation_playing(CTX_wm_manager(C)))
		ED_screen_animation_play(C, 0, 0);
	
	/* handle UI stuff */
	WM_cursor_wait(1);

	/* flush multires changes (for sculpt) */
	multires_force_render_update(active_object);

	/* flush changes from dynamic topology sculpt */
	sculptsession_bm_to_me_for_render(active_object);

	/* cleanup sequencer caches before starting user triggered render.
	 * otherwise, invalidated cache entries can make their way into
	 * the output rendering. We can't put that into RE_BlenderFrame,
	 * since sequence rendering can call that recursively... (peter) */
	BKE_sequencer_cache_cleanup();

	/* get editmode results */
	ED_object_editmode_load(CTX_data_edit_object(C));

	// store spare
	// get view3d layer, local layer, make this nice api call to render
	// store spare

	/* ensure at least 1 area shows result */
	render_view_open(C, event->x, event->y);

	jobflag = WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS;
	
	/* custom scene and single layer re-render */
	screen_render_scene_layer_set(op, mainp, &scene, &srl);

	if (RNA_struct_property_is_set(op->ptr, "layer"))
		jobflag |= WM_JOB_SUSPEND;

	/* job custom data */
	rj = MEM_callocN(sizeof(RenderJob), "render job");
	rj->main = mainp;
	rj->scene = scene;
	rj->win = CTX_wm_window(C);
	rj->srl = srl;
	rj->camera_override = camera_override;
	rj->lay = scene->lay;
	rj->anim = is_animation;
	rj->write_still = is_write_still && !is_animation;
	rj->iuser.scene = scene;
	rj->iuser.ok = 1;
	rj->reports = op->reports;

	if (v3d) {
		rj->lay = v3d->lay;

		if (v3d->localvd)
			rj->lay |= v3d->localvd->lay;
	}

	/* setup job */
	if (RE_seq_render_active(scene, &scene->r)) name = "Sequence Render";
	else name = "Render";

	wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, name, jobflag, WM_JOB_TYPE_RENDER);
	WM_jobs_customdata_set(wm_job, rj, render_freejob);
	WM_jobs_timer(wm_job, 0.2, NC_SCENE | ND_RENDER_RESULT, 0);
	WM_jobs_callbacks(wm_job, render_startjob, NULL, NULL, render_endjob);

	/* get a render result image, and make sure it is empty */
	ima = BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result");
	BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
	BKE_image_backup_render(rj->scene, ima);
	rj->image = ima;

	/* setup new render */
	re = RE_NewRender(scene->id.name);
	RE_test_break_cb(re, rj, render_breakjob);
	RE_draw_lock_cb(re, rj, render_drawlock);
	RE_display_draw_cb(re, rj, image_rect_update);
	RE_stats_draw_cb(re, rj, image_renderinfo_cb);
	RE_progress_cb(re, rj, render_progress_update);

	rj->re = re;
	G.is_break = FALSE;

	/* store actual owner of job, so modal operator could check for it,
	 * the reason of this is that active scene could change when rendering
	 * several layers from compositor [#31800]
	 */
	op->customdata = scene;

	WM_jobs_start(CTX_wm_manager(C), wm_job);

	WM_cursor_wait(0);
	WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);

	/* we set G.is_rendering here already instead of only in the job, this ensure
	 * main loop or other scene updates are disabled in time, since they may
	 * have started before the job thread */
	G.is_rendering = TRUE;

	/* add modal handler for ESC */
	WM_event_add_modal_handler(C, op);

	return OPERATOR_RUNNING_MODAL;
}
示例#30
0
/* function used for WM_OT_save_mainfile too */
static int wm_collada_export_exec(bContext *C, wmOperator *op)
{
    char filepath[FILE_MAX];
    int apply_modifiers;
    int export_mesh_type;
    int selected;
    int include_children;
    int include_armatures;
    int include_shapekeys;
    int deform_bones_only;

    int include_uv_textures;
    int include_material_textures;
    int use_texture_copies;
    int active_uv_only;

    int triangulate;
    int use_object_instantiation;
    int sort_by_name;
    int export_transformation_type;
    int open_sim;

    int export_count;

    if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
        BKE_report(op->reports, RPT_ERROR, "No filename given");
        return OPERATOR_CANCELLED;
    }

    RNA_string_get(op->ptr, "filepath", filepath);
    BLI_ensure_extension(filepath, sizeof(filepath), ".dae");


    /* Avoid File write exceptions in Collada */
    if (!BLI_exists(filepath)) {
        BLI_make_existing_file(filepath);
        if (!BLI_file_touch(filepath)) {
            BKE_report(op->reports, RPT_ERROR, "Can't create export file");
            fprintf(stdout, "Collada export: Can not create: %s\n", filepath);
            return OPERATOR_CANCELLED;
        }
    }
    else if (!BLI_file_is_writable(filepath)) {
        BKE_report(op->reports, RPT_ERROR, "Can't overwrite export file");
        fprintf(stdout, "Collada export: Can not modify: %s\n", filepath);
        return OPERATOR_CANCELLED;
    }

    /* Now the exporter can create and write the export file */

    /* Options panel */
    apply_modifiers          = RNA_boolean_get(op->ptr, "apply_modifiers");
    export_mesh_type         = RNA_enum_get(op->ptr,    "export_mesh_type_selection");
    selected                 = RNA_boolean_get(op->ptr, "selected");
    include_children         = RNA_boolean_get(op->ptr, "include_children");
    include_armatures        = RNA_boolean_get(op->ptr, "include_armatures");
    include_shapekeys        = RNA_boolean_get(op->ptr, "include_shapekeys");
    deform_bones_only        = RNA_boolean_get(op->ptr, "deform_bones_only");

    include_uv_textures      = RNA_boolean_get(op->ptr, "include_uv_textures");
    include_material_textures = RNA_boolean_get(op->ptr, "include_material_textures");
    use_texture_copies       = RNA_boolean_get(op->ptr, "use_texture_copies");
    active_uv_only           = RNA_boolean_get(op->ptr, "active_uv_only");

    triangulate                = RNA_boolean_get(op->ptr, "triangulate");
    use_object_instantiation   = RNA_boolean_get(op->ptr, "use_object_instantiation");
    sort_by_name               = RNA_boolean_get(op->ptr, "sort_by_name");
    export_transformation_type = RNA_enum_get(op->ptr,    "export_transformation_type_selection");
    open_sim                   = RNA_boolean_get(op->ptr, "open_sim");

    /* get editmode results */
    ED_object_editmode_load(CTX_data_edit_object(C));


    export_count = collada_export(CTX_data_scene(C),
                                  filepath,
                                  apply_modifiers,
                                  export_mesh_type,
                                  selected,
                                  include_children,
                                  include_armatures,
                                  include_shapekeys,
                                  deform_bones_only,

                                  active_uv_only,
                                  include_uv_textures,
                                  include_material_textures,
                                  use_texture_copies,

                                  triangulate,
                                  use_object_instantiation,
                                  sort_by_name,
                                  export_transformation_type,
                                  open_sim);

    if (export_count == 0) {
        BKE_report(op->reports, RPT_WARNING, "Export file is empty");
        return OPERATOR_CANCELLED;
    }
    else {
        char buff[100];
        sprintf(buff, "Exported %d Objects", export_count);
        BKE_report(op->reports, RPT_INFO, buff);
        return OPERATOR_FINISHED;
    }
}