If the frame size is changed, drawing energy value is delete

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
manggae
Earned a small fee
Earned a small fee
Posts: 12
Joined: Tue Jul 14, 2015 10:06 am

If the frame size is changed, drawing energy value is delete

Postby manggae » Wed Jul 29, 2015 7:12 am

I was able to complete the program. Giving a lot of help from this site.
Features of the program is playing wav file, extract energy and draw energy value.
However, there are problems.

If the frame size is changed, drawing energy value is delete....

void testdrawFrame::OnDrawEnergyClick(wxCommandEvent& event)
{
wxClientDC cdc(Panel1);
wxBufferedDC dc(&cdc);
dc.Clear();
///////////////////////////// extract sound
.....clipping

//////////////////////////////
wxRect rect = Panel1->GetRect();
float amp_scale2= (float)(frameN/rect.GetLeft())/4;
wxPen pen(*wxRED);
dc.SetPen(pen);
for (int n=0; n<frameN; n++)
{
dc.DrawLine( n/(amp_scale2), rect.GetHeight()/2, n/(amp_scale2), 2*feature2d[n][0] );
}
}
Last edited by manggae on Wed Jul 29, 2015 12:07 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 12507
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: If the frame size is changed, drawing energy value is delete

Postby doublemax » Wed Jul 29, 2015 7:50 am

Everything you draw on a wxClientDC will be overdrawn by the next "regular" redraw, e.g. if you minimize/restore the window or move another window over yours.

Therefore you should catch the wxEVT_PAINT event and do your drawing there.
Use the source, Luke!

manggae
Earned a small fee
Earned a small fee
Posts: 12
Joined: Tue Jul 14, 2015 10:06 am

Re: If the frame size is changed, drawing energy value is delete

Postby manggae » Wed Jul 29, 2015 8:54 am

Can you give an example concerning wxEVT_PAINT?

i make the source, but it is not action......
How do I fix it?

Code: Select all

Connect(ID_PANEL1,wxEVT_PAINT,wxPaintEventHandler(testdrawFrame::OnPaint));

void testdrawFrame::OnPaint(wxPaintEvent& event)
{
    wxClientDC cdc(Panel1);
    wxBufferedDC dc(&cdc);
    dc.Clear();

    wxRect rect = Panel1->GetRect();
    float amp_scale2= (float)(frameN/rect.GetLeft())/4;
    wxPen pen(*wxRED);
    dc.SetPen(pen);
      for (int n=0; n<frameN; n++)
      {
         dc.DrawLine( n/(amp_scale2), rect.GetHeight()/2, n/(amp_scale2), 2*feature2d[n][0] );
      }

}
Last edited by doublemax on Wed Jul 29, 2015 9:59 am, edited 1 time in total.
Reason: Added code tags

User avatar
doublemax
Moderator
Moderator
Posts: 12507
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: If the frame size is changed, drawing energy value is delete

Postby doublemax » Wed Jul 29, 2015 10:00 am

Code: Select all

Panel1->Connect(wxEVT_PAINT, wxPaintEventHandler(testdrawFrame::OnPaint));

void testdrawFrame::OnPaint(wxPaintEvent& event)
{
  wxBufferedPaintDC dc(Panel1);

  // drawing code here
}
Use the source, Luke!

manggae
Earned a small fee
Earned a small fee
Posts: 12
Joined: Tue Jul 14, 2015 10:06 am

Re: If the frame size is changed, drawing energy value is delete

Postby manggae » Wed Jul 29, 2015 10:16 am

this code
" Panel1->Connect(wxEVT_PAINT,(wxObjectEventFunction)&testdrawFrame::OnPaint);" is include the testdrawFrame::testdrawFrame(wxWindow* parent,wxWindowID id) ?

so stop the program......

User avatar
doublemax
Moderator
Moderator
Posts: 12507
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: If the frame size is changed, drawing energy value is delete

Postby doublemax » Wed Jul 29, 2015 10:19 am

Sorry.

Code: Select all

Panel1->Connect(wxEVT_PAINT, wxPaintEventHandler(testdrawFrame::OnPaint), NULL, this);
Use the source, Luke!

manggae
Earned a small fee
Earned a small fee
Posts: 12
Joined: Tue Jul 14, 2015 10:06 am

Re: If the frame size is changed, drawing energy value is delete

Postby manggae » Wed Jul 29, 2015 11:14 am

I've uploaded the source, i click the button("draw energy") and draw energy value,
but Source gave you is taught, Let the program starts as soon as the figure is drawn.

How do I transfer the event?

Code: Select all

void testdrawFrame::OnDrawEnergyClick(wxCommandEvent& event)
{

    if ( little_endian() ) {
      m_byteOrder = MY_LITTLE_ENDIAN;
      m_swapByte = 0;
   }
   else{
      m_byteOrder = MY_BIG_ENDIAN;
      m_swapByte = 1;
   }
   const char* tag =NULL;
   if(tag){ //태그 있으면 읽기
      m_tag=tag;
   }
   FILE *fi, *fo; //
   FeatKind fk=FE_ENERGY;
   const char *infile;
   idx=ListView1->GetFirstSelected();
    path = (LPCSTR)ListView1->GetItemData(idx);
    //////출력 파일 명
    wxString filename;
   int nInex = path.Find(".");
   filename = path.Left(nInex);
   wxString kindoutput = ".txt";
   wxString outputresult = filename + kindoutput;

    fi=fopen(path,"rb");
    if(fi==NULL)
   {
      //err_fopen("C:\\test12\\test1.raw");
   }
   const char *outfile=outputresult;
   fo=fopen(outfile,"w");
   fseek(fi,0L,SEEK_END);
    int fsize = ftell(fi);
    rewind(fi);
    CFeature adcData;
    adcData.vec.resize(fsize/sizeof(short));
    int sampleN = ad_read(fi,&adcData.vec[0],fsize/sizeof(short));
    CFeature feature;
    frameN = FeatureMain(fk, adcData, 0, sampleN, feature, -1, -1);
    int dimN = GetDim(fk);
   vector<int> pTag(dimN);
    ReadTag(m_tag.c_str(), &pTag[0], dimN);
    string featname = GetFeatName(fk);
    switch(fk){
   case FE_LPCRES:
   case FE_EPOCH:
   default:
      write_feature_vectors(fo, feature.mat, &pTag[0], featname.c_str());
      break;
   }
   fclose(fi);
   fclose(fo);
}



void testdrawFrame::OnPaint(wxPaintEvent& event)
{
    wxClientDC dc(Panel1);
    //wxBufferedPaintDC dc(Panel1);
    /*wxRect rect = Panel1->GetRect();
    float amp_scale2= (float)(frameN/rect.GetLeft())/4;
    wxPen pen(*wxWHITE);
    dc.SetPen(pen);
      for (int n=0; n<frameN; n++)
      {
         dc.DrawLine( n/(amp_scale2), rect.GetHeight()/2, n/(amp_scale2), 2*feature2d[n][0] );
      }
    dc.Clear();*/
    dc.DrawLine(0,0,100,100);

}
Last edited by doublemax on Wed Jul 29, 2015 11:51 am, edited 1 time in total.
Reason: Added code tags

User avatar
doublemax
Moderator
Moderator
Posts: 12507
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: If the frame size is changed, drawing energy value is delete

Postby doublemax » Wed Jul 29, 2015 11:53 am

Sorry, i didn't understand that.

I'm guessing that you don't see the updated content after loading data. Call Panel1->Refresh() to force an update.

Also, you shouldn't use wxClientDC. Use wxPaintDC or wxBufferedPaintDC in an event handler.
Use the source, Luke!

manggae
Earned a small fee
Earned a small fee
Posts: 12
Joined: Tue Jul 14, 2015 10:06 am

Re: If the frame size is changed, drawing energy value is delete

Postby manggae » Wed Jul 29, 2015 12:07 pm

Thanks to you, I've solved the problem.!!!!!!!
thank you!!!!

void testdrawFrame::OnDrawEnergyClick(wxCommandEvent& event)
{



if ( little_endian() ) {
m_byteOrder = MY_LITTLE_ENDIAN;
m_swapByte = 0;
}
else{
m_byteOrder = MY_BIG_ENDIAN;
m_swapByte = 1;
}
const char* tag =NULL;
if(tag){ //태그 있으면 읽기
m_tag=tag;
}
FILE *fi, *fo; //
FeatKind fk=FE_ENERGY;
const char *infile;
idx=ListView1->GetFirstSelected();
path = (LPCSTR)ListView1->GetItemData(idx);
//////출력 파일 명
wxString filename;
int nInex = path.Find(".");
filename = path.Left(nInex);
wxString kindoutput = ".txt";
wxString outputresult = filename + kindoutput;

fi=fopen(path,"rb");
if(fi==NULL)
{
//err_fopen("C:\\test12\\test1.raw");
}
const char *outfile=outputresult;
fo=fopen(outfile,"w");
fseek(fi,0L,SEEK_END);
int fsize = ftell(fi);
rewind(fi);
CFeature adcData;
adcData.vec.resize(fsize/sizeof(short));
int sampleN = ad_read(fi,&adcData.vec[0],fsize/sizeof(short));
CFeature feature;
frameN = FeatureMain(fk, adcData, 0, sampleN, feature, -1, -1);
int dimN = GetDim(fk);//에너지 경우 dimN =1임
vector<int> pTag(dimN);
ReadTag(m_tag.c_str(), &pTag[0], dimN);
string featname = GetFeatName(fk);
switch(fk){
case FE_LPCRES:
case FE_EPOCH:
default:
write_feature_vectors(fo, feature.mat, &pTag[0], featname.c_str());
break;
}
fclose(fi);
fclose(fo);

Panel1->Refresh();
}

void testdrawFrame::OnPaint(wxPaintEvent& event)
{

wxPaintDC dc(Panel1);
//wxBufferedPaintDC dc(Panel1);
wxRect rect = Panel1->GetRect();
float amp_scale2= (float)(frameN/rect.GetLeft())/4;
wxPen pen(*wxWHITE);
dc.SetPen(pen);
for (int n=0; n<frameN; n++)
{
dc.DrawLine( n/(amp_scale2), rect.GetHeight()/2, n/(amp_scale2), 2*feature2d[n][0] );
}
}


Return to “Component Writing”

Who is online

Users browsing this forum: No registered users and 4 guests