/***************************************************************************
 *   Copyright (C) 2004 by Hans Oischinger                                 *
 *   hans.oischinger@kdemail.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.,                                       *
 *   51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#ifndef ESETGENERICATTRCMD_H
#define ESETGENERICATTRCMD_H

#include "ecommand.h"
#include "visitors/avisitor.h"

class ElementNode;
class Attribute;
class AnimateElement;
/**
 * ESetGenericAttrCMD allows you to set or animate any attribute
 * @author Hans Oischinger
 */
class ESetGenericAttrCMD : public ECommand, public AVisitor
{
public:
  /**
   * The constructor accepts any concrete attribute as a target attribute, however the newattr
   * has to fit in some way: 
   * @param element 
   * @param targetattr 
   * @param newattr 
   * @return 
   */
  ESetGenericAttrCMD( ElementNode* element, Attribute &targetattr, Attribute &newattr );
  ~ESetGenericAttrCMD();

  void execute();
  void unexecute();

  virtual bool visit( TimeAttribute& );
  virtual bool visit( LengthAttribute& );
  virtual bool visit( Angle& );
  virtual bool visit( AnimatedColor& );
  virtual bool visit( AnimatedEnum& );
  virtual bool visit( AnimatedLength& );
  virtual bool visit( AnimatedNumber& );
  virtual bool visit( AnimatedTransformList& );
  virtual bool visit( ColorAttribute& );
  virtual bool visit( Enumeration& );
  virtual bool visit( FillAttribute& );
  virtual bool visit( Number& );
  virtual bool visit( StrokeAttribute& );
  virtual bool visit( Transform& );
  virtual bool visit( TransformList& );
  virtual bool visit( URIReference& );

protected:
  /**
   * Sets begin and duration of m_animElement and appends it to the tree
   * as a child of m_element
   */
  void finalizeAnimateElement();

private:
  ElementNode* m_element;
  Attribute* m_attribute;
  Attribute* m_targetAttr;
  Attribute* m_newAttr;
  Attribute* m_oldAttr;

  AnimateElement* m_animElement;
  bool m_removed; // True if the AnimateElement created by this command has been removed 
                  // and can be deleted in the destructor

};

#endif
