CAA RADE GUI Design

Contents

[hide]

[edit] Overview

This article details how to make a GUI in CAA RADE using only code (no interactive tools for GUI design) Although there is an interactive tool in CAA that integrates with Visual Studio, I have had little success getting it to work and behave in a useful way. I prefer to do it with the code instead, which guarantees the proper GUI behavior.

[edit] Needed Includes

#include "CATBaseUnknown.h"
#include "CATDlgDialog.h"
#include "CATApplicationFrame.h"
#include "CATDialog.h"
#include "CATDlgGridConstraints.h"
#include "CATDlgRadioButton.h"
#include "CATDlgFrame.h"
#include "CATDlgPushButton.h"
#include "CATDlgEditor.h"
#include "CATDlgPushItem.h"
#include "CATDlgLabel.h"
#include "CATDlgSpinner.h"

[edit] Basic Concepts

GUI Layout can be managed in two ways: Grid Layout, or Tabulated Layout. A combination of approaches can be used, which is how the following GUI is managed. In general it is easiest to get the behavior that you expect by using the tabulated layout at least on the top level (in this example the "top level" is the CATDlgDialog object level. This means that all of the direct children of the CATDlgDialog object are managed with a tabulated layout. In this example, most of the sub-children are managed with a grid layout because it is simple and straightforward.) The tabulated layout is more dynamic and easier to control in a resizing window.

[edit] Header File

class TSTDialogFromScratch: public CATDlgDialog
{
	DeclareResource(TSTDialogFromScratch, CATDlgDialog);

public:

	TSTDialogFromScratch ();
	~TSTDialogFromScratch ();
	void Build ();

//methods for the GUI
	void ActivateShapeFrame();
	void ActivateDirFrame();
	void ActivateAll();


//Design Part widgets
	CATDlgEditor* pDPart;
//shape type widgets
	CATDlgRadioButton *pCircRad;
	CATDlgRadioButton *pRectRad;
	CATDlgRadioButton *pSlotRad;
	CATDlgRadioButton *pTriRad;
	CATDlgSpinner* pNumCS;

//direction widgets
	CATDlgEditor* pXDir;
	CATDlgEditor* pYDir;
	CATDlgEditor* pZDir;

//statistical widgets
	//CATDlgEditor  *pNumSampInp;
	//CATDlgEditor *pNumBinsInp;

//Dialog command widgets
	CATDlgPushButton *OKButton;
	CATDlgPushButton *ApplyButton;
	CATDlgPushButton *CanButton;
};

Any Widgets that other classes may need access to should be declared as pointers in the header file so that a handle to the widget can be retrieved later.

[edit] Definition File

#include "TSTDialogFromScratch.h"

TSTDialogFromScratch::TSTDialogFromScratch():
CATDlgDialog((CATApplicationFrame::GetFrame())->GetMainWindow(),
		"MyDialog",CATDlgWndNoButton)
{
	//dialog window sizing rules
	this->SetGridColumnResizable(0,1);
	this->SetGridRowResizable(0,1);

	//widget initialization
	pCircRad = NULL;
	pRectRad = NULL;
	pSlotRad = NULL;

	pXDir = NULL;
	pYDir = NULL;
	pZDir = NULL;

	OKButton = NULL;
	ApplyButton = NULL;
	CanButton = NULL;

	this->Build();
}

TSTDialogFromScratch::~TSTDialogFromScratch()
{
  	pCircRad = NULL;
	pRectRad = NULL;
	pSlotRad = NULL;

	pXDir = NULL;
	pYDir = NULL;
	pZDir = NULL;

	OKButton = NULL;
	ApplyButton = NULL;
	CanButton = NULL;
}

void TSTDialogFromScratch::Build ()
{

	CATDlgFrame * pDesSpaceFrame = new CATDlgFrame(this,"Design Space", CATDlgGridLayout);
	{
		CATDlgLabel* pDSpaceLab = new CATDlgLabel(pDesSpaceFrame,"Design Space Part",CATDlgLabLeft);
		pDSpaceLab->SetGridConstraints(0,0,1,1,CATGRID_CENTER);
	
		pDPart = new CATDlgEditor(pDesSpaceFrame,"Design Part",0);
		pDPart->SetGridConstraints(0,1,1,1,CATGRID_CENTER);
	}

	CATDlgFrame * pShapeFrame = new CATDlgFrame(this,"Shapes", CATDlgGridLayout);
	{
		pCircRad = new CATDlgRadioButton(pShapeFrame,"Circle",NULL);
		pCircRad->SetState(CATDlgCheck,1);
		pCircRad->SetGridConstraints(0,0,1,1,CATGRID_LEFT);

		pRectRad = new CATDlgRadioButton(pShapeFrame,"Rectangle",NULL);
		pRectRad->SetState(CATDlgUncheck,1);
		pRectRad->SetGridConstraints(1,0,1,1,CATGRID_LEFT);

		pSlotRad = new CATDlgRadioButton(pShapeFrame,"Slot",NULL);
		pSlotRad->SetState(CATDlgUncheck,1);
		pSlotRad->SetGridConstraints(2,0,1,1,CATGRID_LEFT);

		pTriRad = new CATDlgRadioButton(pShapeFrame,"Triangle",NULL);
		pTriRad->SetState(CATDlgUncheck,1);
		pTriRad->SetGridConstraints(3,0,1,1,CATGRID_LEFT);

		pNumCS = new CATDlgSpinner(pShapeFrame, "numCS",NULL);
		pNumCS->SetGridConstraints(4,0,1,2,CATGRID_LEFT);
		pNumCS->SetRange(2,10,8,0);
		pNumCS->SetCurrentText("2");
	}

	CATDlgFrame * pDirFrame = new CATDlgFrame(this,"Direction", CATDlgGridLayout);
	{
		CATDlgLabel *pXDirLab = new CATDlgLabel(pDirFrame,"X",CATDlgLabLeft);
		pXDirLab->SetGridConstraints(0,0,1,1,CATGRID_BOTTOM);

		pXDir = new CATDlgEditor(pDirFrame,"X Component",CATDlgEdtFloat  );
		pXDir->SetGridConstraints(0,1,1,1,CATGRID_LEFT);
		pXDir->SetLine("0");
		
		CATDlgLabel *pYDirLab = new CATDlgLabel(pDirFrame,"Y",CATDlgLabLeft);
		pYDirLab->SetGridConstraints(1,0,1,1,CATGRID_BOTTOM);

		pYDir = new CATDlgEditor(pDirFrame,"Y Component",CATDlgEdtFloat  );
		pYDir->SetGridConstraints(1,1,1,1,CATGRID_LEFT);
		pYDir->SetLine("0");
		//pYDir->SetSensitivity(CATDlgDisable);

		CATDlgLabel *pZDirLab = new CATDlgLabel(pDirFrame,"Z",CATDlgLabLeft);
		pZDirLab->SetGridConstraints(2,0,1,1,CATGRID_BOTTOM);

		pZDir = new CATDlgEditor(pDirFrame,"Z Component",CATDlgEdtFloat  );
		pZDir->SetGridConstraints(2,1,1,1,CATGRID_LEFT);
		pZDir->SetLine("1");
	}

	CATDlgFrame * pButtonFrame = new CATDlgFrame(this,"", CATDlgFraNoFrame|CATDlgFraNoTitle);
	{
		OKButton = new CATDlgPushButton(pButtonFrame, "OK",NULL);
		OKButton->SetSensitivity(CATDlgDisable);

		ApplyButton = new CATDlgPushButton(pButtonFrame, "Apply",NULL);

		CanButton =  new CATDlgPushButton(pButtonFrame, "Cancel",NULL);		
	}

	this->SetVerticalAttachment(0,CATDlgTopOrLeft,pDesSpaceFrame,pShapeFrame,NULL);
	this->SetVerticalAttachment(1,CATDlgRightOrBottomRelative, pShapeFrame,NULL);
	this->SetVerticalAttachment(1,CATDlgTopOrLeftRelative,pDirFrame,NULL);
	this->SetVerticalAttachment(2,CATDlgRightOrBottomRelative,pDesSpaceFrame,pDirFrame,pButtonFrame,NULL);

	this->SetHorizontalAttachment(0,CATDlgTopOrLeft,pDesSpaceFrame,NULL);
	this->SetHorizontalAttachment(1,CATDlgRightOrBottomRelative,pDesSpaceFrame,NULL);
	this->SetHorizontalAttachment(1,CATDlgTopOrLeftRelative,pShapeFrame,pDirFrame,NULL);
	this->SetHorizontalAttachment(2,CATDlgRightOrBottomRelative,pShapeFrame,pDirFrame,NULL);
	this->SetHorizontalAttachment(2,CATDlgTopOrLeftRelative,pButtonFrame,NULL);
	this->SetHorizontalAttachment(3,CATDlgRightOrBottomRelative,pButtonFrame,NULL);

	this->SetFocusOn(OKButton);
	this->SetVisibility(CATDlgShow);
}