]> Creatis software - creaRigidRegistration.git/blobdiff - PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx
*** empty log message ***
[creaRigidRegistration.git] / PackRecalage / src / bbPackRecalageImageSwitcherBox.cxx
index 919e32cbf505fb7d5248e5402c92ef77bdad00bb..65696f6904dc6c60cc190565ed2d6dfd91107c38 100644 (file)
@@ -4,27 +4,58 @@ namespace bbPackRecalage
 {
        MyTimer::MyTimer(ImageSwitcherBox *box): wxTimer()
        {
-               _box = box;
+               _box = box;             
        }
 
        MyTimer::~MyTimer()
        {
+               //delete this;
        }
 
        void MyTimer::Notify()
        {
-               _box->Process();
+               //This will be called each time the timer finishes a countdown
+               _box->Change();
                _box->bbSignalOutputModification(std::string("Out")); 
-       }
+       }       
 
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageSwitcherBox)
+BBTK_BLACK_BOX_IMPLEMENTATION(ImageSwitcherBox,bbtk::WxBlackBox);
 
+void ImageSwitcherBox::Change()
+{
+       //Just changes the images each time the timer finishes a countdown
        
+       if(change == false)
+       {
+               bbSetOutputOut(bbGetInputIn2());                
+               change = true;
+       }
+       else
+       {
+               bbSetOutputOut(bbGetInputIn1());
+               change = false;
+       }       
+}
 
-BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageSwitcherBox)
-BBTK_BLACK_BOX_IMPLEMENTATION(ImageSwitcherBox,bbtk::WxBlackBox);
 void ImageSwitcherBox::Process()
 {
        time = bbGetInputTime();
+       _on =  bbGetInputOn();
+
+       if(firstTime == true)
+       {
+               if(bbGetInputIn1() != NULL)
+               {
+                       bbSetOutputOut(bbGetInputIn1());
+                       firstTime = false;                      
+               }
+               else if(bbGetInputIn2() != NULL)
+               {
+                       bbSetOutputOut(bbGetInputIn2());
+                       firstTime = false;                      
+               }
+       }
                
        if(myTimer == NULL)
        {
@@ -32,27 +63,27 @@ void ImageSwitcherBox::Process()
                myTimer->Start(time);
                oldTime = time;
        }
-       else if(oldTime != time && myTimer != NULL)
+       
+       if(!_on)
        {
                myTimer->Stop();
-               myTimer->Start(time);
-               oldTime = time;
        }
-
-       if(change == false)
+       else if(!myTimer->IsRunning())
        {
-               bbSetOutputOut(bbGetInputIn1());
-               change = true;
+               myTimer->Start(time);
+               oldTime = time;
        }
-       else
+       else if(oldTime != time)
        {
-               bbSetOutputOut(bbGetInputIn2());
-               change = false;
+               myTimer->Stop();
+               myTimer->Start(time);
+               oldTime=time;
        }
 }
 void ImageSwitcherBox::CreateWidget(wxWindow* parent)
 {
-       bbSetOutputWidget( new wxButton ( parent  , -1 , _T("Start/Stop Image Change") ) );  
+       //Creates a simple text widget because it is necesary that a non-empty widget exists for creatingh the thread of the timer.
+       bbSetOutputWidget( new wxStaticText(parent, -1, _T("Image Switcher")) );        
 }
 void ImageSwitcherBox::bbUserSetDefaultValues()
 {
@@ -60,6 +91,8 @@ void ImageSwitcherBox::bbUserSetDefaultValues()
        change = false;
        time = 500;
        oldTime = 500;
+       firstTime = true;
+       _on=false;
 }
 void ImageSwitcherBox::bbUserInitializeProcessing()
 {
@@ -71,4 +104,5 @@ void ImageSwitcherBox::bbUserFinalizeProcessing()
        delete myTimer;
 }
 }
-// EO namespace bbPackRecalage
\ No newline at end of file
+// EO namespace bbPackRecalage
+