// {{{RME classifier 'Logical View::Alteracao'

#if defined( PRAGMA ) && ! defined( PRAGMA_IMPLEMENTED )
#pragma implementation "Alteracao.h"
#endif

#include <RTSystem/CorrigirRota.h>
#include <Alteracao.h>
#include <NewProtocol1.h>
#include <math.h>

// {{{RME classifier 'Logical View::Alteracao' tool 'OT::Cpp' property 'ImplementationPreface'
// {{{USR tool 'OT::Cpp' property 'ImplementationPreface'
// }}}USR
// }}}RME

static const RTRelayDescriptor rtg_relays[] =
{
	{
		"NewPort1"
	  , &NewProtocol1::Base::rt_class
	  , 1 // cardinality
	}
};

static RTActor * new_Alteracao_Actor( RTController * _rts, RTActorRef * _ref )
{
	return new Alteracao_Actor( _rts, _ref );
}

const RTActorClass Alteracao =
{
	(const RTActorClass *)0
  , "Alteracao"
  , (RTVersionId)0
  , 1
  , rtg_relays
  , new_Alteracao_Actor
};

static const char * const rtg_state_names[] =
{
	"TOP"
  , "Aguardando_Desvio_Rota"
  , "Processando"
  , "Grava_Dados"
  , "Calcula_Correcao"
  , "Valida_Correcao"
  , "Calcula_AmortizacaoLinear"
  , "Calcula_AmortizacaoAngular"
  , "Calcula_Desvio"
  , "Transferindo_Dados"
};

#define SUPER RTActor

Alteracao_Actor::Alteracao_Actor( RTController * rtg_rts, RTActorRef * rtg_ref )
	: RTActor( rtg_rts, rtg_ref )
{
}

Alteracao_Actor::~Alteracao_Actor( void )
{
}

// {{{RME classifier 'Logical View::Alteracao' operation 'Guardar_DesAngular()'
void Alteracao_Actor::Guardar_DesAngular( void )
{
	// {{{USR operation 'Guardar_DesAngular()'
	// }}}USR
}
// }}}RME

// {{{RME classifier 'Logical View::Alteracao' operation 'Guardar_DesLinear()'
void Alteracao_Actor::Guardar_DesLinear( void )
{
	// {{{USR operation 'Guardar_DesLinear()'
	// }}}USR
}
// }}}RME

// {{{RME classifier 'Logical View::Alteracao' operation 'Guardar_PosBase()'
void Alteracao_Actor::Guardar_PosBase( void )
{
	// {{{USR operation 'Guardar_PosBase()'
	// }}}USR
}
// }}}RME

// {{{RME classifier 'Logical View::Alteracao' operation 'Calcular_Correcao()'
void Alteracao_Actor::Calcular_Correcao( void )
{
	// {{{USR operation 'Calcular_Correcao()'
	if (Desvio < 0 )
	{
		Correcao = PosBase  - Desvio;
	}

	else {
	Correcao = PosBase + Desvio;
	}
	// }}}USR
}
// }}}RME

// {{{RME classifier 'Logical View::Alteracao' operation 'Validar_Correcao()'
void Alteracao_Actor::Validar_Correcao( void )
{
	// {{{USR operation 'Validar_Correcao()'
	// }}}USR
}
// }}}RME

// {{{RME classifier 'Logical View::Alteracao' operation 'Calcular_Desvio()'
void Alteracao_Actor::Calcular_Desvio( void )
{
	// {{{USR operation 'Calcular_Desvio()'
	Desvio = 
	(AmortizacaoA + AmortizacaoL)/0,4;

	// }}}USR
}
// }}}RME

// {{{RME classifier 'Logical View::Alteracao' operation 'Calcular_AmortizacaoA()'
void Alteracao_Actor::Calcular_AmortizacaoA( void )
{
	// {{{USR operation 'Calcular_AmortizacaoA()'
	AmortizacaoA = DesAngular * 0,6;
	// }}}USR
}
// }}}RME

// {{{RME classifier 'Logical View::Alteracao' operation 'Calcular_AmortizacaoL()'
void Alteracao_Actor::Calcular_AmortizacaoL( void )
{
	// {{{USR operation 'Calcular_AmortizacaoL()'
	AmortizacaoL = DesLinear * 0,8;
	// }}}USR
}
// }}}RME

INLINE_CHAINS void Alteracao_Actor::chain1_PowerUp( void )
{
	// transition ':TOP:Initial:PowerUp'
	rtgChainBegin( 1, "PowerUp" );
	rtgTransitionBegin();
	rtgTransitionEnd();
	enterState( 2 );
}

void Alteracao_Actor::rtsBehavior( int signalIndex, int portIndex )
{
	for( int stateIndex = getCurrentState(); ; stateIndex = rtg_parent_state[ stateIndex - 1 ] )
		switch( stateIndex )
		{
		case 1:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					chain1_PowerUp();
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			unexpectedMessage();
			return;
			// }}}RME
		case 2:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Aguardando_Desvio_Rota'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 3:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Processando'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 4:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Processando:Grava_Dados'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 5:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Processando:Calcula_Correcao'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 6:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Processando:Valida_Correcao'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 7:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Processando:Calcula_AmortizacaoLinear'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 8:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Processando:Calcula_AmortizacaoAngular'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 9:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Processando:Calcula_Desvio'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		case 10:
			// {{{RME classifier 'Logical View::Alteracao' state ':TOP:Transferindo_Dados'
			switch( portIndex )
			{
			case 0:
				switch( signalIndex )
				{
				case 1:
					return;
				default:
					break;
				}
				break;
			default:
				break;
			}
			break;
			// }}}RME
		default:
			unexpectedState();
			return;
		}
}

const RTActor_class * Alteracao_Actor::getActorData( void ) const
{
	return &Alteracao_Actor::rtg_class;
}

const RTActor_class Alteracao_Actor::rtg_class =
{
	(const RTActor_class *)0
  , rtg_state_names
  , 10
  , Alteracao_Actor::rtg_parent_state
  , &Alteracao
  , 0
  , (const RTComponentDescriptor *)0
  , 0
  , (const RTPortDescriptor *)0
  , 0
  , (const RTLocalBindingDescriptor *)0
  , 7
  , Alteracao_Actor::rtg_Alteracao_fields
};

const RTStateId Alteracao_Actor::rtg_parent_state[] =
{
	0
  , 1
  , 1
  , 3
  , 3
  , 3
  , 3
  , 3
  , 3
  , 1
};

const RTFieldDescriptor Alteracao_Actor::rtg_Alteracao_fields[] =
{
	// {{{RME classifier 'Logical View::Alteracao' classAttribute 'DesLinear'
	{
		"DesLinear"
	  , RTOffsetOf( Alteracao_Actor, DesLinear )
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'DesLinear' tool 'OT::CppTargetRTS' property 'TypeDescriptor'
	  , &RTType_float
		// }}}RME
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'DesLinear' tool 'OT::CppTargetRTS' property 'GenerateTypeModifier'
	  , (const RTTypeModifier *)0
		// }}}RME
	}
	// }}}RME
	// {{{RME classifier 'Logical View::Alteracao' classAttribute 'DesAngular'
  , {
		"DesAngular"
	  , RTOffsetOf( Alteracao_Actor, DesAngular )
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'DesAngular' tool 'OT::CppTargetRTS' property 'TypeDescriptor'
	  , &RTType_float
		// }}}RME
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'DesAngular' tool 'OT::CppTargetRTS' property 'GenerateTypeModifier'
	  , (const RTTypeModifier *)0
		// }}}RME
	}
	// }}}RME
	// {{{RME classifier 'Logical View::Alteracao' classAttribute 'PosBase'
  , {
		"PosBase"
	  , RTOffsetOf( Alteracao_Actor, PosBase )
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'PosBase' tool 'OT::CppTargetRTS' property 'TypeDescriptor'
	  , &RTType_float
		// }}}RME
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'PosBase' tool 'OT::CppTargetRTS' property 'GenerateTypeModifier'
	  , (const RTTypeModifier *)0
		// }}}RME
	}
	// }}}RME
	// {{{RME classifier 'Logical View::Alteracao' classAttribute 'Desvio'
  , {
		"Desvio"
	  , RTOffsetOf( Alteracao_Actor, Desvio )
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'Desvio' tool 'OT::CppTargetRTS' property 'TypeDescriptor'
	  , &RTType_float
		// }}}RME
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'Desvio' tool 'OT::CppTargetRTS' property 'GenerateTypeModifier'
	  , (const RTTypeModifier *)0
		// }}}RME
	}
	// }}}RME
	// {{{RME classifier 'Logical View::Alteracao' classAttribute 'AmortizacaoA'
  , {
		"AmortizacaoA"
	  , RTOffsetOf( Alteracao_Actor, AmortizacaoA )
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'AmortizacaoA' tool 'OT::CppTargetRTS' property 'TypeDescriptor'
	  , &RTType_float
		// }}}RME
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'AmortizacaoA' tool 'OT::CppTargetRTS' property 'GenerateTypeModifier'
	  , (const RTTypeModifier *)0
		// }}}RME
	}
	// }}}RME
	// {{{RME classifier 'Logical View::Alteracao' classAttribute 'AmortizacaoL'
  , {
		"AmortizacaoL"
	  , RTOffsetOf( Alteracao_Actor, AmortizacaoL )
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'AmortizacaoL' tool 'OT::CppTargetRTS' property 'TypeDescriptor'
	  , &RTType_float
		// }}}RME
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'AmortizacaoL' tool 'OT::CppTargetRTS' property 'GenerateTypeModifier'
	  , (const RTTypeModifier *)0
		// }}}RME
	}
	// }}}RME
	// {{{RME classifier 'Logical View::Alteracao' classAttribute 'Correcao'
  , {
		"Correcao"
	  , RTOffsetOf( Alteracao_Actor, Correcao )
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'Correcao' tool 'OT::CppTargetRTS' property 'TypeDescriptor'
	  , &RTType_float
		// }}}RME
		// {{{RME classifier 'Logical View::Alteracao' classAttribute 'Correcao' tool 'OT::CppTargetRTS' property 'GenerateTypeModifier'
	  , (const RTTypeModifier *)0
		// }}}RME
	}
	// }}}RME
};
#undef SUPER

// {{{RME classifier 'Logical View::Alteracao' tool 'OT::Cpp' property 'ImplementationEnding'
// {{{USR tool 'OT::Cpp' property 'ImplementationEnding'
// }}}USR
// }}}RME

// }}}RME