]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx
#3545 Save Load in TransformWidget2 box
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuTransformWidget2.cxx
1 //===== 
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)
3 //===== 
4 #include "bbcreaMaracasVisuTransformWidget2.h"
5 #include "bbcreaMaracasVisuPackage.h"
6
7 #include <wx/filedlg.h>
8
9 namespace bbcreaMaracasVisu
10 {
11
12 // The widget created by the box
13 class TransformWidgetPanel : public wxPanel
14 {
15 public:
16     TransformWidgetPanel(TransformWidget2* box, wxWindow *parent);
17     ~TransformWidgetPanel           ();
18     void OnSetPoint                 (wxCommandEvent& event);
19     void ReleaseAngle               (wxSlider *slider);
20     void TrackAngle                 (double angle ,int idVector);
21     void SetPossiblePoint           (std::vector<double> possiblePoint);
22     void _OnSetPoint                ();
23     void _OnSetPointLocalReference  ();
24     void ReleaseCenter              (wxSlider *slider);
25     void TrackCenter                (double step);
26
27     
28     // Type : Module A
29     void OnSliderTrackX     (wxScrollEvent& event);
30     void OnSliderTrackY     (wxScrollEvent& event);
31     void OnSliderTrackZ     (wxScrollEvent& event);
32     void OnSliderReleaseX   (wxScrollEvent& event);
33     void OnSliderReleaseY   (wxScrollEvent& event);
34     void OnSliderReleaseZ   (wxScrollEvent& event);
35     
36     // Type : Module B
37     void OnRadioButtonX(wxEvent& event);
38     void OnRadioButtonY(wxEvent& event);
39     void OnRadioButtonZ(wxEvent& event);
40     void OnRadioButtonN(wxEvent& event);
41     void OnSave(wxCommandEvent& event);
42     void OnLoad(wxCommandEvent& event);
43     void OnReset(wxCommandEvent& event);
44     void OnMoveDown(wxCommandEvent& event);
45     void OnMoveUp(wxCommandEvent& event);
46     void OnMemory(wxCommandEvent& event);
47     void OnMemoryGoBack(wxCommandEvent& event);
48     void OnSliderGeneralTrack(wxScrollEvent& event);
49     void OnSliderGeneralRelease(wxScrollEvent& event);
50     
51 private:
52     vtkTransform            *t;
53     vtkTransform            *tt;
54     std::vector<double>     mttActualPoint;
55     std::vector<double>     mPossiblePoint;
56     std::vector<double>     mLastPossiblePoint_localReference;
57     std::vector<double>     mActualPoint;
58     std::vector<double>     mMemoryPoint;
59     vtkMatrix4x4            *mMemoryMatrix;
60     TransformWidget2        *mBox;
61     
62     // Type : Module A
63     wxSlider                *mSliderRotationX;
64     wxSlider                *mSliderRotationY;
65     wxSlider                *mSliderRotationZ;
66     // Type : Module B
67     char                    mTool;
68     wxSlider                *mSliderGeneral;
69     wxCheckBox              *cbLocalReference;
70 };
71
72 //------------------------------------------------------------------------
73 //------------------------------------------------------------------------
74 //------------------------------------------------------------------------
75
76 TransformWidgetPanel::TransformWidgetPanel(TransformWidget2* box, wxWindow *parent)
77   : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
78   mBox(box)
79 {
80     t                       = vtkTransform::New();   // Transoform activa
81     tt                      = vtkTransform::New();   // Transform temporal para el slider
82     mMemoryMatrix           = vtkMatrix4x4::New();
83     mttActualPoint.push_back(0);
84     mttActualPoint.push_back(0);
85     mttActualPoint.push_back(0);
86     
87     mActualPoint.push_back(0);
88     mActualPoint.push_back(0);
89     mActualPoint.push_back(0);
90
91     mPossiblePoint.push_back(0);
92     mPossiblePoint.push_back(0);
93     mPossiblePoint.push_back(0);
94
95     wxSize  sizeSliderWidget;
96     wxSize sizeButton;
97     
98     if (mBox->bbGetInputType()==0)
99     {
100         sizeSliderWidget.Set(25,25);
101         sizeButton.Set( 45 , -1 );
102         mSliderRotationX        = new wxSlider( this, -1, 0 , -180, 180     , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator                           );
103         mSliderRotationY        = new wxSlider( this, -1, 0 , -180, 180     , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator                           );
104         mSliderRotationZ        = new wxSlider( this, -1, 0 , -180, 180     , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator                           );
105         wxButton *mBtnSetPoint  = new wxButton( this, -1, _T("Set Point")   , wxDefaultPosition, sizeButton                                                                     );
106         Connect(mBtnSetPoint->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED    , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSetPoint      );
107         Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBRELEASE       , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseX);
108         Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBTRACK         , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX  );
109         Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_CHANGED            , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX  );
110         Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBRELEASE       , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseY);
111         Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBTRACK         , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY  );
112         Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_CHANGED            , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY  );
113         Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBRELEASE       , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseZ);
114         Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBTRACK         , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ  );
115         Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_CHANGED            , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ  );
116         wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
117         sizer->Add( mSliderRotationX    , 1 );
118         sizer->Add( mSliderRotationY    , 1 );
119         sizer->Add( mSliderRotationZ    , 1 );
120         sizer->Add( mBtnSetPoint        , 1 );
121         SetSizer(sizer);
122     } // if Type == 0
123     
124     if (mBox->bbGetInputType()==1)
125     {
126         sizeSliderWidget.Set( 160 , -1  );
127         sizeButton.Set( 15 , -1 );
128         wxRadioButton *rBtnC     = new wxRadioButton( this, -1, _T("Cen")        , wxDefaultPosition  , wxDefaultSize , wxRB_GROUP      );
129         wxRadioButton *rBtnX     = new wxRadioButton( this, -1, _T("ri")         , wxDefaultPosition  , wxDefaultSize , 0               );
130         wxRadioButton *rBtnY     = new wxRadioButton( this, -1, _T("rj")         , wxDefaultPosition  , wxDefaultSize , 0               );
131         wxRadioButton *rBtnZ     = new wxRadioButton( this, -1, _T("rk")         , wxDefaultPosition  , wxDefaultSize , 0               );
132         wxButton *BtnSave        = new wxButton     ( this, -1, _T("Save")       , wxDefaultPosition, sizeButton                                                                            );
133         wxButton *BtnLoad        = new wxButton     ( this, -1, _T("Load")       , wxDefaultPosition, sizeButton                                                                            );
134         rBtnC->SetValue(true);        mTool = 3;
135         mSliderGeneral           = new wxSlider     ( this, -1, 0 , -180, 180    , wxDefaultPosition,sizeSliderWidget ,wxSL_HORIZONTAL, wxDefaultValidator                                  );
136         cbLocalReference         = new wxCheckBox   ( this,-1, _T("Loc Ref")     , wxDefaultPosition,wxDefaultSize    ,wxCHK_2STATE | wxALIGN_RIGHT                                         );
137         wxButton *BtnMoveDown    = new wxButton     ( this, -1, _T("-")          , wxDefaultPosition, sizeButton                                                                            );
138         wxButton *BtnMoveUp      = new wxButton     ( this, -1, _T("+")          , wxDefaultPosition, sizeButton                                                                            );
139         wxButton *BtnReset       = new wxButton     ( this, -1, _T("Init")       , wxDefaultPosition, sizeButton                                                                            );
140         wxButton *BtnMemory      = new wxButton     ( this, -1, _T("Set")        , wxDefaultPosition, sizeButton                                                                            );
141         wxButton *BtnMemoryGoBack= new wxButton     ( this, -1, _T("Reset")      , wxDefaultPosition, sizeButton                                                                            );
142         Connect( rBtnX->GetId()          , wxEVT_COMMAND_RADIOBUTTON_SELECTED    , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonX               );
143         Connect( rBtnY->GetId()          , wxEVT_COMMAND_RADIOBUTTON_SELECTED    , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonY               );
144         Connect( rBtnZ->GetId()          , wxEVT_COMMAND_RADIOBUTTON_SELECTED    , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonZ               );
145         Connect( rBtnC->GetId()          , wxEVT_COMMAND_RADIOBUTTON_SELECTED    , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonN               );
146         Connect( BtnSave->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnSave                       );
147         Connect( BtnLoad->GetId()        , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction)(void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnLoad                       );
148         Connect( BtnReset->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnReset                );
149         Connect( BtnMoveDown->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveDown             );
150         Connect( BtnMoveUp->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveUp               );
151         Connect( BtnMemory->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMemory               );
152         Connect( BtnMemoryGoBack->GetId(), wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMemoryGoBack         );
153         Connect( mSliderGeneral->GetId() , wxEVT_SCROLL_THUMBRELEASE             , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralRelease );
154         Connect( mSliderGeneral->GetId() , wxEVT_SCROLL_THUMBTRACK               , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack   );
155         Connect( mSliderGeneral->GetId() , wxEVT_SCROLL_CHANGED                  , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack   );
156         
157         wxBoxSizer *sizerA1 = new wxBoxSizer(wxHORIZONTAL);
158         sizerA1->Add( rBtnC              , 1 );
159         sizerA1->Add( rBtnX              , 1 );
160         sizerA1->Add( rBtnY              , 1 );
161         sizerA1->Add( rBtnZ              , 1 );
162         wxBoxSizer *sizerA2 = new wxBoxSizer(wxHORIZONTAL);
163         sizerA2->Add( BtnSave            , 1 );
164         sizerA2->Add( BtnLoad            , 1 );
165         wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
166         sizerA->Add( sizerA1            , 1 );
167         sizerA->Add( sizerA2            , 1 );
168
169         wxBoxSizer *sizerB = new wxBoxSizer(wxHORIZONTAL);
170         sizerB->Add( mSliderGeneral     , 1 );
171         sizerB->Add( BtnMoveDown        , 0 );
172         sizerB->Add( BtnMoveUp          , 0 );
173         wxBoxSizer *sizerC = new wxBoxSizer(wxHORIZONTAL);
174         sizerC->Add( cbLocalReference   , 1 );
175         sizerC->Add( BtnReset           , 1 );
176         sizerC->Add( BtnMemory          , 1 );
177         sizerC->Add( BtnMemoryGoBack    , 1 );
178         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
179         sizer->Add( sizerA              , 0 );
180         sizer->Add( sizerB              , 0 );
181         sizer->Add( sizerC              , 0 );
182         SetSizer(sizer);
183     } // if
184 }
185
186 TransformWidgetPanel::~TransformWidgetPanel()
187 {
188 }
189
190 void TransformWidgetPanel::ReleaseAngle( wxSlider * slider )
191 {
192     if (slider!=NULL)
193     {
194         slider->SetValue(0);
195     }
196     // t = t*tt
197     t->PostMultiply();
198     t->Concatenate ( tt->GetMatrix() );    t->Update();
199     tt->GetMatrix()->Identity();  tt->Update();
200     mBox->bbSetOutputOut( t );
201     mBox->bbSignalOutputModification(std::string("Out"));
202 }
203
204 void TransformWidgetPanel::OnSliderReleaseX(wxScrollEvent& event)
205 {
206     ReleaseAngle( mSliderRotationX );
207 }
208
209 void TransformWidgetPanel::OnSliderReleaseY(wxScrollEvent& event)
210 {
211     ReleaseAngle( mSliderRotationY );
212 }
213
214 void TransformWidgetPanel::OnSliderReleaseZ(wxScrollEvent& event)
215 {
216     ReleaseAngle( mSliderRotationZ );
217 }
218
219 void TransformWidgetPanel::TrackAngle( double angle, int idVector)
220 {
221     // out = t*tt
222     if (tt!=NULL)
223     {
224         tt->Delete();
225     }
226     vtkMatrix4x4    *tm     = t->GetMatrix();
227     double          tvx    = tm->GetElement(0,idVector);
228     double          tvy    = tm->GetElement(1,idVector);
229     double          tvz    = tm->GetElement(2,idVector);
230     tt = vtkTransform::New();
231     tt->PostMultiply();
232
233 //    angle = angle/2;
234     tt->RotateWXYZ( angle , tvx,tvy,tvz);  tt->Update();
235     vtkTransform *result=vtkTransform::New();
236     result->PostMultiply();
237     result->Concatenate ( t->GetMatrix() );    result->Update();
238     result->Concatenate ( tt->GetMatrix() );   result->Update();
239     mBox->bbSetOutputOut( result );
240     mBox->bbSignalOutputModification(std::string("Out"));
241 }
242
243 void TransformWidgetPanel::OnSliderTrackX(wxScrollEvent& event)
244 {
245     TrackAngle(mSliderRotationX->GetValue() ,0);
246 }
247
248 void TransformWidgetPanel::OnSliderTrackY(wxScrollEvent& event)
249 {
250     TrackAngle(mSliderRotationY->GetValue() ,1);
251 }
252
253 void TransformWidgetPanel::OnSliderTrackZ(wxScrollEvent& event)
254 {
255     TrackAngle(mSliderRotationZ->GetValue() ,2);
256 }
257
258 void TransformWidgetPanel::SetPossiblePoint(std::vector<double> possiblePoint)
259 {
260     mPossiblePoint = possiblePoint;
261 }
262
263 void TransformWidgetPanel::_OnSetPoint()
264 {
265     mActualPoint                        = mPossiblePoint;
266     mLastPossiblePoint_localReference   = mPossiblePoint;
267     mBox->bbSetOutputActualPoint( mActualPoint );
268     mBox->bbSignalOutputModification(std::string("ActualPoint"));
269 }
270
271 void TransformWidgetPanel::_OnSetPointLocalReference()
272 {
273     mActualPoint        = mLastPossiblePoint_localReference;
274 //    mLastPossiblePoint  = mPossiblePoint;
275     mBox->bbSetOutputActualPoint( mActualPoint );
276     mBox->bbSignalOutputModification(std::string("ActualPoint"));
277 }
278
279
280
281 void TransformWidgetPanel::OnSetPoint(wxCommandEvent& event)
282 {
283     _OnSetPoint();
284 }
285
286 //------------------------------------------------------------------------
287
288 void TransformWidgetPanel::OnRadioButtonX(wxEvent& event)
289 {
290     mTool = 0;
291 }
292
293 void TransformWidgetPanel::OnRadioButtonY(wxEvent& event)
294 {
295     mTool = 1;
296 }
297
298 void TransformWidgetPanel::OnRadioButtonZ(wxEvent& event)
299 {
300     mTool = 2;
301 }
302
303 void TransformWidgetPanel::OnRadioButtonN(wxEvent& event)
304 {
305     mTool = 3;
306 }
307
308 void TransformWidgetPanel::OnReset(wxCommandEvent& event)
309 {
310     if ((mTool>=0) && (mTool<=2))
311     {
312         
313         if (cbLocalReference->GetValue()==false)
314         {
315             tt->GetMatrix()->Identity(); tt->Update();
316             t->GetMatrix()->Identity();  t->Update();
317             if (mTool==0)
318             {
319                 ReleaseAngle( NULL );
320             } // if
321             if (mTool==1)
322             {
323                 t->RotateWXYZ( 90 , 1,0,0);  tt->Update();
324                 ReleaseAngle( NULL );
325             } // if
326             if (mTool==2)
327             {
328                 t->RotateWXYZ( 90 , 0,1,0);  tt->Update();
329                 ReleaseAngle( NULL );
330             } // if
331         } else {
332             TrackAngle(45, mTool );
333             ReleaseAngle( NULL );
334         } // if cbLocalReference
335
336         
337     } // if mTool >=0   <=2
338     if (mTool==3)
339     {
340         if (cbLocalReference->GetValue()==false)
341         {
342             _OnSetPoint();
343         } else {
344             _OnSetPointLocalReference();
345         } // if cbLocalReference
346     } // if mTool == 3
347 }
348
349
350
351 void TransformWidgetPanel::ReleaseCenter( wxSlider * slider )
352 {
353     if (slider!=NULL)
354     {
355         slider->SetValue(0);
356     }
357     mActualPoint[0] = mttActualPoint[0];
358     mActualPoint[1] = mttActualPoint[1];
359     mActualPoint[2] = mttActualPoint[2];
360 }
361
362 void TransformWidgetPanel::TrackCenter( double step )
363 {
364     vtkMatrix4x4    *tm     = t->GetMatrix();
365     mttActualPoint[0]       = mActualPoint[0] + tm->GetElement(0,2)*step;
366     mttActualPoint[1]       = mActualPoint[1] + tm->GetElement(1,2)*step;
367     mttActualPoint[2]       = mActualPoint[2] + tm->GetElement(2,2)*step;
368     mBox->bbSetOutputActualPoint( mttActualPoint );
369     mBox->bbSignalOutputModification(std::string("ActualPoint"));
370     mBox->bbSetOutputOut( t );
371     mBox->bbSignalOutputModification(std::string("Out"));
372 }
373
374 void TransformWidgetPanel::OnMoveDown(wxCommandEvent& event)
375 {
376     if ((mTool>=0) && (mTool<=2))
377     {
378         TrackAngle( -1 , mTool );
379         ReleaseAngle( NULL );
380     }
381     if (mTool==3)
382     {
383         TrackCenter( -1 );
384         ReleaseCenter( NULL );
385     } // if mTool == 3
386 }
387
388 void TransformWidgetPanel::OnMoveUp(wxCommandEvent& event)
389 {
390     if ((mTool>=0) && (mTool<=2))
391     {
392         TrackAngle( 1 , mTool );
393         ReleaseAngle( NULL );
394     } // if mTool == 0 1 2
395     if (mTool==3)
396     {
397         TrackCenter( 1 );
398         ReleaseCenter( NULL );
399     } // if mTool == 3
400 }
401
402 void TransformWidgetPanel::OnMemory(wxCommandEvent& event)
403 {
404     mMemoryPoint            = mActualPoint;
405     mMemoryMatrix->DeepCopy( t->GetMatrix() );
406 }
407
408 void TransformWidgetPanel::OnSave(wxCommandEvent& event)
409 {
410     wxFileDialog* FD = new wxFileDialog( 0,
411                                         _T("Save free plane configuratin"),
412                                         _T(""),
413                                         _T(""),
414                                         _T("(*.fpConf)|*.fpConf"),
415                                         wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
416                                         wxDefaultPosition);
417
418     int result_FD = FD->ShowModal();
419     // This line is need it by windows //EED
420     FD->SetReturnCode( result_FD );
421     if (FD->GetReturnCode()==wxID_OK)
422     {
423         std::string filename= (const char*) ( FD->GetPath().mb_str() );
424         FILE *ff;
425         ff = fopen( filename.c_str() , "w+" );
426         if (ff!=NULL)
427         {
428             fprintf(ff,"ActualPoint:\n");
429             fprintf(ff,"%f  %f  %f\n",mActualPoint[0], mActualPoint[1], mActualPoint[2] );
430             vtkMatrix4x4 *m = t->GetMatrix();
431             fprintf(ff,"Transform:\n");
432             fprintf(ff,"%f  %f  %f  %f  \n",m->GetElement(0,0), m->GetElement(1,0), m->GetElement(2,0), m->GetElement(3,0) );
433             fprintf(ff,"%f  %f  %f  %f  \n",m->GetElement(0,1), m->GetElement(1,1), m->GetElement(2,1), m->GetElement(3,1) );
434             fprintf(ff,"%f  %f  %f  %f  \n",m->GetElement(0,2), m->GetElement(1,2), m->GetElement(2,2), m->GetElement(3,2) );
435             fprintf(ff,"%f  %f  %f  %f\n\n",m->GetElement(0,3), m->GetElement(1,3), m->GetElement(2,3), m->GetElement(3,3) );
436             fclose(ff);
437         } else {   // else ff
438             printf("TransformWidgetPanel::OnSave  ...Error... creating file \n");
439         } //ff
440     }     // dialog box
441 }
442
443 void TransformWidgetPanel::OnLoad(wxCommandEvent& event)
444 {
445     wxFileDialog* FD = new wxFileDialog( 0,
446                                          _T("Load groups of points .."),
447                                          _T(""),
448                                          _T(""),
449                                          _T("(*.fpConf)|*.fpConf"),
450                                          wxFD_OPEN | wxFD_FILE_MUST_EXIST,
451                                          wxDefaultPosition);
452
453     int result_FD = FD->ShowModal();
454     // This line is need it by windows //EED
455     FD->SetReturnCode( result_FD );
456     if (FD->GetReturnCode()==wxID_OK)
457     {
458         std::string filename= (const char*) ( FD->GetPath().mb_str() );
459         FILE *ff;
460         ff = fopen( filename.c_str() , "r" );
461         if (ff!=NULL)
462         {
463             char tmpStr[128];
464             float t0,t1,t2,t3;
465             fscanf(ff,"%s\n",tmpStr);  // ActualPoint:
466             fscanf(ff,"%f  %f  %f\n",&t0,&t1,&t2);
467             mActualPoint[0]=t0;
468             mActualPoint[1]=t1;
469             mActualPoint[2]=t2;
470
471             vtkMatrix4x4 *m = t->GetMatrix();
472             fscanf(ff,"%s\n",tmpStr); // Transform:
473             fscanf(ff,"%f %f  %f %f\n",&t0,&t1,&t2,&t3);
474             m->SetElement(0,0,t0);
475             m->SetElement(1,0,t1);
476             m->SetElement(2,0,t2);
477             m->SetElement(3,0,t3);
478             fscanf(ff,"%f %f  %f %f\n",&t0,&t1,&t2,&t3);
479             m->SetElement(0,1,t0);
480             m->SetElement(1,1,t1);
481             m->SetElement(2,1,t2);
482             m->SetElement(3,1,t3);
483             fscanf(ff,"%f %f  %f %f\n",&t0,&t1,&t2,&t3);
484             m->SetElement(0,2,t0);
485             m->SetElement(1,2,t1);
486             m->SetElement(2,2,t2);
487             m->SetElement(3,2,t3);
488             fscanf(ff,"%f %f  %f %f\n",&t0,&t1,&t2,&t3);
489             m->SetElement(0,3,t0);
490             m->SetElement(1,3,t1);
491             m->SetElement(2,3,t2);
492             m->SetElement(3,3,t3);
493             t->Update();
494
495             mBox->bbSetOutputActualPoint( mActualPoint );
496             mBox->bbSignalOutputModification(std::string("ActualPoint"));
497             mBox->bbSetOutputOut( t );
498             mBox->bbSignalOutputModification(std::string("Out"));
499
500             fclose(ff);
501         } else {   // else ff
502             printf("TransformWidgetPanel::OnLoad  ...Error... reading file \n");
503         } //ff
504     }     // dialog box
505
506 }
507
508
509 void TransformWidgetPanel::OnMemoryGoBack(wxCommandEvent& event)
510 {
511     mActualPoint = mMemoryPoint;
512     t->GetMatrix()->Identity();
513     vtkMatrix4x4 *m = vtkMatrix4x4::New();
514     m->DeepCopy( mMemoryMatrix );
515     t->SetMatrix( m );
516     mBox->bbSetOutputActualPoint( mActualPoint );
517     mBox->bbSignalOutputModification(std::string("ActualPoint"));
518     mBox->bbSetOutputOut( t );
519     mBox->bbSignalOutputModification(std::string("Out"));
520 }
521
522
523
524 void TransformWidgetPanel::OnSliderGeneralRelease(wxScrollEvent& event)
525 {
526     if ((mTool>=0) && (mTool<=2))
527     {
528         ReleaseAngle( mSliderGeneral );
529     } // if mTool == 0 1 2
530     if (mTool==3)
531     {
532         ReleaseCenter( mSliderGeneral );
533     } // if mTool == 3
534 }
535
536 void TransformWidgetPanel::OnSliderGeneralTrack(wxScrollEvent& event)
537 {
538     if ((mTool>=0) && (mTool<=2))
539     {
540         TrackAngle( mSliderGeneral->GetValue() , mTool );
541     }  // if mTool == 0 1 2
542     if (mTool==3)
543     {
544         TrackCenter( mSliderGeneral->GetValue() );
545     } // if mTool == 3
546 }
547
548
549 //------------------------------------------------------------------------
550 //------------------------------------------------------------------------
551 //------------------------------------------------------------------------
552
553 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransformWidget2)
554 BBTK_BLACK_BOX_IMPLEMENTATION(TransformWidget2,bbtk::WxBlackBox);
555 //===== 
556 // 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)
557 //===== 
558 void TransformWidget2::Process()
559 {
560     TransformWidgetPanel *w = (TransformWidgetPanel*) bbGetOutputWidget( );
561     w->SetPossiblePoint( bbGetInputPossiblePoint() );
562     if (firsttime==true)
563     {
564         firsttime=false;
565         w->_OnSetPoint();
566     }// if
567 }
568
569 //===== 
570 // 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)
571 //===== 
572 void TransformWidget2::CreateWidget(wxWindow* parent)
573 {
574    TransformWidgetPanel *w =  new TransformWidgetPanel(this,parent);
575    bbSetOutputWidget( w );
576 }
577
578 //===== 
579 // 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)
580 //===== 
581 void TransformWidget2::bbUserSetDefaultValues()
582 {
583     firsttime=true;
584     bbSetInputType(1);
585 }
586
587 //===== 
588 // 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)
589 //===== 
590 void TransformWidget2::bbUserInitializeProcessing()
591 {
592 }
593
594 //===== 
595 // 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)
596 //===== 
597 void TransformWidget2::bbUserFinalizeProcessing()
598 {
599 }
600
601 }// EO namespace bbcreaMaracasVisu
602
603