// Copyright (C) 2005 Gideon May (gideon@computer.org) // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. #include #include #include #include #include #include #include "held_ptr.hpp" using namespace boost::python; namespace { class ScalarPrinter : public osgSim::ScalarBar::ScalarPrinter { public: ScalarPrinter(PyObject * p) : _self(p) { Py_XINCREF(_self); } ~ScalarPrinter() { Py_XDECREF(_self); } virtual std::string printScalar(float scalar) { // std::cout << "ScalarPrinter::printScalar scalar=" << scalar << std::endl; try { return call_method(_self, "printScalar", scalar); } catch(...) { throw_error_already_set(); } return std::string(""); } virtual std::string printScalar_imp(float scalar) { return osgSim::ScalarBar::ScalarPrinter::printScalar(scalar); } private: PyObject * _self; }; } namespace PyOSGSim { void init_ScalarBar() { class_, bases > scalar_bar("ScalarBar", no_init); scope scalar_bar_scope(scalar_bar); scalar_bar.def(init<>()); scalar_bar.def(init()); scalar_bar.def(init()); scalar_bar.def(init()); scalar_bar.def(init()); /** Set the number of distinct colours on the ScalarBar. */ scalar_bar.def("setNumColors", &osgSim::ScalarBar::setNumColors); /** Get the number of distinct colours on the ScalarBar. */ scalar_bar.def("getNumColors", &osgSim::ScalarBar::getNumColors); /** Set the number of labels to display along the ScalarBar. There will be one label at each end point, and evenly distributed labels in between. */ scalar_bar.def("setNumLabels", &osgSim::ScalarBar::setNumLabels); /** Get the number of labels displayed along the ScalarBar. */ scalar_bar.def("getNumLabels", &osgSim::ScalarBar::getNumLabels); /** Set the ScalarsToColors mapping object for the ScalarBar. */ scalar_bar.def("setScalarsToColors", &osgSim::ScalarBar::setScalarsToColors); /** Get the ScalarsToColors mapping object from the ScalarBar. */ //const ScalarsToColors* getScalarsToColors() const // scalar_bar.def("getScalarsToColors", &osgSim::ScalarBar::getScalarsToColors); /** Set the title for the ScalarBar, set "" for no title. */ scalar_bar.def("setTitle", &osgSim::ScalarBar::setTitle); /** Get the title for the ScalarBar. */ scalar_bar.def("getTitle", &osgSim::ScalarBar::getTitle); /** Set the position of scalar bar's lower left corner.*/ scalar_bar.def("setPosition", &osgSim::ScalarBar::setPosition); /** Get the position of scalar bar.*/ scalar_bar.def("getPosition", &osgSim::ScalarBar::getPosition, return_value_policy()); /** Set the width of the scalar bar.*/ scalar_bar.def("setWidth", &osgSim::ScalarBar::setWidth); /** Get the width of the scalar bar.*/ scalar_bar.def("getWidth", &osgSim::ScalarBar::getWidth); /** Set the aspect ration (y/x) for the displayed bar. Bear in mind you may want to change this if you change the orientation. */ scalar_bar.def("setAspectRatio", &osgSim::ScalarBar::setAspectRatio); /** Get the aspect ration (y/x) for the displayed bar. */ scalar_bar.def("getAspectRatio", &osgSim::ScalarBar::getAspectRatio); /** Set the orientation of the ScalarBar. @see Orientation */ scalar_bar.def("setOrientation", &osgSim::ScalarBar::setOrientation); /** Get the orientation of the ScalarBar. @see Orientation */ scalar_bar.def("getOrientation", &osgSim::ScalarBar::getOrientation); /** Set a ScalarPrinter object for the ScalarBar. For every displayed ScalarBar label, the scalar value will be passed to the ScalarPrinter object to turn it into a string. Users may override the default ScalarPrinter object to map scalars to whatever strings they wish. @see ScalarPrinter */ scalar_bar.def("setScalarPrinter", &osgSim::ScalarBar::setScalarPrinter); /** Get the ScalarPrinter object */ // const ScalarPrinter* getScalarPrinter() const; // scalar_bar.def("getScalarPrinter", &osgSim::ScalarBar::getScalarPrinter); /** Set the TextProperties for the labels & title. @see TextProperties */ scalar_bar.def("setTextProperties", &osgSim::ScalarBar::setTextProperties); /** Get the TextProperties for the labels & title. @see TextProperties */ // const TextProperties& getTextProperties() const; // scalar_bar.def("getTextProperties", &osgSim::ScalarBar::getTextProperties); /** force update the drawables used to render the scalar bar.*/ scalar_bar.def("update", &osgSim::ScalarBar::update); enum_ orientation("Orientation"); # define OSG_ENUM(VALUE) \ (orientation.value(#VALUE, osgSim::ScalarBar::VALUE), \ scalar_bar.def(#VALUE, object(osgSim::ScalarBar::VALUE))) OSG_ENUM(HORIZONTAL); OSG_ENUM(VERTICAL); class_, bases, boost::noncopyable > scalar_printer("ScalarPrinter", no_init); scalar_printer.def(init<>()); scalar_printer.def("printScalar", &ScalarPrinter::printScalar_imp); class_ text_properties("TextProperties"); text_properties.def(init<>()); text_properties.def_readwrite("_fontFile", &osgSim::ScalarBar::TextProperties::_fontFile); text_properties.def_readwrite("_fontResolution", &osgSim::ScalarBar::TextProperties::_fontResolution); text_properties.def_readwrite("_characterSize", &osgSim::ScalarBar::TextProperties::_characterSize); text_properties.def_readwrite("_color", &osgSim::ScalarBar::TextProperties::_color); } }