]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMPackageHelpDialog.cpp
#3180 crea Feature New Normal Future - Set wx-config for wxWidgets 2.8
[crea.git] / lib / creaDevManagerLib / wxCDMPackageHelpDialog.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  * wxCDMPackageHelpDialog.cpp
31  *
32  *  Created on: 9/1/2013
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "wxCDMPackageHelpDialog.h"
37
38 #include "creaDevManagerIds.h"
39
40 #include "modelCDMProject.h"
41
42 BEGIN_EVENT_TABLE(wxCDMPackageHelpDialog, wxDialog)
43 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMPackageHelpDialog::OnCMakeLists)
44 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageHelpDialog::OnCMakeLists)
45 EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMPackageHelpDialog::OnFinish)
46 EVT_CHECKBOX(ID_CHECKBOX_DISABLE_HELP, wxCDMPackageHelpDialog::OnDisableHelp)
47 END_EVENT_TABLE()
48
49 wxCDMPackageHelpDialog::wxCDMPackageHelpDialog(
50     wxWindow* parent,
51     modelCDMPackage* package,
52     wxWindowID id,
53     const wxString& caption,
54     const wxPoint& position,
55     const wxSize& size,
56     long style
57 )
58 {
59   wxCDMPackageHelpDialog::Create(parent, id, caption, position, size, style);
60   this->package = package;
61 }
62
63 wxCDMPackageHelpDialog::~wxCDMPackageHelpDialog()
64 {
65 }
66
67 bool wxCDMPackageHelpDialog::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 wxCDMPackageHelpDialog::CreateControls()
84 {
85
86   wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
87
88
89   wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Working with Packages"), 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           "Packages contain black boxes, which allow to work modularly with other boxes. This boxes can use the functions "
97           "present in your libraries and expose them to work in a BBTK-fashion.\n"
98           "\n"
99           "To create a black box click on the \"Create Black Box\" button.\n"
100           "If you want to check the files in the file explorer click the \"Open Package Folder\" "
101           "button.\n"
102           "\n"
103           "Don't forget to include the libraries your black boxes use in the Package directory CMakeLists.txt file by "
104           "uncommenting the \"SET\" commands for third party libraries or by including the library name inside the "
105           "\"SET(${BBTK_PACKAGE_NAME}_LIBS\"command and its path inside the \"SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS\" "
106           "command for custom libraries.\n"
107           "Also, make sure you include this package in the Project directory's CMakeLists.txt file\n using the "
108           "ADD_SUBDIRECTORY([packageName]) command.\n"
109           "You can open these files with the following buttons."),
110           wxDefaultPosition,
111           wxDefaultSize,
112           wxALIGN_LEFT
113   );
114   v_sizer1->Add(instruction, 0,wxEXPAND | wxALL, 5);
115
116   wxButton* editCMakePkgBtn = new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, wxT("Open Package's directory CMakeLists file"));
117   editCMakePkgBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageHelpDialog::OnCMakeListsEnter,NULL,this);
118   editCMakePkgBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageHelpDialog::OnCMakeListsExit,NULL,this);
119   wxButton* editCMakePrjBtn= new wxButton(this, ID_BUTTON_OPENPROJECT, wxT("Open Project's directory CMakeLists file"));
120   editCMakePrjBtn->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageHelpDialog::OnCMakeListsEnter,NULL,this);
121   editCMakePrjBtn->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageHelpDialog::OnCMakeListsExit,NULL,this);
122
123   v_sizer1->Add(editCMakePkgBtn, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
124   v_sizer1->Add(editCMakePrjBtn, 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 wxCDMPackageHelpDialog::OnCMakeLists(wxCommandEvent& event)
135 {
136   std::string* result;
137
138   if((int)((wxButton*)event.GetEventObject())->GetId() == (int)ID_BUTTON_EDIT_CMAKELISTSFILE)
139     {
140
141       if(!this->package->OpenCMakeListsFile(result))
142         wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
143
144       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
145
146       if(this->package->GetCMakeLists() != NULL)
147         {
148           newEvent->SetClientData(this->package->GetCMakeLists());
149           newEvent->SetId(0);
150           wxPostEvent(this->GetParent(), *newEvent);
151         }
152     }
153   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
154     {
155       modelCDMIProjectTreeNode* node = this->package;
156       while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
157         {
158           node = node->GetParent();
159         }
160       if (node != NULL)
161         {
162           if(!((modelCDMProject*)node)->OpenCMakeListsFile(result))
163             wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
164
165           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
166
167           if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
168             {
169               newEvent->SetClientData(((modelCDMProject*)node)->GetCMakeLists());
170               newEvent->SetId(0);
171               wxPostEvent(this->GetParent(), *newEvent);
172             }
173         }
174       else
175         {
176           wxMessageBox(crea::std2wx("No project CMakeLists file was found."),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
177         }
178     }
179 }
180
181 void wxCDMPackageHelpDialog::OnCMakeListsEnter(wxMouseEvent& event)
182 {
183   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
184     {
185       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
186
187       if(this->package->GetCMakeLists() != NULL)
188         {
189           newEvent->SetClientData(this->package->GetCMakeLists());
190           newEvent->SetId(0);
191           wxPostEvent(this->GetParent(), *newEvent);
192         }
193     }
194   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
195     {
196       modelCDMIProjectTreeNode* node = this->package;
197       while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
198         {
199           node = node->GetParent();
200         }
201       if (node != NULL)
202         {
203           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
204
205           if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
206             {
207               newEvent->SetClientData(((modelCDMProject*)node)->GetCMakeLists());
208               newEvent->SetId(0);
209               wxPostEvent(this->GetParent(), *newEvent);
210             }
211         }
212     }
213   event.Skip();
214 }
215
216 void wxCDMPackageHelpDialog::OnCMakeListsExit(wxMouseEvent& event)
217 {
218   if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_EDIT_CMAKELISTSFILE)
219     {
220       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
221
222       if(this->package->GetCMakeLists() != NULL)
223         {
224           newEvent->SetClientData(this->package->GetCMakeLists());
225           newEvent->SetId(0);
226           wxPostEvent(this->GetParent(), *newEvent);
227         }
228     }
229   else if(((wxButton*)event.GetEventObject())->GetId() == ID_BUTTON_OPENPROJECT)
230     {
231       modelCDMIProjectTreeNode* node = this->package;
232       while (node != NULL && dynamic_cast<modelCDMProject*>(node) == NULL)
233         {
234           node = node->GetParent();
235         }
236       if (node != NULL)
237         {
238           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
239
240           if(((modelCDMProject*)node)->GetCMakeLists() != NULL)
241             {
242               newEvent->SetClientData(((modelCDMProject*)node)->GetCMakeLists());
243               newEvent->SetId(0);
244               wxPostEvent(this->GetParent(), *newEvent);
245             }
246         }
247     }
248   event.Skip();
249 }
250
251 void wxCDMPackageHelpDialog::OnFinish(wxCommandEvent& event)
252 {
253   this->EndDialog(wxID_CANCEL);
254 }
255
256 void wxCDMPackageHelpDialog::OnDisableHelp(wxCommandEvent& event)
257 {
258   wxPostEvent(this->GetParent(), event);
259 }