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/wfstream.h>
00022 #include <math.h>
00023
00024 #include "wx/canextobj/canobj3d.h"
00025
00026 #include "wx/canvas/candoc.h"
00027 #include "wx/canvas/polygon.h"
00028 #include "wx/canvas/drawer.h"
00029
00030
00031
00032
00033
00034 IMPLEMENT_CLASS(a2d3DShape, a2dCanvasObject)
00035
00036 #define CIRCLE_STEPS 128
00037
00038
00039
00040
00041
00042 a2d3DShape::a2d3DShape( a2dCanvasObject* toshadow, double depth, double angle ): a2dCanvasObject()
00043 {
00044 m_shape = toshadow;
00045
00046 SetFill( *a2dBLACK_FILL );
00047 SetStroke( *a2dBLACK_STROKE );
00048 m_depth = depth;
00049 m_angle3d = wxDegToRad(angle);
00050 }
00051
00052 a2d3DShape::~a2d3DShape()
00053 {
00054 }
00055
00056 a2d3DShape::a2d3DShape( const a2d3DShape &other, CloneOptions options )
00057 :a2dCanvasObject( other, options )
00058 {
00059 m_depth = other.m_depth;
00060 m_angle3d = other.m_angle3d;
00061 m_shape=other.m_shape;
00062 }
00063
00064 a2dObject* a2d3DShape::Clone( CloneOptions options ) const
00065 {
00066 return new a2d3DShape( *this, options );
00067 };
00068
00069 void a2d3DShape::SetExtrudeFillFromShape()
00070 {
00071 SetFill( m_shape->GetFill() );
00072 SetPending(true);
00073 }
00074 void a2d3DShape::SetExtrudeStrokeFromShape()
00075 {
00076 SetStroke( m_shape->GetStroke() );
00077 SetPending(true);
00078 }
00079
00080 void a2d3DShape::DoWalker( wxObject *parent, a2dWalkerIOHandler& handler )
00081 {
00082 a2dCanvasObject::DoWalker( parent, handler );
00083 if (m_shape)
00084 m_shape->Walker( this, handler );
00085 }
00086
00087 bool a2d3DShape::DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox )
00088 {
00089 bool calc=false;
00090
00091
00092
00093 if ( m_shape->GetCanvasDocument()==m_root )
00094 {
00095 calc=m_shape->Update( mode );
00096 if ( ( mode & updatemask_force ) || calc || !m_bbox.GetValid() )
00097 {
00098 m_bbox.SetValid(false);
00099 m_bbox.Expand( m_shape->GetMappedBbox(m_lworld) );
00100
00101 a2dAffineMatrix tworld = m_lworld;
00102 tworld.Translate( cos(m_angle3d)*m_depth, sin(m_angle3d)*m_depth );
00103 m_bbox.Expand( m_shape->GetMappedBbox(tworld) );
00104
00105 calc=true;
00106 }
00107 }
00108
00109 return calc;
00110 }
00111
00112 void a2d3DShape::DoRender( a2dIterC& ic, OVERLAP WXUNUSED(clipparent) )
00113 {
00114 a2dAffineMatrix inverse = m_lworld;
00115 inverse.Invert();
00116
00117 a2dAffineMatrix tworld = ic.GetTransform();
00118 tworld *= inverse;
00119
00120 a2dRectC* rec = wxDynamicCast( m_shape.Get(), a2dRectC);
00121 if ( rec )
00122 {
00123 a2dVertexArray* cpoints = new a2dVertexArray;
00124 a2dAffineMatrix tworld = ic.GetTransform();
00125 tworld *= m_shape->GetTransformMatrix();
00126
00127
00128
00129 ic.GetDrawer2D()->SetTransform( tworld );
00130
00131 if (m_angle3d > 0)
00132 {
00133 cpoints->push_back( new a2dLineSegment( -rec->GetWidth()/2, rec->GetHeight()/2));
00134 cpoints->push_back( new a2dLineSegment( -rec->GetWidth()/2+ cos(m_angle3d-wxPI/30)*m_depth, rec->GetHeight()/2+ sin(m_angle3d-wxPI/30)*m_depth));
00135 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2+ cos(m_angle3d)*m_depth, rec->GetHeight()/2+ sin(m_angle3d-wxPI/30)*m_depth));
00136 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, rec->GetHeight()/2));
00137
00138 ic.GetDrawer2D()->DrawPolygon( cpoints, false, wxWINDING_RULE);
00139 cpoints->clear();
00140 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, rec->GetHeight()/2));
00141 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2+ cos(m_angle3d)*m_depth, rec->GetHeight()/2+ sin(m_angle3d-wxPI/30)*m_depth));
00142 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2+ cos(m_angle3d)*m_depth, -rec->GetHeight()/2+ sin(m_angle3d)*m_depth));
00143 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, -rec->GetHeight()/2));
00144
00145 ic.GetDrawer2D()->DrawPolygon( cpoints, false, wxWINDING_RULE);
00146 }
00147 else
00148 {
00149
00150 cpoints->push_back( new a2dLineSegment( -rec->GetWidth()/2, -rec->GetHeight()/2));
00151 cpoints->push_back( new a2dLineSegment( -rec->GetWidth()/2+ cos(m_angle3d+wxPI/30)*m_depth, -rec->GetHeight()/2+ sin(m_angle3d+wxPI/30)*m_depth));
00152 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2+ cos(m_angle3d)*m_depth, -rec->GetHeight()/2+ sin(m_angle3d+wxPI/30)*m_depth));
00153 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, -rec->GetHeight()/2));
00154
00155 ic.GetDrawer2D()->DrawPolygon( cpoints, false, wxWINDING_RULE);
00156 cpoints->clear();
00157 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, rec->GetHeight()/2));
00158 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2+ cos(m_angle3d)*m_depth, rec->GetHeight()/2+ sin(m_angle3d)*m_depth));
00159 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2+ cos(m_angle3d)*m_depth, -rec->GetHeight()/2+ sin(m_angle3d+wxPI/30)*m_depth));
00160 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, -rec->GetHeight()/2));
00161
00162 ic.GetDrawer2D()->DrawPolygon( cpoints, false, wxWINDING_RULE);
00163 }
00164
00165 cpoints->push_back( new a2dLineSegment( -rec->GetWidth()/2, -rec->GetHeight()/2));
00166 cpoints->push_back( new a2dLineSegment( -rec->GetWidth()/2, rec->GetHeight()/2));
00167 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, rec->GetHeight()/2));
00168 cpoints->push_back( new a2dLineSegment( rec->GetWidth()/2, -rec->GetHeight()/2));
00169
00170 ic.GetDrawer2D()->DrawPolygon( cpoints, false, wxWINDING_RULE);
00171
00172 cpoints->clear();
00173
00174 delete cpoints;
00175 }
00176 }
00177
00178 #if wxART2D_USE_CVGIO
00179 void a2d3DShape::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
00180 {
00181 a2dCanvasObject::DoSave( parent, out, xmlparts, towrite );
00182 if ( xmlparts == a2dXmlSer_attrib )
00183 {
00184 }
00185 else
00186 {
00187
00188 if ( m_shape->GetCanvasDocument()==m_root )
00189 {
00190 m_shape->Save( this, out, towrite);
00191 }
00192 }
00193 }
00194
00195 void a2d3DShape::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
00196 {
00197 a2dCanvasObject::DoLoad( parent, parser, xmlparts );
00198 }
00199
00200 #endif //wxART2D_USE_CVGIO
00201
00202 bool a2d3DShape::DoIsHitWorld( a2dIterC& WXUNUSED(ic), a2dHitEvent& hitEvent )
00203 {
00204 hitEvent.m_how = a2dHit::stock_fill;
00205 return true;
00206
00207
00208 }
00209