]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx
65696f6904dc6c60cc190565ed2d6dfd91107c38
[creaRigidRegistration.git] / PackRecalage / src / bbPackRecalageImageSwitcherBox.cxx
1 #include "bbPackRecalageImageSwitcherBox.h"
2 #include "bbPackRecalagePackage.h"
3 namespace bbPackRecalage
4 {
5         MyTimer::MyTimer(ImageSwitcherBox *box): wxTimer()
6         {
7                 _box = box;             
8         }
9
10         MyTimer::~MyTimer()
11         {
12                 //delete this;
13         }
14
15         void MyTimer::Notify()
16         {
17                 //This will be called each time the timer finishes a countdown
18                 _box->Change();
19                 _box->bbSignalOutputModification(std::string("Out")); 
20         }       
21
22 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageSwitcherBox)
23 BBTK_BLACK_BOX_IMPLEMENTATION(ImageSwitcherBox,bbtk::WxBlackBox);
24
25 void ImageSwitcherBox::Change()
26 {
27         //Just changes the images each time the timer finishes a countdown
28         
29         if(change == false)
30         {
31                 bbSetOutputOut(bbGetInputIn2());                
32                 change = true;
33         }
34         else
35         {
36                 bbSetOutputOut(bbGetInputIn1());
37                 change = false;
38         }       
39 }
40
41 void ImageSwitcherBox::Process()
42 {
43         time = bbGetInputTime();
44         _on =  bbGetInputOn();
45
46         if(firstTime == true)
47         {
48                 if(bbGetInputIn1() != NULL)
49                 {
50                         bbSetOutputOut(bbGetInputIn1());
51                         firstTime = false;                      
52                 }
53                 else if(bbGetInputIn2() != NULL)
54                 {
55                         bbSetOutputOut(bbGetInputIn2());
56                         firstTime = false;                      
57                 }
58         }
59                 
60         if(myTimer == NULL)
61         {
62                 myTimer = new MyTimer(this);
63                 myTimer->Start(time);
64                 oldTime = time;
65         }
66         
67         if(!_on)
68         {
69                 myTimer->Stop();
70         }
71         else if(!myTimer->IsRunning())
72         {
73                 myTimer->Start(time);
74                 oldTime = time;
75         }
76         else if(oldTime != time)
77         {
78                 myTimer->Stop();
79                 myTimer->Start(time);
80                 oldTime=time;
81         }
82 }
83 void ImageSwitcherBox::CreateWidget(wxWindow* parent)
84 {
85         //Creates a simple text widget because it is necesary that a non-empty widget exists for creatingh the thread of the timer.
86         bbSetOutputWidget( new wxStaticText(parent, -1, _T("Image Switcher")) );        
87 }
88 void ImageSwitcherBox::bbUserSetDefaultValues()
89 {
90         myTimer = NULL;
91         change = false;
92         time = 500;
93         oldTime = 500;
94         firstTime = true;
95         _on=false;
96 }
97 void ImageSwitcherBox::bbUserInitializeProcessing()
98 {
99
100 }
101 void ImageSwitcherBox::bbUserFinalizeProcessing()
102 {
103         myTimer->Stop();
104         delete myTimer;
105 }
106 }
107 // EO namespace bbPackRecalage
108