00001 #ifndef DEFINER_H
00002 #define DEFINER_H
00003
00004 #include "std/support.H"
00005 #include "net/data_item.H"
00006 #include "net/stream.H"
00007 #include "mlib/points.H"
00008 #include "mod.H"
00009 #include "body.H"
00010
00011 class GEOM;
00012 class BODY;
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #define CBASIC_DATA const BASIC_DATA
00050 template<class T>
00051 class BASIC_DATA {
00052 protected:
00053 T _data;
00054 MOD _id;
00055 GEOM *_geom;
00056
00057 public :
00058 BASIC_DATA() {}
00059 BASIC_DATA(const BASIC_DATA<T> &d):_data(d._data),_id(d._id),_geom(0) {}
00060 virtual ~BASIC_DATA() {}
00061 const MOD &id() const { return _id; }
00062 MOD &id() { return _id; }
00063 const T &data() const { return _data; }
00064 T &data() { return _data; }
00065 const GEOM *geom() const { return _geom; }
00066 GEOM * geom() { return _geom; }
00067
00068 void write(GEOM *g, T d, MOD m) { _geom = g; _data = d; _id = m; }
00069 };
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 #define CDEFINER const DEFINER
00082 class DEFINER : public DATA_ITEM {
00083 public :
00084 enum data_mask {
00085 XFORM = 1,
00086 ORIG_BODY = 2,
00087 XFORM_AND_ORIG_BODY = 3,
00088 CSG_BODY = 4
00089 };
00090 protected :
00091 int _reached;
00092 data_mask _out_mask;
00093 BASIC_DATA<mlib::Wtransf> _xf_delt;
00094 BASIC_DATA<int> _ob_delt;
00095 ARRAY<GEOM*> _inputs;
00096 ARRAY<GEOM*> _outputs;
00097 static TAGlist *_def_tags;
00098 public :
00099 DEFINER();
00100 DEFINER(CDEFINER *d, GEOM *g): _reached(0), _out_mask(d->_out_mask),
00101 _inputs(d->_inputs) { set_geom(g); }
00102 virtual~DEFINER();
00103 virtual DEFINER *copy (GEOM *g) const { return new DEFINER(this,g); }
00104
00105 virtual CTAGlist &tags () const;
00106
00107 virtual void add_input(GEOM *o);
00108 virtual void rem_input(GEOM *o);
00109
00110 virtual GEOM *feat_geom() const { return 0; }
00111 const GEOM *geom (int i = 0) const { return _outputs[i]; }
00112 GEOM *geom (int i = 0) { return _outputs[i]; }
00113 virtual void rem_geom (GEOM *g) { _outputs -= g; }
00114 virtual void add_geom (GEOM *g) { _outputs += g; }
00115
00116 virtual void clear_geom() { _outputs.clear(); }
00117 virtual void set_geom (GEOM *g) { _outputs += g; }
00118
00119 void clear_deltas() { _xf_delt.data() = mlib::Identity;}
00120 void set_delta(GEOM *g, CBODYptr&, CMOD&m)
00121 {_ob_delt.write(g,0,m);reach();}
00122 void set_delta(GEOM *g, mlib::CWtransf&d,CMOD&m)
00123 {_xf_delt.write(g,
00124 m == _xf_delt.id() ? d : d * _xf_delt.data(),m);
00125 reach(); }
00126 mlib::Wtransf xf_delta () { return _xf_delt.data(); }
00127 CBASIC_DATA<mlib::Wtransf> &xf_delt () const { return _xf_delt;}
00128
00129
00130 void reach (int r=1) { _reached = r; }
00131 int reached () { return _reached; }
00132 int mask (data_mask d) { return (int)_out_mask&(int)d;}
00133
00134 int num_outputs() const { return _outputs.num(); }
00135 int num_inputs() const { return _inputs.num(); }
00136 data_mask out_mask() const { return _out_mask; }
00137 GEOM *operator[](int i) { return _inputs[i]; }
00138 virtual ARRAY<GEOM *> required() const { return ARRAY<GEOM *>(); }
00139
00140 virtual void visit (MOD &mod);
00141 virtual void print (ostream &os) { os << class_name(); }
00142 virtual DATA_ITEM*dup () const { return new DEFINER;}
00143 virtual void put_outmask(TAGformat &d) const { d.id()<< (int)_out_mask;}
00144 virtual void put_inputs (TAGformat &d) const;
00145 virtual void get_outmask(TAGformat &d) { *d >> (int&)_out_mask; }
00146 virtual void get_inputs (TAGformat &d);
00147
00148 DEFINE_RTTI_METHODS2("DEFINER", DATA_ITEM, CDEFINER *);
00149
00150 };
00151
00152 inline STDdstream &operator<<(STDdstream &ds, CDEFINER *p)
00153 { return p ? p->format(ds) : ds; }
00154
00155 #define CDATA const DATA
00156 template<class T>
00157 class DATA : public BASIC_DATA<T> {
00158 ARRAY<DEFINER*> _outputs;
00159
00160 public :
00161 DATA() {}
00162
00163 DATA(const DATA<T> &d):BASIC_DATA<T>(d) {}
00164 ARRAY<DEFINER*> *operator->() { return &_outputs; }
00165 const ARRAY<DEFINER*> *operator->() const { return &_outputs; }
00166 ARRAY<DEFINER*> &operator *() { return _outputs; }
00167 const ARRAY<DEFINER*> &operator *() const { return _outputs; }
00168 void operator+=(DEFINER *d) { _outputs += d; }
00169 void operator-=(DEFINER *d) { _outputs -= d; }
00170 DEFINER *operator[](int i) { return _outputs[i]; }
00171
00172 void write(T d) { data() = d; }
00173 void write(GEOM *g, T d, MOD m) { write(g,d,d,m); }
00174 void write(GEOM *g, T x, T d, MOD m) { data() = x; id() = m;
00175 for (int i=0; i<_outputs.num(); i++)
00176 _outputs[i]->set_delta(g,d,m); }
00177 friend
00178 ostream &operator << (ostream &os, const DATA<T> &d) { return os<<d.data(); }
00179
00180 using BASIC_DATA<T>::id;
00181 using BASIC_DATA<T>::data;
00182 };
00183
00184 #define CCOMPOSITE_DEF const COMPOSITE_DEF
00185 class COMPOSITE_DEF : public DEFINER {
00186 public :
00187 COMPOSITE_DEF () { }
00188 COMPOSITE_DEF (CCOMPOSITE_DEF *d, GEOM *g):DEFINER(d,g) { }
00189
00190 virtual void visit (MOD &mod);
00191 virtual void inputs_changed(int all_eq, int any_body_mod, MOD &m) = 0;
00192
00193 DEFINE_RTTI_METHODS2("COMPOSITE", DEFINER, CDEFINER *);
00194 };
00195
00196 #endif
00197