#include "CurveCreator.h"
#include <QtCore/QVector>
#include <math.h>
IMPLEMENT_CLASS( CurveCreator, BrushOperation, "CurveCreator" );
static QVector< Store< Vector >* > gLines;
QVector< Store<Vector>* >& CurveCreator::Lines() { return gLines; }
CurveCreator::CurveCreator() :
m_iCurrentCurve( -1 ),
m_iDoState( 0 )
{
};
void CurveCreator::BeginStroke( Mesh *, Modifier, TriggerType )
{
gLines.push_back( new Store<Vector> );
m_iDoState = 0;
m_iCurrentCurve = gLines.size() - 1;
};
void CurveCreator::EndStroke( void )
{
if( gLines.back()->ItemCount() == 0 )
{
m_iCurrentCurve = -1;
gLines.pop_back();
};
Kernel()->DoOperation( this );
Kernel()->Redraw();
};
void CurveCreator::AddPatch( const SurfacePoint *, const Vector &, float, float, float, AxisAlignedBoundingBox & )
{
};
void CurveCreator::MouseMove( float fX, float fY, float , float , AxisAlignedBoundingBox &a )
{
SurfacePoint pp;
ViewPort *pVPp = Kernel()->ViewPort();
if( Kernel()->Scene()->ActiveCamera()->Pick( fX*pVPp->Width(), fY*pVPp->Height(), pp ) )
{
gLines.back()->Add( pp.WorldPosition() );
};
for( unsigned int i = 0; i < gLines.size(); ++i )
{
for( unsigned int j = 0; j < gLines[i]->ItemCount(); ++j )
a.Extend( gLines[i]->operator[](j) );
};
};
bool CurveCreator::ExecuteAndInvert( void )
{
if( m_iDoState == 0 )
{
m_iLine.Clear();
m_iDoState = 1;
}
else if( m_iDoState == 1 )
{
if( m_iCurrentCurve != -1 )
{
Store<Vector>* pLine = gLines.back();
m_iLine = *pLine;
gLines.pop_back();
delete pLine;
pLine = 0;
};
m_iDoState = 2;
}
else if( m_iDoState == 2 )
{
if( m_iCurrentCurve != -1 )
{
Store<Vector>* pNewLine = new Store<Vector>;
*pNewLine = m_iLine;
gLines.push_back( pNewLine );
};
m_iDoState = 1;
};
Kernel()->Redraw();
return true;
};
void CurveCreator::Serialize( Stream &s )
{
s == m_iCurrentCurve == m_iLine == m_iDoState;
};