Subversion Repositories f9daq

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
146 f9daq 1
#include "../include/sipmscan.h"
2
#include "../include/workstation.h"
3
 
4
#include <stdio.h>
5
#include <stdlib.h>
6
 
7
// Title labels for each of the frame
8
void TGAppMainFrame::TGTitleLabel(TGWindow *parent, TGHorizontalFrame *fTitle, const char *title, Pixel_t foreColor, Pixel_t backColor, const char *font)
9
{
10
   TGLabel *lab = new TGLabel(fTitle, title);
11
   lab->ChangeBackground(backColor);
12
   lab->SetTextColor(foreColor);
13
   lab->SetTextFont(font);
14
   fTitle->AddFrame(lab, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY) );
15
   fTitle->ChangeBackground(backColor);
16
}
17
 
18
// Splitter to a set number of frames
19
bool TGAppMainFrame::TGSplitter(TGWindow *parent, const char *majorSplit, int *horSplits, int *vertSplits, const char *frameTitles[512], TGCompositeFrame **frames, int *frameWidth, int *frameHeight)
20
{
21
   // Number of Frames that are not the ones we supply
22
   int nrofmed = 0;
23
   // Number of all splits in the minor direction
24
   int minorSplits = 0;
25
   int k = 0;
26
 
27
   // Title frame height
28
   int titHeight = 25;
29
 
30
   if(strcmp("horizontal",majorSplit) == 0)
31
   {
32
      fLayout[idtotal] = new TGCompositeFrame(parent, 300, 300, kHorizontalFrame);
33
      for(int i = 0; i <= horSplits[0]; i++)
34
      {
35
         minorSplits += vertSplits[i];
36
         if(vertSplits[i] > 0)
37
            nrofmed++;
38
      }
39
 
40
      if(DBGSIG > 1) printf("TGSplitter(): Number of intermediate frames = %d, all minor splits = %d\n", nrofmed, minorSplits);
41
 
42
 
43
      TGCompositeFrame *fInter[nrofmed];
44
      TGVSplitter *vsplit[horSplits[0]];
45
      TGHSplitter *hsplit[minorSplits];
46
 
47
      nrofmed = 0;
48
 
49
      for(int i = 0; i <= horSplits[0]; i++)
50
      {
51
         if(DBGSIG > 1) printf("TGSplitter(): i = %d\n",i);
52
         for(int j = 0; j <= vertSplits[i]; j++)
53
         {
54
            if(DBGSIG > 1) printf("TGSplitter(): j = %d, vertSplits = %d\n",j, vertSplits[i]);
55
            if( vertSplits[i] > 0 )
56
            {
57
               if(j == 0)
58
               {
59
                  if(DBGSIG > 1) printf("TGSplitter(): vertSplits - j = %d (nrofmed = %d)\n", (vertSplits[i]-j), nrofmed);
60
                  if(i > 0)
61
                  {
62
                     fInter[nrofmed] = new TGCompositeFrame(fLayout[idtotal], frameWidth[k], 200, kVerticalFrame);
63
                     fLayout[idtotal]->AddFrame(fInter[nrofmed], new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
64
                  }
65
                  else
66
                  {
67
                     fInter[nrofmed] = new TGCompositeFrame(fLayout[idtotal], frameWidth[k], 200, kVerticalFrame | kFixedWidth);
68
                     fLayout[idtotal]->AddFrame(fInter[nrofmed], new TGLayoutHints(kLHintsExpandY));
69
                  }
70
               }
71
 
72
               if( (vertSplits[i]-j) > 0)
73
               {
74
                  if(DBGSIG > 1) printf("TGSplitter(): Step 0a (k = %d)\n", k);
75
 
76
                  frames[k] = new TGCompositeFrame(fInter[nrofmed], frameWidth[k], frameHeight[k], kVerticalFrame | kFixedHeight | kSunkenFrame);
77
                  fTitle = new TGHorizontalFrame(frames[k], 100, titHeight, kFixedHeight | kSunkenFrame);
78
                  TGTitleLabel(frames[k], fTitle, frameTitles[k], (Pixel_t)FORECOLOR, (Pixel_t)BACKCOLOR, FONT);
79
                  frames[k]->AddFrame(fTitle, new TGLayoutHints(kLHintsExpandX | kLHintsTop) );
80
                  fInter[nrofmed]->AddFrame(frames[k], new TGLayoutHints(kLHintsExpandX));
81
 
82
                  if(DBGSIG > 1) printf("TGSplitter(): Step 1a\n");
83
 
84
                  hsplit[nrofmed] = new TGHSplitter(fInter[nrofmed]);
85
                  hsplit[nrofmed]->SetFrame(frames[k], kTRUE);
86
                  fInter[nrofmed]->AddFrame(hsplit[nrofmed], new TGLayoutHints(kLHintsExpandX));
87
 
88
                  if(DBGSIG > 1) printf("TGSplitter(): Step 2a\n");
89
 
90
                  k++;
91
               }
92
               else
93
               {
94
                  if(DBGSIG > 1) printf("TGSplitter(): Step 0b (k = %d)\n", k);
95
 
96
                  frames[k] = new TGCompositeFrame(fInter[nrofmed], frameWidth[k], frameHeight[k], kVerticalFrame | kSunkenFrame);
97
                  fTitle = new TGHorizontalFrame(frames[k], 100, titHeight, kFixedHeight | kSunkenFrame);
98
                  TGTitleLabel(frames[k], fTitle, frameTitles[k], (Pixel_t)FORECOLOR, (Pixel_t)BACKCOLOR, FONT);
99
                  frames[k]->AddFrame(fTitle, new TGLayoutHints(kLHintsExpandX | kLHintsTop) );
100
                  fInter[nrofmed]->AddFrame(frames[k], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
101
 
102
                  if(DBGSIG > 1) printf("TGSplitter(): Step 1b\n");
103
                  k++;
104
               }
105
            }
106
            else
107
            {
108
               if(DBGSIG > 1) printf("TGSplitter(): Step 0c (k = %d)\n", k);
109
 
110
               frames[k] = new TGCompositeFrame(fLayout[idtotal], frameWidth[k], frameHeight[k], kVerticalFrame | kSunkenFrame);
111
               fTitle = new TGHorizontalFrame(frames[k], 100, titHeight, kFixedHeight | kSunkenFrame);
112
               TGTitleLabel(frames[k], fTitle, frameTitles[k], (Pixel_t)FORECOLOR, (Pixel_t)BACKCOLOR, FONT);
113
               frames[k]->AddFrame(fTitle, new TGLayoutHints(kLHintsExpandX | kLHintsTop) );
114
               fLayout[idtotal]->AddFrame(frames[k], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
115
 
116
               if(DBGSIG > 1) printf("TGSplitter(): Step 1c\n");
117
               k++;
118
            }
119
         }
120
 
121
         if(DBGSIG > 1) printf("TGSplitter(): i = %d, horSplits = %d\n", i, horSplits[0]);
122
 
123
         if(i != horSplits[0])
124
         {
125
            vsplit[i] = new TGVSplitter(fLayout[idtotal]);
126
            if( vertSplits[i] > 0 )
127
               vsplit[i]->SetFrame(fInter[nrofmed], kTRUE);
128
            else
129
               vsplit[i]->SetFrame(frames[k], kTRUE);
130
            fLayout[idtotal]->AddFrame(vsplit[nrofmed], new TGLayoutHints(kLHintsExpandY));
131
         }
132
 
133
         nrofmed++;
134
      }
135
 
136
      if(DBGSIG > 1) printf("TGSplitter(): Finished horizontal layout\n");
137
   }
138
   else if(strcmp("vertical",majorSplit) == 0)
139
   {
140
/*      for(int i = 0; i <= vertSplits[0]; i++)
141
      {
142
         minorSplits += horSplits[i];
143
         if(horSplits[i] > 0)
144
            nrofmed++;
145
      }
146
 
147
      printf("Number of intermediate frames = %d\n", nrofmed);
148
 
149
      TGCompositeFrame *fInter[nrofmed];*/
150
   }
151
   else
152
      return false;
153
 
154
   return true;
155
}
156
 
157
// Function for setting up the layout
158
void TGAppMainFrame::LayoutRead(int nrframes, int *w, int *h)
159
{
160
   int WM, HM, k = 0, start = 0;
161
 
162
   std::ifstream ilayout;
163
 
164
   char *cTemp, *cTemp2, readTemp[1024];
165
   cTemp = new char[512];
166
   cTemp2 = new char[512];
167
   sprintf(cTemp, "%s/layout/selected_layout.txt", rootdir);
168
   ilayout.open(cTemp, std::ifstream::in);
169
   if(ilayout.is_open())
170
   {
171
      ilayout >> cTemp2;
172
   }
173
   ilayout.close();
174
   printf("Loaded layout file is: %s\n", cTemp2);
175
 
176
   sprintf(cTemp, "%s/layout/%s", rootdir, cTemp2);
177
   ilayout.open(cTemp, std::ifstream::in);
178
   if(ilayout.is_open())
179
   {
180
      while(1)
181
      {
182
         if(ilayout.peek() == '#')
183
         {
184
            ilayout.getline(readTemp, 1024, '\n');
185
            if(DBGSIG > 1) printf("LayoutRead(): readTemp = %s\n", readTemp);
186
         }
187
         else if(ilayout.peek() == '\n')
188
            ilayout.ignore(1, '\n');
189
         else
190
         {  
191
            if(start == 0)
192
            {
193
               ilayout >> WM >> HM >> readTemp;
194
               ilayout.ignore(1, '\n');
195
               start++;
196
               if(DBGSIG > 1) printf("LayoutRead(): W = %d, H = %d, Name = %s\n", WM, HM, readTemp);
197
            }
198
            else
199
            {
200
               ilayout >> w[k] >> h[k] >> readTemp;
201
               ilayout.ignore(1, '\n');
202
               if(DBGSIG > 1) printf("LayoutRead(): w[%d] = %d, h[%d] = %d, Name = %s\n", k, w[k], k, h[k], readTemp);
203
               k++;
204
 
205
               if(k == nrframes) break;
206
            }
207
         }
208
      }
209
   }
210
 
211
   ilayout.close();
212
   delete[] cTemp;
213
   delete[] cTemp2;
214
}
215
 
216
// Function for saving the current layout
217
void TGAppMainFrame::LayoutSave()
218
{
219
   TGFileInfo file_info;
220
   const char *filetypes[] = {"Layout","*.layout",0,0};
221
   char *cTemp;
222
   file_info.fFileTypes = filetypes;
223
   cTemp = new char[1024];
224
   sprintf(cTemp, "%s/layout", rootdir);
225
   file_info.fIniDir = StrDup(cTemp);
226
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info);
227
   delete[] cTemp;
228
 
229
   if(file_info.fFilename != NULL)
230
   {
231
      if(DBGSIG) printf("LayoutSave(): The layout save name: %s\n", file_info.fFilename);
232
 
233
      std::ofstream olayout;
234
 
235
      olayout.open(file_info.fFilename, std::ofstream::out);
236
      if(olayout.is_open())
237
      {
238
         olayout << "# Whole window width and height" << std::endl;
239
         olayout << fMain->GetWidth() << "\t" << fMain->GetHeight() << "\tmain" << std::endl << std::endl;
240
         olayout << "# Measurement subwindows width and height" << std::endl;
241
         for(int i = 0; i < measwin; i++)
242
            olayout << measLayout[i]->GetWidth() << "\t" << measLayout[i]->GetHeight() << "\tmeasurementwindow" << i << std::endl;
243
         olayout << std::endl;
244
         olayout << "# Analysis subwindows width and height" << std::endl;
245
         for(int i = 0; i < analysiswin; i++)
246
            olayout << analysisLayout[i]->GetWidth() << "\t" << analysisLayout[i]->GetHeight() << "\tanalysiswindow" << i << std::endl;
247
      }
248
      else
249
         printf("Error! Save file can not be opened (please do not use default.layout since it is write protected).\n");
250
      olayout.close();
251
   }
252
}
253
 
254
// Function for setting a user created layout
255
void TGAppMainFrame::LayoutSet()
256
{
257
   TGFileInfo file_info;
258
   int ret = 0;
259
   const char *filetypes[] = {"Layout","*.layout",0,0};
260
   char *cTemp, *layoutdir;
261
   file_info.fFileTypes = filetypes;
262
   layoutdir = new char[1024];
263
   sprintf(layoutdir, "%s/layout", rootdir);
264
   file_info.fIniDir = StrDup(layoutdir);
265
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info);
266
 
267
   if(file_info.fFilename != NULL)
268
   {
269
      if(DBGSIG) printf("LayoutSet(): The layout save name: %s\n", file_info.fFilename);
270
      cTemp = new char[512];
271
      remove_before_last(file_info.fFilename, '/', cTemp);
272
      if(DBGSIG) printf("LayoutSet(): New selected layout: %s\n", cTemp);
273
 
274
      FILE *fp;
275
      sprintf(layoutdir, "%s/layout/selected_layout.txt", rootdir);
276
      fp = fopen(layoutdir, "w");
277
      fprintf(fp, "%s", cTemp);
278
      fclose(fp);
279
 
280
      sprintf(layoutdir, "Please restart the program to enable the selected layout (%s) for future use.", cTemp);
281
      new TGMsgBox(gClient->GetRoot(), fMain, "Setting new layout", layoutdir, kMBIconAsterisk, kMBOk, &ret);
282
      delete[] cTemp;
283
   }
284
   delete[] layoutdir;
285
}
286
 
287
// Layout function for the main window (width and height)
288
void layoutMainWindow(int *w, int *h)
289
{
290
   std::ifstream ilayout;
291
 
292
   char *cTemp, *cTemp2, readTemp[1024];
293
   cTemp = new char[512];
294
   cTemp2 = new char[512];
295
   sprintf(cTemp, "%s/layout/selected_layout.txt", rootdir);
296
   ilayout.open(cTemp, std::ifstream::in);
297
   if(ilayout.is_open())
298
   {
299
      ilayout >> cTemp2;
300
   }
301
   ilayout.close();
302
   if(DBGSIG) printf("layoutMainWindow(): Loaded layout file is: %s\n", cTemp2);
303
 
304
   sprintf(cTemp, "%s/layout/%s", rootdir, cTemp2);
305
   ilayout.open(cTemp, std::ifstream::in);
306
   if(ilayout.is_open())
307
   {
308
      while(1)
309
      {
310
         if(ilayout.peek() == '#')
311
            ilayout.getline(readTemp, 1024, '\n');
312
         else if(ilayout.peek() == '\n')
313
            ilayout.ignore(1, '\n');
314
         else
315
         {  
316
            ilayout >> *w >> *h;
317
            if(DBGSIG > 1) printf("layoutMainWindow(): W = %d, H = %d\n", *w, *h);
318
            break;
319
         }
320
      }
321
   }
322
 
323
   ilayout.close();
324
   delete[] cTemp;
325
   delete[] cTemp2;
326
}
327