]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMBlackBoxHelpDialog.cpp
e08ba65ae9e1b20b2da116d454ed3c36900e1312
[crea.git] / lib / creaDevManagerLib / wxCDMBlackBoxHelpDialog.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  * wxCDMBlackBoxHelpDialog.cpp
31  *
32  *  Created on: 11/1/2013
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "wxCDMBlackBoxHelpDialog.h"
37
38 #include "creaDevManagerIds.h"
39
40 #include "modelCDMProject.h"
41 #include "modelCDMPackage.h"
42
43 BEGIN_EVENT_TABLE(wxCDMBlackBoxHelpDialog, wxDialog)
44 EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMBlackBoxHelpDialog::OnFinish)
45 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMBlackBoxHelpDialog::OnCMakeLists)
46 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMBlackBoxHelpDialog::OnCMakeLists)
47 EVT_CHECKBOX(ID_CHECKBOX_DISABLE_HELP, wxCDMBlackBoxHelpDialog::OnDisableHelp)
48 END_EVENT_TABLE()
49
50 wxCDMBlackBoxHelpDialog::wxCDMBlackBoxHelpDialog(
51     wxWindow* parent,
52     modelCDMBlackBox* blackBox,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& position,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMBlackBoxHelpDialog::Create(parent, id, caption, position, size, style);
61   this->blackBox = blackBox;
62 }
63
64 wxCDMBlackBoxHelpDialog::~wxCDMBlackBoxHelpDialog()
65 {
66 }
67
68 bool wxCDMBlackBoxHelpDialog::Create(
69     wxWindow* parent,
70     wxWindowID id,
71     const wxString& caption,
72     const wxPoint& position,
73     const wxSize& size,
74     long int style
75 )
76 {
77   wxDialog::Create(parent, id, caption, position, size, style);
78
79   this->CreateControls();
80
81   return TRUE;
82 }
83
84 void wxCDMBlackBoxHelpDialog::CreateControls()
85 {
86
87   wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
88
89
90   wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Working with BlackBoxes"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY);
91   v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5);
92
93   wxStaticText* instruction = new wxStaticText(
94       this,
95       wxID_ANY,
96       crea::std2wx(
97           "Black boxes are made to work in a modular fashion. They have programmer defined inputs and outputs. Their "
98           "purpose is to use the functions available in the libraries and expose them to be used as boxes in the crea "
99           "environment.\n"
100           "Black boxes are stored in the src folder of a package and they are composed of two files, the header(.h) "
101           "and the implementation(.cxx) files.\n"
102           "To start developing black boxes, go ahead and open the header file with the button \"Open .h\" and define "
103           "the inputs and outputs of the black box. Then, you will be able to use them in the implementation file, which "
104           "you can open using the \"Open .cxx\" button.\n"
105           "If you don't understand how this inputs and outputs are used, try looking at the sample black boxes available "
106           "in the sample package, which is shipped with every new project.\n"
107           "Also, don't forget to include the libraries your boxes use in the header and implementation files. They should "
108           "also be pointed and included in the package's directory CMakeLists.txt file and the project's directory "
109           "CMakeLists.txt file. Again, please take a look at the sample package and its boxes to see how to include libraries "
110           "in order to use them in the boxes.\n"
111           "\n"
112           "You can easily edit the CMakeLists files previously mentioned by clicking on the following buttons."),
113           wxDefaultPosition,
114           wxDefaultSize,
115           wxALIGN_LEFT
116   );
117   v_sizer1->Add(instruction, 0,wxEXPAND | wxALL, 5);
118
119   wxButton* editCMakePkgBtn = new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, wxT("Open Package's directory CMakeLists file"));
120   editCMakePkgBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsEnter,NULL,this);
121   editCMakePkgBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsExit,NULL,this);
122   wxButton* editCMakePrjBtn= new wxButton(this, ID_BUTTON_OPENPROJECT, wxT("Open Project's directory CMakeLists file"));
123   editCMakePrjBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsEnter,NULL,this);
124   editCMakePrjBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsExit,NULL,this);
125
126   v_sizer1->Add(editCMakePkgBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
127   v_sizer1->Add(editCMakePrjBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
128
129   v_sizer1->Add(new wxCheckBox(this, ID_CHECKBOX_DISABLE_HELP, wxT("&Disable help")), 0, wxALIGN_RIGHT | wxRIGHT, 10);
130
131   v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Close")), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30);
132
133   SetSizer(v_sizer1);
134   //v_sizer1->RecalcSizes();
135 }
136
137 void wxCDMBlackBoxHelpDialog::OnFinish(wxCommandEvent& event)
138 {
139   this->EndDialog(wxID_CANCEL);
140 }
141
142 void wxCDMBlackBoxHelpDialog::OnCMakeLists(wxCommandEvent& event)
143 {
144   std::string* result;
145
146   if((int)((wxButton*)event.GetEventObject())->GetId() == (int)ID_BUTTON_EDIT_CMAKELISTSFILE)
147     {
148       modelCDMIProjectTreeNode* node = this->blackBox;
149       while (node != NULL && dynamic_cast<modelCDMPackage*>(node) == NULL)
150         {
151           node = node->GetParent();
152         }
153       if (node != NULL)
154         {
155           if(!((modelCDMPackage*)node)->OpenCMakeListsFile(result))
156             wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
157
158           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
159
160           if(((modelCDMPackage*)node)->GetCMakeLists() != NULL)
161             {
162               int CMId = ((modelCDMPackage*)node)->GetCMakeLists()->GetId();
163               newEvent->SetInt(CMId);
164               newEvent->SetId(0);
165               wxPostEvent(this->GetParent(), *newEvent);
166             }
167         }
168       else
169         {
170           wxMessageBox(crea::std2wx("No project CMakeLists file was found."),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
171         }
172     }
173   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
174     {
175       modelCDMIProjectTreeNode* node = this->blackBox;
176       while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
177         {
178           node = node->GetParent();
179         }
180       if (node != NULL)
181         {
182           if(!((modelCDMProject*)node)->OpenCMakeListsFile(result))
183             wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
184
185           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
186
187           if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
188             {
189               int CMId = ((modelCDMProject*)node)->GetCMakeLists()->GetId();
190               newEvent->SetInt(CMId);
191               newEvent->SetId(0);
192               wxPostEvent(this->GetParent(), *newEvent);
193             }
194         }
195       else
196         {
197           wxMessageBox(crea::std2wx("No project CMakeLists file was found."),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
198         }
199     }
200 }
201
202 void wxCDMBlackBoxHelpDialog::OnCMakeListsEnter(wxMouseEvent& event)
203 {
204   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
205     {
206       modelCDMIProjectTreeNode* node = this->blackBox;
207       while (node != NULL && dynamic_cast<modelCDMPackage*>(node) == NULL)
208         {
209           node = node->GetParent();
210         }
211       if (node != NULL)
212         {
213           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
214
215           if(((modelCDMPackage*)node)->GetCMakeLists() != NULL)
216             {
217               int CMId = ((modelCDMPackage*)node)->GetCMakeLists()->GetId();
218               newEvent->SetInt(CMId);
219               newEvent->SetId(0);
220               wxPostEvent(this->GetParent(), *newEvent);
221             }
222         }
223     }
224   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
225     {
226       modelCDMIProjectTreeNode* node = this->blackBox;
227       while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
228         {
229           node = node->GetParent();
230         }
231       if (node != NULL)
232         {
233           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
234
235           if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
236             {
237               int CMId = ((modelCDMProject*)node)->GetCMakeLists()->GetId();
238               newEvent->SetInt(CMId);
239               newEvent->SetId(0);
240               wxPostEvent(this->GetParent(), *newEvent);
241             }
242         }
243     }
244   event.Skip();
245 }
246
247 void wxCDMBlackBoxHelpDialog::OnCMakeListsExit(wxMouseEvent& event)
248 {
249   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
250       {
251         modelCDMIProjectTreeNode* node = this->blackBox;
252         while (node != NULL && dynamic_cast<modelCDMPackage*>(node) == NULL)
253           {
254             node = node->GetParent();
255           }
256         if (node != NULL)
257           {
258             wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
259
260             if(((modelCDMPackage*)node)->GetCMakeLists() != NULL)
261               {
262                 int CMId = ((modelCDMPackage*)node)->GetCMakeLists()->GetId();
263                 newEvent->SetInt(CMId);
264                 newEvent->SetId(0);
265                 wxPostEvent(this->GetParent(), *newEvent);
266               }
267           }
268       }
269     else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
270       {
271         modelCDMIProjectTreeNode* node = this->blackBox;
272         while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
273           {
274             node = node->GetParent();
275           }
276         if (node != NULL)
277           {
278             wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
279
280             if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
281               {
282                 int CMId = ((modelCDMProject*)node)->GetCMakeLists()->GetId();
283                 newEvent->SetInt(CMId);
284                 newEvent->SetId(0);
285                 wxPostEvent(this->GetParent(), *newEvent);
286               }
287           }
288       }
289     event.Skip();
290 }
291
292 void wxCDMBlackBoxHelpDialog::OnDisableHelp(wxCommandEvent& event)
293 {
294   wxPostEvent(this->GetParent(), event);
295 }