]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMMainFrame.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMMainFrame.cpp
index d8ffea1e4f50b10728a563145b306e437f4bd434..98ff113ef689c82150b9145d44fd993bef9ce14f 100755 (executable)
 
 #include <creaWx.h>
 #include "wx/treectrl.h"
+#include "wx/treebase.h"
 #include "CDMUtilities.h"
 
 #include "creaDevManagerIds.h"
 #include "wxCDMMainDescriptionPanel.h"
 #include "wxCDMProjectDescriptionPanel.h"
+#include "wxCDMAppliDescriptionPanel.h"
+#include "wxCDMApplicationDescriptionPanel.h"
+#include "wxCDMLibDescriptionPanel.h"
+#include "wxCDMLibraryDescriptionPanel.h"
+#include "wxCDMPackageDescriptionPanel.h"
+#include "wxCDMBlackBoxDescriptionPanel.h"
+#include "wxCDMCMakeListsDescriptionPanel.h"
+#include "wxCDMFolderDescriptionPanel.h"
+#include "wxCDMFileDescriptionPanel.h"
+#include "wxCDMPackageManagerPanel.h"
+
 #include "wxCDMProjectActionsPanel.h"
 #include "wxCDMNewProjectDialog.h"
 
@@ -67,7 +79,8 @@ EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager
 EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis)
 EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject)
 EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject)
-EVT_TREE_SEL_CHANGED(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged)
+EVT_TREE_SEL_CHANGING(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged)
+EVT_COMMAND(wxID_ANY, wxEVT_DISPLAY_CHANGED, wxCDMMainFrame::OnCreationComplete)
 END_EVENT_TABLE()
 
 wxCDMMainFrame::wxCDMMainFrame(
@@ -103,6 +116,20 @@ bool wxCDMMainFrame::Create(
   return TRUE;
 }
 
+modelCDMMain* wxCDMMainFrame::GetModel() const
+{
+  return this->model;
+}
+
+void wxCDMMainFrame::RefreshProject()
+{
+  std::string* result;
+  std::cout << "refreshing project" << std::endl;
+  this->model->RefreshProject(result);
+  std::cout << "rebuilding project tree" << std::endl;
+  this->tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
+}
+
 void wxCDMMainFrame::CreateMenus()
 {
   wxMenuBar* menuBar = new wxMenuBar;
@@ -174,17 +201,16 @@ void wxCDMMainFrame::CreateControls()
       this,
       ID_TREE_PROJECTS,
       wxDefaultPosition,
-      wxSize(300,400),
+      wxSize(200,400),
       wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
   );
-  tree_Projects->SetMinSize(wxSize(200,200));
 
   panel_Properties = new wxCDMMainDescriptionPanel(
       this,
       ID_WINDOW_PROPERTIES,
       wxT("Description Panel"),
       wxDefaultPosition,
-      wxSize(300, 400),
+      wxSize(400, 600),
       0
   );
 
@@ -192,11 +218,15 @@ void wxCDMMainFrame::CreateControls()
 
 
 
-  auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
-  auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
+
+
+  auiManager.AddPane(panel_Properties, wxAuiPaneInfo().BestSize(600,400).CenterPane().Name(wxT("panel_Properties")).Caption(wxT("Properties")));
+  auiManager.AddPane(tree_Projects, wxAuiPaneInfo().Left().MinSize(300,300).BestSize(300,400).CloseButton(false).Name(wxT("tree_Projects")).Caption(wxT("Projects Tree")));
+
+  wxString pers = auiManager.SavePerspective();
 
   auiManager.Update();
-  auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
+  auiManager.LoadPerspective(pers,true);
 }
 
 //Event Handlers
@@ -254,7 +284,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
           ID_WINDOW_PROPERTIES,
           wxT("Description Panel"),
           wxDefaultPosition,
-          wxSize(300, 400),
+          wxSize(600, 400),
           0);
       //show projectactions panel
       if(this->panel_ProjectActions != NULL)
@@ -268,14 +298,14 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
           ID_WINDOW_PROJ_ACTIONS,
           wxT("Project Actions Panel"),
           wxDefaultPosition,
-          wxSize(600,200),
+          wxSize(800,200),
           0
       );
       panel_ProjectActions->SetMinSize(wxSize(500, 100));
 
 
-      auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
-      auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
+      auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400));
+      auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("Project Actions")).BestSize(800,70).CloseButton(false));
 
       auiManager.Update();
 
@@ -341,7 +371,7 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
           ID_WINDOW_PROPERTIES,
           wxT("Description Panel"),
           wxDefaultPosition,
-          wxSize(300, 400),
+          wxSize(600, 400),
           0
       );
 
@@ -356,14 +386,14 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
           ID_WINDOW_PROJ_ACTIONS,
           wxT("Project Actions Panel"),
           wxDefaultPosition,
-          wxSize(600,200),
+          wxSize(800,200),
           0
       );
       panel_ProjectActions->SetMinSize(wxSize(500, 100));
 
 
-      auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
-      auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
+      auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400));
+      auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("Project Actions")).BestSize(800,70).CloseButton(false));
 
       auiManager.Update();
     }
@@ -377,12 +407,14 @@ void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
 }
 void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
 {
+  std::cout << "closing project" << std::endl;
   std::string* result;
   if(!this->model->CloseProject(result))
     {
       std::cout << "error closing project: " << *result << std::endl;
       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
     }
+
   tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
 
   if(this->panel_Properties != NULL)
@@ -401,11 +433,11 @@ void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
       ID_WINDOW_PROPERTIES,
       wxT("Description Panel"),
       wxDefaultPosition,
-      wxSize(300, 400),
+      wxSize(600, 400),
       0
   );
 
-  auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
+  auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400));
 
   auiManager.Update();
   event.Skip();
@@ -437,11 +469,11 @@ void wxCDMMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
       ID_WINDOW_PROPERTIES,
       wxT("Description Panel"),
       wxDefaultPosition,
-      wxSize(300, 400),
+      wxSize(600, 400),
       0
   );
 
-  auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
+  auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400));
 
   auiManager.Update();
   event.Skip();
@@ -478,7 +510,7 @@ void wxCDMMainFrame::OnMenuExit(wxCommandEvent& event)
       ID_WINDOW_PROPERTIES,
       wxT("Description Panel"),
       wxDefaultPosition,
-      wxSize(300, 400),
+      wxSize(600, 400),
       0
   );
   Close();
@@ -493,6 +525,8 @@ void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
     {
       wxMessageBox( crea::std2wx(result->c_str()), wxT("Refresh Project - Error"), wxICON_ERROR);
     }
+  this->tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject());
+  this->auiManager.Update();
   //TODO: Show possible problems in CMakeLists files
   event.Skip();
 }
@@ -579,6 +613,13 @@ void wxCDMMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
 void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
 {
   std::cout << "New Tree Selection" << std::endl;
+
+  if(event.GetId() != 0)
+    {
+      event.Skip();
+    }
+
+
   //get selected element
   wxTreeItemId elementId = event.GetItem();
 
@@ -587,9 +628,287 @@ void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event)
   std::cout << "Tree Selection: " << element->GetName() << std::endl;
 
   //TODO get element type
-  //TODO create element description
-  //TODO delete old view
-  //TODO set new view
+  //project
+  modelCDMProject* elementProject = dynamic_cast<modelCDMProject*>(element);
+  wxPanel* description;
+  if(elementProject != NULL)
+    {
+      //create element description
+      description = new wxCDMProjectDescriptionPanel(
+          this,
+          elementProject,
+          ID_WINDOW_PROPERTIES,
+          wxT("Description Panel"),
+          wxDefaultPosition,
+          wxSize(600, 400),
+          0
+      );
+
+    }
+  else
+    {
+      //appli
+      modelCDMAppli* elementAppli = dynamic_cast<modelCDMAppli*>(element);
+      if(elementAppli != NULL)
+        {
+          //create element description
+          description = new wxCDMAppliDescriptionPanel(
+              this,
+              elementAppli,
+              ID_WINDOW_PROPERTIES,
+              wxT("Description Panel"),
+              wxDefaultPosition,
+              wxSize(600, 400),
+              0
+          );
+        }
+      else
+        {
+          //application
+          modelCDMApplication* elementApplication = dynamic_cast<modelCDMApplication*>(element);
+          if(elementApplication != NULL)
+            {
+              //create element description
+              description = new wxCDMApplicationDescriptionPanel(
+                  this,
+                  elementApplication,
+                  ID_WINDOW_PROPERTIES,
+                  wxT("Description Panel"),
+                  wxDefaultPosition,
+                  wxSize(600, 400),
+                  0
+              );
+            }
+          else
+            {
+              //lib
+              modelCDMLib* elementLib = dynamic_cast<modelCDMLib*>(element);
+              if(elementLib != NULL)
+                {
+                  //create element description
+                  description = new wxCDMLibDescriptionPanel(
+                      this,
+                      elementLib,
+                      ID_WINDOW_PROPERTIES,
+                      wxT("Description Panel"),
+                      wxDefaultPosition,
+                      wxSize(600, 400),
+                      0
+                  );
+                }
+              else
+                {
+                  //library
+                  modelCDMLibrary* elementLibrary = dynamic_cast<modelCDMLibrary*>(element);
+                  if(elementLibrary != NULL)
+                    {
+                      //create element description
+                      description = new wxCDMLibraryDescriptionPanel(
+                          this,
+                          elementLibrary,
+                          ID_WINDOW_PROPERTIES,
+                          wxT("Description Panel"),
+                          wxDefaultPosition,
+                          wxSize(600, 400),
+                          0
+                      );
+                    }
+                  else
+                    {
+                      //package
+                      modelCDMPackage* elementPackage = dynamic_cast<modelCDMPackage*>(element);
+                      if(elementPackage != NULL)
+                        {
+                          //create element description
+                          description = new wxCDMPackageDescriptionPanel(
+                              this,
+                              elementPackage,
+                              ID_WINDOW_PROPERTIES,
+                              wxT("Description Panel"),
+                              wxDefaultPosition,
+                              wxSize(600, 400),
+                              0
+                          );
+                        }
+                      else
+                        {
+                          //black box
+                          modelCDMBlackBox* elementBlackBox = dynamic_cast<modelCDMBlackBox*>(element);
+                          if(elementBlackBox != NULL)
+                            {
+                              //create element description
+                              description = new wxCDMBlackBoxDescriptionPanel(
+                                  this,
+                                  elementBlackBox,
+                                  ID_WINDOW_PROPERTIES,
+                                  wxT("Description Panel"),
+                                  wxDefaultPosition,
+                                  wxSize(600, 400),
+                                  0
+                              );
+                            }
+                          else
+                            {
+                              //CMakeLists
+                              modelCDMCMakeListsFile* elementCMakeLists = dynamic_cast<modelCDMCMakeListsFile*>(element);
+                              if(elementCMakeLists != NULL)
+                                {
+                                  //create element description
+                                  description = new wxCDMCMakeListsDescriptionPanel(
+                                      this,
+                                      elementCMakeLists,
+                                      ID_WINDOW_PROPERTIES,
+                                      wxT("Description Panel"),
+                                      wxDefaultPosition,
+                                      wxSize(600, 400),
+                                      0
+                                  );
+                                }
+                              else
+                                {
+                                  //folder
+                                  modelCDMFolder* elementFolder = dynamic_cast<modelCDMFolder*>(element);
+                                  if(elementFolder != NULL)
+                                    {
+                                      //create element description
+                                      description = new wxCDMFolderDescriptionPanel(
+                                          this,
+                                          elementFolder,
+                                          ID_WINDOW_PROPERTIES,
+                                          wxT("Description Panel"),
+                                          wxDefaultPosition,
+                                          wxSize(600, 400),
+                                          0
+                                      );
+                                    }
+                                  else
+                                    {
+                                      //file
+                                      modelCDMFile* elementFile = dynamic_cast<modelCDMFile*>(element);
+                                      if(elementFile != NULL)
+                                        {
+                                          //create element description
+                                          description = new wxCDMFileDescriptionPanel(
+                                              this,
+                                              elementFile,
+                                              ID_WINDOW_PROPERTIES,
+                                              wxT("Description Panel"),
+                                              wxDefaultPosition,
+                                              wxSize(600, 400),
+                                              0
+                                          );
+                                        }
+                                      else
+                                        {
+
+                                          //main if not any
+                                          //create element description
+                                          description = new wxCDMMainDescriptionPanel(
+                                              this,
+                                              ID_WINDOW_PROPERTIES,
+                                              wxT("Description Panel"),
+                                              wxDefaultPosition,
+                                              wxSize(600, 400),
+                                              0
+                                          );
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+  if(this->panel_Properties!= NULL)
+    this->panel_Properties->Hide();
+
+  auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400));
+  auiManager.Update();
+
+  //delete old view
+  if(this->panel_Properties!= NULL)
+    {
+      this->panel_Properties->Destroy();
+      auiManager.DetachPane(this->panel_Properties);
+    }
+  //set new view
+
+  this->panel_Properties = description;
+  //auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400));
+  auiManager.Update();
   event.Skip();
+  return;
+
+}
 
+void wxCDMMainFrame::OnCreationComplete(wxCommandEvent& event)
+{
+  std::cout << "inMainFrame id: " << event.GetId() << ", tree element: "<< event.GetInt() << std::endl;
+  switch(event.GetId() != 0)
+  {
+  case 0:
+    this->tree_Projects->SelectItem(event.GetInt(), false);
+    this->tree_Projects->SelectItem(event.GetInt(), true);
+    break;
+  case 1:
+    wxPanel* description = NULL;
+    if(event.GetString() == wxT("manage_packages"))
+      {
+        description = new wxCDMPackageManagerPanel(
+            this,
+            this->model->GetProject(),
+            ID_WINDOW_PROPERTIES,
+            wxT("Description Panel"),
+            wxDefaultPosition,
+            wxSize(600, 400),
+            0
+        );
+      }
+    else if(event.GetString() == wxT("manage_libraries"))
+      {
+        description = new wxCDMLibDescriptionPanel(
+            this,
+            this->model->GetProject()->GetLib(),
+            ID_WINDOW_PROPERTIES,
+            wxT("Description Panel"),
+            wxDefaultPosition,
+            wxSize(600, 400),
+            0
+        );
+      }
+    else if(event.GetString() == wxT("manage_applications"))
+      {
+        description = new wxCDMAppliDescriptionPanel(
+            this,
+            this->model->GetProject()->GetAppli(),
+            ID_WINDOW_PROPERTIES,
+            wxT("Description Panel"),
+            wxDefaultPosition,
+            wxSize(600, 400),
+            0
+        );
+      }
+
+    if(this->panel_Properties!= NULL)
+      this->panel_Properties->Hide();
+
+    auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400));
+    auiManager.Update();
+
+    //delete old view
+    if(this->panel_Properties!= NULL)
+      {
+        this->panel_Properties->Destroy();
+        auiManager.DetachPane(this->panel_Properties);
+      }
+    //set new view
+
+    this->panel_Properties = description;
+    auiManager.Update();
+    break;
+  }
+  event.Skip();
 }