diff --git a/hurricane/src/hurricane/CellCollections.cpp b/hurricane/src/hurricane/CellCollections.cpp index 1a0c159b..38ff0e5b 100644 --- a/hurricane/src/hurricane/CellCollections.cpp +++ b/hurricane/src/hurricane/CellCollections.cpp @@ -1136,6 +1136,73 @@ class Cell_LeafInstanceOccurrencesUnder : public Collection { }; +// **************************************************************************************************** +// Cell_NonLeafInstanceOccurrences declaration +// **************************************************************************************************** + +class Cell_NonLeafInstanceOccurrences : public Collection { +// ******************************************************************** + +// Types +// ***** + + public: typedef Collection Inherit; + + public: class Locator : public Hurricane::Locator { + // ************************************************************ + + public: typedef Hurricane::Locator Inherit; + + private: const Cell* _cell; + private: int _state; + private: InstanceLocator _nonLeafInstanceLocator; + private: OccurrenceLocator _occurrenceLocator; + + public: Locator(const Cell* cell = NULL); + public: Locator(const Locator& locator); + + public: Locator& operator=(const Locator& locator); + + public: virtual Occurrence getElement() const; + public: virtual Hurricane::Locator* getClone() const; + + public: virtual bool isValid() const; + + public: virtual void progress(); + + public: virtual string _getString() const; + + }; + +// Attributes +// ********** + + private: const Cell* _cell; + +// Constructors +// ************ + + public: Cell_NonLeafInstanceOccurrences(const Cell* cell = NULL); + public: Cell_NonLeafInstanceOccurrences(const Cell_NonLeafInstanceOccurrences& occurrences); + +// Operators +// ********* + + public: Cell_NonLeafInstanceOccurrences& operator=(const Cell_NonLeafInstanceOccurrences& occurrences); + +// Accessors +// ********* + + public: virtual Collection* getClone() const; + public: virtual Hurricane::Locator* getLocator() const; + +// Others +// ****** + + public: virtual string _getString() const; + +}; + // **************************************************************************************************** @@ -1961,6 +2028,12 @@ Occurrences Cell::getLeafInstanceOccurrencesUnder(const Box& area) const return Cell_LeafInstanceOccurrencesUnder(this, area); } +Occurrences Cell::getNonLeafInstanceOccurrences() const +// *********************************************** +{ + return Cell_NonLeafInstanceOccurrences(this); +} + Occurrences Cell::getComponentOccurrences(const Layer::Mask& mask) const // ******************************************************************* { @@ -3533,6 +3606,174 @@ string Cell_LeafInstanceOccurrencesUnder::Locator::_getString() const + +// **************************************************************************************************** +// Cell_NonLeafInstanceOccurrences implementation +// **************************************************************************************************** + +Cell_NonLeafInstanceOccurrences::Cell_NonLeafInstanceOccurrences(const Cell* cell) +// ******************************************************************************* +: Inherit(), + _cell(cell) +{ +} + +Cell_NonLeafInstanceOccurrences::Cell_NonLeafInstanceOccurrences(const Cell_NonLeafInstanceOccurrences& occurrences) +// **************************************************************************************************** +: Inherit(), + _cell(occurrences._cell) +{ +} + +Cell_NonLeafInstanceOccurrences& Cell_NonLeafInstanceOccurrences::operator=(const Cell_NonLeafInstanceOccurrences& occurrences) +// **************************************************************************************************** +{ + _cell = occurrences._cell; + return *this; +} + +Collection* Cell_NonLeafInstanceOccurrences::getClone() const +// ********************************************************************* +{ + return new Cell_NonLeafInstanceOccurrences(*this); +} + +Locator* Cell_NonLeafInstanceOccurrences::getLocator() const +// ******************************************************************** +{ + return new Locator(_cell); +} + +string Cell_NonLeafInstanceOccurrences::_getString() const +// ******************************************************* +{ + string s = "<" + _TName("Cell::NonLeafInstanceOccurrences"); + if (_cell) s += " " + getString(_cell); + s += ">"; + return s; +} + + + +// **************************************************************************************************** +// Cell_NonLeafInstanceOccurrences::Locator implementation +// **************************************************************************************************** + +Cell_NonLeafInstanceOccurrences::Locator::Locator(const Cell* cell) +// **************************************************************** + : Inherit () + , _cell (cell) + , _state (0) + , _nonLeafInstanceLocator() + , _occurrenceLocator () +{ + if ( _cell ) { + _nonLeafInstanceLocator = _cell->getNonLeafInstances().getLocator(); + if ( _nonLeafInstanceLocator.isValid() ) { + _state = 1; + } + } +} + +Cell_NonLeafInstanceOccurrences::Locator::Locator(const Locator& locator) +// ********************************************************************** + : Inherit () + , _cell (locator._cell) + , _state (locator._state) + , _nonLeafInstanceLocator(locator._nonLeafInstanceLocator) + , _occurrenceLocator (locator._occurrenceLocator) +{ } + +Cell_NonLeafInstanceOccurrences::Locator& Cell_NonLeafInstanceOccurrences::Locator::operator=(const Locator& locator) +// ******************************************************************************************************************** +{ + _cell = locator._cell; + _state = locator._state; + _nonLeafInstanceLocator = locator._nonLeafInstanceLocator; + _occurrenceLocator = locator._occurrenceLocator; + return *this; +} + +Occurrence Cell_NonLeafInstanceOccurrences::Locator::getElement() const +// ********************************************************************* +{ + if ( _state ) { + switch ( _state ) { + case 1 : return Occurrence(_nonLeafInstanceLocator.getElement()); + case 2 : + { + Occurrence occurrence = _occurrenceLocator.getElement(); + Entity* entity = occurrence.getEntity(); + Path path = Path(_nonLeafInstanceLocator.getElement(), occurrence.getPath()); + return Occurrence(entity, path); + } + } + } + return Occurrence(); +} + +Locator* Cell_NonLeafInstanceOccurrences::Locator::getClone() const +// ***************************************************************************** +{ + return new Locator(*this); +} + +bool Cell_NonLeafInstanceOccurrences::Locator::isValid() const +// ************************************************************ +{ + return ( _state != 0 ); +} + +void Cell_NonLeafInstanceOccurrences::Locator::progress() +// ******************************************************* +{ + if ( _state ) { + switch ( _state ) { + case 1: + { + _nonLeafInstanceLocator.progress(); + if ( _nonLeafInstanceLocator.isValid() ) break; + + _state = 2; + _nonLeafInstanceLocator = _cell->getNonLeafInstances().getLocator(); + if ( not _nonLeafInstanceLocator.isValid() ) { + _state = 0; + break; + } + + Cell* masterCell = _nonLeafInstanceLocator.getElement()->getMasterCell(); + _occurrenceLocator = masterCell->getNonLeafInstanceOccurrences().getLocator(); + + if ( _occurrenceLocator.isValid() ) break; + } + case 2: + _occurrenceLocator.progress (); + + while ( (_state != 0) and not _occurrenceLocator.isValid() ) { + _nonLeafInstanceLocator.progress(); + if ( not _nonLeafInstanceLocator.isValid() ) { + _state = 0; + break; + } + + Cell* masterCell = _nonLeafInstanceLocator.getElement()->getMasterCell(); + _occurrenceLocator = masterCell->getNonLeafInstanceOccurrences().getLocator(); + } + } + } +} + +string Cell_NonLeafInstanceOccurrences::Locator::_getString() const +// **************************************************************** +{ + string s = "<" + _TName("Cell::NonLeafInstanceOccurrences::Locator"); + if (_cell) s += " " + getString(_cell); + s += ">"; + return s; +} + + + // **************************************************************************************************** // Cell_TerminalInstanceOccurrences implementation // **************************************************************************************************** diff --git a/hurricane/src/hurricane/Instance.cpp b/hurricane/src/hurricane/Instance.cpp index 32753f4f..865b2bac 100644 --- a/hurricane/src/hurricane/Instance.cpp +++ b/hurricane/src/hurricane/Instance.cpp @@ -304,6 +304,7 @@ void Instance::materialize() // ************************* { if (not isMaterialized()) { + cerr << "materialize: " << this << endl; Box boundingBox = getBoundingBox(); if (!boundingBox.isEmpty()) { QuadTree* quadTree = _cell->_getQuadTree(); @@ -375,10 +376,12 @@ void Instance::setTransformation(const Transformation& transformation) void Instance::setPlacementStatus(const PlacementStatus& placementstatus) // ********************************************************************** { + cerr << "setPlacementStatus of " << this << " to " << placementstatus << endl; if (placementstatus != _placementStatus) { invalidate(true); if (_placementStatus == PlacementStatus::UNPLACED) { + cerr << "setPlacementStatus: PLACED/FIXED " << this << endl; materialize (); } else if (placementstatus == PlacementStatus::UNPLACED) unmaterialize (); @@ -448,6 +451,7 @@ void Instance::setMasterCell(Cell* masterCell, bool secureFlag) void Instance::_postCreate() // ************************* { + _cell->setTerminal(false); _cell->_getInstanceMap()._insert(this); _masterCell->_getSlaveInstanceSet()._insert(this); @@ -456,9 +460,13 @@ void Instance::_postCreate() end_for; } + cerr << "Initial placement status " << this << " " << _placementStatus << endl; + bool autoMaterialization = not autoMaterializationIsDisabled(); - if ( _placementStatus == PlacementStatus::UNPLACED ) + if ( _placementStatus == PlacementStatus::UNPLACED ) { disableAutoMaterialization(); + cerr << "do not materialize: " << this << endl; + } Inherit::_postCreate(); diff --git a/hurricane/src/hurricane/TextTranslator.cpp b/hurricane/src/hurricane/TextTranslator.cpp new file mode 100644 index 00000000..00d2f171 --- /dev/null +++ b/hurricane/src/hurricane/TextTranslator.cpp @@ -0,0 +1,64 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// +// =================================================================== +// +// $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@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./TextTranslator.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#include +#include "hurricane/TextTranslator.h" + + +namespace Hurricane { + + using std::string; + using std::vector; + using std::cerr; + using std::endl; + + + string TextTranslator::translate ( const string& source ) const + { + string translated = source; + + for ( size_t pos=0 ; pos ( const Hurricane::Instance::PlacementStatus::Code* object ) { switch ( *object ) { - case Hurricane::Instance::PlacementStatus::UNPLACED: return "PLACED"; + case Hurricane::Instance::PlacementStatus::UNPLACED: return "UNPLACED"; + case Hurricane::Instance::PlacementStatus::PLACED: return "PLACED"; + case Hurricane::Instance::PlacementStatus::FIXED: return "FIXED"; + } + return "ABNORMAL"; + } + +template<> +inline std::string getString + ( Hurricane::Instance::PlacementStatus::Code object ) + { + switch ( object ) { + case Hurricane::Instance::PlacementStatus::UNPLACED: return "UNPLACED"; case Hurricane::Instance::PlacementStatus::PLACED: return "PLACED"; case Hurricane::Instance::PlacementStatus::FIXED: return "FIXED"; } @@ -212,13 +224,20 @@ inline Hurricane::Record* getRecord +inline Hurricane::Record* getRecord + ( const Hurricane::Instance::PlacementStatus::Code object ) + { + Hurricane::Record* record = new Hurricane::Record(getString(object)); + record->add(getSlot("Code", (unsigned int)object)); + return record; + } + INSPECTOR_P_SUPPORT(Hurricane::Instance); INSPECTOR_P_SUPPORT(Hurricane::Instance::PlacementStatus); INSPECTOR_P_SUPPORT(Hurricane::Instance::PlugMap); INSPECTOR_P_SUPPORT(Hurricane::Instance::SharedPathMap); -IOSTREAM_POINTER_SUPPORT(Hurricane::Instance::PlacementStatus::Code); -IOSTREAM_VALUE_SUPPORT(Hurricane::Instance::PlacementStatus::Code); #endif // HURRICANE_INSTANCE diff --git a/hurricane/src/hurricane/hurricane/TextTranslator.h b/hurricane/src/hurricane/hurricane/TextTranslator.h new file mode 100644 index 00000000..827c53dc --- /dev/null +++ b/hurricane/src/hurricane/hurricane/TextTranslator.h @@ -0,0 +1,72 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// +// =================================================================== +// +// $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@asim.lip6.fr | +// | =============================================================== | +// | C++ Header : "./TextTranslator.h" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#ifndef __HURRICANE_TEXT_TRANSLATOR__ +#define __HURRICANE_TEXT_TRANSLATOR__ + +#include +#include + +namespace Hurricane { + + + class TextTranslator { + public: + inline TextTranslator (); + inline void addTranslation ( const std::string& original, const std::string& translation ); + std::string translate ( const std::string& source ) const; + private: + class Translation { + public: + inline Translation ( const std::string& original, const std::string& translation ); + public: + std::string _original; + std::string _translation; + }; + private: + std::vector _translations; + }; + + +// Inline Methods. + inline TextTranslator::Translation::Translation ( const std::string& original + , const std::string& translation ) + : _original (original) + , _translation(translation) + { } + + inline TextTranslator::TextTranslator () : _translations() {} + + inline void TextTranslator::addTranslation ( const std::string& original + , const std::string& translation ) + { + _translations.push_back ( Translation(original,translation) ); + } + + +} // End of Hurricane namespace. + + +#endif // __HURRICANE_TEXT_TRANSLATOR__ diff --git a/hurricane/src/isobar/CMakeLists.txt b/hurricane/src/isobar/CMakeLists.txt index 7ae5d5c3..e989b582 100644 --- a/hurricane/src/isobar/CMakeLists.txt +++ b/hurricane/src/isobar/CMakeLists.txt @@ -1,5 +1,8 @@ + include ( ${QT_USE_FILE} ) + include_directories ( ${HURRICANE_SOURCE_DIR}/src/hurricane + ${HURRICANE_SOURCE_DIR}/src/viewer ${HURRICANE_SOURCE_DIR}/src/isobar ${PYTHON_INCLUDE_PATH} ) @@ -7,6 +10,7 @@ PyBox.cpp PyCell.cpp PyCellCollection.cpp + PyCellViewer.cpp PyComponent.cpp PyComponentCollection.cpp PyContact.cpp @@ -44,6 +48,7 @@ hurricane/isobar/PyBox.h hurricane/isobar/PyCell.h hurricane/isobar/PyCellCollection.h + hurricane/isobar/PyCellViewer.h hurricane/isobar/PyComponent.h hurricane/isobar/PyComponentCollection.h hurricane/isobar/PyContact.h diff --git a/hurricane/src/isobar/PyDbU.cpp b/hurricane/src/isobar/PyDbU.cpp index 297a2169..e81063a3 100644 --- a/hurricane/src/isobar/PyDbU.cpp +++ b/hurricane/src/isobar/PyDbU.cpp @@ -195,7 +195,8 @@ extern "C" { if ( ! PyArg_ParseTuple(args,"|O&:DbU.symbolic",Converter,&arg0) ) return ( NULL ); - if ( __cs.getObjectIds() == FLOAT_ARG ) { result = DbU::lambda ( PyFloat_AsDouble ( arg0 ) ); } + if ( __cs.getObjectIds() == FLOAT_ARG ) { result = DbU::lambda ( PyFloat_AsDouble ( arg0 ) ); } + else if ( __cs.getObjectIds() == INT_ARG ) { result = DbU::lambda ( PyLong_AsLong ( arg0 ) ); } else { PyErr_SetString ( ConstructorError, "invalid number of parameters or bad type for DbU.symbolic converter." ); return ( NULL ); diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp index a9e220bb..85cc4698 100644 --- a/hurricane/src/isobar/PyHurricane.cpp +++ b/hurricane/src/isobar/PyHurricane.cpp @@ -63,6 +63,7 @@ #include "hurricane/isobar/PyEntity.h" #include "hurricane/isobar/PyCell.h" #include "hurricane/isobar/PyCellCollection.h" +#include "hurricane/isobar/PyCellViewer.h" #include "hurricane/isobar/PyLayer.h" #include "hurricane/isobar/PyPin.h" #include "hurricane/isobar/PyPinCollection.h" @@ -516,7 +517,7 @@ extern "C" { , { "DataBase" , (PyCFunction)PyDataBase_create , METH_NOARGS , "Creates the DataBase." } , { "getDataBase" , (PyCFunction)PyDataBase_getDataBase , METH_NOARGS , "Gets the current DataBase." } , { "Library" , (PyCFunction)PyLibrary_create , METH_VARARGS, "Creates a new Library." } -// , { "getLibrary" , (PyCFunction)PyLibrary_getLibrary , METH_NOARGS , "Gets the current Library." } +// , { "getLibrary" , (PyCFunction)PyLibrary_getLibrary , METH_NOARGS , "Gets the current Library." } , { "Reference" , (PyCFunction)PyReference_create , METH_VARARGS, "Creates a new Reference." } , { "Cell" , (PyCFunction)PyCell_create , METH_VARARGS, "Creates a new Cell." } , { "Instance" , (PyCFunction)PyInstance_create , METH_VARARGS, "Creates a new Instance." } @@ -575,6 +576,7 @@ extern "C" { PyContact_LinkPyType (); PyPin_LinkPyType (); PyPlug_LinkPyType (); + PyCellViewer_LinkPyType (); PYTYPE_READY ( Point ) PYTYPE_READY ( Box ) @@ -605,6 +607,7 @@ extern "C" { PYTYPE_READY ( ReferenceCollection ) PYTYPE_READY ( ReferenceCollectionLocator ) PYTYPE_READY ( HyperNet ) + PYTYPE_READY ( CellViewer ) PYTYPE_READY_SUB ( Cell , Entity ) PYTYPE_READY_SUB ( Instance , Entity ) @@ -620,48 +623,48 @@ extern "C" { PYTYPE_READY_SUB ( Plug , Component) PYTYPE_READY_SUB ( Pad , Component) - // Identifier string can take up to 10 characters ! - __cs.addType ( "box" , &PyTypeBox , "" , false ); - __cs.addType ( "ent" , &PyTypeEntity , "" , false ); - __cs.addType ( "cell" , &PyTypeCell , "" , false, "ent" ); - __cs.addType ( "cellCol" , &PyTypeCellCollection , "" , false ); - __cs.addType ( "comp" , &PyTypeComponent , "" , false, "ent" ); - __cs.addType ( "compCol" , &PyTypeComponentCollection, "" , false ); - __cs.addType ( "contact" , &PyTypeContact , "" , false, "comp" ); - // Do not change the "none" string. It's hardwired to the None object. - __cs.addType ( "none" , Py_None->ob_type , "" , true ); - __cs.addType ( "float" , &PyFloat_Type , "" , true ); - __cs.addType ( "int" , &PyInt_Type , "" , true ); - __cs.addType ( "bool" , &PyBool_Type , "" , true ); - __cs.addType ( "string" , &PyString_Type , "" , true ); - __cs.addType ( "list" , &PyList_Type , "" , true ); + __cs.addType ( "box" , &PyTypeBox , "" , false ); + __cs.addType ( "ent" , &PyTypeEntity , "" , false ); + __cs.addType ( "cell" , &PyTypeCell , "" , false, "ent" ); + __cs.addType ( "cellCol" , &PyTypeCellCollection , "" , false ); + __cs.addType ( "cellView" , &PyTypeCellViewer , "" , false, "view" ); + __cs.addType ( "comp" , &PyTypeComponent , "" , false, "ent" ); + __cs.addType ( "compCol" , &PyTypeComponentCollection , "" , false ); + __cs.addType ( "contact" , &PyTypeContact , "" , false, "comp" ); + // Do not change the "none" string. It's hardwired to the None object. + __cs.addType ( "none" , Py_None->ob_type , "" , true ); + __cs.addType ( "float" , &PyFloat_Type , "" , true ); + __cs.addType ( "int" , &PyInt_Type , "" , true ); + __cs.addType ( "bool" , &PyBool_Type , "" , true ); + __cs.addType ( "string" , &PyString_Type , "" , true ); + __cs.addType ( "list" , &PyList_Type , "" , true ); // Do not change the "function" string. It's hardwired to callable (function) objects. - __cs.addType ( "function" , NULL , "" , true ); - __cs.addType ( "horiz" , &PyTypeHorizontal , "" , false, "segment" ); - __cs.addType ( "inst" , &PyTypeInstance , "" , false, "ent" ); - __cs.addType ( "instCol" , &PyTypeInstanceCollection, "" , false ); - __cs.addType ( "layer" , &PyTypeLayer , "" , false ); - __cs.addType ( "library" , &PyTypeLibrary , "" , false ); - __cs.addType ( "ref" , &PyTypeReference , "" , false, "ent" ); - __cs.addType ( "refCol" , &PyTypeReferenceCollection, "" , false ); - __cs.addType ( "net" , &PyTypeNet , "" , false, "ent" ); - __cs.addType ( "netCol" , &PyTypeNetCollection , "" , false ); - __cs.addType ( "hyperNet" , &PyTypeHyperNet , "" , false ); - __cs.addType ( "pin" , &PyTypePin , "" , false, "contact" ); - __cs.addType ( "pinCol" , &PyTypePinCollection , "" , false ); - __cs.addType ( "plug" , &PyTypePlug , "" , false, "comp" ); - __cs.addType ( "plugCol" , &PyTypePlugCollection , "" , false ); - __cs.addType ( "point" , &PyTypePoint , "" , false ); - __cs.addType ( "segment" , &PyTypeSegment , "" , false, "comp" ); - __cs.addType ( "pad " , &PyTypePad , "" , false, "comp" ); - __cs.addType ( "segmentCol" , &PyTypeSegmentCollection, "", false ); - __cs.addType ( "db" , &PyTypeDataBase , "" , false ); - __cs.addType ( "techno" , &PyTypeTechnology , "" , false ); - __cs.addType ( "transfo" , &PyTypeTransformation , "" , false ); - __cs.addType ( "vert" , &PyTypeVertical , "" , false, "segment" ); - __cs.addType ( "path" , &PyTypePath , "" , false ); - __cs.addType ( "occur" , &PyTypeOccurrence , "" , false ); + __cs.addType ( "function" , NULL , "" , true ); + __cs.addType ( "horiz" , &PyTypeHorizontal , "" , false, "segment" ); + __cs.addType ( "inst" , &PyTypeInstance , "" , false, "ent" ); + __cs.addType ( "instCol" , &PyTypeInstanceCollection , "" , false ); + __cs.addType ( "layer" , &PyTypeLayer , "" , false ); + __cs.addType ( "library" , &PyTypeLibrary , "" , false ); + __cs.addType ( "ref" , &PyTypeReference , "" , false, "ent" ); + __cs.addType ( "refCol" , &PyTypeReferenceCollection , "" , false ); + __cs.addType ( "net" , &PyTypeNet , "" , false, "ent" ); + __cs.addType ( "netCol" , &PyTypeNetCollection , "" , false ); + __cs.addType ( "hyperNet" , &PyTypeHyperNet , "" , false ); + __cs.addType ( "pin" , &PyTypePin , "" , false, "contact" ); + __cs.addType ( "pinCol" , &PyTypePinCollection , "" , false ); + __cs.addType ( "plug" , &PyTypePlug , "" , false, "comp" ); + __cs.addType ( "plugCol" , &PyTypePlugCollection , "" , false ); + __cs.addType ( "point" , &PyTypePoint , "" , false ); + __cs.addType ( "segment" , &PyTypeSegment , "" , false, "comp" ); + __cs.addType ( "pad " , &PyTypePad , "" , false, "comp" ); + __cs.addType ( "segmentCol" , &PyTypeSegmentCollection , "" , false ); + __cs.addType ( "db" , &PyTypeDataBase , "" , false ); + __cs.addType ( "techno" , &PyTypeTechnology , "" , false ); + __cs.addType ( "transfo" , &PyTypeTransformation , "" , false ); + __cs.addType ( "vert" , &PyTypeVertical , "" , false, "segment" ); + __cs.addType ( "path" , &PyTypePath , "" , false ); + __cs.addType ( "occur" , &PyTypeOccurrence , "" , false ); __cs.addType ( "occurCol" , &PyTypeOccurrenceCollection, "", false ); diff --git a/hurricane/src/isobar/Script.cpp b/hurricane/src/isobar/Script.cpp index 10cf7e43..c33c07da 100644 --- a/hurricane/src/isobar/Script.cpp +++ b/hurricane/src/isobar/Script.cpp @@ -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. // @@ -42,13 +42,22 @@ #include "hurricane/Error.h" #include "hurricane/Cell.h" #include "hurricane/isobar/PyCell.h" +#include "hurricane/isobar/PyCellViewer.h" #include "hurricane/isobar/Script.h" +namespace { + + const char* __editorKw = "__editor"; + +} // End of anonymous namespace. + + namespace Isobar { using std::string; using Hurricane::Cell; + using Hurricane::CellViewer; // ------------------------------------------------------------------- @@ -62,17 +71,34 @@ namespace Isobar { { _pathes.push_back ( path ); } - Script::Script ( const string& name ) - : _moduleName(name) - , _sysModule (NULL) - , _userModule(NULL) + void Script::removePath ( const string& path ) { + vector::iterator ipath = _pathes.begin(); + for ( ; ipath != _pathes.end() ; ++ipath ) { + if ( (*ipath) == path ) { + _pathes.erase ( ipath ); + return; + } + } } + Script::Script ( const string& name ) + : _moduleName (name) + , _sysModule (NULL) + , _hurricaneModule(NULL) + , _userModule (NULL) + , _pyFunction (NULL) + , _pyArgs (NULL) + , _pyResult (NULL) + , _cellViewer (NULL) + { } + + Script::~Script () { - _destroyModules(); + _finalize(); + Py_Finalize (); } @@ -89,16 +115,15 @@ namespace Isobar { } + void Script::setEditor ( CellViewer* viewer ) + { _cellViewer = viewer; } + + 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" ); + _initialize (); _userModule = PyImport_ImportModule ( const_cast(_moduleName.c_str()) ); @@ -106,36 +131,35 @@ namespace Isobar { if ( PyErr_Occurred() ) { PyErr_Print (); } + _finalize (); 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 (); + _setEditor (); + + _pyFunction = PyObject_GetAttrString(_userModule, const_cast(function.c_str())); + if ( (_pyFunction == NULL) or not PyCallable_Check(_pyFunction) ) { + _finalize (); 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) ); + _pyArgs = PyTuple_New(1); + if ( cell != NULL ) PyTuple_SetItem ( _pyArgs, 0, (PyObject*)PyCell_Link(cell) ); + else PyTuple_SetItem ( _pyArgs, 0, Py_None ); - PyObject* pyResult = PyEval_CallObject ( pyFunction, pyArgs ); + _pyResult = PyEval_CallObject ( _pyFunction, _pyArgs ); - if ( pyResult == NULL ) { + 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 (); + _finalize(); return true; } @@ -143,6 +167,9 @@ namespace Isobar { void Script::_importSys () { + if ( not Py_IsInitialized() ) + throw Error ( "Script::_importSys(): Called before Py_Initialize()." ); + _sysModule = _importModule ( "sys" ); PyObject* path = PyObject_GetAttrString ( _sysModule, "path" ); @@ -152,15 +179,22 @@ namespace Isobar { 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(__editorKw), Py_None ); } @@ -178,15 +212,50 @@ namespace Isobar { } - void Script::_destroyModules () + void Script::_initialize () + { + Py_Initialize (); + _importSys (); + _importHurricane (); + } + + + void Script::_finalize () { if ( not Py_IsInitialized() ) return; - if ( _userModule != NULL ) Py_DECREF ( _userModule ); - if ( _sysModule != NULL ) Py_DECREF ( _sysModule ); + if ( _pyResult != NULL ) Py_DECREF ( _pyResult ); + if ( _pyArgs != NULL ) Py_DECREF ( _pyArgs ); + if ( _pyFunction != NULL ) Py_DECREF ( _pyFunction ); + if ( _userModule != NULL ) Py_DECREF ( _userModule ); + if ( _hurricaneModule != NULL ) Py_DECREF ( _hurricaneModule ); + if ( _sysModule != NULL ) Py_DECREF ( _sysModule ); - _userModule = NULL; - _sysModule = NULL; + Py_Finalize (); + + _userModule = NULL; + _sysModule = NULL; + _hurricaneModule = NULL; + _pyFunction = NULL; + _pyArgs = NULL; + _pyResult = NULL; + } + + + void Script::_setEditor () + { + if ( _userModule == NULL ) return; + + PyObject* dictionary = PyModule_GetDict ( _userModule ); + + if ( _cellViewer != NULL ) { + PyCellViewer* pyCellViewer = PyObject_NEW ( PyCellViewer, &PyTypeCellViewer ); + pyCellViewer->_object = _cellViewer; + + PyDict_SetItemString ( dictionary, __editorKw, (PyObject*)pyCellViewer ); + } else { + PyDict_SetItemString ( dictionary, __editorKw, Py_None ); + } } diff --git a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h index 72bdbd59..d5066cef 100644 --- a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h +++ b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h @@ -599,6 +599,33 @@ extern "C" { PyObject_DEL ( self ); \ } +// ------------------------------------------------------------------- +// Attribute Method For Singleton Deletion. + +// # define SingletonDeleteMethod(SELF_TYPE) +// static void Py##SELF_TYPE##_DeAlloc ( Py##SELF_TYPE *self ) +// { +// trace << "PySingletonObject_DeAlloc(" << hex << self << ") " +// << self->ACCESS_OBJECT << endl; +// +// if ( self->ACCESS_OBJECT != NULL ) { +// ostringstream message; +// message << "Never delete singleton "#SELF_TYPE"."; +// PyErr_SetString ( ProxyError, message.str().c_str() ); +// } +// PyObject_DEL ( self ); +// } + +// ------------------------------------------------------------------- +// Attribute Method For Singleton Deletion. + +# define SingletonDeleteMethod(SELF_TYPE) \ + static void Py##SELF_TYPE##_DeAlloc ( Py##SELF_TYPE *self ) \ + { \ + trace << "PySingletonObject_DeAlloc(" << hex << self << ") " \ + << self->ACCESS_OBJECT << endl; \ + } + diff --git a/hurricane/src/isobar/hurricane/isobar/Script.h b/hurricane/src/isobar/hurricane/isobar/Script.h index 15c0ad96..31edd481 100644 --- a/hurricane/src/isobar/hurricane/isobar/Script.h +++ b/hurricane/src/isobar/hurricane/isobar/Script.h @@ -45,6 +45,7 @@ #include namespace Hurricane { class Cell; + class CellViewer; } @@ -53,29 +54,43 @@ 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 ); + static void addPath ( const std::string& path ); + static void removePath ( const std::string& path ); + static Script* create ( const std::string& name ); + void destroy (); + inline PyObject* getSysModule (); + inline PyObject* getHurricaneModule (); + inline PyObject* getUserModule (); + void setEditor ( Hurricane::CellViewer* ); + bool runFunction ( const std::string& function, Hurricane::Cell* cell ); protected: static std::vector _pathes; std::string _moduleName; PyObject* _sysModule; + PyObject* _hurricaneModule; PyObject* _userModule; + PyObject* _pyFunction; + PyObject* _pyArgs; + PyObject* _pyResult; + Hurricane::CellViewer* _cellViewer; protected: - Script ( const std::string& name ); - ~Script (); - Script ( const Script& ); - Script& operator= ( const Script& ); - void _importSys (); - PyObject* _importModule ( const std::string& ); - void _destroyModules (); + Script ( const std::string& name ); + ~Script (); + Script ( const Script& ); + Script& operator= ( const Script& ); + void _importSys (); + void _importHurricane (); + PyObject* _importModule ( const std::string& ); + void _initialize (); + void _finalize (); + void _setEditor (); }; // Inline Methods. - inline PyObject* Script::getUserModule () { return _userModule; } + inline PyObject* Script::getSysModule () { return _sysModule; } + inline PyObject* Script::getHurricaneModule () { return _hurricaneModule; } + inline PyObject* Script::getUserModule () { return _userModule; } } // End of Isobar namespace. diff --git a/hurricane/src/viewer/CMakeLists.txt b/hurricane/src/viewer/CMakeLists.txt index a4452d84..fc679018 100644 --- a/hurricane/src/viewer/CMakeLists.txt +++ b/hurricane/src/viewer/CMakeLists.txt @@ -2,9 +2,11 @@ include ( ${QT_USE_FILE} ) include_directories ( ${HURRICANE_SOURCE_DIR}/src/hurricane + ${HURRICANE_SOURCE_DIR}/src/isobar ${HURRICANE_SOURCE_DIR}/src/viewer ${CONFIGURATION_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} + ${PYTHON_INCLUDE_PATH} ) set ( mocincludes hurricane/viewer/HApplication.h @@ -32,6 +34,7 @@ hurricane/viewer/NetlistWidget.h hurricane/viewer/DisplayFilterWidget.h hurricane/viewer/ControllerWidget.h + hurricane/viewer/ScriptWidget.h ) set ( exports hurricane/viewer/HApplication.h hurricane/viewer/ScreenUtilities.h @@ -65,6 +68,7 @@ hurricane/viewer/NetlistWidget.h hurricane/viewer/DisplayFilterWidget.h hurricane/viewer/ControllerWidget.h + hurricane/viewer/ScriptWidget.h hurricane/viewer/PaletteWidget.h ) set ( cpps HApplication.cpp @@ -106,6 +110,7 @@ NetlistWidget.cpp DisplayFilterWidget.cpp ControllerWidget.cpp + ScriptWidget.cpp ) qt4_wrap_cpp ( MOC_SRCS ${mocincludes} ) diff --git a/hurricane/src/viewer/CellViewer.cpp b/hurricane/src/viewer/CellViewer.cpp index 053f2304..536c8517 100644 --- a/hurricane/src/viewer/CellViewer.cpp +++ b/hurricane/src/viewer/CellViewer.cpp @@ -44,6 +44,7 @@ #include "hurricane/viewer/CellViewer.h" #include "hurricane/viewer/MousePositionWidget.h" #include "hurricane/viewer/ControllerWidget.h" +#include "hurricane/viewer/ScriptWidget.h" #include "hurricane/viewer/GotoWidget.h" @@ -67,6 +68,7 @@ namespace Hurricane { , _rubberChangeAction (NULL) , _clearRulersAction (NULL) , _controllerAction (NULL) + , _scriptAction (NULL) , _fileMenu (NULL) , _viewMenu (NULL) , _toolsMenu (NULL) @@ -74,6 +76,7 @@ namespace Hurricane { //, _mapView (NULL) , _mousePosition (NULL) , _controller (NULL) + , _script (NULL) , _goto (NULL) , _cellWidget (NULL) , _moveCommand () @@ -96,6 +99,7 @@ namespace Hurricane { CellViewer::~CellViewer () { _controller->deleteLater (); + //_script->deleteLater (); _goto->deleteLater (); } @@ -198,6 +202,12 @@ namespace Hurricane { _controllerAction->setStatusTip ( tr("Fine Tune && Inspect DataBase") ); _controllerAction->setIcon ( QIcon(":/images/swiss-knife.png") ); _controllerAction->setShortcut ( QKeySequence(tr("CTRL+I")) ); + + _scriptAction = new QAction ( tr("Script"), this ); + _scriptAction->setObjectName ( "viewer.menuBar.tools.script" ); + _scriptAction->setStatusTip ( tr("Run Python Script") ); + _scriptAction->setIcon ( QIcon(":/images/python-logo-v3.png") ); + //_scriptAction->setShortcut ( QKeySequence(tr("CTRL+I")) ); } @@ -236,6 +246,7 @@ namespace Hurricane { _toolsMenu = menuBar()->addMenu ( tr("Tools") ); _toolsMenu->setObjectName ( "viewer.menuBar.tools" ); _toolsMenu->addAction ( _controllerAction ); + _toolsMenu->addAction ( _scriptAction ); } @@ -293,6 +304,7 @@ namespace Hurricane { connect ( _rubberChangeAction , SIGNAL(triggered()) , _cellWidget, SLOT(rubberChange()) ); connect ( _clearRulersAction , SIGNAL(triggered()) , _cellWidget, SLOT(clearRulers()) ); connect ( _controllerAction , SIGNAL(triggered()) , _controller, SLOT(toggleShow()) ); + connect ( _scriptAction , SIGNAL(triggered()) , this , SLOT(runScript()) ); connect ( _gotoAction , SIGNAL(triggered()) , this , SLOT(doGoto()) ); connect ( _cellWidget , SIGNAL(dbuModeChanged(unsigned int,DbU::UnitPower)) @@ -531,4 +543,10 @@ namespace Hurricane { } + void CellViewer::runScript () + { + ScriptWidget::runScript ( this, getCell() ); + } + + } // End of Hurricane namespace. diff --git a/hurricane/src/viewer/CellViewer.qrc b/hurricane/src/viewer/CellViewer.qrc index 168c250e..b9c33291 100644 --- a/hurricane/src/viewer/CellViewer.qrc +++ b/hurricane/src/viewer/CellViewer.qrc @@ -9,6 +9,7 @@ images/gtk-go-forward-rtl.png images/gtk-go-forward-ltr.png images/swiss-knife.png + images/python-logo-v3.png images/gnome-gmush.png images/gnome-core.png images/i-core.png diff --git a/hurricane/src/viewer/CellWidget.cpp b/hurricane/src/viewer/CellWidget.cpp index fa7c5a9c..e4229aa8 100644 --- a/hurricane/src/viewer/CellWidget.cpp +++ b/hurricane/src/viewer/CellWidget.cpp @@ -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 // // =================================================================== // diff --git a/hurricane/src/viewer/ScriptWidget.cpp b/hurricane/src/viewer/ScriptWidget.cpp new file mode 100644 index 00000000..e3e3e299 --- /dev/null +++ b/hurricane/src/viewer/ScriptWidget.cpp @@ -0,0 +1,141 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | C O R I O L I S | +// | 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@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./ScriptWidget.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#include +#include +using namespace std; + +#include +namespace bfs = boost::filesystem; + +#include "hurricane/Warning.h" +#include "hurricane/isobar/Script.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hurricane/viewer/Graphics.h" +#include "hurricane/viewer/ScriptWidget.h" +#include "hurricane/viewer/CellViewer.h" + + +namespace Hurricane { + + +// ------------------------------------------------------------------- +// Class : "ScriptWidget". + + + ScriptWidget::ScriptWidget ( QWidget* parent ) + : QDialog (parent) + , _lineEdit(NULL) + { + setWindowTitle ( tr("Run Script") ); + + QLabel* label = new QLabel (); + label->setText ( tr("Python script to execute") ); + label->setFont ( Graphics::getNormalFont(true) ); + + _lineEdit = new QLineEdit (); + _lineEdit->setMinimumWidth ( 400 ); + + QPushButton* okButton = new QPushButton (); + okButton->setText ( "OK" ); + okButton->setDefault ( true ); + + QPushButton* cancelButton = new QPushButton (); + cancelButton->setText ( "Cancel" ); + + QHBoxLayout* hLayout1 = new QHBoxLayout (); + hLayout1->addStretch (); + hLayout1->addWidget ( okButton ); + hLayout1->addStretch (); + hLayout1->addWidget ( cancelButton ); + hLayout1->addStretch (); + + //QFrame* separator = new QFrame (); + //separator->setFrameShape ( QFrame::HLine ); + //separator->setFrameShadow ( QFrame::Sunken ); + + QVBoxLayout* vLayout = new QVBoxLayout (); + vLayout->setSizeConstraint ( QLayout::SetFixedSize ); + vLayout->addWidget ( label ); + vLayout->addWidget ( _lineEdit ); + vLayout->addLayout ( hLayout1 ); + //vLayout->addWidget ( separator ); + + setLayout ( vLayout ); + //setModal ( true ); + + connect ( okButton, SIGNAL(clicked()) , this, SLOT(accept()) ); + connect ( cancelButton, SIGNAL(clicked()) , this, SLOT(reject()) ); + } + + + const QString ScriptWidget::getScriptName () const + { + return _lineEdit->text(); + } + + + bool ScriptWidget::runScript ( QWidget* parent, Cell* cell ) + { + ScriptWidget* dialog = new ScriptWidget ( parent ); + bool doRunScript = (dialog->exec() == Accepted); + QString scriptName = dialog->getScriptName (); + + delete dialog; + if ( not doRunScript ) return false; + + if ( scriptName.endsWith(".py",Qt::CaseInsensitive) ) + scriptName.truncate ( scriptName.size()-3 ); + + bfs::path userScript = scriptName.toStdString(); + bfs::path userDirectory = userScript.branch_path(); + + if ( not userDirectory.is_complete() ) + userDirectory = bfs::current_path() / userDirectory; + userDirectory.normalize(); + + Isobar::Script::addPath ( userDirectory.string() ); + + dbo_ptr script = Isobar::Script::create(userScript.leaf()); + script->setEditor ( qobject_cast(parent) ); + + bool returnCode = script->runFunction ( "__hurricane_main__", cell ); + + Isobar::Script::removePath ( userDirectory.string() ); + + return returnCode; + } + + +} // End of Hurricane namespace. diff --git a/hurricane/src/viewer/hurricane/viewer/CellViewer.h b/hurricane/src/viewer/hurricane/viewer/CellViewer.h index 94b79ec8..daca5283 100644 --- a/hurricane/src/viewer/hurricane/viewer/CellViewer.h +++ b/hurricane/src/viewer/hurricane/viewer/CellViewer.h @@ -57,6 +57,7 @@ namespace Hurricane { class GotoWidget; class MousePositionWidget; class ControllerWidget; + class ScriptWidget; class CellViewer : public QMainWindow { @@ -90,6 +91,7 @@ namespace Hurricane { void imageDisplay (); void raiseToolInterrupt (); void clearToolInterrupt (); + void runScript (); signals: void showSelectionToggled ( bool ); void stateChanged ( shared_ptr& ); @@ -119,6 +121,7 @@ namespace Hurricane { QAction* _rubberChangeAction; QAction* _clearRulersAction; QAction* _controllerAction; + QAction* _scriptAction; QMenu* _fileMenu; QMenu* _viewMenu; QMenu* _toolsMenu; @@ -126,6 +129,7 @@ namespace Hurricane { //MapView* _mapView; MousePositionWidget* _mousePosition; ControllerWidget* _controller; + ScriptWidget* _script; GotoWidget* _goto; CellWidget* _cellWidget; MoveCommand _moveCommand; diff --git a/hurricane/src/viewer/hurricane/viewer/ScriptWidget.h b/hurricane/src/viewer/hurricane/viewer/ScriptWidget.h new file mode 100644 index 00000000..9e179bf2 --- /dev/null +++ b/hurricane/src/viewer/hurricane/viewer/ScriptWidget.h @@ -0,0 +1,55 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | C O R I O L I S | +// | 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@asim.lip6.fr | +// | =============================================================== | +// | C++ Header : "./ScriptWidget.h" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#ifndef __HURRICANE_SCRIPT_WIDGET__ +#define __HURRICANE_SCRIPT_WIDGET__ + +#include + +class QLineEdit; + + +namespace Hurricane { + + class Cell; + + + class ScriptWidget : public QDialog { + Q_OBJECT; + public: + static bool runScript ( QWidget* parent, Cell* ); + const QString getScriptName () const; + protected: + ScriptWidget ( QWidget* parent=NULL ); + protected: + QLineEdit* _lineEdit; + }; + + +} // End of Hurricane namespace. + + +#endif // __HURRICANE_SCRIPT_WIDGET__ + diff --git a/hurricane/src/viewer/images/python-logo-v3.png b/hurricane/src/viewer/images/python-logo-v3.png new file mode 100644 index 00000000..66671525 Binary files /dev/null and b/hurricane/src/viewer/images/python-logo-v3.png differ