From fbd9aba2f5dd100a6f855c8de03f624d46b02007 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Thu, 1 Jul 2010 11:46:29 +0000 Subject: [PATCH] * 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. --- hurricane/CMakeLists.txt | 4 +- hurricane/cmake_modules/FindHURRICANE.cmake | 4 +- hurricane/src/hurricane/CMakeLists.txt | 8 +- hurricane/src/hurricane/Exception.cpp | 40 ++++ .../src/hurricane/hurricane/Breakpoint.h | 2 +- hurricane/src/hurricane/hurricane/Exception.h | 15 +- hurricane/src/isobar/CMakeLists.txt | 161 ++++++++------- hurricane/src/isobar/Script.cpp | 193 ++++++++++++++++++ .../src/isobar/hurricane/isobar/Script.h | 84 ++++++++ hurricane/src/viewer/CMakeLists.txt | 12 +- hurricane/src/viewer/Graphics.cpp | 70 +++++-- hurricane/src/viewer/HApplication.cpp | 3 +- .../src/viewer/hurricane/viewer/Graphics.h | 53 ++--- 13 files changed, 504 insertions(+), 145 deletions(-) create mode 100644 hurricane/src/isobar/Script.cpp create mode 100644 hurricane/src/isobar/hurricane/isobar/Script.h diff --git a/hurricane/CMakeLists.txt b/hurricane/CMakeLists.txt index 95f52215..f1697a89 100644 --- a/hurricane/CMakeLists.txt +++ b/hurricane/CMakeLists.txt @@ -55,13 +55,13 @@ IF(NOT BUILD_SHARED_LIBS) ) MESSAGE(STATUS "Building static libraries.") IF(Boost_FOUND) - SET(Boost_USE_STATIC_LIBS ON) - MESSAGE(STATUS "Using Boost static libraries.") ENDIF(Boost_FOUND) ELSE(NOT BUILD_SHARED_LIBS) MESSAGE(STATUS "Building dynamic libraries.") 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) ADD_SUBDIRECTORY(src) diff --git a/hurricane/cmake_modules/FindHURRICANE.cmake b/hurricane/cmake_modules/FindHURRICANE.cmake index c6b4d5ef..e254c7d6 100644 --- a/hurricane/cmake_modules/FindHURRICANE.cmake +++ b/hurricane/cmake_modules/FindHURRICANE.cmake @@ -41,14 +41,14 @@ MACRO(HURRICANE_CHECK_LIBRARIES) ENDMACRO(HURRICANE_CHECK_LIBRARIES) MACRO(SET_LIB_LINK_MODE) + SET(Boost_USE_STATIC_LIBS ON) + MESSAGE(STATUS "Always uses Boost static libraries.") IF(NOT BUILD_SHARED_LIBS) # check for qmake FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake-qt4 qmake PATHS /opt/qt4-static-4.3.2/bin NO_DEFAULT_PATH ) - SET(Boost_USE_STATIC_LIBS ON) - MESSAGE(STATUS "Using Boost static libraries.") MESSAGE(STATUS "Building static libraries.") ELSE(NOT BUILD_SHARED_LIBS) MESSAGE(STATUS "Building dynamic libraries.") diff --git a/hurricane/src/hurricane/CMakeLists.txt b/hurricane/src/hurricane/CMakeLists.txt index bbbec097..f6eab7fa 100644 --- a/hurricane/src/hurricane/CMakeLists.txt +++ b/hurricane/src/hurricane/CMakeLists.txt @@ -81,6 +81,7 @@ hurricane/Vertical.h hurricane/Verticals.h hurricane/Views.h hurricane/Warning.h + hurricane/TextTranslator.h ) set ( cpps Record.cpp Slot.cpp @@ -148,8 +149,9 @@ Query.cpp Marker.cpp Timer.cpp + TextTranslator.cpp ) - add_library ( hurricane ${cpps} ) - install ( TARGETS hurricane DESTINATION lib${LIB_SUFFIX} ) - install ( FILES ${includes} DESTINATION include/coriolis2/hurricane ) + add_library ( hurricane ${cpps} ) + install ( TARGETS hurricane DESTINATION lib${LIB_SUFFIX} ) + install ( FILES ${includes} DESTINATION include/coriolis2/hurricane ) diff --git a/hurricane/src/hurricane/Exception.cpp b/hurricane/src/hurricane/Exception.cpp index 69a031ef..397701f2 100644 --- a/hurricane/src/hurricane/Exception.cpp +++ b/hurricane/src/hurricane/Exception.cpp @@ -19,6 +19,42 @@ #include "hurricane/Exception.h" + +namespace { + + using namespace Hurricane; + + + TextTranslator getDefaultTextTranslator () + { + TextTranslator translator; + + translator.addTranslation ( "
" , "\n" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "", "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "" , "" ); + translator.addTranslation ( "<" , "<" ); + translator.addTranslation ( ">" , ">" ); + + return translator; + } + + +} // End of anonymous namespace. + + + namespace Hurricane { @@ -27,6 +63,10 @@ namespace Hurricane { // Exception implementation // **************************************************************************************************** +TextTranslator Exception::_textTranslator = getDefaultTextTranslator(); +TextTranslator Exception::_htmlTranslator; + + Exception::Exception() // ******************* { diff --git a/hurricane/src/hurricane/hurricane/Breakpoint.h b/hurricane/src/hurricane/hurricane/Breakpoint.h index c21fc19c..1ecde080 100644 --- a/hurricane/src/hurricane/hurricane/Breakpoint.h +++ b/hurricane/src/hurricane/hurricane/Breakpoint.h @@ -1,7 +1,7 @@ // -*- 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. // diff --git a/hurricane/src/hurricane/hurricane/Exception.h b/hurricane/src/hurricane/hurricane/Exception.h index 6c8d4028..06dd1076 100644 --- a/hurricane/src/hurricane/hurricane/Exception.h +++ b/hurricane/src/hurricane/hurricane/Exception.h @@ -21,6 +21,7 @@ #define HURRICANE_EXCEPTION #include "hurricane/Commons.h" +#include "hurricane/TextTranslator.h" namespace Hurricane { @@ -33,6 +34,12 @@ namespace Hurricane { class Exception { // ************** +// Attributes +// ********** + + private: static TextTranslator _textTranslator; + private: static TextTranslator _htmlTranslator; + // Constructors // ************ @@ -53,12 +60,16 @@ class Exception { // 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 // ****** - 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; }; diff --git a/hurricane/src/isobar/CMakeLists.txt b/hurricane/src/isobar/CMakeLists.txt index 0c3c43cd..7ae5d5c3 100644 --- a/hurricane/src/isobar/CMakeLists.txt +++ b/hurricane/src/isobar/CMakeLists.txt @@ -3,94 +3,93 @@ ${HURRICANE_SOURCE_DIR}/src/isobar ${PYTHON_INCLUDE_PATH} ) - set ( sources ProxyProperty.cpp - PyBox.cpp - PyCell.cpp - PyCellCollection.cpp - PyComponent.cpp - PyComponentCollection.cpp - PyContact.cpp - PyDataBase.cpp - PyEntity.cpp - PyHorizontal.cpp - PyHurricane.cpp - PyHyperNet.cpp - PyInstance.cpp - PyInstanceCollection.cpp - PyLayer.cpp - PyLibrary.cpp - PyNet.cpp - PyNetCollection.cpp - PyOccurrence.cpp - PyOccurrenceCollection.cpp - PyPad.cpp - PyPath.cpp - PyPin.cpp - PyPinCollection.cpp - PyPlug.cpp - PyPlugCollection.cpp - PyPoint.cpp - PyReference.cpp - PyReferenceCollection.cpp - PySegment.cpp - PySegmentCollection.cpp - PyTechnology.cpp - PyTransformation.cpp - PyDbU.cpp - PyUpdateSession.cpp - PyVertical.cpp - - ) - set ( includes hurricane/isobar/ProxyProperty.h - hurricane/isobar/PyBox.h - hurricane/isobar/PyCell.h - hurricane/isobar/PyCellCollection.h - hurricane/isobar/PyComponent.h - hurricane/isobar/PyComponentCollection.h - hurricane/isobar/PyContact.h - hurricane/isobar/PyDataBase.h - hurricane/isobar/PyEntity.h - hurricane/isobar/PyHorizontal.h - hurricane/isobar/PyHurricane.h - hurricane/isobar/PyHyperNet.h - hurricane/isobar/PyInstance.h - hurricane/isobar/PyInstanceCollection.h - hurricane/isobar/PyLayer.h - hurricane/isobar/PyLibrary.h - hurricane/isobar/PyNet.h - hurricane/isobar/PyNetCollection.h - hurricane/isobar/PyOccurrence.h - hurricane/isobar/PyOccurrenceCollection.h - hurricane/isobar/PyPad.h - hurricane/isobar/PyPath.h - hurricane/isobar/PyPin.h - hurricane/isobar/PyPinCollection.h - hurricane/isobar/PyPlug.h - hurricane/isobar/PyPlugCollection.h - hurricane/isobar/PyPoint.h - hurricane/isobar/PyReference.h - hurricane/isobar/PyReferenceCollection.h - hurricane/isobar/PySegment.h - hurricane/isobar/PySegmentCollection.h - hurricane/isobar/PyTechnology.h - hurricane/isobar/PyTransformation.h - hurricane/isobar/PyDbU.h - hurricane/isobar/PyUpdateSession.h - hurricane/isobar/PyVertical.h + set ( sources ProxyProperty.cpp + PyBox.cpp + PyCell.cpp + PyCellCollection.cpp + PyComponent.cpp + PyComponentCollection.cpp + PyContact.cpp + PyDataBase.cpp + PyEntity.cpp + PyHorizontal.cpp + PyHurricane.cpp + PyHyperNet.cpp + PyInstance.cpp + PyInstanceCollection.cpp + PyLayer.cpp + PyLibrary.cpp + PyNet.cpp + PyNetCollection.cpp + PyOccurrence.cpp + PyOccurrenceCollection.cpp + PyPad.cpp + PyPath.cpp + PyPin.cpp + PyPinCollection.cpp + PyPlug.cpp + PyPlugCollection.cpp + PyPoint.cpp + PyReference.cpp + PyReferenceCollection.cpp + PySegment.cpp + PySegmentCollection.cpp + PyTechnology.cpp + PyTransformation.cpp + PyDbU.cpp + PyUpdateSession.cpp + PyVertical.cpp + ) + set ( includes hurricane/isobar/ProxyProperty.h + hurricane/isobar/PyBox.h + hurricane/isobar/PyCell.h + hurricane/isobar/PyCellCollection.h + hurricane/isobar/PyComponent.h + hurricane/isobar/PyComponentCollection.h + hurricane/isobar/PyContact.h + hurricane/isobar/PyDataBase.h + hurricane/isobar/PyEntity.h + hurricane/isobar/PyHorizontal.h + hurricane/isobar/PyHurricane.h + hurricane/isobar/PyHyperNet.h + hurricane/isobar/PyInstance.h + hurricane/isobar/PyInstanceCollection.h + hurricane/isobar/PyLayer.h + hurricane/isobar/PyLibrary.h + hurricane/isobar/PyNet.h + hurricane/isobar/PyNetCollection.h + hurricane/isobar/PyOccurrence.h + hurricane/isobar/PyOccurrenceCollection.h + hurricane/isobar/PyPad.h + hurricane/isobar/PyPath.h + hurricane/isobar/PyPin.h + hurricane/isobar/PyPinCollection.h + hurricane/isobar/PyPlug.h + hurricane/isobar/PyPlugCollection.h + hurricane/isobar/PyPoint.h + hurricane/isobar/PyReference.h + hurricane/isobar/PyReferenceCollection.h + hurricane/isobar/PySegment.h + hurricane/isobar/PySegmentCollection.h + hurricane/isobar/PyTechnology.h + hurricane/isobar/PyTransformation.h + hurricane/isobar/PyDbU.h + hurricane/isobar/PyUpdateSession.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 ) - - add_library ( isobar ${sources} ) - target_link_libraries ( isobar hurricane ${PYTHON_LIBRARIES} -lutil ) - + install ( FILES ${includes} + ${includes2} DESTINATION include/coriolis2/hurricane/isobar ) + add_library ( isobar ${sources} ${sources2} ) add_library ( Hurricane MODULE ${sources} ) set_target_properties ( Hurricane PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -D__PYTHON_MODULE__=1" PREFIX "" ) - target_link_libraries ( Hurricane isobar hurricane ${PYTHON_LIBRARIES} ) - install ( TARGETS isobar DESTINATION lib${LIB_SUFFIX} ) install ( TARGETS Hurricane DESTINATION ${PYTHON_SITE_PACKAGES} ) diff --git a/hurricane/src/isobar/Script.cpp b/hurricane/src/isobar/Script.cpp new file mode 100644 index 00000000..10cf7e43 --- /dev/null +++ b/hurricane/src/isobar/Script.cpp @@ -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 +// . +// +// =================================================================== +// +// $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 +#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 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(_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(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::iterator ipath = _pathes.begin(); + + for ( ; ipath != _pathes.end() ; ++ipath ) { + cerr << "PYTHONPATH:" << (*ipath) << endl; + + PyObject* element = PyString_FromString ( const_cast((*ipath).c_str()) ); + PyList_Insert ( path, 0, element ); + } + + int size = PySequence_Size(path); + for ( int i=0 ; i." + , moduleName.c_str() ); + + PyObject* module = PyImport_ImportModule ( const_cast(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. diff --git a/hurricane/src/isobar/hurricane/isobar/Script.h b/hurricane/src/isobar/hurricane/isobar/Script.h new file mode 100644 index 00000000..15c0ad96 --- /dev/null +++ b/hurricane/src/isobar/hurricane/isobar/Script.h @@ -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 +// . +// +// =================================================================== +// +// $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 +#include +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 _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__ diff --git a/hurricane/src/viewer/CMakeLists.txt b/hurricane/src/viewer/CMakeLists.txt index 48a08b5b..a4452d84 100644 --- a/hurricane/src/viewer/CMakeLists.txt +++ b/hurricane/src/viewer/CMakeLists.txt @@ -111,12 +111,6 @@ qt4_wrap_cpp ( MOC_SRCS ${mocincludes} ) qt4_add_resources ( RCC_SRCS CellViewer.qrc ) - install ( FILES ${exports} DESTINATION include/coriolis2/hurricane/viewer ) - - 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 ( FILES ${exports} DESTINATION include/coriolis2/hurricane/viewer ) + add_library ( viewer ${cpps} ${MOC_SRCS} ${RCC_SRCS} ) + install ( TARGETS viewer DESTINATION lib${LIB_SUFFIX} ) diff --git a/hurricane/src/viewer/Graphics.cpp b/hurricane/src/viewer/Graphics.cpp index 76d60a38..440511ce 100644 --- a/hurricane/src/viewer/Graphics.cpp +++ b/hurricane/src/viewer/Graphics.cpp @@ -23,7 +23,7 @@ // x-----------------------------------------------------------------x -# include +#include #include #include @@ -31,13 +31,12 @@ #include #include "hurricane/Name.h" +#include "hurricane/Exception.h" #include "hurricane/viewer/DisplayStyle.h" #include "hurricane/viewer/Graphics.h" - - namespace Hurricane { @@ -45,13 +44,32 @@ namespace Hurricane { Graphics::Graphics () - : _styles() - , _active(NULL) - , _fireColorScale() - , _rainbowColorScale() + : _htmlTranslator () + , _styles () + , _active (NULL) + , _fireColorScale () + , _rainbowColorScale () , _temperatureColorScale() - , _qtEnabled(false) + , _qtEnabled (false) { + _htmlTranslator.addTranslation ( "
" , "
" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "", "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "" , "" ); + _htmlTranslator.addTranslation ( "<" , "<" ); + _htmlTranslator.addTranslation ( ">" , ">" ); + _htmlTranslator.addTranslation ( "\n" , "
" ); } @@ -68,6 +86,8 @@ namespace Hurricane { DisplayStyle* fallback = new DisplayStyle("Fallback"); fallback->setDescription ( "Builtin fallback style" ); _singleton->_addStyle ( fallback ); + + Exception::setHtmlTranslator ( _singleton->_getHtmlTranslator() ); } return _singleton; @@ -277,23 +297,31 @@ namespace Hurricane { } + const TextTranslator& Graphics::getHtmlTranslator () + { + return getGraphics()->_getHtmlTranslator(); + } + + 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 ( '<' ); - while ( pos < protect.size() ) { - protect.replace ( pos, 1, "<" ); - pos = protect.find ( '<', pos ); - } - pos = protect.find ( '>' ); - while ( pos < protect.size() ) { - protect.replace ( pos, 1, ">" ); - pos = protect.find ( '>', pos ); - } - return protect; + // if ( !isEnabled() ) return protect; + + // unsigned int pos = protect.find ( '<' ); + // while ( pos < protect.size() ) { + // protect.replace ( pos, 1, "<" ); + // pos = protect.find ( '<', pos ); + // } + // pos = protect.find ( '>' ); + // while ( pos < protect.size() ) { + // protect.replace ( pos, 1, ">" ); + // pos = protect.find ( '>', pos ); + // } + // return protect; } diff --git a/hurricane/src/viewer/HApplication.cpp b/hurricane/src/viewer/HApplication.cpp index 1ea41df8..59e02056 100644 --- a/hurricane/src/viewer/HApplication.cpp +++ b/hurricane/src/viewer/HApplication.cpp @@ -27,6 +27,7 @@ #include #include "hurricane/Exception.h" +#include "hurricane/viewer/Graphics.h" #include "hurricane/viewer/ExceptionWidget.h" #include "hurricane/viewer/HApplication.h" @@ -77,7 +78,7 @@ namespace Hurricane { } catch ( Exception& e ) { ExceptionWidget* ew = new ExceptionWidget (); - ew->setMessage ( e.what().c_str() ); + ew->setMessage ( e.htmlWhat().c_str() ); if ( ew->exec() == QDialog::Rejected ) kill ( getpid(), SIGSEGV ); } diff --git a/hurricane/src/viewer/hurricane/viewer/Graphics.h b/hurricane/src/viewer/hurricane/viewer/Graphics.h index 67de7ea3..986c699b 100644 --- a/hurricane/src/viewer/hurricane/viewer/Graphics.h +++ b/hurricane/src/viewer/hurricane/viewer/Graphics.h @@ -2,7 +2,7 @@ // -*- C++ -*- // // 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 #include "hurricane/Breakpoint.h" +#include "hurricane/TextTranslator.h" #include "hurricane/viewer/DisplayStyle.h" #include "hurricane/viewer/ColorScale.h" #include "hurricane/viewer/BreakpointWidget.h" @@ -66,6 +67,7 @@ namespace Hurricane { static float getThreshold ( const Name& key ); static int getDarkening (); static const ColorScale& getColorScale ( ColorScale::ScaleType ); + static const TextTranslator& getHtmlTranslator(); static string toHtml ( const string& ); static bool breakpointStopCb ( const string& message ); @@ -81,6 +83,7 @@ namespace Hurricane { // Internals - Attributes. protected: static Graphics* _singleton; + TextTranslator _htmlTranslator; vector _styles; DisplayStyle* _active; FireColorScale _fireColorScale; @@ -89,28 +92,29 @@ namespace Hurricane { bool _qtEnabled; // Internals - Constructors & Destructors. - Graphics (); - Graphics ( const Graphics& ); - Graphics& operator= ( const Graphics& ); - ~Graphics (); - - // Internals - Methods. - size_t _findStyle ( const Name& key ) const; - void _addStyle ( DisplayStyle* displayStyle ); - void _setStyle ( const Name& key ); - void _setStyle ( size_t id ); - DisplayStyle* _getStyle ( const Name& key ); - DisplayStyle* _getStyle () const; - inline const vector& _getStyles () const; - inline const Name& _getGroup ( const Name& key ) const; - inline QColor _getColor ( const Name& key, int darkening ) const; - inline QPen _getPen ( const Name& key, int darkening ) const; - inline QBrush _getBrush ( const Name& key, int darkening ) const; - inline const string& _getPattern ( const Name& key ) const; - inline float _getThreshold ( const Name& key ) const; - inline int _getDarkening () const; - inline const ColorScale& _getColorScale ( ColorScale::ScaleType ) const; - inline void _enable (); + Graphics (); + Graphics ( const Graphics& ); + Graphics& operator= ( const Graphics& ); + ~Graphics (); + + // Internals - Methods. + size_t _findStyle ( const Name& key ) const; + void _addStyle ( DisplayStyle* displayStyle ); + void _setStyle ( const Name& key ); + void _setStyle ( size_t id ); + DisplayStyle* _getStyle ( const Name& key ); + DisplayStyle* _getStyle () const; + inline const vector& _getStyles () const; + inline const Name& _getGroup ( const Name& key ) const; + inline QColor _getColor ( const Name& key, int darkening ) const; + inline QPen _getPen ( const Name& key, int darkening ) const; + inline QBrush _getBrush ( const Name& key, int darkening ) const; + inline const string& _getPattern ( const Name& key ) const; + inline float _getThreshold ( const Name& key ) const; + inline int _getDarkening () const; + inline const ColorScale& _getColorScale ( ColorScale::ScaleType ) const; + inline void _enable (); + inline const TextTranslator& _getHtmlTranslator () const; }; @@ -159,6 +163,9 @@ namespace Hurricane { inline const vector& Graphics::_getStyles () const { return _styles; } + inline const TextTranslator& Graphics::_getHtmlTranslator () const + { return _htmlTranslator; } +