- export MousePositionWidget.h so pharos can use it (displays the (x,y) mouse position in status bar)
    
    ADDS
    - add a getOnPhysicalGrid() in DbU
    - add getPhysical and getOnPhysicalGrid functions in PyDbU and also defines useful CONSTANTS
This commit is contained in:
Damien Dupuis 2009-10-15 13:46:29 +00:00
parent fee6e4c593
commit 297e58d535
5 changed files with 119 additions and 17 deletions

View File

@ -98,6 +98,7 @@ namespace Hurricane {
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 );
static inline DbU::Unit getOnPhysicalGrid ( DbU::Unit u, SnapMode mode=Superior );
// Conversions.
static inline long getDb ( Unit u );
static inline double getGrid ( Unit u );
@ -126,16 +127,17 @@ namespace Hurricane {
// Inline Functions.
inline DbU::Unit DbU::db ( long value ) { return value; }
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 _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; }
inline DbU::Unit DbU::db ( long value ) { return value; }
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 _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; }
inline DbU::Unit DbU::getOnPhysicalGrid ( DbU::Unit u, SnapMode mode ) { return getOnCustomGrid(u, grid(1), mode); }
} // End of Hurricane namespace.

View File

@ -37,6 +37,7 @@
hurricane/viewer/GraphicsWidget.h
hurricane/viewer/ExceptionWidget.h
hurricane/viewer/BreakpointWidget.h
hurricane/viewer/MousePositionWidget.h
hurricane/viewer/Selector.h
hurricane/viewer/Command.h
hurricane/viewer/AreaCommand.h

View File

@ -61,6 +61,10 @@ using namespace Hurricane;
extern "C" {
#define LOAD_CONSTANT(CONSTANT_VALUE,CONSTANT_NAME) \
constant = PyInt_FromLong ( (long)CONSTANT_VALUE ); \
PyDict_SetItemString ( dictionnary, CONSTANT_NAME, constant ); \
Py_DECREF ( constant );
// x=================================================================x
// | "PyDbU" Python Module Code Part |
@ -68,6 +72,50 @@ extern "C" {
#if defined(__PYTHON_MODULE__)
// x-------------------------------------------------------------x
// | "PyDbU" Local Functions |
// x-------------------------------------------------------------x
static DbU::SnapMode PyInt_AsSnapMode ( PyObject* object ) {
switch ( PyInt_AsLong(object) ) {
case DbU::Inferior : return ( DbU::Inferior );
case DbU::Superior : return ( DbU::Superior );
case DbU::Nearest : return ( DbU::Nearest );
}
return ( DbU::Superior );
}
static DbU::UnitPower PyInt_AsUnitPower ( PyObject* object ) {
switch ( PyInt_AsLong(object) ) {
case DbU::Pico : return ( DbU::Pico );
case DbU::Nano : return ( DbU::Nano );
case DbU::Micro : return ( DbU::Micro );
case DbU::Milli : return ( DbU::Milli );
case DbU::Unity : return ( DbU::Unity );
case DbU::Kilo : return ( DbU::Kilo );
}
return ( DbU::Micro );
}
// x-------------------------------------------------------------x
// | Global Constants Loading |
// x-------------------------------------------------------------x
extern void DbULoadConstants ( PyObject* dictionnary ) {
PyObject* constant;
LOAD_CONSTANT ( DbU::Inferior, "SnapModeInferior" )
LOAD_CONSTANT ( DbU::Superior, "SnapModeSuperior" )
LOAD_CONSTANT ( DbU::Nearest , "SnapModeNearest" )
LOAD_CONSTANT ( DbU::Pico , "UnitPowerPico" )
LOAD_CONSTANT ( DbU::Nano , "UnitPowerNano" )
LOAD_CONSTANT ( DbU::Micro , "UnitPowerMicro" )
LOAD_CONSTANT ( DbU::Milli , "UnitPowerMilli" )
LOAD_CONSTANT ( DbU::Unity , "UnitPowerUnity" )
LOAD_CONSTANT ( DbU::Kilo , "UnitPowerKilo" )
}
// x-------------------------------------------------------------x
// | "PyDbU" General Methods |
@ -200,6 +248,20 @@ extern "C" {
}
// ---------------------------------------------------------------
// Module Method : "PyDbU_getPhysical ()"
extern PyObject* PyDbU_getPhysical ( PyObject* module, PyObject* args )
{
trace << "PyDbU_getPhysical ()" << endl;
PyObject* arg0;
PyObject* arg1;
if ( ! ParseTwoArg ( "Dbu.getPhysical", args,INTS2_ARG, &arg0, &arg1 ) ) return ( NULL );
return ( Py_BuildValue("d",DbU::getPhysical(PyInt_AsLong(arg0), PyInt_AsUnitPower(arg1))) );
}
// ---------------------------------------------------------------
// Module Method : "PyDbU_getResolution ()"
@ -211,6 +273,36 @@ extern "C" {
}
// ---------------------------------------------------------------
// Module Method : "PyDbu_getOnPhysicalGrid ()"
extern PyObject* PyDbU_getOnPhysicalGrid ( PyObject* module, PyObject* args )
{
trace << "PyDbU_getOnPhysicalGrid ()" << endl;
PyObject* arg0;
PyObject* arg1;
DbU::Unit result;
HTRY
__cs.init ( "DbU.getOnPhysicalGrid" );
if (!PyArg_ParseTuple(args, "O&|O&O&:DbU.getOnPhysicalGrid", Converter, &arg0, Converter, &arg1)) {
return NULL;
}
if ( __cs.getObjectIds() == INTS2_ARG ) {
result = DbU::getOnPhysicalGrid ( PyInt_AsLong(arg0), PyInt_AsSnapMode(arg1) );
} else if ( __cs.getObjectIds() == INT_ARG ) {
result = DbU::getOnPhysicalGrid ( PyInt_AsLong(arg0) );
} else {
return NULL;
}
HCATCH
return ( Py_BuildValue ( "i", result ) );
}
#endif // End of Python Module Code Part.

View File

@ -506,6 +506,8 @@ extern "C" {
, { "DbU_getDb" , PyDbU_getDb , METH_VARARGS, "Converts a DbU::Unit to an integer value (no scale factor)." }
, { "DbU_getGrid" , PyDbU_getGrid , METH_VARARGS, "Converts a DbU::Unit to a to grid founder." }
, { "DbU_getLambda" , PyDbU_getLambda , METH_VARARGS, "Converts a DbU::Unit to a symbolic value (to lambda)." }
, { "DbU_getPhysical" , PyDbU_getPhysical , METH_VARARGS, "Converts a DbU::Unit to a physical value." }
, { "DbU_getOnPhysicalGrid" , PyDbU_getOnPhysicalGrid , METH_VARARGS, "Adjusts a DbU::Unit to physical grid." }
, { "Point" , PyPoint_create , METH_VARARGS, "Creates a new Point." }
, { "Box" , PyBox_create , METH_VARARGS, "Creates a new Box." }
, { "Transformation" , PyTransformation_create , METH_VARARGS, "Creates a new Transformation." }
@ -679,6 +681,7 @@ extern "C" {
PyDict_SetItemString ( dictionnary, "ProxyError" , ProxyError );
PyDict_SetItemString ( dictionnary, "HurricaneError" , HurricaneError );
DbULoadConstants ( dictionnary );
TransformationLoadConstants ( dictionnary );
NetLoadConstants ( dictionnary );
InstanceLoadConstants ( dictionnary );

View File

@ -77,13 +77,17 @@ extern "C" {
// -------------------------------------------------------------------
// Functions & Types exported to "PyHurricane.ccp".
extern PyObject* PyDbU_db ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_grid ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_lambda ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getDb ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getGrid ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getLambda ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getResolution ( PyObject* module );
extern PyObject* PyDbU_db ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_grid ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_lambda ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getDb ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getGrid ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getLambda ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getPhysical ( PyObject* module, PyObject* args );
extern PyObject* PyDbU_getResolution ( PyObject* module );
extern PyObject* PyDbU_getOnPhysicalGrid ( PyObject* module, PyObject* args );
extern void DbULoadConstants ( PyObject* dictionnary );
} // End of extern "C".