]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mathplot.cxx
#3128 creaMaracasVisu Feature New Normal - branch changeWx28to30 compilation with...
[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         } else {
372                 tmp=8-tmp;
373                 fmt.Printf(wxT("%%.%df"), tmp >= -1 ? 2 : -tmp);
374         } // if temp
375
376         double n = floor( (w.GetPosY() - (double)extend / w.GetScaleY()) / step ) * step ;
377
378         tmp=65536;
379         for (;n < end; n += step)
380         {
381                 const int p = (int)((w.GetPosY() - n) * w.GetScaleY());
382                 dc.DrawLine( orgx, GetYTranslated(sizedc, p), orgx+4, GetYTranslated(sizedc,p));
383
384                 s.Printf(fmt, n);
385                 dc.GetTextExtent(s, &tx, &ty);
386                 if ((tmp-p+ty/2) > 32)
387                 {
388                         dc.DrawText( s, orgx+4, GetYTranslated(sizedc,p-ty/2));
389                         tmp=p-ty/2;
390                 } // if
391         } // for
392
393         dc.GetTextExtent(m_name, &tx, &ty);
394         dc.DrawText( m_name, orgx-tx-4, GetYTranslated(sizedc,-extend + ty + 4));
395 }
396
397 //-----------------------------------------------------------------------------
398 // mpWindow
399 //-----------------------------------------------------------------------------
400
401 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
402 #if wxMAJOR_VERSION <= 2
403         IMPLEMENT_DYNAMIC_CLASS(mpWindow, wxScrolledWindow)
404 #else
405         wxIMPLEMENT_DYNAMIC_CLASS(mpWindow, wxScrolledWindow);
406 #endif
407
408
409 BEGIN_EVENT_TABLE(mpWindow, wxScrolledWindow)
410 EVT_PAINT    ( mpWindow::OnPaint)
411 EVT_SIZE     ( mpWindow::OnSize)
412 EVT_SCROLLWIN( mpWindow::OnScroll2)
413
414 EVT_MIDDLE_UP( mpWindow::OnShowPopupMenu)
415 EVT_RIGHT_UP ( mpWindow::OnShowPopupMenu)
416 EVT_MENU( mpID_CENTER,    mpWindow::OnCenter)
417 EVT_MENU( mpID_FIT,       mpWindow::OnFit)
418 EVT_MENU( mpID_ZOOM_IN,   mpWindow::OnZoomIn)
419 EVT_MENU( mpID_ZOOM_OUT,  mpWindow::OnZoomOut)
420 //EVT_MENU( mpID_LINE_GUIDES, mpWindow::OnGuideLines)
421 // New method that belongs to the mpWindow
422 EVT_MENU( mpID_LOCKASPECT,mpWindow::OnLockAspect)
423 END_EVENT_TABLE()
424
425 mpWindow::mpWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
426 : wxScrolledWindow( parent, id, wxDefaultPosition, wxDefaultSize, flag, wxT("wxPlotter") )
427 {
428         m_scaleX                        = m_scaleY              = 1.0;
429         m_posX                          = m_posY                = 0;
430         m_scrX                          = m_scrY                = 64;
431         m_minX                          = m_minY                = 0;
432         m_maxX                          = m_maxY                = 0;
433         maxScrX                         = maxScrY       = 200;
434         minScrX                         = minScrY       = 0;
435         m_clickedX                      = 0;
436         m_clickedY                      = 5000;
437         m_lockaspect            = FALSE;
438         offsetX                         = offsetY               = 0;
439         offsetPixelX            = offsetPixelY  = 0;
440         _bitmap_functions       = NULL;
441
442         real_guideLine_X        = -1;
443         real_guideLine_Y        = -1;
444         drawGuides                      = true;
445         type                            = 1;
446
447         m_popmenu.Append( mpID_CENTER,     _("Center"),      _("Center plot view to this position"));
448         m_popmenu.Append( mpID_FIT,        _("Fit"),         _("Set plot view to show all items"));
449         m_popmenu.Append( mpID_ZOOM_IN,    _("Zoom in"),     _("Zoom in plot view."));
450         m_popmenu.Append( mpID_ZOOM_OUT,   _("Zoom out"),    _("Zoom out plot view."));
451         m_popmenu.AppendCheckItem( mpID_LOCKASPECT, _("Lock aspect"), _("Lock horizontal and vertical zoom aspect."));
452
453         m_popmenu.AppendCheckItem( mpID_LINE_GUIDES, _("Turn off guide lines"), _("Enables/Disables the guide lines"));
454
455         m_layers.DeleteContents(TRUE);
456         SetBackgroundColour( *wxWHITE );
457         EnableScrolling(FALSE, FALSE);
458         SetSizeHints(128, 128);
459         
460         //_bitmap_functions= new wxBitmap(700,800);
461
462         UpdateAll();
463 }
464
465 mpWindow::~mpWindow()
466 {
467 }
468
469 void mpWindow::Fit()
470 {
471         if (UpdateBBox())
472         {
473                 int cx, cy;
474                 GetClientSize( &cx, &cy);
475                 
476                 double d;
477                 d = m_maxX - m_minX;
478                 if (d!=0)
479                 {
480                         m_scaleX = cx/d;
481                         m_posX = m_minX + d/2;
482                 }
483                 d = m_maxY - m_minY;
484                 if (d!=0)
485                 {
486                         m_scaleY = cy/d;
487                         m_posY = m_minY + d/2;
488                 }
489
490                 if (m_lockaspect)
491                 {
492                         double s = (m_scaleX + m_scaleY)/2;
493                         m_scaleX = s;
494                         m_scaleY = s;
495                 }
496
497                 UpdateAll();
498         }
499 }
500
501 void mpWindow::ZoomIn()
502 {
503         m_scaleX = m_scaleX * 2;
504         m_scaleY = m_scaleY * 2;
505         UpdateAll();
506 }
507
508 void mpWindow::ZoomOut()
509 {
510         m_scaleX = m_scaleX / 2;
511         m_scaleY = m_scaleY / 2;
512         UpdateAll();
513 }
514
515 void mpWindow::LockAspect(bool enable)
516 {
517         m_lockaspect = enable;
518         m_popmenu.Check(mpID_LOCKASPECT, enable);
519         if (m_lockaspect)
520         {
521                 double s = (m_scaleX + m_scaleY)/2;
522                 m_scaleX = s;
523                 m_scaleY = s;
524         }
525         UpdateAll();
526 }
527
528 void mpWindow::OnShowPopupMenu(wxMouseEvent &event)
529 {
530         m_clickedX = event.GetX();
531         m_clickedY = event.GetY();
532         PopupMenu( &m_popmenu, event.GetX(), event.GetY());
533 }
534
535 void mpWindow::OnLockAspect(wxCommandEvent &event)
536 {
537         LockAspect( !m_popmenu.IsChecked(mpID_LOCKASPECT) );
538 }
539
540 void mpWindow::OnFit(wxCommandEvent &event)
541 {
542         Fit();
543 }
544
545 void mpWindow::OnCenter(wxCommandEvent &event)
546 {
547         int cx, cy;
548         GetClientSize(&cx, &cy);
549         SetPos( (double)(m_clickedX-cx/2) / m_scaleX + m_posX, (double)(cy/2-m_clickedY) / m_scaleY + m_posY);
550 }
551
552 void mpWindow::OnZoomIn(wxCommandEvent &event)
553 {
554         int cx, cy;
555         GetClientSize(&cx, &cy);
556         m_posX = (double)(m_clickedX-cx/2) / m_scaleX + m_posX;
557         m_posY = (double)(cy/2-m_clickedY) / m_scaleY + m_posY;
558         ZoomIn();
559 }
560
561 void mpWindow::OnZoomOut(wxCommandEvent &event)
562 {
563         ZoomOut();
564 }
565
566 void mpWindow::OnSize( wxSizeEvent &event )
567 {
568         UpdateAll();
569 }
570
571 bool mpWindow::AddLayer( mpLayer* layer)
572 {
573         bool ret = m_layers.Append( layer) != NULL;
574         UpdateAll();
575         return ret;
576 }
577
578 void mpWindow::DelLayer( mpLayer* layer)
579 {
580         m_layers.DeleteObject( layer);
581         UpdateAll();
582 }
583
584 void mpWindow::Refresh(bool eraseBackground, const wxRect* rect)
585 {
586         wxScrolledWindow::Refresh(false);
587 }
588
589
590 void mpWindow::OnPaint( wxPaintEvent &event )
591 {
592         wxPaintDC dc(this);
593         dc.GetSize(&m_scrX, &m_scrY);
594
595         //m_scrX=200;
596         //m_scrY=200;
597
598         wxMemoryDC temp_dc;
599         //_bitmap_functions->SetWidth(m_scrX);
600         //_bitmap_functions->SetHeight(m_scrY);
601         _bitmap_functions=new wxBitmap(m_scrX,m_scrY);
602         temp_dc.SelectObject(*_bitmap_functions);
603
604         // Background
605         //      wxColour colourParent =  wxColour(255,0,0);
606         temp_dc.SetBrush(wxBrush( *wxWHITE_BRUSH  ) );
607         temp_dc.SetPen(wxPen( *wxBLACK_PEN  ));
608         temp_dc.DrawRectangle(0,0,m_scrX,m_scrY);
609         
610
611         wxNode *node = m_layers.GetFirst();
612         while (node)
613         {
614                 ((mpLayer*)node->GetData())->Plot( temp_dc, *this);
615                 node = node->GetNext();
616         }
617         
618         //dc.SetDeviceOrigin(70,40);
619         //dc.SetAxisOrientation(false,true);
620         //temp_dc.SetAxisOrientation(true,false);
621         
622         //EED 14mai2009
623         //dc.Blit(0,0, m_scrX, m_scrY, &temp_dc,-70,-m_scrY+40);
624         
625         temp_dc.SetDeviceOrigin(0,0);
626         dc.Blit(0,0, m_scrX, m_scrY, &temp_dc,0,0);
627         
628         
629         delete _bitmap_functions; 
630         //_bitmap_functions
631         //dc.SetAxisOrientation(false,true);
632
633
634 }
635
636 /*
637 void mpWindow::OnPaint( wxPaintEvent &event )
638 {
639         wxPaintDC dc(this);
640         
641         //dc.BeginDrawing();
642         
643         dc.GetSize(&m_scrX, &m_scrY);
644         
645         //const int orgy   = m_scrY-40;
646         //dc.SetDeviceOrigin(70,orgy);
647         //dc.SetAxisOrientation(true,true);
648
649 //      wxMemoryDC temp_dc;
650 //      
651 //      //_bitmap_functions=new wxBitmap(m_scrX,m_scrY);
652 //      
653 //      _bitmap_functions->SetWidth(100);//m_scrX);
654 //      _bitmap_functions->SetHeight(200);//m_scrY);
655 //      
656 //      temp_dc.SelectObject(*_bitmap_functions);
657 //      
658 //      // Background
659 //      wxColour colourParent =  wxColour(255,0,0);
660 //      temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
661 //      temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID  ));
662 //      temp_dc.DrawRectangle(0,0,100,200);
663 //      dc.Blit(0,0, 100, 200, &temp_dc,0,0);
664 //      //dc.SetDeviceOrigin( m_scrX>>1, m_scrY>>1);
665
666         wxNode *node = m_layers.GetFirst();
667         while (node)
668         {
669                 ((mpLayer*)node->GetData())->Plot( dc, *this);
670                 node = node->GetNext();
671         }
672         //temp_dc.SetAxisOrientation(true,false);
673         //dc.EndDrawing();
674         // dc.SetAxisOrientation(true,true);
675          //dc.Blit(70,(int)(-m_scrY+40),m_scrX-100,m_scrY-50,&temp_dc,0,0);
676 }
677 */
678
679 void mpWindow::OnScroll2(wxScrollWinEvent &event)
680 {
681         int width, height;
682         GetClientSize( &width, &height);
683         int px, py;
684         GetViewStart( &px, &py);
685
686         if (event.GetOrientation() == wxHORIZONTAL)
687         {
688                 SetPosX( (double)px / GetScaleX() + m_minX + (double)(width>>1)/GetScaleX());
689         }
690         else
691         {
692                 SetPosY( m_maxY - (double)py / GetScaleY() - (double)(height>>1)/GetScaleY());
693         }
694         event.Skip();
695 }
696
697 bool mpWindow::UpdateBBox()
698 {
699         bool first = TRUE;
700
701         wxNode *node = m_layers.GetFirst();
702
703         while(node)
704         {
705                 mpLayer* f = (mpLayer*)node->GetData();
706
707                 if (f->HasBBox())
708                 {
709                         if (first)
710                         {
711                                 first = FALSE;
712                                 m_minX = f->GetMinX(); m_maxX=f->GetMaxX();
713                                 m_minY = f->GetMinY(); m_maxY=f->GetMaxY();
714                         }
715                         else
716                         {
717                                 if (f->GetMinX()<m_minX) m_minX=f->GetMinX(); if (f->GetMaxX()>m_maxX) m_maxX=f->GetMaxX();
718                                 if (f->GetMinY()<m_minY) m_minY=f->GetMinY(); if (f->GetMaxY()>m_maxY) m_maxY=f->GetMaxY();
719                         }
720                 }
721                 node = node->GetNext();
722         }
723
724         return first == FALSE;
725 }
726
727 void mpWindow::UpdateAll()
728 {
729         if (UpdateBBox())
730         {
731                 int cx, cy;
732                 GetClientSize( &cx, &cy);
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         FitInside();
740         Refresh( false );
741 }
742
743 /*
744 * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES cimmand event
745 * event The corresponding event to handle
746 */
747 /*
748 void mpWindow :: OnGuideLines (wxCommandEvent   &event)
749 {
750         wxString nextAction_text;
751         if( drawGuides )
752         {
753                 setLineGuidesCondition(false);
754                 nextAction_text << "Turn on guide lines";
755                 UpdateAll();
756         }
757         else
758         {
759                 setLineGuidesCondition(true);
760                 nextAction_text << "Turn off guide lines";
761                 UpdateAll();
762         }
763         m_popmenu.SetLabel ( mpID_LINE_GUIDES, nextAction_text ); 
764 }
765 */
766
767
768
769 bool mpWindow::drawGuideLines()
770         {
771                 return drawGuides;
772         }       
773