source: trunk/src/testing/app/JuxtaView/UI/JuxtaSCUI.cpp @ 4

Revision 4, 14.1 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/*=============================================================================
2
3  Program: JuxtaView for SAGE
4  Module:  JuxtaSCUI.cpp - Part of JuxtaView's UI
5  Authors: Arun Rao, arao@evl.uic.edu,
6           Ratko Jagodic, rjagodic@evl.uic.edu,
7           Nicholas Schwarz, schwarz@evl.uic.edu,
8           et al.
9  Date:    30 September 2004
10  Modified: 28 October 2004
11
12  Copyright (c) 2005 Electronic Visualization Laboratory,
13                     University of Illinois at Chicago
14
15  All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are met:
19 *
20 *  * Redistributions of source code must retain the above copyright
21 *    notice, this list of conditions and the following disclaimer.
22 *  * Redistributions in binary form must reproduce the above
23 *    copyright notice, this list of conditions and the following disclaimer
24 *    in the documentation and/or other materials provided with the distribution.
25 *  * Neither the name of the University of Illinois at Chicago nor
26 *    the names of its contributors may be used to endorse or promote
27 *    products derived from this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
33 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41  Direct questions, comments, etc. to schwarz@evl.uic.edu or
42  http://www.evl.uic.edu/cavern/forum/
43
44=============================================================================*/
45
46#include "JuxtaSCUI.h"
47
48void SkipComments(FILE* fin,char commentFlag);
49#define COMMENT_FLAG '#'
50
51JuxtaSCUIFrame::JuxtaSCUIFrame(bool ov, char* skinfilename,wxWindow* parent, int id, const wxString& title,
52                           const wxPoint& pos, const wxSize& size, long style)
53                           :wxFrame(parent,id,title,pos,size,style)
54{
55        QUANTAinit();
56        client = NULL;
57
58
59        //---------setup the ui
60        wxImage* img;
61        wxBitmapButton* bmpbtn;
62        wxBitmap* bmp;
63        wxPanel* panel;
64        char buffer[100];
65        char background[100];
66        char upfile[100];
67        char downfile[100];
68        int xpos,ypos;
69
70        gApp->SetTopWindow(this);
71
72        panel = new wxPanel(this,-1);
73
74        //background
75        wxInitAllImageHandlers();
76        FILE* skinfile = NULL;
77
78        if(skinfilename == NULL)
79                skinfile = fopen("Skins/default.jsk","r");
80        else
81                skinfile = fopen(skinfilename,"r");
82
83        if(skinfile == NULL)
84                return;
85
86        SkipComments(skinfile,COMMENT_FLAG);
87
88        //get the background filename
89        fscanf(skinfile,"%s\n",background);
90        img = new wxImage(wxCSTRINGCAST(background));
91        bmp = new wxBitmap((*img));
92        statbmp = new wxStaticBitmap(panel,20,(*bmp),wxPoint(0,0));
93#if defined(_WIN32) || defined(WIN32) || defined(WINDOWS) || defined(_WINDOWS_)
94        statbmp->Disable();     //to make sure the button pushes go to the buttons, not the background image
95#endif
96
97        //get the pan up info
98        SkipComments(skinfile,COMMENT_FLAG);
99        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
100        img = new wxImage(upfile);
101        bmpbtn = new wxBitmapButton(panel,ID_PanUp,(*img),wxPoint(xpos,ypos),
102                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
103        img = new wxImage(downfile);
104        bmpbtn->SetBitmapSelected((*img));
105        bmpbtn->SetToolTip(buffer);
106
107        //get the pan down info
108        SkipComments(skinfile,COMMENT_FLAG);
109        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
110        img = new wxImage(upfile);
111        bmpbtn = new wxBitmapButton(panel,ID_PanDown,(*img),wxPoint(xpos,ypos),
112                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
113        img = new wxImage(downfile);
114        bmpbtn->SetBitmapSelected((*img));
115        bmpbtn->SetToolTip(buffer);
116
117        //get the pan left info
118        SkipComments(skinfile,COMMENT_FLAG);
119        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
120        img = new wxImage(upfile);
121        bmpbtn = new wxBitmapButton(panel,ID_PanLeft,(*img),wxPoint(xpos,ypos),
122                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
123        img = new wxImage(downfile);
124        bmpbtn->SetBitmapSelected((*img));
125        bmpbtn->SetToolTip(buffer);
126
127        //get the pan right info
128        SkipComments(skinfile,COMMENT_FLAG);
129        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
130        img = new wxImage(upfile);
131        bmpbtn = new wxBitmapButton(panel,ID_PanRight,(*img),wxPoint(xpos,ypos),
132                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
133        img = new wxImage(downfile);
134        bmpbtn->SetBitmapSelected((*img));
135        bmpbtn->SetToolTip(buffer);
136
137        //get the fast pan up info
138        SkipComments(skinfile,COMMENT_FLAG);
139        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
140        img = new wxImage(upfile);
141        bmpbtn = new wxBitmapButton(panel,ID_FastPanUp,(*img),wxPoint(xpos,ypos),
142                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
143        img = new wxImage(downfile);
144        bmpbtn->SetBitmapSelected((*img));
145        bmpbtn->SetToolTip(buffer);
146
147        //load up the fast pan down button
148        SkipComments(skinfile,COMMENT_FLAG);
149        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
150        img = new wxImage(upfile);
151        bmpbtn = new wxBitmapButton(panel,ID_FastPanDown,(*img),wxPoint(xpos,ypos),
152                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
153        img = new wxImage(downfile);
154        bmpbtn->SetBitmapSelected((*img));
155        bmpbtn->SetToolTip(buffer);
156
157        //load up the fast pan left button
158        SkipComments(skinfile,COMMENT_FLAG);
159        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
160        img = new wxImage(upfile);
161        bmpbtn = new wxBitmapButton(panel,ID_FastPanLeft,(*img),wxPoint(xpos,ypos),
162                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
163        img = new wxImage(downfile);
164        bmpbtn->SetBitmapSelected((*img));
165        bmpbtn->SetToolTip(buffer);
166
167        //load up the fast pan right button
168        SkipComments(skinfile,COMMENT_FLAG);
169        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
170        img = new wxImage(upfile);
171        bmpbtn = new wxBitmapButton(panel,ID_FastPanRight,(*img),wxPoint(xpos,ypos),
172                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
173        img = new wxImage(downfile);
174        bmpbtn->SetBitmapSelected((*img));
175        bmpbtn->SetToolTip(buffer);
176
177        //load up the zoom in button
178        SkipComments(skinfile,COMMENT_FLAG);
179        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
180        img = new wxImage(upfile);
181        bmpbtn = new wxBitmapButton(panel,ID_ZoomIn,(*img),wxPoint(xpos,ypos),
182                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
183        img = new wxImage(downfile);
184        bmpbtn->SetBitmapSelected((*img));
185        bmpbtn->SetToolTip(buffer);
186
187        //load up the zoom out button
188        SkipComments(skinfile,COMMENT_FLAG);
189        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
190        img = new wxImage(upfile);
191        bmpbtn = new wxBitmapButton(panel,ID_ZoomOut,(*img),wxPoint(xpos,ypos),
192                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
193        img = new wxImage(downfile);
194        bmpbtn->SetBitmapSelected((*img));
195        bmpbtn->SetToolTip(buffer);
196
197        //load up the Quit button
198        SkipComments(skinfile,COMMENT_FLAG);
199        fscanf(skinfile,"%s %s %s (%d,%d)\n",buffer,upfile,downfile,&xpos,&ypos);
200        img = new wxImage(upfile);
201        bmpbtn = new wxBitmapButton(panel,ID_Quit,(*img),wxPoint(xpos,ypos),
202                                        wxSize(img->GetWidth(),img->GetHeight()),wxBORDER_NONE);
203        img = new wxImage(downfile);
204        bmpbtn->SetBitmapSelected((*img));
205        bmpbtn->SetToolTip(buffer);
206
207        fclose(skinfile);
208
209        overviewframe = NULL;
210        showoverview = ov;
211
212}
213
214
215void JuxtaSCUIFrame::Show()
216{
217        if(overviewframe && showoverview)
218                overviewframe->Show();
219
220        wxFrame::Show();
221}
222
223
224BEGIN_EVENT_TABLE( JuxtaSCUIFrame, wxFrame)
225        EVT_BUTTON( ID_PanUp, JuxtaSCUIFrame::OnEvent)
226        EVT_BUTTON( ID_PanDown, JuxtaSCUIFrame::OnEvent)
227        EVT_BUTTON( ID_PanLeft, JuxtaSCUIFrame::OnEvent)
228        EVT_BUTTON( ID_PanRight, JuxtaSCUIFrame::OnEvent)
229        EVT_BUTTON( ID_FastPanUp, JuxtaSCUIFrame::OnEvent)
230        EVT_BUTTON( ID_FastPanDown, JuxtaSCUIFrame::OnEvent)
231        EVT_BUTTON( ID_FastPanLeft, JuxtaSCUIFrame::OnEvent)
232        EVT_BUTTON( ID_FastPanRight, JuxtaSCUIFrame::OnEvent)
233        EVT_BUTTON( ID_ZoomIn, JuxtaSCUIFrame::OnEvent)
234        EVT_BUTTON( ID_ZoomOut, JuxtaSCUIFrame::OnEvent)
235        EVT_BUTTON( ID_Quit, JuxtaSCUIFrame::OnEvent)
236END_EVENT_TABLE()
237
238//------------------------------------------
239JuxtaSCUIFrame::~JuxtaSCUIFrame()
240{
241
242        if(client)
243        {
244                PassEvent(JVQUIT);
245                client->close();
246                delete client;
247        }
248
249}
250
251
252//------------------------------------------
253void JuxtaSCUIFrame::Init(char* configfilename)
254{
255        FILE* fin = fopen(configfilename,"r");
256        if(!fin)
257                return;
258
259        char ip[32];
260        int port;
261        memset(ip,0,32);
262
263        fscanf(fin,"%s : %d\n",ip,&port);
264
265        client = new QUANTAnet_tcpClient_c();
266        if( client->connectToServer(ip,port) < 0)
267        {
268                client->close();
269                delete client;
270                client = NULL;
271#if DEBUG
272                wxMessageBox("Failed To Connect To Server.\nMake sure juxtauiclient.conf file has correct server ip and port number.\nCorrect format is \"server ip\" : \"port number\"");
273#endif
274        }
275        else
276        {
277                //make sure the user didn't disable the overview
278                if(showoverview)
279                {
280                        fprintf(stderr,"Attempting to load overview\n");
281                        //ask for the overview!!!!
282                        overviewframe = new JuxtaOverviewFrame(gApp->GetTopWindow(),
283                                                        -1,"Overview",
284                                                        wxPoint(wxWindow::GetSize().GetWidth(),0),
285                                                        wxSize(100,200),
286                                                        wxMINIMIZE_BOX | wxFRAME_NO_TASKBAR | wxRESIZE_BORDER);
287                        overviewframe->Layout();
288                        overviewframe->Show();
289
290                        GetOverview();
291                        GetExtents();
292                }
293                else
294                {
295                        fprintf(stderr,"Not attempting to make overview\n");
296                        overviewframe = new JuxtaOverviewFrame(0,-1,"",wxPoint(0,0),wxSize(0,0),wxSIMPLE_BORDER);
297                        overviewframe->Layout();
298                        overviewframe->Show();
299                }
300
301                fflush(stderr);
302
303        }
304
305        fclose(fin);
306}
307
308//------------------------------------------
309void JuxtaSCUIFrame::OnEvent(wxCommandEvent& event)
310{
311
312        //disable all buttons but quit
313        //here's the tree
314        //      this
315        //      |_______panel
316        //              |________All the buttons!!!!!!
317
318//      this->GetChildren().GetFirst()->GetData()->Disable();
319
320        switch(event.GetId())
321        {
322        case ID_FastPanLeft:
323                PassEvent(JVFAST_PAN_LEFT);
324                break;
325        case ID_FastPanRight:
326                PassEvent(JVFAST_PAN_RIGHT);
327                break;
328        case ID_FastPanUp:
329                PassEvent(JVFAST_PAN_UP);
330                break;
331        case ID_FastPanDown:
332                PassEvent(JVFAST_PAN_DOWN);
333                break;
334        case ID_PanLeft:
335                PassEvent(JVPAN_LEFT);
336                break;
337        case ID_PanRight:
338                PassEvent(JVPAN_RIGHT);
339                break;
340        case ID_PanUp:
341                PassEvent(JVPAN_UP);
342                break;
343        case ID_PanDown:
344                PassEvent(JVPAN_DOWN);
345                break;
346        case ID_ZoomIn:
347                PassEvent(JVZOOM_IN);
348                break;
349        case ID_ZoomOut:
350                PassEvent(JVZOOM_OUT);
351                break;
352        case ID_Quit:
353                PassEvent(JVQUIT);
354                break;
355        default:
356                break;
357        }       //end switch
358
359        //ask for the extent if it's not quit
360        if( event.GetId() != ID_Quit && overviewframe && showoverview )
361        {
362                GetExtents();
363                if(overviewframe)
364                        overviewframe->Refresh();
365        }
366
367        Refresh();
368
369//      this->GetChildren().GetFirst()->GetData()->Enable();
370
371}
372//------------------------------------------
373void JuxtaSCUIFrame::PassEvent(char* strEvent)
374{
375#if DEBUG
376        fprintf(stderr,"passing event %s\n",strEvent);
377#endif
378        //pass event to server
379        static char sendBuffer[TRANSMISSION_SIZE];
380        static int size = TRANSMISSION_SIZE;
381
382        clientMutex.Lock();
383                memset(sendBuffer,0,TRANSMISSION_SIZE);
384                strcpy(sendBuffer,strEvent);
385
386                if(client)
387                {
388                        client->write(sendBuffer,&size, QUANTAnet_tcpClient_c::BLOCKING);
389                }
390        clientMutex.Unlock();
391
392}
393
394//------------------------------------------
395void JuxtaSCUIFrame::PassBuffer(void* buffer,int size)
396{
397        clientMutex.Lock();
398                if(client)
399                {
400                        client->write((const char*)buffer,&size,QUANTAnet_tcpClient_c::BLOCKING);
401                }
402        clientMutex.Unlock();
403
404}
405
406//------------------------------------------
407void JuxtaSCUIFrame::GetExtents()
408{
409#if DEBUG
410        fprintf(stderr,"Getting extents for overview\n");
411#endif
412        //pass event to server
413        static char sendBuffer[TRANSMISSION_SIZE];
414        static int sendsize = TRANSMISSION_SIZE;
415        static int readsize = sizeof(float) * 4;
416
417        memset(sendBuffer,0,TRANSMISSION_SIZE);
418        clientMutex.Lock();
419                strcpy(sendBuffer,JVEXTENTS);
420
421                float readarray[4];
422                if( client )
423                {
424                        client->write(sendBuffer,&sendsize,QUANTAnet_tcpClient_c::BLOCKING);
425                        //get four floats
426                        client->read((char*)readarray,&readsize,QUANTAnet_tcpClient_c::BLOCKING);
427                        if(overviewframe)
428                                overviewframe->SetExtentRectangle(readarray[0],readarray[1],readarray[2],readarray[3]);
429
430#if DEBUG
431                fprintf(stderr,"floats recieved: %f, %f, %f, %f\n",readarray[0],readarray[1],readarray[2],readarray[3]);
432#endif
433                }
434        clientMutex.Unlock();
435
436
437
438}
439
440void JuxtaSCUIFrame::GetOverview()
441{
442#if DEBUG
443        fprintf(stderr,"Getting overview image\n");
444#endif
445        //pass event to server
446        static char sendBuffer[TRANSMISSION_SIZE];
447        static int sendsize = TRANSMISSION_SIZE;
448        static int readsize;
449
450        memset(sendBuffer,0,TRANSMISSION_SIZE);
451
452        clientMutex.Lock();
453                strcpy(sendBuffer,JVOVERVIEW);
454
455                if(client)
456                {
457                        //ask for the overview
458                        client->write(sendBuffer,&sendsize,QUANTAnet_tcpClient_c::BLOCKING);
459
460                        //get two ints
461                        int dimarray[2];
462                        readsize = sizeof(int) * 2;
463                        client->read((char*)dimarray,&readsize,QUANTAnet_tcpClient_c::BLOCKING);
464
465                        //get pixels
466                        readsize = dimarray[0] * dimarray[1] * 3;
467                        unsigned char* img = new unsigned char[readsize];
468                        client->read((char*)img,&readsize,QUANTAnet_tcpClient_c::BLOCKING);
469
470                        if(overviewframe)
471                                overviewframe->SetImage(dimarray[0],dimarray[1],img);
472
473#if DEBUG
474                fprintf(stderr,"Got overview of dims %d x %d\n",dimarray[0],dimarray[1]);
475#endif
476
477                }
478
479        clientMutex.Unlock();
480
481}
482
483//------------------------------------------
484
485void SkipComments(FILE* fin,char commentFlag)
486{
487        char c;
488        c = fgetc(fin);
489        bool skipline;
490        if( c == commentFlag)
491        {
492                skipline = true;
493                while(skipline)
494                {
495                        while( c != '\n' && !feof(fin))
496                                c = fgetc(fin);
497
498                        if(feof(fin))
499                                return;
500
501                        long position = ftell(fin);
502                        c = fgetc(fin);
503                        if(c != commentFlag)
504                        {
505                                skipline = false;
506                                fseek(fin,position,0);
507                        }
508                }
509        }
510        else
511        {
512                fseek(fin, ftell(fin) - 1, 0);
513        }
514}
Note: See TracBrowser for help on using the repository browser.