* All tools:

- Library linking: there must not be "target_link_library()" for libraries,
        only when building binaries. Avoid clashes between static module
        or class variables, and strange reinitialisation of those variables.
    - Change: Boost is now always linked staticly.
  * ./hurricane/src/hurricane:
    - New: TextTranslator to allow translation to and from text & HTML.
    - Change: In Exception, make uses of TextTranslator to correctly display
        exception text when in graphic mode.
  * ./hurricane/src/isobar:
    - New: Script, small object to wrap around Python scripts.
This commit is contained in:
Jean-Paul Chaput 2010-07-01 11:46:29 +00:00
parent ff826d31cf
commit fbd9aba2f5
13 changed files with 504 additions and 145 deletions

View File

@ -55,13 +55,13 @@ IF(NOT BUILD_SHARED_LIBS)
) )
MESSAGE(STATUS "Building static libraries.") MESSAGE(STATUS "Building static libraries.")
IF(Boost_FOUND) IF(Boost_FOUND)
SET(Boost_USE_STATIC_LIBS ON)
MESSAGE(STATUS "Using Boost static libraries.")
ENDIF(Boost_FOUND) ENDIF(Boost_FOUND)
ELSE(NOT BUILD_SHARED_LIBS) ELSE(NOT BUILD_SHARED_LIBS)
MESSAGE(STATUS "Building dynamic libraries.") MESSAGE(STATUS "Building dynamic libraries.")
ENDIF(NOT BUILD_SHARED_LIBS) ENDIF(NOT BUILD_SHARED_LIBS)
SET(Boost_USE_STATIC_LIBS ON)
MESSAGE(STATUS "Always uses Boost static libraries.")
FIND_PACKAGE(Boost 1.33.1 COMPONENTS regex REQUIRED) FIND_PACKAGE(Boost 1.33.1 COMPONENTS regex REQUIRED)
ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src)

View File

@ -41,14 +41,14 @@ MACRO(HURRICANE_CHECK_LIBRARIES)
ENDMACRO(HURRICANE_CHECK_LIBRARIES) ENDMACRO(HURRICANE_CHECK_LIBRARIES)
MACRO(SET_LIB_LINK_MODE) MACRO(SET_LIB_LINK_MODE)
SET(Boost_USE_STATIC_LIBS ON)
MESSAGE(STATUS "Always uses Boost static libraries.")
IF(NOT BUILD_SHARED_LIBS) IF(NOT BUILD_SHARED_LIBS)
# check for qmake # check for qmake
FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake-qt4 qmake PATHS FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake-qt4 qmake PATHS
/opt/qt4-static-4.3.2/bin /opt/qt4-static-4.3.2/bin
NO_DEFAULT_PATH NO_DEFAULT_PATH
) )
SET(Boost_USE_STATIC_LIBS ON)
MESSAGE(STATUS "Using Boost static libraries.")
MESSAGE(STATUS "Building static libraries.") MESSAGE(STATUS "Building static libraries.")
ELSE(NOT BUILD_SHARED_LIBS) ELSE(NOT BUILD_SHARED_LIBS)
MESSAGE(STATUS "Building dynamic libraries.") MESSAGE(STATUS "Building dynamic libraries.")

View File

@ -81,6 +81,7 @@
hurricane/Vertical.h hurricane/Verticals.h hurricane/Vertical.h hurricane/Verticals.h
hurricane/Views.h hurricane/Views.h
hurricane/Warning.h hurricane/Warning.h
hurricane/TextTranslator.h
) )
set ( cpps Record.cpp set ( cpps Record.cpp
Slot.cpp Slot.cpp
@ -148,6 +149,7 @@
Query.cpp Query.cpp
Marker.cpp Marker.cpp
Timer.cpp Timer.cpp
TextTranslator.cpp
) )
add_library ( hurricane ${cpps} ) add_library ( hurricane ${cpps} )

View File

@ -19,6 +19,42 @@
#include "hurricane/Exception.h" #include "hurricane/Exception.h"
namespace {
using namespace Hurricane;
TextTranslator getDefaultTextTranslator ()
{
TextTranslator translator;
translator.addTranslation ( "<br>" , "\n" );
translator.addTranslation ( "<em>" , "" );
translator.addTranslation ( "</em>" , "" );
translator.addTranslation ( "<strong>" , "" );
translator.addTranslation ( "</strong>", "" );
translator.addTranslation ( "<tt>" , "" );
translator.addTranslation ( "</tt>" , "" );
translator.addTranslation ( "<b>" , "" );
translator.addTranslation ( "</b>" , "" );
translator.addTranslation ( "<i>" , "" );
translator.addTranslation ( "</i>" , "" );
translator.addTranslation ( "<big>" , "" );
translator.addTranslation ( "</big>" , "" );
translator.addTranslation ( "<small>" , "" );
translator.addTranslation ( "</small>" , "" );
translator.addTranslation ( "&lt;" , "<" );
translator.addTranslation ( "&gt;" , ">" );
return translator;
}
} // End of anonymous namespace.
namespace Hurricane { namespace Hurricane {
@ -27,6 +63,10 @@ namespace Hurricane {
// Exception implementation // Exception implementation
// **************************************************************************************************** // ****************************************************************************************************
TextTranslator Exception::_textTranslator = getDefaultTextTranslator();
TextTranslator Exception::_htmlTranslator;
Exception::Exception() Exception::Exception()
// ******************* // *******************
{ {

View File

@ -1,7 +1,7 @@
// -*- C++ -*- // -*- C++ -*-
// //
// Copyright (c) BULL S.A. 2000-2009, All Rights Reserved // Copyright (c) BULL S.A. 2000-2010, All Rights Reserved
// //
// This file is part of Hurricane. // This file is part of Hurricane.
// //

View File

@ -21,6 +21,7 @@
#define HURRICANE_EXCEPTION #define HURRICANE_EXCEPTION
#include "hurricane/Commons.h" #include "hurricane/Commons.h"
#include "hurricane/TextTranslator.h"
namespace Hurricane { namespace Hurricane {
@ -33,6 +34,12 @@ namespace Hurricane {
class Exception { class Exception {
// ************** // **************
// Attributes
// **********
private: static TextTranslator _textTranslator;
private: static TextTranslator _htmlTranslator;
// Constructors // Constructors
// ************ // ************
@ -53,12 +60,16 @@ class Exception {
// Accessors // Accessors
// ********* // *********
public: string what() const { return _getString(); }; public: string what () const { return textWhat(); };
public: string textWhat() const { return _textTranslator.translate(_getString()); };
public: string htmlWhat() const { return _htmlTranslator.translate(_getString()); };
// Others // Others
// ****** // ******
public: virtual string _getString() const = 0; public: static void setTextTranslator ( const TextTranslator& translator ) { _textTranslator=translator; }
public: static void setHtmlTranslator ( const TextTranslator& translator ) { _htmlTranslator=translator; }
public: virtual string _getString () const = 0;
}; };

View File

@ -39,7 +39,6 @@
PyDbU.cpp PyDbU.cpp
PyUpdateSession.cpp PyUpdateSession.cpp
PyVertical.cpp PyVertical.cpp
) )
set ( includes hurricane/isobar/ProxyProperty.h set ( includes hurricane/isobar/ProxyProperty.h
hurricane/isobar/PyBox.h hurricane/isobar/PyBox.h
@ -78,19 +77,19 @@
hurricane/isobar/PyUpdateSession.h hurricane/isobar/PyUpdateSession.h
hurricane/isobar/PyVertical.h hurricane/isobar/PyVertical.h
) )
# source2 & include2 for module that are *not* Python wrappers but true
# Hurricane modules.
set ( sources2 Script.cpp )
set ( includes2 hurricane/isobar/Script.h)
install ( FILES ${includes} DESTINATION include/coriolis2/hurricane/isobar ) install ( FILES ${includes}
${includes2} DESTINATION include/coriolis2/hurricane/isobar )
add_library ( isobar ${sources} ) add_library ( isobar ${sources} ${sources2} )
target_link_libraries ( isobar hurricane ${PYTHON_LIBRARIES} -lutil )
add_library ( Hurricane MODULE ${sources} ) add_library ( Hurricane MODULE ${sources} )
set_target_properties ( Hurricane PROPERTIES set_target_properties ( Hurricane PROPERTIES
COMPILE_FLAGS "${COMPILE_FLAGS} -D__PYTHON_MODULE__=1" COMPILE_FLAGS "${COMPILE_FLAGS} -D__PYTHON_MODULE__=1"
PREFIX "" PREFIX ""
) )
target_link_libraries ( Hurricane isobar hurricane ${PYTHON_LIBRARIES} )
install ( TARGETS isobar DESTINATION lib${LIB_SUFFIX} ) install ( TARGETS isobar DESTINATION lib${LIB_SUFFIX} )
install ( TARGETS Hurricane DESTINATION ${PYTHON_SITE_PACKAGES} ) install ( TARGETS Hurricane DESTINATION ${PYTHON_SITE_PACKAGES} )

View File

@ -0,0 +1,193 @@
// -*- C++ -*-
//
// Copyright (c) BULL S.A. 2000-2009, All Rights Reserved
//
// This file is part of Hurricane.
//
// Hurricane is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// Hurricane is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
// TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
// General Public License for more details.
//
// You should have received a copy of the Lesser GNU General Public
// License along with Hurricane. If not, see
// <http://www.gnu.org/licenses/>.
//
// ===================================================================
//
// $Id$
//
// x-----------------------------------------------------------------x
// | |
// | H U R R I C A N E |
// | V L S I B a c k e n d D a t a - B a s e |
// | |
// | Author : Jean-Paul Chaput |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Module : "./Script.cpp" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
#include <sstream>
#include "hurricane/Error.h"
#include "hurricane/Cell.h"
#include "hurricane/isobar/PyCell.h"
#include "hurricane/isobar/Script.h"
namespace Isobar {
using std::string;
using Hurricane::Cell;
// -------------------------------------------------------------------
// Class : "Isobar::Script".
vector<string> Script::_pathes;
void Script::addPath ( const string& path )
{ _pathes.push_back ( path ); }
Script::Script ( const string& name )
: _moduleName(name)
, _sysModule (NULL)
, _userModule(NULL)
{
}
Script::~Script ()
{
_destroyModules();
}
Script* Script::create ( const std::string& name )
{
Script* script = new Script ( name );
return script;
}
void Script::destroy ()
{
delete this;
}
bool Script::runFunction ( const std::string& function, Cell* cell )
{
bool returnCode = true;
if ( cell == NULL )
throw Error("Script::runFunction(): NULL Cell as argument");
Py_Initialize ();
_importSys ();
_importModule ( "Hurricane" );
_userModule = PyImport_ImportModule ( const_cast<char*>(_moduleName.c_str()) );
if ( _userModule == NULL ) {
if ( PyErr_Occurred() ) {
PyErr_Print ();
}
throw Error("Cannot load python module: <%s>",_moduleName.c_str());
}
PyObject* pyFunction = PyObject_GetAttrString(_userModule, const_cast<char*>(function.c_str()));
if ( (pyFunction == NULL) or not PyCallable_Check(pyFunction) ) {
_destroyModules ();
throw Error("Python module <%s> doesn't contains any <%s> function."
,_moduleName.c_str(),function.c_str());
}
PyObject* pyArgs = PyTuple_New(1);
PyTuple_SetItem ( pyArgs, 0, (PyObject*)PyCell_Link(cell) );
PyObject* pyResult = PyEval_CallObject ( pyFunction, pyArgs );
if ( pyResult == NULL ) {
cerr << "Something has gone slightly wrong" << endl;
} else
Py_DECREF ( pyResult );
if ( PyErr_Occurred() ) {
PyErr_Print ();
returnCode = false;
}
Py_DECREF ( pyFunction );
Py_DECREF ( pyArgs );
_destroyModules ();
Py_Finalize ();
return true;
}
void Script::_importSys ()
{
_sysModule = _importModule ( "sys" );
PyObject* path = PyObject_GetAttrString ( _sysModule, "path" );
if ( path == NULL )
throw Error("Script::_importSys(): No \"sys.path\" attribute.");
vector<string>::iterator ipath = _pathes.begin();
for ( ; ipath != _pathes.end() ; ++ipath ) {
cerr << "PYTHONPATH:" << (*ipath) << endl;
PyObject* element = PyString_FromString ( const_cast<char*>((*ipath).c_str()) );
PyList_Insert ( path, 0, element );
}
int size = PySequence_Size(path);
for ( int i=0 ; i<size ; ++i )
PyObject* element = PySequence_GetItem(path,i);
}
PyObject* Script::_importModule ( const string& moduleName )
{
if ( not Py_IsInitialized() )
throw Error ( "Script::_importModule(): Called before Py_Initialize() while importing <%s>."
, moduleName.c_str() );
PyObject* module = PyImport_ImportModule ( const_cast<char*>(moduleName.c_str()) );
if ( module == NULL )
throw Error("Script::_importModule(): No <%s> module.",moduleName.c_str());
return module;
}
void Script::_destroyModules ()
{
if ( not Py_IsInitialized() ) return;
if ( _userModule != NULL ) Py_DECREF ( _userModule );
if ( _sysModule != NULL ) Py_DECREF ( _sysModule );
_userModule = NULL;
_sysModule = NULL;
}
} // End of Isobar namespace.

View File

@ -0,0 +1,84 @@
// -*- C++ -*-
//
// Copyright (c) BULL S.A. 2000-2010, All Rights Reserved
//
// This file is part of ISOBAR.
//
// ISOBAR is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// ISOBAR is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
// TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
// General Public License for more details.
//
// You should have received a copy of the Lesser GNU General Public
// License along with ISOBAR. If not, see
// <http://www.gnu.org/licenses/>.
//
// ===================================================================
//
// $Id$
//
// x-----------------------------------------------------------------x
// | |
// | H U R R I C A N E |
// | V L S I B a c k e n d D a t a - B a s e |
// | |
// | Author : Jean-Paul Chaput |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./hurricane/isobar/Script.h" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
# ifndef __ISOBAR_SCRIPT__
# define __ISOBAR_SCRIPT__
#include <vector>
#include <Python.h>
namespace Hurricane {
class Cell;
}
namespace Isobar {
class Script {
public:
static void addPath ( const std::string& path );
static Script* create ( const std::string& name );
void destroy ();
inline PyObject* getUserModule ();
bool runFunction ( const std::string& function, Hurricane::Cell* cell );
protected:
static std::vector<std::string> _pathes;
std::string _moduleName;
PyObject* _sysModule;
PyObject* _userModule;
protected:
Script ( const std::string& name );
~Script ();
Script ( const Script& );
Script& operator= ( const Script& );
void _importSys ();
PyObject* _importModule ( const std::string& );
void _destroyModules ();
};
// Inline Methods.
inline PyObject* Script::getUserModule () { return _userModule; }
} // End of Isobar namespace.
# endif // __ISOBAR_SCRIPT__

View File

@ -112,11 +112,5 @@
qt4_add_resources ( RCC_SRCS CellViewer.qrc ) qt4_add_resources ( RCC_SRCS CellViewer.qrc )
install ( FILES ${exports} DESTINATION include/coriolis2/hurricane/viewer ) install ( FILES ${exports} DESTINATION include/coriolis2/hurricane/viewer )
add_library ( viewer ${cpps} ${MOC_SRCS} ${RCC_SRCS} ) add_library ( viewer ${cpps} ${MOC_SRCS} ${RCC_SRCS} )
target_link_libraries ( viewer hurricane
${CONFIGURATION_LIBRARIES}
${QT_LIBRARIES}
${Boost_LIBRARIES}
)
install ( TARGETS viewer DESTINATION lib${LIB_SUFFIX} ) install ( TARGETS viewer DESTINATION lib${LIB_SUFFIX} )

View File

@ -23,7 +23,7 @@
// x-----------------------------------------------------------------x // x-----------------------------------------------------------------x
# include <assert.h> #include <assert.h>
#include <Qt> #include <Qt>
#include <QBrush> #include <QBrush>
@ -31,13 +31,12 @@
#include <QApplication> #include <QApplication>
#include "hurricane/Name.h" #include "hurricane/Name.h"
#include "hurricane/Exception.h"
#include "hurricane/viewer/DisplayStyle.h" #include "hurricane/viewer/DisplayStyle.h"
#include "hurricane/viewer/Graphics.h" #include "hurricane/viewer/Graphics.h"
namespace Hurricane { namespace Hurricane {
@ -45,13 +44,32 @@ namespace Hurricane {
Graphics::Graphics () Graphics::Graphics ()
: _styles() : _htmlTranslator ()
, _active(NULL) , _styles ()
, _fireColorScale() , _active (NULL)
, _rainbowColorScale() , _fireColorScale ()
, _rainbowColorScale ()
, _temperatureColorScale() , _temperatureColorScale()
, _qtEnabled(false) , _qtEnabled (false)
{ {
_htmlTranslator.addTranslation ( "<br>" , "<br>" );
_htmlTranslator.addTranslation ( "<em>" , "<em>" );
_htmlTranslator.addTranslation ( "</em>" , "</em>" );
_htmlTranslator.addTranslation ( "<strong>" , "<strong>" );
_htmlTranslator.addTranslation ( "</strong>", "</strong>" );
_htmlTranslator.addTranslation ( "<tt>" , "<tt>" );
_htmlTranslator.addTranslation ( "</tt>" , "</tt>" );
_htmlTranslator.addTranslation ( "<b>" , "<b>" );
_htmlTranslator.addTranslation ( "</b>" , "</b>" );
_htmlTranslator.addTranslation ( "<i>" , "<i>" );
_htmlTranslator.addTranslation ( "</i>" , "</i>" );
_htmlTranslator.addTranslation ( "<big>" , "<big>" );
_htmlTranslator.addTranslation ( "</big>" , "</big>" );
_htmlTranslator.addTranslation ( "<small>" , "<small>" );
_htmlTranslator.addTranslation ( "</small>" , "</small>" );
_htmlTranslator.addTranslation ( "<" , "&lt;" );
_htmlTranslator.addTranslation ( ">" , "&gt;" );
_htmlTranslator.addTranslation ( "\n" , "<br>" );
} }
@ -68,6 +86,8 @@ namespace Hurricane {
DisplayStyle* fallback = new DisplayStyle("Fallback"); DisplayStyle* fallback = new DisplayStyle("Fallback");
fallback->setDescription ( "Builtin fallback style" ); fallback->setDescription ( "Builtin fallback style" );
_singleton->_addStyle ( fallback ); _singleton->_addStyle ( fallback );
Exception::setHtmlTranslator ( _singleton->_getHtmlTranslator() );
} }
return _singleton; return _singleton;
@ -277,23 +297,31 @@ namespace Hurricane {
} }
const TextTranslator& Graphics::getHtmlTranslator ()
{
return getGraphics()->_getHtmlTranslator();
}
string Graphics::toHtml ( const string& s ) string Graphics::toHtml ( const string& s )
{ {
string protect = s; return getGraphics()->getHtmlTranslator().translate(s);
if ( !isEnabled() ) return protect; // string protect = s;
unsigned int pos = protect.find ( '<' ); // if ( !isEnabled() ) return protect;
while ( pos < protect.size() ) {
protect.replace ( pos, 1, "&lt;" ); // unsigned int pos = protect.find ( '<' );
pos = protect.find ( '<', pos ); // while ( pos < protect.size() ) {
} // protect.replace ( pos, 1, "&lt;" );
pos = protect.find ( '>' ); // pos = protect.find ( '<', pos );
while ( pos < protect.size() ) { // }
protect.replace ( pos, 1, "&gt;" ); // pos = protect.find ( '>' );
pos = protect.find ( '>', pos ); // while ( pos < protect.size() ) {
} // protect.replace ( pos, 1, "&gt;" );
return protect; // pos = protect.find ( '>', pos );
// }
// return protect;
} }

View File

@ -27,6 +27,7 @@
#include <iostream> #include <iostream>
#include "hurricane/Exception.h" #include "hurricane/Exception.h"
#include "hurricane/viewer/Graphics.h"
#include "hurricane/viewer/ExceptionWidget.h" #include "hurricane/viewer/ExceptionWidget.h"
#include "hurricane/viewer/HApplication.h" #include "hurricane/viewer/HApplication.h"
@ -77,7 +78,7 @@ namespace Hurricane {
} }
catch ( Exception& e ) { catch ( Exception& e ) {
ExceptionWidget* ew = new ExceptionWidget (); ExceptionWidget* ew = new ExceptionWidget ();
ew->setMessage ( e.what().c_str() ); ew->setMessage ( e.htmlWhat().c_str() );
if ( ew->exec() == QDialog::Rejected ) if ( ew->exec() == QDialog::Rejected )
kill ( getpid(), SIGSEGV ); kill ( getpid(), SIGSEGV );
} }

View File

@ -2,7 +2,7 @@
// -*- C++ -*- // -*- C++ -*-
// //
// This file is part of the Coriolis Software. // This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2009, All Rights Reserved // Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved
// //
// =================================================================== // ===================================================================
// //
@ -31,6 +31,7 @@
#include <vector> #include <vector>
#include "hurricane/Breakpoint.h" #include "hurricane/Breakpoint.h"
#include "hurricane/TextTranslator.h"
#include "hurricane/viewer/DisplayStyle.h" #include "hurricane/viewer/DisplayStyle.h"
#include "hurricane/viewer/ColorScale.h" #include "hurricane/viewer/ColorScale.h"
#include "hurricane/viewer/BreakpointWidget.h" #include "hurricane/viewer/BreakpointWidget.h"
@ -66,6 +67,7 @@ namespace Hurricane {
static float getThreshold ( const Name& key ); static float getThreshold ( const Name& key );
static int getDarkening (); static int getDarkening ();
static const ColorScale& getColorScale ( ColorScale::ScaleType ); static const ColorScale& getColorScale ( ColorScale::ScaleType );
static const TextTranslator& getHtmlTranslator();
static string toHtml ( const string& ); static string toHtml ( const string& );
static bool breakpointStopCb ( const string& message ); static bool breakpointStopCb ( const string& message );
@ -81,6 +83,7 @@ namespace Hurricane {
// Internals - Attributes. // Internals - Attributes.
protected: protected:
static Graphics* _singleton; static Graphics* _singleton;
TextTranslator _htmlTranslator;
vector<DisplayStyle*> _styles; vector<DisplayStyle*> _styles;
DisplayStyle* _active; DisplayStyle* _active;
FireColorScale _fireColorScale; FireColorScale _fireColorScale;
@ -111,6 +114,7 @@ namespace Hurricane {
inline int _getDarkening () const; inline int _getDarkening () const;
inline const ColorScale& _getColorScale ( ColorScale::ScaleType ) const; inline const ColorScale& _getColorScale ( ColorScale::ScaleType ) const;
inline void _enable (); inline void _enable ();
inline const TextTranslator& _getHtmlTranslator () const;
}; };
@ -159,6 +163,9 @@ namespace Hurricane {
inline const vector<DisplayStyle*>& Graphics::_getStyles () const inline const vector<DisplayStyle*>& Graphics::_getStyles () const
{ return _styles; } { return _styles; }
inline const TextTranslator& Graphics::_getHtmlTranslator () const
{ return _htmlTranslator; }