Simplification of the Hurricane::Observer mechanism.

* Change: In Hurricane::Observer, simplification of the template so that
    we can use it directly instead of creating a derived class with an
    implementation of Observer::notify(). Now the implemenation is the
    same for all and just calls a notify() method on the owner object.
      Create a StaticObservable for fast access of the observers. This
    is mainly a fixed size table (array<>) with oberservers at known
    indexes. This way we can go from the obervable to the observer
    owner in one indirect access (or so I hope).
* Change: In Hurricane::CellViewer, use the new observers.
* Change: In Hurricane::ControllerWidget, use the new observers.
* Change: In Hurricane::CellWidget, set the winidow initial size to a
   more sensible 500px.
* Change: In CRL::LibraryManager, use the new observers.
* Change: In CRL::LibraryManager, use the new observers.
* Change: In CRL, in display.conf & technology.conf, modification for
    the ST hcmos9gp capacitors.
This commit is contained in:
Jean-Paul Chaput 2016-06-03 17:19:46 +02:00
parent fac3474d55
commit 747027f23a
10 changed files with 232 additions and 192 deletions

View File

@ -63,10 +63,10 @@ stylesTable = \
# Group: MIM6.
, (Group , 'MIM6')
, (Drawing, 'topmim6', { 'color':'Blue' , 'pattern':'poids2.8' , 'threshold':0.80*scale })
, (Drawing, 'botmim6', { 'color':'Aqua' , 'pattern':'light_antihash0.8', 'threshold':0.80*scale })
, (Drawing, 'padopen', { 'color':'LightPink', 'pattern':'light_antihash1.8', 'threshold':0.80*scale })
, (Drawing, 'alucap' , { 'color':'Green' , 'pattern':'light_antihash2.8', 'threshold':0.80*scale })
#, (Drawing, 'topmim6', { 'color':'Blue' , 'pattern':'poids2.8' , 'threshold':0.80*scale })
, (Drawing, 'metbot' , { 'color':'Aqua' , 'pattern':'light_antihash0.8', 'threshold':0.80*scale })
, (Drawing, 'cut6' , { 'color':'LightPink', 'pattern':'light_antihash1.8', 'threshold':0.80*scale })
, (Drawing, 'metal7' , { 'color':'Green' , 'pattern':'light_antihash2.8', 'threshold':0.80*scale })
# Group: Blockages.
, (Group , 'Blockages')
@ -169,10 +169,10 @@ stylesTable = \
# MIM6.
, (Group , 'MIM6')
, (Drawing, 'topmim6', { 'color':'Blue' , 'pattern':'poids2.32' , 'threshold':0.80*scale })
, (Drawing, 'botmim6', { 'color':'Aqua' , 'pattern':'light_antihash0.8' , 'threshold':0.80*scale })
, (Drawing, 'padopen', { 'color':'LightPink', 'pattern':'light_antihash1.8' , 'threshold':0.80*scale })
, (Drawing, 'alucap' , { 'color':'Green' , 'pattern':'light_antihash2.8' , 'threshold':0.80*scale })
#, (Drawing, 'topmim6', { 'color':'Blue' , 'pattern':'poids2.32' , 'threshold':0.80*scale })
, (Drawing, 'metbot' , { 'color':'Aqua' , 'pattern':'light_antihash0.8' , 'threshold':0.80*scale })
#, (Drawing, 'padopen', { 'color':'LightPink', 'pattern':'light_antihash1.8' , 'threshold':0.80*scale })
, (Drawing, 'metal7' , { 'color':'Green' , 'pattern':'light_antihash2.8' , 'threshold':0.80*scale })
# Blockages.
, (Group , 'Blockages')
@ -345,10 +345,10 @@ stylesTable = \
# Group: MIM6.
, (Group , 'MIM6')
, (Drawing, 'topmim6', { 'color':'Blue' , 'pattern':'poids2.8' , 'threshold':0.80*scale })
, (Drawing, 'botmim6', { 'color':'Aqua' , 'pattern':'light_antihash0.8', 'threshold':0.80*scale })
, (Drawing, 'padopen', { 'color':'LightPink', 'pattern':'light_antihash1.8', 'threshold':0.80*scale })
, (Drawing, 'alucap' , { 'color':'Green' , 'pattern':'light_antihash2.8', 'threshold':0.80*scale })
#, (Drawing, 'topmim6', { 'color':'Blue' , 'pattern':'poids2.8' , 'threshold':0.80*scale })
, (Drawing, 'metbot' , { 'color':'Aqua' , 'pattern':'light_antihash0.8', 'threshold':0.80*scale })
, (Drawing, 'cut6' , { 'color':'LightPink', 'pattern':'light_antihash1.8', 'threshold':0.80*scale })
, (Drawing, 'metal7' , { 'color':'Green' , 'pattern':'light_antihash2.8', 'threshold':0.80*scale })
# Group: Blockages.
, (Group , 'Blockages')

View File

@ -53,10 +53,10 @@ realLayersTable = \
, ('metal7' , BasicLayer.Material.metal )
, ('cut7' , BasicLayer.Material.cut )
, ('metal8' , BasicLayer.Material.metal )
, ('topmim6' , BasicLayer.Material.other ) # For Capacitances & Pads.
, ('botmim6' , BasicLayer.Material.other )
, ('padopen' , BasicLayer.Material.other )
, ('alucap' , BasicLayer.Material.other )
#, ('topmim6' , BasicLayer.Material.other ) # For Capacitances & Pads.
#, ('metbot' , BasicLayer.Material.other )
#, ('padopen' , BasicLayer.Material.other )
#, ('alucap' , BasicLayer.Material.other )
, ('text.cell' , BasicLayer.Material.other ) # Misc. non-physical layers.
, ('text.instance', BasicLayer.Material.other ) # Used by the software for visualization
@ -134,7 +134,7 @@ symbolicLayersTable = \
# This is a simple list of Real & Symbolic layers.
workingLayersTable = \
[ 'cut0', 'cut1' , 'cut2' , 'cut3' , 'cut4' , 'cut5'
[ 'cut0', 'cut1' , 'cut2' , 'cut3' , 'cut4' , 'cut5' , 'cut6'
, 'POLY', 'POLY2'
, 'METAL1' , 'METAL2' , 'METAL3' , 'METAL4' , 'METAL5' , 'METAL6' , 'METAL7' , 'METAL8'
, 'BLOCKAGE1', 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4', 'BLOCKAGE5', 'BLOCKAGE6', 'BLOCKAGE7', 'BLOCKAGE8'

View File

@ -43,9 +43,10 @@ namespace CRL {
// -------------------------------------------------------------------
// Class : "FrameworkObserver".
void FrameworkObserver::notify ( unsigned int flags )
//void FrameworkObserver::notify ( unsigned int flags )
void LibraryManager::notify ( LibraryManager* manager, unsigned int flags )
{
LibraryManager* manager = getOwner();
//LibraryManager* manager = getOwner();
if (flags & (AllianceFramework::AddedLibrary
|AllianceFramework::RemovedLibrary)) {
manager->getLibrariesWidget()->update();

View File

@ -43,29 +43,14 @@ namespace CRL {
class LibraryManager;
// -------------------------------------------------------------------
// Class : "FrameworkObserver".
class FrameworkObserver : public Observer<LibraryManager> {
public:
inline FrameworkObserver ( LibraryManager* );
virtual void notify ( unsigned int flags );
private:
FrameworkObserver ( const FrameworkObserver& );
};
inline FrameworkObserver::FrameworkObserver ( LibraryManager* owner )
: Observer<LibraryManager>(owner)
{ }
// -------------------------------------------------------------------
// Class : "LibraryManager".
class LibraryManager : public QWidget {
Q_OBJECT;
public:
static void notify ( LibraryManager*, unsigned int flags );
public:
LibraryManager ( QWidget* parent=NULL );
~LibraryManager ();
@ -78,12 +63,12 @@ namespace CRL {
CellViewer* openCell ( Cell*, unsigned int flags );
void updateLibrary ( Cell* );
private:
FrameworkObserver _frameworkObserver;
LibrariesWidget* _librariesWidget;
CellsWidget* _cellsWidget;
ViewsWidget* _viewsWidget;
CellViewer* _cellViewer;
QLabel* _libPath;
Observer<LibraryManager> _frameworkObserver;
LibrariesWidget* _librariesWidget;
CellsWidget* _cellsWidget;
ViewsWidget* _viewsWidget;
CellViewer* _cellViewer;
QLabel* _libPath;
};

View File

@ -30,44 +30,44 @@ namespace Hurricane {
class BaseObserver {
public:
virtual void notify ( unsigned int flags );
template< typename T >
inline T* as ();
};
template< typename T>
inline T* BaseObserver::as () { return dynamic_cast<T*>(this); }
template< typename T>
template< typename OwnerT>
class Observer : public BaseObserver {
public:
inline Observer ( const T* owner );
inline T* getOwner () const;
inline Observer ( const OwnerT* owner );
inline OwnerT* getOwner () const;
virtual void notify ( unsigned int flags );
private:
Observer ( const Observer& );
Observer ( const Observer& );
Observer& operator= ( const Observer& );
private:
static int _ownerOffset;
};
template< typename T>
int Observer<T>::_ownerOffset = -1;
template< typename OwnerT>
int Observer<OwnerT>::_ownerOffset = -1;
template< typename T>
inline Observer<T>::Observer ( const T* owner )
template< typename OwnerT>
inline Observer<OwnerT>::Observer ( const OwnerT* owner )
: BaseObserver()
{
if (owner == NULL)
throw Hurricane::Error( "Observer::Observer(), attempt to create with NULL owner." );
throw Error( "Observer::Observer(), attempt to create with NULL owner." );
if (_ownerOffset < 0)
_ownerOffset = (unsigned long)this - (unsigned long)owner;
if (_ownerOffset < 0) _ownerOffset = (unsigned long)this - (unsigned long)owner;
}
template< typename T>
inline T* Observer<T>::getOwner () const { return reinterpret_cast<T*>((unsigned long)this - _ownerOffset); }
template< typename OwnerT>
inline OwnerT* Observer<OwnerT>::getOwner () const
{ return reinterpret_cast<OwnerT*>((unsigned long)this - _ownerOffset); }
template< typename OwnerT>
void Observer<OwnerT>::notify ( unsigned int flags )
{ OwnerT::notify( getOwner(), flags ); }
// -------------------------------------------------------------------
@ -104,6 +104,65 @@ namespace Hurricane {
}
// -------------------------------------------------------------------
// Class : "StaticObservable".
template<size_t slotsNb>
class StaticObservable {
public:
inline StaticObservable ();
inline const std::array<BaseObserver*,slotsNb>&
getObservers () const;
inline void setObserver ( size_t slot, BaseObserver* );
inline void notify ( unsigned int flags );
template<typename OwnerT>
inline OwnerT* getObserver ( size_t slot ) const;
private:
StaticObservable ( const StaticObservable& );
StaticObservable& operator= ( const StaticObservable& );
private:
std::array<BaseObserver*,slotsNb> _observers;
};
template<size_t slotsNb>
inline StaticObservable<slotsNb>::StaticObservable ()
: _observers()
{ }
template<size_t slotsNb>
inline const std::array<BaseObserver*,slotsNb>& StaticObservable<slotsNb>::getObservers () const
{ return _observers; }
template<size_t slotsNb>
inline void StaticObservable<slotsNb>::notify ( unsigned int flags )
{
for ( BaseObserver* iobserver : _observers ) {
if (iobserver) iobserver->notify( flags );
}
}
template<size_t slotsNb>
inline void StaticObservable<slotsNb>::setObserver ( size_t slot, BaseObserver* observer )
{
if (slot < _observers.size()) _observers[slot] = observer;
else
throw Error( "StaticObserver::setObserver(): Trying to access out of range slot %u (size:%u)."
, slot, _observers.size()
);
}
template<size_t slotsNb>
template<typename OwnerT>
inline OwnerT* StaticObservable<slotsNb>::getObserver ( size_t slot ) const
{ return (slot < _observers.size()) ? static_cast< Observer<OwnerT>* >(_observers[slot])->getOwner() : NULL; }
} // Hurricane namespace.
#endif

View File

@ -62,9 +62,12 @@ namespace Hurricane {
// -------------------------------------------------------------------
// Class : "CellObserver".
void CellObserver::notify ( unsigned int flags )
// void CellObserver::notify ( unsigned int flags )
void CellViewer::notify ( CellViewer* viewer, unsigned int flags )
{
CellViewer* viewer = getOwner();
cdebug.log(111) << "CellViewer::notify() " << viewer << endl;
//CellViewer* viewer = getOwner();
switch ( flags & (Cell::Flags::CellAboutToChange
|Cell::Flags::CellChanged
|Cell::Flags::CellDestroyed) ) {

View File

@ -1042,7 +1042,7 @@ namespace Hurricane {
// Class : "Hurricane::CellWidget".
int CellWidget::_initialSide = 250;
int CellWidget::_initialSide = 500;
CellWidget::CellWidget ( QWidget* parent )

View File

@ -661,9 +661,11 @@ namespace Hurricane {
// -------------------------------------------------------------------
// Class : "ControllerWidget::GraphicsObserver".
void ControllerWidget::GraphicsObserver::notify ( unsigned int flags )
//void ControllerWidget::GraphicsObserver::notify ( unsigned int flags )
void ControllerWidget::notify ( ControllerWidget* controller, unsigned int flags )
{
ControllerWidget* controller = getOwner();
cdebug.log(111) << "ControllerWidget::notify()" << endl;
//ControllerWidget* controller = getOwner();
if (flags & Graphics::ChangedDisplayStyles) {
controller->graphicsUpdated();
}

View File

@ -57,18 +57,18 @@ namespace Hurricane {
// -------------------------------------------------------------------
// Class : "CellObserver".
class CellObserver : public Observer<CellViewer> {
public:
inline CellObserver ( CellViewer* );
virtual void notify ( unsigned int flags );
private:
CellObserver ( const CellObserver& );
};
// class CellObserver : public Observer<CellViewer> {
// public:
// inline CellObserver ( CellViewer* );
// virtual void notify ( unsigned int flags );
// private:
// CellObserver ( const CellObserver& );
// };
inline CellObserver::CellObserver ( CellViewer* owner )
: Observer<CellViewer>(owner)
{ }
// inline CellObserver::CellObserver ( CellViewer* owner )
// : Observer<CellViewer>(owner)
// { }
// -------------------------------------------------------------------
@ -86,90 +86,92 @@ namespace Hurricane {
typedef std::map< const QString, boost::any > ActionLut;
typedef bool (QWidget::* SlotMethod)();
public:
CellViewer ( QWidget* parent=NULL );
virtual ~CellViewer ();
inline bool isToolInterrupted () const;
QMenu* createDebugMenu ();
bool hasMenu ( const QString& path ) const;
bool hasMenuAction ( const QString& path ) const;
QMenu* addMenu ( const QString& path
, std::string text
, unsigned int flags=NoFlags
);
bool addToMenu ( const QString& path );
QAction* addToMenu ( const QString& path
, std::string text
, std::string textTip
, std::function< void() >
, QIcon icon=QIcon() );
QAction* addToMenu ( const QString& path
, std::string text
, std::string textTip
, std::string scriptPath );
QAction* addToMenu ( QString path
, QString text
, QString textTip
, const QKeySequence& shortCut
, QIcon icon =QIcon());
inline void setEnableRedrawInterrupt ( bool );
inline void setApplicationName ( const QString& );
inline CellObserver* getCellObserver ();
Cell* getCell () const;
virtual void setCell ( Cell* );
void renameCell ( const char* );
virtual Cell* getCellFromDb ( const char* );
inline CellWidget* getCellWidget ();
inline const CellWidget* getCellWidget () const;
inline ControllerWidget* getControllerWidget ();
void setAnonNetSelectable ( bool );
void select ( Occurrence& );
void unselect ( Occurrence& );
void unselectAll ();
inline void setLayerVisible ( const Name& layer, bool visible );
void runScript ( QString scriptPath );
virtual CellViewer* vcreate () const;
virtual std::string _getString () const;
public slots:
void doAction ();
void doGoto ();
void changeSelectionMode ();
void setShowSelection ( bool );
void setState ( shared_ptr<CellWidget::State>& );
void removeHistory ( Cell* );
void openHistoryCell ();
void openDesignBlob ();
void saveDesignBlob ();
void printDisplay ();
void print ( QPrinter* );
void imageDisplay ();
void raiseToolInterrupt ();
void clearToolInterrupt ();
void runScriptWidget ();
void runStressScript ();
inline void emitCellAboutToChange ();
inline void emitCellChanged ();
inline void emitCellPreModificated ();
inline void emitCellPostModificated ();
signals:
void cellLoadedFromDisk ( Cell* );
void showSelectionToggled ( bool );
void stateChanged ( shared_ptr<CellWidget::State>& );
void redrawCellWidget ();
void cellPreModificated ();
void cellPostModificated ();
protected:
void createMenus ();
void refreshTitle ();
void refreshHistory ();
void rebuildHistory ();
private:
QString _getAbsWidgetPath ( const QString& relPath ) const;
QMenu* _getParentMenu ( const QString& ) const;
void _runScript ( QString scriptPath );
static void notify ( CellViewer*, unsigned int flags );
public:
CellViewer ( QWidget* parent=NULL );
virtual ~CellViewer ();
inline bool isToolInterrupted () const;
QMenu* createDebugMenu ();
bool hasMenu ( const QString& path ) const;
bool hasMenuAction ( const QString& path ) const;
QMenu* addMenu ( const QString& path
, std::string text
, unsigned int flags=NoFlags
);
bool addToMenu ( const QString& path );
QAction* addToMenu ( const QString& path
, std::string text
, std::string textTip
, std::function< void() >
, QIcon icon=QIcon() );
QAction* addToMenu ( const QString& path
, std::string text
, std::string textTip
, std::string scriptPath );
QAction* addToMenu ( QString path
, QString text
, QString textTip
, const QKeySequence& shortCut
, QIcon icon =QIcon());
inline void setEnableRedrawInterrupt ( bool );
inline void setApplicationName ( const QString& );
inline Observer<CellViewer>* getCellObserver ();
Cell* getCell () const;
virtual void setCell ( Cell* );
void renameCell ( const char* );
virtual Cell* getCellFromDb ( const char* );
inline CellWidget* getCellWidget ();
inline const CellWidget* getCellWidget () const;
inline ControllerWidget* getControllerWidget ();
void setAnonNetSelectable ( bool );
void select ( Occurrence& );
void unselect ( Occurrence& );
void unselectAll ();
inline void setLayerVisible ( const Name& layer, bool visible );
void runScript ( QString scriptPath );
virtual CellViewer* vcreate () const;
virtual std::string _getString () const;
public slots:
void doAction ();
void doGoto ();
void changeSelectionMode ();
void setShowSelection ( bool );
void setState ( shared_ptr<CellWidget::State>& );
void removeHistory ( Cell* );
void openHistoryCell ();
void openDesignBlob ();
void saveDesignBlob ();
void printDisplay ();
void print ( QPrinter* );
void imageDisplay ();
void raiseToolInterrupt ();
void clearToolInterrupt ();
void runScriptWidget ();
void runStressScript ();
inline void emitCellAboutToChange ();
inline void emitCellChanged ();
inline void emitCellPreModificated ();
inline void emitCellPostModificated ();
signals:
void cellLoadedFromDisk ( Cell* );
void showSelectionToggled ( bool );
void stateChanged ( shared_ptr<CellWidget::State>& );
void redrawCellWidget ();
void cellPreModificated ();
void cellPostModificated ();
protected:
void createMenus ();
void refreshTitle ();
void refreshHistory ();
void rebuildHistory ();
private:
QString _getAbsWidgetPath ( const QString& relPath ) const;
QMenu* _getParentMenu ( const QString& ) const;
void _runScript ( QString scriptPath );
protected:
static QString _prefixWPath;
CellObserver _cellObserver;
Observer<CellViewer> _cellObserver;
QString _applicationName;
QAction* _openAction;
QAction* _cellHistoryAction[CellHistorySize];
@ -198,17 +200,17 @@ namespace Hurricane {
// Inline Functions.
inline bool CellViewer::isToolInterrupted () const { return _toolInterrupt; }
inline CellObserver* CellViewer::getCellObserver () { return &_cellObserver; }
inline CellWidget* CellViewer::getCellWidget () { return _cellWidget; }
inline const CellWidget* CellViewer::getCellWidget () const { return _cellWidget; }
inline ControllerWidget* CellViewer::getControllerWidget () { return _controller; }
inline void CellViewer::setApplicationName ( const QString& name ) { _applicationName = name; }
inline void CellViewer::setLayerVisible ( const Name& layer, bool visible ) { _cellWidget->setLayerVisible(layer,visible); }
inline void CellViewer::emitCellAboutToChange () { _flags |= InCellChange; emit cellPreModificated(); }
inline void CellViewer::emitCellChanged () { _flags &= ~InCellChange; emit cellPostModificated(); }
inline void CellViewer::emitCellPreModificated () { emit cellPreModificated(); }
inline void CellViewer::emitCellPostModificated () { emit cellPostModificated(); }
inline bool CellViewer::isToolInterrupted () const { return _toolInterrupt; }
inline Observer<CellViewer>* CellViewer::getCellObserver () { return &_cellObserver; }
inline CellWidget* CellViewer::getCellWidget () { return _cellWidget; }
inline const CellWidget* CellViewer::getCellWidget () const { return _cellWidget; }
inline ControllerWidget* CellViewer::getControllerWidget () { return _controller; }
inline void CellViewer::setApplicationName ( const QString& name ) { _applicationName = name; }
inline void CellViewer::setLayerVisible ( const Name& layer, bool visible ) { _cellWidget->setLayerVisible(layer,visible); }
inline void CellViewer::emitCellAboutToChange () { _flags |= InCellChange; emit cellPreModificated(); }
inline void CellViewer::emitCellChanged () { _flags &= ~InCellChange; emit cellPostModificated(); }
inline void CellViewer::emitCellPreModificated () { emit cellPreModificated(); }
inline void CellViewer::emitCellPostModificated () { emit cellPostModificated(); }
inline void CellViewer::setEnableRedrawInterrupt ( bool state )
{ _cellWidget->setEnableRedrawInterrupt(state); }

View File

@ -296,16 +296,9 @@ namespace Hurricane {
class ControllerWidget : public QTabWidget {
Q_OBJECT;
public:
class GraphicsObserver : public Observer<ControllerWidget> {
public:
inline GraphicsObserver ( ControllerWidget* );
virtual void notify ( unsigned int flags );
private:
GraphicsObserver ( const GraphicsObserver& );
};
public:
static void notify ( ControllerWidget*, unsigned int flags );
public:
ControllerWidget ( QWidget* parent=NULL );
inline CellWidget* getCellWidget ();
@ -328,16 +321,16 @@ namespace Hurricane {
void toggleShow ();
protected:
GraphicsObserver _observer;
CellWidget* _cellWidget;
TabGraphics* _tabGraphics;
TabPalette* _tabPalette;
TabDisplayFilter* _tabDisplayFilter;
TabNetlist* _tabNetlist;
TabHierarchy* _tabHierarchy;
TabSelection* _tabSelection;
TabInspector* _tabInspector;
TabSettings* _tabSettings;
Observer<ControllerWidget> _observer;
CellWidget* _cellWidget;
TabGraphics* _tabGraphics;
TabPalette* _tabPalette;
TabDisplayFilter* _tabDisplayFilter;
TabNetlist* _tabNetlist;
TabHierarchy* _tabHierarchy;
TabSelection* _tabSelection;
TabInspector* _tabInspector;
TabSettings* _tabSettings;
};
@ -351,11 +344,6 @@ namespace Hurricane {
inline InspectorWidget* ControllerWidget::getInspectorWidget () { return _tabInspector->getInspectorWidget(); }
inline TabSettings* ControllerWidget::getSettings () { return _tabSettings; }
//inline int ControllerWidget::addSetting ( QWidget* page, const QString& label ) { return _tabSettings->addSetting(page,label); }
inline ControllerWidget::GraphicsObserver::GraphicsObserver ( ControllerWidget* owner )
: Observer<ControllerWidget>(owner)
{ }
} // End of Hurricane namespace.