]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWxBlackBox.h
New widget pipeline : progressing ...
[bbtk.git] / kernel / src / bbtkWxBlackBox.h
index d074414dea09017946f65e00c0a89d94e0d3cc37..e2857e0d47c57d0f87ce4d0b548272b77bbb138a 100644 (file)
@@ -1,20 +1,34 @@
-/*=========================================================================
-                                                                                
+/*=========================================================================                                                                               
   Program:   bbtk
   Module:    $RCSfile: bbtkWxBlackBox.h,v $
   Language:  C++
-  Date:      $Date: 2008/01/22 15:41:34 $
-  Version:   $Revision: 1.2 $
-                                                                                
-  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
-  l'Image). All rights reserved. See Doc/License.txt or
-  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
-                                                                                
-     This software is distributed WITHOUT ANY WARRANTY; without even
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-     PURPOSE.  See the above copyright notices for more information.
-                                                                                
-=========================================================================*//**
+  Date:      $Date: 2008/11/25 11:17:13 $
+  Version:   $Revision: 1.21 $
+========================================================================*/
+
+
+/* ---------------------------------------------------------------------
+
+* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
+* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
+*
+*  This software is governed by the CeCILL-B license under French law and 
+*  abiding by the rules of distribution of free software. You can  use, 
+*  modify and/ or redistribute the software under the terms of the CeCILL-B 
+*  license as circulated by CEA, CNRS and INRIA at the following URL 
+*  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
+*  or in the file LICENSE.txt.
+*
+*  As a counterpart to the access to the source code and  rights to copy,
+*  modify and redistribute granted by the license, users are provided only
+*  with a limited warranty  and the software's author,  the holder of the
+*  economic rights,  and the successive licensors  have only  limited
+*  liability. 
+*
+*  The fact that you are presently reading this means that you have had
+*  knowledge of the CeCILL-B license and that you accept its terms.
+* ------------------------------------------------------------------------ */                                                                         
+/**
  * \brief Short description in one line
  * 
  * Long description which 
@@ -38,7 +52,7 @@
 
 
 #include "bbtkWx.h"
-#include "bbtkUserBlackBox.h"
+#include "bbtkAtomicBlackBox.h"
 
 
 namespace bbtk
@@ -60,49 +74,61 @@ namespace bbtk
 
   //==================================================================
   /// Widget black boxes
-  class BBTK_EXPORT WxBlackBox : public bbtk::UserBlackBox  
-  {
-    BBTK_USER_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::UserBlackBox);
-    //   BBTK_DECLARE_INPUT(WinParent,WxParentToChildData*);
+  class BBTK_EXPORT WxBlackBox : public bbtk::AtomicBlackBox  
+  { 
+    BBTK_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::AtomicBlackBox);
     BBTK_DECLARE_INPUT(WinTitle,std::string);
     BBTK_DECLARE_INPUT(WinWidth,int);
     BBTK_DECLARE_INPUT(WinHeight,int);
     BBTK_DECLARE_INPUT(WinDialog,bool);
     BBTK_DECLARE_INPUT(WinHide,Void);
-    BBTK_DECLARE_OUTPUT(Widget, wxWindow*);//WxBlackBoxWidget*);
+    BBTK_DECLARE_INPUT(WinClose,Void);
+    BBTK_DECLARE_OUTPUT(Widget, wxWindow*);
 
   public:
+    /// Main processing method of the box. Overloaded to handle windows inclusion : if the output Widget is connected then the execution is transfered to the box to which it is connected (as the container window must be created and displayed - this box will be executed by the normal pipeline recursion mechanism)
+    virtual void bbExecute(bool force = false);
+
+
     typedef WxBlackBoxWindow Window;
     
-    /// Returns the window associated to the box
+    /// Returns the **OWN** window associated to the box
     /// If 0 returned = no window
     Window* bbGetWindow() { return bbmWindow; }
 
-    /// Returns the Parent Window that must be used to create the widget 
-    wxWindow* bbGetWxParent() { return bbGlobalGetTopWindow(); }
-
-
-    /// Returns the global parent of all bbtk windows
-    static wxWindow* bbGlobalGetTopWindow();
-    /// Sets the global parent of all bbtk windows
-    static void bbGlobalSetTopWindow(wxWindow*);
-
-    static void bbGlobalIncNbWindowsAlive() { bbmgNbWindowsAlive++; }
-    static void bbGlobalDecNbWindowsAlive();
-    static int  bbGlobalGetNbWindowsAlive() { return bbmgNbWindowsAlive; }
-    static bool bbGlobalIsSomeWindowAlive() { return (bbmgNbWindowsAlive>0);}
-
-    static void bbGlobalDecNbWindowsShown();
-    static void bbGlobalIncNbWindowsShown() { bbmgNbWindowsShown++; }
-    static int  bbGlobalGetNbWindowsShown() { return bbmgNbWindowsShown; }
-    static bool bbGlobalIsSomeWindowShown() { return (bbmgNbWindowsShown>0);}
+    /// Returns the window containing the widget associated to the box
+    /// Which can be the own window of **ANOTHER** box in case of 
+    /// a hierarchy of widgets.
+    /// More precisely :
+    /// If bbGetWindow() != 0 then returns bbGetWindow()
+    /// Else if the output 'Widget' is connected 
+    ///  then returns bbGetContainingWindow() of the box connected to 'Widget'
+    /// Else returns 0;
+    Window* bbGetContainingWindow();
+
+    /// Returns the parent wxWindow that must be used to create the widget 
+         //
+         // LG 24/11/08 : New widget pipeline
+         //    wxWindow* bbGetWxParent();
+
+    /// Returns true iff the 'containing window' exists and is shown 
+    /// (see bbGetContainingWindow).
+    bool bbIsShown();
 
+    //==================================================================    
+    /// User callback invoked when the containing window is shown
+    virtual void bbUserOnShow() {}
+    //==================================================================    
+    //==================================================================    
+    /// User callback invoked when the containing window is hidden
+    virtual void bbUserOnHide() {}
+    //==================================================================    
 
-  private:
-    static wxWindow* bbmgTopWindow;
-    static int bbmgNbWindowsAlive;
-    static int bbmgNbWindowsShown;
+         // LG 24/11/08 : New widget pipeline
+         void bbCreateWidgetAndEventHandler(wxWindow* parent); 
 
+         
   protected:
     
   
@@ -110,7 +136,7 @@ namespace bbtk
     /// User callback called in the box contructor
     virtual void bbUserConstructor();
     /// User callback called in the box copy constructor
-    virtual void bbUserCopyConstructor();
+    virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
     /// User callback called in the box destructor
     virtual void bbUserDestructor();
     //==================================================================    
@@ -118,27 +144,44 @@ namespace bbtk
     //==================================================================    
     /// User callback for creating the widget associated to the box
     /// ** Must be defined **
-    virtual void bbUserCreateWidget() 
+         // LG 24/11/08 : New widget pipeline
+         virtual void bbUserCreateWidget(wxWindow* parent) 
     {
-      bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is undefined : cannot work !!");
+      bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
     }
     //==================================================================    
-    
+
+
+         wxWindow* bbCreateWidgetOfInput(const std::string& in, wxWindow* parent);
+
+
     //==================================================================
-    /// Calls the user defined widget creation method 
-    /// and the user processing method and then displays the window
-    virtual void bbProcess() 
-    { 
-      if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
-      this->bbUserProcess(); 
-      bbShowWindow();
-    }
+    /// Main processing method of the box.
+    virtual IOStatus bbBackwardUpdate( Connection::Pointer caller );
+    //==================================================================
+
+
+
+    //==================================================================
+    /// Overloaded processing method for WxBlackBoxes :
+    /// 1) if the widget is null then 
+    ///    calls the user defined widget creation method : bbUserCreateWidget()
+    /// 2) calls the user defined processing method : bbUserProcess()
+    /// 3) displays the window : bbShowWindow();
+    virtual void bbProcess();
     //==================================================================
 
     //==================================================================
-    /// Specific methods for windows creation during pipeline execution
+    /// If necessary creates the WxBlackBoxWindow associated to the box
+    /// and shows it 
+    /// (does nothing if the box output 'Widget' is connected which 
+    /// means that the box does not have its own window but is contained 
+    /// into another window)
     void bbShowWindow();
+    /// Hides the WxBlackBoxWindow associated to the box (if exists)
     void bbHideWindow();
+    /// Closes (destroys) the WxBlackBoxWindow associated to the box (if exists)
+    void bbCloseWindow();
     //==================================================================
 
   private:
@@ -165,6 +208,18 @@ namespace bbtk
 
     void bbInitAttributes();
 
+  protected :
+
+
+    /// For Forward update mechanism when execution is called 
+    /// on a contained window
+    /// Is set to true before transfering update to parent 
+    /// in order to not re-transfer a second time...
+    bool bbmUpdateTransferedToParent;
+
+    bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
+    void bbSetUpdateTransferedToParent(bool b) 
+    { bbmUpdateTransferedToParent = b; }
 
   };
   //=================================================================
@@ -174,35 +229,52 @@ namespace bbtk
   /// Defines the bbUserCreateWidget method
 #define BBTK_CREATE_WIDGET(CALLBACK)                                   \
   public:                                                              \
-  inline void bbUserCreateWidget()                                     \
+  inline void bbUserCreateWidget(wxWindow* parent)                                     \
+  {                                                                    \
+    bbtkDebugMessageInc("wx",1,"**> Creating widget for ["             \
+                       <<bbGetFullName()<<"]"<<std::endl);             \
+    CALLBACK(parent);                                                          \
+    bbtkDebugMessageInc("wx",1,"<** Creating widget for ["             \
+                       <<bbGetFullName()<<"]"<<std::endl);             \
+  }
+  
+  //======================================================================
+
+  //======================================================================
+  /// Defines the bbUserOnShow method
+#define BBTK_ON_SHOW_WIDGET(CALLBACK)                                  \
+  public:                                                              \
+  inline void bbUserOnShow()                                   \
   {                                                                    \
-    bbtkDebugMessageInc("Process",1,"=> "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
+    bbtkDebugMessageInc("wx",1,"**> Showing ["         \
                        <<bbGetFullName()<<"]"<<std::endl);             \
     CALLBACK();                                                                \
-    bbtkDebugMessageDec("Process",1,"<= "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
+    bbtkDebugMessageInc("wx",1,"<** Showing ["         \
                        <<bbGetFullName()<<"]"<<std::endl);             \
   }
   
   //======================================================================
 
   //=================================================================
-  // UserBlackBox description
-  BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::UserBlackBox);
+  // WxBlackBoxDescriptor declaration
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
   BBTK_NAME("WxBlackBox");
-  //  BBTK_INPUT_NOCOPY(WxBlackBox,WinParent,"Parent widget box",
-  //               WxParentToChildData*);
+  // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
+  BBTK_CATEGORY("widget");
   BBTK_INPUT(WxBlackBox,WinTitle,
-            "Title of the window (only used if the box is the top window of a Parent-Child hierarchy)",
-            std::string);
+            "Title of the window (*)",
+            std::string,"");
   BBTK_INPUT(WxBlackBox,WinWidth,
-            "Width of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
+            "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
   BBTK_INPUT(WxBlackBox,WinHeight,
-            "Height of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
+            "Height of the window (*)",int,"");
   BBTK_INPUT(WxBlackBox,WinDialog,
-            "Set to 'true' to have a dialog window, i.e. which is modal (steals the focus until closed) (only used if the box is the top window of a Parent-Child hierarchy)",bool);
+            "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
   BBTK_INPUT(WxBlackBox,WinHide,
-            "Any signal received hides the window (only active if the box is the top window of a Parent-Child hierarchy)",Void);
-  BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*);
+            "Any signal received hides the window (*)",Void,"signal");
+  BBTK_INPUT(WxBlackBox,WinClose,
+            "Any signal received closes the window (*)",Void,"signal");
+  BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*,"");
   BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
   //=================================================================
 
@@ -219,16 +291,17 @@ namespace bbtk
   class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
   {
   public:
-    WxBlackBoxWindow(WxBlackBox* box);
+    WxBlackBoxWindow(WxBlackBox::Pointer box);
     virtual ~WxBlackBoxWindow();
     virtual void bbShow();
     virtual void bbHide();
+    virtual void bbClose();
     bool bbIsShown() { return mShown; }
-    virtual WxBlackBox* bbGetBlackBox() { return mBox; }
+    virtual WxBlackBox::Pointer bbGetBlackBox() { return mBox.lock(); }
     virtual wxDialog* bbGetDialog() { return 0; } 
     virtual wxFrame* bbGetFrame() { return 0; } 
   private:
-    WxBlackBox* mBox;
+    WxBlackBox::WeakPointer mBox;
     bool mShown;
   };
   //==================================================================
@@ -238,11 +311,12 @@ namespace bbtk
   class BBTK_EXPORT  WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
   {
   public:
-    WxBlackBoxDialog(WxBlackBox* box, 
+    WxBlackBoxDialog(WxBlackBox::Pointer box, 
                     wxWindow *parent, wxString title, wxSize size);
     ~WxBlackBoxDialog();
     void bbShow();  
     void bbHide();
+    void bbClose();
     wxDialog* bbGetDialog() { return this; } 
   };
   //==================================================================
@@ -252,43 +326,17 @@ namespace bbtk
   class BBTK_EXPORT  WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
   {
   public:
-    WxBlackBoxFrame(WxBlackBox* box,
+    WxBlackBoxFrame(WxBlackBox::Pointer box,
                    wxWindow *parent, wxString title, wxSize size);
     ~WxBlackBoxFrame();
     void bbShow();
     void bbHide();
+    void bbClose();
     wxFrame* bbGetFrame() { return this; } 
   };
   //==================================================================
 
 
-  /*
- //=================================================================
-  /// Class from which a user defined widget associated to a WxBlackBox 
-  /// should inherit
-  class BBTK_EXPORT  WxBlackBoxWidget
-  {
-  public:
-    /// Ctor with the WxBlackBox which created it 
-    WxBlackBoxWidget( WxBlackBox* box);
-    /// Dtor
-    virtual ~WxBlackBoxWidget();
-
-    /// Returns the WxBlackBox which created it
-    WxBlackBox* GetBlackBox() { return mBox; }
-    /// Returns the WxBlackBox which created it (const)
-    const WxBlackBox* GetBlackBox() const { return mBox; }
-
-    /// Returns the wxWindow associated to the widget
-    virtual wxWindow* GetWxWindow() { return 0; }
-
-    virtual bool IsDead() { return false; }
-
-  private:
-    WxBlackBox* mBox;
-  };  
-  //=================================================================
-  */
 
   //=================================================================
   // Handles the destroy events of a widget associated to a WxBlackBox 
@@ -297,7 +345,7 @@ namespace bbtk
   {
   public:
     /// Ctor with the box and widget 
-    WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
+    WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, wxWindow *widget );
     /// Dtor
     ~WxBlackBoxWidgetEventHandler();
     /// Returns true iff is the handler for that window  
@@ -309,37 +357,12 @@ namespace bbtk
     //bool IsDead() { return mDead; }
 
   private:
-    WxBlackBox* mBox;
+    WxBlackBox::WeakPointer mBox;
     wxWindow* mWindow;
     //bool mDead;
   };  
   //=================================================================
 
-  /*
-  //=================================================================
-  /// A WxBlackBoxWidget which is a wxPanel also
-  class BBTK_EXPORT  WxBlackBoxWidgetPanel :     
-                               public wxPanel,
-                               public WxBlackBoxWidget
-//                             public WxBlackBoxWidget,
-//                             public wxPanel
-  {
-  public:
-    /// Ctor with the parent and the WxBlackBox which created it 
-    WxBlackBoxWidgetPanel(WxBlackBox* box,  wxWindow *parent)
-      :
-      wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
-      WxBlackBoxWidget(box)
-    {}
-    
-    /// Returns the top panel of the widget    
-    wxWindow* GetWxWindow() { return (wxWindow*)(wxPanel*)(this); }
-    /// Returns the top panel of the widget    
-    wxPanel* GetPanel() { return (wxPanel*)(this); }
-
-  };  
-  //=================================================================
-  */
 
 
 } //namespace bbtk