//////////////////////////////////////
// START of File: CO1_PLIN.CPP
//////////////////////////////////////


//===================================================================
//
// COPYRIGHT NOTICE:  This code is protected by Copyright!
//
// Copyright (c) 1994, 1995, 1996, 1997 by DPC Technology.
// All rights reserved. 
//
// See files "cf_copyr.h" and "cf_licen.h" for details of 
// copyright and license specifications, and contact information.
//
//===================================================================

//
// Include this source file's header file:
//
#include	<cf_api/bf_defs.h>
#include    <cf_api/co1_plin.hpp> 
            // relative to the IDE's (global) include path: ~/cfrz

//
// Implement the Chart Framework "Poly Line" class.  
// All functions not implemented here are implemented in the *.hpp file.
//
cf_3DPolyLine
    ::cf_3DPolyLine()
        : cf_3DPointSeries()    // Default c-tor 
            {}

// Std c-tor lets user assign display attribs
cf_3DPolyLine
    ::cf_3DPolyLine( cf_DispAttribs *p_attrToDrawWith )
        : cf_3DPointSeries( p_attrToDrawWith )  // Param-ed c-tor 
            {}


cf_3DPolyLine
    ::~cf_3DPolyLine() 
        {}

//
// DRAW this cf_3DPolyLine on a bf_Display.  
//
void
    cf_3DPolyLine
        ::draw2D( bf_Display *p_bf_dspOutputDisplay ) 
{
    int     i;  // Std ICV.

    // Construct the polyline to be drawn:
    cf_2DPoint *a_cf_2dpDrawArray = new cf_2DPoint[ this->iNumPoints ];
    for ( i = 0; i < this->iNumPoints; i++ )
        a_cf_2dpDrawArray[i] = ( (cf_3DPoint*) 
                                da_p_cf_3dpVertices[i + 1] )->screenPoint();
       
    //
    // Set up the display attributes to draw the body of 
    // the polyLine -- Note that we render the LINE of 
    // the PolyLine with the BRUSH color (if set), NOT the 
    // Pen color (we use pen colors to draw any markers)!
    //
    bf_Color   bf_clrOrigPen      = CF_BLACK;
    bf_Color   bf_clrCurrBrush    = CF_BLACK;
    BOOL        bPenColorReset      = FALSE;
    int         iOrigPenWidth       = 1;
                // Harmless defaults...

    if ( bWereDispAttribsSet_ == TRUE )
    {
        bf_clrOrigPen = p_cf_datbForDrawOps_->colorPen();
        bf_clrCurrBrush = p_cf_datbForDrawOps_->colorBrush();
        p_cf_datbForDrawOps_->colorPen( bf_clrCurrBrush );
        bPenColorReset = TRUE;
    }   // Pen Color is now BRUSH Color! Orig pen color saved.

    // Now ready to render the Poly-Line:
    this->dispPushPenAttribs( p_bf_dspOutputDisplay );
    p_bf_dspOutputDisplay
            ->dsp_polyline( a_cf_2dpDrawArray, this->iNumPoints );
    this->dispPopPenAttribs( p_bf_dspOutputDisplay );

    // Reset the colors that we monkeyed around with!
    if ( bPenColorReset == TRUE )
        p_cf_datbForDrawOps_->colorPen( bf_clrOrigPen );

    //
    // If called for, draw the individual data points/markers 
    // (using a pen width of one AND the original pen color).
    //
    if ( bWereDispAttribsSet_ == TRUE )
    {
        if ( p_cf_datbForDrawOps_->markWhen2D() == TRUE )
        {
            // Set a pen width of ONE!
            iOrigPenWidth = p_cf_datbForDrawOps_->stylePenWidth();
            p_cf_datbForDrawOps_->stylePenWidth( 1 );
                
            this->dispPushBrushAttribs( p_bf_dspOutputDisplay );
            this->dispPushPenAttribs( p_bf_dspOutputDisplay );
            for ( i = 1; i <= this->iNumPoints; i++ ) 
                ( (cf_3DPoint*) da_p_cf_3dpVertices[ i ] )
                                    ->draw2D( p_bf_dspOutputDisplay );
                // Which all should be set to IGNORE their own attribs:
            this->dispPopPenAttribs( p_bf_dspOutputDisplay );
            this->dispPopBrushAttribs( p_bf_dspOutputDisplay );
            
            // Restore what we monkeyed around with!
            p_cf_datbForDrawOps_->stylePenWidth( iOrigPenWidth );
            
        }   // 2D Markers now drawn.
    }
    
    // Clean up:
    delete [] a_cf_2dpDrawArray;
            //was: delete [ this->iNumPoints ] a_cf_2dpDrawArray;

    return;

}   // end of cf_3DPolyLine::draw2D(...)


    
void
    cf_3DPolyLine
        ::draw3D( bf_Display *p_bf_dspOutputDisplay )
{
    int     i;  // Std ICV.

    // Construct the polyline to be drawn:
    cf_2DPoint *a_cf_2dpDrawArray = new cf_2DPoint[ this->iNumPoints ];
    for ( i = 0; i < this->iNumPoints; i++ )
        a_cf_2dpDrawArray[ i ] 
            = ((cf_3DPoint*) da_p_cf_3dpVertices[i + 1] )->screenPoint();
       
    //
    // Set up the display attributes to draw the body of 
    // the polyLine -- Note that we render the LINE of 
    // the PolyLine with the BRUSH color (if set), NOT the 
    // Pen color (we use pen colors to draw any markers)!
    //
    bf_Color   bf_clrOrigPen      = CF_BLACK;
    bf_Color   bf_clrCurrBrush    = CF_BLACK;
    BOOL        bPenColorReset      = FALSE;
    int         iOrigPenWidth       = 1;
                // Harmless defaults...

    if ( bWereDispAttribsSet_ == TRUE )
    {
        bf_clrOrigPen = p_cf_datbForDrawOps_->colorPen();
        bf_clrCurrBrush = p_cf_datbForDrawOps_->colorBrush();
        p_cf_datbForDrawOps_->colorPen( bf_clrCurrBrush );
        bPenColorReset = TRUE;
    }   // Pen Color is now BRUSH Color! Orig pen color saved.

    // Now ready to render the Poly-Line:
    this->dispPushPenAttribs( p_bf_dspOutputDisplay );
    p_bf_dspOutputDisplay
            ->dsp_polyline( a_cf_2dpDrawArray, this->iNumPoints );
    this->dispPopPenAttribs( p_bf_dspOutputDisplay );

    // Reset the colors that we monkeyed around with!
    if ( bPenColorReset == TRUE )
        p_cf_datbForDrawOps_->colorPen( bf_clrOrigPen );

    //
    // If called for, draw the individual data points/markers 
    // (using a pen width of one AND the original pen color).
    //
    if ( bWereDispAttribsSet_ == TRUE )
    {
        if ( p_cf_datbForDrawOps_->markWhen3D() == TRUE )
        {
            // Set a pen width of ONE!
            iOrigPenWidth = p_cf_datbForDrawOps_->stylePenWidth();
            p_cf_datbForDrawOps_->stylePenWidth( 1 );
                
            this->dispPushBrushAttribs( p_bf_dspOutputDisplay );
            this->dispPushPenAttribs( p_bf_dspOutputDisplay );
            for ( i = 1; i <= this->iNumPoints; i++ ) 
                ((cf_3DPoint*) this->da_p_cf_3dpVertices[ i ] )
                                    ->draw3D( p_bf_dspOutputDisplay );
                // Which all should be set to IGNORE their own attribs:
            this->dispPopPenAttribs( p_bf_dspOutputDisplay );
            this->dispPopBrushAttribs( p_bf_dspOutputDisplay );
            
            // Restore what we monkeyed around with!
            p_cf_datbForDrawOps_->stylePenWidth( iOrigPenWidth );
            
        }   // 3D Markers now drawn.
    }
    
    // Clean up:
    delete [] a_cf_2dpDrawArray;
            //was: delete [ this->iNumPoints ] a_cf_2dpDrawArray;

    return;

}   // end of cf_3DPolyLine::draw3D(...)

    
//
// End of cf_3DPolyLine Implementation.
// 

//////////////////////////////////////
// END of File: CO1_PLIN.CPP
//////////////////////////////////////

