/*************************************************************************** * Copyright (c) 2016 Eivind Kvedalen * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #ifndef RENAMEOBJECTIDENTIFIEREXPRESSIONVISITOR_H #define RENAMEOBJECTIDENTIFIEREXPRESSIONVISITOR_H #include "Expression.h" namespace App { /** * @brief The RenameObjectIdentifierExpressionVisitor class is a functor used to visit each node of an expression, and * possibly rename VariableExpression nodes. */ template class RenameObjectIdentifierExpressionVisitor : public ExpressionModifier

{ public: RenameObjectIdentifierExpressionVisitor( P &_prop, const std::map &_paths, const ObjectIdentifier &_owner) : ExpressionModifier

(_prop) , paths( _paths ) , owner( _owner ) { } void visit(Expression &node) { this->renameObjectIdentifier(node,paths,owner); } private: const std::map &paths; /**< Map with current and new object identifiers */ const ObjectIdentifier owner; /**< Owner of expression */ }; template class UpdateElementReferenceExpressionVisitor : public ExpressionModifier

{ public: explicit UpdateElementReferenceExpressionVisitor(P & _prop, App::DocumentObject *feature=nullptr, bool reverse=false) : ExpressionModifier

(_prop),feature(feature),reverse(reverse) { } void visit(Expression &node) { this->updateElementReference(node,feature,reverse); } private: App::DocumentObject *feature; bool reverse; }; // Document relabel is not undoable, so we don't derive from // ExpressionModifier, hence not calling aboutToSetValue/hasSetValue(). // By right, modification of document label should not change evaluation result // of any expression. class RelabelDocumentExpressionVisitor : public ExpressionVisitor { public: explicit RelabelDocumentExpressionVisitor(const App::Document &doc) : doc(doc) { } void visit(Expression &node) override { this->relabeledDocument(node,doc.getOldLabel(),doc.Label.getStrValue()); } private: const App::Document &doc; }; template class MoveCellsExpressionVisitor : public ExpressionModifier

{ public: MoveCellsExpressionVisitor(P &prop, const CellAddress &address, int rowCount, int colCount) : ExpressionModifier

(prop),address(address),rowCount(rowCount),colCount(colCount) {} void visit(Expression &node) { this->moveCells(node,address,rowCount,colCount); } private: CellAddress address; int rowCount; int colCount; }; template class OffsetCellsExpressionVisitor : public ExpressionModifier

{ public: OffsetCellsExpressionVisitor(P &prop, int rowOffset, int colOffset) : ExpressionModifier

(prop),rowOffset(rowOffset),colOffset(colOffset) {} void visit(Expression &node) { this->offsetCells(node,rowOffset,colOffset); } private: int rowOffset; int colOffset; }; } #endif // RENAMEOBJECTIDENTIFIEREXPRESSIONVISITOR_H