]> Creatis software - bbtk.git/blob - packages/kw/src/bbkwLayoutSplit.cxx
Feature #1774
[bbtk.git] / packages / kw / src / bbkwLayoutSplit.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la SantÈ)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbkwLayoutSplit.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:05 $
33   Version:   $Revision: 1.5 $
34 =========================================================================*/
35
36
37
38 /**
39  *  \file
40  *  \brief
41  */
42
43
44 #ifdef USE_KWWIDGETS
45
46 #include "bbkwLayoutSplit.h"
47 #include "bbkwPackage.h"
48 #include "bbtkUtilities.h"
49
50 #include <vtkKWSplitFrame.h>
51
52 namespace bbkw
53 {
54   BBTK_ADD_BLACK_BOX_TO_PACKAGE(kw,LayoutSplit);
55   BBTK_BLACK_BOX_IMPLEMENTATION(LayoutSplit,bbtk::KWBlackBox);
56
57   void LayoutSplit::bbUserConstructor()
58   {
59     bbSetInputOrientation("VERTICAL");
60     bbSetInputProportion(50);
61     bbSetInputWidget1(NULL);
62     bbSetInputWidget2(NULL);
63   }
64
65   void LayoutSplit::Process()
66   {
67   }
68
69
70   void LayoutSplit::CreateWidget(vtkKWFrame* parent) 
71   {
72     vtkKWSplitFrame *splitframe = vtkKWSplitFrame::New();
73     bbSetOutputWidget(splitframe);
74     splitframe->SetParent(parent);
75     splitframe->Create();
76     splitframe->SetFrame1MinimumSize(5);
77     splitframe->SetFrame2MinimumSize(5);
78     splitframe->SetExpandableFrameToBothFrames();
79
80  
81     int width = parent->GetWidth();
82     int height = parent->GetHeight();
83     int orientation = 0;
84     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|H|HORIZONTAL")==true)  
85       { 
86         orientation = 0; 
87      }
88     else if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true)           
89       {
90         orientation = 1; 
91       }
92     else 
93       {
94         bbtkWarning("Unrecognized value '"<<bbGetInputOrientation()<<"' for input 'Orientation' of LayoutSplit "<<bbGetName()<<std::endl);
95       }
96
97     if (orientation==0)
98       {
99         splitframe->SetOrientationToHorizontal ();
100         width = width / 2;
101       }
102     else 
103       {
104         splitframe->SetOrientationToVertical ();
105         height = height / 2 ;   
106       }  
107
108    width = width - 5;
109    height = height - 5 ;
110  
111    /*   
112     bbGetOutputWidget()->GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
113                                                   bbGetOutputWidget()->GetWidgetName(),
114                                                   parent->GetWidth(),
115                                                   parent->GetHeight() );
116    */
117    bbGetOutputWidget()->GetApplication()->Script
118      ("pack %s -expand yes -fill both",
119       bbGetOutputWidget()->GetWidgetName());
120
121     splitframe->SetReliefToGroove();
122     splitframe->SetBorderWidth(2);
123
124
125     vtkKWWidget* w1 =  bbCreateWidgetOfInput("Widget1",splitframe->GetFrame1());
126     
127     vtkKWWidget* w2 = bbCreateWidgetOfInput("Widget2",splitframe->GetFrame2());
128  
129     splitframe->GetApplication()->Script
130       ("pack %s -expand yes -fill both",
131        w1->GetWidgetName()) ;
132    splitframe->GetApplication()->Script
133       ("pack %s -expand yes -fill both",
134        w2->GetWidgetName()) ;
135
136     /*
137     splitframe->GetApplication()->Script("pack %s -expand yes -fill x -fill y",         w2->GetWidgetName());
138     */
139    /*
140    splitframe->GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
141                                         w1->GetWidgetName(),
142                                         width,
143                                         height);
144
145   splitframe->GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
146                                        w2->GetWidgetName(),
147                                        width,
148                                        height);
149   
150     */
151
152   }
153
154
155   // This callback is necessary to get actual processing of the view 
156   // when window is shown
157   /*
158   void  LayoutSplit::OnShowWidget()
159   {
160     if (bbGetOutputWidget()==0)
161       {
162         return;
163         //bbtkError("LayoutSplit::OnShowWidget() : Output Widget == 0 !");
164       }
165     kwSplitterWindow* win = (kwSplitterWindow*)bbGetOutputWidget();
166     int w,h;
167     if (win==0)
168       {
169         return;
170         //      bbtkError("LayoutSplit::OnShowWidget() : win == 0 !");
171       }
172     win->GetClientSize(&w,&h);
173     int pos = 100;
174     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),
175                                     "0|H|HORIZONTAL")==true)  
176       { 
177         pos = (int)(w * bbGetInputProportion() * 0.01);
178       }
179     else 
180       {
181         pos = (int)(h * bbGetInputProportion() * 0.01);
182       } 
183     //    std::cout << "pos = "<<pos<<std::endl;
184   
185     win->SetSashPosition(pos,true);
186     bbUserOnShowWidget("Widget1");
187     bbUserOnShowWidget("Widget2");
188   }
189   */
190
191
192
193 }//namespace bbkw
194
195 #endif // _USE_KWWIDGETS_
196