10 #include <vtkCallbackCommand.h>
11 #include <vtkCommand.h>
12 #include <vtkObjectFactory.h>
13 #include <vtkPolyLineRepresentation.h>
14 #include <vtkRenderWindowInteractor.h>
22 : KeyEventCallbackCommand(nullptr) {
44 vtkRenderWindowInteractor* iren) {
46 this->Superclass::SetInteractor(iren);
54 if (enabling && this->Interactor) {
66 this->Interactor->AddObserver(vtkCommand::KeyPressEvent,
69 this->Interactor->AddObserver(vtkCommand::KeyReleaseEvent,
76 this->Superclass::SetEnabled(enabling);
84 this->Interactor->RemoveObservers(vtkCommand::KeyPressEvent);
85 this->Interactor->RemoveObservers(vtkCommand::KeyReleaseEvent);
88 this->Interactor->AddObserver(vtkCommand::KeyPressEvent,
90 this->Interactor->AddObserver(vtkCommand::KeyReleaseEvent,
94 if (!enabling && this->Interactor) {
129 if (!self->GetEnabled()) {
136 if (!self->Interactor || !self->WidgetRep) {
140 if (!self->GetProcessEvents()) {
144 vtkPolyLineRepresentation* rep =
145 vtkPolyLineRepresentation::SafeDownCast(self->WidgetRep);
151 char* cKeySym =
nullptr;
153 if (self->Interactor) {
154 cKeySym =
self->Interactor->GetKeySym();
164 std::string keySym = cKeySym;
165 std::transform(keySym.begin(), keySym.end(), keySym.begin(), ::toupper);
169 bool isConstraintKey = (keySym ==
"X" || keySym ==
"Y" || keySym ==
"Z");
170 if (!isConstraintKey) {
175 if (
event == vtkCommand::KeyPressEvent) {
178 rep->SetXTranslationAxisOn();
179 }
else if (keySym ==
"Y") {
181 rep->SetYTranslationAxisOn();
182 }
else if (keySym ==
"Z") {
184 rep->SetZTranslationAxisOn();
186 }
else if (
event == vtkCommand::KeyReleaseEvent) {
187 if (keySym ==
"X" || keySym ==
"Y" || keySym ==
"Z") {
189 rep->SetTranslationAxisOff();