CompositeFunctionRep.cxx
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 
14 #include "CompositeFunctionRep.h"
15 
16 #include "FunctionParameter.h"
17 
18 #include "functions/FunctionBase.h"
20 
21 #include "reps/LineFunctionRep.h"
22 
23 #include <algorithm>
24 
25 #include <cassert>
26 
27 using std::find;
28 using std::string;
29 using std::vector;
30 
31 using namespace hippodraw;
32 
34 CompositeFunctionRep ( FunctionBase * function, DataRep * target )
35  : FunctionRep ( function, target )
36 {
37  m_rep = new LineFunctionRep ();
38  // The above deleted in ~DataRep()
39 
40  const Color blue ( Color::blue );
41  m_rep -> setColor ( blue );
42  m_rep -> setSize ( 2 );
43 }
44 
49 void
52 {
53  frep -> setInComposite ( true );
54  m_func_reps.push_back ( frep );
55 
56  FunctionBase * composite = getFunction ();
57  FunctionBase * function = frep -> getFunction ();
58 
59  composite -> addToComposite ( function );
60 
61  Fitter * fitter = getFitter ();
62  if ( fitter != 0 ) {
63  vector < int > flags = getFixedFlags (); // a copy
64  int size = function -> size ();
65  while ( size-- != 0 ) {
66  flags.push_back ( 0 );
67  }
68 
69  setFixedFlags ( flags );
70  }
71 }
72 
73 bool
75 isMember ( const FunctionRep * rep )
76 {
77  FunctionRepList_t::iterator first
78  = find ( m_func_reps.begin(), m_func_reps.end(), rep );
79 
80  return first != m_func_reps.end();
81 }
82 
83 void
86 {
87  FunctionBase * function = frep -> getFunction ();
88  FunctionBase * composite = getFunction ();
89  composite -> removeFromComposite ( function );
90 
91  FunctionRepList_t::iterator first
92  = find ( m_func_reps.begin(), m_func_reps.end(), frep );
93  if ( first != m_func_reps.end () ) {
94  m_func_reps.erase ( first );
95  }
96 
97  frep -> setInComposite ( false );
98 }
99 
100 unsigned int
102 count () const
103 {
104  return m_func_reps.size ();
105 }
106 
110 {
111  return m_func_reps;
112 }
113 
114 void
117 {
118 
119  drawCuts ( transform, view );
120 
121  const Range & range = m_projector -> getRange ( Axes::X );
122  FunctionBase * function = getFunction ();
123  LineFunctionRep * rep = dynamic_cast < LineFunctionRep * > ( m_rep );
124  assert ( rep != 0 );
125 
126  rep -> drawProjectedValues ( range, function, transform, view );
127 
128  setDirty ( false );
129 }
130 
131 void
133 setFixedFlags ( const std::vector < int > & flags )
134 {
135  unsigned int size = m_func_reps.size ();
136  vector<int>::const_iterator first = flags.begin();
137 
138  for ( unsigned int i = 0; i < size; i++ ) {
139  FunctionRep * frep = m_func_reps[i];
140  vector < int > tmp = frep -> getFixedFlags ();// a copy
141  unsigned int number = tmp.size ();
142  vector<int>::const_iterator end = first + number;
143  copy ( first, end, tmp.begin() );
144  frep -> setFixedFlags ( tmp );
145  first = end;
146  }
147 
148  FunctionRep::setFixedFlags ( flags );
149 }

Generated for HippoDraw Class Library by doxygen