2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
4 #include "bbcreaMaracasVisuTransformWidget2.h"
5 #include "bbcreaMaracasVisuPackage.h"
6 namespace bbcreaMaracasVisu
9 // The widget created by the box
10 class TransformWidgetPanel : public wxPanel
13 TransformWidgetPanel(TransformWidget2* box, wxWindow *parent);
14 ~TransformWidgetPanel ();
15 void OnSetPoint (wxCommandEvent& event);
16 void ReleaseAngle (wxSlider *slider);
17 void TrackAngle (double angle ,int idVector);
18 void SetPossiblePoint (std::vector<double> possiblePoint);
20 void ReleaseCenter (wxSlider *slider);
21 void TrackCenter (double step);
25 void OnSliderTrackX (wxScrollEvent& event);
26 void OnSliderTrackY (wxScrollEvent& event);
27 void OnSliderTrackZ (wxScrollEvent& event);
28 void OnSliderReleaseX (wxScrollEvent& event);
29 void OnSliderReleaseY (wxScrollEvent& event);
30 void OnSliderReleaseZ (wxScrollEvent& event);
33 void OnRadioButtonX(wxEvent& event);
34 void OnRadioButtonY(wxEvent& event);
35 void OnRadioButtonZ(wxEvent& event);
36 void OnRadioButtonN(wxEvent& event);
37 void OnReset(wxCommandEvent& event);
38 void OnMoveDown(wxCommandEvent& event);
39 void OnMoveUp(wxCommandEvent& event);
40 void OnSliderGeneralTrack(wxScrollEvent& event);
41 void OnSliderGeneralRelease(wxScrollEvent& event);
46 std::vector<double> mttActualPoint;
47 std::vector<double> mPossiblePoint;
48 std::vector<double> mActualPoint;
49 TransformWidget2 *mBox;
52 wxSlider *mSliderRotationX;
53 wxSlider *mSliderRotationY;
54 wxSlider *mSliderRotationZ;
57 wxSlider *mSliderGeneral;
60 //------------------------------------------------------------------------
61 //------------------------------------------------------------------------
62 //------------------------------------------------------------------------
64 TransformWidgetPanel::TransformWidgetPanel(TransformWidget2* box, wxWindow *parent)
65 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
68 t = vtkTransform::New();
69 tt = vtkTransform::New();
70 mttActualPoint.push_back(0);
71 mttActualPoint.push_back(0);
72 mttActualPoint.push_back(0);
74 mActualPoint.push_back(0);
75 mActualPoint.push_back(0);
76 mActualPoint.push_back(0);
78 mPossiblePoint.push_back(0);
79 mPossiblePoint.push_back(0);
80 mPossiblePoint.push_back(0);
82 wxSize sizeSliderWidget;
85 if (mBox->bbGetInputType()==0)
87 sizeSliderWidget.Set(25,25);
88 sizeButton.Set( 45 , -1 );
89 mSliderRotationX = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator );
90 mSliderRotationY = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator );
91 mSliderRotationZ = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator );
92 wxButton *mBtnSetPoint = new wxButton( this, -1, _T("Set Point") , wxDefaultPosition, sizeButton );
93 Connect(mBtnSetPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSetPoint );
94 Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseX );
95 Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX );
96 Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX );
97 Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseY );
98 Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY );
99 Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY );
100 Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseZ );
101 Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ );
102 Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ );
103 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
104 sizer->Add( mSliderRotationX , 1 );
105 sizer->Add( mSliderRotationY , 1 );
106 sizer->Add( mSliderRotationZ , 1 );
107 sizer->Add( mBtnSetPoint , 1 );
111 if (mBox->bbGetInputType()==1)
113 sizeSliderWidget.Set(250,-1 );
114 sizeButton.Set( 65 , -1 );
115 wxRadioButton *rBtnX = new wxRadioButton( this, -1, _T("ri") , wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
116 wxRadioButton *rBtnY = new wxRadioButton( this, -1, _T("rj") , wxDefaultPosition, wxDefaultSize, 0);
117 wxRadioButton *rBtnZ = new wxRadioButton( this, -1, _T("rk") , wxDefaultPosition, wxDefaultSize, 0);
118 wxRadioButton *rBtnC = new wxRadioButton( this, -1, _T("C.") , wxDefaultPosition, wxDefaultSize, 0);
119 rBtnC->SetValue(true); mTool=3;
120 mSliderGeneral = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator );
121 wxButton *mBtnMoveDown = new wxButton( this, -1, _T("-") , wxDefaultPosition, sizeButton );
122 wxButton *mBtnMoveUp = new wxButton( this, -1, _T("+") , wxDefaultPosition, sizeButton );
123 wxButton *mBtnReset = new wxButton( this, -1, _T("Reset") , wxDefaultPosition, sizeButton );
124 Connect( rBtnX->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonX );
125 Connect( rBtnY->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonY );
126 Connect( rBtnZ->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonZ );
127 Connect( rBtnC->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonN );
128 Connect(mBtnReset->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnReset );
129 Connect(mBtnMoveDown->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveDown );
130 Connect(mBtnMoveUp->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveUp );
131 Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralRelease );
132 Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack );
133 Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack );
136 wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
137 sizerA->Add( rBtnC , 1 );
138 sizerA->Add( rBtnX , 1 );
139 sizerA->Add( rBtnY , 1 );
140 sizerA->Add( rBtnZ , 1 );
141 wxBoxSizer *sizerB = new wxBoxSizer(wxHORIZONTAL);
142 sizerB->Add( mSliderGeneral , 0 );
143 wxBoxSizer *sizerC = new wxBoxSizer(wxHORIZONTAL);
144 sizerC->Add( mBtnReset , 1 );
145 sizerC->Add( mBtnMoveDown , 1 );
146 sizerC->Add( mBtnMoveUp , 1 );
147 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
148 sizer->Add( sizerA , 0 );
149 sizer->Add( sizerB , 0 );
150 sizer->Add( sizerC , 0 );
157 TransformWidgetPanel::~TransformWidgetPanel()
161 void TransformWidgetPanel::ReleaseAngle( wxSlider * slider )
169 t->Concatenate ( tt->GetMatrix() ); t->Update();
170 tt->GetMatrix()->Identity(); tt->Update();
171 mBox->bbSetOutputOut( t );
172 mBox->bbSignalOutputModification(std::string("Out"));
175 void TransformWidgetPanel::OnSliderReleaseX(wxScrollEvent& event)
177 ReleaseAngle( mSliderRotationX );
180 void TransformWidgetPanel::OnSliderReleaseY(wxScrollEvent& event)
182 ReleaseAngle( mSliderRotationY );
185 void TransformWidgetPanel::OnSliderReleaseZ(wxScrollEvent& event)
187 ReleaseAngle( mSliderRotationZ );
190 void TransformWidgetPanel::TrackAngle( double angle, int idVector)
197 vtkMatrix4x4 *tm = t->GetMatrix();
198 double tvx = tm->GetElement(0,idVector);
199 double tvy = tm->GetElement(1,idVector);
200 double tvz = tm->GetElement(2,idVector);
201 tt = vtkTransform::New();
205 tt->RotateWXYZ( angle , tvx,tvy,tvz); tt->Update();
206 vtkTransform *result=vtkTransform::New();
207 result->PostMultiply();
208 result->Concatenate ( t->GetMatrix() ); result->Update();
209 result->Concatenate ( tt->GetMatrix() ); result->Update();
210 mBox->bbSetOutputOut( result );
211 mBox->bbSignalOutputModification(std::string("Out"));
214 void TransformWidgetPanel::OnSliderTrackX(wxScrollEvent& event)
216 TrackAngle(mSliderRotationX->GetValue() ,0);
219 void TransformWidgetPanel::OnSliderTrackY(wxScrollEvent& event)
221 TrackAngle(mSliderRotationY->GetValue() ,1);
224 void TransformWidgetPanel::OnSliderTrackZ(wxScrollEvent& event)
226 TrackAngle(mSliderRotationZ->GetValue() ,2);
229 void TransformWidgetPanel::SetPossiblePoint(std::vector<double> possiblePoint)
231 mPossiblePoint = possiblePoint;
234 void TransformWidgetPanel::_OnSetPoint()
236 mActualPoint = mPossiblePoint;
237 mBox->bbSetOutputActualPoint( mActualPoint );
238 mBox->bbSignalOutputModification(std::string("ActualPoint"));
241 void TransformWidgetPanel::OnSetPoint(wxCommandEvent& event)
246 //------------------------------------------------------------------------
248 void TransformWidgetPanel::OnRadioButtonX(wxEvent& event)
253 void TransformWidgetPanel::OnRadioButtonY(wxEvent& event)
258 void TransformWidgetPanel::OnRadioButtonZ(wxEvent& event)
263 void TransformWidgetPanel::OnRadioButtonN(wxEvent& event)
268 void TransformWidgetPanel::OnReset(wxCommandEvent& event)
270 if ((mTool>=0) && (mTool<=2))
272 tt->GetMatrix()->Identity(); tt->Update();
273 t->GetMatrix()->Identity(); t->Update();
276 ReleaseAngle( NULL );
280 t->RotateWXYZ( 90 , 1,0,0); tt->Update();
281 ReleaseAngle( NULL );
285 t->RotateWXYZ( 90 , 0,1,0); tt->Update();
286 ReleaseAngle( NULL );
288 } // if mTool >=0 <=2
297 void TransformWidgetPanel::ReleaseCenter( wxSlider * slider )
303 mActualPoint[0] = mttActualPoint[0];
304 mActualPoint[1] = mttActualPoint[1];
305 mActualPoint[2] = mttActualPoint[2];
308 void TransformWidgetPanel::TrackCenter( double step )
310 vtkMatrix4x4 *tm = t->GetMatrix();
311 mttActualPoint[0] = mActualPoint[0] + tm->GetElement(0,2)*step;
312 mttActualPoint[1] = mActualPoint[1] + tm->GetElement(1,2)*step;
313 mttActualPoint[2] = mActualPoint[2] + tm->GetElement(2,2)*step;
314 mBox->bbSetOutputActualPoint( mttActualPoint );
315 mBox->bbSignalOutputModification(std::string("ActualPoint"));
316 mBox->bbSetOutputOut( t );
317 mBox->bbSignalOutputModification(std::string("Out"));
320 void TransformWidgetPanel::OnMoveDown(wxCommandEvent& event)
322 if ((mTool>=0) && (mTool<=2))
324 TrackAngle( -1 , mTool );
325 ReleaseAngle( NULL );
330 ReleaseCenter( NULL );
334 void TransformWidgetPanel::OnMoveUp(wxCommandEvent& event)
336 if ((mTool>=0) && (mTool<=2))
338 TrackAngle( 1 , mTool );
339 ReleaseAngle( NULL );
340 } // if mTool == 0 1 2
344 ReleaseCenter( NULL );
348 void TransformWidgetPanel::OnSliderGeneralRelease(wxScrollEvent& event)
350 if ((mTool>=0) && (mTool<=2))
352 ReleaseAngle( mSliderGeneral );
353 } // if mTool == 0 1 2
356 ReleaseCenter( mSliderGeneral );
360 void TransformWidgetPanel::OnSliderGeneralTrack(wxScrollEvent& event)
362 if ((mTool>=0) && (mTool<=2))
364 TrackAngle( mSliderGeneral->GetValue() , mTool );
365 } // if mTool == 0 1 2
368 TrackCenter( mSliderGeneral->GetValue() );
373 //------------------------------------------------------------------------
374 //------------------------------------------------------------------------
375 //------------------------------------------------------------------------
377 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransformWidget2)
378 BBTK_BLACK_BOX_IMPLEMENTATION(TransformWidget2,bbtk::WxBlackBox);
380 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
382 void TransformWidget2::Process()
384 TransformWidgetPanel *w = (TransformWidgetPanel*) bbGetOutputWidget( );
385 w->SetPossiblePoint( bbGetInputPossiblePoint() );
394 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
396 void TransformWidget2::CreateWidget(wxWindow* parent)
398 TransformWidgetPanel *w = new TransformWidgetPanel(this,parent);
399 bbSetOutputWidget( w );
403 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
405 void TransformWidget2::bbUserSetDefaultValues()
412 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
414 void TransformWidget2::bbUserInitializeProcessing()
419 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
421 void TransformWidget2::bbUserFinalizeProcessing()
425 }// EO namespace bbcreaMaracasVisu