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