]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/controller/buttonContainerController.cxx
#2520 creaMaracasVisu Bug New Normal - Color Layer with double images
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaButtonContainer / controller / buttonContainerController.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*!
27  * @file buttonContainerController.cxx
28  * @brief This contains the ButtonContainerController class implementation
29  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
30  * @date  2011-06-02
31  */
32
33 #include "buttonContainerController.h"
34
35 namespace creaButtonContainer
36 {
37         namespace controller
38         {
39                 // ----------------------------------------------------------------------------------
40                 ButtonContainerController::ButtonContainerController( BCPanel* panel )
41                 {
42                         std::cout<< "MLER | ButtonContainerController::ButtonContainerController( BCPanel* panel )" << std::endl;
43                         this->m_BCPanel = panel;
44                 }
45                 // ----------------------------------------------------------------------------------
46                 ButtonContainerController::~ButtonContainerController( )
47                 {
48                 }
49                 // ----------------------------------------------------------------------------------
50                 void
51                 ButtonContainerController::AddEvents( )
52                 {
53                         try
54                         {
55                                 std::cout<< "MLER | ButtonContainerController:: AddEvents( )" << std::endl;
56                                 //Adding ButtonManagerEvents
57                                 for( GroupManagerList::iterator it =
58                                     this->m_BCPanel->m_GroupManagerList.begin( ); it
59                                     != this->m_BCPanel->m_GroupManagerList.end( ); ++it )
60                                 {
61                                         this->Connect(
62                                             ( *it ).first,
63                                             wxEVT_COMMAND_BUTTON_CLICKED,
64                                             (wxObjectEventFunction) &ButtonContainerController::ButtonExpEvent );
65                                 }//rof
66
67                                 //Adding ButtonEvents
68                                 for( ButtonGroupList::iterator it =
69                                     this->m_BCPanel->m_ButtonGroupList.begin( ); it
70                                     != this->m_BCPanel->m_ButtonGroupList.end( ); ++it )
71                                 {
72                                         KeyList keylist = ( *it )->GetButtonIdContainer( );
73                                         for( KeyList::iterator it2 = keylist.begin( ); it2 != keylist.end( ); ++it2 )
74                                         {
75                                                 this->Connect( ( *it2 ), wxEVT_COMMAND_BUTTON_CLICKED,
76                                                     (wxObjectEventFunction) &ButtonContainerController::ButtonEvent );
77                                         }//rof
78                                 }//rof
79                         }//yrt
80                         catch ( const std::exception& e )
81                         {
82                                 std::cerr << "ButtonContainerController::AddEvents( ) exception: "
83                                     << e.what( ) << std::endl;
84                         }//hctac
85                 }
86                 // ----------------------------------------------------------------------------------
87                 void
88                 ButtonContainerController::ButtonExpEvent( wxCommandEvent& event )
89                 {
90                         long id = event.GetId( );
91                         std::cout<< "MLER | ButtonContainerController:: ButtonExpEvent( wxCommandEvent& event )" << std::endl;
92
93                         try
94                         {
95                                 //changing the button label when its clicked and then hide the buttons of the group.
96                                 if ( this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->GetLabel( ).Cmp(
97                                     _( "+" ) ) == 0 )
98                                 {
99                                         this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->SetLabel(
100                                             _( "-" ) );
101                                         this->m_BCPanel->m_GroupManagerList[ id ]->HideSubPanel( false );
102                                 }//fi
103                                 else if ( this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->GetLabel( ).Cmp(
104                                     _( "-" ) ) == 0 )
105                                 {
106                                         this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->SetLabel(
107                                             _( "+" ) );
108                                         this->m_BCPanel->m_GroupManagerList[ id ]->HideSubPanel( true );
109                                 }//fi esle
110                                 this->m_BCPanel->FitSizer( );
111                         }//yrt
112                         catch ( const std::exception& e )
113                         {
114                                 std::cerr
115                                     << "ButtonContainerController::ButtonExpEvent( wxCommandEvent& event ) exception: "
116                                     << e.what( ) << std::endl;
117                         }//hctac
118                 }
119                 // ----------------------------------------------------------------------------------
120                 void
121                 ButtonContainerController::ButtonEvent( wxCommandEvent& event )
122                 {
123                         std::cout<< "MLER | ButtonContainerController:: ButtonEvent( wxCommandEvent& event )" << std::endl;
124                         try
125                         {
126                                 for( ButtonGroupList::iterator it =
127                                     this->m_BCPanel->m_ButtonGroupList.begin( ); it
128                                     != this->m_BCPanel->m_ButtonGroupList.end( ); ++it )
129                                 {
130                                         if ( ( *it )->GetButton( event.GetId( ) ) != NULL )
131                                         {
132                                                 ( *it )->GetButton( event.GetId( ) )->Execute( );
133                                         }//fi
134                                 }//rof
135                         }//yrt
136                         catch ( const std::exception& e )
137                         {
138                                 std::cerr
139                                     << "ButtonContainerController::ButtonEvent( wxCommandEvent& event ) exception: "
140                                     << e.what( ) << std::endl;
141                         }//hctac
142                 }
143         // ----------------------------------------------------------------------------------
144
145
146         }//ecapsename
147 }//ecapsename
148