IMP  2.0.1
The Integrative Modeling Platform
geometry_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/display/geometry_macros.h
3  * \brief macros for display classes
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPDISPLAY_GEOMETRY_MACROS_H
9 #define IMPDISPLAY_GEOMETRY_MACROS_H
10 #include "declare_Geometry.h"
11 #include <IMP/singleton_macros.h>
12 #include <IMP/pair_macros.h>
13 
14 //! Define information for an Geometry object
15 #define IMP_GEOMETRY(Name) \
16  IMP_IMPLEMENT(IMP::display::Geometries get_components() const); \
17  IMP_OBJECT(Name)
18 
19 
20 
21 
22 #define IMP_DISPLAY_GEOMETRY_DEF(Name, Type) \
23  Name::Name(std::string name): display::Geometry(name) {} \
24  Name::Name(const Type &v): display::Geometry(#Name), v_(v){} \
25  Name::Name(const Type &v, const Color &c): \
26  display::Geometry(c, #Name), v_(v) {} \
27  Name::Name(const Type &v, const std::string n): \
28  display::Geometry(n), v_(v) {} \
29  Name::Name(const Type &v, const Color &c, std::string n): \
30  display::Geometry(c,n), v_(v) {} \
31  display::Geometries Name::get_components() const { \
32  return display::Geometries(1, const_cast<Name*>(this)); \
33  } \
34  void Name::do_show(std::ostream &out) const { \
35  out << #Name << "Geometry: " << get_geometry(); \
36  }; \
37  IMP_REQUIRE_SEMICOLON_NAMESPACE
38 
39 #if defined(IMP_DOXYGEN) || defined(SWIG)
40 //! Define a geometric object using an IMP::algebra one
41 #define IMP_DISPLAY_GEOMETRY_DECL(Name, Names, Type) \
42  /** Display a geometric object.*/ \
43  class IMPDISPLAYEXPORT Name: public display::Geometry { \
44  public: \
45  Name(const Type &v); \
46  Name(const Type &v, const display::Color &c); \
47  Name(const Type &v, const std::string n); \
48  Name(const Type &v, const display::Color &c, std::string n); \
49  virtual const Type& get_geometry() const {return v_;} \
50  void set_geometry(const Type &v) { v_=v;} \
51  IMP_GEOMETRY(Name); \
52  }; \
53  /** Create a Geometry with the passed primitive.*/ \
54  inline Name *create_geometry(const Type &t, \
55  std::string name=#Type+"%1%")
56 
57 
58 #define IMP_DISPLAY_GEOMETRY_DECOMPOSABLE_DECL(Name, Names, Type) \
59  /** Display a compound geometric object.*/ \
60  class IMPDISPLAYEXPORT Name: public display::Geometry { \
61  public: \
62  Name(const Type &v); \
63  Name(const Type &v, const display::Color &c); \
64  Name(const Type &v, const std::string n); \
65  Name(const Type &v, const display::Color &c, std::string n); \
66  virtual const Type& get_geometry() const {return v_;} \
67  void set_geometry(const Type &v) { v_=v;} \
68  IMP_GEOMETRY(Name); \
69  }; \
70  /** Create a Geometry with the passed primitive.*/ \
71  inline Name *create_geometry(const Type &t, \
72  std::string name=#Type+"%1%")
73 
74 #else
75 
76 //! Define a geometric object using an IMP::algebra one
77 #define IMP_DISPLAY_GEOMETRY_DECL(Name, Names, Type) \
78  /** Display a geometric object.*/ \
79  class IMPDISPLAYEXPORT Name: public display::Geometry { \
80  Type v_; \
81  public: \
82  Name(std::string name); \
83  Name(const Type &v); \
84  Name(const Type &v, const display::Color &c); \
85  Name(const Type &v, const std::string n); \
86  Name(const Type &v, const display::Color &c, std::string n); \
87  virtual const Type& get_geometry() const {return v_;} \
88  void set_geometry(const Type &v) { v_=v;} \
89  IMP_GEOMETRY(Name); \
90  }; \
91  inline Name *create_geometry(const Type &t, \
92  std::string name \
93  =std::string(#Type)+"%1%") { \
94  return new Name(t, name); \
95  } \
96  IMP_OBJECTS(Name, Names)
97 
98 
99 
100 #define IMP_DISPLAY_GEOMETRY_DECOMPOSABLE_DECL(Name, Names, Type) \
101  /** Display a compound geometric object.*/ \
102  class IMPDISPLAYEXPORT Name: public display::Geometry { \
103  Type v_; \
104  public: \
105  Name(std::string name); \
106  Name(const Type &v); \
107  Name(const Type &v, const display::Color &c); \
108  Name(const Type &v, const std::string n); \
109  Name(const Type &v, const display::Color &c, std::string n); \
110  virtual const Type& get_geometry() const {return v_;} \
111  void set_geometry(const Type &v) { v_=v;} \
112  IMP_GEOMETRY(Name); \
113  }; \
114  inline Name *create_geometry(const Type &t, \
115  std::string name \
116  =std::string(#Type)+"%1%") { \
117  return new Name(t, name); \
118  } \
119  IMP_OBJECTS(Name, Names)
120 #endif
121 
122 
123 #define IMP_DISPLAY_GEOMETRY_DECOMPOSABLE_DEF(Name, Type, decomp) \
124  Name::Name(std::string name): display::Geometry(name) {} \
125  Name::Name(const Type &v): display::Geometry(#Name), v_(v){} \
126  Name::Name(const Type &v, const display::Color &c): \
127  display::Geometry(c, #Name), v_(v) {} \
128  Name::Name(const Type &v, const std::string n): \
129  display::Geometry(n), v_(v) {} \
130  Name::Name(const Type &v, const display::Color &c, std::string n): \
131  display::Geometry(c,n), v_(v) {} \
132  void Name::do_show(std::ostream &out) const { \
133  out << #Name << "Geometry: " \
134  << get_geometry(); \
135  } \
136  display::Geometries Name::get_components() const { \
137  display::Geometries ret; \
138  decomp; \
139  return ret; \
140  } \
141  IMP_REQUIRE_SEMICOLON_NAMESPACE
142 
143 #define IMP_PARTICLE_GEOMETRY(Name, Decorator, action) \
144  /** Display a particle.*/ \
145  class Name##Geometry: public display::SingletonGeometry { \
146  public: \
147  Name##Geometry(Particle* p): display::SingletonGeometry(p){} \
148  Name##Geometry(Decorator d): display::SingletonGeometry(d){} \
149  IMP_IMPLEMENT_INLINE(display::Geometries get_components() const, { \
150  display::Geometries ret; \
151  Decorator d(get_particle()); \
152  action; \
153  return ret; \
154  }); \
155  IMP_OBJECT_METHODS(Name##Geometry); \
156  }; \
157  /** Display multiple particles.*/ \
158  class Name##sGeometry: public display::SingletonsGeometry { \
159  public: \
160  Name##sGeometry(SingletonContainer* sc): display::SingletonsGeometry(sc){} \
161  IMP_IMPLEMENT_INLINE(display::Geometries get_components() const, { \
162  display::Geometries ret; \
163  IMP_FOREACH_SINGLETON(get_container(), { \
164  Decorator d(_1); \
165  action; \
166  }); \
167  return ret; \
168  }); \
169  IMP_OBJECT_METHODS(Name##sGeometry); \
170  }
171 
172 
173 #define IMP_PARTICLE_PAIR_GEOMETRY(Name, Decorator, action) \
174  /** Display a pair of particles.*/ \
175  class Name##Geometry: public display::PairGeometry { \
176  public: \
177  Name##Geometry(const ParticlePair &pp): \
178  display::PairGeometry(pp){} \
179  IMP_IMPLEMENT_INLINE(display::Geometries get_components() const, { \
180  display::Geometries ret; \
181  Decorator d0(get_particle_pair()[0]); \
182  Decorator d1(get_particle_pair()[1]); \
183  action; \
184  return ret; \
185  }) \
186  IMP_OBJECT_METHODS(Name##Geometry); \
187  }; \
188  /** Display multiple pairs of particles.*/ \
189  class Name##sGeometry: public display::PairsGeometry { \
190  public: \
191  Name##sGeometry(PairContainer* sc): display::PairsGeometry(sc){} \
192  IMP_IMPLEMENT_INLINE(display::Geometries get_components() const, { \
193  display::Geometries ret; \
194  IMP_FOREACH_PAIR(get_container(),{ \
195  Decorator d0(_1[0]); \
196  Decorator d1(_1[1]); \
197  action; \
198  }); \
199  return ret; \
200  }); \
201  IMP_OBJECT_METHODS(Name##sGeometry); \
202  }
203 
204 #endif /* IMPDISPLAY_GEOMETRY_MACROS_H */