00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _WX_MATRIXH__
00019 #define _WX_MATRIXH__
00020
00021 #include "wx/geometry.h"
00022 #include "wx/artbase/artglob.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class A2DARTBASEDLLEXP a2dAffineMatrix
00054 {
00055 public:
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 a2dAffineMatrix( double xt, double yt, double scalex = 1, double scaley = 1, double degrees = 0 );
00070
00071 a2dAffineMatrix( double sx, double shx, double shy, double sy, double tx, double ty );
00072
00073
00074 a2dAffineMatrix( void );
00075
00076
00077 a2dAffineMatrix( const a2dAffineMatrix& mat );
00078
00079
00080
00081
00082
00083
00084 double GetValue( int col, int row ) const;
00085
00086
00087
00088
00089
00090
00091 void SetValue( int col, int row, double value );
00092
00093
00094 void operator= ( const a2dAffineMatrix& mat );
00095
00096
00097 friend A2DARTBASEDLLEXP bool operator == ( const a2dAffineMatrix& a, const a2dAffineMatrix& b );
00098
00099
00100 friend A2DARTBASEDLLEXP bool operator != ( const a2dAffineMatrix& a, const a2dAffineMatrix& b );
00101
00102
00103 bool operator== ( const a2dAffineMatrix& a );
00104
00105
00106 bool operator!= ( const a2dAffineMatrix& a );
00107
00108
00109 a2dAffineMatrix& operator*=( const a2dAffineMatrix& m );
00110
00111
00112 a2dAffineMatrix operator*( const a2dAffineMatrix& m ) const;
00113
00114
00115 a2dAffineMatrix operator-( const a2dAffineMatrix& a );
00116
00117
00118 friend A2DARTBASEDLLEXP a2dAffineMatrix operator-( const a2dAffineMatrix& a, const a2dAffineMatrix& b );
00119
00120 static inline a2dAffineMatrix Mul( const a2dAffineMatrix &m1, const a2dAffineMatrix &m2 ) { return m1 * m2; }
00121
00122
00123
00124
00125
00126 double& operator()( int col, int row );
00127
00128
00129
00130
00131
00132 double operator()( int col, int row ) const;
00133
00134
00135 bool Invert( void );
00136
00137
00138 bool Identity( void );
00139
00140
00141 static const a2dAffineMatrix &GetIdentityMatrix() {return sm_Identity; }
00142
00143
00144
00145
00146
00147 inline bool IsIdentity( void ) const { return m_isIdentity; }
00148
00149
00150 inline bool IsIdentity1( void ) const ;
00151
00152
00153
00154
00155 inline bool IsTranslate( void ) const;
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 bool Scale( double scale );
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 bool RemoveScale();
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 a2dAffineMatrix& Scale( const double &xs, const double &ys, const double &xc, const double &yc );
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 a2dAffineMatrix& Mirror( bool y = true, bool x = false );
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 bool Translate( double x, double y );
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 bool Rotate( double angle );
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 bool SkewX( double degrees );
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 bool SkewY( double degrees );
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 a2dAffineMatrix& Rotate( const double &r, const double &x, const double &y );
00252
00253
00254 void TransformPoint( double x, double y, double& tx, double& ty ) const;
00255
00256
00257 void TransformPoint( double& tx, double& ty ) const;
00258
00259
00260 void TransformPoint( a2dPoint2D *point ) const;
00261
00262
00263 void TransformPoint( const a2dPoint2D& src, a2dPoint2D *dest ) const;
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 void TransformVector( double dx, double dy, double& tdx, double& tdy ) const;
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 double TransformDistance( double distance ) const;
00286
00287
00288 void TransformDistance( double& dx, double& dy ) const;
00289
00290
00291 double Get_scaleX() const;
00292
00293
00294 double Get_scaleY() const;
00295
00296
00297
00298
00299
00300
00301 double GetRotation() const;
00302
00303
00304
00305
00306
00307
00308 void SetRotation( double rotation );
00309
00310
00311 a2dPoint2D GetTranslation() const { return a2dPoint2D( m_matrix[2][0], m_matrix[2][1] ); }
00312
00313
00314 double GetDeterminant() const;
00315
00316 double GetDeterminant1() const;
00317
00318 double GetDeterminant2() const;
00319
00320 double GetMaximum() const;
00321
00322 double GetMaximum1() const;
00323
00324 double GetMaximum2() const;
00325
00326
00327 void DebugDump( const wxChar *text, double w, double h ) const;
00328
00329
00330 public:
00331
00332
00333 double m_matrix[3][2];
00334
00335
00336 bool m_isIdentity;
00337
00338 protected:
00339
00340 static const a2dAffineMatrix sm_Identity;
00341 };
00342
00343
00344
00345 inline bool a2dAffineMatrix::IsIdentity1( void ) const
00346 {
00347 return
00348 ( m_matrix[0][0] == 1.0 &&
00349 m_matrix[1][1] == 1.0 &&
00350 m_matrix[1][0] == 0.0 &&
00351 m_matrix[2][0] == 0.0 &&
00352 m_matrix[0][1] == 0.0 &&
00353 m_matrix[2][1] == 0.0
00354 );
00355 }
00356
00357 inline bool a2dAffineMatrix::IsTranslate( void ) const
00358 {
00359 return
00360 ( m_matrix[0][0] == 1.0 &&
00361 m_matrix[1][1] == 1.0 &&
00362 m_matrix[1][0] == 0.0 &&
00363 m_matrix[0][1] == 0.0
00364 );
00365 }
00366
00367
00368 A2DARTBASEDLLEXP_DATA( extern a2dAffineMatrix ) a2dIDENTITY_MATRIX;
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 extern A2DARTBASEDLLEXP bool ParseCvgTransForm( a2dAffineMatrix& matrix, const wxString& str, wxString& error );
00379
00380
00381
00382
00383
00384
00385
00386 class A2DARTBASEDLLEXP a2dMatrixProperty;
00387 #if defined(WXART2D_USINGDLL)
00388 template class A2DARTBASEDLLEXP a2dPropertyIdTyped<a2dAffineMatrix, a2dMatrixProperty>;
00389 #endif
00390 typedef a2dPropertyIdTyped<a2dAffineMatrix, a2dMatrixProperty> a2dPropertyIdMatrix;
00391
00392
00393
00394
00395
00396
00397 class A2DARTBASEDLLEXP a2dMatrixProperty: public a2dNamedProperty
00398 {
00399 public:
00400
00401 a2dMatrixProperty();
00402
00403 a2dMatrixProperty( const a2dPropertyIdMatrix* id, const a2dAffineMatrix& value = a2dIDENTITY_MATRIX );
00404
00405 a2dMatrixProperty( const a2dMatrixProperty* ori );
00406
00407 a2dMatrixProperty( const a2dMatrixProperty &other );
00408
00409 virtual ~a2dMatrixProperty();
00410
00411 a2dNamedProperty* Clone( a2dObject::CloneOptions options ) const;
00412
00413 virtual void Assign( const a2dNamedProperty &other );
00414
00415 void SetValue( const a2dAffineMatrix& value );
00416
00417 a2dAffineMatrix& GetValue() { return m_value; }
00418 const a2dAffineMatrix& GetValue() const { return m_value; }
00419
00420 a2dAffineMatrix* GetValuePtr() { return & m_value; }
00421
00422 virtual wxString StringRepresentation() const;
00423
00424 virtual wxString StringValueRepresentation() const;
00425
00426
00427
00428 static a2dMatrixProperty *CreatePropertyFromString( const a2dPropertyIdMatrix* id, const wxString &value );
00429
00430 #if wxART2D_USE_CVGIO
00431 virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
00432 virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
00433 #endif //wxART2D_USE_CVGIO
00434
00435 DECLARE_DYNAMIC_CLASS( a2dMatrixProperty )
00436
00437 protected:
00438
00439 a2dAffineMatrix m_value;
00440 };
00441
00442
00443 class A2DARTBASEDLLEXP a2dPoint2DProperty;
00444 #if defined(WXART2D_USINGDLL)
00445 template class A2DARTBASEDLLEXP a2dPropertyIdTyped<a2dPoint2D, a2dPoint2DProperty>;
00446 #endif
00447 typedef a2dPropertyIdTyped<a2dPoint2D, a2dPoint2DProperty> a2dPropertyIdPoint2D;
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 class A2DARTBASEDLLEXP a2dPoint2DProperty: public a2dNamedProperty
00459 {
00460 public:
00461
00462
00463 a2dPoint2DProperty();
00464
00465
00466 a2dPoint2DProperty( const a2dPropertyIdPoint2D* id, const a2dPoint2D& value, int index = 0, bool afterinversion = false );
00467
00468
00469 a2dPoint2DProperty( const a2dPoint2DProperty* ori );
00470
00471
00472 a2dPoint2DProperty( const a2dPoint2DProperty &other );
00473
00474
00475 virtual ~a2dPoint2DProperty();
00476
00477
00478 a2dNamedProperty* Clone( a2dObject::CloneOptions options ) const;
00479
00480 virtual void Assign( const a2dNamedProperty &other );
00481
00482
00483
00484 static a2dPoint2DProperty *CreatePropertyFromString( const a2dPropertyIdPoint2D* id, const wxString &value );
00485
00486
00487 void SetValue( double x, double y, int index = 0, bool afterinversion = false );
00488
00489
00490 void SetValue( const a2dPoint2D& P, int index = 0, bool afterinversion = false );
00491
00492
00493 a2dPoint2D& GetValue() { return m_value; }
00494 const a2dPoint2D& GetValue() const { return m_value; }
00495
00496
00497 a2dPoint2D* GetValuePtr() { return & m_value; }
00498
00499
00500 wxInt32 GetIndex() { return m_index; }
00501
00502
00503 bool GetAfterinversion() { return m_afterinversion; }
00504
00505
00506 virtual wxString StringRepresentation() const;
00507
00508
00509 virtual wxString StringValueRepresentation() const;
00510
00511 #if wxART2D_USE_CVGIO
00512 virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
00513 virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
00514 #endif //wxART2D_USE_CVGIO
00515
00516 DECLARE_DYNAMIC_CLASS( a2dPoint2DProperty )
00517
00518 protected:
00519
00520
00521 a2dPoint2D m_value;
00522
00523
00524 wxInt32 m_index;
00525
00526
00527
00528 bool m_afterinversion;
00529 };
00530
00531 #endif
00532