[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14985] branches/soc-2008-mxcurioni/source /blender/freestyle: soc-2008-mxcurioni: PythonInterpreter works, using Blender's Python functions.

Maxime Curioni maxime.curioni at gmail.com
Mon May 26 21:52:57 CEST 2008


Revision: 14985
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14985
Author:   mxcurioni
Date:     2008-05-26 21:52:55 +0200 (Mon, 26 May 2008)

Log Message:
-----------
soc-2008-mxcurioni: PythonInterpreter works, using Blender's Python functions. The drawing still does not produce anything because the SWIG module wrapper is missing

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/test_config.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/StringUtils.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/StringUtils.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-05-26 17:46:35 UTC (rev 14984)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-05-26 19:52:55 UTC (rev 14985)
@@ -6,7 +6,7 @@
 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']

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp	2008-05-26 17:46:35 UTC (rev 14984)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp	2008-05-26 19:52:55 UTC (rev 14985)
@@ -64,6 +64,7 @@
 
 #include "../system/StringUtils.h"
 
+#include "test_config.h"
 
 Controller::Controller()
 {
@@ -1057,64 +1058,53 @@
 }
 
 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);
+
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/test_config.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/test_config.h	2008-05-26 17:46:35 UTC (rev 14984)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/test_config.h	2008-05-26 19:52:55 UTC (rev 14985)
@@ -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

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h	2008-05-26 17:46:35 UTC (rev 14984)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h	2008-05-26 19:52:55 UTC (rev 14985)
@@ -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 @@
   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 @@
 
   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 @@
 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;
   }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/StringUtils.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/StringUtils.cpp	2008-05-26 17:46:35 UTC (rev 14984)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/StringUtils.cpp	2008-05-26 19:52:55 UTC (rev 14985)
@@ -27,25 +27,29 @@
 
   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;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list