]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMBlackBoxHelpDialog.cpp
6502b223c75a8983994ed6e1bf1ebf7b1703e34e
[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);
91 //new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY);
92
93 //EED 2023-10-23
94 //v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5);
95   v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL , 5);
96
97   wxStaticText* instruction = new wxStaticText(
98       this,
99       wxID_ANY,
100       crea::std2wx(
101           "Black boxes are made to work in a modular fashion. They have programmer defined inputs and outputs. Their "
102           "purpose is to use the functions available in the libraries and expose them to be used as boxes in the crea "
103           "environment.\n"
104           "Black boxes are stored in the src folder of a package and they are composed of two files, the header(.h) "
105           "and the implementation(.cxx) files.\n"
106           "To start developing black boxes, go ahead and open the header file with the button \"Open .h\" and define "
107           "the inputs and outputs of the black box. Then, you will be able to use them in the implementation file, which "
108           "you can open using the \"Open .cxx\" button.\n"
109           "If you don't understand how this inputs and outputs are used, try looking at the sample black boxes available "
110           "in the sample package, which is shipped with every new project.\n"
111           "Also, don't forget to include the libraries your boxes use in the header and implementation files. They should "
112           "also be pointed and included in the package's directory CMakeLists.txt file by uncommenting the \"SET\" commands "
113           "for third party libraries or by including the library name inside the \"SET(${BBTK_PACKAGE_NAME}_LIBS\"command "
114           "and its path inside the \"SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS\" command for custom libraries. You must also "
115           "include the package your black box is in by including the command \"ADD_SUBDIRECTORY([packageName])\" in the "
116           "project's directory CMakeLists.txt file. Again, please take a look at the sample package and its boxes to see "
117           "how to include libraries in order to use them in the boxes.\n"
118           "\n"
119           "You can easily edit the CMakeLists files previously mentioned by clicking on the following buttons."),
120           wxDefaultPosition,
121           wxDefaultSize,
122           wxALIGN_LEFT
123   );
124   v_sizer1->Add(instruction, 0,wxEXPAND | wxALL, 5);
125
126   wxButton* editCMakePkgBtn = new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, wxT("Open Package's directory CMakeLists file"));
127   editCMakePkgBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsEnter,NULL,this);
128   editCMakePkgBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsExit,NULL,this);
129   wxButton* editCMakePrjBtn= new wxButton(this, ID_BUTTON_OPENPROJECT, wxT("Open Project's directory CMakeLists file"));
130   editCMakePrjBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsEnter,NULL,this);
131   editCMakePrjBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxHelpDialog::OnCMakeListsExit,NULL,this);
132
133   v_sizer1->Add(editCMakePkgBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
134   v_sizer1->Add(editCMakePrjBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
135
136   v_sizer1->Add(new wxCheckBox(this, ID_CHECKBOX_DISABLE_HELP, wxT("&Disable help")), 0, wxALIGN_RIGHT | wxRIGHT, 10);
137
138 //EED 2023-10-23
139 //  v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Close")), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30);
140   v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Close")), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM , 30);
141
142   SetSizer(v_sizer1);
143   //v_sizer1->RecalcSizes();
144 }
145
146 void wxCDMBlackBoxHelpDialog::OnFinish(wxCommandEvent& event)
147 {
148   this->EndDialog(wxID_CANCEL);
149 }
150
151 void wxCDMBlackBoxHelpDialog::OnCMakeLists(wxCommandEvent& event)
152 {
153   std::string* result;
154
155   if((int)((wxButton*)event.GetEventObject())->GetId() == (int)ID_BUTTON_EDIT_CMAKELISTSFILE)
156     {
157       modelCDMIProjectTreeNode* node = this->blackBox;
158       while (node != NULL && dynamic_cast<modelCDMPackage*>(node) == NULL)
159         {
160           node = node->GetParent();
161         }
162       if (node != NULL)
163         {
164           if(!((modelCDMPackage*)node)->OpenCMakeListsFile(result))
165             wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
166
167           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
168
169           if(((modelCDMPackage*)node)->GetCMakeLists() != NULL)
170             {
171               newEvent->SetClientData(((modelCDMPackage*)node)->GetCMakeLists());
172               newEvent->SetId(0);
173               wxPostEvent(this->GetParent(), *newEvent);
174             }
175         }
176       else
177         {
178           wxMessageBox(crea::std2wx("No project CMakeLists file was found."),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
179         }
180     }
181   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
182     {
183       modelCDMIProjectTreeNode* node = this->blackBox;
184       while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
185         {
186           node = node->GetParent();
187         }
188       if (node != NULL)
189         {
190           if(!((modelCDMProject*)node)->OpenCMakeListsFile(result))
191             wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
192
193           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
194
195           if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
196             {
197               newEvent->SetClientData(((modelCDMProject*)node)->GetCMakeLists());
198               newEvent->SetId(0);
199               wxPostEvent(this->GetParent(), *newEvent);
200             }
201         }
202       else
203         {
204           wxMessageBox(crea::std2wx("No project CMakeLists file was found."),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
205         }
206     }
207 }
208
209 void wxCDMBlackBoxHelpDialog::OnCMakeListsEnter(wxMouseEvent& event)
210 {
211   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
212     {
213       modelCDMIProjectTreeNode* node = this->blackBox;
214       while (node != NULL && dynamic_cast<modelCDMPackage*>(node) == NULL)
215         {
216           node = node->GetParent();
217         }
218       if (node != NULL)
219         {
220           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
221
222           if(((modelCDMPackage*)node)->GetCMakeLists() != NULL)
223             {
224               newEvent->SetClientData(((modelCDMPackage*)node)->GetCMakeLists());
225               newEvent->SetId(0);
226               wxPostEvent(this->GetParent(), *newEvent);
227             }
228         }
229     }
230   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
231     {
232       modelCDMIProjectTreeNode* node = this->blackBox;
233       while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
234         {
235           node = node->GetParent();
236         }
237       if (node != NULL)
238         {
239           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
240
241           if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
242             {
243               newEvent->SetClientData(((modelCDMProject*)node)->GetCMakeLists());
244               newEvent->SetId(0);
245               wxPostEvent(this->GetParent(), *newEvent);
246             }
247         }
248     }
249   event.Skip();
250 }
251
252 void wxCDMBlackBoxHelpDialog::OnCMakeListsExit(wxMouseEvent& event)
253 {
254   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
255       {
256         modelCDMIProjectTreeNode* node = this->blackBox;
257         while (node != NULL && dynamic_cast<modelCDMPackage*>(node) == NULL)
258           {
259             node = node->GetParent();
260           }
261         if (node != NULL)
262           {
263             wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
264
265             if(((modelCDMPackage*)node)->GetCMakeLists() != NULL)
266               {
267                 newEvent->SetClientData(((modelCDMPackage*)node)->GetCMakeLists());
268                 newEvent->SetId(0);
269                 wxPostEvent(this->GetParent(), *newEvent);
270               }
271           }
272       }
273     else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
274       {
275         modelCDMIProjectTreeNode* node = this->blackBox;
276         while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
277           {
278             node = node->GetParent();
279           }
280         if (node != NULL)
281           {
282             wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
283
284             if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
285               {
286                 newEvent->SetClientData(((modelCDMProject*)node)->GetCMakeLists());
287                 newEvent->SetId(0);
288                 wxPostEvent(this->GetParent(), *newEvent);
289               }
290           }
291       }
292     event.Skip();
293 }
294
295 void wxCDMBlackBoxHelpDialog::OnDisableHelp(wxCommandEvent& event)
296 {
297   wxPostEvent(this->GetParent(), event);
298 }