]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMApplicationHelpDialog.cpp
8601b02c5b1348bdf343ad53e5532e815feb5af1
[crea.git] / lib / creaDevManagerLib / wxCDMApplicationHelpDialog.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ 
26  */
27
28
29 /*
30  * wxCDMApplicationHelpDialog.cpp
31  *
32  *  Created on: 11/1/2013
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "wxCDMApplicationHelpDialog.h"
37
38 #include "creaDevManagerIds.h"
39
40 #include "modelCDMAppli.h"
41
42 BEGIN_EVENT_TABLE(wxCDMApplicationHelpDialog, wxDialog)
43 EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMApplicationHelpDialog::OnFinish)
44 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMApplicationHelpDialog::OnCMakeLists)
45 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMApplicationHelpDialog::OnCMakeLists)
46 EVT_CHECKBOX(ID_CHECKBOX_DISABLE_HELP, wxCDMApplicationHelpDialog::OnDisableHelp)
47 END_EVENT_TABLE()
48
49 wxCDMApplicationHelpDialog::wxCDMApplicationHelpDialog(
50     wxWindow* parent,
51     modelCDMApplication* application,
52     wxWindowID id,
53     const wxString& caption,
54     const wxPoint& position,
55     const wxSize& size,
56     long style
57 )
58 {
59   wxCDMApplicationHelpDialog::Create(parent, id, caption, position, size, style);
60   this->application = application;
61 }
62
63 wxCDMApplicationHelpDialog::~wxCDMApplicationHelpDialog()
64 {
65 }
66
67 bool wxCDMApplicationHelpDialog::Create(
68     wxWindow* parent,
69     wxWindowID id,
70     const wxString& caption,
71     const wxPoint& position,
72     const wxSize& size,
73     long int style
74 )
75 {
76   wxDialog::Create(parent, id, caption, position, size, style);
77
78   this->CreateControls();
79
80   return TRUE;
81 }
82
83 void wxCDMApplicationHelpDialog::CreateControls()
84 {
85
86   wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
87
88
89   wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Working with Applications"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY);
90   v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5);
91
92   wxStaticText* instruction = new wxStaticText(
93       this,
94       wxID_ANY,
95       crea::std2wx(
96           "Applications are stand alone programs that use the projects' core functionality (libraries' functions). These "
97           "applications are useful when showing the projects' \"out of the box\" functionalities.\n"
98           "Applications are stored in the project's appli folder and each application has its own dedicated folder. Inside "
99           "these folders each application has its main file.\n"
100           "\n"
101           "To start developing an application, go ahead and open the application main file with the button \"Open Main File\" "
102           "and implement the application's functionality.\n"
103           "If you need to create separate classes in the application folder, or inside an specific folders you can do it by "
104           "creating a new class with the \"Create Class\" button or by creating a folder with the \"Create Folder\" button.\n"
105           "Then, in order to include your applications in the project correctly you must include them in the appli's folder "
106           "\"CMakeLists.txt\" file. Also, if you create additional folders in your library you should include them in the application's "
107           "\"CMakeLists.txt\" file.\n"
108           "\n"
109           "You can easily edit the CMakeLists files previously mentioned by clicking on the following buttons."),
110           wxDefaultPosition,
111           wxDefaultSize,
112           wxALIGN_LEFT
113   );
114   v_sizer1->Add(instruction, 0,wxEXPAND | wxALL, 5);
115
116   wxButton* editCMakeApplicationBtn = new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, wxT("Open Application's directory CMakeLists file"));
117   editCMakeApplicationBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationHelpDialog::OnCMakeListsEnter,NULL,this);
118   editCMakeApplicationBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationHelpDialog::OnCMakeListsExit,NULL,this);
119   wxButton* editCMakeAppliBtn= new wxButton(this, ID_BUTTON_OPENPROJECT, wxT("Open Appli's directory CMakeLists file"));
120   editCMakeAppliBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationHelpDialog::OnCMakeListsEnter,NULL,this);
121   editCMakeAppliBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationHelpDialog::OnCMakeListsExit,NULL,this);
122
123   v_sizer1->Add(editCMakeApplicationBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
124   v_sizer1->Add(editCMakeAppliBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
125
126   v_sizer1->Add(new wxCheckBox(this, ID_CHECKBOX_DISABLE_HELP, wxT("&Disable help")), 0, wxALIGN_RIGHT | wxRIGHT, 10);
127
128   v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Close")), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30);
129
130   SetSizer(v_sizer1);
131   //v_sizer1->RecalcSizes();
132 }
133
134 void wxCDMApplicationHelpDialog::OnFinish(wxCommandEvent& event)
135 {
136   this->EndDialog(wxID_CANCEL);
137 }
138
139 void wxCDMApplicationHelpDialog::OnCMakeLists(wxCommandEvent& event)
140 {
141   std::string* result;
142
143   if((int)((wxButton*)event.GetEventObject())->GetId() == (int)ID_BUTTON_EDIT_CMAKELISTSFILE)
144     {
145
146       if(!this->application->OpenCMakeListsFile(result))
147         wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
148
149       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
150
151       if(this->application->GetCMakeLists() != NULL)
152         {
153           int CMId = this->application->GetCMakeLists()->GetId();
154           newEvent->SetInt(CMId);
155           newEvent->SetId(0);
156           wxPostEvent(this->GetParent(), *newEvent);
157         }
158     }
159   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
160     {
161       modelCDMIProjectTreeNode* node = this->application;
162       while (node != NULL && dynamic_cast<modelCDMAppli*>(node) == NULL)
163         {
164           node = node->GetParent();
165         }
166       if (node != NULL)
167         {
168           if(!((modelCDMAppli*)node)->OpenCMakeListsFile(result))
169             wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
170
171           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
172
173           if(((modelCDMAppli*)node)->GetCMakeLists() != NULL)
174             {
175               int CMId = ((modelCDMAppli*)node)->GetCMakeLists()->GetId();
176               newEvent->SetInt(CMId);
177               newEvent->SetId(0);
178               wxPostEvent(this->GetParent(), *newEvent);
179             }
180         }
181       else
182         {
183           wxMessageBox(crea::std2wx("No project CMakeLists file was found."),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
184         }
185     }
186 }
187
188 void wxCDMApplicationHelpDialog::OnCMakeListsEnter(wxMouseEvent& event)
189 {
190   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
191     {
192       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
193
194       if(this->application->GetCMakeLists() != NULL)
195         {
196           int CMId = this->application->GetCMakeLists()->GetId();
197           newEvent->SetInt(CMId);
198           newEvent->SetId(0);
199           wxPostEvent(this->GetParent(), *newEvent);
200         }
201     }
202   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
203     {
204       modelCDMIProjectTreeNode* node = this->application;
205       while (node != NULL && dynamic_cast<modelCDMAppli*>(node) == NULL)
206         {
207           node = node->GetParent();
208         }
209       if (node != NULL)
210         {
211           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
212
213           if(((modelCDMAppli*)node)->GetCMakeLists() != NULL)
214             {
215               int CMId = ((modelCDMAppli*)node)->GetCMakeLists()->GetId();
216               newEvent->SetInt(CMId);
217               newEvent->SetId(0);
218               wxPostEvent(this->GetParent(), *newEvent);
219             }
220         }
221     }
222   event.Skip();
223 }
224
225 void wxCDMApplicationHelpDialog::OnCMakeListsExit(wxMouseEvent& event)
226 {
227   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
228     {
229       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
230
231       if(this->application->GetCMakeLists() != NULL)
232         {
233           int CMId = this->application->GetCMakeLists()->GetId();
234           newEvent->SetInt(CMId);
235           newEvent->SetId(0);
236           wxPostEvent(this->GetParent(), *newEvent);
237         }
238     }
239   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
240     {
241       modelCDMIProjectTreeNode* node = this->application;
242       while (node != NULL && dynamic_cast<modelCDMAppli*>(node) == NULL)
243         {
244           node = node->GetParent();
245         }
246       if (node != NULL)
247         {
248           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
249
250           if(((modelCDMAppli*)node)->GetCMakeLists() != NULL)
251             {
252               int CMId = ((modelCDMAppli*)node)->GetCMakeLists()->GetId();
253               newEvent->SetInt(CMId);
254               newEvent->SetId(0);
255               wxPostEvent(this->GetParent(), *newEvent);
256             }
257         }
258     }
259   event.Skip();
260 }
261
262 void wxCDMApplicationHelpDialog::OnDisableHelp(wxCommandEvent& event)
263 {
264   wxPostEvent(this->GetParent(), event);
265 }