]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx
99c0a643b7227e955671a6fec333048642923f64
[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                 _box->Change();
18                 _box->bbSignalOutputModification(std::string("Out")); 
19         }       
20
21 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageSwitcherBox)
22 BBTK_BLACK_BOX_IMPLEMENTATION(ImageSwitcherBox,bbtk::WxBlackBox);
23
24 void ImageSwitcherBox::Change()
25 {
26         if(change == false)
27         {
28                 bbSetOutputOut(bbGetInputIn2());                
29                 change = true;
30         }
31         else
32         {
33                 bbSetOutputOut(bbGetInputIn1());
34                 change = false;
35         }       
36 }
37
38 void ImageSwitcherBox::Process()
39 {
40         time = bbGetInputTime();
41         _on =  bbGetInputOn();
42
43         if(firstTime == true)
44         {
45                 if(bbGetInputIn1() != NULL)
46                 {
47                         bbSetOutputOut(bbGetInputIn1());
48                         firstTime = false;                      
49                 }
50                 else if(bbGetInputIn2() != NULL)
51                 {
52                         bbSetOutputOut(bbGetInputIn2());
53                         firstTime = false;                      
54                 }
55         }
56                 
57         if(myTimer == NULL)
58         {
59                 myTimer = new MyTimer(this);
60                 myTimer->Start(time);
61                 oldTime = time;
62         }
63         /*
64         if(oldTime != time && myTimer !=NULL)
65         {
66                 myTimer->Stop();
67                 myTimer->Start(time);
68                 oldTime = time;
69         }*/
70
71         if(!_on)
72         {
73                 myTimer->Stop();
74         }
75         else if(!myTimer->IsRunning())
76         {
77                 myTimer->Start(time);
78                 oldTime = time;
79         }
80         else if(oldTime != time)
81         {
82                 myTimer->Stop();
83                 myTimer->Start(time);
84                 oldTime=time;
85         }
86 }
87 void ImageSwitcherBox::CreateWidget(wxWindow* parent)
88 {
89         bbSetOutputWidget( new wxStaticText(parent, -1, _T("Image Switcher")) );        
90 }
91 void ImageSwitcherBox::bbUserSetDefaultValues()
92 {
93         myTimer = NULL;
94         change = false;
95         time = 500;
96         oldTime = 500;
97         firstTime = true;
98         _on=false;
99 }
100 void ImageSwitcherBox::bbUserInitializeProcessing()
101 {
102
103 }
104 void ImageSwitcherBox::bbUserFinalizeProcessing()
105 {
106         myTimer->Stop();
107         delete myTimer;
108 }
109 }
110 // EO namespace bbPackRecalage
111