]> Creatis software - creaRigidRegistration.git/blobdiff - PackRecalage/src/bbPackRecalageImageSwitcherBox.cxx
*** empty log message ***
[creaRigidRegistration.git] / PackRecalage / src / bbPackRecalageImageSwitcherBox.cxx
index 1c603f6c17b3b5cc2da47a47cd2490c4e7d5d43a..99c0a643b7227e955671a6fec333048642923f64 100644 (file)
@@ -4,28 +4,55 @@ namespace bbPackRecalage
 {
        MyTimer::MyTimer(ImageSwitcherBox *box): wxTimer()
        {
-               _box = box;
+               _box = box;             
        }
 
        MyTimer::~MyTimer()
        {
+               delete this;
        }
 
        void MyTimer::Notify()
        {
-               _box->Process();
+               _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()
+{
+       if(change == false)
+       {
+               bbSetOutputOut(bbGetInputIn2());                
+               change = true;
+       }
+       else
+       {
+               bbSetOutputOut(bbGetInputIn1());
+               change = false;
+       }       
+}
+
 void ImageSwitcherBox::Process()
 {
        time = bbGetInputTime();
-       _on = bbGetInputOn();
+       _on =  bbGetInputOn();
+
+       if(firstTime == true)
+       {
+               if(bbGetInputIn1() != NULL)
+               {
+                       bbSetOutputOut(bbGetInputIn1());
+                       firstTime = false;                      
+               }
+               else if(bbGetInputIn2() != NULL)
+               {
+                       bbSetOutputOut(bbGetInputIn2());
+                       firstTime = false;                      
+               }
+       }
                
        if(myTimer == NULL)
        {
@@ -33,28 +60,33 @@ void ImageSwitcherBox::Process()
                myTimer->Start(time);
                oldTime = time;
        }
-       
+       /*
        if(oldTime != time && myTimer !=NULL)
        {
                myTimer->Stop();
                myTimer->Start(time);
                oldTime = time;
+       }*/
+
+       if(!_on)
+       {
+               myTimer->Stop();
        }
-       
-       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") ) );  
+       bbSetOutputWidget( new wxStaticText(parent, -1, _T("Image Switcher")) );        
 }
 void ImageSwitcherBox::bbUserSetDefaultValues()
 {
@@ -62,7 +94,8 @@ void ImageSwitcherBox::bbUserSetDefaultValues()
        change = false;
        time = 500;
        oldTime = 500;
-       _on = false;
+       firstTime = true;
+       _on=false;
 }
 void ImageSwitcherBox::bbUserInitializeProcessing()
 {