00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "a2dprec.h"
00016
00017 #ifdef __BORLANDC__
00018 #pragma hdrstop
00019 #endif
00020
00021 #ifndef WX_PRECOMP
00022 #include "wx/wx.h"
00023 #endif
00024
00025 #include "wx/curves/plotbox.h"
00026 #include "wx/canvas/drawer.h"
00027 #include "wx/canvas/canvas.h"
00028 #include "wx/canvas/cancom.h"
00029 #include "wx/editor/sttool.h"
00030 #include "wx/editor/edit.h"
00031
00032 IMPLEMENT_DYNAMIC_CLASS(a2dPlot, a2dCanvasXYDisplayGroup)
00033 IMPLEMENT_DYNAMIC_CLASS(a2dCurveGroupLegend, a2dCanvasObject)
00034
00035
00036
00037
00038 #define text_HEIGHT_FACTOR (1.0/40)
00039 #define padding_FACTOR (1.0/100)
00040
00041 A2D_BEGIN_EVENT_TABLE( a2dPlot, a2dCanvasXYDisplayGroup )
00042 A2D_EVT_CANVASOBJECT_MOUSE_EVENT( a2dPlot::OnCanvasObjectMouseEvent )
00043 A2D_END_EVENT_TABLE()
00044
00045 a2dPlot::a2dPlot(double x, double y)
00046 :a2dCanvasXYDisplayGroup(x, y)
00047 {
00048 m_topPadding = 0;
00049 m_bottomPadding = 0;
00050 m_leftPadding = 0;
00051 m_rightPadding = 0;
00052 m_autoPlace = true;
00053 m_autoYNames = false;
00054 }
00055
00056 a2dPlot::~a2dPlot()
00057 {
00058 }
00059
00060 a2dPlot::a2dPlot( const a2dPlot &other, CloneOptions options )
00061 :a2dCanvasXYDisplayGroup( other, options )
00062 {
00063 m_topPadding = other.m_topPadding;
00064 m_bottomPadding = other.m_bottomPadding;
00065 m_leftPadding = other.m_leftPadding;
00066 m_rightPadding = other.m_rightPadding;
00067 m_autoPlace = other.m_autoPlace;
00068 m_autoYNames = other.m_autoYNames;
00069 }
00070
00071 a2dObject* a2dPlot::Clone( CloneOptions options ) const
00072 {
00073 return new a2dPlot( *this, options );
00074 }
00075
00076 void a2dPlot::SetPadding( double leftPadding, double rightPadding, double topPadding, double bottomPadding )
00077 {
00078 m_topPadding = topPadding;
00079 m_bottomPadding = bottomPadding;
00080 m_leftPadding = leftPadding;
00081 m_rightPadding = rightPadding;
00082 }
00083
00084 void a2dPlot::SetTitle( const wxString& title)
00085 {
00086 a2dText* textobj = (a2dText*) Find( _T("__TITLE__") );
00087 if ( title.IsEmpty() )
00088 ReleaseChild( textobj );
00089 else
00090 {
00091 if ( !textobj )
00092 {
00093 textobj = new a2dText( title, 0, 0, a2dFont( 10, wxSWISS ), 0 );
00094 textobj->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00095 textobj->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00096
00097 Append(textobj);
00098 textobj->SetName( _T("__TITLE__") );
00099 }
00100 else
00101 textobj->SetText( title );
00102 }
00103 }
00104
00105 void a2dPlot::SetXLabel( const wxString& xlabel, const wxColour& color)
00106 {
00107 a2dText* textobj = (a2dText*) Find( _T("__XLABEL__") );
00108 if ( xlabel.IsEmpty() )
00109 ReleaseChild( textobj );
00110 else
00111 {
00112 if ( !textobj )
00113 {
00114 textobj = new a2dText( xlabel, 0, 0, a2dFont( 10, wxSWISS ), 0 );
00115 textobj->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00116 textobj->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00117 Append(textobj);
00118 textobj->SetName( _T("__XLABEL__") );
00119 }
00120 else
00121 textobj->SetText( xlabel );
00122 if( color != wxNullColour )
00123 textobj->SetStroke(color);
00124 }
00125 }
00126
00127 void a2dPlot::SetY1Label( const wxString& ylabel, const wxColour& color)
00128 {
00129 a2dText* textobj = (a2dText*) Find( _T("__Y1LABEL__") );
00130 if ( ylabel.IsEmpty() )
00131 ReleaseChild( textobj );
00132 else
00133 {
00134 if ( !textobj )
00135 {
00136 textobj = new a2dText( ylabel, 0, 0, a2dFont( 10, wxSWISS ), 0 );
00137 textobj->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00138 textobj->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00139 Append(textobj);
00140 textobj->SetName( _T("__Y1LABEL__") );
00141 }
00142 else
00143 textobj->SetText( ylabel );
00144 if( color != wxNullColour )
00145 textobj->SetStroke(color);
00146 }
00147 }
00148
00149 void a2dPlot::SetY2Label( const wxString& ylabel, const wxColour& color)
00150 {
00151 a2dText* textobj = (a2dText*) Find( _T("__Y2LABEL__") );
00152 if ( ylabel.IsEmpty() )
00153 ReleaseChild( textobj );
00154 else
00155 {
00156 if ( !textobj )
00157 {
00158 textobj = new a2dText( ylabel, 0, 0, a2dFont( 10, wxSWISS ), 0 );
00159 textobj->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00160 textobj->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00161 Append(textobj);
00162 textobj->SetName( _T("__Y2LABEL__") );
00163 }
00164 else
00165 textobj->SetText( ylabel );
00166 if( color != wxNullColour )
00167 textobj->SetStroke(color);
00168 }
00169 }
00170
00171 void a2dPlot::SetTitleTextDc( a2dText* title )
00172 {
00173 if ( title )
00174 {
00175 title->SetName( _T("__TITLE__") );
00176 title->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00177 title->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00178 if ( !SwitchChildNamed( _T("__TITLE__") , title ) )
00179 Append( title );
00180 }
00181 else
00182 {
00183 a2dText* textobj = (a2dText*) Find( _T("__TITLE__") );
00184 ReleaseChild( textobj );
00185 }
00186 }
00187
00188 void a2dPlot::SetMarkerShow( a2dMarkerShow* showm )
00189 {
00190 if ( showm )
00191 {
00192 showm->SetName( _T("__SHOWM__") );
00193 showm->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00194 if ( !SwitchChildNamed( _T("__SHOWM__") , showm ) )
00195 Append( showm );
00196 }
00197 else
00198 {
00199 a2dMarkerShow* showobj = (a2dMarkerShow*) Find( _T("__SHOWM__") );
00200 ReleaseChild( showobj );
00201 }
00202 }
00203
00204 void a2dPlot::SetXLabelTextDc( a2dText* xLabelTextDc )
00205 {
00206 if ( xLabelTextDc )
00207 {
00208 xLabelTextDc->SetName( _T("__XLABEL__") );
00209 xLabelTextDc->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00210 xLabelTextDc->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00211 if ( !SwitchChildNamed( _T("__XLABEL__"), xLabelTextDc ) )
00212 Append( xLabelTextDc );
00213 }
00214 else
00215 {
00216 a2dText* textobj = (a2dText*) Find( _T("__XLABEL__") );
00217 ReleaseChild( textobj );
00218 }
00219 }
00220
00221 void a2dPlot::SetY1LabelTextDc( a2dText* yLabelTextDc )
00222 {
00223 if ( yLabelTextDc )
00224 {
00225 yLabelTextDc->SetName( _T("__Y1LABEL__") );
00226 yLabelTextDc->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00227 yLabelTextDc->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00228 if ( !SwitchChildNamed( _T("__Y1LABEL__"), yLabelTextDc ) )
00229 Append( yLabelTextDc );
00230 }
00231 else
00232 {
00233 a2dText* textobj = (a2dText*) Find( _T("__Y1LABEL__") );
00234 ReleaseChild( textobj );
00235 }
00236 }
00237
00238 void a2dPlot::SetY2LabelTextDc( a2dText* yLabelTextDc )
00239 {
00240 if ( yLabelTextDc )
00241 {
00242 yLabelTextDc->SetName( _T("__Y2LABEL__") );
00243 yLabelTextDc->SetSpecificFlags( !m_autoPlace, a2dCanvasOFlags::DRAGGABLE );
00244 yLabelTextDc->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00245 if ( !SwitchChildNamed( _T("__Y2LABEL__"), yLabelTextDc ) )
00246 Append( yLabelTextDc );
00247 }
00248 else
00249 {
00250 a2dText* textobj = (a2dText*) Find( _T("__Y2LABEL__") );
00251 ReleaseChild( textobj );
00252 }
00253 }
00254
00255 void a2dPlot::DoRender( a2dIterC& ic, OVERLAP clipparent)
00256 {
00257 a2dCanvasXYDisplayGroup::DoRender( ic, clipparent );
00258 }
00259
00260 a2dBoundingBox a2dPlot::DoGetUnTransformedBbox( a2dBboxFlags flags ) const
00261 {
00262 a2dBoundingBox bbox;
00263
00264
00265 bbox.Expand( a2dCanvasXYDisplayGroup::DoGetUnTransformedBbox() );
00266
00267 if ( m_autoPlace )
00268 {
00269 a2dText* titleTextDc = (a2dText*) Find( _T("__TITLE__") );
00270 a2dText* xLabelTextDc = (a2dText*) Find( _T("__XLABEL__") );
00271 a2dText* y1LabelTextDc = (a2dText*) Find( _T("__Y1LABEL__") );
00272 a2dText* y2LabelTextDc = (a2dText*) Find( _T("__Y2LABEL__") );
00273 a2dMarkerShow* markerShow = (a2dMarkerShow*) Find( _T("__SHOWM__") );
00274
00275 if ( titleTextDc )
00276 {
00277 a2dBoundingBox tbox = titleTextDc->GetBbox();
00278 tbox.EnlargeXY(m_leftPadding,m_topPadding);
00279 bbox.Expand( tbox );
00280 }
00281
00282 if ( xLabelTextDc )
00283 {
00284 a2dBoundingBox tbox = xLabelTextDc->GetBbox();
00285 tbox.EnlargeXY(m_leftPadding,m_bottomPadding);
00286 bbox.Expand( tbox );
00287 }
00288
00289 if ( y1LabelTextDc )
00290 {
00291 a2dBoundingBox tbox = y1LabelTextDc->GetBbox();
00292 tbox.EnlargeXY(m_leftPadding,m_bottomPadding);
00293 bbox.Expand( tbox );
00294 }
00295
00296 if ( y2LabelTextDc )
00297 {
00298 a2dBoundingBox tbox = y2LabelTextDc->GetBbox();
00299 tbox.EnlargeXY(m_rightPadding,m_bottomPadding);
00300 bbox.Expand( tbox );
00301 }
00302
00303 if ( markerShow )
00304 {
00305 a2dBoundingBox tbox = markerShow->GetBbox();
00306 tbox.EnlargeXY(m_leftPadding,m_bottomPadding);
00307 bbox.Expand( tbox );
00308 }
00309 }
00310
00311 return bbox;
00312 }
00313
00314 bool a2dPlot::DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox )
00315 {
00316 bool calc = false;
00317
00318 calc = a2dCanvasXYDisplayGroup::DoUpdate( mode, childbox, clipbox, propbox );
00319
00320 if ( !m_bbox.GetValid() || calc )
00321 {
00322
00323 if(m_autoYNames)
00324 {
00325 if(m_axesarealist->m_leftAxisY != (a2dCurvesArea*) NULL)
00326 {
00327 wxString axisName = m_axesarealist->m_leftAxisY->GetAxisText();
00328 wxColour areacolor = m_axesarealist->m_leftAxisY->GetColor();
00329 if(!axisName.IsEmpty())
00330 SetY1Label(axisName, areacolor);
00331 else
00332 SetY1Label(wxT("-"), *wxBLACK);
00333 }
00334 if(m_axesarealist->m_rightAxisY != (a2dCurvesArea*) NULL)
00335 {
00336 wxString axisName = m_axesarealist->m_rightAxisY->GetAxisText();
00337 wxColour areacolor = m_axesarealist->m_rightAxisY->GetColor();
00338 if(!axisName.IsEmpty())
00339 SetY2Label(axisName, areacolor);
00340 else
00341 SetY2Label(wxT("-"), *wxBLACK);
00342 }
00343 }
00344
00345
00346 m_bbox.SetValid( false );
00347 m_bbox.Expand( a2dCanvasXYDisplayGroup::DoGetUnTransformedBbox() );
00348
00349
00350 double minx, miny;
00351 double maxx, maxy;
00352
00353 minx = m_bbox.GetMinX();
00354 maxx = m_bbox.GetMaxX();
00355 miny = m_bbox.GetMinY();
00356 maxy = m_bbox.GetMaxY();
00357
00358 double width = m_bbox.GetWidth();
00359 double height = m_bbox.GetHeight();
00360
00361 a2dText* titleTextDc = (a2dText*) Find( _T("__TITLE__") );
00362 a2dText* xLabelTextDc = (a2dText*) Find( _T("__XLABEL__") );
00363 a2dText* y1LabelTextDc = (a2dText*) Find( _T("__Y1LABEL__") );
00364 a2dText* y2LabelTextDc = (a2dText*) Find( _T("__Y2LABEL__") );
00365 a2dMarkerShow* markerShow = (a2dMarkerShow*) Find( _T("__SHOWM__") );
00366
00367
00368 if(m_topPadding == 0)
00369 m_topPadding = height*padding_FACTOR;
00370
00371
00372 if(m_bottomPadding == 0)
00373 m_bottomPadding = height*padding_FACTOR;
00374
00375
00376 if(m_leftPadding == 0)
00377 m_leftPadding = width*padding_FACTOR;
00378
00379
00380 if(m_rightPadding == 0)
00381 m_rightPadding = width*padding_FACTOR;
00382
00383 if ( m_autoPlace )
00384 {
00385 if ( titleTextDc )
00386 {
00387
00388
00389
00390
00391
00392
00393 titleTextDc->SetAlignment(wxCENTRE | wxBOTTOM | wxBBOX);
00394
00395
00396 double dy = 0;
00397 titleTextDc->SetPosXY(minx + width/2.0, maxy + m_topPadding + dy);
00398 titleTextDc->Update( updatemask_normal );
00399 a2dCanvasView* view = wxStaticCastNull( PROPID_ViewDependent->GetPropertyValue( titleTextDc ).Get(), a2dCanvasView );
00400
00401 if( view && titleTextDc->GetBbox().GetWidth() > m_bbox.GetWidth())
00402 {
00403 titleTextDc->GetBbox().SetMin( minx, titleTextDc->GetBbox().GetMinY());
00404 titleTextDc->GetBbox().SetMax( maxx, titleTextDc->GetBbox().GetMaxY());
00405 }
00406 a2dBoundingBox tbox = titleTextDc->GetBbox();
00407
00408
00409
00410
00411
00412 tbox.EnlargeXY(m_leftPadding,m_topPadding);
00413 m_bbox.Expand( tbox );
00414 }
00415
00416 if ( xLabelTextDc )
00417 {
00418
00419
00420
00421
00422
00423
00424 xLabelTextDc->SetAlignment(wxCENTRE | wxTOP | wxBBOX);
00425 xLabelTextDc->SetPosXY(minx + width/2,
00426 miny - m_bottomPadding - xLabelTextDc->GetTextHeight());
00427 xLabelTextDc->Update( updatemask_normal );
00428 a2dCanvasView* view = wxStaticCastNull( PROPID_ViewDependent->GetPropertyValue( xLabelTextDc ).Get(), a2dCanvasView );
00429
00430 if( view && xLabelTextDc->GetBbox().GetWidth() > m_bbox.GetWidth())
00431 {
00432 xLabelTextDc->GetBbox().SetMin( minx, xLabelTextDc->GetBbox().GetMinY());
00433 xLabelTextDc->GetBbox().SetMax( maxx, xLabelTextDc->GetBbox().GetMaxY());
00434 }
00435 a2dBoundingBox tbox = xLabelTextDc->GetBbox();
00436
00437
00438
00439
00440
00441 tbox.EnlargeXY(m_leftPadding,m_bottomPadding);
00442 m_bbox.Expand( tbox );
00443 }
00444
00445 if ( y1LabelTextDc )
00446 {
00447 SetPosYLabel(y1LabelTextDc, minx - m_leftPadding, miny + height/2, height, true);
00448 a2dCanvasView* view = wxStaticCastNull( PROPID_ViewDependent->GetPropertyValue( y1LabelTextDc ).Get(), a2dCanvasView );
00449
00450 if( view && y1LabelTextDc->GetBbox().GetHeight() > m_bbox.GetHeight())
00451 {
00452 y1LabelTextDc->GetBbox().SetMin(y1LabelTextDc->GetBbox().GetMinX(), miny);
00453 y1LabelTextDc->GetBbox().SetMax(y1LabelTextDc->GetBbox().GetMaxX(), maxy);
00454 }
00455 a2dBoundingBox tbox = y1LabelTextDc->GetBbox();
00456
00457
00458
00459
00460
00461 tbox.EnlargeXY(m_leftPadding,m_bottomPadding);
00462 m_bbox.Expand( tbox );
00463 }
00464
00465 if ( y2LabelTextDc )
00466 {
00467 SetPosYLabel(y2LabelTextDc, maxx + m_rightPadding, miny + height/2, height, false);
00468 a2dCanvasView* view = wxStaticCastNull( PROPID_ViewDependent->GetPropertyValue( y2LabelTextDc ).Get(), a2dCanvasView );
00469
00470 if( view && y2LabelTextDc->GetBbox().GetHeight() > m_bbox.GetHeight())
00471 {
00472 y2LabelTextDc->GetBbox().SetMin(y2LabelTextDc->GetBbox().GetMinX(), minx);
00473 y2LabelTextDc->GetBbox().SetMax(y2LabelTextDc->GetBbox().GetMaxX(), maxy);
00474 }
00475 a2dBoundingBox tbox = y2LabelTextDc->GetBbox();
00476
00477
00478
00479
00480
00481 tbox.EnlargeXY(m_rightPadding,m_bottomPadding);
00482 m_bbox.Expand( tbox );
00483 }
00484
00485 if ( markerShow )
00486 {
00487 markerShow->SetSpecificFlags( false, a2dCanvasOFlags::PRERENDERASCHILD );
00488
00489
00490
00491
00492 markerShow->SetPosXY(minx + width/2.0, miny );
00493 markerShow->Update( updatemask_normal );
00494 a2dBoundingBox tbox = markerShow->GetBbox();
00495 tbox.EnlargeXY(m_leftPadding,m_bottomPadding);
00496 m_bbox.Expand( tbox );
00497 }
00498 }
00499 m_bbox.MapBbox(m_lworld);
00500 return true;
00501 }
00502
00503 return false;
00504 }
00505
00506 void a2dPlot::SetPosYLabel(a2dText* yLabelTextDc, double x, double y, double tHeight, bool left)
00507 {
00508 double yangle = yLabelTextDc->GetTransformMatrix().GetRotation();
00509
00510 int alignment = wxCENTRE | wxBBOX;
00511 if (yangle == 0)
00512 alignment |= left ? wxRIGHT : wxLEFT;
00513 else if (yangle == -90)
00514 alignment |= left ? wxTOP : wxBOTTOM;
00515 else
00516 alignment |= left ? wxBOTTOM : wxTOP;
00517
00518 yLabelTextDc->SetAlignment(alignment);
00519
00520 yLabelTextDc->SetPosXY(x, y);
00521 yLabelTextDc->Update( updatemask_normal );
00522 }
00523
00524 void a2dPlot::OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event )
00525 {
00526 a2dIterC* ic = event.GetIterC();
00527 if ( m_flags.m_editingCopy )
00528 {
00529
00530 double xw,yw;
00531 xw = event.GetX();
00532 yw = event.GetY();
00533
00534 if ( event.GetMouseEvent().LeftDown() )
00535 {
00536 a2dHitEvent hitevent = a2dHitEvent(xw, yw, false);
00537 if ( IsHitWorld( *ic, hitevent ) )
00538 {
00539 a2dPlot* original = wxStaticCast( PROPID_Original->GetPropertyValue( this).Get(), a2dPlot );
00540
00541 a2dIterC iclocal( ic->GetCanvasView() );
00542 iclocal.SetLayer( m_layer );
00543 a2dIterCU cu( iclocal, m_lworld );
00544
00545 a2dText* titleTextDc = (a2dText*) original->Find( _T("__TITLE__") );
00546 a2dText* xLabelTextDc = (a2dText*) original->Find( _T("__XLABEL__") );
00547 a2dText* y1LabelTextDc = (a2dText*) original->Find( _T("__Y1LABEL__") );
00548 a2dText* y2LabelTextDc = (a2dText*) original->Find( _T("__Y2LABEL__") );
00549 a2dMarkerShow* markerShow = (a2dMarkerShow*) Find( _T("__SHOWM__") );
00550
00551 a2dCanvasObject* hittext = NULL;
00552 a2dHitEvent hitevent = a2dHitEvent(xw, yw, false);
00553 if ( titleTextDc )
00554 hittext = titleTextDc->IsHitWorld( iclocal, hitevent );
00555
00556 if ( !hittext && xLabelTextDc )
00557 hittext = xLabelTextDc->IsHitWorld( iclocal, hitevent );
00558
00559 if ( !hittext && y1LabelTextDc )
00560 hittext = y1LabelTextDc->IsHitWorld( iclocal, hitevent );
00561
00562 if ( !hittext && y2LabelTextDc )
00563 hittext = y2LabelTextDc->IsHitWorld( iclocal, hitevent );
00564
00565 if( !hittext && markerShow)
00566 hittext = markerShow->IsHitWorld( iclocal, hitevent );
00567
00568 if ( hittext && hittext->GetEditable() )
00569 {
00570 #if wxART2D_USE_EDITOR
00571
00572 a2dIterCU cuw( *ic, original );
00573
00574 a2dStToolContr* controller = wxStaticCast( PROPID_Controller->GetPropertyValue( this).Get(), a2dStToolContr );
00575 ic->SetCorridorPath( true, NULL );
00576 controller->StartEditingObject( hittext, *ic );
00577 #else //wxART2D_USE_EDITOR
00578 wxMessageBox( wxT("Need editor module enabled for this") );
00579 #endif //wxART2D_USE_EDITOR
00580 }
00581 else
00582 event.Skip();
00583 }
00584 else
00585 event.Skip();
00586 }
00587 else
00588 event.Skip();
00589 }
00590 else
00591 event.Skip();
00592 }
00593
00594 #if wxART2D_USE_CVGIO
00595 void a2dPlot::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
00596 {
00597 a2dCanvasXYDisplayGroup::DoSave( parent, out, xmlparts, towrite );
00598 if ( xmlparts == a2dXmlSer_attrib )
00599 {
00600 out.WriteAttribute( _T("autoPlace") , m_autoPlace );
00601 out.WriteAttribute( _T("topPadding") , m_topPadding );
00602 out.WriteAttribute( _T("bottomPadding") , m_bottomPadding );
00603 out.WriteAttribute( _T("leftPadding") , m_leftPadding );
00604 out.WriteAttribute( _T("rightPadding") , m_rightPadding );
00605 out.WriteNewLine();
00606 }
00607 else
00608 {
00609 }
00610 }
00611
00612 void a2dPlot::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
00613 {
00614 a2dCanvasXYDisplayGroup::DoLoad( parent, parser, xmlparts );
00615 if ( xmlparts == a2dXmlSer_attrib )
00616 {
00617 m_autoPlace = parser.RequireAttributeValueBool( _T("autoPlace") );
00618 m_topPadding = parser.RequireAttributeValueDouble( _T("topPadding") );
00619 m_bottomPadding = parser.RequireAttributeValueDouble( _T("bottomPadding") );
00620 m_leftPadding = parser.RequireAttributeValueDouble( _T("leftPadding") );
00621 m_rightPadding = parser.RequireAttributeValueDouble( _T("rightPadding") );
00622 }
00623 else
00624 {
00625 }
00626 }
00627 #endif //wxART2D_USE_CVGIO
00628
00629
00630
00631
00632
00633
00634
00635 void a2dCurveGroupLegend::DoWalker( wxObject* parent, a2dWalkerIOHandler& handler )
00636 {
00637 handler.WalkTask( parent, this, a2dWalker_a2dDerivedCanvasObjectStart );
00638 a2dCanvasObject::DoWalker( parent, handler );
00639 if (m_curveGroup)
00640 m_curveGroup->Walker( this, handler );
00641
00642 handler.WalkTask( parent, this, a2dWalker_a2dDerivedCanvasObjectEnd );
00643 }
00644
00645 A2D_BEGIN_EVENT_TABLE(a2dCurveGroupLegend,a2dCanvasObject)
00646 A2D_EVT_CANVASOBJECT_MOUSE_EVENT( a2dCurveGroupLegend::OnCanvasObjectMouseEvent )
00647 A2D_EVT_CHAR( a2dCurveGroupLegend::OnChar )
00648 A2D_END_EVENT_TABLE()
00649
00650 void a2dCurveGroupLegend::OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event )
00651 {
00652
00653
00654 event.Skip();
00655 }
00656
00657 void a2dCurveGroupLegend::OnChar(wxKeyEvent& event)
00658 {
00659 }
00660
00661 a2dCurveGroupLegend::a2dCurveGroupLegend( const wxString& format, a2dCanvasXYDisplayGroupAreas* curveGroup, const a2dFont& font)
00662 : a2dCanvasObject()
00663 {
00664 m_curveGroup = curveGroup;
00665 m_format = format;
00666 m_font = font;
00667 m_linespace = font.GetSize() / 10.0;
00668 }
00669
00670 a2dCurveGroupLegend::~a2dCurveGroupLegend()
00671 {
00672 }
00673
00674 a2dCurveGroupLegend::a2dCurveGroupLegend( const a2dCurveGroupLegend &other, CloneOptions options )
00675 :a2dCanvasObject( other, options )
00676 {
00677 m_curveGroup = other.m_curveGroup;
00678 m_font = other.m_font;
00679 m_format = other.m_format;
00680 m_linespace = other.m_linespace;
00681 }
00682
00683 a2dObject* a2dCurveGroupLegend::Clone( CloneOptions options ) const
00684 {
00685 return new a2dCurveGroupLegend( *this, options );
00686 };
00687
00688 void a2dCurveGroupLegend::DoAddPending( a2dIterC& WXUNUSED(ic) )
00689 {
00690 }
00691
00692 void a2dCurveGroupLegend::DependencyPending( a2dWalkerIOHandler* WXUNUSED(handler) )
00693 {
00694 if ( !m_flags.m_pending && m_curveGroup->GetPending() )
00695 {
00696 SetPending(true);
00697 }
00698 }
00699
00700 a2dBoundingBox a2dCurveGroupLegend::DoGetUnTransformedBbox( a2dBboxFlags flags ) const
00701 {
00702 a2dBoundingBox bbox;
00703
00704 double height = 0;
00705
00706 if ( !m_format.IsEmpty() && m_font.GetSize() )
00707 {
00708 const a2dCurvesAreaList& areaList = m_curveGroup->GetCurvesAreaList();
00709 for(size_t i=0; i < areaList.GetCount(); i++)
00710 {
00711 const a2dCurvesArea* area = areaList.Item(i);
00712 a2dCanvasObjectList::const_iterator iter = area->GetChildObjectList()->begin();
00713 while( iter != area->GetChildObjectList()->end() )
00714 {
00715 const a2dCurveObject* item = wxDynamicCast( (*iter).Get(), a2dCurve );
00716 if ( item )
00717 {
00718 wxString form;
00719 form.Printf(m_format, item->GetName().c_str() );
00720
00721 a2dBoundingBox linebbox = m_font.GetTextExtent(form, UNKNOWN_YAXIS, a2dDEFAULT_ALIGNMENT );
00722 linebbox.Translate(0.0, height);
00723 bbox.Expand(linebbox);
00724 height = height - (GetLineHeight() + m_linespace);
00725 }
00726 ++iter;
00727 }
00728 }
00729 }
00730 return bbox;
00731 }
00732
00733 bool a2dCurveGroupLegend::DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox )
00734 {
00735 if ( m_curveGroup && !m_bbox.GetValid() )
00736 {
00737 m_bbox=DoGetUnTransformedBbox();
00738 m_bbox.MapBbox(m_lworld);
00739 return true;
00740 }
00741 return false;
00742 }
00743
00744 #if wxART2D_USE_CVGIO
00745
00746 void a2dCurveGroupLegend::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
00747 {
00748 a2dCanvasObject::DoSave( parent, out, xmlparts, towrite );
00749 if ( xmlparts == a2dXmlSer_attrib )
00750 {
00751 out.WriteAttribute( wxT("curvegroupname") , m_curveGroup->GetName() );
00752 }
00753 else
00754 {
00755 }
00756 }
00757
00758 void a2dCurveGroupLegend::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
00759 {
00760 a2dCanvasObject::DoLoad( parent, parser, xmlparts );
00761 if ( xmlparts == a2dXmlSer_attrib )
00762 {
00763 }
00764 else
00765 {
00766 }
00767
00768
00769 }
00770 #endif //wxART2D_USE_CVGIO
00771
00772 void a2dCurveGroupLegend::DoRender( a2dIterC& ic, OVERLAP WXUNUSED(clipparent) )
00773 {
00774 if(!m_format.IsEmpty())
00775 {
00776
00777 ic.GetDrawer2D()->SetFont( m_font );
00778 ic.GetDrawer2D()->SetDrawerFill(*a2dTRANSPARENT_FILL);
00779
00780 double height = 0;
00781
00782 const a2dCurvesAreaList& areaList = m_curveGroup->GetCurvesAreaList();
00783 for(size_t i=0; i < areaList.GetCount(); i++)
00784 {
00785 const a2dCurvesArea* area = areaList.Item(i);
00786 a2dCanvasObjectList::const_iterator iter = area->GetChildObjectList()->begin();
00787 while( iter != area->GetChildObjectList()->end() )
00788 {
00789 const a2dCurveObject* item = wxDynamicCast( (*iter).Get(), a2dCurve );
00790 if ( item )
00791 {
00792 wxString form;
00793 form.Printf(m_format, item->GetName().c_str() );
00794
00795 ic.GetDrawer2D()->DrawText( form, 0, height, a2dDEFAULT_ALIGNMENT );
00796 height = height - (GetLineHeight() + m_linespace);
00797 }
00798 ++iter;
00799 }
00800 }
00801 ic.GetDrawer2D()->SetFont( *a2dNullFONT );
00802 }
00803 }
00804
00805 bool a2dCurveGroupLegend::DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent )
00806 {
00807 a2dPoint2D P = a2dPoint2D(hitEvent.m_relx, hitEvent.m_rely);
00808
00809
00810
00811 hitEvent.m_how.m_hit = a2dHit::hit_fill;
00812 return true;
00813 }
00814