// curveact.cpp -- curve actions // // Written by Frederic Bouvier, started June 2002. // // Copyright (C) 2002 Frederic Bouvier - fredb@users.sourceforge.net // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: curveact.cpp,v 1.12 2005/05/09 07:01:50 fredb Exp $ #ifdef _MSC_VER #pragma warning( disable : 4786 4503 ) #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "curveact.hpp" #include "mainwin.hpp" FGSD_ActionID FGSD_AddCurveAction::_id; FGSD_AddCurveAction::FGSD_AddCurveAction() : _lon( 0 ) , _lat( 0 ) { } FGSD_AddCurveAction::FGSD_AddCurveAction( double __lon, double __lat ) : _lon( __lon ) , _lat( __lat ) { } bool FGSD_AddCurveAction::undo() { return _mainWindow->removeCurve( _lon, _lat ); } bool FGSD_AddCurveAction::redo( bool __step ) { bool ret = _mainWindow->newCurve( _lon, _lat ); if ( __step ) step( 1 ); return ret; } std::string FGSD_AddCurveAction::name() const { return "add"; } std::string FGSD_AddCurveAction::description() const { return "add a curve"; } FGSD_ActionID FGSD_AddCurveAction::type() const { return _id; } void *FGSD_AddCurveAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_AddCurveAction::clone() const { return new FGSD_AddCurveAction( *this ); } bool FGSD_AddCurveAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _lon; lat = _lat; return true; } bool FGSD_AddCurveAction::savable() const { return false; } bool FGSD_AddCurveAction::save( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "scenery-curve" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "longitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "latitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); return ret; } bool FGSD_AddCurveAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "longitude", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "latitude", 0, true ); if ( node ) { _lat = node->getDoubleValue(); ret = true; } } return ret; } //------------------------------------------------ FGSD_ActionID FGSD_RemoveCurveAction::_id; FGSD_RemoveCurveAction::FGSD_RemoveCurveAction() { } FGSD_RemoveCurveAction::FGSD_RemoveCurveAction( const FGSD_Curve &__curve ) { _pointList = __curve.points(); _opened = __curve.opened(); _current = __curve.current(); } bool FGSD_RemoveCurveAction::undo() { return _mainWindow->newCurve( &_pointList, _opened, _current ); } bool FGSD_RemoveCurveAction::redo( bool __step ) { bool ret = _mainWindow->removeCurve( _pointList[ 0 ].x(), _pointList[ 0 ].y() ); if ( __step ) step( 1 ); return ret; } std::string FGSD_RemoveCurveAction::name() const { return "remove"; } std::string FGSD_RemoveCurveAction::description() const { return "remove a curve"; } FGSD_ActionID FGSD_RemoveCurveAction::type() const { return _id; } void *FGSD_RemoveCurveAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_RemoveCurveAction::clone() const { return new FGSD_RemoveCurveAction( *this ); } bool FGSD_RemoveCurveAction::getPosition( bool undo, double &lon, double &lat ) const { Point3D p = _pointList.front().p; lon = p.x(); lat = p.y(); return true; } bool FGSD_RemoveCurveAction::savable() const { return false; } bool FGSD_RemoveCurveAction::save( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "scenery-curve" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "opened", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setBoolValue( _opened ); node = __node->getChild( "current", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setIntValue( _current ); size_t nb = _pointList.size(); for ( size_t i = 0; i < nb; i++ ) { node = __node->getChild( "longitude", i, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _pointList[ i ].x() ); node = __node->getChild( "latitude", i, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _pointList[ i ].y() ); } return ret; } bool FGSD_RemoveCurveAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "opened" ); if ( node ) { _opened = node->getBoolValue(); node = __node->getChild( "current", 0, true ); if ( node ) { _current = node->getIntValue(); _pointList.clear(); std::vector cLongitude = __node->getChildren( "longitude" ); std::vector cLatitude = __node->getChildren( "latitude" ); size_t nb = cLongitude.size(); for ( size_t i = 0; i < nb; i++ ) { Point3D p; node = cLongitude[ i ]; p.setx( node->getDoubleValue() ); node = cLatitude[ i ]; p.sety( node->getDoubleValue() ); p.setz( 0 ); _pointList.push_back( p ); } } } return ret; } //------------------------------------------------ FGSD_ActionID FGSD_AddCurvePointAction::_id; FGSD_AddCurvePointAction::FGSD_AddCurvePointAction() : _index( (size_t)-1 ) , _pLon( 0 ) , _pLat( 0 ) { } FGSD_AddCurvePointAction::FGSD_AddCurvePointAction( double __lon, double __lat, size_t __index, double __pLon, double __pLat ) : _lon( __lon ) , _lat( __lat ) , _index( __index ) , _pLon( __pLon ) , _pLat( __pLat ) { } bool FGSD_AddCurvePointAction::undo() { return _mainWindow->removeCurvePoint( _lon, _lat, _index ); } bool FGSD_AddCurvePointAction::redo( bool __step ) { bool ret = _mainWindow->addCurvePoint( _lon, _lat, _index, _pLon, _pLat ); if ( __step ) step( 1 ); return ret; } std::string FGSD_AddCurvePointAction::name() const { return "insert-point"; } std::string FGSD_AddCurvePointAction::description() const { return "insert a curve point"; } FGSD_ActionID FGSD_AddCurvePointAction::type() const { return _id; } void *FGSD_AddCurvePointAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_AddCurvePointAction::clone() const { return new FGSD_AddCurvePointAction( *this ); } bool FGSD_AddCurvePointAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _pLon; lat = _pLat; return true; } bool FGSD_AddCurvePointAction::savable() const { return false; } bool FGSD_AddCurvePointAction::save( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "scenery-curve" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "longitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "latitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); node = __node->getChild( "index", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setIntValue( _index ); node = __node->getChild( "point-x", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _pLon ); node = __node->getChild( "point-y", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _pLat ); return ret; } bool FGSD_AddCurvePointAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "longitude", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "latitude", 0, true ); if ( node ) { _lat = node->getDoubleValue(); node = __node->getChild( "index", 0, true ); if ( node ) { _index = node->getIntValue(); node = __node->getChild( "point-x", 0, true ); if ( node ) { _pLon = node->getDoubleValue(); node = __node->getChild( "point-y", 0, true ); if ( node ) { _pLat = node->getDoubleValue(); ret = true; } } } } } return ret; } //------------------------------------------------ FGSD_ActionID FGSD_RemoveCurvePointAction::_id; FGSD_RemoveCurvePointAction::FGSD_RemoveCurvePointAction() : _index( (size_t)-1 ) , _pLon( 0 ) , _pLat( 0 ) { } FGSD_RemoveCurvePointAction::FGSD_RemoveCurvePointAction( double __lon, double __lat, size_t __index, double __pLon, double __pLat, bool __last ) : _lon( __lon ) , _lat( __lat ) , _index( __index ) , _pLon( __pLon ) , _pLat( __pLat ) , _last( __last ) { } bool FGSD_RemoveCurvePointAction::undo() { bool ret; if ( _last ) ret = _mainWindow->newCurve( _lon, _lat ); else ret = _mainWindow->addCurvePoint( _lon, _lat, _index, _pLon, _pLat ); return ret; } bool FGSD_RemoveCurvePointAction::redo( bool __step ) { bool ret; if ( _last ) ret = _mainWindow->removeCurve( _lon, _lat ); else ret = _mainWindow->removeCurvePoint( _lon, _lat, _index ); if ( __step ) step( 1 ); return ret; } std::string FGSD_RemoveCurvePointAction::name() const { return "remove-point"; } std::string FGSD_RemoveCurvePointAction::description() const { return "remove a curve point"; } FGSD_ActionID FGSD_RemoveCurvePointAction::type() const { return _id; } void *FGSD_RemoveCurvePointAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_RemoveCurvePointAction::clone() const { return new FGSD_RemoveCurvePointAction( *this ); } bool FGSD_RemoveCurvePointAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _pLon; lat = _pLat; return true; } bool FGSD_RemoveCurvePointAction::savable() const { return false; } bool FGSD_RemoveCurvePointAction::save( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "scenery-curve" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "longitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "latitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); node = __node->getChild( "index", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setIntValue( _index ); node = __node->getChild( "point-x", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _pLon ); node = __node->getChild( "point-y", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _pLat ); return ret; } bool FGSD_RemoveCurvePointAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "longitude", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "latitude", 0, true ); if ( node ) { _lat = node->getDoubleValue(); node = __node->getChild( "index", 0, true ); if ( node ) { _index = node->getIntValue(); node = __node->getChild( "point-x", 0, true ); if ( node ) { _pLon = node->getDoubleValue(); node = __node->getChild( "point-y", 0, true ); if ( node ) { _pLat = node->getDoubleValue(); ret = true; } } } } } return ret; } //------------------------------------------------ FGSD_ActionID FGSD_MoveCurvePointAction::_id; FGSD_MoveCurvePointAction::FGSD_MoveCurvePointAction() : _index( (size_t)-1 ) { } FGSD_MoveCurvePointAction::FGSD_MoveCurvePointAction( double __lon, double __lat, size_t __index, double __xdepl, double __ydepl ) : _lon( __lon ) , _lat( __lat ) , _index( __index ) , _xdepl( __xdepl ) , _ydepl( __ydepl ) { } bool FGSD_MoveCurvePointAction::undo() { return _mainWindow->moveCurvePoint( _lon, _lat, _index, -_xdepl, -_ydepl, true ); } bool FGSD_MoveCurvePointAction::redo( bool __step ) { bool ret = _mainWindow->moveCurvePoint( _lon, _lat, _index, _xdepl, _ydepl, false ); if ( __step ) step( 1 ); return ret; } std::string FGSD_MoveCurvePointAction::name() const { return "move-point"; } std::string FGSD_MoveCurvePointAction::description() const { return "move a curve point"; } bool FGSD_MoveCurvePointAction::combine( FGSD_Action *__action ) { bool ret = false; FGSD_MoveCurvePointAction *act = (FGSD_MoveCurvePointAction *)__action->convertTo( FGSD_MoveCurvePointAction::_id ); if ( act ) { double olon = act->_lon; double olat = act->_lat; if ( act->_index == 0 ) { olon += act->_xdepl; olat += act->_ydepl; } if ( act && olon == _lon && olat == _lat && act->_index == _index ) { act->_xdepl += _xdepl; act->_ydepl += _ydepl; ret = true; } } return ret; } FGSD_ActionID FGSD_MoveCurvePointAction::type() const { return _id; } void *FGSD_MoveCurvePointAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_MoveCurvePointAction::clone() const { return new FGSD_MoveCurvePointAction( *this ); } bool FGSD_MoveCurvePointAction::getPosition( bool undo, double &lon, double &lat ) const { return _mainWindow->getCurvePointPosition( _lon, _lat, _index, lon, lat ); } bool FGSD_MoveCurvePointAction::savable() const { return false; } bool FGSD_MoveCurvePointAction::save( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "scenery-curve" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "longitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "latitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); node = __node->getChild( "index", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setIntValue( _index ); node = __node->getChild( "x-translation", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _xdepl ); node = __node->getChild( "y-translation", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _ydepl ); return ret; } bool FGSD_MoveCurvePointAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "longitude", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "latitude", 0, true ); if ( node ) { _lat = node->getDoubleValue(); node = __node->getChild( "index", 0, true ); if ( node ) { _index = node->getIntValue(); node = __node->getChild( "x-translation", 0, true ); if ( node ) { _xdepl = node->getDoubleValue(); node = __node->getChild( "y-translation", 0, true ); if ( node ) { _ydepl = node->getDoubleValue(); ret = true; } } } } } return ret; } //------------------------------------------------ FGSD_ActionID FGSD_CurvePropertiesAction::_id; FGSD_CurvePropertiesAction::FGSD_CurvePropertiesAction() { } FGSD_CurvePropertiesAction::FGSD_CurvePropertiesAction( const FGSD_Curve &__curve, FGSD_Curve::CurveType __type, double __height, const char *__material, bool __water ) : _newType( __type ) , _newHeight( __height ) , _newMaterial( __material ) , _newWater( __water ) { Point3D p = __curve.firstPoint(); _lon = p[ 0 ]; _lat = p[ 1 ]; _oldType = __curve.curveType(); _oldHeight = __curve.height(); _oldMaterial = __curve.material(); _oldWater = __curve.water(); } bool FGSD_CurvePropertiesAction::undo() { return _mainWindow->setCurveProperties( _lon, _lat, _oldType, _oldHeight, _oldMaterial.c_str(), _oldWater ); } bool FGSD_CurvePropertiesAction::redo( bool __step ) { bool ret = _mainWindow->setCurveProperties( _lon, _lat, _newType, _newHeight, _newMaterial.c_str(), _newWater ); if ( __step ) step( 1 ); return ret; } std::string FGSD_CurvePropertiesAction::name() const { return "properties"; } std::string FGSD_CurvePropertiesAction::description() const { return "change curve properties"; } FGSD_ActionID FGSD_CurvePropertiesAction::type() const { return _id; } void *FGSD_CurvePropertiesAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_CurvePropertiesAction::clone() const { return new FGSD_CurvePropertiesAction( *this ); } bool FGSD_CurvePropertiesAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _lon; lat = _lat; return true; } bool FGSD_CurvePropertiesAction::savable() const { return false; } bool FGSD_CurvePropertiesAction::save( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "scenery-curve" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "longitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "latitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); node = __node->getChild( "old-type", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); switch ( _oldType ) { case FGSD_Curve::UnSet: node->setStringValue( "UnSet" ); break; case FGSD_Curve::Curve2D: node->setStringValue( "Curve2D" ); break; case FGSD_Curve::Curve2D5: node->setStringValue( "Curve2D5" ); break; case FGSD_Curve::Curve3D: node->setStringValue( "Curve3D" ); break; } node = __node->getChild( "old-material", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( _oldMaterial.c_str() ); node = __node->getChild( "old-water", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setBoolValue( _oldWater ); node = __node->getChild( "old-height", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _oldHeight ); node = __node->getChild( "new-type", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); switch ( _newType ) { case FGSD_Curve::UnSet: node->setStringValue( "UnSet" ); break; case FGSD_Curve::Curve2D: node->setStringValue( "Curve2D" ); break; case FGSD_Curve::Curve2D5: node->setStringValue( "Curve2D5" ); break; case FGSD_Curve::Curve3D: node->setStringValue( "Curve3D" ); break; } node = __node->getChild( "new-material", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( _newMaterial.c_str() ); node = __node->getChild( "new-water", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setBoolValue( _newWater ); node = __node->getChild( "new-height", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _newHeight ); return ret; } bool FGSD_CurvePropertiesAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "longitude", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "latitude", 0, true ); if ( node ) { _lat = node->getDoubleValue(); node = __node->getChild( "old-type", 0, true ); if ( node ) { std::string type = node->getStringValue(); if ( type == "Curve2D" ) _oldType = FGSD_Curve::Curve2D; else if ( type == "Curve2D5" ) _oldType = FGSD_Curve::Curve2D5; else if ( type == "Curve3D" ) _oldType = FGSD_Curve::Curve3D; else _oldType = FGSD_Curve::UnSet; node = __node->getChild( "old-material", 0, true ); if ( node ) { _oldMaterial = node->getStringValue(); node = __node->getChild( "old-water", 0, true ); if ( node ) { _oldWater = node->getBoolValue(); node = __node->getChild( "old-height", 0, true ); if ( node ) { _oldHeight = node->getDoubleValue(); node = __node->getChild( "new-type", 0, true ); if ( node ) { std::string type = node->getStringValue(); if ( type == "Curve2D" ) _newType = FGSD_Curve::Curve2D; else if ( type == "Curve2D5" ) _newType = FGSD_Curve::Curve2D5; else if ( type == "Curve3D" ) _newType = FGSD_Curve::Curve3D; else _newType = FGSD_Curve::UnSet; node = __node->getChild( "new-material", 0, true ); if ( node ) { _newMaterial = node->getStringValue(); node = __node->getChild( "new-water", 0, true ); if ( node ) { _newWater = node->getBoolValue(); node = __node->getChild( "new-height", 0, true ); if ( node ) { _newHeight = node->getDoubleValue(); ret = true; } } } } } } } } } } return ret; } //------------------------------------------------ FGSD_ActionID FGSD_EmbedCurveAction::_id; FGSD_EmbedCurveAction::FGSD_EmbedCurveAction() : _lon( 0 ) , _lat( 0 ) { } FGSD_EmbedCurveAction::FGSD_EmbedCurveAction( double __lon, double __lat ) : _lon( __lon ) , _lat( __lat ) { } bool FGSD_EmbedCurveAction::undo() { return false; } bool FGSD_EmbedCurveAction::redo( bool __step ) { bool ret = _mainWindow->embedCurve( _lon, _lat ); if ( __step ) step( 1 ); return ret; } std::string FGSD_EmbedCurveAction::name() const { return "embed"; } std::string FGSD_EmbedCurveAction::description() const { return "embed a curve"; } FGSD_ActionID FGSD_EmbedCurveAction::type() const { return _id; } void *FGSD_EmbedCurveAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_EmbedCurveAction::clone() const { return new FGSD_EmbedCurveAction( *this ); } bool FGSD_EmbedCurveAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _lon; lat = _lat; return true; } bool FGSD_EmbedCurveAction::savable() const { return false; } bool FGSD_EmbedCurveAction::save( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "scenery-curve" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "longitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "latitude", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); return ret; } bool FGSD_EmbedCurveAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "longitude", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "latitude", 0, true ); if ( node ) { _lat = node->getDoubleValue(); ret = true; } } return ret; }