26 #include <vtkXMLDataElement.h>
27 #include <vtkXMLParser.h>
37 class EventConfigXMLParser :
public vtkXMLParser
40 EventConfigXMLParser(EventConfigPrivate *d);
46 void StartElement(
const char *elementName,
const char **atts)
override;
51 void EndElement(
const char *elementName)
override;
53 std::string ReadXMLStringAttribute(
const std::string &name,
const char **atts);
54 bool ReadXMLBooleanAttribute(
const std::string &name,
const char **atts);
57 EventConfigPrivate *
const d;
63 EventConfigPrivate(
const EventConfigPrivate &other);
67 std::string variantName;
71 typedef std::list<EventMapping> EventListType;
77 void InsertMapping(
const EventMapping &mapping);
79 void CopyMapping(
const EventListType);
93 EventMapping m_CurrEventMapping;
98 EventListType m_EventList;
104 EventConfigXMLParser m_XmlParser;
108 mitk::EventConfigPrivate::EventConfigPrivate()
109 : m_PropertyList(PropertyList::
New()), m_EventPropertyList(PropertyList::
New()), m_Errors(false), m_XmlParser(this)
112 m_XmlParser.SetReferenceCount(0);
115 mitk::EventConfigPrivate::EventConfigPrivate(
const EventConfigPrivate &other)
116 :
us::SharedData(other),
117 m_PropertyList(other.m_PropertyList->
Clone()),
118 m_EventPropertyList(other.m_EventPropertyList->
Clone()),
119 m_CurrEventMapping(other.m_CurrEventMapping),
120 m_EventList(other.m_EventList),
121 m_Errors(other.m_Errors),
125 m_XmlParser.SetReferenceCount(0);
128 void mitk::EventConfigPrivate::InsertMapping(
const EventMapping &mapping)
130 for (EventListType::iterator it = m_EventList.begin(); it != m_EventList.end(); ++it)
132 if (*(it->interactionEvent) == *mapping.interactionEvent)
135 m_EventList.erase(it);
139 m_EventList.push_back(mapping);
142 void mitk::EventConfigPrivate::CopyMapping(
const EventListType eventList)
144 EventListType::const_iterator iter;
145 for (iter = eventList.begin(); iter != eventList.end(); ++iter)
147 InsertMapping(*(iter));
151 mitk::EventConfigXMLParser::EventConfigXMLParser(EventConfigPrivate *d) : d(d)
155 void mitk::EventConfigXMLParser::StartElement(
const char *elementName,
const char **atts)
157 std::string name(elementName);
167 d->m_PropertyList->SetStringProperty(name.c_str(), value.c_str());
178 eventVariant.c_str());
179 d->m_CurrEventMapping.variantName = eventVariant;
187 d->m_EventPropertyList->SetStringProperty(name.c_str(), value.c_str());
191 void mitk::EventConfigXMLParser::EndElement(
const char *elementName)
193 const std::string name(elementName);
198 if (event.IsNotNull())
200 d->m_CurrEventMapping.interactionEvent = event;
201 d->InsertMapping(d->m_CurrEventMapping);
205 MITK_WARN <<
"EventConfig: Unknown Event-Type in config. Entry skipped: " << name;
210 std::string mitk::EventConfigXMLParser::ReadXMLStringAttribute(
const std::string &name,
const char **atts)
214 const char **attsIter = atts;
218 if (name == *attsIter)
226 return std::string();
229 bool mitk::EventConfigXMLParser::ReadXMLBooleanAttribute(
const std::string &name,
const char **atts)
231 std::string s = ReadXMLStringAttribute(name, atts);
232 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
254 MITK_ERROR <<
"Resource not valid. State machine pattern in module " << module->
GetName()
255 <<
" not found: /Interactions/" <<
filename;
261 newConfig.d->m_XmlParser.SetStream(&stream);
262 bool success = newConfig.d->m_XmlParser.Parse() && !newConfig.d->m_Errors;
272 newConfig.d->m_XmlParser.SetStream(&inputStream);
273 bool success = newConfig.d->m_XmlParser.Parse() && !newConfig.d->m_Errors;
282 std::vector<PropertyList::Pointer>::const_iterator it_end = configDescription.end();
283 for (std::vector<PropertyList::Pointer>::const_iterator it = configDescription.begin(); it != it_end; ++it)
285 std::string typeVariant;
287 if (typeVariant !=
"")
290 if (event.IsNotNull())
292 d->m_CurrEventMapping.interactionEvent = event;
293 std::string eventVariant;
295 d->m_CurrEventMapping.variantName = eventVariant;
296 d->InsertMapping(d->m_CurrEventMapping);
300 MITK_WARN <<
"EventConfig: Unknown Event-Type in config. When constructing from PropertyList.";
306 if (typeVariant !=
"")
308 std::string name, value;
311 d->m_PropertyList->SetStringProperty(name.c_str(), value.c_str());
329 return !(d->m_EventList.empty() && d->m_PropertyList->IsEmpty());
341 MITK_ERROR <<
"Resource not valid. State machine pattern in module " << module->
GetName()
342 <<
" not found: /Interactions/" << fileName;
348 newConfig.d->m_XmlParser.SetStream(&stream);
349 bool success = newConfig.d->m_XmlParser.Parse() && !newConfig.d->m_Errors;
362 d->m_PropertyList->ConcatenatePropertyList(config.d->m_PropertyList->
Clone(),
true);
363 d->m_EventPropertyList = config.d->m_EventPropertyList->
Clone();
364 d->m_CurrEventMapping = config.d->m_CurrEventMapping;
365 d->CopyMapping(config.d->m_EventList);
372 return d->m_PropertyList;
378 if (std::strcmp(interactionEvent->GetNameOfClass(),
"InternalEvent") == 0)
384 for (EventConfigPrivate::EventListType::const_iterator it = d->m_EventList.begin(); it != d->m_EventList.end(); ++it)
386 if (*(it->interactionEvent) == *interactionEvent)
388 return (*it).variantName;
394 if (std::strcmp(interactionEvent->GetNameOfClass(),
"InteractionKeyEvent") == 0)
397 return (
"Std" + keyEvent->
GetKey());
404 d->m_PropertyList->Clear();
405 d->m_EventPropertyList->Clear();
406 d->m_CurrEventMapping.variantName.clear();
407 d->m_CurrEventMapping.interactionEvent = NULL;
408 d->m_EventList.clear();
static const std::string xmlParameterName()
itk::SmartPointer< Self > Pointer
void ClearConfig()
Reset this EventConfig object, rendering it invalid.
std::string GetName() const
itk::SmartPointer< const Self > ConstPointer
static const std::string xmlParameterValue()
EventConfig()
Constructs an invalid EventConfig object.
static const std::string xmlTagConfigRoot()
static const std::string xmlTagParam()
DataCollection - Class to facilitate loading/accessing structured data.
Class to create events from within the application to signal about internal events.
PropertyList::Pointer GetAttributes() const
EventConfig & operator=(const EventConfig &other)
static const std::string xmlParameterEventClass()
static InteractionEvent::Pointer CreateEvent(PropertyList::Pointer eventDescription)
std::string GetSignalName() const
bool AddConfig(const std::string &filename, const us::Module *module=nullptr)
This method extends this configuration.
static const std::string xmlParameterEventVariant()
std::string GetMappedEvent(const EventType &interactionEvent) const
Module * GetModule() const
static const std::string filename
bool IsValid() const
Checks wether this EventConfig object is valid.
static const std::string xmlTagEventVariant()
Handles key events. Takes a std::string for pressed key or special key description, mitk::ModifierKeys for modifiers
Configuration Object for Statemachines.
itk::SmartPointer< Self > Pointer
ModuleResource GetResource(const std::string &path) const
std::string GetKey() const
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
static const std::string xmlTagAttribute()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.