]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMProjectActionsPanel.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / wxCDMProjectActionsPanel.cpp
index c4e2b0ff88ef900a946cbc3579cf0fc618876bc9..514d247faf7c32e3728ec5b640a5a4b5f8662232 100755 (executable)
 
 #include "wxCDMProjectActionsPanel.h"
 
+#include <wx/progdlg.h>
+
 #include "creaDevManagerIds.h"
 
+#include <map>
+#include "wxCDMProjectStructureReportDialog.h"
+
 BEGIN_EVENT_TABLE(wxCDMProjectActionsPanel, wxPanel)
+EVT_BUTTON(ID_BUTTON_CHECK_PROJECT, wxCDMProjectActionsPanel::OnBtnCheckProjectStructure)
 EVT_BUTTON(ID_BUTTON_BUILD_PROJECT, wxCDMProjectActionsPanel::OnBtnBuildProject)
 EVT_BUTTON(ID_BUTTON_CONFIGURE_BUILD, wxCDMProjectActionsPanel::OnBtnConfigureBuild)
-EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMProjectActionsPanel::OnBtnEditCMakeLists)
 EVT_BUTTON(ID_BUTTON_CONNECT_PROJECT, wxCDMProjectActionsPanel::OnBtnConnectProject)
 END_EVENT_TABLE()
 
 wxCDMProjectActionsPanel::wxCDMProjectActionsPanel(
     wxWindow* parent,
+    modelCDMProject* project,
     wxWindowID id,
     const wxString& caption,
     const wxPoint& pos,
@@ -52,6 +58,7 @@ wxCDMProjectActionsPanel::wxCDMProjectActionsPanel(
 )
 {
   wxCDMProjectActionsPanel::Create(parent,id,caption,pos,size,style);
+  this->project = project;
 }
 
 wxCDMProjectActionsPanel::~wxCDMProjectActionsPanel()
@@ -70,44 +77,136 @@ bool wxCDMProjectActionsPanel::Create(
   wxPanel::Create(parent,id,pos,size,style);
   wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
   this->SetSizer(sizer);
-
   CreateControls();
+  // this part makes the scrollbars show up
+  this->FitInside(); // ask the sizer about the needed size
+  this->SetScrollRate(5, 5);
 
   return TRUE;
 }
 
 void wxCDMProjectActionsPanel::CreateControls()
 {
-  this->GetSizer()->Add(new wxButton(this, ID_BUTTON_BUILD_PROJECT, _T("Build Project (make)")), 0, wxALL, 5);
-  this->GetSizer()->Add(new wxButton(this, ID_BUTTON_CONFIGURE_BUILD, _T("Configure Build (ccmake)")), 0, wxALL, 5);
-  this->GetSizer()->Add(new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists")), 0, wxALL, 5);
-  this->GetSizer()->Add(new wxButton(this, ID_BUTTON_CONNECT_PROJECT, _T("Connect Project")), 0, wxALL, 5);
+  wxButton* checkStructbt = new wxButton(this, ID_BUTTON_CHECK_PROJECT, _T("1. Check Project Structure"));
+  checkStructbt->SetToolTip(wxT("This step checks the project structure and tells what is going to be compiled."));
+  wxButton* configurebt = new wxButton(this, ID_BUTTON_CONFIGURE_BUILD, _T("2. Configure Project (CMake)"));
+  configurebt->SetToolTip(wxT("This is the second step in order to execute the project. Make sure you have selected the desired Build location."));
+  wxButton* compilebt = new wxButton(this, ID_BUTTON_BUILD_PROJECT, _T("3. Compile Project"));
+  compilebt->SetToolTip(wxT("This step should be done after configuring the project. This will create the executables."));
+  wxButton* plugbt = new wxButton(this, ID_BUTTON_CONNECT_PROJECT, _T("4. Plug Packages (BBTK)"));
+  plugbt->SetToolTip(wxT("This step should be done after compiling the project. This will allow to use the boxes in this project to be available in the bbEditor."));
+  this->GetSizer()->Add(checkStructbt, 0, wxALL, 5);
+  this->GetSizer()->Add(configurebt, 0, wxALL, 5);
+  this->GetSizer()->Add(compilebt, 0, wxALL, 5);
+  this->GetSizer()->Add(plugbt, 0, wxALL, 5);
 }
 
-void wxCDMProjectActionsPanel::OnBtnBuildProject(wxCommandEvent& event)
+//check project structure
+void wxCDMProjectActionsPanel::OnBtnCheckProjectStructure(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnBuildProject not implemented" << std::endl;
-  event.Skip();
+  std::map<std::string, bool> prjStruct;
+  this->project->CheckStructure(prjStruct);
+  std::cout << prjStruct.size() << std::endl;
+  wxCDMProjectStructureReportDialog* structure = new wxCDMProjectStructureReportDialog(this->GetParent(), prjStruct, wxID_ANY);
+  structure->Show(true);
 }
 
+//configure project
 void wxCDMProjectActionsPanel::OnBtnConfigureBuild(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnConfigureBuild not implemented" << std::endl;
-  event.Skip();
+  std::string* result;
+  if(!this->project->ConfigureBuild(result))
+    {
+      wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Configuration - Error!"));
+      return;
+    }
+  wxMessageBox(crea::std2wx("The configuration was executed successfully."), wxT("Project Configuration"));
 }
 
-void wxCDMProjectActionsPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
+//compile project
+void wxCDMProjectActionsPanel::OnBtnBuildProject(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
-  event.Skip();
-}
+#ifdef _WIN32
+  std::string* result;
+  if(!this->project->Build(result, ""))
+    {
+      wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Compilation - Error!"));
+      return;
+    }
+#else
+
+  std::string* result;
+  int isDir = wxMessageBox(crea::std2wx("Is this the path of the project compilation?:\n"+this->project->GetBuildPath()), wxT("Project Compilation - CreaDevManager"), wxYES_NO|wxCANCEL);
+  if(isDir != wxCANCEL)
+    {
+      wxString file = crea::std2wx(this->project->GetBuildPath());
+      if(isDir == wxNO)
+        {
+          file = wxDirSelector(
+              wxT("Please select the folder where your project is to be built."),
+              crea::std2wx(this->project->GetBuildPath())
+          );
+        }
 
+      if(!file.IsEmpty())
+        {
+          this->project->SetBuildPath(crea::wx2std(file), result);
+
+          wxTextEntryDialog* buildDlg = new wxTextEntryDialog(
+                this,
+                wxT("Check the compilation instruction:"),
+                wxT("Project Compilation - CreaDevManager"),
+                crea::std2wx(this->project->GetBuildInstruction()),
+                wxTE_MULTILINE | wxOK | wxCANCEL
+            );
+
+          if (buildDlg->ShowModal() == wxID_OK)
+            {
+              std::string buildDlgStr = crea::wx2std(buildDlg->GetValue());
+              //check line
+              if (buildDlgStr != "")
+                {
+                  std::string* result;
+                  if(!this->project->Build(result, buildDlgStr))
+                    {
+                      wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Compilation - Error!"));
+                      return;
+                    }
+                }
+            }
+        }
+    }
+#endif
+}
+//plug packages
 void wxCDMProjectActionsPanel::OnBtnConnectProject(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnConnectProject not implemented" << std::endl;
-  event.Skip();
+  std::string* result;
+  int isDir = wxMessageBox(crea::std2wx("Is this the path of the project compilation to plug?:\n"+this->project->GetBuildPath()), wxT("Plug BBTK Packages"), wxYES_NO|wxCANCEL);
+  if(isDir != wxCANCEL)
+    {
+      wxString file = crea::std2wx(this->project->GetBuildPath());
+      if(isDir == wxNO)
+        {
+          file = wxDirSelector(
+              wxT("Please select the folder containing the bbtkPackage file you want to use. Usually it is where you built your project."),
+              crea::std2wx(this->project->GetBuildPath())
+          );
+        }
+
+      if(!file.IsEmpty())
+        {
+          if(!this->project->Connect(result, crea::wx2std(file)))
+            {
+              wxMessageBox(crea::std2wx(result->c_str()), wxT("Plug BBTK Packages - Error!"), wxICON_ERROR);
+              return;
+            }
+          else
+            {
+              wxMessageBox(crea::std2wx("The connection was executed successfully. Please check the console to see the compilation result.\n Also, don't forget to restart the BBTK Graphical Editor (if already opened) to see the plugged packages."), wxT("Plug Package"));
+            }
+
+        }
+
+    }
 }