/*
 * Copyright (C) 2008-2012 Delft University of Technology - All rights reserved.
 *
 * Author: Reijer Idema
 */

/*
 * Power System Branch class source.
 */
#include <sstream>		// USES stringstream
#include "Branch.h"

POWERSYSTEM_NAMESPACE_BEGIN

/////////////////////////////// PUBLIC ///////////////////////////////////////

//============================= LIFECYCLE ====================================

Branch::Branch(void) :
	mIsActive(false), mFromBus(0), mToBus(0),
	mResistance(0), mReactance(0), mSusceptance(0), mRatio(0), mAngle(0) { }

//============================= OPERATIONS ===================================

std::string Branch::ToString(void) const
{
	std::stringstream ss;
	ss << *this;
	return ss.str();
} // operator<<

//============================= ACCESS     ===================================

bool Branch::IsActive(void) const { return mIsActive; }
void Branch::Activate(void) { mIsActive = true; }
void Branch::Deactivate(void) { mIsActive = false; }

Branch::BusIndexType Branch::GetFromBus(void) const { return mFromBus; }
Branch::BusIndexType Branch::SetFromBus(BusIndexType i) { return (mFromBus = i); }

Branch::BusIndexType Branch::GetToBus(void) const { return mToBus; }
Branch::BusIndexType Branch::SetToBus(BusIndexType i) { return (mToBus = i); }

double Branch::GetResistance(void) const { return mResistance; }
double Branch::SetResistance(double val) { return (mResistance = val); }

double Branch::GetReactance(void) const { return mReactance; }
double Branch::SetReactance(double val) { return (mReactance = val); }

double Branch::GetSusceptance(void) const { return mSusceptance; }
double Branch::SetSusceptance(double val) { return (mSusceptance = val); }

double Branch::GetRatio(void) const { return mRatio; }
double Branch::SetRatio(double val) { return (mRatio = val); }

double Branch::GetAngle(void) const { return mAngle; }
double Branch::SetAngle(double val) { return (mAngle = val); }

/////////////////////////////// NON-MEMBER ///////////////////////////////////

std::ostream& operator<<(std::ostream& rOutput, const Branch& rBranch)
{
	std::string sep = "\t";		// tab seperator
	rOutput << rBranch.GetFromBus() << sep << rBranch.GetToBus() << ":" << sep;
	rOutput << rBranch.GetResistance() << sep << rBranch.GetReactance() << sep;
	rOutput << rBranch.GetSusceptance() << sep;
	rOutput << rBranch.GetRatio() << sep << rBranch.GetAngle() << sep;
	rOutput << (rBranch.IsActive() ? "ON" : "OFF");
	return rOutput;
}

POWERSYSTEM_NAMESPACE_END
