2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAFramework.
6
Licensed under the MIT Open Source License,
7
for details please see LICENSE file or the website
8
http://www.opensource.org/licenses/mit-license.php
11
#include "COLLADAFWStableHeaders.h"
12
#include "COLLADAFWFormulas.h"
14
#include "MathMLASTNode.h"
15
#include "MathMLASTArithmeticExpression.h"
16
#include "MathMLASTBinaryComparisionExpression.h"
17
#include "MathMLASTConstantExpression.h"
18
#include "MathMLASTFragmentExpression.h"
19
#include "MathMLASTFunctionExpression.h"
20
#include "MathMLASTLogicExpression.h"
21
#include "MathMLASTUnaryArithmeticExpression.h"
22
#include "MathMLASTVariableExpression.h"
28
//------------------------------
29
void setFragments( MathML::AST::INode* astNode, const Formula::ASTNodeASTNodeMap& originalClonedASTNodeMap)
31
switch ( astNode->getNodeType() )
33
case MathML::AST::INode::ARITHMETIC:
35
MathML::AST::ArithmeticExpression* arithmetic = (MathML::AST::ArithmeticExpression*)astNode;
36
MathML::AST::NodeList& operands = arithmetic->getOperands();
37
for ( size_t i = 0, count = operands.size(); i < count; ++i )
39
setFragments(operands[i], originalClonedASTNodeMap);
43
case MathML::AST::INode::COMPARISON:
45
MathML::AST::BinaryComparisonExpression* comparison = (MathML::AST::BinaryComparisonExpression*)astNode;
46
setFragments(comparison->getLeftOperand(), originalClonedASTNodeMap);
47
setFragments(comparison->getRightOperand(), originalClonedASTNodeMap);
50
case MathML::AST::INode::CONSTANT:
51
case MathML::AST::INode::VARIABLE:
53
case MathML::AST::INode::FRAGMENT:
55
MathML::AST::FragmentExpression* fragment = (MathML::AST::FragmentExpression*)astNode;
56
MathML::AST::INode* fragmentNode = fragment->getFragment();
57
Formula::ASTNodeASTNodeMap::const_iterator it = originalClonedASTNodeMap.find(fragmentNode);
58
COLLADABU_ASSERT( it != originalClonedASTNodeMap.end() );
59
fragment->setFragment( it->second );
62
case MathML::AST::INode::LOGICAL:
64
MathML::AST::LogicExpression* logical = (MathML::AST::LogicExpression*)astNode;
65
MathML::AST::NodeList& operands = logical->getOperands();
66
for ( size_t i = 0, count = operands.size(); i < count; ++i )
68
setFragments(operands[i], originalClonedASTNodeMap);
72
case MathML::AST::INode::UNARY:
74
MathML::AST::UnaryExpression* unary = (MathML::AST::UnaryExpression*)astNode;
75
setFragments(unary->getOperand(), originalClonedASTNodeMap);
78
case MathML::AST::INode::FUNCTION:
80
MathML::AST::FunctionExpression* func = (MathML::AST::FunctionExpression*)astNode;
81
MathML::AST::NodeList& operands = func->getParameterList();
82
for ( size_t i = 0, count = operands.size(); i < count; ++i )
84
setFragments(operands[i], originalClonedASTNodeMap);
89
COLLADABU_ASSERT(false);
94
//------------------------------
96
: mFormulas( FormulaArray::OWNER )
100
//------------------------------
101
Formulas::Formulas( const Formulas& rhs )
102
: mFormulas( FormulaArray::OWNER )
104
Formula::ASTNodeASTNodeMap originalClonedASTNodeMap;
105
size_t count = rhs.mFormulas.getCount();
106
mFormulas.reallocMemory(count);
107
for ( size_t i = 0; i < count; ++i )
109
mFormulas[i] = rhs.mFormulas[i]->clone( originalClonedASTNodeMap );
111
mFormulas.setCount(count);
113
for ( size_t i = 0; i < count; ++i )
115
const MathmlAstArray& asts = mFormulas[i]->getMathmlAsts();
116
// second step: set fragments to corresponding formula ast
117
for ( size_t j = 0, count = asts.getCount(); j < count; ++j )
119
setFragments(asts[j], originalClonedASTNodeMap);
123
//------------------------------
124
Formulas::~Formulas()
126
for ( size_t i = 0, count = mFormulas.getCount(); i < count; ++i )
128
FW_DELETE mFormulas[i];
132
} // namespace COLLADAFW