next up previous contents
Next: Geometry Up: Dialog classes Previous: Dialog classes

Kinematics

#if !defined(__kinematc_h)              // Sentry, use file only if it's not already included.
#define __kinematc_h

/*  Project pg
    University of Ljubljana
    Copyright � 1995 LECAD. All Rights Reserved.

    SUBSYSTEM:    pg.apx Application
    FILE:         kinematc.h
    AUTHOR:       CAD lab


    OVERVIEW
    ========
    Class definition for Kinematic (TDialog).      
*/

#include <owl\owlpch.h>
#pragma hdrstop

#include <owl\edit.h>
#include <owl\radiobut.h>

#include "pgapp.rh"            // Definition of all resources.


//{{TDialog = Kinematic}}
struct KinematicXfer {
//{{KinematicXFER_DATA}}
    bool    FixCarrier;
    bool    FixRing;
    bool    FixSun;
    bool    InCarrier;
    bool    InRing;
    bool    InSun;
    char    NoPlanets[ 255 ];
    bool    OutCarrier;
    bool    OutRing;
    bool    OutSun;
    char    TeethRing[ 255 ];
    char    TeethSun[ 255 ];
//{{KinematicXFER_DATA_END}}
};

enum { SEL_SUN, SEL_RING, SEL_CARRIER };


struct KineData {
        int iInput ;
        int iOutput ;
        int iFixed ;
        int iNoPlanets ;
        int iTeethRing ;
        int iTeethSun ;
    int iTeethPlanet ;
} ;

class Kinematic : public TDialog {
public:
    Kinematic (TWindow* parent, TResId resId = IDD_KIN_SCHEME, TModule* module = 0);
        void GetValues( KineData *data ) ;
        void SetValues( KineData data ) ;
    virtual ~Kinematic ();

//{{KinematicXFER_DEF}}
protected:
    TRadioButton *FixCarrier;
    TRadioButton *FixRing;
    TRadioButton *FixSun;
    TRadioButton *InCarrier;
    TRadioButton *InRing;
    TRadioButton *InSun;
    TEdit *NoPlanets;
    TRadioButton *OutCarrier;
    TRadioButton *OutRing;
    TRadioButton *OutSun;
    TEdit *TeethRing;
    TEdit *TeethSun;

//{{KinematicXFER_DEF_END}}

//{{KinematicVIRTUAL_BEGIN}}
public:
    virtual void SetupWindow ();
    virtual bool CanClose ();
//{{KinematicVIRTUAL_END}}
};    //{{Kinematic}}


#endif                                      // __kinematc_h sentry.


/*  Project pg
    University of Ljubljana
    Copyright  1995 LECAD. All Rights Reserved.

    SUBSYSTEM:    pg.apx Application
        FILE:         kinematc.cpp
        AUTHOR:       CAD lab


    OVERVIEW
    ========
        Source file for implementation of Kinematic (TDialog).
*/

#include <owl\owlpch.h>
#pragma hdrstop

#include "kinematc.h"


//{{Kinematic Implementation}}


static KinematicXfer KinematicData;
static int iInitDone  = 0 ;

Kinematic::Kinematic (TWindow* parent, TResId resId, TModule* module):
    TDialog(parent, resId, module)
{
//{{KinematicXFER_USE}}
        FixCarrier = new TRadioButton(this, IDC_FIX_CARRIER, 0);
        FixRing = new TRadioButton(this, IDC_FIX_RING, 0);
    FixSun = new TRadioButton(this, IDC_FIX_SUN, 0);
    InCarrier = new TRadioButton(this, IDC_IN_CARRIER, 0);
        InRing = new TRadioButton(this, IDC_IN_RING, 0);
    InSun = new TRadioButton(this, IDC_IN_SUN, 0);
    NoPlanets = new TEdit(this, IDC_NO_PLANETS, 255);
    OutCarrier = new TRadioButton(this, IDC_OUT_CARRIER, 0);
    OutRing = new TRadioButton(this, IDC_OUT_RING, 0);
    OutSun = new TRadioButton(this, IDC_OUT_SUN, 0);
    TeethRing = new TEdit(this, IDC_TEETH_RING, 255);
    TeethSun = new TEdit(this, IDC_TEETH_SUN, 255);

    SetTransferBuffer(&KinematicData);
//{{KinematicXFER_USE_END}}

    // INSERT>> Your constructor code here.

}


Kinematic::~Kinematic ()
{
    Destroy();

    // INSERT>> Your destructor code here.

}

void Kinematic::GetValues( KineData *data )
{
        if( KinematicData.InSun ) {
                data->iInput = SEL_SUN ;
        } else if ( KinematicData.InRing ) {
                data->iInput = SEL_RING ;
        } else {
                data->iInput = SEL_CARRIER ;
        }

        if( KinematicData.FixSun ) {
                data->iFixed = SEL_SUN ;
        } else if ( KinematicData.FixRing ) {
                data->iFixed = SEL_RING ;
        } else {
                data->iFixed = SEL_CARRIER ;
        }

        if( KinematicData.OutSun ) {
                data->iOutput = SEL_SUN ;
        } else if ( KinematicData.OutRing ) {
                data->iOutput = SEL_RING ;
        } else {
                data->iOutput = SEL_CARRIER ;
        }
        data->iNoPlanets = atoi(KinematicData.NoPlanets) ;
        data->iTeethRing = atoi(KinematicData.TeethRing) ;
        data->iTeethSun = atoi(KinematicData.TeethSun) ;
}


void Kinematic::SetValues( KineData data )
{
        // set states for radio buttons
        KinematicData.InSun = data.iInput == SEL_SUN ;
        KinematicData.InRing = data.iInput == SEL_RING ;
        KinematicData.InCarrier = data.iInput == SEL_CARRIER ;
        KinematicData.FixSun = data.iFixed == SEL_SUN ;
        KinematicData.FixRing = data.iFixed == SEL_RING ;
        KinematicData.FixCarrier = data.iFixed == SEL_CARRIER ;
        KinematicData.OutSun = data.iOutput == SEL_SUN ;
        KinematicData.OutRing = data.iOutput == SEL_RING ;
        KinematicData.OutCarrier = data.iOutput == SEL_CARRIER ;

        // set values for input fields
        wsprintf( KinematicData.NoPlanets, "%d", data.iNoPlanets ) ;
        wsprintf( KinematicData.TeethRing, "%d", data.iTeethRing ) ; 
        wsprintf( KinematicData.TeethSun, "%d", data.iTeethSun ) ;
}



void Kinematic::SetupWindow ()
{
    TDialog::SetupWindow();


        if ( !iInitDone ) {
                // do the initialization
                InSun->Check() ;
                InRing->Uncheck() ;
                InCarrier->Uncheck() ;
                FixSun->Uncheck() ;
                FixRing->Check() ;
                FixCarrier->Uncheck() ;
                OutSun->Uncheck() ;
                OutRing->Uncheck() ;
                OutCarrier->Check() ;
                NoPlanets->SetText( "3" ) ;
                TeethSun->SetText( "21" ) ;
                TeethRing->SetText( "108" ) ;
                iInitDone = 1 ;
        }
}


bool Kinematic::CanClose ()
{
        bool result;
        int iInput, iFixed, iOutput ;

        result = TDialog::CanClose();

        // INSERT>> Your code here.
        if( InSun->GetCheck() == BF_CHECKED ) {
                iInput = SEL_SUN ;
        } else if ( InRing->GetCheck() == BF_CHECKED ) {
                iInput = SEL_RING ;
        } else {
                iInput = SEL_CARRIER ;
        }

        if( FixSun->GetCheck() == BF_CHECKED ) {
                iFixed = SEL_SUN ;
        } else if ( FixRing->GetCheck() == BF_CHECKED ) {
                iFixed = SEL_RING ;
        } else {
                iFixed = SEL_CARRIER ;
        }

        if( OutSun->GetCheck() == BF_CHECKED ) {
                iOutput = SEL_SUN ;
        } else if ( OutRing->GetCheck() == BF_CHECKED ) {
                iOutput = SEL_RING ;
        } else {
                iOutput = SEL_CARRIER ;
        }


        if( iInput == iOutput || iInput == iFixed || iOutput == iFixed ) {
                // display error
                MessageBox( "Input, output and fixed gears MUST be different.\r\n"
                                        "Please, correct", "Error in input data" ) ;
                result = false ;
        } else {
                result = true ;
        }

        return result;
}



Leon Kos
Tue Dec 2 10:35:04 CET 1997