Propagate

 

 

 

The Tool_Propagate class enable you to have a propagate tool in your mode. The tool is used to "propagate" the values you have on one frame to an adjacent frame in the same group. When you click on the "Up" or "Down" button, the function you associated with to the tool with the "Set" method will be called with a pointer to the source frame and a pointer to the target frame.  The user can use the center arrow buttons to select the "source" frame.

 

 

The variables of the Tool_Propagate class are:

 

There is no variable associated with this class.

 

 

The methods of the Tool_Propagate class are:

 

 

Tool_Propagate( void ) ;

 

Constructor

 

~Tool_Propagate() ;

 

Destructor

 

int          Read( void ) ;

 

// There is no "Read" method for this class

 

int          Set( int (*Propagate_Fct)() ) ;

Associate a function to the propagate buttons.  The associated function return an integer (0 is a problem occurred and the function failed) and receive 2 arguments (void *), a NULL casted pointer to the "source" frame and a NULL casted pointer to the target frame.

int (*Propagate_Fct)( void *source, void *target ) ;

 

int          Demo_Propagate( void *v_source, void *v_target )

{

          // --- make sure we can propagate ---

          SliceO_Frame *source = (SliceO_Frame *) v_source ;

          SliceO_Frame *target = (SliceO_Frame *) v_target ;

          // --- here we just print the propagate info ---

          Error_Fct( hwnd, ERROR_CODE_REPORT, "Propagate from %s to %s",

                    source->Name_Get(), target->Name_Get() ) ;

          return( 1 ) ;

}

 

extern "C" __declspec(dllexport) int Ctrl_Resize( HWND wnd, int width, int height )

{

          ...

          // --- associate a function to the propagate action ---

          tool_propagate.Set( Demo_Propagate ) ;

          ...

}

 

 

The methods shared with the other SliceO_Tool classes are:

 

 

int          Click( int up_down ) ;

You must call this method if the user has activated a mouse button while the cursor is inside the tool

 

void          Draw( void ) ;

 

This method will draw the tool

 

int          Height( unsigned short nb=10 ) ;

This method returns the height (in pixel) of the tool. The "nb" parameter defines how many lines of information will be displayed.

 

int          Keyboard( int key ) ;

You must call this method if the user has activated a keyboard key while the cursor is inside the tool

 

void          Leave( void ) ;

 

You must call this method if the user move the cursor outside of the tool

 

int          Motion( int up_down ) ;

 

You must call this method if the user move the cursor inside the tool

 

int          Resize( Boxs *box ) ;

You must call this method to resize the tool. The tool will reside inside the bounding box of the "Boxs" class.

 

int          Scroll( int val ) ;

You must call this method if the user has activated the mouse wheel while the cursor is inside the tool

 

void          Update( UInt64 flag )

You must call this method when external events change the content of the tool.  The "flag" parameter is the "Update Flag" defining these changes.

The update should be called if one of the following flags are changed:

UPDATE_ALL_TOOLS

UPDATE_CUR_FRAME          // the current frame has changed

UPDATE_CUR_BRUSH          // the current brush has changed

 

An example of the usage of the Tool_Propagate class is given in the Samples\SliceO Tools\Propagate demo directory. 

 

The tool_propagate_ctrl.cpp file from the tool_Propagate demo

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

// --- for Propagate Tool ---

static          Boxs          box_prop ;

static          Tool_Propagate          tool_propagate ;

 

// --- defined in tool_propagate_propagate.cpp ---

int          Demo_Propagate( void *v_source, void *v_target ) ;

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Register

//

//          Parameters:          mode (unsigned short *)          Used only for Tools.

//                                                            If this pointer is not NULL,

//                                                            use it to specify to what tool

//                                                            window we belong.

//                                                            SLICEO_TOOL_2D, _BASIC,_3D...

//                                                  

//          Returns:          (int)                    Vertical size of your menu (in pixels)

//

//          This is called once at the start of the program.  We need it to

//          know you are using your own func. and how much space to reserve

//          in the menu interface.  You must also change the "mode" flag to

//          reflect in what tool window you want to appear.

//

//          Note: If you do not need a graphic interface, just comment out

//                the "Ctrl_Register" function.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Register( unsigned short *mode )

{

          // --- this is a 2D TAG tool only ---

          if ( mode )

              (*mode) = SLICEO_TOOL_2D ;

 

// --------------------------------------------------------------------

// In the "Config" menu, the user can change the interface's size.

// This action change a number of variables that are used to compute

// the size of the tool in the intearface.  We now load a few of these

// variables and use them to compute the dimension of our interface box.

// --------------------------------------------------------------------

short          Title_Dim =           (short) Fct_Variable_Value( "$INTERFACE_TITLE_DIM_BIG" ) ;

short          Space_Dim =           (short) Fct_Variable_Value( "$INTERFACE_SPACE_DIM" ) ;

 

          // --- compute the height of the interface ---

          short height = Title_Dim                    // title at top of tool

                         +          tool_propagate.Height()          // propagate

                         + Space_Dim ;                    // space at the bottom

 

          return( height ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Create

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                              width (int)          horiz. size of the window

//                              height (int)          vert. size of the window

//          Returns:          (int)                    0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Create( HWND wnd, int width, int height )

{

char   *Title_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

char   *Title_Font_Weight = (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

short          Title_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

short          Border_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

 

          box_box.Name = "------- SliceO Propagate -------" ;

          box_box.Flag      = OUTIL_DISABLE | OUTIL_NO_3D ;

          box_box.Pos_X     = 1 ;

          box_box.Pos_Y     = 1 ;

          box_box.Dim_X     = width - 2 ;

          box_box.Dim_Y     = height - 2 ;

          box_box.border    = Border_Dim;

          box_box.color.set( WINDOW_COLOR_TOOL_R,

                                 WINDOW_COLOR_TOOL_G,

                                 WINDOW_COLOR_TOOL_B ) ;

          box_box.Font_Name   = Title_Font_Name ;

          box_box.Font_Scale  = Title_Font_Scale ;

          box_box.Font_Weight = Title_Font_Weight ;

          box_box.Init( wnd ) ; 

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Resize

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                              width (int)          horiz. size of the window

//                              height (int)          vert. size of the window

//          Returns:          (int)                    0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Resize( HWND wnd, int width, int height )

{

short          p_x, p_y, d_x, d_y ;

 

// -----------------------------------------------------------------------

// In the "Config" menu, the user can change the interface's size.

// This action change a number of variables that are used to compute

// the size of the tool in the intearface.  We now load a few of these

// variables and use them to compute the dimension of our interface tools.

// -----------------------------------------------------------------------

char   *Title_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

char   *Title_Font_Weight = (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

short          Title_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

char   *Tools_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TOOL_FONT_NAME" ) ;

char   *Tools_Font_Weigth = (char *) Fct_Variable_Value( "$INTERFACE_TOOL_FONT_WEIGHT" ) ;

short          Tools_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TOOL_FONT_SCALE" ) ;

 

short          Space_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_SPACE_DIM" ) ;

short          Border_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

 

          if ( wnd ) {

              box_box.Pos_X     = 1 ;

              box_box.Pos_Y     = 1 ;

              box_box.Dim_X     = width - 2 ;

              box_box.Dim_Y     = height - 2 ;

              box_box.border    = Border_Dim;

              box_box.Font_Name   = Title_Font_Name ;

              box_box.Font_Scale  = Title_Font_Scale ;

              box_box.Font_Weight = Title_Font_Weight ;

              box_box.Init( wnd ) ; 

          } else {

              wnd = box_box.wnd ;

          }

 

          // ===========================================================================

          // --- Brush_Selection Tool

          // ===========================================================================

          p_x = box_box.Pos_X + Space_Dim ;

          p_y = box_box.Pos_Y + Space_Dim ;

          d_x = box_box.Dim_X - 2*Space_Dim ;

          d_y = tool_propagate.Height() ;

 

          // --- The tool will be inside this box ---

          box_prop.Flag =  OUTIL_EMPTY ;

          box_prop.Pos_X = p_x ;

          box_prop.Pos_Y = p_y ;

          box_prop.Dim_X = d_x ;

          box_prop.Dim_Y = d_y ;

          box_prop.border   = Border_Dim ;

          box_prop.Font_Name   = Tools_Font_Name ;

          box_prop.Font_Weight = Tools_Font_Weigth ;

          box_prop.Font_Scale  = Tools_Font_Scale ;

          box_prop.color = box_box.color ;

          box_prop.Init( wnd ) ; 

 

          // --- now prepare the tool itself ---

          tool_propagate.Resize( &box_prop ) ;

 

          // --- associate a function to the propagate action ---

          tool_propagate.Set( Demo_Propagate ) ;

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Draw

//

//          Parameters:          (void)

//          Returns:          (int)                    0 if error

//

//          This is called each time your menu has to be re-drawn

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Draw( HWND wnd )

{

          // --- if the window if off or invible, we can get out ---

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          box_box.Draw() ;

 

          // --- Propagate Tool ---

          tool_propagate.Draw() ;

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Leave

//

//          Parameters:          (void)

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor leave your menu

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Leave( void )

{

          // --- if the window if off or invible, we can get out ---

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          // --- Propagate Tool ---

          tool_propagate.Leave() ;

 

          return( 1 ) ;

}

 

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Click

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              up_down (int)          state of the mouse buttons

//                              x, y (int)          current cursor position

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor is inside your menu and the state

//          of the mouse buttons has changed.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Click( HWND wnd, int up_down, short x, short y )

{

 

          // --- We only refresh the image when we release the button ---

          if ( ! up_down ) {

              return( 0 ) ;

          }

 

          // ------------------------------------------------

          // ---              Propagate Tool                              ---

          // ------------------------------------------------

          if ( tool_propagate.Click( up_down ) >= 0  ) {

//                    // --- we need to refresh the graphics ---

//                    Fct_Redraw( REDRAW_CLEAR_2D ) ;

          }

          // ------------------------------------------------

 

          return( 0 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Key

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              key (int)          code of the activated key

//                              x, y (int)          current cursor position

//          Returns:          (int)                    1 if key is used

//

//          This is called each time the cursor is inside your menu and a keyboard

//          key has been pressed.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Key( HWND wnd, int key, short x, short y )

{

          // --- Propagate Tool ---

          if ( tool_propagate.Keyboard( key ) )

              return( 1 ) ;

 

          return( 0 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Motion

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              up_down (int)          state of the mouse buttons

//                              x, y (int)          current cursor position

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor is inside your menu and the cursor

//          has moved.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Motion( HWND wnd, int up_down, short x, short y )

{

          // ------------------------------------------------

          // The mouse has moved.  By calling "select" we

          // insure that the box will get the "select" color

          // if the cursor is over it.

          // ------------------------------------------------

 

          // --- Propagate Tool ---

          if ( box_prop.Select( up_down ) ) {

              tool_propagate.Motion( up_down ) ;

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

 

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Scroll

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              up_down (int)          state of the mouse buttons

//                              x, y (int)          current cursor position (in Wnd space)

//

//          Returns:          (int)                    0 if unused

//

//          This is called each time the cursor is inside your menu and the mouse

//          wheel has been activated.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Scroll( HWND wnd, int count, short x, short y )

{

          // --- Propagate Tool ---

          if ( box_prop.Select( KEY_QUERY ) ) {

              tool_propagate.Scroll( count ) ;

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Update

//

//          Parameters:          (void)

//          Returns:          (int)                    0 if error

//

//          This is called each time something has been modified from another

//          control and sliceO Beleive it may affect you.

//

// ----------------------------------------------------------------------------

int          Ctrl_Update( UInt64 flag )

{

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

 

          // --- We changed the current frame ---

          if ( flag & UPDATE_CUR_FRAME ) {

              tool_propagate.Update( flag ) ;

          }

 

          return( 1 ) ;

}

 

...