22#include "ReferenceFrame.h"
24#include "ElementMacros.h"
42 class GenericCompositeModel;
46 struct ElementFactoryMeta;
49 enum PropertyValueType {
57 typedef std::variant<UndefinedProperty, int64_t, Real, bool, std::string> BasePropertyVariant;
61 using BasePropertyVariant::BasePropertyVariant;
63 std::string m_description;
64 std::string m_context;
65 bool m_hidden =
false;
69 setHidden(
bool hidden)
81 setDescription(std::string
const &desc)
87 setContext(std::string
const &ctx)
116 inline PropertyValueType
119 return static_cast<PropertyValueType
>(index());
123 inline operator T()
const
127 return std::get<int64_t>(*
this);
131 return std::get<Real>(*
this);
135 return std::get<bool>(*
this);
142 inline int64_t asInteger()
const {
return std::get<int64_t>(*
this); }
143 inline Real asReal()
const {
return std::get<Real>(*
this); }
144 inline bool asBool()
const {
return std::get<bool>(*
this); }
145 inline std::string asString()
const {
return std::get<std::string>(*
this); }
149 inline PropertyValue::operator bool()
const
155 return std::get<int64_t>(*
this) != 0;
158 return std::get<Real>(*
this) < -0.5
159 || std::get<Real>(*
this) > 0.5;
162 return std::get<bool>(*
this);
165 return val ==
"1" || iequals(val,
"yes") || iequals(val,
"true");
171 class ElementFactory;
174 std::string m_className;
182 std::vector<GLfloat> m_bbLines;
184 std::list<Element *> m_children;
185 std::list<ReferenceFrame *> m_portList;
186 std::map<std::string, ReferenceFrame *> m_nameToPort;
187 std::vector<std::string> m_sortedProperties;
188 std::map<std::string, PropertyValue> m_properties;
191 bool m_selected =
false;
192 bool m_visible =
true;
200 Real m_specRed = .25;
201 Real m_specGreen = .25;
202 Real m_specBlue = .25;
208 void material(std::string
const &role);
209 void refreshProperties();
210 void registerProperty(
213 std::string
const &);
223 registerPort(std::string
const &name, T *frame)
225 auto ret = registerPort(name,
static_cast<ReferenceFrame *
>(frame));
226 return static_cast<T *
>(ret);
229 virtual bool propertyChanged(std::string
const &,
PropertyValue const &);
231 void setBoundingBox(
Vec3 const &p1,
Vec3 const &p2);
232 void updatePropertyValue(std::string
const &,
PropertyValue const &);
243 inline Real red()
const {
return m_red; }
244 inline Real green()
const {
return m_green; }
245 inline Real blue()
const {
return m_blue; }
256 return m_parentModel;
262 m_parentModel = model;
274 hasProperty(std::string
const &prop)
const
276 return m_properties.find(prop) != m_properties.end();
279 inline PropertyValueType
280 queryPropertyType(std::string
const &prop)
const
282 auto it = m_properties.find(prop);
284 if (it == m_properties.end())
285 return UndefinedValue;
287 return it->second.type();
291 propertyIsHidden(std::string
const &prop)
const
293 auto it = m_properties.find(prop);
295 if (it == m_properties.end())
298 return it->second.isHidden();
305 return m_parentFrame;
315 void refreshFrames();
318 std::set<std::string> ports()
const;
321 std::set<std::string> properties()
const;
324 std::vector<std::string> sortedProperties()
const;
331 std::string
const &port,
332 std::string
const &type,
333 std::string
const &name =
"");
339 std::string
const &port,
340 std::string
const &type,
341 std::string
const &name =
"")
343 auto ret = plug(port, type, name);
344 return static_cast<T *
>(ret);
355 get(std::string
const &name)
const
357 return static_cast<T
>(get(name));
361 void setSelected(
bool);
362 void setVisible(
bool);
363 void boundingBox(
Vec3 &p1,
Vec3 &p2)
const;
366 virtual void enterOpenGL();
367 virtual void nativeMaterialOpenGL(std::string
const &role);
368 virtual void renderOpenGL();
370 void calcBoundingBoxOpenGL();
371 void renderBoundingBoxOpenGL();
373 virtual OMModel *nestedModel()
const;
377 Element *lookupElement(std::string
const &name)
const;
378 OpticalElement *lookupOpticalElement(std::string
const &name)
const;
379 Detector *lookupDetector(std::string
const &name)
const;
380 const OpticalPath *lookupOpticalPath(std::string
const &name)
const;
386 std::string description;
387 std::map<std::string, PropertyValue> properties;
388 std::vector<std::string> sortedProperties;
394 std::list<ElementFactoryMeta> m_meta;
398 void enterDecls(std::string
const &, std::string
const &);
402 std::string
const &);
407 std::string
const &);
413 std::string
const &name,
415 Element *parent =
nullptr) = 0;
417 std::string name()
const;
Definition: Detector.h:116
Definition: Element.h:393
Definition: Element.h:173
Definition: GenericCompositeModel.h:120
Definition: OMModel.h:204
Definition: OpticalElement.h:87
Definition: ReferenceFrame.h:59
Definition: OpticalElement.h:54