BOOL CForceGraphView::CreateGraph()
{
	if ( m_pController == NULL )
		return FALSE;

	CStrip* pStrip = m_pController->GetActiveStrip();

	if ( pStrip == NULL )
		return FALSE;

	CStandPass* pPass = m_pController->GetActivePass();

	if ( pPass == NULL && 
		 pStrip->GetMeasuredData() == NULL )
		 return TRUE;	
	 
	C2DGraphSubSet * pLGraphSubSet = AddNew2DGraphSubSet(eTop | eLeft);
	C2DGraphSubSet * pRGraphSubSet = AddNew2DGraphSubSet(eTop | eRight);
	C2DGraphSet * pGraphSet = GetGraphSet();
	
	double dYMax = 0;

	_2D_POINTS_CREATE_STRUCT pcs;
	pcs.bDeletePoints		= TRUE;
	pcs.bIncludeInLegend	= TRUE;
	pcs.crColor				= RGB(255, 0, 0);
	pcs.nMarkType			= MT_NOMARK;
	pcs.nPenWidth			= 25;
	pcs.pPointArray			= new CObArray();
	pcs.strTitle			= CStringEx(IDS_FORCE);

	if ( pPass != NULL )
	{
		for (int i = 0; i < pPass->GetForceCount(); i++)
		{
			pcs.pPointArray->Add(new C2DPoint(pPass->GetXPosition(i), pPass->GetForce(i) / 1e3));
		}

		pLGraphSubSet->AddPoints(pcs);

		pcs.pPointArray			= new CObArray();
		pcs.strTitle			= CStringEx(IDS_BENDING_FORCE);

		for (int i = 0; i < pPass->GetBendingForceCount(); i++)
		{
			pcs.pPointArray->Add(new C2DPoint(pPass->GetXPosition(i), pPass->GetBendingForce(i) / 1e3));
		}

		pRGraphSubSet->AddPoints(pcs);
	}

	CMeasuredData* pData = pStrip->GetMeasuredData();

	if ( pData != NULL )
	{
		CMeasuredDataMillPass* pMillPass = pStrip->GetMeasuredData()->GetMillPass(m_pController->GetActiveMillPassIndex());

		if ( pMillPass != NULL )
		{
			pcs.pPointArray	= new CObArray();
			pcs.strTitle	= CStringEx(IDS_FORCE);
			pcs.strTitle   += _T(" S1");
			pcs.crColor		= RGB(255, 0, 0);

			double dX = 0.;
			for ( auto point : pMillPass->GetAllPointsCL() )
			{
				CMeasuredDataMillPassPointCL* pPoint = point.second;
				
				if ( pPoint != NULL )
					pcs.pPointArray->Add( new C2DPoint(dX, pPoint->GetForceS1() / 1e3 ) );

				dX += ( 1.0 / ( pMillPass->GetPointCLCount() - 1 ) );
			}

			pLGraphSubSet->AddPoints( pcs );

			pcs.pPointArray	= new CObArray();
			pcs.strTitle	= CStringEx(IDS_FORCE);
			pcs.strTitle   += _T(" S2");
			pcs.crColor		= RGB(255, 0, 0);

			dX = 0.;
			for ( auto point : pMillPass->GetAllPointsCL() )
			{
				CMeasuredDataMillPassPointCL* pPoint = point.second;
				
				if ( pPoint != NULL )
					pcs.pPointArray->Add( new C2DPoint(dX, pPoint->GetForceS2() / 1e3 ) );

				dX += ( 1.0 / ( pMillPass->GetPointCLCount() - 1 ) );
			}

			pLGraphSubSet->AddPoints( pcs );

			pcs.pPointArray	= new CObArray();
			pcs.strTitle	= CStringEx(IDS_BENDING_FORCE);
			pcs.strTitle   += _T(" S1");
			pcs.crColor		= RGB(0, 0, 255);

			dX = 0.;
			for ( auto point : pMillPass->GetAllPointsCL() )
			{
				CMeasuredDataMillPassPointCL* pPoint = point.second;
				
				if ( pPoint != NULL )
					pcs.pPointArray->Add( new C2DPoint(dX, pPoint->GetBendingForceS1() / 1e3 ) );

				dX += ( 1.0 / ( pMillPass->GetPointCLCount() - 1 ) );
			}

			pLGraphSubSet->AddPoints( pcs );

			pcs.pPointArray	= new CObArray();
			pcs.strTitle	= CStringEx(IDS_BENDING_FORCE);
			pcs.strTitle   += _T(" S2");
			pcs.crColor		= RGB(0, 0, 255);

			dX = 0.;
			for ( auto point : pMillPass->GetAllPointsCL() )
			{
				CMeasuredDataMillPassPointCL* pPoint = point.second;
				
				if ( pPoint != NULL )
					pcs.pPointArray->Add( new C2DPoint(dX, pPoint->GetBendingForceS2() / 1e3 ) );

				dX += ( 1.0 / ( pMillPass->GetPointCLCount() - 1 ) );
			}

			pLGraphSubSet->AddPoints( pcs );

		}
	}
	
	CString strXDescription, strXUnits;
	strXDescription = CStringEx(IDS_LENGTH);

	pGraphSet->SetXAxisText(strXDescription);
	pGraphSet->SetXAxisMin((0.0));
	pGraphSet->SetXAxisMax((1.0));
	
	// Axis Y name	
	CString strYDescription;
	strYDescription = CStringEx(IDS_FORCE);
	strYDescription += _T(" |[");
	strYDescription += CStringEx(IDS_UNIT_KN);
	strYDescription += _T("]");
	
	pLGraphSubSet->SetAxisText(strYDescription);

	strYDescription = CStringEx(IDS_BENDING_FORCE);
	strYDescription += _T(" |[");
	strYDescription += CStringEx(IDS_UNIT_KN);
	strYDescription += _T("]");
	
	pRGraphSubSet->SetAxisText(strYDescription);
	
	// Nastaveni fontu
	LOGFONT *lplf;	
	lplf = pGraphSet->GetAxesFont();
	lplf->lfHeight = 8;
	#if defined(AFX_TARG_CSY) || defined(AFX_TARG_PLK)
		lplf->lfCharSet = EASTEUROPE_CHARSET;
	#endif
	#if defined(AFX_TARG_ENU)
		lplf->lfCharSet = DEFAULT_CHARSET;
	#endif
	pGraphSet->SetAxesFont( lplf );
	
	// Nastav typ grafu HorniLeve strane
	pGraphSet->SetTopLeftSubSet(pLGraphSubSet, TRUE );
	pGraphSet->SetTopRightSubSet(pRGraphSubSet, TRUE );
	
	// Povol kresleni mrizky
	pGraphSet->SetXAxisMainGridPenStyle( pGraphSet->XAxisAuxGridPenStyle() );
	pLGraphSubSet->SetMainGridPenStyle( pLGraphSubSet->GetAuxGridPenStyle() );
	pRGraphSubSet->SetMainGridPenStyle( pRGraphSubSet->GetAuxGridPenStyle() );
	pGraphSet->SetXAxisMainGrid( TRUE );
	pLGraphSubSet->SetMainGrid( TRUE );
	pRGraphSubSet->SetMainGrid( TRUE );

	 return TRUE;
 }