diff options
author | Maxime Curioni <maxime.curioni@gmail.com> | 2008-05-26 23:52:55 +0400 |
---|---|---|
committer | Maxime Curioni <maxime.curioni@gmail.com> | 2008-05-26 23:52:55 +0400 |
commit | 373d42dbeaef014ce6d8c9d337242966d7ca8e5f (patch) | |
tree | bf150d1c812ae8de8702580fd49ccfa9fe88f59f | |
parent | fc8cd192a3a22322f6127345dc14f8463b35ee1f (diff) |
soc-2008-mxcurioni: PythonInterpreter works, using Blender's Python functions. The drawing still does not produce anything because the SWIG module wrapper is missing
6 files changed, 111 insertions, 104 deletions
diff --git a/source/blender/freestyle/SConscript b/source/blender/freestyle/SConscript index 97b7d4cf9f2..623bf0308dd 100644 --- a/source/blender/freestyle/SConscript +++ b/source/blender/freestyle/SConscript @@ -6,7 +6,7 @@ sources = [] defs = [] incs = '' -incs += '../blenkernel ../blenlib ../imbuf ../makesdna' +incs += '../blenkernel ../blenlib ../imbuf ../makesdna ../python' incs += ' #/extern/freestyle/lib3ds' incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_LIB3DS_INC'] diff --git a/source/blender/freestyle/intern/app_blender/Controller.cpp b/source/blender/freestyle/intern/app_blender/Controller.cpp index 25d9653b8f4..38f0ff0b7f0 100755 --- a/source/blender/freestyle/intern/app_blender/Controller.cpp +++ b/source/blender/freestyle/intern/app_blender/Controller.cpp @@ -64,6 +64,7 @@ #include "../system/StringUtils.h" +#include "test_config.h" Controller::Controller() { @@ -1057,64 +1058,53 @@ void Controller::displayDensityCurves(int x, int y){ } void Controller::init_options(){ -// //from AppOptionsWindow.cpp -// -// // Directories -// ViewMapIO::Options::setModelsPath((const char*)modelsPathLineEdit->text().toAscii().data()); -// PythonInterpreter::Options::setPythonPath((const char*)pythonPathLineEdit->text().toAscii().data()); -// TextureManager::Options::setPatternsPath((const char*)patternsPathLineEdit->text().toAscii().data()); -// TextureManager::Options::setBrushesPath((const char*)brushesPathLineEdit->text().toAscii().data()); -// //g_pController->setBrowserCmd(browserCmdLineEdit->text()); -// //g_pController->setHelpIndex(helpIndexPathLineEdit->text()); -// -// // ViewMap Format -// if (asFloatCheckBox->isChecked()) -// ViewMapIO::Options::addFlags(ViewMapIO::Options::FLOAT_VECTORS); -// else -// ViewMapIO::Options::rmFlags(ViewMapIO::Options::FLOAT_VECTORS); -// if (noOccluderListCheckBox->isChecked()) -// ViewMapIO::Options::addFlags(ViewMapIO::Options::NO_OCCLUDERS); -// else -// ViewMapIO::Options::rmFlags(ViewMapIO::Options::NO_OCCLUDERS); -// g_pController->setComputeSteerableViewMapFlag(steerableViewMapCheckBox->isChecked()); -// -// // Visibility -// if (qiCheckBox->isChecked()) -// g_pController->setQuantitativeInvisibility(true); -// else -// g_pController->setQuantitativeInvisibility(false); -// -// // Papers Textures -// vector<string> sl; -// for (unsigned i = 0; i < paperTexturesList->count(); i++) { -// sl.push_back(paperTexturesList->item(i)->text().toAscii().constData()); -// } -// TextureManager::Options::setPaperTextures(sl); -// -// // Drawing Buffers -// if (frontBufferCheckBox->isChecked()) -// g_pController->setFrontBufferFlag(true); -// else -// g_pController->setFrontBufferFlag(false); -// if (backBufferCheckBox->isChecked()) -// g_pController->setBackBufferFlag(true); -// else -// g_pController->setBackBufferFlag(false); -// -// // Ridges and Valleys -// g_pController->setComputeRidgesAndValleysFlag(ridgeValleyCheckBox->isChecked()); -// // Suggestive Contours -// g_pController->setComputeSuggestiveContoursFlag(suggestiveContoursCheckBox->isChecked()); -// bool ok; -// real r = sphereRadiusLineEdit->text().toFloat(&ok); -// if(ok) -// g_pController->setSphereRadius(r); -// else -// sphereRadiusLineEdit->setText(QString(QString::number(g_pController->getSphereRadius()))); -// r = krEpsilonLineEdit->text().toFloat(&ok); -// if(ok) -// g_pController->setSuggestiveContourKrDerivativeEpsilon(r); -// else -// krEpsilonLineEdit->setText(QString(QString::number(g_pController->getSuggestiveContourKrDerivativeEpsilon()))); -// } +// from AppOptionsWindow.cpp +// Default init options + + Config::Path * cpath = Config::Path::getInstance(); + + // const string& getProjectDir() const {return _ProjectDir;} + // const string& getModelsPath() const {return _ModelsPath;} + // const string& getPatternsPath() const {return _PatternsPath;} + // const string& getBrushesPath() const {return _BrushesPath;} + // const string& getPythonPath() const {return _PythonPath;} + // const string& getBrowserCmd() const {return _BrowserCmd;} + // const string& getHelpIndexpath() const {return _HelpIndexPath;} + // const string& getPapersDir() const {return _PapersDir;} + // const string& getEnvMapDir() const {return _EnvMapDir;} + // const string& getMapsDir() const {return _MapsDir;} + // const string& getHomeDir() const {return _HomeDir;} + + // Directories + ViewMapIO::Options::setModelsPath( StringUtils::toAscii( cpath->getModelsPath() ) ); + PythonInterpreter::Options::setPythonPath( StringUtils::toAscii( cpath->getPythonPath() ) ); + TextureManager::Options::setPatternsPath( StringUtils::toAscii( cpath->getPatternsPath() ) ); + TextureManager::Options::setBrushesPath( StringUtils::toAscii( cpath->getModelsPath() ) ); + + // ViewMap Format + ViewMapIO::Options::rmFlags(ViewMapIO::Options::FLOAT_VECTORS); + ViewMapIO::Options::rmFlags(ViewMapIO::Options::NO_OCCLUDERS); + setComputeSteerableViewMapFlag( false ); + + // Visibility + setQuantitativeInvisibility(true); + + // Papers Textures + vector<string> sl; + sl.push_back( StringUtils::toAscii( TEST_TEXTURE_FILE ) ); + TextureManager::Options::setPaperTextures(sl); + + // Drawing Buffers + setFrontBufferFlag(false); + setBackBufferFlag(true); + + + // Ridges and Valleys + setComputeRidgesAndValleysFlag( false ); + + // Suggestive Contours + setComputeSuggestiveContoursFlag( false ); + setSphereRadius(1); + setSuggestiveContourKrDerivativeEpsilon(0); + } diff --git a/source/blender/freestyle/intern/app_blender/test_config.h b/source/blender/freestyle/intern/app_blender/test_config.h index 773ca2f75f5..98239f279f3 100644 --- a/source/blender/freestyle/intern/app_blender/test_config.h +++ b/source/blender/freestyle/intern/app_blender/test_config.h @@ -3,4 +3,7 @@ #define TEST_STYLE_MODULE_FILE "/Users/mx/Documents/work/GSoC_2008/bf-blender/branches/soc-2008-mxcurioni/source/blender/freestyle/style_modules/contour.py" -#define TEST_ROOT_DIR "/Users/mx/Documents/work/GSoC_2008/bf-blender/branches/soc-2008-mxcurioni/source/blender/freestyle"
\ No newline at end of file +#define TEST_ROOT_DIR "/Users/mx/Documents/work/GSoC_2008/bf-blender/branches/soc-2008-mxcurioni/source/blender/freestyle" + + +#define TEST_TEXTURE_FILE "/Users/mx/Documents/work/GSoC_2008/bf-blender/branches/soc-2008-mxcurioni/source/blender/freestyle/data/textures/papers/whitepaper.jpg"
\ No newline at end of file diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h index b8eaa4a8a3c..d9b563fabaa 100755 --- a/source/blender/freestyle/intern/system/PythonInterpreter.h +++ b/source/blender/freestyle/intern/system/PythonInterpreter.h @@ -35,6 +35,12 @@ # include "StringUtils.h" # include "Interpreter.h" +//soc +extern "C" { +#include "BKE_text.h" +#include "BPY_extern.h" +} + class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter { public: @@ -42,12 +48,6 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter PythonInterpreter() { _language = "Python"; //Py_Initialize(); - - cout << "Freestyle Python Init: " << endl; - cout << "- is init : " << Py_IsInitialized() << endl; - cout << "- prog path : " << Py_GetProgramFullPath() << endl; - cout << "- mod path : " << Py_GetPath() << endl; - cout << "- version : " << Py_GetVersion() << endl; } virtual ~PythonInterpreter() { @@ -64,11 +64,22 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter int interpretFile(const string& filename) { initPath(); - string cmd("execfile(\"" + filename + "\")"); - char* c_cmd = strdup(cmd.c_str()); - int err = PyRun_SimpleString(c_cmd); - free(c_cmd); - return err; + + char *fn = const_cast<char*>(filename.c_str()); + struct Text *text = add_text( fn ); + + if (text == NULL) { + cout << "\nError in PythonInterpreter::interpretFile:" << endl; + cout << "couldn't create Blender text from" << fn << endl; + } + + if (BPY_txt_do_python_Text(text) != 1) { + cout << "\nError executing Python script from PythonInterpreter::interpretFile:" << endl; + cout << fn << " (at line " << BPY_Err_getLinenumber() << ")" << endl; + return BPY_Err_getLinenumber(); + } + + return 0; } struct Options @@ -91,22 +102,20 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter private: static void initPath() { - if (_initialized) - return; - PyRun_SimpleString("import sys"); - vector<string> pathnames; - StringUtils::getPathName(_path, "", pathnames); - string cmd; - char* c_cmd; - for (vector<string>::const_iterator it = pathnames.begin(); - it != pathnames.end(); - ++it) { - cmd = "sys.path.append(\"" + *it + "\")"; - c_cmd = strdup(cmd.c_str()); - PyRun_SimpleString(c_cmd); - free(c_cmd); - } - PyRun_SimpleString("from Freestyle import *"); + if (_initialized) + return; + + // vector<string> pathnames; + // StringUtils::getPathName(_path, "", pathnames); + // + // for (vector<string>::const_iterator it = pathnames.begin(); it != pathnames.end();++it) { + // if ( !it->empty() ) { + // cout << "Adding Python path: " << *it << endl; + // syspath_append( const_cast<char*>(it->c_str()) ); + // } + // } + + //PyRun_SimpleString("from Freestyle import *"); _initialized = true; } diff --git a/source/blender/freestyle/intern/system/StringUtils.cpp b/source/blender/freestyle/intern/system/StringUtils.cpp index bbdbef10a10..58798daf42a 100755 --- a/source/blender/freestyle/intern/system/StringUtils.cpp +++ b/source/blender/freestyle/intern/system/StringUtils.cpp @@ -27,25 +27,29 @@ namespace StringUtils { void getPathName(const string& path, const string& base, vector<string>& pathnames) { string dir; + string res; + char cleaned[FILE_MAX]; unsigned size = path.size(); + pathnames.push_back(base); - for (unsigned pos = 0, sep = path.find(Config::PATH_SEP, pos); - pos < size; - pos = sep + 1, sep = path.find(Config::PATH_SEP, pos)) { - if (sep == (unsigned)string::npos) - sep = size; - dir = path.substr(pos, sep - pos); -//soc QFileInfo fi(dir.c_str()); -//soc string res = (const char*)fi.absoluteFilePath().toAscii(); - char cleaned[FILE_MAX]; - BLI_strncpy(cleaned, dir.c_str(), FILE_MAX); - BLI_cleanup_file(NULL, cleaned); - string res = toAscii( string(cleaned) ); + for ( unsigned pos = 0, sep = path.find(Config::PATH_SEP, pos); + pos < size; + pos = sep + 1, sep = path.find(Config::PATH_SEP, pos)) { + + if (sep == (unsigned)string::npos) + sep = size; + + dir = path.substr(pos, sep - pos); + + BLI_strncpy(cleaned, dir.c_str(), FILE_MAX); + BLI_cleanup_file(NULL, cleaned); + res = toAscii( string(cleaned) ); - if (!base.empty()) - res += Config::DIR_SEP + base; - pathnames.push_back(res); + if (!base.empty()) + res += Config::DIR_SEP + base; + + pathnames.push_back(res); } } diff --git a/source/blender/freestyle/intern/system/StringUtils.h b/source/blender/freestyle/intern/system/StringUtils.h index b30eaae2247..7b43886fa27 100755 --- a/source/blender/freestyle/intern/system/StringUtils.h +++ b/source/blender/freestyle/intern/system/StringUtils.h @@ -31,6 +31,7 @@ # include <vector> # include <string> # include <sstream> +# include <iostream> # include "FreestyleConfig.h" //soc |