]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mathplot.cxx
bf519013eec252d10a83c4f04e186272c9b6659c
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / mathplot.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 // Name:        mathplot.cpp
28 // Purpose:     Framework for mathematical graph plotting in wxWindows
29 // Author:      David Schalig
30 // Modified by:
31 // Created:     21/07/2003
32 // Copyright:   (c) David Schalig
33 // Licence:     wxWindows licence
34 /////////////////////////////////////////////////////////////////////////////
35
36 /*EED
37 #ifdef __GNUG__
38 #pragma implementation "plot.h"
39 #endif
40 */
41 // For compilers that support precompilation, includes "wx.h".
42 #include "wx/wxprec.h"
43 #ifdef __BORLANDC__
44 #pragma hdrstop
45 #endif
46
47 /*EED
48 #ifndef WX_PRECOMP
49 #include "wx/object.h"
50 #include "wx/font.h"
51 #include "wx/colour.h"
52 #include "wx/settings.h"
53 #include "wx/sizer.h"
54 #include "wx/log.h"
55 #include "wx/intl.h"
56 #include "wx/dcclient.h"
57 #endif
58
59 // EED
60 #ifndef WX_PRECOMP
61 #include <wx/wx.h>
62 #endif
63 */
64
65
66 #include "mathplot.h"
67 //#include "wx/bmpbuttn.h"
68 //#include "wx/module.h"
69
70 //#include <math.h>
71
72 //-----------------------------------------------------------------------------
73 // mpLayer
74 //-----------------------------------------------------------------------------
75
76 IMPLEMENT_ABSTRACT_CLASS(mpLayer, wxObject)
77
78 mpLayer::mpLayer()
79 {
80 // EED wx 2.8.5
81 //      SetPen( *wxBLACK_PEN);
82 //      SetFont(*wxNORMAL_FONT);
83
84         wxFont ff( *wxNORMAL_FONT);
85         wxPen pp( *wxBLACK_PEN);
86         SetPen( pp );
87         SetFont( ff );
88
89 }
90
91 //-----------------------------------------------------------------------------
92 // mpLayer implementations - functions
93 //-----------------------------------------------------------------------------
94
95 IMPLEMENT_ABSTRACT_CLASS(mpFX, mpLayer)
96
97 mpFX::mpFX(wxString name, int flags)
98
99         SetName(name);
100         m_flags = flags; 
101 }
102
103 void mpFX::Plot(wxDC & dc, mpWindow & w)
104 {
105         dc.SetPen( m_pen);
106
107         if (m_pen.GetWidth() <= 1) 
108         {
109                 for (wxCoord i = -(w.GetScrX()>>1); i < (w.GetScrX()>>1); ++i)
110                 {
111                         dc.DrawPoint(i, (wxCoord) ((w.GetPosY() - GetY( (double)i / w.GetScaleX() + w.GetPosX()) ) * w.GetScaleY()));
112                 }
113         }
114         else
115         {
116                 for (wxCoord i = -(w.GetScrX()>>1); i < (w.GetScrX()>>1); ++i)
117                 {
118                         wxCoord c = (wxCoord) ((w.GetPosY() - GetY( (double)i / w.GetScaleX() + w.GetPosX()) ) * w.GetScaleY());
119                         dc.DrawLine( i, c, i, c);
120                 }
121         }
122
123         if (!m_name.IsEmpty())
124         {
125                 dc.SetFont(m_font);
126
127                 wxCoord tx, ty;
128                 dc.GetTextExtent(m_name, &tx, &ty);
129
130                 if ((m_flags & mpALIGNMASK) == mpALIGN_RIGHT)
131                         tx = (w.GetScrX()>>1) - tx - 8;
132                 else if ((m_flags & mpALIGNMASK) == mpALIGN_CENTER)
133                         tx = -tx/2;
134                 else
135                         tx = -(w.GetScrX()>>1) + 8;
136
137                 dc.DrawText( m_name, tx, (wxCoord) ((w.GetPosY() - GetY( (double)tx / w.GetScaleX() + w.GetPosX())) * w.GetScaleY()) );
138         }
139 }
140
141 IMPLEMENT_ABSTRACT_CLASS(mpFY, mpLayer)
142
143 mpFY::mpFY(wxString name, int flags)
144
145         SetName(name);
146         m_flags = flags;
147 }
148
149 void mpFY::Plot(wxDC & dc, mpWindow & w)
150 {
151         dc.SetPen( m_pen);
152
153         wxCoord i;
154
155         if (m_pen.GetWidth() <= 1) 
156         {
157                 for (i = -(w.GetScrY()>>1); i < (w.GetScrY()>>1); ++i)
158                 {
159                         dc.DrawPoint((wxCoord) ((GetX( (double)i / w.GetScaleY() + w.GetPosY()) - w.GetPosX()) * w.GetScaleX()), -i);
160                 }
161         }
162         else
163         {
164                 for (i = -(w.GetScrY()>>1); i < (w.GetScrY()>>1); ++i)
165                 {
166                         wxCoord c =  (wxCoord) ((GetX( (double)i / w.GetScaleY() + w.GetPosY()) - w.GetPosX()) * w.GetScaleX());
167                         dc.DrawLine(c, -i, c, -i);
168                 }
169         }
170
171         if (!m_name.IsEmpty())
172         {
173                 dc.SetFont(m_font);
174
175                 wxCoord tx, ty;
176                 dc.GetTextExtent(m_name, &tx, &ty);
177
178                 if ((m_flags & mpALIGNMASK) == mpALIGN_TOP)
179                         ty = (w.GetScrY()>>1) - 8;
180                 else if ((m_flags & mpALIGNMASK) == mpALIGN_CENTER)
181                         ty = 16 - ty/2;
182                 else
183                         ty = -(w.GetScrY()>>1) + 8;
184
185                 dc.DrawText( m_name, (wxCoord) ((GetX( (double)i / w.GetScaleY() + w.GetPosY()) - w.GetPosX()) * w.GetScaleX()), -ty);
186         }
187 }
188
189 IMPLEMENT_ABSTRACT_CLASS(mpFXY, mpLayer)
190
191 mpFXY::mpFXY(wxString name, int flags)
192
193         SetName(name);
194         m_flags = flags; 
195 }
196
197 void mpFXY::Plot(wxDC & dc, mpWindow & w)
198 {
199         dc.SetPen( m_pen);
200
201         double x, y;
202         Rewind();
203
204         // for some reason DrawPoint does not use the current pen,
205         // so we use DrawLine for fat pens
206
207         if (m_pen.GetWidth() <= 1) 
208         {
209                 while (GetNextXY(x, y))
210                 {
211                         dc.DrawPoint( (wxCoord) ((x - w.GetPosX()) * w.GetScaleX()) ,
212                                 (wxCoord) ((w.GetPosY() - y) * w.GetScaleY()) );
213                 }
214         }
215         else
216         {
217                 while (GetNextXY(x, y))
218                 {
219                         wxCoord cx = (wxCoord) ((x - w.GetPosX()) * w.GetScaleX());
220                         wxCoord cy = (wxCoord) ((w.GetPosY() - y) * w.GetScaleY());
221                         dc.DrawLine(cx, cy, cx, cy);
222                 }
223         }
224
225         if (!m_name.IsEmpty())
226         {
227                 dc.SetFont(m_font);
228
229                 wxCoord tx, ty;
230                 dc.GetTextExtent(m_name, &tx, &ty);
231
232                 // xxx implement else ... if (!HasBBox())
233                 {
234                         const int sx = w.GetScrX()>>1;
235                         const int sy = w.GetScrY()>>1;
236
237                         if ((m_flags & mpALIGNMASK) == mpALIGN_NE)
238                         {
239                                 tx = sx - tx - 8;
240                                 ty = -sy + 8;
241                         }
242                         else if ((m_flags & mpALIGNMASK) == mpALIGN_NW)
243                         {
244                                 tx = -sx + 8;
245                                 ty = -sy + 8;
246                         }
247                         else if ((m_flags & mpALIGNMASK) == mpALIGN_SW)
248                         {
249                                 tx = -sx + 8;
250                                 ty = sy - 8 - ty;
251                         }
252                         else
253                         {
254                                 tx = sx - tx - 8;
255                                 ty = sy - 8 - ty;
256                         }
257                 }
258                 //else
259                 //{
260                 //}
261
262                 dc.DrawText( m_name, tx, ty);
263         }
264 }
265
266 //-----------------------------------------------------------------------------
267 // mpLayer implementations - furniture (scales, ...)
268 //-----------------------------------------------------------------------------
269
270 #define mpLN10 2.3025850929940456840179914546844
271
272 IMPLEMENT_CLASS(mpScaleX, mpLayer)
273
274 mpScaleX::mpScaleX(wxString name)
275
276         SetName(name);/*
277         SetFont(*wxSMALL_FONT);
278         SetPen(*wxGREY_PEN);*/
279
280         wxFont ff( *wxSMALL_FONT);
281         wxPen pp( *wxGREY_PEN);
282         SetPen( pp );
283         SetFont( ff );
284 }
285
286 void mpScaleX::Plot(wxDC & dc, mpWindow & w)
287 {
288         dc.SetPen( m_pen);
289         dc.SetFont( m_font);
290
291         const int orgy   = (int)(w.GetPosY() * w.GetScaleY());
292         const int extend = w.GetScrX()/2;
293
294         dc.DrawLine( -extend, orgy, extend, orgy);
295
296         const double dig  = floor( log( 128.0 / w.GetScaleX() ) / mpLN10 );
297         const double step = exp( mpLN10 * dig);
298         const double end  = w.GetPosX() + (double)extend / w.GetScaleX();
299
300         wxCoord tx, ty;
301         wxString s;
302         wxString fmt;
303         int tmp = (int)dig;
304         if (tmp>=1)
305         {
306                 fmt = wxT("%.f");
307         }
308         else
309         {
310                 tmp=8-tmp;
311                 fmt.Printf(wxT("%%.%df"), tmp >= -1 ? 2 : -tmp);
312         }
313
314         double n = floor( (w.GetPosX() - (double)extend / w.GetScaleX()) / step ) * step ;
315
316         tmp=-65535;
317         for (;n < end; n += step)
318         {
319                 const int p = (int)((n - w.GetPosX()) * w.GetScaleX());
320                 dc.DrawLine( p, orgy, p, orgy+4);
321
322                 s.Printf(fmt, n);
323                 dc.GetTextExtent(s, &tx, &ty);
324                 if ((p-tx/2-tmp) > 64)
325                 {
326                         dc.DrawText( s, p-tx/2, orgy+4);
327                         tmp=p+tx/2;
328                 }
329         }
330
331         dc.GetTextExtent(m_name, &tx, &ty);
332         dc.DrawText( m_name, extend - tx - 4, orgy + 4 + ty);
333 }
334
335 IMPLEMENT_CLASS(mpScaleY, mpLayer)
336
337 mpScaleY::mpScaleY(wxString name)
338
339         SetName(name);/*
340         SetFont(*wxSMALL_FONT);
341         SetPen(*wxGREY_PEN);*/
342         wxFont ff( *wxSMALL_FONT);
343         wxPen pp( *wxGREY_PEN);
344         SetPen( pp );
345         SetFont( ff );
346 }
347
348 void mpScaleY::Plot(wxDC & dc, mpWindow & w, int orgy)
349 {
350         dc.SetPen( m_pen);
351         dc.SetFont( m_font);
352
353         const int orgx   = -(int)(w.GetPosX() * w.GetScaleX());
354         const int extend = w.GetScrY()/2;
355
356         double sizedc = dc.GetSize().GetHeight()-orgy;
357
358         dc.DrawLine( orgx, GetYTranslated(sizedc, -extend), orgx, GetYTranslated(sizedc, extend));
359
360         const double dig  = floor( log( 128.0 / w.GetScaleY() ) / mpLN10 );
361         const double step = exp( mpLN10 * dig);
362         const double end  = w.GetPosY() + (double)extend / w.GetScaleY();
363
364         wxCoord tx, ty;
365         wxString s;
366         wxString fmt;
367         int tmp = (int)dig;
368         if (tmp>=1)
369         {
370                 fmt = wxT("%.f");
371         }
372         else
373         {
374                 tmp=8-tmp;
375                 fmt.Printf(wxT("%%.%df"), tmp >= -1 ? 2 : -tmp);
376         }
377
378         double n = floor( (w.GetPosY() - (double)extend / w.GetScaleY()) / step ) * step ;
379
380         tmp=65536;
381         for (;n < end; n += step)
382         {
383                 const int p = (int)((w.GetPosY() - n) * w.GetScaleY());
384                 dc.DrawLine( orgx, GetYTranslated(sizedc, p), orgx+4, GetYTranslated(sizedc,p));
385
386                 s.Printf(fmt, n);
387                 dc.GetTextExtent(s, &tx, &ty);
388                 if ((tmp-p+ty/2) > 32)
389                 {
390                         dc.DrawText( s, orgx+4, GetYTranslated(sizedc,p-ty/2));
391                         tmp=p-ty/2;
392                 }
393         }
394
395         dc.GetTextExtent(m_name, &tx, &ty);
396         dc.DrawText( m_name, orgx-tx-4, GetYTranslated(sizedc,-extend + ty + 4));
397 }
398
399 //-----------------------------------------------------------------------------
400 // mpWindow
401 //-----------------------------------------------------------------------------
402
403 IMPLEMENT_DYNAMIC_CLASS(mpWindow, wxScrolledWindow)
404
405 BEGIN_EVENT_TABLE(mpWindow, wxScrolledWindow)
406 EVT_PAINT    ( mpWindow::OnPaint)
407 EVT_SIZE     ( mpWindow::OnSize)
408 EVT_SCROLLWIN( mpWindow::OnScroll2)
409
410 EVT_MIDDLE_UP( mpWindow::OnShowPopupMenu)
411 EVT_RIGHT_UP ( mpWindow::OnShowPopupMenu)
412 EVT_MENU( mpID_CENTER,    mpWindow::OnCenter)
413 EVT_MENU( mpID_FIT,       mpWindow::OnFit)
414 EVT_MENU( mpID_ZOOM_IN,   mpWindow::OnZoomIn)
415 EVT_MENU( mpID_ZOOM_OUT,  mpWindow::OnZoomOut)
416 //EVT_MENU( mpID_LINE_GUIDES, mpWindow::OnGuideLines)
417 // New method that belongs to the mpWindow
418 EVT_MENU( mpID_LOCKASPECT,mpWindow::OnLockAspect)
419 END_EVENT_TABLE()
420
421 mpWindow::mpWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
422 : wxScrolledWindow( parent, id, wxDefaultPosition, wxDefaultSize, flag, wxT("wxPlotter") )
423 {
424         m_scaleX = m_scaleY = 1.0;
425         m_posX   = m_posY   = 0;
426         m_scrX   = m_scrY   = 64;
427         m_minX   = m_minY   = 0;
428         m_maxX   = m_maxY   = 0;
429         maxScrX = maxScrY   = 200;
430         minScrX = minScrY   = 0;
431         m_clickedX =  0;
432         m_clickedY = 5000;
433         m_lockaspect = FALSE;
434         offsetX = offsetY = 0;
435         offsetPixelX = offsetPixelY= 0;
436         _bitmap_functions=NULL;
437
438         real_guideLine_X = -1;
439         real_guideLine_Y = -1;
440         drawGuides = true;
441         type=1;
442
443         m_popmenu.Append( mpID_CENTER,     _("Center"),      _("Center plot view to this position"));
444         m_popmenu.Append( mpID_FIT,        _("Fit"),         _("Set plot view to show all items"));
445         m_popmenu.Append( mpID_ZOOM_IN,    _("Zoom in"),     _("Zoom in plot view."));
446         m_popmenu.Append( mpID_ZOOM_OUT,   _("Zoom out"),    _("Zoom out plot view."));
447         m_popmenu.AppendCheckItem( mpID_LOCKASPECT, _("Lock aspect"), _("Lock horizontal and vertical zoom aspect."));
448
449         m_popmenu.AppendCheckItem( mpID_LINE_GUIDES, _("Turn off guide lines"), _("Enables/Disables the guide lines"));
450
451         m_layers.DeleteContents(TRUE);
452         SetBackgroundColour( *wxWHITE );
453         EnableScrolling(FALSE, FALSE);
454         SetSizeHints(128, 128);
455         
456         //_bitmap_functions= new wxBitmap(700,800);
457
458         UpdateAll();
459 }
460
461 mpWindow::~mpWindow()
462 {
463 }
464
465 void mpWindow::Fit()
466 {
467         if (UpdateBBox())
468         {
469                 int cx, cy;
470                 GetClientSize( &cx, &cy);
471                 
472                 double d;
473                 d = m_maxX - m_minX;
474                 if (d!=0)
475                 {
476                         m_scaleX = cx/d;
477                         m_posX = m_minX + d/2;
478                 }
479                 d = m_maxY - m_minY;
480                 if (d!=0)
481                 {
482                         m_scaleY = cy/d;
483                         m_posY = m_minY + d/2;
484                 }
485
486                 if (m_lockaspect)
487                 {
488                         double s = (m_scaleX + m_scaleY)/2;
489                         m_scaleX = s;
490                         m_scaleY = s;
491                 }
492
493                 UpdateAll();
494         }
495 }
496
497 void mpWindow::ZoomIn()
498 {
499         m_scaleX = m_scaleX * 2;
500         m_scaleY = m_scaleY * 2;
501         UpdateAll();
502 }
503
504 void mpWindow::ZoomOut()
505 {
506         m_scaleX = m_scaleX / 2;
507         m_scaleY = m_scaleY / 2;
508         UpdateAll();
509 }
510
511 void mpWindow::LockAspect(bool enable)
512 {
513         m_lockaspect = enable;
514
515         m_popmenu.Check(mpID_LOCKASPECT, enable);
516
517         if (m_lockaspect)
518         {
519                 double s = (m_scaleX + m_scaleY)/2;
520                 m_scaleX = s;
521                 m_scaleY = s;
522         }
523
524         UpdateAll();
525 }
526
527 void mpWindow::OnShowPopupMenu(wxMouseEvent &event)
528 {
529         m_clickedX = event.GetX();
530         m_clickedY = event.GetY();
531         PopupMenu( &m_popmenu, event.GetX(), event.GetY());
532 }
533
534 void mpWindow::OnLockAspect(wxCommandEvent &event)
535 {
536         LockAspect( !m_popmenu.IsChecked(mpID_LOCKASPECT) );
537 }
538
539 void mpWindow::OnFit(wxCommandEvent &event)
540 {
541         Fit();
542 }
543
544 void mpWindow::OnCenter(wxCommandEvent &event)
545 {
546         int cx, cy;
547         GetClientSize(&cx, &cy);
548         SetPos( (double)(m_clickedX-cx/2) / m_scaleX + m_posX, (double)(cy/2-m_clickedY) / m_scaleY + m_posY);
549 }
550
551 void mpWindow::OnZoomIn(wxCommandEvent &event)
552 {
553         int cx, cy;
554         GetClientSize(&cx, &cy);
555         m_posX = (double)(m_clickedX-cx/2) / m_scaleX + m_posX;
556         m_posY = (double)(cy/2-m_clickedY) / m_scaleY + m_posY;
557         ZoomIn();
558 }
559
560 void mpWindow::OnZoomOut(wxCommandEvent &event)
561 {
562         ZoomOut();
563 }
564
565 void mpWindow::OnSize( wxSizeEvent &event )
566 {
567         UpdateAll();
568 }
569
570 bool mpWindow::AddLayer( mpLayer* layer)
571 {
572         bool ret = m_layers.Append( layer) != NULL;
573         UpdateAll();
574         return ret;
575 }
576
577 void mpWindow::DelLayer( mpLayer* layer)
578 {
579         m_layers.DeleteObject( layer);
580         UpdateAll();
581 }
582
583 void mpWindow::Refresh(bool eraseBackground, const wxRect* rect)
584 {
585         wxScrolledWindow::Refresh(false);
586 }
587
588
589 void mpWindow::OnPaint( wxPaintEvent &event )
590 {
591         wxPaintDC dc(this);
592         dc.GetSize(&m_scrX, &m_scrY);
593
594         //m_scrX=200;
595         //m_scrY=200;
596
597         wxMemoryDC temp_dc;
598         //_bitmap_functions->SetWidth(m_scrX);
599         //_bitmap_functions->SetHeight(m_scrY);
600         _bitmap_functions=new wxBitmap(m_scrX,m_scrY);
601         temp_dc.SelectObject(*_bitmap_functions);
602
603         // Background
604         //      wxColour colourParent =  wxColour(255,0,0);
605         temp_dc.SetBrush(wxBrush( *wxWHITE_BRUSH  ) );
606         temp_dc.SetPen(wxPen( *wxBLACK_PEN  ));
607         temp_dc.DrawRectangle(0,0,m_scrX,m_scrY);
608         
609
610         wxNode *node = m_layers.GetFirst();
611         while (node)
612         {
613                 ((mpLayer*)node->GetData())->Plot( temp_dc, *this);
614                 node = node->GetNext();
615         }
616         
617         //dc.SetDeviceOrigin(70,40);
618         //dc.SetAxisOrientation(false,true);
619         //temp_dc.SetAxisOrientation(true,false);
620         
621         //EED 14mai2009
622         //dc.Blit(0,0, m_scrX, m_scrY, &temp_dc,-70,-m_scrY+40);
623         
624         temp_dc.SetDeviceOrigin(0,0);
625         dc.Blit(0,0, m_scrX, m_scrY, &temp_dc,0,0);
626         
627         
628         delete _bitmap_functions; 
629         //_bitmap_functions
630         //dc.SetAxisOrientation(false,true);
631
632
633 }
634
635 /*
636 void mpWindow::OnPaint( wxPaintEvent &event )
637 {
638         wxPaintDC dc(this);
639         
640         //dc.BeginDrawing();
641         
642         dc.GetSize(&m_scrX, &m_scrY);
643         
644         //const int orgy   = m_scrY-40;
645         //dc.SetDeviceOrigin(70,orgy);
646         //dc.SetAxisOrientation(true,true);
647
648 //      wxMemoryDC temp_dc;
649 //      
650 //      //_bitmap_functions=new wxBitmap(m_scrX,m_scrY);
651 //      
652 //      _bitmap_functions->SetWidth(100);//m_scrX);
653 //      _bitmap_functions->SetHeight(200);//m_scrY);
654 //      
655 //      temp_dc.SelectObject(*_bitmap_functions);
656 //      
657 //      // Background
658 //      wxColour colourParent =  wxColour(255,0,0);
659 //      temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
660 //      temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID  ));
661 //      temp_dc.DrawRectangle(0,0,100,200);
662 //      dc.Blit(0,0, 100, 200, &temp_dc,0,0);
663 //      //dc.SetDeviceOrigin( m_scrX>>1, m_scrY>>1);
664
665         wxNode *node = m_layers.GetFirst();
666         while (node)
667         {
668                 ((mpLayer*)node->GetData())->Plot( dc, *this);
669                 node = node->GetNext();
670         }
671         //temp_dc.SetAxisOrientation(true,false);
672         //dc.EndDrawing();
673         // dc.SetAxisOrientation(true,true);
674          //dc.Blit(70,(int)(-m_scrY+40),m_scrX-100,m_scrY-50,&temp_dc,0,0);
675 }
676 */
677
678 void mpWindow::OnScroll2(wxScrollWinEvent &event)
679 {
680         int width, height;
681         GetClientSize( &width, &height);
682         int px, py;
683         GetViewStart( &px, &py);
684
685         if (event.GetOrientation() == wxHORIZONTAL)
686         {
687                 SetPosX( (double)px / GetScaleX() + m_minX + (double)(width>>1)/GetScaleX());
688         }
689         else
690         {
691                 SetPosY( m_maxY - (double)py / GetScaleY() - (double)(height>>1)/GetScaleY());
692         }
693         event.Skip();
694 }
695
696 bool mpWindow::UpdateBBox()
697 {
698         bool first = TRUE;
699
700         wxNode *node = m_layers.GetFirst();
701
702         while(node)
703         {
704                 mpLayer* f = (mpLayer*)node->GetData();
705
706                 if (f->HasBBox())
707                 {
708                         if (first)
709                         {
710                                 first = FALSE;
711                                 m_minX = f->GetMinX(); m_maxX=f->GetMaxX();
712                                 m_minY = f->GetMinY(); m_maxY=f->GetMaxY();
713                         }
714                         else
715                         {
716                                 if (f->GetMinX()<m_minX) m_minX=f->GetMinX(); if (f->GetMaxX()>m_maxX) m_maxX=f->GetMaxX();
717                                 if (f->GetMinY()<m_minY) m_minY=f->GetMinY(); if (f->GetMaxY()>m_maxY) m_maxY=f->GetMaxY();
718                         }
719                 }
720                 node = node->GetNext();
721         }
722
723         return first == FALSE;
724 }
725
726 void mpWindow::UpdateAll()
727 {
728         if (UpdateBBox())
729         {
730                 int cx, cy;
731                 GetClientSize( &cx, &cy);
732
733                 const int sx = (int)((m_maxX - m_minX) * GetScaleX()); // JPRx
734                 const int sy = (int)((m_maxY - m_minY) * GetScaleY()); // JPRx
735                 const int px = (int)((GetPosX() - m_minX) * GetScaleX() - (cx>>1)); // JPRx
736                 const int py = (int)((GetPosY() - m_minY) * GetScaleY() - (cy>>1)); // JPRx
737                 SetScrollbars( 1, 1, sx, sy, px, py);
738         }
739
740         FitInside();
741         Refresh( false );
742 }
743
744 /*
745 * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES cimmand event
746 * event The corresponding event to handle
747 */
748 /*
749 void mpWindow :: OnGuideLines (wxCommandEvent   &event)
750 {
751         wxString nextAction_text;
752         if( drawGuides )
753         {
754                 setLineGuidesCondition(false);
755                 nextAction_text << "Turn on guide lines";
756                 UpdateAll();
757         }
758         else
759         {
760                 setLineGuidesCondition(true);
761                 nextAction_text << "Turn off guide lines";
762                 UpdateAll();
763         }
764         m_popmenu.SetLabel ( mpID_LINE_GUIDES, nextAction_text ); 
765 }
766 */
767
768
769
770 bool mpWindow::drawGuideLines()
771         {
772                 return drawGuides;
773         }       
774