first time programming in wxWindows 2.4.2--student

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
namespace
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Mar 02, 2005 3:16 am

first time programming in wxWindows 2.4.2--student

Post by namespace » Tue Mar 15, 2005 5:34 am

To Whomever It May Concern,

I am a student at the University of Saskatchewan in Saskatoon, Saskatchewan, Canada. Recently, I have tried to write my first GUI code on MS Windows XP SP2 using the wxWindows 2.4.2 distribution. For a very long time I have been working with 'text based' programs in Java and C++, and this is my first try at using wxWindows. Wow! That's the only word that I can use to describe it. Although I have a working program, there are a few runtime errors that occur after the code has been compliled using Borland C++ Builder X Personal Edition. Would someone out there be able to help me?

(1) The application is designed to read in a .WAV file, extract some information from the header, perform a 'cookbook version' of the Fast Fourier Transform on the sound data, and then display the processed data using a wxPlotWindow. (The Fast Fourier Transform is required to calculate the intensity in decibels of the sound pressure level). Because I am a student in Physical Geography with an interest in Computer Science, I have set up an experiment to study the propagation of a sound pulse through a snowpack (that's the reason why I call the program 'snowLab'). (The sound pulses were created in the field using an audio oscillator, and recorded on a digital recorder.) However, the code that I have written does not seem to be working very well with the Standard Template Library. As far as I can tell, the section of the program used to manipulate the data for the Fast Fourier Transform seems to work, but the program crashes when I try to calculate the intensity of the pressure disturbance in decibels. I have checked to see if

#define wxUSE_GLOBAL_MEMORY_OPERATORS 0
#define wxUSE_DEBUG_NEW_ALWAYS 0

are set to zero in the appropriate header files, and I have also typed in

#ifdef new
#undef new
#endif

to ensure that the 'new' keyword has not been redefined. Am I using the Standard Template Library in the proper manner?

(2) I've noticed that the icon for the program 'snowLab' does not display properly in the upper left-hand corner of the window; all that the program shows is a empty white 'box'. Am I using the wxWindows icon resources in the proper fashion?

Here is the code (all as one file) that I have written. I hope that someone is able to help me.

Code: Select all

//----------------------------------------------
//snowLab program
#ifdef __BIDE__
#define _NO_VCL
#include "condefs.h"
#define WinMain WinMain
  USERC("snowlab.rc");
#endif

#ifdef new
#undef new
#endif

//Include files
#include <windows>
#include <vector>
#include <math>

#include <wx/wxprec.h>
#pragma hdrstop
#include <wx/wx.h>

#include <wx/toolbar.h>
#include <wx/image.h>
#include <wx/dialog.h>
#include <wx/plot/plot.h>
#include <wx/listctrl.h>
#include <wx/sizer.h>
#include <wx/log.h>
#include <wx/intl.h>
#include <wx/wfstream.h>
#include <wx/datstrm.h>
#include <wx/string.h>
#include <wx/dynarray.h>


#define USE_XPM_BITMAPS 1 //Use XPM bitmaps

#include "loadfile.xpm"
#include "fileinfo.xpm"
#include "closefile.xpm"
#include "play.xpm"
#include "savelog.xpm"
#include "exit.xpm"
#include "question.xpm"

//Derived classes
class MyApp;
class PlotCurve;

//Array to hold all of the data from the .WAV file
std::vector<float>dataWav;
std::vector<float>decibelValues;

//Int to hold size of dataWav
unsigned int dataSize;

//Pointer to plot window
wxPlotWindow *m_plot;

class MyPlotCurve: public wxPlotCurve
{
  public:
  MyPlotCurve(int offsetY, double startY, double endY):
            wxPlotCurve(offsetY, startY, endY){}
  virtual wxInt32 GetStartX()
  {
    return 0;
  }
  virtual wxInt32 GetEndX()
  {
    return dataSize-1;
  }

  virtual double GetY(int x)
  {
    double resultReturn = decibelValues[x];
    return resultReturn;
  }
};


//Variables to hold the state of the buttons
bool LOADFILE_ENABLE  = TRUE;
bool FILEINFO_ENABLE  = FALSE;
bool CLOSEFILE_ENABLE = FALSE;
bool PLAY_ENABLE      = FALSE;
bool SAVELOG_ENABLE   = FALSE;
bool EXIT_ENABLE      = TRUE;
bool QUESTION_ENABLE  = TRUE;


//Strings to hold the name of the file currently being processed
wxString currentFile;   //Full path
wxString fileName;      //Only name of file

//String to hold the file information displayed to the user
wxString info;

//Information contained in the header of WAV file
  wxString fileIdent;
  wxString fileLengthSubtractEight;
  wxString fileType;

  //fmt chunk
  wxString fmtDescriptor;
  wxString lengthFmtData;
  wxString formatTag;
  wxString channels;
  wxString sampleRate;
  wxString bytesPerSecond;
  wxString blockAlign;
  wxString bitsPerSample;
  wxString dataDescriptor;
  wxString lengthOfDataBlock;


class MyApp: public wxApp
{
 public:
  bool OnInit();
};

class MyFrame: public wxFrame
{
 public:
  MyFrame(wxFrame *parent, wxWindowID id = -1, const wxString& title =
          "snowLab v.1.03", const wxPoint& pos = wxDefaultPosition, const
          wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE);

  void OnOpen(wxCommandEvent& WXUNUSED(event));
  void FileInfo(wxCommandEvent& WXUNUSED(event));
  void OnClose(wxCommandEvent& WXUNUSED(event));
  void OnPlay(wxCommandEvent& WXUNUSED(event));
  void OnSaveLog(wxCommandEvent& WXUNUSED(event));
  void OnExit(wxCommandEvent& WXUNUSED(event));
  void OnHelp(wxCommandEvent& WXUNUSED(event));
  void OnPlotClick(wxPlotEvent &event);

  void OnToolEnter(wxCommandEvent& event);
  void CreateToolBarNow();
  void setToolBarOpen();
  void playWaveFileNow();
  void printInfo();
  void getFileInfo();
  void clearInfo();

  //Functions associated with FFT
  void doFFTAll();

  //Text control
  wxTextCtrl *m_log;

 private:
  bool    m_horzToolbar;
  wxToolBar *m_tbar;

  DECLARE_EVENT_TABLE()
};

//Constants

const int ID_TOOLBAR = 500;

enum
{
  IDM_TOOLBAR_ONOPEN = 1,
  IDM_TOOLBAR_INFO = 2,
  IDM_TOOLBAR_CLOSE = 3,
  IDM_TOOLBAR_PLAY = 4,
  IDM_TOOLBAR_SAVELOG = 5,
  IDM_TOOLBAR_EXIT = 6,
  IDM_TOOLBAR_HELP = 7
};



//Implementation
IMPLEMENT_APP(MyApp)

//Event tables
BEGIN_EVENT_TABLE (MyFrame, wxFrame)
  EVT_TOOL(IDM_TOOLBAR_ONOPEN, MyFrame::OnOpen)
  EVT_TOOL(IDM_TOOLBAR_INFO, MyFrame::FileInfo)
  EVT_TOOL(IDM_TOOLBAR_CLOSE, MyFrame::OnClose)
  EVT_TOOL(IDM_TOOLBAR_PLAY, MyFrame::OnPlay)
  EVT_TOOL(IDM_TOOLBAR_SAVELOG, MyFrame::OnSaveLog)
  EVT_TOOL(IDM_TOOLBAR_EXIT, MyFrame::OnExit)
  EVT_TOOL(IDM_TOOLBAR_HELP, MyFrame::OnHelp)
  EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
  EVT_PLOT_CLICKED(-1, MyFrame::OnPlotClick)
END_EVENT_TABLE()


bool MyApp::OnInit()
{
  MyFrame* frame = new MyFrame((wxFrame*)NULL, -1, "snowLab v.1.03",
                        wxPoint(250, 150), wxSize(800, 700));

  frame->SetIcon(wxIcon(_T("snowlab.ico")));
  frame->SetStatusText("Welcome to snowLab");
  frame->Centre(wxBOTH);
  SetTopWindow(frame);
  frame->Show(TRUE);
  return TRUE;
}

void MyFrame::CreateToolBarNow()
{
  wxToolBarBase *toolbar = GetToolBar();

  long style = wxTB_HORIZONTAL;

  toolbar = CreateToolBar(style, ID_TOOLBAR);
  toolbar->SetMargins(4,4);

  //Toolbar setup
  wxBitmap toolBarBitmaps[7];

  toolBarBitmaps[0] = wxBitmap(loadfile_xpm);
  toolBarBitmaps[1] = wxBitmap(fileinfo_xpm);
  toolBarBitmaps[2] = wxBitmap(closefile_xpm);
  toolBarBitmaps[3] = wxBitmap(play_xpm);
  toolBarBitmaps[4] = wxBitmap(savelog_xpm);
  toolBarBitmaps[5] = wxBitmap(exit_xpm);
  toolBarBitmaps[6] = wxBitmap(question_xpm);

  int w = toolBarBitmaps[0].GetWidth();
  int h = toolBarBitmaps[0].GetHeight();

  toolbar->SetToolBitmapSize(wxSize(w,h));

  int currentX = 5;
  int width = 24;

  //Create buttons for toolbar
  toolbar->AddTool(1, toolBarBitmaps[0], wxNullBitmap, FALSE, currentX,
                   -1,(wxObject *)NULL, "Process New File");
  toolbar ->EnableTool(1, LOADFILE_ENABLE);
  currentX = currentX + (width +5);


  toolbar->AddTool(2, toolBarBitmaps[1], wxNullBitmap, FALSE, currentX,
                 -1,(wxObject *)NULL, "File Info");
  toolbar->EnableTool(2, FILEINFO_ENABLE);
  currentX = currentX + (width +5);

  toolbar->AddTool(3, toolBarBitmaps[2], wxNullBitmap, FALSE, currentX,
                 -1,(wxObject *)NULL, "Clear Plot");
  toolbar->EnableTool(3, CLOSEFILE_ENABLE);
  currentX = currentX + (width +5);

  toolbar->AddTool(4, toolBarBitmaps[3], wxNullBitmap, FALSE, currentX,
                 -1,(wxObject *)NULL, "Play Sound File");
  toolbar->EnableTool(4, PLAY_ENABLE);
  currentX = currentX + (width +5);

  toolbar->AddTool(5, toolBarBitmaps[4], wxNullBitmap, FALSE, currentX,
                -1,(wxObject *)NULL, "Save Log");
  toolbar->EnableTool(5, SAVELOG_ENABLE);
  currentX = currentX + (width +5);

  toolbar->AddTool(6, toolBarBitmaps[5], wxNullBitmap, FALSE, currentX,
               -1,(wxObject *)NULL, "Exit Program");
  toolbar->EnableTool(6, EXIT_ENABLE);
  currentX = currentX + (width +5);

  toolbar->AddTool(7, toolBarBitmaps[6], wxNullBitmap, FALSE, currentX,
               -1,(wxObject *)NULL, "About this program");
  toolbar->EnableTool(7, QUESTION_ENABLE);

  toolbar->Realize();
  toolbar->SetRows(1);
}

//MyFrame Constructor
MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString&title,
                  const wxPoint& pos, const wxSize& size, long style):
                  wxFrame(parent, id, title, pos, size, style)
{
  m_tbar = NULL;
  m_horzToolbar = TRUE;

  CreateStatusBar(2);
  SetIcon(wxIcon("snowlab.ico"));
  CreateToolBarNow();

  //Add the plot window to the app
  m_plot = new wxPlotWindow(this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER | wxPLOT_DEFAULT);
  m_plot->SetUnitsPerValue(1);

  m_log = new wxTextCtrl(this, -1, "snowLab v. 1.03 Log Window\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE);
  wxLog *prevLog = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
  delete prevLog;

  wxBoxSizer *box = new wxBoxSizer(wxVERTICAL);
  box->Add(m_plot, 1, wxEXPAND);
  box->Add(m_log, 0, wxEXPAND);
  SetAutoLayout(TRUE);
  SetSizer(box);
}

//Other functions
void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
{
  wxFileDialog *dlg = new wxFileDialog(this, "Sound File Selection", "", "",
                        "Wave File (*.WAV)|*.WAV", wxOPEN, wxDefaultPosition);
  if (dlg->ShowModal() == wxID_OK)
  {
    fileName = dlg->GetFilename();
    currentFile = dlg->GetPath();
    //Set the status text for the file
    SetStatusText(fileName, 1);
    //Clear all of the file information from the last file loaded
    clearInfo();
    //Get the file information from the current file selected
    getFileInfo();
    //Calculate the FFT of the data and obtain the intensity(in decibels)
    doFFTAll();

    //Enable other buttons
    setToolBarOpen();
  }
  else
  {
    dlg->Destroy();
  }
}

void MyFrame::FileInfo(wxCommandEvent& WXUNUSED(event))
{
 printInfo();
}

void MyFrame::OnClose(wxCommandEvent& WXUNUSED(event))
{
  //Using this function, you clear the display

}

void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
{
  playWaveFileNow();
}

void MyFrame::OnSaveLog(wxCommandEvent& WXUNUSED(event))
{
  wxFileDialog *dlg = new wxFileDialog(this, "Save Log", "", "",
                      "Text File (*.TXT)|*.TXT", wxSAVE, wxDefaultPosition);
  if (dlg->ShowModal() == wxID_OK)
  {
    dlg->Destroy();
  }

}

void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
{
  Close(TRUE);
}

void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
{
  wxString infoMsg;
  infoMsg.Printf(_T("snowLab"));
  wxMessageBox(infoMsg, "About snowLab", wxOK | wxICON_INFORMATION, this);
}

void MyFrame::OnToolEnter(wxCommandEvent& event)
{

  if (event.GetSelection() > -1)
  {
    wxString str;

    switch(event.GetSelection())
    {
      case 1:
      str = _T("Open sound file and display a time series of the intensity");
      break;

      case 2:
      str = _T("Display information about the recorded sound file");
      break;

      case 3:
      str = _T("Clear the plot displayed on the screen");
      break;

      case 4:
      str = _T("Play the recorded sound file");
      break;

      case 5:
      str = _T("Save log file");
      break;

      case 6:
      str = _T("Exit this program");
      break;

      case 7:
      str = _T("About this program");
    }
    SetStatusText(str);
  }
  else
  {
    SetStatusText("");
  }
}

void MyFrame::setToolBarOpen()
{
  //Enable all of the buttons
  bool FILEINFO_ENABLE  = TRUE;
  bool CLOSEFILE_ENABLE = TRUE;
  bool PLAY_ENABLE      = TRUE;
  bool SAVELOG_ENABLE   = TRUE;

  wxToolBarBase *tb = GetToolBar();
  tb->EnableTool(2, FILEINFO_ENABLE);
  tb->EnableTool(3, CLOSEFILE_ENABLE);
  tb->EnableTool(4, PLAY_ENABLE);
  tb->EnableTool(5, SAVELOG_ENABLE);
}

void MyFrame::playWaveFileNow()
{
  //Use Windows API to lock the resource and play the .WAV file
  PlaySound(currentFile, NULL, SND_SYNC | SND_NODEFAULT);
}

void MyFrame::printInfo()
{
  info = "";
  info.Append("\nFile Name: ");
  info.Append(fileName);
  info.Append("\nFile Identifier: ");
  info.Append(fileIdent);
  info.Append("\n[(File Length) - 8]: ");
  info.Append(fileLengthSubtractEight);
  info.Append("\nFile Type: ");
  info.Append(fileType);
  info.Append("\nFile Format: ");
  info.Append(fmtDescriptor);
  info.Append("\nLength of fmt data: ");
  info.Append(lengthFmtData);
  info.Append("\nFormat Tag: ");
  info.Append(formatTag);
  info.Append("\nChannels: ");
  info.Append(channels);
  info.Append("\nSamples per second: ");
  info.Append(sampleRate);
  info.Append("\n(rate of sampling)*(block align): ");
  info.Append(bytesPerSecond);
  info.Append("\nchannels * bits/sample/8: ");
  info.Append(blockAlign);
  info.Append("\nBits per sample: ");
  info.Append(bitsPerSample);
  info.Append("\nData Descriptor: ");
  info.Append(dataDescriptor);
  info.Append("\nLength of Data Block: ");
  info.Append(lengthOfDataBlock);
  wxMessageBox(info, "About .WAV File", wxOK | wxICON_INFORMATION, this);
}

void MyFrame::getFileInfo()
{
  wxFileInputStream input (currentFile);
  wxDataInputStream store (input);

 if (input.LastError() != wxSTREAM_NOERROR)
 {
   wxString s;
   s.Printf(_T("The file that you requested could not be loaded.\nPlease try again."));
   wxMessageBox(s, "Error Loading .WAV File", wxOK | wxICON_INFORMATION, this);
 }

 //Get file identifier
 for (int i = 0; i < 4; i++)
 {
   wxUint8 identifyFile = store.Read8();
   fileIdent.Append(identifyFile);
 }

 //Get the (file length)-8
 int fileLengthSubtracted = store.Read32();
 wxString placeIn;
 placeIn << fileLengthSubtracted;
 fileLengthSubtractEight.Append(placeIn);

 //Get the file type (should be .WAV)
 for (int i = 0; i < 4; i++)
 {
   wxUint8 typeOfFile = store.Read8();
   fileType.Append(typeOfFile);
 }

 //Separate information for fmt chunk
 for (int i = 0; i < 4; i++)
 {
   wxUint8 descriptionFmt = store.Read8();
   fmtDescriptor.Append(descriptionFmt);
 }

 //Get the format of the file
 int FmtDataLength = store.Read32();
 wxString FmtDataLengthPlaceIn;
 FmtDataLengthPlaceIn << FmtDataLength;
 lengthFmtData.Append(FmtDataLengthPlaceIn);

 //Get the format tag for the data
 wxUint8 getFormatTag1 = store.Read8();
 wxString getFormatTagPlaceIn1;
 getFormatTagPlaceIn1 << getFormatTag1;
 formatTag.Append(getFormatTagPlaceIn1);

 wxUint8 getFormatTag2 = store.Read8();
 wxString getFormatTagPlaceIn2;
 getFormatTagPlaceIn2 << "." << getFormatTag2;
 formatTag.Append(getFormatTagPlaceIn2);

 //Get the number of channels for the data
 wxUint8 getChannels1 = store.Read8();
 wxString getChannelsPlaceIn1;
 getChannelsPlaceIn1 << getChannels1;
 channels.Append(getFormatTagPlaceIn1);

 wxUint8 getChannels2 = store.Read8();
 wxString getChannelsPlaceIn2;
 getChannelsPlaceIn2 << "." << getChannels2;
 channels.Append(getFormatTagPlaceIn2);

 //Get the sample rate for the file
 int getSampleRate = store.Read32();
 wxString getSampleRatePlaceIn;
 getSampleRatePlaceIn << getSampleRate;
 sampleRate.Append(getSampleRatePlaceIn);

 //Get the number of bytes recorded in the file per second
 int getBytesPerSecond = store.Read32();
 wxString getBytesPerSecondPlaceIn;
 getBytesPerSecondPlaceIn << getBytesPerSecond;
 bytesPerSecond.Append(getBytesPerSecondPlaceIn);

 //Get the block align of the file
 wxUint8 getBlockAlign1 = store.Read8();
 wxString getBlockAlignPlaceIn1;
 getBlockAlignPlaceIn1 << getBlockAlign1 ;
 blockAlign.Append(getBlockAlignPlaceIn1);

 wxUint8 getBlockAlign2 = store.Read8();
 wxString getBlockAlignPlaceIn2;
 getBlockAlignPlaceIn2 << "." << getBlockAlign2 ;
 blockAlign.Append(getBlockAlignPlaceIn2);

 //Get the bits per sample in the file
 wxUint8 getBitsPerSample1 = store.Read8();
 wxString getBitsPerSamplePlaceIn1;
 getBitsPerSamplePlaceIn1 << getBitsPerSample1 ;
 bitsPerSample.Append(getBitsPerSamplePlaceIn1);

 wxUint8 getBitsPerSample2 = store.Read8();
 wxString getBitsPerSamplePlaceIn2;
 getBitsPerSamplePlaceIn2 << "." << getBitsPerSample2 ;
 bitsPerSample.Append(getBitsPerSamplePlaceIn2);

 //Separate information for the data chunk
 for (int i = 0; i < 4; i++)
 {
   wxUint8 descriptionDataChunk = store.Read8();
   dataDescriptor.Append(descriptionDataChunk);
 }

 //Get the length of the data block
 int sizeOfData = store.Read32();
 wxString dataLengthPlaceIn;
 dataLengthPlaceIn << sizeOfData;
 lengthOfDataBlock.Append(dataLengthPlaceIn);


 //Value to hold data taken out of the file
 int addItem;
 //Place all of the data into the vector dataWav
 while(!input.Eof())
 {
   int addItem = store.Read16();
   dataWav.push_back(addItem);
 }
 dataSize = dataWav.size();
}

void MyFrame::clearInfo()
{
  //Clear the info string
  info = "";

  //Clear the arrays that hold data from the .WAV file
  dataWav.clear();
  decibelValues.clear();

  //Clear the size of the array
  dataSize = 0;

  //Clear information contained in the header of WAV file
  fileIdent = "";
  fileLengthSubtractEight = "";
  fileType = "";

  //fmt chunk
  fmtDescriptor = "";
  lengthFmtData = "";
  formatTag = "";
  channels = "";
  sampleRate = "";
  bytesPerSecond = "";
  blockAlign = "";
  bitsPerSample = "";
  dataDescriptor = "";
  lengthOfDataBlock = "";
}

void MyFrame::OnPlotClick(wxPlotEvent &event)
{

}

//Function to do FFT
void MyFrame::doFFTAll()
{
  //Create an array to use in the FFT
  std::vector<float>v;
  //Define the size of the array to be twice that of the original
  int augmentedSize = int(2*dataWav.size());
  //wxLogMessage("I have now created the vector v");

  //Set up the augmented vector
  //---------------------------------------------------
  int augmentLoopCounter = 0;
  const int zero = 0;
  //Fill every second element in the array with a zero
  for (int i = 0; i < augmentedSize; i ++)
  {
    if ((i%2 == 0) && (i != 0))
    {
      v.push_back(zero);
    }
    else
    {
      //Fill the first element in the vector with the actual data
      v.push_back(dataWav[augmentLoopCounter++]);
    }
  }
  //wxLogMessage("I have now created the augmented arrays");
  //-----------------------------------------------------
  //Perform the FFT
  //-----------------------------------------------------
  int nn = augmentedSize;
  int n;
  int mmax;
  int m;
  int j;
  int istep;
  int i;
  float temp1;
  float temp2;
  float tempr;
  float tempi;
  double wtemp;
  double wr;
  double wpr;
  double wpi;
  double wi;
  double theta;

  n = nn << 1;
  j = 1;
  for (i = 1; i < n; i +=2)
  {
    if (j > i)
    {
      //swap element at position j with element at position i
      //swap element at position i with element at position j
      temp1 = v[j];
      temp2 = v[i];
      v[j] = temp2;
      v[i] = temp1;

      //swap element at position j+1 with element at position i+1
      //swap element at position i+1 with element at position j+1
      temp1 = v[j+1];
      temp2 = v[i+1];
      v[j+1] = temp2;
      v[i+1] = temp1;
    }
    m = n >> 1;
    while ((m >=2)&&(j > m))
    {
      j -= m;
      m >>= 1;
    }
    j += m;
  }
  mmax = 2;
  while(n > mmax)
  {
    istep = 2*mmax;
    theta = 6.283185/mmax;
    wtemp = sin(0.5*theta);
    wpr = -2.0*wtemp*wtemp;
    wpi = sin(theta);
    wr = 1.0;
    wi = 0.0;
    for (m = 1; m < mmax; m += 2)
    {
      for (i = m; i <= n; i +=istep)
      {
        j = i + mmax;
        tempr = (wr*v[j])-(wi*v[j + 1]);
        tempi = (wr*v[j + 1])+(wi*v[j]);
        v[j] = v[i]-tempr;
        v[j + 1] = v[i + 1]-tempi;
        v[i] = v[i] + tempr;
        v[i+1] = v[i+1] + tempi;
      }
      wr = ((wtemp = wr)*wpr)-(wi*wpi)+wr;
      wi = (wi*wpr)+(wtemp*wpi)+wi;
    }
    mmax = istep;
  }
  //-----------------------------------------------------
  //Calculate the intensity in decibels
  //-----------------------------------------------------
  wxLogMessage("I am now filling the decibel data matrix");
  for (unsigned int i = 0; i < v.size()-2; i +=2)
  {
  float value1 = v[i]*0.00000001;
  float value2 = v[i+1]*0.00000001;
  float sum = (value1*value1)+(value2*value2);
  float greaterSum = sum*10000000;
  float logGreaterSum = log10(greaterSum);
  decibelValues.push_back(logGreaterSum);
  }

  //Create a new plot
  //m_plot->Add(new MyPlotCurve(0, 600, 600));
}

//end of file.
Thank you very much!

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Tue Mar 15, 2005 11:58 am

Is it the commented line at the end,

Code: Select all

  //m_plot->Add(new MyPlotCurve(0, 600, 600));
that seems to be the problem?

My guess is that the height of your visible area in the curve is zero (600-600), might cause the MyPlotCurve class to crash. Could you try with ome more sensible values, like 0,0,600 ?



Also I noted your method MyFrame::OnToolEnter seems to duplicate functionality in the standard toolbar/statusbar.

namespace
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Mar 02, 2005 3:16 am

Post by namespace » Tue Mar 15, 2005 6:21 pm

Thanks for your help, geon! I tried what you suggested, but the problem still persists. The program crashes and the behavior is erratic when I use push_back() to add an element to the vector. Any other activity with the vector seems to give unwanted results. The compiler (with the Borland C++ Builder IDE) tells me sporadically that the 'structure packing size' has changed in a header file associated with the standard distribution. If I could reproduce this message for you, I would paste it here, but I can't because it doesn't appear regularly (it hasn't for about two days). Thank you, however, for your reply to my posting; your suggestion for the method MyFrame::OnToolEnter clears up the problem with the icon!

namespace
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Mar 02, 2005 3:16 am

Post by namespace » Tue Mar 15, 2005 10:02 pm

I just realized--the code given below in my first posting has a nice 'box' placed around it. In addition, someone has colour-coded the text! Thank you to the person who did this; it is much appreciated!

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Wed Mar 16, 2005 11:54 am

The compiler (with the Borland C++ Builder IDE) tells me sporadically that the 'structure packing size' has changed in a header file associated with the standard distribution.
This sounds to me like your version of the STL or wx headers have changed since you compiled the libraries. Or maby you use .lib-files incaompatible with your compiler. (Borland is a bit different from gcc/microsoft.) Maby someone else knows more.

You could try to recompile wx. Might help.

someone has colour-coded the text!
Just select the text and click the "Code" button above the text editing area.

Post Reply