ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've been trying without success to figure out how to use the PLplot wxWidgets driver. The only demo program for this driver that I could find is in the wxPLplot version 0.1 download. (I didn't build the driver from that download -- I'm using the packages from the Debian Lenny and Ubuntu Hardy Heron distributions.)
I couldn't use the makefile included with that demo program because it calls a `plplot-config` script which is not in that download nor in the Debian or Ubuntu distributions but I have been able to compile it using:
But when I try to run it it immediately crashes. If I strip it down so that all it does is open a wxFrame with a wxMenuBar, wxPanel, and wxBoxSizer, it opens the window. But if I add 1 more line of code, putting a wxPLplotwindow in that panel, it crashes.
Here's the code. As you can see, I commented out many lines to pin down the problem. Line 130, instantiating the plotwindow, causes the segmentation fault. What am I missing?
Code:
/* $Id: demo_str.cpp,v 1.7 2005/12/14 08:49:28 smekal Exp $
Copyright (C) 2005 Werner Smekal, Sjaak Verdoold
Copyright (C) 2005 Germain Carrera Corraleche
Copyright (C) 1999 Frank Huebner
This file is part of PLplot.
PLplot is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PLplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with PLplot; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <plplot/plplotP.h>
#include <plplot/wxPLplotwindow.h>
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
// void OnZoomIn(wxCommandEvent& event);
// void OnZoomOut(wxCommandEvent& event);
private:
wxPLplotwindow* plotwindow;
DECLARE_EVENT_TABLE()
};
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
enum { Minimal_Quit = wxID_EXIT, Minimal_About = wxID_ABOUT};
// Minimal_ZoomIn = 10000, Minimal_ZoomOut };
// ----------------------------------------------------------------------------
// event tables and other macros for wxWidgets
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
// EVT_MENU(Minimal_ZoomIn, MyFrame::OnZoomIn)
// EVT_MENU(Minimal_ZoomOut, MyFrame::OnZoomOut)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
// ============================================================================
// implementation
// ============================================================================
/*! This method is called right at the beginning and opens a frame for us.
*
* @author wxWidgets dev team
* @date 2005.11.11
*/
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( _T("wxPLplot demo") );
frame->Show( true );
return true;
}
/*! Constructor of our custom frame, where the Menu is created and a
* a wxPLplotwindow is inserted into the frame. We plot some easy function
* just to show how it works. wxPLplotwindow takes care of all the setup
* for the use of PLplot library. We just need to get a pointer to the
* wxPLplotstream via the GetStream() method. This gives us access to the
* PLplot API.
*
* @author wxWidgets dev team, Werner Smekal
* @date 2005.11.11
*/
MyFrame::MyFrame( const wxString& title )
: wxFrame( NULL, wxID_ANY, title )
{
// add menu
wxMenu *fileMenu = new wxMenu;
fileMenu->Append( Minimal_About, _T("&About...\tF1"), _T("Show about dialog") );
// fileMenu->Append( Minimal_ZoomIn, _T("Zoom &in 10%\tCtrl++"), _T("Zoom in 10%") );
// fileMenu->Append( Minimal_ZoomOut, _T("Zoom &out 10%\tCtrl+-"), _T("Zoom out 10%") );
fileMenu->Append( Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program") );
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append( fileMenu, _T("&File") );
SetMenuBar( menuBar );
// add the wxPLplot
wxPanel* panel = new wxPanel( this );
wxBoxSizer* box = new wxBoxSizer( wxVERTICAL );
plotwindow = new wxPLplotwindow( panel ); // ****** THIS LINE CAUSES SEG FAULT ******
// box->Add( plotwindow, 1, wxALL | wxEXPAND, 0 );
panel->SetSizer( box );
SetSize( 640, 500 );
/*
wxPLplotstream* stream = plotwindow->GetStream();
stream->col0( 1 );
stream->env( -2.0, 10.0, -0.4, 1.2, 0, 2 );
stream->col0( 2 );
stream->sdiplt( 0.0f, 0.0f, 1.0f, 1.0f );
stream->lab( "x-axis", "y-axis", "title" );
// Draw the lines
int size=2048;
PLFLT* x = new PLFLT[size];
PLFLT* y = new PLFLT[size];
// Fill up the arrays.
for( int i=0; i<size; i++ ) {
x[i] = (i/20.48 - 19.0) / 6.0;
y[i] = 1.0;
if( x[i] != 0.0 )
y[i] = sin(2*x[i]) / (2*x[i]);
}
stream->col0( 3 );
stream->wid( 2 );
stream->line( size, x, y );
stream->wid( 1 );
*/
// plotwindow->Refresh();
}
/*! Close() method is called, if we get a quit event.
*
* @author wxWidgets dev team
* @date 2005.11.11
*
* @param event : information about the event
*/
void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
{
Close( true );
}
/*! Show information if Menu entry About was choosen.
*
* @author wxWidgets dev team, Werner Smekal
* @date 2005.11.11
*
* @param event : information about the event
*/
void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
{
wxMessageBox( _T("This is the About dialog of the wxPLplot sample.\n"), _T("About wxPLplot"),
wxOK | wxICON_INFORMATION, this );
}
/*! This Zoom method doesn't work as expected :).
*
* @author Werner Smekal
* @date 2005.11.25
*
* @param event : information about the event
*/
/*void MyFrame::OnZoomIn( wxCommandEvent& WXUNUSED(event) )
{
wxPLplotstream* stream = plotwindow->GetStream();
stream->sdiplz( 0.05f, 0.05f, 0.95f, 0.95f );
plotwindow->RenewPlot();
}
*/
/*! This Zoom method doesn't work as expected :).
*
* @author Werner Smekal
* @date 2005.11.25
*
* @param event : information about the event
*/
/*void MyFrame::OnZoomOut( wxCommandEvent& WXUNUSED(event) )
{
wxPLplotstream* stream = plotwindow->GetStream();
stream->sdiplz( -0.05f, -0.05f, 1.05f, 1.05f );
plotwindow->RenewPlot();
}
*/
Last edited by r.stiltskin; 01-05-2010 at 04:35 PM.
Reason: Solved.
Solved: apparently the PLplot wxWidgets driver (pkg plplot9-driver-wxwidgets) only works with wxWidgets version 2.6 (although it compiles with wxWidgets ver 2.8 without complaining).
I also found another demo in the PLplot 5.80 source download, the file is plplot-5.8.0/examples/c++/wxPLplotDemo.cpp.
Both of these demos run under wxWidgets-2.6.
One more thing: PLplot requires the ttf-freefont package.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.