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 _OnSetPointLocalReference ();
21 void ReleaseCenter (wxSlider *slider);
22 void TrackCenter (double step);
26 void OnSliderTrackX (wxScrollEvent& event);
27 void OnSliderTrackY (wxScrollEvent& event);
28 void OnSliderTrackZ (wxScrollEvent& event);
29 void OnSliderReleaseX (wxScrollEvent& event);
30 void OnSliderReleaseY (wxScrollEvent& event);
31 void OnSliderReleaseZ (wxScrollEvent& event);
34 void OnRadioButtonX(wxEvent& event);
35 void OnRadioButtonY(wxEvent& event);
36 void OnRadioButtonZ(wxEvent& event);
37 void OnRadioButtonN(wxEvent& event);
38 void OnReset(wxCommandEvent& event);
39 void OnMoveDown(wxCommandEvent& event);
40 void OnMoveUp(wxCommandEvent& event);
41 void OnSliderGeneralTrack(wxScrollEvent& event);
42 void OnSliderGeneralRelease(wxScrollEvent& event);
47 std::vector<double> mttActualPoint;
48 std::vector<double> mPossiblePoint;
49 std::vector<double> mLastPossiblePoint_localReference;
50 std::vector<double> mActualPoint;
51 TransformWidget2 *mBox;
54 wxSlider *mSliderRotationX;
55 wxSlider *mSliderRotationY;
56 wxSlider *mSliderRotationZ;
59 wxSlider *mSliderGeneral;
60 wxCheckBox *cbLocalReference;
63 //------------------------------------------------------------------------
64 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
67 TransformWidgetPanel::TransformWidgetPanel(TransformWidget2* box, wxWindow *parent)
68 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
71 t = vtkTransform::New();
72 tt = vtkTransform::New();
73 mttActualPoint.push_back(0);
74 mttActualPoint.push_back(0);
75 mttActualPoint.push_back(0);
77 mActualPoint.push_back(0);
78 mActualPoint.push_back(0);
79 mActualPoint.push_back(0);
81 mPossiblePoint.push_back(0);
82 mPossiblePoint.push_back(0);
83 mPossiblePoint.push_back(0);
85 wxSize sizeSliderWidget;
88 if (mBox->bbGetInputType()==0)
90 sizeSliderWidget.Set(25,25);
91 sizeButton.Set( 45 , -1 );
92 mSliderRotationX = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator );
93 mSliderRotationY = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator );
94 mSliderRotationZ = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator );
95 wxButton *mBtnSetPoint = new wxButton( this, -1, _T("Set Point") , wxDefaultPosition, sizeButton );
96 Connect(mBtnSetPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSetPoint );
97 Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseX );
98 Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX );
99 Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX );
100 Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseY );
101 Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY );
102 Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY );
103 Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseZ );
104 Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ );
105 Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ );
106 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
107 sizer->Add( mSliderRotationX , 1 );
108 sizer->Add( mSliderRotationY , 1 );
109 sizer->Add( mSliderRotationZ , 1 );
110 sizer->Add( mBtnSetPoint , 1 );
114 if (mBox->bbGetInputType()==1)
116 sizeSliderWidget.Set(250,-1 );
117 sizeButton.Set( 45 , -1 );
118 wxRadioButton *rBtnX = new wxRadioButton( this, -1, _T("ri") , wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
119 wxRadioButton *rBtnY = new wxRadioButton( this, -1, _T("rj") , wxDefaultPosition, wxDefaultSize, 0);
120 wxRadioButton *rBtnZ = new wxRadioButton( this, -1, _T("rk") , wxDefaultPosition, wxDefaultSize, 0);
121 wxRadioButton *rBtnC = new wxRadioButton( this, -1, _T("Center") , wxDefaultPosition, wxDefaultSize, 0);
122 rBtnC->SetValue(true); mTool = 3;
123 mSliderGeneral = new wxSlider ( this, -1, 0 , -180, 180, wxDefaultPosition,sizeSliderWidget ,wxSL_HORIZONTAL, wxDefaultValidator );
124 cbLocalReference = new wxCheckBox ( this,-1, _T("Loc Ref"), wxDefaultPosition,wxDefaultSize ,wxCHK_2STATE | wxALIGN_RIGHT );
125 wxButton *mBtnMoveDown = new wxButton ( this, -1, _T("-") , wxDefaultPosition, sizeButton );
126 wxButton *mBtnMoveUp = new wxButton ( this, -1, _T("+") , wxDefaultPosition, sizeButton );
127 wxButton *mBtnReset = new wxButton ( this, -1, _T("Reset") , wxDefaultPosition, sizeButton );
128 Connect( rBtnX->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonX );
129 Connect( rBtnY->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonY );
130 Connect( rBtnZ->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonZ );
131 Connect( rBtnC->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonN );
132 Connect(mBtnReset->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnReset );
133 Connect(mBtnMoveDown->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveDown );
134 Connect(mBtnMoveUp->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveUp );
135 Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralRelease );
136 Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack );
137 Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack );
139 wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
140 sizerA->Add( rBtnC , 1 );
141 sizerA->Add( rBtnX , 1 );
142 sizerA->Add( rBtnY , 1 );
143 sizerA->Add( rBtnZ , 1 );
144 wxBoxSizer *sizerB = new wxBoxSizer(wxHORIZONTAL);
145 sizerB->Add( mSliderGeneral , 0 );
146 wxBoxSizer *sizerC = new wxBoxSizer(wxHORIZONTAL);
147 sizerC->Add( cbLocalReference , 1 );
148 sizerC->Add( mBtnReset , 1 );
149 sizerC->Add( mBtnMoveDown , 1 );
150 sizerC->Add( mBtnMoveUp , 1 );
151 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
152 sizer->Add( sizerA , 0 );
153 sizer->Add( sizerB , 0 );
154 sizer->Add( sizerC , 0 );
161 TransformWidgetPanel::~TransformWidgetPanel()
165 void TransformWidgetPanel::ReleaseAngle( wxSlider * slider )
173 t->Concatenate ( tt->GetMatrix() ); t->Update();
174 tt->GetMatrix()->Identity(); tt->Update();
175 mBox->bbSetOutputOut( t );
176 mBox->bbSignalOutputModification(std::string("Out"));
179 void TransformWidgetPanel::OnSliderReleaseX(wxScrollEvent& event)
181 ReleaseAngle( mSliderRotationX );
184 void TransformWidgetPanel::OnSliderReleaseY(wxScrollEvent& event)
186 ReleaseAngle( mSliderRotationY );
189 void TransformWidgetPanel::OnSliderReleaseZ(wxScrollEvent& event)
191 ReleaseAngle( mSliderRotationZ );
194 void TransformWidgetPanel::TrackAngle( double angle, int idVector)
201 vtkMatrix4x4 *tm = t->GetMatrix();
202 double tvx = tm->GetElement(0,idVector);
203 double tvy = tm->GetElement(1,idVector);
204 double tvz = tm->GetElement(2,idVector);
205 tt = vtkTransform::New();
209 tt->RotateWXYZ( angle , tvx,tvy,tvz); tt->Update();
210 vtkTransform *result=vtkTransform::New();
211 result->PostMultiply();
212 result->Concatenate ( t->GetMatrix() ); result->Update();
213 result->Concatenate ( tt->GetMatrix() ); result->Update();
214 mBox->bbSetOutputOut( result );
215 mBox->bbSignalOutputModification(std::string("Out"));
218 void TransformWidgetPanel::OnSliderTrackX(wxScrollEvent& event)
220 TrackAngle(mSliderRotationX->GetValue() ,0);
223 void TransformWidgetPanel::OnSliderTrackY(wxScrollEvent& event)
225 TrackAngle(mSliderRotationY->GetValue() ,1);
228 void TransformWidgetPanel::OnSliderTrackZ(wxScrollEvent& event)
230 TrackAngle(mSliderRotationZ->GetValue() ,2);
233 void TransformWidgetPanel::SetPossiblePoint(std::vector<double> possiblePoint)
235 mPossiblePoint = possiblePoint;
238 void TransformWidgetPanel::_OnSetPoint()
240 mActualPoint = mPossiblePoint;
241 mLastPossiblePoint_localReference = mPossiblePoint;
242 mBox->bbSetOutputActualPoint( mActualPoint );
243 mBox->bbSignalOutputModification(std::string("ActualPoint"));
246 void TransformWidgetPanel::_OnSetPointLocalReference()
248 mActualPoint = mLastPossiblePoint_localReference;
249 // mLastPossiblePoint = mPossiblePoint;
250 mBox->bbSetOutputActualPoint( mActualPoint );
251 mBox->bbSignalOutputModification(std::string("ActualPoint"));
256 void TransformWidgetPanel::OnSetPoint(wxCommandEvent& event)
261 //------------------------------------------------------------------------
263 void TransformWidgetPanel::OnRadioButtonX(wxEvent& event)
268 void TransformWidgetPanel::OnRadioButtonY(wxEvent& event)
273 void TransformWidgetPanel::OnRadioButtonZ(wxEvent& event)
278 void TransformWidgetPanel::OnRadioButtonN(wxEvent& event)
283 void TransformWidgetPanel::OnReset(wxCommandEvent& event)
285 if ((mTool>=0) && (mTool<=2))
288 if (cbLocalReference->GetValue()==false)
290 tt->GetMatrix()->Identity(); tt->Update();
291 t->GetMatrix()->Identity(); t->Update();
294 ReleaseAngle( NULL );
298 t->RotateWXYZ( 90 , 1,0,0); tt->Update();
299 ReleaseAngle( NULL );
303 t->RotateWXYZ( 90 , 0,1,0); tt->Update();
304 ReleaseAngle( NULL );
307 TrackAngle(45, mTool );
308 ReleaseAngle( NULL );
309 } // if cbLocalReference
312 } // if mTool >=0 <=2
315 if (cbLocalReference->GetValue()==false)
319 _OnSetPointLocalReference();
320 } // if cbLocalReference
326 void TransformWidgetPanel::ReleaseCenter( wxSlider * slider )
332 mActualPoint[0] = mttActualPoint[0];
333 mActualPoint[1] = mttActualPoint[1];
334 mActualPoint[2] = mttActualPoint[2];
337 void TransformWidgetPanel::TrackCenter( double step )
339 vtkMatrix4x4 *tm = t->GetMatrix();
340 mttActualPoint[0] = mActualPoint[0] + tm->GetElement(0,2)*step;
341 mttActualPoint[1] = mActualPoint[1] + tm->GetElement(1,2)*step;
342 mttActualPoint[2] = mActualPoint[2] + tm->GetElement(2,2)*step;
343 mBox->bbSetOutputActualPoint( mttActualPoint );
344 mBox->bbSignalOutputModification(std::string("ActualPoint"));
345 mBox->bbSetOutputOut( t );
346 mBox->bbSignalOutputModification(std::string("Out"));
349 void TransformWidgetPanel::OnMoveDown(wxCommandEvent& event)
351 if ((mTool>=0) && (mTool<=2))
353 TrackAngle( -1 , mTool );
354 ReleaseAngle( NULL );
359 ReleaseCenter( NULL );
363 void TransformWidgetPanel::OnMoveUp(wxCommandEvent& event)
365 if ((mTool>=0) && (mTool<=2))
367 TrackAngle( 1 , mTool );
368 ReleaseAngle( NULL );
369 } // if mTool == 0 1 2
373 ReleaseCenter( NULL );
377 void TransformWidgetPanel::OnSliderGeneralRelease(wxScrollEvent& event)
379 if ((mTool>=0) && (mTool<=2))
381 ReleaseAngle( mSliderGeneral );
382 } // if mTool == 0 1 2
385 ReleaseCenter( mSliderGeneral );
389 void TransformWidgetPanel::OnSliderGeneralTrack(wxScrollEvent& event)
391 if ((mTool>=0) && (mTool<=2))
393 TrackAngle( mSliderGeneral->GetValue() , mTool );
394 } // if mTool == 0 1 2
397 TrackCenter( mSliderGeneral->GetValue() );
402 //------------------------------------------------------------------------
403 //------------------------------------------------------------------------
404 //------------------------------------------------------------------------
406 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransformWidget2)
407 BBTK_BLACK_BOX_IMPLEMENTATION(TransformWidget2,bbtk::WxBlackBox);
409 // 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)
411 void TransformWidget2::Process()
413 TransformWidgetPanel *w = (TransformWidgetPanel*) bbGetOutputWidget( );
414 w->SetPossiblePoint( bbGetInputPossiblePoint() );
423 // 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)
425 void TransformWidget2::CreateWidget(wxWindow* parent)
427 TransformWidgetPanel *w = new TransformWidgetPanel(this,parent);
428 bbSetOutputWidget( w );
432 // 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)
434 void TransformWidget2::bbUserSetDefaultValues()
441 // 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)
443 void TransformWidget2::bbUserInitializeProcessing()
448 // 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)
450 void TransformWidget2::bbUserFinalizeProcessing()
454 }// EO namespace bbcreaMaracasVisu