* ./hurricane/src/hurricane :

- New: In DbU, create a "onCustomGrid(point,step,round)" method to place
        a point on an arbitrary grid. That different from the real or symbolic
        ones.
    - Bug: In DbU, all the snap function where bugged when passed negatives
        coordinates.
    - New: In DbU, new conversion function, DbU::getPhysical() to translate into
        physical (metric) system.
    - New: In CellWidget, separate the "Snap Grid" (real or symbolic) from the
        cursor position. The cursor position will now be displayed in half-lambda
        (symbolic mode) or founder grid unit (real mode).
          That can be changed trough the CellWidget::setCursorStep(DbU::Unit)
        method.
    - New: In CellViewer/ControllerWidget, the CTRL+I keys toggle the visibility
        of the Controller instead of systematically showing it.
This commit is contained in:
Jean-Paul Chaput 2009-10-14 08:20:08 +00:00
parent 4365b6cefb
commit fee6e4c593
8 changed files with 152 additions and 54 deletions

View File

@ -38,8 +38,9 @@
// x-----------------------------------------------------------------x
#include <climits>
#include <cstring>
#include <cstdlib>
#include <limits>
#include "hurricane/DbU.h"
#include "hurricane/Error.h"
@ -58,8 +59,8 @@ namespace Hurricane {
unsigned int DbU::_stringMode = DbU::Symbolic;
DbU::Unit DbU::_symbolicSnapGridStep = DbU::lambda(1.0);
DbU::Unit DbU::_realSnapGridStep = DbU::grid (10.0);
const DbU::Unit DbU::Min = LONG_MIN;
const DbU::Unit DbU::Max = LONG_MAX;
const DbU::Unit DbU::Min = std::numeric_limits<long>::min();
const DbU::Unit DbU::Max = std::numeric_limits<long>::max();
// -------------------------------------------------------------------
@ -192,10 +193,14 @@ namespace Hurricane {
DbU::Unit modulo = u % _symbolicSnapGridStep;
if ( !modulo ) return u;
if ( modulo < 0 ) inferior -= _symbolicSnapGridStep;
if ( mode == Inferior ) { return inferior; }
else if ( mode == Superior ) { return inferior + _symbolicSnapGridStep; }
if ( modulo < 0 )
return inferior + ( (modulo > - (_symbolicSnapGridStep/2)) ? _symbolicSnapGridStep : 0 );
return inferior + ( (modulo > (_symbolicSnapGridStep/2)) ? _symbolicSnapGridStep : 0 );
}
@ -210,14 +215,36 @@ namespace Hurricane {
DbU::Unit modulo = u % _realSnapGridStep;
if ( !modulo ) return u;
if ( modulo < 0 ) inferior -= _realSnapGridStep;
if ( mode == Inferior ) { return inferior; }
else if ( mode == Superior ) { return inferior + _realSnapGridStep; }
if ( modulo < 0 )
return inferior + ( (modulo > - (_realSnapGridStep/2)) ? _realSnapGridStep : 0 );
return inferior + ( (modulo > (_realSnapGridStep/2)) ? _realSnapGridStep : 0 );
}
DbU::Unit DbU::getOnCustomGrid ( DbU::Unit u, DbU::Unit step, SnapMode mode )
{
DbU::Unit inferior = ( u / step ) * step;
DbU::Unit modulo = abs ( u % step );
if ( !modulo ) return u;
if ( modulo < 0 ) inferior -= step;
if ( mode == Inferior ) { return inferior; }
else if ( mode == Superior ) { return inferior + step; }
if ( modulo < 0 )
return inferior + ( (modulo > - (step/2)) ? step : 0 );
return inferior + ( (modulo > (step/2)) ? step : 0 );
}
string DbU::getValueString ( DbU::Unit u, int mode )
{
char buffer[1024];

View File

@ -97,10 +97,12 @@ namespace Hurricane {
static DbU::Unit getSymbolicSnapGridStep ();
static DbU::Unit getOnSymbolicSnapGrid ( DbU::Unit u, SnapMode mode=Nearest );
static inline void setSymbolicSnapGridStep ( DbU::Unit step );
static DbU::Unit getOnCustomGrid ( DbU::Unit u, DbU::Unit step, SnapMode mode=Nearest );
// Conversions.
static inline long getDb ( Unit u );
static inline double getGrid ( Unit u );
static inline double getLambda ( Unit u );
static inline double getPhysical ( Unit u, UnitPower p );
static string getValueString ( Unit u, int mode=SmartTruncate );
static Record* getValueRecord ( const Unit* u );
static Slot* getValueSlot ( const string& name, const Unit* u );
@ -128,8 +130,9 @@ namespace Hurricane {
inline DbU::Unit DbU::grid ( double value ) { return (long)rint( value/_resolution ); }
inline DbU::Unit DbU::lambda ( double value ) { return grid(value*_gridsPerLambda); }
inline long DbU::getDb ( DbU::Unit u ) { return u; }
inline double DbU::getGrid ( DbU::Unit u ) { return _resolution*(double)u; }
inline double DbU::getGrid ( DbU::Unit u ) { return _physicalsPerGrid*_resolution*(double)u; }
inline double DbU::getLambda ( DbU::Unit u ) { return getGrid(u)/_gridsPerLambda; }
inline double DbU::getPhysical ( DbU::Unit u, UnitPower p ) { return (_physicalsPerGrid*_resolution*(double)u)/getUnitPower(p); }
inline void DbU::setStringMode ( unsigned int mode ) { _stringMode = mode; }
inline void DbU::setRealSnapGridStep ( DbU::Unit step ) { _realSnapGridStep = step; }
inline void DbU::setSymbolicSnapGridStep ( DbU::Unit step ) { _symbolicSnapGridStep = step; }

View File

@ -49,38 +49,40 @@
namespace Hurricane {
CellViewer::CellViewer ( QWidget* parent ) : QMainWindow(parent)
, _applicationName(tr("Viewer"))
, _openAction(NULL)
, _nextAction(NULL)
, _printAction(NULL)
, _imageAction(NULL)
, _saveAction(NULL)
, _closeAction(NULL)
, _exitAction(NULL)
, _refreshAction(NULL)
CellViewer::CellViewer ( QWidget* parent ) : QMainWindow (parent)
, _applicationName (tr("Viewer"))
, _toolInterruptAction(NULL)
, _openAction (NULL)
, _nextAction (NULL)
, _printAction (NULL)
, _imageAction (NULL)
, _saveAction (NULL)
, _closeAction (NULL)
, _exitAction (NULL)
, _refreshAction (NULL)
, _fitToContentsAction(NULL)
, _showSelectionAction(NULL)
, _rubberChangeAction(NULL)
, _clearRulersAction(NULL)
, _controllerAction(NULL)
, _fileMenu(NULL)
, _viewMenu(NULL)
, _toolsMenu(NULL)
, _debugMenu(NULL)
//, _mapView(NULL)
, _palette(NULL)
, _mousePosition(NULL)
, _controller(NULL)
, _cellWidget(NULL)
, _moveCommand()
, _zoomCommand()
, _rulerCommand()
, _selectCommand()
, _hierarchyCommand()
, _cellHistory()
, _firstShow(false)
, _updateState(ExternalEmit)
, _rubberChangeAction (NULL)
, _clearRulersAction (NULL)
, _controllerAction (NULL)
, _fileMenu (NULL)
, _viewMenu (NULL)
, _toolsMenu (NULL)
, _debugMenu (NULL)
//, _mapView (NULL)
, _palette (NULL)
, _mousePosition (NULL)
, _controller (NULL)
, _cellWidget (NULL)
, _moveCommand ()
, _zoomCommand ()
, _rulerCommand ()
, _selectCommand ()
, _hierarchyCommand ()
, _cellHistory ()
, _firstShow (false)
, _toolInterrupt (false)
, _updateState (ExternalEmit)
{
setObjectName("viewer");
@ -101,6 +103,14 @@ namespace Hurricane {
{
if ( _openAction ) return;
_toolInterruptAction = new QAction ( tr("Interrupt"), this );
_toolInterruptAction->setObjectName ( "viewer.interrupt" );
_toolInterruptAction->setShortcut ( QKeySequence(tr("CTRL+C")) );
//_toolInterruptAction->setIcon ( QIcon(":/images/stock_open.png") );
_toolInterruptAction->setStatusTip ( tr("Interrupt the running tool") );
connect ( _toolInterruptAction, SIGNAL(triggered()), this, SLOT(raiseToolInterrupt()) );
addAction ( _toolInterruptAction );
_openAction = new QAction ( tr("&Open Cell"), this );
_openAction->setObjectName ( "viewer.menuBar.file.openCell" );
_openAction->setShortcut ( QKeySequence(tr("CTRL+O")) );
@ -273,7 +283,7 @@ namespace Hurricane {
connect ( _showSelectionAction , SIGNAL(toggled(bool)) , this , SLOT(setShowSelection(bool)) );
connect ( _rubberChangeAction , SIGNAL(triggered()) , _cellWidget, SLOT(rubberChange()) );
connect ( _clearRulersAction , SIGNAL(triggered()) , _cellWidget, SLOT(clearRulers()) );
connect ( _controllerAction , SIGNAL(triggered()) , this , SLOT(showController()) );
connect ( _controllerAction , SIGNAL(triggered()) , _controller, SLOT(toggleShow()) );
connect ( _cellWidget , SIGNAL(mousePositionChanged(const Point&))
, _mousePosition , SLOT (setPosition(const Point&)) );
@ -379,12 +389,6 @@ namespace Hurricane {
}
void CellViewer::showController ()
{
_controller->show ();
}
void CellViewer::changeSelectionMode ()
{
if ( _updateState != InternalEmit ) {
@ -403,6 +407,14 @@ namespace Hurricane {
}
void CellViewer::raiseToolInterrupt ()
{ _toolInterrupt = true; }
void CellViewer::clearToolInterrupt ()
{ _toolInterrupt = false; }
void CellViewer::openHistoryCell ()
{
QAction* historyAction = qobject_cast<QAction*> ( sender() );

View File

@ -177,6 +177,7 @@ namespace Hurricane {
Point spotPoint = Point ( _cellWidget->_onSnapGrid(mousePoint.getX())
, _cellWidget->_onSnapGrid(mousePoint.getY())
);
return _cellWidget->dbuToScreenPoint(spotPoint);
}

View File

@ -23,6 +23,7 @@
// x-----------------------------------------------------------------x
#include <QAction>
#include <QFrame>
#include <QHBoxLayout>
#include <QVBoxLayout>
@ -464,7 +465,13 @@ namespace Hurricane {
addTab ( _tabSelection , "Selection" );
addTab ( _tabInspector , "Inspector" );
connect ( this, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)) );
QAction* toggleShow = new QAction ( tr("Controller"), this );
toggleShow->setObjectName ( "controller.action.hideShow" );
toggleShow->setShortcut ( QKeySequence(tr("CTRL+I")) );
addAction ( toggleShow );
connect ( toggleShow, SIGNAL(triggered()) , this, SLOT(toggleShow()) );
connect ( this , SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)) );
connect ( _tabSelection->getSelection(), SIGNAL(inspect(Occurrence&))
, _tabInspector , SLOT (setSelectionOccurrence(Occurrence&)) );
@ -472,6 +479,10 @@ namespace Hurricane {
}
void ControllerWidget::toggleShow ()
{ setVisible ( !isVisible() ); }
void ControllerWidget::setCellWidget ( CellWidget* cellWidget )
{
_cellWidget = cellWidget;

View File

@ -68,6 +68,7 @@ namespace Hurricane {
public:
CellViewer ( QWidget* parent=NULL );
virtual ~CellViewer ();
inline bool isToolInterrupted () const;
QMenu* createDebugMenu ();
inline void setEnableRedrawInterrupt ( bool );
inline void setApplicationName ( const QString& );
@ -83,10 +84,11 @@ namespace Hurricane {
void changeSelectionMode ();
void setShowSelection ( bool );
void setState ( shared_ptr<CellWidget::State>& );
void showController ();
void openHistoryCell ();
void printDisplay ();
void imageDisplay ();
void raiseToolInterrupt ();
void clearToolInterrupt ();
signals:
void showSelectionToggled ( bool );
void stateChanged ( shared_ptr<CellWidget::State>& );
@ -96,6 +98,7 @@ namespace Hurricane {
enum { CellHistorySize = 10 };
protected:
QString _applicationName;
QAction* _toolInterruptAction;
QAction* _openAction;
QAction* _nextAction;
QAction* _cellHistoryAction[CellHistorySize];
@ -127,6 +130,7 @@ namespace Hurricane {
list< shared_ptr<CellWidget::State> >
_cellHistory;
bool _firstShow;
bool _toolInterrupt;
UpdateState _updateState;
protected:
@ -142,6 +146,7 @@ namespace Hurricane {
inline void CellViewer::setEnableRedrawInterrupt ( bool state )
{ _cellWidget->setEnableRedrawInterrupt(state); }
inline bool CellViewer::isToolInterrupted () const { return _toolInterrupt; }
inline CellWidget* CellViewer::getCellWidget () { return _cellWidget; }
inline ControllerWidget* CellViewer::getControllerWidget () { return _controller; }
inline void CellViewer::setApplicationName ( const QString& name ) { _applicationName = name; }

View File

@ -137,6 +137,7 @@ namespace Hurricane {
void detachFromPalette ();
void bindCommand ( Command* );
void unbindCommand ( Command* );
inline void setCursorStep ( DbU::Unit );
inline bool realMode () const;
inline bool symbolicMode () const;
inline bool showBoundaries () const;
@ -204,10 +205,13 @@ namespace Hurricane {
Box computeVisibleArea ( float scale ) const;
Box computeVisibleArea ( float scale, const Point& topLeft ) const;
Box computeVisibleArea ( const Box&, float& scale ) const;
inline DbU::Unit cursorStep () const;
inline bool _underDetailedGridThreshold() const;
inline DbU::Unit _snapGridStep () const;
inline DbU::Unit _onSnapGrid ( DbU::Unit ) const;
inline Point _onSnapGrid ( const Point& ) const;
inline DbU::Unit _onCursorGrid ( DbU::Unit ) const;
inline Point _onCursorGrid ( const Point& ) const;
// Qt QWidget Functions Overloads.
void pushCursor ( Qt::CursorShape cursor );
void popCursor ();
@ -525,6 +529,7 @@ namespace Hurricane {
inline State ( Cell* cell=NULL );
inline void setCell ( Cell* );
inline void setCellWidget ( CellWidget* );
inline void setCursorStep ( DbU::Unit );
inline void setRealMode ();
inline void setSymbolicMode ();
inline void setShowBoundaries ( bool );
@ -544,6 +549,7 @@ namespace Hurricane {
const Name& getName () const;
inline SelectorCriterions& getSelection ();
inline RulerSet& getRulers ();
inline DbU::Unit cursorStep () const;
inline bool realMode () const;
inline bool symbolicMode () const;
inline bool showBoundaries () const;
@ -572,6 +578,7 @@ namespace Hurricane {
CellWidget* _cellWidget;
SelectorCriterions _selection;
RulerSet _rulers;
DbU::Unit _cursorStep;
bool _symbolicMode;
bool _showBoundaries;
bool _showSelection;
@ -858,6 +865,7 @@ namespace Hurricane {
, _cellWidget (NULL)
, _selection ()
, _rulers ()
, _cursorStep (DbU::lambda(0.5))
, _symbolicMode (true)
, _showBoundaries (true)
, _showSelection (false)
@ -889,12 +897,22 @@ namespace Hurricane {
}
inline void CellWidget::State::setCursorStep ( DbU::Unit step )
{ _cursorStep = step; }
inline void CellWidget::State::setRealMode ()
{ _symbolicMode = false; }
{
_symbolicMode = false;
_cursorStep = DbU::grid ( 1.0 );
}
inline void CellWidget::State::setSymbolicMode ()
{ _symbolicMode = true; }
{
_symbolicMode = true;
_cursorStep = DbU::lambda ( 0.5 );
}
inline void CellWidget::State::setShowBoundaries ( bool state )
@ -944,6 +962,10 @@ namespace Hurricane {
{ return _cell; }
inline DbU::Unit CellWidget::State::cursorStep () const
{ return _cursorStep; }
inline CellWidget::SelectorCriterions& CellWidget::State::getSelection ()
{ return _selection; }
@ -1006,6 +1028,10 @@ namespace Hurricane {
{ return state->getName() == _cellName; }
inline void CellWidget::setCursorStep ( DbU::Unit step )
{ _state->setCursorStep(step); }
inline shared_ptr<CellWidget::State>& CellWidget::getState ()
{
_state->setTopLeft ( getTopLeft() );
@ -1178,6 +1204,10 @@ namespace Hurricane {
{ return _palette; }
inline DbU::Unit CellWidget::cursorStep () const
{ return _state->cursorStep(); }
inline bool CellWidget::realMode () const
{ return !_state->symbolicMode(); }
@ -1217,7 +1247,7 @@ namespace Hurricane {
inline void CellWidget::updateMousePosition ()
{
Point mousePoint = screenToDbuPoint ( _mousePosition );
emit mousePositionChanged ( _onSnapGrid(mousePoint) );
emit mousePositionChanged ( _onCursorGrid(mousePoint) );
}
@ -1276,6 +1306,14 @@ namespace Hurricane {
{ return Point(_onSnapGrid(p.getX()),_onSnapGrid(p.getY())); }
inline DbU::Unit CellWidget::_onCursorGrid ( DbU::Unit u ) const
{ return DbU::getOnCustomGrid(u,cursorStep()); }
inline Point CellWidget::_onCursorGrid ( const Point& p ) const
{ return Point(_onCursorGrid(p.getX()),_onCursorGrid(p.getY())); }
} // End of Hurricane namespace.

View File

@ -249,6 +249,7 @@ namespace Hurricane {
void cellPostModificate ();
void cellChanged ( Cell* );
void updateTab ( int index );
void toggleShow ();
protected:
CellWidget* _cellWidget;