//////////////////////////////////////
// START of File: CO1_VOBJ.CPP
//////////////////////////////////////

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

#include	<cf_api/bf_defs.h>
#include    <cf_api/c1_vobj.hpp>

//------------------------------------------------------------
// Implement the Chart FrameWork virtual "Object" base class.
//------------------------------------------------------------
cf_Virt3DObj::cf_Virt3DObj()
{
    p_cf_datbForDrawOps_    = NULL;
    bWereDispAttribsSet_    = FALSE;
    bWereDispAttribsNewed_  = FALSE;

    p_cf_tatbForTextOps_    = NULL;
    bWereTextAttribsSet_    = FALSE;
    bWereTextAttribsNewed_  = FALSE;

    bIgnorePushBrush_   = FALSE;
    bIgnorePushFont_    = FALSE;
    bIgnorePushPen_     = FALSE;

    bDispUsingFacetSort_    = FALSE;
    bDispUsingZDepthSort_   = FALSE;
    bDispUsingHSE_          = FALSE;

    bDispWireFrame_            = FALSE;
    bAppliedKernelDispMetrics_ = FALSE;

    bDispVisible_       = TRUE;
}


cf_Virt3DObj
    ::cf_Virt3DObj( cf_DispAttribs *p_attrToDrawWith )
{
    p_cf_datbForDrawOps_    = p_attrToDrawWith;
    bWereDispAttribsSet_    = TRUE;
    bWereDispAttribsNewed_  =    FALSE;

    p_cf_tatbForTextOps_    = NULL;
    bWereTextAttribsSet_    = FALSE;
    bWereTextAttribsNewed_  = FALSE;

    bIgnorePushBrush_   = FALSE;
    bIgnorePushFont_    = FALSE;
    bIgnorePushPen_     = FALSE;

    bDispUsingFacetSort_    = FALSE;
    bDispUsingZDepthSort_   = FALSE;
    bDispUsingHSE_          = FALSE;

    bDispWireFrame_            = FALSE;
    bAppliedKernelDispMetrics_ = FALSE;

    bDispVisible_       = TRUE;
}



cf_Virt3DObj
    ::~cf_Virt3DObj()
{
    if ( bWereDispAttribsSet_ == TRUE )
        if ( bWereDispAttribsNewed_ == TRUE )
                delete p_cf_datbForDrawOps_;

    if ( bWereTextAttribsSet_ == TRUE )
        if ( bWereTextAttribsNewed_ == TRUE )
                delete p_cf_tatbForTextOps_;
}


cf_Virt3DObj&
    cf_Virt3DObj
        ::operator=( const cf_Virt3DObj &cr_cf_vobjSource )
{
    //----------------------------------------------------
    // Copy this virtual object's DISPLAY Attribute State:
    //----------------------------------------------------
    if ( cr_cf_vobjSource.bWereDispAttribsSet_ == TRUE )
    // I.e. -- does the target even HAVE display attributes set?
    {
        // If the target new()ed its OWN "display attrib" object,
        // (i.e. it's NOT using someone else's display attribute)...
        if ( cr_cf_vobjSource.bWereDispAttribsNewed_ == TRUE )
        {
            // Make ourselves ready to do a CONTENT copy
            if ( bWereDispAttribsNewed_ == FALSE )
            {   // we need to allocate our OWN new disp-attribs!
                p_cf_datbForDrawOps_ = new cf_DispAttribs();
                bWereDispAttribsNewed_ = TRUE;
                // Keep track of what we just did (for the d-tor!);
            }
            // ...now we're ready to do a CONTENT copy:
            *(p_cf_datbForDrawOps_) = *(cr_cf_vobjSource.p_cf_datbForDrawOps_);
            bWereDispAttribsSet_ = TRUE;
        }
        else
        // The target did NOT new() its own display attribs -- it's
        // just pointing to someone else's -- let's point there, too!
        {
            p_cf_datbForDrawOps_ = cr_cf_vobjSource.p_cf_datbForDrawOps_;
            bWereDispAttribsNewed_ = FALSE;
            bWereDispAttribsSet_ = TRUE;
            // Keep track of what we just did (for the d-tor!);
        }
    }
    else
    // The source object's display attribs were NEVER SET!
    {
        p_cf_datbForDrawOps_ = NULL;
        bWereDispAttribsSet_ = FALSE;
        bWereDispAttribsNewed_ = FALSE;
        // We assume the default c-tor init state...
    }

    //----------------------------------------------------
    // Copy this virtual object's Text Attribute State:
    //----------------------------------------------------
    if ( cr_cf_vobjSource.bWereTextAttribsSet_ == TRUE )
    // I.e. -- does the target even HAVE text attributes set?
    {
        // If the target new()ed its OWN "text attrib" object,
        // (i.e. it's NOT using someone else's text attribute)...
        if ( cr_cf_vobjSource.bWereTextAttribsNewed_ == TRUE )
        {
            // Make ourselves ready to do a CONTENT copy
            if ( bWereTextAttribsNewed_ == FALSE )
            {   // we need to allocate our OWN new disp-attribs!
                p_cf_tatbForTextOps_ = new cf_TextAttribs();
                bWereTextAttribsNewed_ = TRUE;
                // Keep track of what we just did (for the d-tor!);
            }
            // ...now we're ready to do a CONTENT copy:
            *(p_cf_tatbForTextOps_) = *(cr_cf_vobjSource.p_cf_tatbForTextOps_);
            bWereTextAttribsSet_ = TRUE;
        }
        else
        // The target did NOT new() its own text attribs -- it's
        // just pointing to someone else's -- let's point there, too!
        {
            p_cf_tatbForTextOps_ = cr_cf_vobjSource.p_cf_tatbForTextOps_;
            bWereTextAttribsNewed_ = FALSE;
            bWereTextAttribsSet_ = TRUE;
            // Keep track of what we just did (for the d-tor!);
        }
    }
    else
    // The source object's text attribs were NEVER SET!
    {
        p_cf_tatbForTextOps_ = NULL;
        bWereTextAttribsSet_ = FALSE;
        bWereTextAttribsNewed_ = FALSE;
        // We assume the default c-tor init state...
    }

    //-----------------------------------------
    // Finish by copying miscelenaous attribs:
    //-----------------------------------------
    bIgnorePushBrush_ = cr_cf_vobjSource.bIgnorePushBrush_;
    bIgnorePushFont_ = cr_cf_vobjSource.bIgnorePushFont_;
    bIgnorePushPen_ = cr_cf_vobjSource.bIgnorePushPen_;

    bDispUsingFacetSort_   = cr_cf_vobjSource.bDispUsingFacetSort_;
    bDispUsingZDepthSort_   = cr_cf_vobjSource.bDispUsingZDepthSort_;
    bDispUsingHSE_     = cr_cf_vobjSource.bDispUsingHSE_;

    bDispWireFrame_    = cr_cf_vobjSource.bDispWireFrame_;

    bAppliedKernelDispMetrics_ = cr_cf_vobjSource.bAppliedKernelDispMetrics_;

    bDispVisible_       = cr_cf_vobjSource.bDispVisible_;

    return( *this );

}   // end of cf_Virt3DObj::operator=( const cf_Virt3DObj& )



//---------------------------------------------------------
// Implement the Virtual-Object's Text-Attributes Methods:
//---------------------------------------------------------
cf_TextAttribs*
cf_Virt3DObj::attribTextCurrent()
{
    if ( bWereTextAttribsSet_ == FALSE ) attribTextNew();
        // which yields the valid pointer return value below:

    return( p_cf_tatbForTextOps_ );
}


cf_TextAttribs*
cf_Virt3DObj::attribTextNew()
{
    // If we made an earlier allocation, get rid of it!
    if ( bWereTextAttribsNewed_ == TRUE ) delete p_cf_tatbForTextOps_;

    // Now -- we make a new set of text-attribs:
    p_cf_tatbForTextOps_ = new cf_TextAttribs();
    bWereTextAttribsNewed_ = TRUE;
    bWereTextAttribsSet_ = TRUE;
        // ...and keep track of what we just did (for the d-tor!);

    return( p_cf_tatbForTextOps_ );
}


void
cf_Virt3DObj::attribTextUsing( cf_TextAttribs *p_cf_tatbSource )
{
    // TRY to screen out bogosities!
    if ( p_cf_tatbSource != NULL )
    {
        // If we made an earlier allocation, get rid of it!
        if ( bWereTextAttribsNewed_ == TRUE ) delete p_cf_tatbForTextOps_;

        // Now -- all we can do is point to the new target!
        p_cf_tatbForTextOps_ = p_cf_tatbSource;
        bWereTextAttribsNewed_ = FALSE;
        bWereTextAttribsSet_ = TRUE;
            // Keep track of what we just did (for the d-tor!);
    }
    else    // Don't set to a BOGUS pointer value!  Just IGNORE it!
    {
        p_cf_tatbForTextOps_ = NULL;
        bWereTextAttribsSet_ = FALSE;
        bWereTextAttribsNewed_ = FALSE;
    }   // We'll assume the (hopefully harmless) default c-tor init state...
}


BOOL
cf_Virt3DObj::attribTextValid()
{
    return( bWereTextAttribsSet_ );
}



void
    cf_Virt3DObj
        ::applyDispMetrics( cf_Kernel  * /*p_cf_kUseThisKernel*/ )
//-------------------------------------------------------------------------
// Called by the parent chart-engine configuration in response to display
// context changes (e.g. re-size events) imposed by the chart-engine's
// parent chart-model/chart-view.
//-------------------------------------------------------------------------
{
    // Make a note to anyone who wants to know later on...
    bAppliedKernelDispMetrics_ = TRUE;
            //... we've run this routine at least once!...
}

void
    cf_Virt3DObj
        ::applyGeomXform( cf_Kernel  * /*p_cf_kUseThisKernel*/ )
{
}

void
    cf_Virt3DObj
        ::applyProjXform( cf_Kernel *p_cf_kUseThisKernel )
{
    // If we haven't yet done a synchronization to the
    // kernel's latest display metrics, let's *force* one!
    if ( bAppliedKernelDispMetrics_ == FALSE )
            this->applyDispMetrics( p_cf_kUseThisKernel );
}

void
    cf_Virt3DObj
        ::applyScaleOp( double /*dXScaleFactor*/,
                        double /*dYScaleFactor*/,
                        double /*dZScaleFactor*/ )
{
}

void
    cf_Virt3DObj
        ::applyTranslateOp( double /*dXTrans*/,
                            double /*dYTrans*/,
                            double /*dZTrans*/ )
{
}



//
// Get whatever we're pointing at. Note that it's wise
// to preceed this with a call to this->dispAttribsValid().
//
cf_DispAttribs*
    cf_Virt3DObj
        ::dispAttribsCurrent()
{
    if ( bWereDispAttribsSet_ == FALSE )
            this->dispAttribsNewSet();
            // which yields the valid pointer return value below:
    return p_cf_datbForDrawOps_;
}

//
// Create a New set of "Display Attribs" to
// be the target for this object's "Display
// Attribs" pointer! Any current new()ed
// allocation will be deleted.  D-tor will
// be notified to delete these current
// new()-ed "Disp Attribs" object.
//
cf_DispAttribs*
    cf_Virt3DObj
        ::dispAttribsNewSet()
{
    // If we made an earlier allocation, get rid of it!
    if ( bWereDispAttribsNewed_ == TRUE )
        if ( p_cf_datbForDrawOps_ != NULL )
                delete p_cf_datbForDrawOps_;

    // Now -- we make a new set of display attribs:
    p_cf_datbForDrawOps_ = new cf_DispAttribs();
    bWereDispAttribsNewed_ = TRUE;
    bWereDispAttribsSet_ = TRUE;
        // Keep track of what we just did (for the d-tor!);

    return p_cf_datbForDrawOps_;
}


//
// Set this object's display attribute pointer!
//
void
    cf_Virt3DObj
        ::dispAttribsPointTo( cf_DispAttribs *p_cf_datbTarget )
{
    // TRY to screen out bogosities!
    if ( p_cf_datbTarget != NULL )
    {
        // If we made an earlier allocation, get rid of it!
        if ( bWereDispAttribsNewed_ == TRUE )
            if ( p_cf_datbForDrawOps_ != NULL )
                    delete p_cf_datbForDrawOps_;

        // Now -- all we can do is point to the new target!
        p_cf_datbForDrawOps_ = p_cf_datbTarget;
        bWereDispAttribsNewed_ = FALSE;
        bWereDispAttribsSet_ = TRUE;
            // Keep track of what we just did (for the d-tor!);
    }
    else
    // Don't set to a BOGUS pointer value!  Just IGNORE it!
    {
        p_cf_datbForDrawOps_ = NULL;
        bWereDispAttribsSet_ = FALSE;
        bWereDispAttribsNewed_ = FALSE;
        // We'll assume the (hopefully harmless)
        // default c-tor init state...
    }

    return;

}   // end of cf_Virt3DObj::dispAttribsSetTo( cf_DispAttribs * )


BOOL
    cf_Virt3DObj
        ::dispAttribsValid()
            { return bWereDispAttribsSet_; }


BOOL
    cf_Virt3DObj
        ::dispIgnorePushBrush()
            { return bIgnorePushBrush_; }
void
    cf_Virt3DObj
        ::dispIgnorePushBrush( BOOL bNewState )
            { bIgnorePushBrush_ = bNewState; }

BOOL
    cf_Virt3DObj
        ::dispIgnorePushFont()
            { return bIgnorePushFont_; }
void
    cf_Virt3DObj
        ::dispIgnorePushFont( BOOL bNewState )
            { bIgnorePushFont_ = bNewState; }

BOOL    
    cf_Virt3DObj
        ::dispIgnorePushPen()
            { return bIgnorePushPen_; }
void    
    cf_Virt3DObj
        ::dispIgnorePushPen( BOOL bNewState )
            { bIgnorePushPen_ = bNewState; }


void
    cf_Virt3DObj
        ::dispPushBrushAttribs( bf_Display *p_bf_dspActive ) 
{
    if ( bDispWireFrame_ == FALSE )
    {
        if ( bIgnorePushBrush_ == FALSE )
        {
            if ( bWereDispAttribsSet_ == TRUE )
                p_bf_dspActive->dsp_pushBrush
                (
                    new bf_Brush( p_cf_datbForDrawOps_
                                                ->colorBrush() ) 
                );
            else
                p_bf_dspActive->dsp_pushBrush
                ( 
                    new bf_Brush( CF_WHITE ) 
                );
        }
    }
    return;
}
        

void
    cf_Virt3DObj
        ::dispPushPenAttribs( bf_Display *p_bf_dspActive ) 
{
    if ( bDispWireFrame_ == FALSE )
    {
        if ( bIgnorePushPen_ == FALSE )
        {
            if ( bWereDispAttribsSet_ == TRUE )
            {
                p_bf_dspActive->dsp_pushPen
                ( 
                  new bf_Pen( p_cf_datbForDrawOps_->colorPen(), 
                              p_cf_datbForDrawOps_->stylePen(), 
                              p_cf_datbForDrawOps_->stylePenWidth() )
                );
                 
            }
            else
                p_bf_dspActive->dsp_pushPen
                ( 
                    new bf_Pen(    CF_BLACK,       // color
                                    CF_PS_SOLID,    // style
                                    1 )             // width 
                );
        }
    }
    return;
}


void
    cf_Virt3DObj
        ::dispPopBrushAttribs( bf_Display *p_bf_dspTarget ) 
{
    if ( bDispWireFrame_ == FALSE )
        if ( bIgnorePushBrush_ == FALSE )
                delete p_bf_dspTarget->dsp_popBrush(); 
                // I.e. ONLY pop & delete IF we newed & pushed!
}


void
    cf_Virt3DObj
        ::dispPopPenAttribs( bf_Display *p_bf_dspTarget ) 
{ 
    if ( bDispWireFrame_ == FALSE )
        if ( bIgnorePushPen_ == FALSE )
                delete p_bf_dspTarget->dsp_popPen(); 
                // I.e. ONLY pop & delete IF we newed & pushed!
}


// Get/set Facet-Based Depth-Sorting calcs ON/OFF.
BOOL
    cf_Virt3DObj
        ::dispUsingFacetSort()
            { return bDispUsingFacetSort_; }
void
    cf_Virt3DObj
        ::dispUsingFacetSort( BOOL bNewState )
            { bDispUsingFacetSort_ = bNewState; }


// Get/set Geometry-Based Depth-Sorting calcs ON/OFF.
BOOL
    cf_Virt3DObj
        ::dispUsingZDepthSort()
            { return bDispUsingZDepthSort_; }
void
    cf_Virt3DObj
        ::dispUsingZDepthSort( BOOL bNewState )
            { bDispUsingZDepthSort_ = bNewState; }

// Get/set Hidden-Surface-Elimination calcs ON/OFF.
BOOL
    cf_Virt3DObj
        ::dispUsingHSE()
            { return bDispUsingHSE_; }
void
    cf_Virt3DObj
        ::dispUsingHSE( BOOL bNewState )
            { bDispUsingHSE_ = bNewState; }

BOOL
cf_Virt3DObj::dispVisibleIs()
{
    return bDispVisible_;
}

void
cf_Virt3DObj::dispVisible
            ( BOOL bNewState )
{
    bDispVisible_ = bNewState;
}


void
cf_Virt3DObj::dispWireFrame
            ( BOOL   bNewState )
{
    bDispWireFrame_ = bNewState;
}

BOOL
cf_Virt3DObj::dispWireFrame()
{
    return bDispWireFrame_;
}


//
// Define "nop" implementations of the DRAW function
// for this virtual BASE objct:
//
void
    cf_Virt3DObj
        ::draw( bf_Display * /*p_bf_dspUseThisDisplay*/ )
{}

void
    cf_Virt3DObj
        ::draw2D( bf_Display * /*p_bf_dspUseThisDisplay*/ )
{}

void
    cf_Virt3DObj
        ::draw3D( bf_Display * /*p_bf_dspUseThisDisplay*/ )
{}


//
//  Get Information on the Data Dimensions 
//  (e.g. for Tick Marking Ops) of cf_Virt3DObjs:
//
double
    cf_Virt3DObj
        ::dataXMin()
            const   
                { return 0.0; }
            
double
    cf_Virt3DObj
        ::dataXMax()
            const   
                { return 0.0; }

double
    cf_Virt3DObj
        ::dataYMin()
            const
                { return 0.0; }
            
double
    cf_Virt3DObj
        ::dataYMax() 
            const   
                { return 0.0; }

double
    cf_Virt3DObj
        ::dataZMin() 
            const   
                { return 0.0; }
            
double
    cf_Virt3DObj
        ::dataZMax()
            const
                { return 0.0; }


//---------------------------------------------------------------------
//  Get Information on the Virtual Dimensions (e.g. for Scaling Ops):
//---------------------------------------------------------------------
double
    cf_Virt3DObj
        ::virtXMin()
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::virtXMax()
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::virtYMin()
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::virtYMax()
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::virtZMin()
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::virtZMax()
            const
                { return 0.0; }


//-----------------------------------------------------------------------
//  Get Info on the TRANSFORMED Dimensions (e.g. for Depth-Sorting Ops):
//-----------------------------------------------------------------------
double
    cf_Virt3DObj
        ::xformXMin()
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::xformXMax()   
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::xformYMin()   
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::xformYMax()   
            const
                { return 0.0; }

double
    cf_Virt3DObj
        ::xformZMin()   
            const
                { return 0.0; }
            
double
    cf_Virt3DObj
        ::xformZMax()   
            const
                { return 0.0; }
//
// END of cf_Virt3DObj implementation.
//

//////////////////////////////////////
// END of File: CO1_VOBJ.CPP
//////////////////////////////////////

