Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Curioni <maxime.curioni@gmail.com>2009-09-28 07:56:31 +0400
committerMaxime Curioni <maxime.curioni@gmail.com>2009-09-28 07:56:31 +0400
commit002ac28643a4dcadc63b8723e964107e06043cd0 (patch)
treedd26feed82935e3257e673445990ac9239ac2da1 /source/blender/freestyle/intern/system
parent1ff038397fd3256c45899667bf1c3cba83947fa3 (diff)
Migration of Freestyle to Blender 2.5 codebase (continued):
- proper Freestyle initialization, with support for undo/redo - re-added FreestyleStyleConfig data structure - Freestyle Python interpreter updated This commit should compile without errors. More work is necessary to complete the migration: - add Freestyle in the UI - set up RNA support
Diffstat (limited to 'source/blender/freestyle/intern/system')
-rwxr-xr-xsource/blender/freestyle/intern/system/Interpreter.h2
-rwxr-xr-xsource/blender/freestyle/intern/system/PythonInterpreter.h53
2 files changed, 26 insertions, 29 deletions
diff --git a/source/blender/freestyle/intern/system/Interpreter.h b/source/blender/freestyle/intern/system/Interpreter.h
index 45cb7793cfd..75aaa2ccd18 100755
--- a/source/blender/freestyle/intern/system/Interpreter.h
+++ b/source/blender/freestyle/intern/system/Interpreter.h
@@ -42,8 +42,6 @@ class LIB_SYSTEM_EXPORT Interpreter
virtual ~Interpreter() {}; //soc
- virtual int interpretCmd(const string& cmd) = 0;
-
virtual int interpretFile(const string& filename) = 0;
virtual string getLanguage() const { return _language; }
diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h
index fa796630b9a..810825e68cf 100755
--- a/source/blender/freestyle/intern/system/PythonInterpreter.h
+++ b/source/blender/freestyle/intern/system/PythonInterpreter.h
@@ -37,12 +37,14 @@
//soc
extern "C" {
+#include "MEM_guardedalloc.h"
#include "BKE_main.h"
+#include "BKE_context.h"
#include "BKE_global.h"
+#include "BKE_report.h"
#include "BKE_text.h"
#include "BKE_library.h"
#include "BPY_extern.h"
-#include "BIF_drawtext.h"
}
class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter
@@ -58,35 +60,32 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter
//Py_Finalize();
}
- int interpretCmd(const string& cmd) {
- initPath();
- char* c_cmd = strdup(cmd.c_str());
- int err = PyRun_SimpleString(c_cmd);
- free(c_cmd);
- return err;
- }
-
int interpretFile(const string& filename) {
- initPath();
- char *fn = const_cast<char*>(filename.c_str());
- struct Text *text = add_text( fn );
+ bContext* C = CTX_create();
+ ReportList* reports = (ReportList*) MEM_mallocN(sizeof(ReportList), "freestyleExecutionReportList");
- if (text == NULL) {
- cout << "\nError in PythonInterpreter::interpretFile:" << endl;
- cout << "couldn't create Blender text from" << fn << endl;
- }
+ initPath(C);
+
+ BKE_reports_init(reports, RPT_ERROR);
+ char *fn = const_cast<char*>(filename.c_str());
- int status = BPY_txt_do_python_Text(text);
+ int status = BPY_run_python_script( C, fn, NULL, reports);
- // cleaning up
- unlink_text(text);
- free_libblock(&G.main->text, text);
-
if (status != 1) {
- cout << "\nError executing Python script from PythonInterpreter::interpretFile:" << endl;
- cout << fn << " (at line " << BPY_Err_getLinenumber() << ")" << endl;
- return BPY_Err_getLinenumber();
+ cout << "\nError executing Python script from PythonInterpreter::interpretFile" << endl;
+ cout << "File: " << fn << endl;
+ cout << "Errors: " << endl;
+ BKE_reports_print(reports, RPT_ERROR);
+ return 1;
+ }
+
+ // cleaning up
+ CTX_free( C );
+ BKE_reports_clear(reports);
+ if ((reports->flag & RPT_FREE) == 0)
+ {
+ MEM_freeN(reports);
}
return 0;
@@ -111,7 +110,7 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter
private:
- static void initPath() {
+ static void initPath(bContext* C) {
if (_initialized)
return;
@@ -130,10 +129,10 @@ private:
}
}
- BPY_txt_do_python_Text(text);
+ BPY_run_python_script( C, NULL, text, NULL);
// cleaning up
- unlink_text(text);
+ unlink_text(G.main, text);
free_libblock(&G.main->text, text);
//PyRun_SimpleString("from Freestyle import *");