00001
00002
00014 #include "CompositeFunctionRep.h"
00015
00016 #include "FunctionParameter.h"
00017
00018 #include "functions/FunctionBase.h"
00019 #include "projectors/ProjectorBase.h"
00020
00021 #include "reps/LineFunctionRep.h"
00022
00023 #include <algorithm>
00024
00025 #include <cassert>
00026
00027 using std::find;
00028 using std::string;
00029 using std::vector;
00030
00031 using namespace hippodraw;
00032
00033 CompositeFunctionRep::
00034 CompositeFunctionRep ( FunctionBase * function, DataRep * target )
00035 : FunctionRep ( function, target )
00036 {
00037 m_rep = new LineFunctionRep ();
00038
00039
00040 const Color blue ( Color::blue );
00041 m_rep -> setColor ( blue );
00042 m_rep -> setSize ( 2 );
00043 }
00044
00049 void
00050 CompositeFunctionRep::
00051 addToComposite ( FunctionRep * frep )
00052 {
00053 frep -> setInComposite ( true );
00054 m_func_reps.push_back ( frep );
00055
00056 FunctionBase * composite = getFunction ();
00057 FunctionBase * function = frep -> getFunction ();
00058
00059 composite -> addToComposite ( function );
00060
00061 Fitter * fitter = getFitter ();
00062 if ( fitter != 0 ) {
00063 vector < int > flags = getFixedFlags ();
00064 int size = function -> size ();
00065 while ( size-- != 0 ) {
00066 flags.push_back ( 0 );
00067 }
00068
00069 setFixedFlags ( flags );
00070 }
00071 }
00072
00073 bool
00074 CompositeFunctionRep::
00075 isMember ( const FunctionRep * rep )
00076 {
00077 FunctionRepList_t::iterator first
00078 = find ( m_func_reps.begin(), m_func_reps.end(), rep );
00079
00080 return first != m_func_reps.end();
00081 }
00082
00083 void
00084 CompositeFunctionRep::
00085 removeFromComposite ( FunctionRep * frep )
00086 {
00087 FunctionBase * function = frep -> getFunction ();
00088 FunctionBase * composite = getFunction ();
00089 composite -> removeFromComposite ( function );
00090
00091 FunctionRepList_t::iterator first
00092 = find ( m_func_reps.begin(), m_func_reps.end(), frep );
00093 if ( first != m_func_reps.end () ) {
00094 m_func_reps.erase ( first );
00095 }
00096
00097 frep -> setInComposite ( false );
00098 }
00099
00100 unsigned int
00101 CompositeFunctionRep::
00102 count () const
00103 {
00104 return m_func_reps.size ();
00105 }
00106
00107 const CompositeFunctionRep::FunctionRepList_t &
00108 CompositeFunctionRep::
00109 getFunctionReps () const
00110 {
00111 return m_func_reps;
00112 }
00113
00114 void
00115 CompositeFunctionRep::
00116 drawProjectedValues ( TransformBase * transform, ViewBase * view )
00117 {
00118
00119 drawCuts ( transform, view );
00120
00121 const Range & range = m_projector -> getRange ( Axes::X );
00122 FunctionBase * function = getFunction ();
00123 LineFunctionRep * rep = dynamic_cast < LineFunctionRep * > ( m_rep );
00124 assert ( rep != 0 );
00125
00126 rep -> drawProjectedValues ( range, function, transform, view );
00127
00128 setDirty ( false );
00129 }
00130
00131 void
00132 CompositeFunctionRep::
00133 setFixedFlags ( const std::vector < int > & flags )
00134 {
00135 unsigned int size = m_func_reps.size ();
00136 vector<int>::const_iterator first = flags.begin();
00137
00138 for ( unsigned int i = 0; i < size; i++ ) {
00139 FunctionRep * frep = m_func_reps[i];
00140 vector < int > tmp = frep -> getFixedFlags ();
00141 unsigned int number = tmp.size ();
00142 vector<int>::const_iterator end = first + number;
00143 copy ( first, end, tmp.begin() );
00144 frep -> setFixedFlags ( tmp );
00145 first = end;
00146 }
00147
00148 FunctionRep::setFixedFlags ( flags );
00149 }