// baseobjact.cpp -- base object 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: baseobjact.cpp,v 1.7 2005/06/09 22:33:58 fredb2 Exp $ #ifdef _MSC_VER #pragma warning( disable : 4786 4503 ) #endif #include "baseobjact.hpp" #include "mainwin.hpp" FGSD_ActionID FGSD_MoveVertexBaseObjectAction::_id; FGSD_MoveVertexBaseObjectAction::FGSD_MoveVertexBaseObjectAction() : _lon( 0 ) , _lat( 0 ) , _xdepl( 0 ) , _ydepl( 0 ) { } FGSD_MoveVertexBaseObjectAction::FGSD_MoveVertexBaseObjectAction( const char *__name, double __lon, double __lat, double __xdepl, double __ydepl ) : _name( __name ) , _lon( __lon ) , _lat( __lat ) , _xdepl( __xdepl ) , _ydepl( __ydepl ) { } bool FGSD_MoveVertexBaseObjectAction::undo() { return _mainWindow->moveBaseObjectVertex( _name.c_str(), _lon + _xdepl, _lat + _ydepl, - _xdepl, - _ydepl ); } bool FGSD_MoveVertexBaseObjectAction::redo( bool __step ) { bool ret = _mainWindow->moveBaseObjectVertex( _name.c_str(), _lon, _lat, _xdepl, _ydepl ); if ( __step ) step( 1 ); return ret; } std::string FGSD_MoveVertexBaseObjectAction::name() const { return "move-vertex"; } std::string FGSD_MoveVertexBaseObjectAction::description() const { return "move a base object vertex"; } bool FGSD_MoveVertexBaseObjectAction::combine( FGSD_Action *__action ) { bool ret = false; FGSD_MoveVertexBaseObjectAction *act = (FGSD_MoveVertexBaseObjectAction *)__action->convertTo( FGSD_MoveVertexBaseObjectAction::_id ); if ( act && act->_name == _name && act->_lon + act->_xdepl == _lon && act->_lat + act->_ydepl == _lat ) { act->_xdepl += _xdepl; act->_ydepl += _ydepl; ret = true; } return ret; } FGSD_ActionID FGSD_MoveVertexBaseObjectAction::type() const { return _id; } void *FGSD_MoveVertexBaseObjectAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_MoveVertexBaseObjectAction::clone() const { return new FGSD_MoveVertexBaseObjectAction( *this ); } bool FGSD_MoveVertexBaseObjectAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _lon; lat = _lat; if ( !undo ) { lon += _xdepl; lat += _ydepl; } return true; } bool FGSD_MoveVertexBaseObjectAction::save( const char *__project, SGPropertyNode *__node ) { SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "base-object" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "object", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( _name.c_str() ); node = __node->getChild( "vertex-lon", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "vertex-lat", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); 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 true; } bool FGSD_MoveVertexBaseObjectAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "object" ); if ( node ) { _name = node->getStringValue(); node = __node->getChild( "vertex-lon", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "vertex-lat", 0, true ); if ( node ) { _lat = node->getDoubleValue(); 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_ChangeHeightBaseObjectAction::_id; FGSD_ChangeHeightBaseObjectAction::FGSD_ChangeHeightBaseObjectAction() : _lon( 0 ) , _lat( 0 ) , _zdepl( 0 ) { } FGSD_ChangeHeightBaseObjectAction::FGSD_ChangeHeightBaseObjectAction( const char *__name, double __lon, double __lat, double __zdepl ) : _name( __name ) , _lon( __lon ) , _lat( __lat ) , _zdepl( __zdepl ) { } bool FGSD_ChangeHeightBaseObjectAction::undo() { return _mainWindow->changeBaseObjectHeight( _name.c_str(), _lon, _lat, - _zdepl ); } bool FGSD_ChangeHeightBaseObjectAction::redo( bool __step ) { bool ret = _mainWindow->changeBaseObjectHeight( _name.c_str(), _lon, _lat, _zdepl ); if ( __step ) step( 1 ); return ret; } std::string FGSD_ChangeHeightBaseObjectAction::name() const { return "change-height"; } std::string FGSD_ChangeHeightBaseObjectAction::description() const { return "change a base object height"; } bool FGSD_ChangeHeightBaseObjectAction::combine( FGSD_Action *__action ) { bool ret = false; FGSD_ChangeHeightBaseObjectAction *act = (FGSD_ChangeHeightBaseObjectAction *)__action->convertTo( FGSD_ChangeHeightBaseObjectAction::_id ); if ( act && act->_name == _name && act->_lon == _lon && act->_lat == _lat ) { act->_zdepl += _zdepl; ret = true; } return ret; } FGSD_ActionID FGSD_ChangeHeightBaseObjectAction::type() const { return _id; } void *FGSD_ChangeHeightBaseObjectAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_ChangeHeightBaseObjectAction::clone() const { return new FGSD_ChangeHeightBaseObjectAction( *this ); } bool FGSD_ChangeHeightBaseObjectAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _lon; lat = _lat; return true; } bool FGSD_ChangeHeightBaseObjectAction::save( const char *__project, SGPropertyNode *__node ) { SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "base-object" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "object", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( _name.c_str() ); node = __node->getChild( "vertex-lon", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "vertex-lat", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); node = __node->getChild( "z-translation", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _zdepl ); return true; } bool FGSD_ChangeHeightBaseObjectAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "object" ); if ( node ) { _name = node->getStringValue(); node = __node->getChild( "vertex-lon", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "vertex-lat", 0, true ); if ( node ) { _lat = node->getDoubleValue(); node = __node->getChild( "z-translation", 0, true ); if ( node ) { _zdepl = node->getDoubleValue(); ret = true; } } } } return ret; } // ------------------------------------------------------------------------ FGSD_ActionID FGSD_ChangeMaterialBaseObjectAction::_id; FGSD_ChangeMaterialBaseObjectAction::FGSD_ChangeMaterialBaseObjectAction() : _lon( 0 ) , _lat( 0 ) { } FGSD_ChangeMaterialBaseObjectAction::FGSD_ChangeMaterialBaseObjectAction( const char *__name, double __lon, double __lat, const std::string &__oldmat, const std::string &__newmat ) : _name( __name ) , _lon( __lon ) , _lat( __lat ) , _oldmat( __oldmat ) , _newmat( __newmat ) { } bool FGSD_ChangeMaterialBaseObjectAction::undo() { return _mainWindow->changeBaseObjectMaterial( _name.c_str(), _lon, _lat, _oldmat ); } bool FGSD_ChangeMaterialBaseObjectAction::redo( bool __step ) { bool ret = _mainWindow->changeBaseObjectMaterial( _name.c_str(), _lon, _lat, _newmat ); if ( __step ) step( 1 ); return ret; } std::string FGSD_ChangeMaterialBaseObjectAction::name() const { return "change-material"; } std::string FGSD_ChangeMaterialBaseObjectAction::description() const { return "change a base object material"; } bool FGSD_ChangeMaterialBaseObjectAction::combine( FGSD_Action *__action ) { bool ret = false; return ret; } FGSD_ActionID FGSD_ChangeMaterialBaseObjectAction::type() const { return _id; } void *FGSD_ChangeMaterialBaseObjectAction::convertTo( FGSD_ActionID __id ) { return __id == _id ? (void *)this : 0; } FGSD_Action *FGSD_ChangeMaterialBaseObjectAction::clone() const { return new FGSD_ChangeMaterialBaseObjectAction( *this ); } bool FGSD_ChangeMaterialBaseObjectAction::getPosition( bool undo, double &lon, double &lat ) const { lon = _lon; lat = _lat; return true; } bool FGSD_ChangeMaterialBaseObjectAction::save( const char *__project, SGPropertyNode *__node ) { SGPropertyNode *node = __node->getChild( "family", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( "base-object" ); node = __node->getChild( "name", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( name().c_str() ); node = __node->getChild( "object", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( _name.c_str() ); node = __node->getChild( "vertex-lon", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lon ); node = __node->getChild( "vertex-lat", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setDoubleValue( _lat ); node = __node->getChild( "old-material", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( _oldmat.c_str() ); node = __node->getChild( "new-material", 0, true ); node->setAttributes( SGPropertyNode::READ | SGPropertyNode::WRITE | SGPropertyNode::ARCHIVE ); node->setStringValue( _newmat.c_str() ); return true; } bool FGSD_ChangeMaterialBaseObjectAction::load( const char *__project, SGPropertyNode *__node ) { bool ret = false; SGPropertyNode *node = __node->getChild( "object" ); if ( node ) { _name = node->getStringValue(); node = __node->getChild( "vertex-lon", 0, true ); if ( node ) { _lon = node->getDoubleValue(); node = __node->getChild( "vertex-lat", 0, true ); if ( node ) { _lat = node->getDoubleValue(); node = __node->getChild( "old-material", 0, true ); if ( node ) { _oldmat = node->getStringValue(); node = __node->getChild( "new-material", 0, true ); if ( node ) { _newmat = node->getStringValue(); ret = true; } } } } } return ret; }