1

Estoy realizando un programa en C++, con wxWidgets y CodeBlocks donde utilizo un wxPanel, al que le agregó elementos como botones, cajas de texto y otros cosas a través de un método público Render() que esta dentro de la clase de la misma ventana. EL asunto es que cuando a Render() lo llamo desde el constructor si funciona, pero si lo llamo desde otro método por ejemplo: AddCita() deja de funcionar. A continuacion les dejare el codigo del .h y el .cpp

Inicio.h

#ifndef INICIO_H_INCLUDED
#define INICIO_H_INCLUDED
#include "wx/wx.h"
#include <wx/datectrl.h>
#include <wx/timectrl.h>
#define LST 200
#include "Citas.h"
#include "Paciente.h"
#include <sstream>
#include <iostream>
using namespace std;

class Inicio : public wxFrame
{
    private:
        wxPanel *panel;
        wxMenuBar *menubar;
        wxMenu *file;
        wxMenu *edit;
        wxMenu *help;
        wxMessageDialog *dlg;
        Citas *ListCitas[LST];
        Paciente *ListPacientes[LST];
        int contCitas;
        int contPacientes;
        ///Formulario de añadir pacientes
        wxTextCtrl *nombres;
        wxTextCtrl *apellidos;
        wxDatePickerCtrl *fechaNacimiento;
        wxRadioButton *masculino;
        wxRadioButton *femenino;
        wxTextCtrl *peso;
        wxTextCtrl *altura;
        wxCheckBox *cardiaco;
        wxCheckBox *diabetes;
        wxTextCtrl *observaciones;
    public:
        Inicio(const wxString &titulo);
        void OnQuit(wxCommandEvent &event);
        void AddCita(wxCommandEvent &event);
        void AddPaciente(wxCommandEvent &event);
        void writePaciente(wxCommandEvent &event);
        void Logout(wxCommandEvent &event);
        void GetHelp(wxCommandEvent &event);
        string getString(wxString);
        float getFloat(wxString);
        void Render(int);
        void Limpiar();
        DECLARE_EVENT_TABLE()
};

enum
{
    btnAddPacienteEvent = wxID_HIGHEST + 1
};

#endif // INICIO_H_INCLUDED

Inicio.cpp

#include "Inicio.h"
#include "Login.h"
#include "BaseDatos.h"

Inicio::Inicio(const wxString &titulo) : wxFrame(NULL, wxID_ANY, titulo)
{
    contCitas = 0;
    contPacientes = 0;

    menubar = new wxMenuBar;
    file = new wxMenu;
    file->Append(wxID_SAVE, wxT("&Guardar datos"));
    file->Append(wxID_EXIT, wxT("&Salir"));
    edit = new wxMenu;
    edit->Append(wxID_ADD, wxT("&Agregar cita"));
    edit->Append(wxID_OPEN, wxT("&Agregar paciente"));
    help = new wxMenu;
    help->Append(wxID_HELP, wxT("&Manual en linea"));

    wxBitmap exit(wxT("assets/exit.png"), wxBITMAP_TYPE_PNG);
    wxBitmap settings(wxT("assets/settings.png"), wxBITMAP_TYPE_PNG);
    wxBitmap add(wxT("assets/add.png"), wxBITMAP_TYPE_PNG);
    wxBitmap paciente(wxT("assets/addPerson.png"), wxBITMAP_TYPE_PNG);
    wxBitmap Listpacientes(wxT("assets/listPacientes.png"), wxBITMAP_TYPE_PNG);
    wxToolBar *toolbar = CreateToolBar();
    toolbar->SetBackgroundColour(wxColour(64, 182, 192));
    toolbar->AddTool(wxID_ADD, wxT("Añadir cita"), add);
    toolbar->AddTool(wxID_OPEN, wxT("Añadir paciente"), paciente);
     toolbar->AddTool(wxID_OPEN, wxT("Lista de pacientes"), Listpacientes);
    toolbar->AddTool(wxID_ADD, wxT("Configuración"), settings);
    toolbar->AddTool(wxID_CLOSE, wxT("Cerrar Sesion"), exit);
    toolbar->Realize();

    menubar->Append(file, wxT("&Archivo"));
    menubar->Append(edit, wxT("&Editar"));
    menubar->Append(help, wxT("&Ayuda"));
    SetMenuBar(menubar);

    this->Render(1);

    Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(Inicio::OnQuit));
    Connect(wxID_OPEN, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(Inicio::AddPaciente));
    Connect(wxID_CLOSE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(Inicio::Logout));
    Connect(wxID_HELP, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(Inicio::GetHelp));
    Connect(wxID_ADD, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(Inicio::AddCita));
}

void Inicio::OnQuit(wxCommandEvent &WXUNUSED(event)) {
    Close(true);
}
void Inicio::AddCita(wxCommandEvent &WXUNUSED(event)) {
    this->Render(1);
}
void Inicio::AddPaciente(wxCommandEvent &WXUNUSED(event)) {
    this->Render(1);
}
void Inicio::Logout(wxCommandEvent &WXUNUSED(event)) {
    ///Cerrar sesion
    this->Show(false);
    BaseDatos *system = new BaseDatos("sesion");
    system->writeBD("0");
    Login *p;
    p = new Login("Iniciar sesión en NoteMedic");
    p->SetBackgroundColour(wxColour(255,255,255));
    p->SetIcon(wxIcon(wxT("assets/logo.png")));
    p->SetSize(640, 400);
    p->Center();
    p->Show(true);
}
void Inicio::GetHelp(wxCommandEvent &WXUNUSED(event)) {
    system("start www.google.com");
}
void Inicio::Render(int menu) {
    this->panel = new wxPanel(this, wxID_ANY);
    this->panel->SetBackgroundColour(wxColour(*wxWHITE));

    ///Motor de renderizado
    switch(menu) {
        case 0:
        {

            ///Renderizar citas
            break;
        }
        case 1:
        {
            ///Añadir paciente
            wxStaticText *indicacion1 = new wxStaticText(this->panel, wxID_ANY, wxT("Nombres:"), wxPoint(20, 20));
            nombres = new wxTextCtrl(this->panel, wxID_ANY, wxT(""),
          wxPoint(100, 17));
            nombres->SetSize(200, 25);
            wxStaticText *indicacion2 = new wxStaticText(this->panel, wxID_ANY, wxT("Apellidos:"),
          wxPoint(320, 20));
            apellidos = new wxTextCtrl(this->panel, wxID_ANY, wxT(""),
          wxPoint(402, 17));
            apellidos->SetSize(200, 25);
            wxStaticText *indicacion3 = new wxStaticText(this->panel, wxID_ANY, wxT("Fecha de nacimiento:"),
          wxPoint(20, 57));
            fechaNacimiento = new wxDatePickerCtrl(this->panel, wxID_ANY, wxDateTime(), wxPoint(165, 54));
            wxStaticText *indicacion4 = new wxStaticText(this->panel, wxID_ANY, wxT("Genero:"),
          wxPoint(320, 57));
            masculino = new wxRadioButton(this->panel, wxID_ANY, wxT("Masculino"),
          wxPoint(380, 54));
            femenino = new wxRadioButton(this->panel, wxID_ANY, wxT("Femenino"),
          wxPoint(480, 54));
            wxStaticText *indicacion5 = new wxStaticText(this->panel, wxID_ANY, wxT("Peso:"),
          wxPoint(20, 94));
            peso = new wxTextCtrl(this->panel, wxID_ANY, wxT(""),
          wxPoint(65, 91));
            peso->SetSize(36, 25);
            wxStaticText *kg = new wxStaticText(this->panel, wxID_ANY, wxT("kg"), wxPoint(104, 94));
            wxStaticText *indicacion6 = new wxStaticText(this->panel, wxID_ANY, wxT("Altura:"),
          wxPoint(164, 94));
            altura = new wxTextCtrl(this->panel, wxID_ANY, wxT(""),
          wxPoint(220, 91));
            altura->SetSize(36, 25);
            wxStaticText *cm = new wxStaticText(this->panel, wxID_ANY, wxT("cm"),
          wxPoint(259, 94));
            cardiaco = new wxCheckBox(this->panel, wxID_ANY, wxT("Cardiaco"),
          wxPoint(320, 91));
            diabetes = new wxCheckBox(this->panel, wxID_ANY, wxT("Diabetes"),
          wxPoint(460, 91));
            wxStaticText *indicacion7 = new wxStaticText(this->panel, wxID_ANY, wxT("Observaciones:"),
          wxPoint(20, 131));
            observaciones = new wxTextCtrl(this->panel, wxID_ANY, wxT(""),
          wxPoint(20, 150));
            observaciones->SetSize(582, 100);
            observaciones->SetDefaultStyle(wxTextAttr(wxTE_MULTILINE));
            wxButton *agregar = new wxButton(this->panel, btnAddPacienteEvent, wxT("Guardar expediente"),
          wxPoint(458, 260));
            break;
        }
        case 2:
        {
            ///Añadir cita
            wxStaticText *indicacion8 = new wxStaticText(this->panel, wxID_ANY, wxT("Selecciona un paciente:"),
          wxPoint(20, 20));
            wxComboBox *pacientes = new wxComboBox(this->panel, wxID_ANY, wxT("Elige un paciente"),
          wxPoint(20, 40));
            pacientes->SetSize(582, 25);
            pacientes->Append(wxT("Item"));
            wxStaticText *indicacion9 = new wxStaticText(this->panel, wxID_ANY, wxT("Fecha:"),
          wxPoint(20, 80));
            wxDatePickerCtrl *fecha = new wxDatePickerCtrl(this->panel, wxID_ANY, wxDateTime(), wxPoint(70, 74));
            wxStaticText *indicacion10 = new wxStaticText(this->panel, wxID_ANY, wxT("Hora:"),
          wxPoint(220, 80));
            wxTimePickerCtrl *hora = new wxTimePickerCtrl(this->panel, wxID_ANY, wxDateTime(), wxPoint(263, 77));
            wxStaticText *indicacion11 = new wxStaticText(this->panel, wxID_ANY, wxT("Descripcion:"),
          wxPoint(20, 117));
            wxTextCtrl *texto = new wxTextCtrl(this->panel, wxID_ANY, wxT(""),
          wxPoint(20, 136));
            texto->SetSize(582, 100);
            texto->SetDefaultStyle(wxTextAttr(wxTE_MULTILINE));
            wxButton *agregar = new wxButton(this->panel, wxID_ANY, wxT("Guardar cita"),
          wxPoint(507, 245));
            break;
        }
        case 3:
        {
            ///Listar pacientes

            break;
        }
    }
}
void Inicio::writePaciente(wxCommandEvent& WXUNUSED(event)) {
    if(this->contPacientes < 200) {
        ///Obtener datos
        string nombresT = this->getString(this->nombres->GetValue());
        string apellidosT = this->getString(this->apellidos->GetValue());
        wxDateTime fechaNacimientoT = this->fechaNacimiento->GetValue();
        bool masculinoT = this->masculino->GetValue();
        float pesoT = this->getFloat(this->peso->GetValue());
        float alturaT = this->getFloat(this->altura->GetValue());
        bool cardiacoT = this->cardiaco->GetValue();
        bool diabetesT = this->diabetes->GetValue();
        string observacionesT = this->getString(this->observaciones->GetValue());
        if (nombresT == "" || apellidosT == "" || pesoT == 0 || alturaT == 0) {
            wxMessageBox(wxT("Faltan datos para agregar al expediente"), wxT("Alerta"), wxICON_WARNING);
        } else {
            ///Añadir a RAM
            ListPacientes[contPacientes] = new Paciente((contPacientes + 1), pesoT, alturaT, cardiacoT, diabetesT, observacionesT);
            contPacientes++;
            wxMessageBox(wxT("Paciente agregado al expediente"),     wxT("Aviso"), wxICON_INFORMATION);
        }
    } else {
        wxMessageBox(wxT("Memoria llena"), wxT("Alerta"), wxICON_WARNING);
    }
}
    string Inicio::getString(wxString texto) {
    string temporal = string(texto.mb_str());
    return temporal;
}
    float Inicio::getFloat(wxString texto) {
    string temporal = string(texto.mb_str());
    stringstream convert(temporal);
    float x;
    convert >> x;
    return x;
}

BEGIN_EVENT_TABLE (Inicio, wxFrame)
  EVT_BUTTON (btnAddPacienteEvent, Inicio::writePaciente)
END_EVENT_TABLE()

Cambiando los valores a la funcion Render() desde el constructor me funciona todo el contenido del switch sin ningun problema. Pero si llamo a la funcion Render() desde otra funcion como por ejemplo AddPaciente() y AddCita() en tiempo de ejecucion, simplemente no hace nada. Soy novato en C++

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.