00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "a2dprec.h"
00012
00013 #ifdef __BORLANDC__
00014 #pragma hdrstop
00015 #endif
00016
00017 #ifndef WX_PRECOMP
00018 #include "wx/wx.h"
00019 #endif
00020
00021 #include "wx/canvas/canobj.h"
00022 #include "wx/canvas/rectangle.h"
00023 #include "wx/canvas/canglob.h"
00024 #include "wx/canvas/vpath.h"
00025 #include "wx/canvas/candoc.h"
00026 #include "wx/canvas/cancom.h"
00027 #include "wx/canvas/drawer.h"
00028 #include "wx/canvas/canvas.h"
00029 #include "wx/canvas/canimage.h"
00030
00031 IMPLEMENT_DYNAMIC_CLASS(a2dImage, a2dCanvasObject)
00032 IMPLEMENT_DYNAMIC_CLASS( a2dRgbaImage, a2dRectMM)
00033
00034
00035
00036
00037
00038 a2dPropertyIdDouble* a2dImage::PROPID_Width = NULL;
00039 a2dPropertyIdDouble* a2dImage::PROPID_Height = NULL;
00040
00041 INITIALIZE_PROPERTIES( a2dImage, a2dCanvasObject )
00042 {
00043 A2D_PROPID_GSI( a2dPropertyIdDouble, a2dImage, Width, 0 );
00044 A2D_PROPID_GSI( a2dPropertyIdDouble, a2dImage, Height, 0 );
00045 return true;
00046 }
00047
00048 a2dImage::a2dImage()
00049 : a2dCanvasObject()
00050 {
00051 m_width = 10;
00052 m_height = 10;
00053 m_OpacityFactor = 255;
00054
00055 m_image = wxImage(10,10);
00056
00057 m_filename = wxT("");
00058
00059 m_type = wxBITMAP_TYPE_PNG;
00060
00061 m_drawPatternOnTop = false;
00062 }
00063
00064 a2dImage::a2dImage( const wxImage &image, double xc, double yc, double w, double h )
00065 : a2dCanvasObject()
00066 {
00067 m_lworld.Translate(xc,yc);
00068
00069 if ( w == 0 )
00070 w = image.GetWidth();
00071
00072 if ( h == 0 )
00073 h = image.GetHeight();
00074
00075 m_width = w;
00076 m_height = h;
00077 m_OpacityFactor = 255;
00078
00079 m_image = image;
00080
00081 m_filename = wxT("");
00082
00083 m_type = wxBITMAP_TYPE_PNG;
00084
00085 m_drawPatternOnTop = false;
00086 }
00087
00088 a2dImage::a2dImage( const wxString &imagefile, wxBitmapType type, double xc, double yc, double w, double h )
00089 : a2dCanvasObject()
00090 {
00091 wxBitmap bitmap;
00092
00093 m_type = type;
00094 if ( !wxFileExists( imagefile ) )
00095 {
00096 a2dGeneralGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _("could not open file %s image file"), imagefile.c_str() );
00097 m_image = wxImage( 100, 100 );
00098 }
00099 else
00100 {
00101 bitmap.LoadFile(imagefile, type);
00102 m_image = bitmap.ConvertToImage();
00103 }
00104
00105 if ( w == 0 )
00106 w = m_image.GetWidth();
00107
00108 if ( h == 0 )
00109 h = m_image.GetHeight();
00110
00111 m_filename = imagefile;
00112
00113 m_lworld.Translate(xc,yc);
00114
00115 m_width = w;
00116 m_height = h;
00117 m_OpacityFactor = 255;
00118
00119 m_drawPatternOnTop = false;
00120 }
00121
00122 a2dImage::a2dImage( a2dCanvasObject* torender, double xc, double yc, double w, double h, int imagew, int imageh )
00123 : a2dCanvasObject()
00124 {
00125 m_lworld.Translate(xc,yc);
00126
00127 m_width = w;
00128 m_height = h;
00129 m_OpacityFactor = 255;
00130
00131 RenderObject( torender, imagew, imageh );
00132
00133 m_filename = wxT("");
00134
00135 m_type = wxBITMAP_TYPE_PNG;
00136
00137 m_drawPatternOnTop = false;
00138 }
00139
00140 a2dImage::a2dImage( const a2dImage &other, CloneOptions options )
00141 :a2dCanvasObject( other, options )
00142 {
00143 m_width = other.m_width;
00144 m_height = other.m_height;
00145 m_OpacityFactor = other.m_OpacityFactor;
00146 m_image = other.m_image;
00147 m_filename = other.m_filename;
00148 m_type = other.m_type;
00149 m_drawPatternOnTop = other.m_drawPatternOnTop;
00150 }
00151
00152 a2dImage::~a2dImage()
00153 {
00154 }
00155
00156 a2dCanvasObjectList* a2dImage::GetAsRectangles( const wxColour& col1, const wxColour& col2, bool transform )
00157 {
00158 a2dAffineMatrix pworld;
00159 if ( transform )
00160 pworld = m_lworld;
00161
00162 a2dCanvasObjectList* canpathlist = new a2dCanvasObjectList();
00163
00164 unsigned char* source_data = m_image.GetData();
00165 long w = m_image.GetWidth();
00166 long h = m_image.GetHeight();
00167
00168 double rectw = m_width/m_image.GetWidth();
00169 double recth = m_height/m_image.GetHeight();
00170
00171 for (long y = 0; y <h; y++)
00172 {
00173 long rowlenght = 0;
00174 long startrow = 0;
00175 for (long x = 0; x < w; x++)
00176 {
00177 unsigned char *pixel = source_data + (y * w)*3 + x*3;
00178 unsigned char red = pixel[0] ;
00179 unsigned char green = pixel[1] ;
00180 unsigned char blue = pixel[2] ;
00181 unsigned char alpha = 255 ;
00182
00183 if ( red >= col1.Red() && red <= col2.Red() &&
00184 green >= col1.Green() && green <= col2.Green() &&
00185 blue >= col1.Blue() && blue <= col2.Blue()
00186 )
00187 {
00188 if ( !rowlenght )
00189 startrow = x;
00190 rowlenght++;
00191 }
00192 else if ( rowlenght )
00193 {
00194 a2dRect* pixRect = new a2dRect( -m_width/2.0 + startrow * rectw, m_height/2.0 -y * recth, rectw*rowlenght, -recth );
00195 pixRect->Transform( pworld );
00196 pixRect->SetLayer( m_layer );
00197 pixRect->SetContourWidth( GetContourWidth() );
00198 pixRect->SetCanvasDocument( m_root, false );
00199 canpathlist->push_back( pixRect );
00200 rowlenght = 0;
00201 }
00202
00203 }
00204 if ( rowlenght )
00205 {
00206 a2dRect* pixRect = new a2dRect( -m_width/2.0 + startrow * rectw, m_height/2.0 -y * recth, rectw*rowlenght, -recth );
00207 pixRect->Transform( pworld );
00208 pixRect->SetLayer( m_layer );
00209 pixRect->SetContourWidth( GetContourWidth() );
00210 pixRect->SetCanvasDocument( m_root, false );
00211 canpathlist->push_back( pixRect );
00212 rowlenght = 0;
00213 }
00214 }
00215
00216 return canpathlist;
00217 }
00218
00219 void a2dImage::RenderObject( a2dCanvasObject* torender, int imagew, int imageh )
00220 {
00221 a2dSmrtPtr<a2dCanvasDocument> doc = torender->GetCanvasDocument();
00222 bool hasDoc = true;
00223 if ( !doc )
00224 {
00225 doc = new a2dCanvasDocument();
00226 doc->Append( torender );
00227 hasDoc = false;
00228 }
00229
00230 a2dSmrtPtr<a2dCanvasView> drawer = new a2dCanvasView( imagew, imageh );
00231 drawer->SetDocument( doc );
00232 drawer->SetShowObject( torender );
00233 doc->SetCanvasDocumentRecursive();
00234
00235 drawer->GetDrawer2D()->SetMappingWidthHeight( 0,0,1000,1000 );
00236 drawer->GetDrawer2D()->SetMappingWidthHeight( torender->GetUnTransformedBbox( a2dCANOBJ_BBOX_CHILDREN ) );
00237 drawer->UpdateArea( 0, 0, imagew, imageh );
00238
00239 m_image = drawer->GetDrawer2D()->GetBuffer().ConvertToImage();
00240
00241 drawer->SetClosed();
00242
00243 if ( !hasDoc )
00244 {
00245 torender->SetCanvasDocument( NULL );
00246 }
00247 }
00248
00249 void a2dImage::SetFilename( const wxString filename, wxBitmapType type, bool doread )
00250 {
00251 m_filename = filename;
00252 m_type = type;
00253
00254 SetPending(true);
00255
00256 if ( doread )
00257 {
00258 if ( !wxFileExists( m_filename) )
00259 a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _("image file %s not found"), m_filename.c_str() );
00260 wxCHECK_RET(m_image.LoadFile( m_filename, type), wxT("invalid image file"));
00261 }
00262 }
00263
00264
00265 void a2dImage::SetDrawPatternOnTop(bool drawPatternOnTop) {
00266
00267
00268 if (m_drawPatternOnTop != drawPatternOnTop)
00269 {
00270 m_drawPatternOnTop = drawPatternOnTop;
00271 SetPending(true);
00272 }
00273 }
00274
00275 bool a2dImage::DoStartEdit( wxUint16 editmode, wxEditStyle editstyle )
00276 {
00277 if ( m_flags.m_editable )
00278 {
00279 PROPID_IncludeChildren->SetPropertyToObject( this, false );
00280 PROPID_Allowrotation->SetPropertyToObject( this, true );
00281 PROPID_Allowskew->SetPropertyToObject( this, false );
00282
00283 return a2dCanvasObject::DoStartEdit( editmode, editstyle );
00284 }
00285
00286 return false;
00287 }
00288
00289
00290 a2dObject* a2dImage::Clone( CloneOptions options ) const
00291 {
00292 return new a2dImage( *this, options );
00293 };
00294
00295 a2dBoundingBox a2dImage::DoGetUnTransformedBbox( a2dBboxFlags WXUNUSED(flags) ) const
00296 {
00297 a2dBoundingBox bbox;
00298
00299 bbox.Expand( -m_width/2, -m_height/2 );
00300 bbox.Expand( m_width/2, m_height/2 );
00301 return bbox;
00302 }
00303
00304 void a2dImage::DoRender( a2dIterC& ic, OVERLAP WXUNUSED(clipparent) )
00305 {
00306
00307 if (!m_drawPatternOnTop)
00308 {
00309 if ( !GetStroke().IsSameAs(*a2dTRANSPARENT_STROKE) || !GetFill().IsSameAs(*a2dTRANSPARENT_FILL ) )
00310 {
00311 ic.GetDrawer2D()->DrawCenterRoundedRectangle( 0, 0, m_width, m_height, 0);
00312 }
00313 }
00314
00315
00316 if ( ic.GetDrawer2D()->GetDrawStyle() != a2dWIREFRAME_INVERT )
00317 {
00318 ic.GetDrawer2D()->DrawImage( m_image, 0, 0, m_width, m_height, m_OpacityFactor );
00319 }
00320 else
00321 ic.GetDrawer2D()->DrawCenterRoundedRectangle( 0, 0 , m_width, m_height, 0);
00322
00323
00324
00325 if (m_drawPatternOnTop)
00326 {
00327 if ( GetStroke() != *a2dTRANSPARENT_STROKE || GetFill() != *a2dTRANSPARENT_FILL )
00328 {
00329 ic.GetDrawer2D()->DrawCenterRoundedRectangle( 0, 0, m_width, m_height, 0);
00330 }
00331 }
00332 if (m_flags.m_selected)
00333 {
00334 ic.GetDrawer2D()->DrawCenterRoundedRectangle( 0, 0 , m_width, m_height, 0);
00335 }
00336 }
00337
00338 bool a2dImage::DoIsHitWorld( a2dIterC& WXUNUSED(ic), a2dHitEvent& hitEvent )
00339 {
00340 hitEvent.m_how = a2dHit::stock_fill;
00341 return true;
00342 }
00343
00344 #if wxART2D_USE_CVGIO
00345 void a2dImage::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
00346 {
00347 a2dCanvasObject::DoLoad( parent, parser, xmlparts );
00348 if ( xmlparts == a2dXmlSer_attrib )
00349 {
00350 m_filename = parser.GetAttributeValue( wxT("filename") );
00351 m_width = parser.GetAttributeValueDouble( wxT("width") );
00352 m_height = parser.GetAttributeValueDouble( wxT("height") );
00353 m_type = (wxBitmapType) parser.GetAttributeValueLong( wxT("type") );
00354 m_drawPatternOnTop = parser.GetAttributeValueBool( wxT("patternontop") );
00355 m_OpacityFactor = parser.GetAttributeValueLong( wxT("opacityfactor") );
00356
00357 if ( !m_filename.IsEmpty() )
00358 {
00359 wxString fname = a2dGlobals->GetImagePathList().FindValidPath( m_filename );
00360 if ( !::wxFileExists( fname ) )
00361 {
00362 a2dGeneralGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "could not open file %s for loading image" ), m_filename.c_str() );
00363 return;
00364 }
00365 m_image.LoadFile( fname, m_type);
00366 }
00367 else
00368 {
00369 m_image = wxImage( (int) m_width, (int) m_height );
00370 }
00371 }
00372 else
00373 {
00374 }
00375 }
00376
00377 void a2dImage::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
00378 {
00379 a2dCanvasObject::DoSave( parent, out, xmlparts, towrite );
00380 if ( xmlparts == a2dXmlSer_attrib )
00381 {
00382 if ( m_filename.IsEmpty() )
00383 {
00384 m_image.SaveFile( GetName(), m_type );
00385 out.WriteAttribute( wxT("filename"), GetName() );
00386 }
00387 else
00388 {
00389 out.WriteAttribute( wxT("filename"), m_filename );
00390 }
00391 out.WriteAttribute( wxT("width"), m_width );
00392 out.WriteAttribute( wxT("height"), m_height );
00393 out.WriteAttribute( wxT("type"), (wxInt32) m_type );
00394 out.WriteAttribute( wxT("patternontop"), m_drawPatternOnTop );
00395 out.WriteAttribute( wxT("opacityfactor"), (wxUint8) m_OpacityFactor );
00396 }
00397 else
00398 {
00399 }
00400 }
00401 #endif //wxART2D_USE_CVGIO
00402
00403
00404
00405
00406
00407 A2D_BEGIN_EVENT_TABLE( a2dRgbaImage, a2dRectMM )
00408 A2D_END_EVENT_TABLE()
00409
00410 a2dRgbaImage::a2dRgbaImage()
00411 : a2dRectMM()
00412 {
00413 }
00414
00415 a2dRgbaImage::a2dRgbaImage( double x, double y, wxImage& image, wxUint8 OpacityFactor )
00416 : a2dRectMM( x, y, image.GetWidth(), image.GetHeight() )
00417 {
00418 m_glimage = a2dImageRGBA( image, OpacityFactor );
00419 m_OpacityFactor = OpacityFactor;
00420 m_drawPatternOnTop = false;
00421 }
00422
00423 a2dRgbaImage::~a2dRgbaImage()
00424 {
00425 }
00426
00427 a2dRgbaImage::a2dRgbaImage( const a2dRgbaImage &other, CloneOptions options )
00428 :a2dRectMM( other, options )
00429 {
00430 m_glimage = other.m_glimage;
00431 m_OpacityFactor = other.m_OpacityFactor;
00432 m_flip = other.m_flip;
00433 m_drawPatternOnTop = other.m_drawPatternOnTop;
00434 }
00435
00436 a2dObject* a2dRgbaImage::Clone( CloneOptions options ) const
00437 {
00438 return new a2dRgbaImage( *this, options );
00439 };
00440
00441 void a2dRgbaImage::DoRender( a2dIterC& ic, OVERLAP clipparent )
00442 {
00443
00444 if (!m_drawPatternOnTop)
00445 {
00446 if ( !GetStroke().IsSameAs(*a2dTRANSPARENT_STROKE) || !GetFill().IsSameAs(*a2dTRANSPARENT_FILL ) )
00447 {
00448 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00449 }
00450 }
00451
00452 if ( ic.GetDrawer2D()->GetDrawStyle() != a2dWIREFRAME_INVERT )
00453 {
00454 ic.GetDrawer2D()->DrawImage( m_glimage, m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, m_OpacityFactor );
00455 }
00456 else
00457 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00458
00459
00460
00461 if (m_drawPatternOnTop)
00462 {
00463 if ( GetStroke() != *a2dTRANSPARENT_STROKE || GetFill() != *a2dTRANSPARENT_FILL )
00464 {
00465 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00466 }
00467 }
00468 if (m_flags.m_selected)
00469 {
00470 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00471 }
00472 }
00473
00474 #if wxART2D_USE_CVGIO
00475
00476 void a2dRgbaImage::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
00477 {
00478 a2dRectMM::DoSave( parent, out, xmlparts, towrite );
00479 if ( xmlparts == a2dXmlSer_attrib )
00480 {
00481 }
00482 else
00483 {
00484 }
00485 }
00486
00487 void a2dRgbaImage::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
00488 {
00489 a2dRectMM::DoLoad( parent, parser, xmlparts );
00490 if ( xmlparts == a2dXmlSer_attrib )
00491 {
00492 }
00493 else
00494 {
00495 }
00496 }
00497 #endif //wxART2D_USE_CVGIO
00498
00499
00500 IMPLEMENT_DYNAMIC_CLASS( a2dImageMM, a2dRectMM)
00501
00502
00503
00504
00505
00506 a2dImageMM::a2dImageMM()
00507 : a2dRectMM(0,0,10,10)
00508 {
00509 m_image = wxImage(10,10);
00510
00511 m_filename = wxT("");
00512
00513 m_type = wxBITMAP_TYPE_PNG;
00514
00515 m_drawPatternOnTop = false;
00516 }
00517
00518 a2dImageMM::a2dImageMM( double x, double y, wxImage& image, unsigned char alpha )
00519 : a2dRectMM( x, y, image.GetWidth(), image.GetHeight() )
00520 {
00521 m_image = image;
00522
00523 m_filename = wxT("");
00524
00525 m_type = wxBITMAP_TYPE_PNG;
00526
00527 m_drawPatternOnTop = false;
00528 }
00529
00530 a2dImageMM::a2dImageMM( const wxImage &image, double x, double y, double w, double h )
00531 : a2dRectMM( x, y, w, h )
00532 {
00533 m_image = image;
00534
00535 m_filename = wxT("");
00536
00537 m_type = wxBITMAP_TYPE_PNG;
00538
00539 m_drawPatternOnTop = false;
00540 }
00541
00542 a2dImageMM::a2dImageMM( const wxString &imagefile, wxBitmapType type, double x, double y, double w, double h )
00543 : a2dRectMM( x, y, w, h )
00544 {
00545 wxBitmap bitmap;
00546
00547 m_type = type;
00548 if ( !wxFileExists( imagefile ) )
00549 {
00550 a2dGeneralGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _("could not open file %s image file"), imagefile.c_str() );
00551 m_image = wxImage( 100, 100 );
00552 }
00553 else
00554 {
00555 bitmap.LoadFile(imagefile, type);
00556 m_image = bitmap.ConvertToImage();
00557 }
00558
00559 m_filename = imagefile;
00560
00561 m_drawPatternOnTop = false;
00562 }
00563
00564 a2dImageMM::a2dImageMM( a2dCanvasObject* torender, double x, double y, double w, double h, int imagew, int imageh )
00565 : a2dRectMM( x, y, w, h )
00566 {
00567 RenderObject( torender, imagew, imageh );
00568
00569 m_filename = wxT("");
00570
00571 m_type = wxBITMAP_TYPE_PNG;
00572
00573 m_drawPatternOnTop = false;
00574 }
00575
00576 a2dImageMM::a2dImageMM( const a2dImageMM &other, CloneOptions options )
00577 :a2dRectMM( other, options )
00578 {
00579 m_image = other.m_image;
00580 m_filename = other.m_filename;
00581 m_type = other.m_type;
00582 m_drawPatternOnTop = other.m_drawPatternOnTop;
00583 }
00584
00585 a2dImageMM::~a2dImageMM()
00586 {
00587 }
00588
00589 a2dCanvasObjectList* a2dImageMM::GetAsRectangles( const wxColour& col1, const wxColour& col2, bool transform )
00590 {
00591 a2dAffineMatrix pworld;
00592 if ( transform )
00593 pworld = m_lworld;
00594
00595 a2dCanvasObjectList* canpathlist = new a2dCanvasObjectList();
00596
00597 unsigned char* source_data = m_image.GetData();
00598 long w = m_image.GetWidth();
00599 long h = m_image.GetHeight();
00600
00601 double rectw = GetWidth()/m_image.GetWidth();
00602 double recth = GetHeight()/m_image.GetHeight();
00603
00604 for (long y = 0; y <h; y++)
00605 {
00606 long rowlenght = 0;
00607 long startrow = 0;
00608 for (long x = 0; x < w; x++)
00609 {
00610 unsigned char *pixel = source_data + (y * w)*3 + x*3;
00611 unsigned char red = pixel[0] ;
00612 unsigned char green = pixel[1] ;
00613 unsigned char blue = pixel[2] ;
00614 unsigned char alpha = 255 ;
00615
00616 if ( red >= col1.Red() && red <= col2.Red() &&
00617 green >= col1.Green() && green <= col2.Green() &&
00618 blue >= col1.Blue() && blue <= col2.Blue()
00619 )
00620 {
00621 if ( !rowlenght )
00622 startrow = x;
00623 rowlenght++;
00624 }
00625 else if ( rowlenght )
00626 {
00627 a2dRect* pixRect = new a2dRect( -GetWidth()/2.0 + startrow * rectw, GetHeight()/2.0 -y * recth, rectw*rowlenght, -recth );
00628 pixRect->Transform( pworld );
00629 pixRect->SetLayer( m_layer );
00630 pixRect->SetContourWidth( GetContourWidth() );
00631 pixRect->SetCanvasDocument( m_root, false );
00632 canpathlist->push_back( pixRect );
00633 rowlenght = 0;
00634 }
00635
00636 }
00637 if ( rowlenght )
00638 {
00639 a2dRect* pixRect = new a2dRect( -GetWidth()/2.0 + startrow * rectw, GetHeight()/2.0 -y * recth, rectw*rowlenght, -recth );
00640 pixRect->Transform( pworld );
00641 pixRect->SetLayer( m_layer );
00642 pixRect->SetContourWidth( GetContourWidth() );
00643 pixRect->SetCanvasDocument( m_root, false );
00644 canpathlist->push_back( pixRect );
00645 rowlenght = 0;
00646 }
00647 }
00648
00649 return canpathlist;
00650 }
00651
00652 void a2dImageMM::RenderObject( a2dCanvasObject* torender, int imagew, int imageh )
00653 {
00654 a2dSmrtPtr<a2dCanvasDocument> doc = torender->GetCanvasDocument();
00655 bool hasDoc = true;
00656 if ( !doc )
00657 {
00658 doc = new a2dCanvasDocument();
00659 doc->Append( torender );
00660 hasDoc = false;
00661 }
00662
00663 a2dSmrtPtr<a2dCanvasView> drawer = new a2dCanvasView( imagew, imageh );
00664 drawer->SetDocument( doc );
00665 drawer->SetShowObject( torender );
00666 doc->SetCanvasDocumentRecursive();
00667
00668 drawer->GetDrawer2D()->SetMappingWidthHeight( 0,0,1000,1000 );
00669 drawer->GetDrawer2D()->SetMappingWidthHeight( torender->GetUnTransformedBbox( a2dCANOBJ_BBOX_CHILDREN ) );
00670 drawer->UpdateArea( 0, 0, imagew, imageh );
00671
00672 m_image = drawer->GetDrawer2D()->GetBuffer().ConvertToImage();
00673
00674 drawer->SetClosed();
00675
00676 if ( !hasDoc )
00677 {
00678 torender->SetCanvasDocument( NULL );
00679 }
00680 }
00681
00682 void a2dImageMM::SetFilename( const wxString filename, wxBitmapType type, bool doread )
00683 {
00684 m_filename = filename;
00685 m_type = type;
00686
00687 SetPending(true);
00688
00689 if ( doread )
00690 {
00691 if ( !wxFileExists( m_filename) )
00692 a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _("image file %s not found"), m_filename.c_str() );
00693 wxCHECK_RET(m_image.LoadFile( m_filename, type), wxT("invalid image file"));
00694 }
00695 }
00696
00697
00698 void a2dImageMM::SetDrawPatternOnTop(bool drawPatternOnTop) {
00699
00700
00701 if (m_drawPatternOnTop != drawPatternOnTop)
00702 {
00703 m_drawPatternOnTop = drawPatternOnTop;
00704 SetPending(true);
00705 }
00706 }
00707
00708 bool a2dImageMM::DoStartEdit( wxUint16 editmode, wxEditStyle editstyle )
00709 {
00710 if ( m_flags.m_editable )
00711 {
00712 PROPID_IncludeChildren->SetPropertyToObject( this, false );
00713 PROPID_Allowrotation->SetPropertyToObject( this, true );
00714 PROPID_Allowskew->SetPropertyToObject( this, false );
00715
00716 return a2dRectMM::DoStartEdit( editmode, editstyle );
00717 }
00718
00719 return false;
00720 }
00721
00722
00723 a2dObject* a2dImageMM::Clone( CloneOptions options ) const
00724 {
00725 return new a2dImageMM( *this, options );
00726 };
00727
00728 void a2dImageMM::DoRender( a2dIterC& ic, OVERLAP WXUNUSED(clipparent) )
00729 {
00730
00731
00732 if (!m_drawPatternOnTop)
00733 {
00734 if (m_flags.m_selected)
00735 {
00736 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00737 }
00738 else if ( !GetStroke().IsSameAs(*a2dTRANSPARENT_STROKE) || !GetFill().IsSameAs(*a2dTRANSPARENT_FILL ) )
00739 {
00740 ic.GetDrawer2D()->DrawCenterRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00741 }
00742 }
00743
00744 if ( ic.GetDrawer2D()->GetDrawStyle() != a2dWIREFRAME_INVERT )
00745 {
00746 ic.GetDrawer2D()->DrawImage( m_image, m_minx + GetWidth()/2.0, m_miny + GetHeight()/2.0, m_maxx - m_minx, m_maxy - m_miny);
00747 }
00748 else
00749 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00750
00751
00752 if (m_drawPatternOnTop)
00753 {
00754 if (m_flags.m_selected)
00755 {
00756 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00757 }
00758 else if ( GetStroke() != *a2dTRANSPARENT_STROKE || GetFill() != *a2dTRANSPARENT_FILL )
00759 {
00760 ic.GetDrawer2D()->DrawRoundedRectangle( m_minx, m_miny, m_maxx - m_minx, m_maxy - m_miny, 0);
00761 }
00762 }
00763 }
00764
00765 bool a2dImageMM::DoIsHitWorld( a2dIterC& WXUNUSED(ic), a2dHitEvent& hitEvent )
00766 {
00767 hitEvent.m_how = a2dHit::stock_fill;
00768 return true;
00769 }
00770
00771 #if wxART2D_USE_CVGIO
00772 void a2dImageMM::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
00773 {
00774 a2dRectMM::DoLoad( parent, parser, xmlparts );
00775 if ( xmlparts == a2dXmlSer_attrib )
00776 {
00777 m_filename = parser.GetAttributeValue( wxT("filename") );
00778 m_type = (wxBitmapType) parser.GetAttributeValueLong( wxT("type") );
00779 m_drawPatternOnTop = parser.GetAttributeValueBool( wxT("patternontop") );
00780
00781 if ( !m_filename.IsEmpty() )
00782 {
00783 wxString fname = a2dGlobals->GetImagePathList().FindValidPath( m_filename );
00784 if ( !::wxFileExists( fname ) )
00785 {
00786 a2dGeneralGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "could not open file %s for loading image" ), m_filename.c_str() );
00787 return;
00788 }
00789 m_image.LoadFile( fname, m_type);
00790 }
00791 else
00792 {
00793 m_image = wxImage( (int) GetWidth(), (int) GetHeight() );
00794 }
00795 }
00796 else
00797 {
00798 }
00799 }
00800
00801 void a2dImageMM::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
00802 {
00803 a2dRectMM::DoSave( parent, out, xmlparts, towrite );
00804 if ( xmlparts == a2dXmlSer_attrib )
00805 {
00806 if ( m_filename.IsEmpty() )
00807 {
00808 m_image.SaveFile( GetName(), m_type );
00809 out.WriteAttribute( wxT("filename"), GetName() );
00810 }
00811 else
00812 {
00813 out.WriteAttribute( wxT("filename"), m_filename );
00814 }
00815 out.WriteAttribute( wxT("type"), (wxInt32) m_type );
00816 out.WriteAttribute( wxT("patternontop"), m_drawPatternOnTop );
00817 }
00818 else
00819 {
00820 }
00821 }
00822 #endif //wxART2D_USE_CVGIO
00823