/*****************************************************
**
**   GenericTableWriter   ---   writeCustomDataEntry
**
******************************************************/
void GenericTableWriter::writeCustomDataEntry( const uint &col, const uint &row, const TAB_CELL_TYPE &type )
{
	assert( table->getNbCols() > col );
	assert( table->getNbRows() > row );
	Formatter *f = Formatter::get();
	DateTimeFormatter *df = DateTimeFormatter::get();
	Lang lang;
	wxString s;
	
	switch( type )
	{
		case TAB_CELL_NAME:
			table->setEntry( col, row,  _( "Name" ));
			table->setEntry( col + 1, row, h->getHName() );
		break;
		case TAB_CELL_FULL_DATE:
		{
			table->setEntry( col, row,  _( "Date" ));
			Location *loc = h->getDataSet()->getLocation();
			table->setEntry( col + 1, row, df->formatDateString( h->getJD(), loc->getTimeZone() + loc->getDST()));
		}
		break;
		case TAB_CELL_LOCAL_TIME:
		{
			table->setEntry( col, row,  _( "Local Time" ));
			Location *loc = h->getDataSet()->getLocation();
			table->setEntry( col + 1, row, f->getTimeFormatted( a_red( getTimeFromJD( h->getDataSet()->getDate()->getJD()) + loc->getTimeZone() + loc->getDST(), 24 )));
		}
		break;
		case TAB_CELL_LOCATION_NAME:
			table->setEntry( col, row,  _( "Location" ));
			table->setEntry( col + 1, row, h->getDataSet()->getLocation()->getLocName() );
		break;
		case TAB_CELL_LOCATION_LONGITUDE:
		{
			table->setEntry( col, row,  _( "Longitude" ));
			Location *loc = h->getDataSet()->getLocation();
			table->setEntry( col + 1, row, f->getLongitudeFormatted( loc->getLongitude()));
		}
		break;
		case TAB_CELL_LOCATION_LATITUDE:
		{
			table->setEntry( col, row,  _( "Latitude" ));
			Location *loc = h->getDataSet()->getLocation();
			table->setEntry( col + 1, row, f->getLatitudeFormatted( loc->getLatitude()));
		}
		break;
		case TAB_CELL_TZ_NAME:
		{
			table->setEntry( col, row,  _( "Time Zone" ));
			Location *loc = h->getDataSet()->getLocation();
			const double tz = loc->getTimeZone();
			table->setEntry( col + 1, row, wxString::Format( wxT( "%s %c%.1f" ), _( "UT" ), ( tz >= 0 ? '+' : ' ' ), tz ));
		}
		break;
		case TAB_CELL_DST:
		{
			table->setEntry( col, row,  _( "Daylight Saving" ));
			Location *loc = h->getDataSet()->getLocation();
			table->setEntry( col + 1, row, wxString::Format( wxT( "%.1f" ), loc->getDST()));
		}
		break;
		case TAB_CELL_UNIVERSAL_TIME:
			table->setEntry( col, row,  _( "Universal Time" ));
			table->setEntry( col + 1, row, f->getTimeFormatted( getTimeFromJD( h->getJD() )));
		break;
		case TAB_CELL_SIDEREAL_TIME:
			table->setEntry( col, row,  _( "Sidereal Time" ));
			table->setEntry( col + 1, row, f->getTimeFormatted( h->getSiderealTime()));
		break;
		case TAB_CELL_JULIAN_DATE:
			table->setEntry( col, row,  _( "Julian Date" ));
			table->setEntry( col + 1, row, wxString::Format( wxT( "%8.5f" ), h->getJD()));
		break;
		case TAB_CELL_SUNRISE:
		{
			table->setEntry( col, row,  _( "Sunrise" ));
			Location *loc = h->getLocation();
			if ( h->getSunrise() != 0 )
			{
				s = f->getTimeFormatted( getTimeFromJD( h->getSunrise() + ( loc->getTimeZone() + loc->getDST()) / 24.0 ));
			}
			else s = _( "n.a." );
			table->setEntry( col + 1, row, s );
		}
		break;
		case TAB_CELL_SUNSET:
		{
			table->setEntry( col, row,  _( "Sunset" ));
			Location *loc = h->getLocation();
			if ( h->getSunset() != 0 )
			{
				s = f->getTimeFormatted( getTimeFromJD( h->getSunset() + ( loc->getTimeZone() + loc->getDST()) / 24.0 ));
			}
			else s = _( "n.a." );
			table->setEntry( col + 1, row, s );
		}
		break;
		case TAB_CELL_VEDIC_AYANAMSA:
			table->setEntry( col, row,  _( "Vedic Ayanamsa" ));
			table->setEntry( col + 1, row, f->getAyanamsaNameAndValue( h->getAyanamsaType( true ), h->getAyanamsa( true )));
		break;
		case TAB_CELL_WESTERN_AYANAMSA:
			table->setEntry( col, row,  _( "Western Ayanamsa" ));
			table->setEntry( col + 1, row, f->getAyanamsaNameAndValue( h->getAyanamsaType( false ), h->getAyanamsa( false )));
		break;
		case TAB_CELL_VARNA:
			table->setEntry( col, row,  _( "Varna" ));
			table->setEntry( col + 1, row, lang.getVarnaName( getVarna( h->getVedicLongitude( OMOON ))));
		break;
		case TAB_CELL_GANA:
			table->setEntry( col, row,  _( "Gana" ));
			table->setEntry( col + 1, row, lang.getGanaName( NakshatraExpert().getGana( h->getVedicLongitude( OMOON ))));
		break;
		case TAB_CELL_YONI:
		{
			Yoni yoni = NakshatraExpert().getYoni( h->getVedicLongitude( OMOON ));
			table->setEntry( col, row,  _( "Yoni" ));
			table->setEntry( col + 1, row, yoni.name );
		}
		break;
		case TAB_CELL_NADI:
			table->setEntry( col, row,  _( "Nadi" ));
			table->setEntry( col + 1, row, lang.getNadiName( NakshatraExpert().getNadi( h->getVedicLongitude( OMOON ))));
		break;
		case TAB_CELL_RAJJU:
		{
			Rajju rajju = NakshatraExpert().getRajju( getNakshatra27( h->getVedicLongitude( OMOON )));
			table->setEntry( col, row,  _( "Rajju" ));
			table->setEntry( col + 1, row, lang.getRajjuName( rajju.aroha, rajju.type ));
		}
		break;
		case TAB_CELL_INCFLUENCE_TIME:
		{
			DasaExpert *expert = DasaExpertFactory().getDasaExpert( D_VIMSOTTARI, h );
			table->setEntry( col, row,  _( "Influence" ));
			table->setEntry( col + 1, row, expert->getDasaLordNameF( expert->getBirthMahaDasaLord(), TF_LONG ));
		}
		break;

		case TAB_CELL_LUNAR_TITHI:
		{
			double angle = red_deg( h->getVedicLongitude( OMOON ) - h->getVedicLongitude( OSUN ));
			table->setEntry( col, row,  _( "Lunar Tithi" ));
			table->setEntry( col + 1, row,  lang.getTithiName( angle / 12 ));
		}
		break;
		case TAB_CELL_WEEKDAY:
			table->setEntry( col, row,  _( "Weekday" ));
			table->setEntry( col + 1, row,  lang.getWeekdayName( h->getDataSet()->getWeekDay() ));
		break;

		case TAB_CELL_HORA_LORD:
		case TAB_CELL_DINA_LORD:
		case TAB_CELL_MASA_LORD:
		case TAB_CELL_VARSHA_LORD:
			writeHoraEntry( col, row, type );
		break;
		default:
			table->setEntry( col, row,  wxString::Format( wxT( "Error, wrong custom data entry id %d" ), (int)type ));
		break;
	};
}
/*****************************************************
**
**   TextHelper   ---   writeTextAnalysis
**
******************************************************/
int TextHelper::writeTextAnalysis( const int &mode, const int varga, const int dasa )
{
	int ret = 0;
	switch ( mode )
	{
	case TEXT_MODE_BASE:
		writeBaseData();
		break;

	case TEXT_MODE_WESTERN_PLANETS:
		ret = writeWesternPlanetReport();
		break;

	case TEXT_MODE_VEDIC_PLANETS:
		ret = writeVedicPlanetReport();
		break;

	case TEXT_MODE_NAKSHATRA:
	{
		NakshatraExpert( horoscope ).write( writer, chartprops, show_header );
	}
	break;

	case TEXT_MODE_ASHTAKAVARGA:
	{
		VargaHoroscope chart( horoscope, varga );
		AshtakavargaExpert aexpert( &chart );
		aexpert.update();
		aexpert.write( writer, show_header );
	}
	break;
	case TEXT_MODE_KP:
		ret = writeKp( dasa );
		break;

	case TEXT_MODE_BHAVA:
		writeBhavas();
		break;

	case TEXT_MODE_ARABICPARTS:
	{
		ArabicPartsExpert( horoscope ).write( writer, chartprops->isVedic(), show_header );
	}
	break;

	case TEXT_MODE_VEDIC_ASPECTARIUM:
	{
		AspectExpert aspexpert( horoscope );
		aspexpert.writeVedicAspectarium( horoscope, writer, chartprops, show_header );
	}
	break;

	case TEXT_MODE_WESTERN_ASPECTARIUM:
	{
		AspectExpert aspexpert( horoscope );
		aspexpert.update( horoscope, chartprops );
		if ( show_header ) writer->writeHeader1( _( "Aspectarium" ));
		aspexpert.writeWesternAspectarium( writer, chartprops );
		aspexpert.writeWesternAspectList( writer, chartprops );
	}
	break;

	case TEXT_MODE_WESTERN_ASPECTARIUM_PLAIN:
	{
		AspectExpert aspexpert( horoscope );
		aspexpert.update( horoscope, chartprops );
		aspexpert.writeWesternAspectarium( writer, chartprops );
	}
	break;

	case TEXT_MODE_ASTRONOMICAL:
		ret = writeAstronomicalData();
		break;

	case TEXT_MODE_VARGA:
	{
		VargaExpert vexpert( horoscope );
		vexpert.write( writer, chartprops->getVedicObjectStyle(), show_header );
	}
	break;

	case TEXT_MODE_DASA:
		assert( dasa >= 0 && dasa < (int)DasaExpertFactory::MAX_DASAEXPERTS );
		DasaExpertFactory::get()->getDasaExpert( dasa )->write( writer, horoscope, varga, show_header );
		break;

	case TEXT_MODE_DASACOMPACT:
		assert( dasa >= 0 && dasa < (int)DasaExpertFactory::MAX_DASAEXPERTS );
		DasaExpertFactory::get()->getDasaExpert( dasa )->writeCompact( writer, horoscope, varga, show_header );
		break;

	case TEXT_MODE_DASALONG:
		assert( dasa >= 0 && dasa < (int)DasaExpertFactory::MAX_DASAEXPERTS );
		DasaExpertFactory::get()->getDasaExpert( dasa )->writeMore( writer, horoscope, varga, show_header );
		break;

	case TEXT_MODE_JAIMINI:
	{
		VargaHoroscope chart( horoscope, varga );
		JaiminiExpert jexpert( &chart );
		jexpert.update();
		jexpert.write( writer, show_header );
	}
	break;

	case TEXT_MODE_MAIN_VIEW:
		ret = writePlanets();
		break;

	default:
		assert( false );
		break;
	}
	if ( ret ) printf( "Warn: %d objects couldn't be calculated\n", ret );
	return ret;
}