Example #1
0
void CGraphWnd::ClearGraph(int graphnum, BOOL bRedraw)
{
    CGraphProps* graph;
    if (graphnum != -1)
    {
        graph = GetGraph(graphnum);
        if (graph == NULL) return;
        graph->RemoveAll();
    } else
    {
        int index;
        graph = GetFirstGraph(&index);
        while (graph!=NULL)
        {
            graph->RemoveAll();
            graph = GetNextGraph(&index);
        };
    };
    if (graph_frame != NULL)
    {
        SGraphChange sgc;
        sgc.graphnum = graphnum;
        sgc.bRedraw = bRedraw;
        sgc.main_wnd_ptr = this;

        graph_frame->UpdateViews(GRAPH_GRAPH_CLEARED, &sgc);
    };
}
Example #2
0
BOOL CGraphWnd::GetBoundRect(double* minx, double* maxx, double* miny, double* maxy)
{
    int grcount = GetGraphCount();
    if (grcount == 0) return FALSE;
    int index;
    BOOL b = FALSE;
    CGraphProps* grprop = GetFirstGraph(&index);
    while(grprop!=NULL)
    {
        if (grprop->GetSize() == 0 || !grprop->IsVisible())
        {
            grprop = GetNextGraph(&index);
            continue;
        };
        if (!b)
        {   //first time
            *minx = grprop->min_x;
            *maxx = grprop->max_x;
            *miny = grprop->min_y;
            *maxy = grprop->max_y;
            b = TRUE;
        } else
        {
            if (grprop->min_x<*minx) *minx = grprop->min_x;
            if (grprop->max_x>*maxx) *maxx = grprop->max_x;
            if (grprop->min_y<*miny) *miny = grprop->min_y;
            if (grprop->max_y>*maxy) *maxy = grprop->max_y;
        };
        grprop = GetNextGraph(&index);
    };
    return b;
}
Example #3
0
int CGraphWnd::AddPoint(int graphnum, double x, double y, BOOL bRedraw, int index/* = -1*/)
{
    int ind, res;
    CGraphProps* graph = GetGraph(graphnum);
    if (graph == NULL) return -1;
    if (index == -1)
    {
        ind = graph->AddPoint(x, y, TRUE, &res);
    } else
    {
        ind = graph->InsertPoint(index, x, y, TRUE);
    };

    if (graph_frame != NULL)
    {
        SGraphChange sgc;
        sgc.graphnum = graphnum;
        sgc.index = ind;
        sgc.bRedraw = bRedraw;
        sgc.main_wnd_ptr = this;

        graph_frame->UpdateViews(GRAPH_POINT_ADDED, &sgc);
    };
    return index;
}
Example #4
0
void CGraphicsPropertyPage::OnGraphHideshow() 
{
    int index = m_graph_combo.GetCurSel();
    if (index == -1) return;
    CGraphProps* grprop = grprops.GetAt(index);
    grprop->SetVisible(!grprop->IsVisible());
    SetHideShowAttr(index);
}
Example #5
0
void CGraphicsPropertyPage::SetActiveSel(int selnum)
{
    if (selnum<0 || selnum>=grprops.GetSize()) return;
    m_graph_combo.SetCurSel(selnum);
    SetHideShowAttr(selnum);
    CGraphProps* grprop = grprops.GetAt(selnum);
    m_graph_title = grprop->GetTitle();
    UpdateData(FALSE);
}
Example #6
0
void CGraphicsPropertyPage::OnGraphsShowall() 
{
    int index = m_graph_combo.GetCurSel();
    if (index == -1) return;
    CGraphProps* grprop;
    for (int i=0; i<grprops.GetSize(); i++)
    {
	grprop = grprops.GetAt(i);
	grprop->SetVisible(TRUE);
    };
    SetHideShowAttr(index);
}
Example #7
0
void CGraphicsPropertyPage::OnGraphChColor() 
{
    int index = m_graph_combo.GetCurSel();
    if (index == -1) return;
    CGraphProps* grprop = grprops.GetAt(index);
    CColorDialog dlg(grprop->GetGraphColor());
    if (dlg.DoModal() == IDOK)
    {
	grprop->SetGraphColor(dlg.GetColor());
	m_graph_combo.RedrawWindow();
    };
}
Example #8
0
void CGraphicsPropertyPage::SetHideShowAttr(int selnum)
{
    if (selnum == -1) return;
    CGraphProps* grprop = grprops.GetAt(selnum);
    CWnd* wnd = GetDlgItem(IDC_GRAPH_HIDESHOW);
    if (wnd == NULL) return;
    if (grprop->IsVisible()) 
    {
	wnd->SetWindowText(_T("Hide"));
    } else
    {
	wnd->SetWindowText(_T("Show"));
    };
}
Example #9
0
void CGraphicsPropertyPage::OnGraphChTitle() 
{
    int index = m_graph_combo.GetCurSel();
    if (index == -1) return;
    CGraphProps* grprop = grprops.GetAt(index);
    CGraphTitlePrompt dlg;
    dlg.m_title = grprop->GetTitle();
    if (dlg.DoModal() == IDOK)
    {
	grprop->SetTitle(dlg.m_title);
	m_graph_combo.RedrawWindow();
	m_graph_title = grprop->GetTitle();
	UpdateData(FALSE);
    };
}
Example #10
0
int CGraphWnd::RemovePoint(int graphnum, int index, BOOL bRedraw)
{
    CGraphProps* graph = GetGraph(graphnum);
    if (graph == NULL) return -1;
    graph->RemovePoint(index, TRUE);

    if (graph_frame != NULL)
    {
        SGraphChange sgc;
        sgc.graphnum = graphnum;
        sgc.index = index;
        sgc.bRedraw = bRedraw;
        sgc.main_wnd_ptr = this;

        graph_frame->UpdateViews(GRAPH_POINT_REMOVED, &sgc);
    };
    return index;
}
Example #11
0
int CGraphWnd::EditPoint(int graphnum, int index, double x, double y, BOOL bRedraw)
{
    CGraphProps* graph = GetGraph(graphnum);
    if (graph == NULL) return -1;
    int res = graph->EditPoint(index, x, y, TRUE);

    if (graph_frame != NULL)
    {
        SGraphChange sgc;
        sgc.graphnum = graphnum;
        sgc.index = index;
        sgc.bRedraw = bRedraw;
        sgc.main_wnd_ptr = this;

        graph_frame->UpdateViews(GRAPH_POINT_CHANGED, &sgc);
    };
    return res;
}
Example #12
0
void CGraphWnd::ReleasePropertyPage(UINT dialog_status)
{
    if (dialog_status == IDOK)
    {
        SetAxisProps(axis_prop_page->m_x_title, axis_prop_page->m_x_uom,
                     axis_prop_page->m_x_precision, GRAPH_X_AXIS, FALSE);
        SetAxisProps(axis_prop_page->m_y_title, axis_prop_page->m_y_uom,
                     axis_prop_page->m_y_precision, GRAPH_Y_AXIS, FALSE);

        for (int i=0; i<graph_prop_page->grprops.GetSize(); i++)
        {
            CGraphProps* grprop = graph_prop_page->grprops.GetAt(i);
            int index = grprop->GetIndex();
            CGraphProps* grp = GetGraph(index);
            grp->SetGraphProps(grprop);
        };
    };

    delete axis_prop_page;
    delete graph_prop_page;
}
Example #13
0
CGraphicsPropertyPage::CGraphicsPropertyPage(CGraphWnd* main_wnd) : CPropertyPage(CGraphicsPropertyPage::IDD)
{
	//{{AFX_DATA_INIT(CGraphicsPropertyPage)
	m_graph_title = _T("");
	//}}AFX_DATA_INIT

    //fill array of graph properties
    if (main_wnd != NULL && main_wnd->GetGraphCount() != 0)
    {
	//fill new array with data
	int index;
	CGraphProps* grp;
	CGraphProps* grprop = main_wnd->GetFirstGraph(&index);
	while (grprop!=NULL)
	{
	    grp = new CGraphProps(grprop, FALSE);
	    grp->SetIndex(index);
	    grprops.Add(grp);
	    grprop = main_wnd->GetNextGraph(&index);
	};
    };
}
Example #14
0
void CGraphPanel::AddPoint(SGraphChange* sgc)
{
    //get main view pointer
    if (sgc->main_wnd_ptr == NULL) return;
    SSinglePoint ssp;
    CGraphProps* sgp = sgc->main_wnd_ptr->GetGraph(sgc->graphnum);
    if (!sgp->IsVisible())
    {
	//if graph is not visible - do not do anything here
	return;
    };
    sgp->GetPoint(sgc->index, &ssp);
    BOOL bNeedRedraw = FALSE;
    if ((unsigned long)(m_grflags & GRAPH_AUTOSCALE))
    {
	//if grafix is autoscaled - just recalc coordinates and redraw the window
	if (ssp.x<__min(GetX1(), GetX2())) 
	{
	    SetMinX(ssp.x, FALSE);
	    bNeedRedraw = TRUE;
	};
	if (ssp.x>__max(GetX1(), GetX2())) 
	{
	    SetMaxX(ssp.x, FALSE);
	    bNeedRedraw = TRUE;
	};
	if (ssp.y<__min(GetY1(), GetY2())) 
	{
	    SetMinY(ssp.y, FALSE);
	    bNeedRedraw = TRUE;
	};
	if (ssp.y>__max(GetY1(), GetY2())) 
	{
	    SetMaxY(ssp.y, FALSE);
	    bNeedRedraw = TRUE;
	};
    };
    //draw new point 
    if (bNeedRedraw) 
    {
	if (sgc->bRedraw)
	{
	    UpdateGraphWindow(NULL);
	};
	return;
    };

    if (!sgc->bRedraw || offscreen == NULL) return;

    //if point is inside the graph - we need invalidate the whole picture
    if (sgc->index!=0 && sgc->index!=sgp->GetSize()-1)
    {
	if (sgc->bRedraw)
	{
	    UpdateGraphWindow(NULL);
	};
	return;
    };

    int x, y, x1, y1;
    x = (int)CurrentCoordsX->WtoX(ssp.x);
    y = (int)CurrentCoordsY->WtoX(ssp.y);

    CDC* dc = offscreen->GetDibCDC();
    if (dc != NULL)
    {
	CDC* cdc = GetDC();

	CPen* pen = sgp->GetPen();
	CBrush* brush = sgp->GetBrush();

	CPen* oldpen = (CPen*)dc->SelectObject(pen);
	CBrush* oldbrush = (CBrush*)dc->SelectObject(brush);

	if (sgp->GetSize()>1)
	{
	    if (sgc->index == 0) sgp->GetPoint(1, &ssp);
	    if (sgc->index == sgp->GetSize()-1) sgp->GetPoint(sgc->index-1, &ssp);
	    x1 = (int)CurrentCoordsX->WtoX(ssp.x);
	    y1 = (int)CurrentCoordsY->WtoX(ssp.y);
	    if (x != x1 || y != y1)
	    {
		if ((m_grflags & GRAPH_GRAPH_SCATTER) == 0)
		{
		    dc->MoveTo(x, y);
		    dc->LineTo(x1, y1);
		};

		if ((m_grflags & GRAPH_SQUAREPOINTS) != 0) 
		{
		    DrawSquarePoint(dc, x, y);
		};

		CRect update_rect(x, y, x1, y1);
		update_rect.NormalizeRect();
		update_rect.InflateRect(GetSquareSide(dc) + 2, GetSquareSide(dc) + 2);
		DoRedraw(cdc, update_rect);
	    };
	} else
	{
	    if ((m_grflags & GRAPH_SQUAREPOINTS) != 0) 
	    {
		DrawSquarePoint(dc, x, y);

		CRect update_rect(x, y, x, y);
		update_rect.NormalizeRect();
		update_rect.InflateRect(GetSquareSide(dc) + 2, GetSquareSide(dc) + 2);
		DoRedraw(cdc, update_rect);
	    };
	};

	dc->SelectObject(oldpen);
	dc->SelectObject(oldbrush);

	sgp->ReleasePen(pen);
	sgp->ReleaseBrush(brush);

	ReleaseDC(cdc);
    };
}
Example #15
0
void CGraphPanel::DrawPoints(CDC* dc, CRect& rect_to_draw)
{
    //draw all the points
    SSinglePoint ssp, ssp1;
    int x, y, x1, y1, grnum;
    if (CurrentCoordsX == NULL || CurrentCoordsY == NULL) return;
    CGraphWnd* main_wnd = get_main_graph_window();
    if (main_wnd == NULL) return;

    //save current state of device context
    int saved_dc = dc->SaveDC();

    //set new clipping region
    dc->IntersectClipRect(rect_to_draw);

    //create new set of CCoordinates
    CCoordinates coords_x(rect_to_draw.left, rect_to_draw.right, CurrentCoordsX->v1(), CurrentCoordsX->v2());
    CCoordinates coords_y(rect_to_draw.bottom, rect_to_draw.top, CurrentCoordsY->v1(), CurrentCoordsY->v2());

    CGraphProps* grprop = main_wnd->GetFirstGraph(&grnum);
    while (grprop!=NULL)
    {
	if (grprop->GetSize() ==0 || !grprop->IsVisible()) 
	{
		grprop = main_wnd->GetNextGraph(&grnum);
		continue;
	};
	//set color
	CPen* pen = grprop->GetPen();
	CBrush* brush = grprop->GetBrush();
	CPen* oldpen = (CPen*)dc->SelectObject(pen);
	CBrush* oldbrush = (CBrush*)dc->SelectObject(brush);

	grprop->GetPoint(0, &ssp);
	x = (int)coords_x.WtoX(ssp.x);
	y = (int)coords_y.WtoX(ssp.y);
	if ((long)(m_grflags & GRAPH_SQUAREPOINTS)!=0) DrawSquarePoint(dc, x, y);
	for (int i=1; i<grprop->GetSize(); i++)
	{
	    grprop->GetPoint(i, &ssp);
	    x1 = (int)coords_x.WtoX(ssp.x);
	    y1 = (int)coords_y.WtoX(ssp.y);
	    if (x != x1 || y != y1)
	    {
		if ((m_grflags & GRAPH_SQUAREPOINTS)!=0) DrawSquarePoint(dc, x1, y1);
		if ((m_grflags & GRAPH_GRAPH_SCATTER) == 0)
		{
		    dc->MoveTo(x, y);
		    dc->LineTo(x1, y1);
		};
		x = x1; y = y1;
	    };
	};
	dc->SelectObject(oldpen);
	dc->SelectObject(oldbrush);
	grprop->ReleasePen(pen);
	grprop->ReleaseBrush(brush);

	grprop = main_wnd->GetNextGraph(&grnum);
    };
    dc->RestoreDC(saved_dc);
}