]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMLibraryHelpDialog.cpp
Fixes:
[crea.git] / lib / creaDevManagerLib / wxCDMLibraryHelpDialog.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  * wxCDMLibraryHelpDialog.cpp
31  *
32  *  Created on: 11/1/2013
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "wxCDMLibraryHelpDialog.h"
37
38 #include "creaDevManagerIds.h"
39
40 #include "modelCDMLib.h"
41
42 BEGIN_EVENT_TABLE(wxCDMLibraryHelpDialog, wxDialog)
43 EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMLibraryHelpDialog::OnFinish)
44 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMLibraryHelpDialog::OnCMakeLists)
45 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibraryHelpDialog::OnCMakeLists)
46 EVT_CHECKBOX(ID_CHECKBOX_DISABLE_HELP, wxCDMLibraryHelpDialog::OnDisableHelp)
47 END_EVENT_TABLE()
48
49 wxCDMLibraryHelpDialog::wxCDMLibraryHelpDialog(
50     wxWindow* parent,
51     modelCDMLibrary* library,
52     wxWindowID id,
53     const wxString& caption,
54     const wxPoint& position,
55     const wxSize& size,
56     long style
57 )
58 {
59   wxCDMLibraryHelpDialog::Create(parent, id, caption, position, size, style);
60   this->library = library;
61 }
62
63 wxCDMLibraryHelpDialog::~wxCDMLibraryHelpDialog()
64 {
65 }
66
67 bool wxCDMLibraryHelpDialog::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 wxCDMLibraryHelpDialog::CreateControls()
84 {
85
86   wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
87
88
89   wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Working with Libraries"), 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           "Libraries are made to expose the projects' main functionalities to the applications and black boxes of the project. "
97           "The functions and classes available in the libraries are the core of any project, thus they should implement important "
98           "tasks such as image processing algorithms or point cloud processing algorithms."
99           "Libraries are stored in the project's lib folder and each library has its own dedicated folder. Inside these folders "
100           "each library has its classes.\n"
101           "\n"
102           "To start developing a library, go ahead and create a new class with the button \"Create Class\" and implement the main "
103           "functionalities of your project inside the created files.\n"
104           "If you need to separate classes in folders you can do it by creating a folder with the \"Create Folder\" button.\n"
105           "Then, in order to include your libraries in the project correctly you must include them in the lib's folder "
106           "\"CMakeLists.txt\" file by using the \"ADD_SUBDIRECTORY([libraryName])\". Also, if you use third party libraries in your "
107           "library you must include them in the library's \"CMakeLists.txt\" file by uncommenting them in the "
108           "\"SET ( ${LIBRARY_NAME}_LINK_LIBRARIES\" command; if you use custom libraries in your library you must also include them "
109           "in the library's \"CMakeLists.txt\" file by including them in the \"SET ( ${LIBRARY_NAME}_LINK_LIBRARIES\" command. Or, "
110           "if you create additional folders in your library you must include them in the library's \"CMakeLists.txt\" file by using "
111           "the \"ADD_SUBDIRECTORY([folderName])\" command.\n"
112           "\n"
113           "You can easily edit the CMakeLists files previously mentioned by clicking on the following buttons."),
114           wxDefaultPosition,
115           wxDefaultSize,
116           wxALIGN_LEFT
117   );
118   v_sizer1->Add(instruction, 0,wxEXPAND | wxALL, 5);
119
120   wxButton* editCMakeLibraryBtn = new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, wxT("Open Library's directory CMakeLists file"));
121   editCMakeLibraryBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryHelpDialog::OnCMakeListsEnter,NULL,this);
122   editCMakeLibraryBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryHelpDialog::OnCMakeListsExit,NULL,this);
123   wxButton* editCMakeLibBtn= new wxButton(this, ID_BUTTON_OPENPROJECT, wxT("Open Lib's directory CMakeLists file"));
124   editCMakeLibBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryHelpDialog::OnCMakeListsEnter,NULL,this);
125   editCMakeLibBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryHelpDialog::OnCMakeListsExit,NULL,this);
126
127   v_sizer1->Add(editCMakeLibraryBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
128   v_sizer1->Add(editCMakeLibBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
129
130   v_sizer1->Add(new wxCheckBox(this, ID_CHECKBOX_DISABLE_HELP, wxT("&Disable help")), 0, wxALIGN_RIGHT | wxRIGHT, 10);
131
132   v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Close")), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30);
133
134   SetSizer(v_sizer1);
135   //v_sizer1->RecalcSizes();
136 }
137
138 void wxCDMLibraryHelpDialog::OnFinish(wxCommandEvent& event)
139 {
140   this->EndDialog(wxID_CANCEL);
141 }
142
143 void wxCDMLibraryHelpDialog::OnCMakeLists(wxCommandEvent& event)
144 {
145   std::string* result;
146
147   if((int)((wxButton*)event.GetEventObject())->GetId() == (int)ID_BUTTON_EDIT_CMAKELISTSFILE)
148     {
149
150       if(!this->library->OpenCMakeListsFile(result))
151         wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
152
153       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
154
155       if(this->library->GetCMakeLists() != NULL)
156         {
157           newEvent->SetClientData(this->library->GetCMakeLists());
158           newEvent->SetId(0);
159           wxPostEvent(this->GetParent(), *newEvent);
160         }
161     }
162   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
163     {
164       modelCDMIProjectTreeNode* node = this->library;
165       while (node != NULL && dynamic_cast<modelCDMLib*>(node) == NULL)
166         {
167           node = node->GetParent();
168         }
169       if (node != NULL)
170         {
171           if(!((modelCDMLib*)node)->OpenCMakeListsFile(result))
172             wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
173
174           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
175
176           if(((modelCDMLib*)node)->GetCMakeLists() != NULL)
177             {
178               newEvent->SetClientData(((modelCDMLib*)node)->GetCMakeLists());
179               newEvent->SetId(0);
180               wxPostEvent(this->GetParent(), *newEvent);
181             }
182         }
183       else
184         {
185           wxMessageBox(crea::std2wx("No project CMakeLists file was found."),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
186         }
187     }
188 }
189
190 void wxCDMLibraryHelpDialog::OnCMakeListsEnter(wxMouseEvent& event)
191 {
192   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
193     {
194       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
195
196       if(this->library->GetCMakeLists() != NULL)
197         {
198           newEvent->SetClientData(this->library->GetCMakeLists());
199           newEvent->SetId(0);
200           wxPostEvent(this->GetParent(), *newEvent);
201         }
202     }
203   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
204     {
205       modelCDMIProjectTreeNode* node = this->library;
206       while (node != NULL && dynamic_cast<modelCDMLib*>(node) == NULL)
207         {
208           node = node->GetParent();
209         }
210       if (node != NULL)
211         {
212           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
213
214           if(((modelCDMLib*)node)->GetCMakeLists() != NULL)
215             {
216               newEvent->SetClientData(((modelCDMLib*)node)->GetCMakeLists());
217               newEvent->SetId(0);
218               wxPostEvent(this->GetParent(), *newEvent);
219             }
220         }
221     }
222   event.Skip();
223 }
224
225 void wxCDMLibraryHelpDialog::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->library->GetCMakeLists() != NULL)
232           {
233             newEvent->SetClientData(this->library->GetCMakeLists());
234             newEvent->SetId(0);
235             wxPostEvent(this->GetParent(), *newEvent);
236           }
237       }
238     else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
239       {
240         modelCDMIProjectTreeNode* node = this->library;
241         while (node != NULL && dynamic_cast<modelCDMLib*>(node) == NULL)
242           {
243             node = node->GetParent();
244           }
245         if (node != NULL)
246           {
247             wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
248
249             if(((modelCDMLib*)node)->GetCMakeLists() != NULL)
250               {
251                 newEvent->SetClientData(((modelCDMLib*)node)->GetCMakeLists());
252                 newEvent->SetId(0);
253                 wxPostEvent(this->GetParent(), *newEvent);
254               }
255           }
256       }
257     event.Skip();
258 }
259
260 void wxCDMLibraryHelpDialog::OnDisableHelp(wxCommandEvent& event)
261 {
262   wxPostEvent(this->GetParent(), event);
263 }