]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
#3057 bbGEditor Feature New Normal - optimizing of vtk actors management (input...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
index 377f625fd6f7f914041541df17b8bc339830354d..1376327ad2bea388f833aa242751243f2d530bec 100644 (file)
@@ -1,3 +1,28 @@
+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
+#                        pour la Santé)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+#
+#  This software is governed by the CeCILL-B license under French law and 
+#  abiding by the rules of distribution of free software. You can  use, 
+#  modify and/ or redistribute the software under the terms of the CeCILL-B 
+#  license as circulated by CEA, CNRS and INRIA at the following URL 
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability. 
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------  
+*/
+
 /*=========================================================================
  Program:   bbtk
  Module:    $RCSfile$
@@ -116,6 +141,7 @@ void wxGUIEditorGraphicBBS::initToolbar() {
        wxBitmap bmp_undo(undo_xpm);
        wxBitmap bmp_redo(redo_xpm);
        wxBitmap bmp_editProperties(editProperties_xpm);
+       wxBitmap bmp_showTree(showTree_xpm);
        wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
 
        //Adds a tool btn to the toolbar
@@ -167,6 +193,8 @@ void wxGUIEditorGraphicBBS::initToolbar() {
        toolbar->AddSeparator();
        toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL,      _T("Edit diagram properties"), _T("Edit diagram properties"));
        toolbar->EnableTool(ID_EDITPROPERTIES, false);
+
+       toolbar->AddTool(ID_SHOWTREE, _T("Show tree"),bmp_showTree, wxNullBitmap, wxITEM_NORMAL,        _T("Show tree"), _T("Show tree"));
        
        toolbar->EnableTool(ID_UNDO, false);
        toolbar->EnableTool(ID_REDO, false);
@@ -213,6 +241,7 @@ void wxGUIEditorGraphicBBS::initToolbar() {
        Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED,     wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
        Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
        Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
+       Connect(ID_SHOWTREE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowTree));
 
 }
 //=========================================================================
@@ -428,18 +457,50 @@ void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::st
 {
        if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName) 
        {
+
                _actualPkgBrowserPkgName = packageName;
                _actualPkgBrowserBoxName = boxName;
 
 //EED 15 oct 2012              BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
                
                Package::Pointer k;
+//EED          ComplexBlackBoxDescriptor::Pointer descriptor;
+               BlackBoxDescriptor::Pointer descriptor;
+
+               std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
+               k                       = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
+               mapDesc         = k->GetDescriptorMap();                
+               descriptor      = mapDesc[_actualPkgBrowserBoxName];
+/*
+               tree.treeTour(0);               
+
+               tree.deleteTree();
+
+               descriptor->GetBoxesInside(tree, 0);
+
+               //tree.treeTour(0);
+               //std::vector<std::string> boxesDiagram = _sceneM->boxesDiagram;
+               //for(int i=0;i<boxesDiagram.size();i++){
+               //      std::cout<<"caja: "<<boxesDiagram[i]<<std::endl;
+               //}             
+               
+               _actualPkgBrowserPkgName = "";
+               _actualPkgBrowserBoxName = "";
+*/
+               /*
+               Package::Pointer k;
                BlackBoxDescriptor::Pointer descriptor;
                std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
                k                       = _pkgBrowser->GetFactory()->GetPackage(packageName);
+               std::vector<std::string> temp;
+               _pkgBrowser->GetFactory()->GetPackagesList(temp);
+               for(int ii = 0 ; ii < temp.size() ; ii++)
+               {
+                               std::cout << " packs "<< temp[ii]<< std::endl;
+               }
                mapDesc         = k->GetDescriptorMap();                
                descriptor      = mapDesc[boxName];
-               
+               */
                _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
        }
 }
@@ -565,13 +626,42 @@ void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
 
 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
 }
+//=========================================================================
+
+void wxGUIEditorGraphicBBS::OnShowTree(wxCommandEvent& event){
+               std::cout <<  "wxGUIEditorGraphicBBS::OnShowTree"<<std::endl;
+if (_actualPkgBrowserPkgName !="" || _actualPkgBrowserBoxName != "") 
+       {
+               Package::Pointer k;
+//EED          ComplexBlackBoxDescriptor::Pointer descriptor;
+               BlackBoxDescriptor::Pointer descriptor;
+
+               std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
+               k                       = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
+               mapDesc         = k->GetDescriptorMap();                
+               descriptor      = mapDesc[_actualPkgBrowserBoxName];
+
+               tree.treeTour(0);               
+
+               tree.deleteTree();
+
+               descriptor->GetBoxesInside(tree, 0);
+               
+               _actualPkgBrowserPkgName = "";
+               _actualPkgBrowserBoxName = "";
+       }
+else
+       {
+               std::cout<<"Select a Box"<<std::endl;
+       }
+}
 
 //=========================================================================
 
 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
 {
        wxDiagramPropertiesEditionDialog* dialog =
-                               new wxDiagramPropertiesEditionDialog(this);
+                               new wxDiagramPropertiesEditionDialog(this, tree);
        dialog->Show();
 }
 
@@ -1000,6 +1090,7 @@ void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fi
        }
        _tabsMgr->addNewTab( crea::std2wx(fileName) );
        _tabsMgr->loadDiagram(inputStream, filePathName);
+
        _tabsMgr->saveTempActualDiagram("load diagram");
        GetToolBar()->EnableTool(ID_UNDO, false);
        GetToolBar()->EnableTool(ID_UNDO, false);
@@ -1023,6 +1114,7 @@ void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
 //=========================================================================
 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) 
 {
+       std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
        BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
        if (bbDes != NULL) {
                std::string typeName = bbDes->GetTypeName();
@@ -1059,6 +1151,7 @@ void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
 //=========================================================================
 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) 
 {
+       std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
        wxToolBar* toolbar = GetToolBar();
        bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
        if (temp) {
@@ -1069,18 +1162,28 @@ void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
 }
 
 //=========================================================================
-
+//EED01
 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) 
 {
        wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
                        wxT("Name of input port"));
-       if (nameDialog->ShowModal() == wxID_OK) {
+       if (nameDialog->ShowModal() == wxID_OK) 
+        {
                wxString fileName = nameDialog->GetValue();
-               if (!fileName.IsEmpty()) {
+               if (!fileName.IsEmpty()) 
+                {
                        std::string portName = (const char*) (fileName.mb_str());
-                       _tabsMgr->addActualDiagramComplexInputPort(portName);
-               }
-       }
+                       if ( !boxNameExists(portName) )
+                       {
+                          _tabsMgr->addActualDiagramComplexInputPort(portName);
+                       } else {
+                          wxMessageDialog *dial = new wxMessageDialog(NULL,
+                                      wxT("Impossible to create Box. The name already exists. Please provide another name"),
+                                      wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
+                          dial->ShowModal();
+                       }
+               } // if !fileName
+       } // if namaDialog
 }
 
 //=========================================================================
@@ -1088,13 +1191,24 @@ void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
 {
        wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
                        wxT("Name of output port"));
-       if (nameDialog->ShowModal() == wxID_OK) {
+       if (nameDialog->ShowModal() == wxID_OK) 
+        {
                wxString fileName = nameDialog->GetValue();
-               if (!fileName.IsEmpty()) {
+               if (!fileName.IsEmpty()) 
+                {
                        std::string portName = (const char*) (fileName.mb_str());
+                       if ( !boxNameExists(portName) )
+                       {
                        _tabsMgr->addActualDiagramComplexOutputPort(portName);
-               }
-       }
+                       } else {
+                          wxMessageDialog *dial = new wxMessageDialog(NULL,
+                                      wxT("Impossible to create Box. The name already exists. Please provide another name"),
+                                      wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
+                          dial->ShowModal();
+                       }
+
+               } // if !filename
+       } // namaDialog
 }
 
 //=========================================================================
@@ -1139,7 +1253,12 @@ void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
                if(userResponse==wxID_OK)
                {
                        std::string path = wx2std (FD->GetPath()) ;
+                       #ifdef WIN32
+                       std::string fname = path + "\\bbtkPackage";
+                       #else
                        std::string fname = path + "/bbtkPackage";
+                       #endif
+                       
                        std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
                        if ( Utilities::FileExists( fname ) )
                        {
@@ -1147,6 +1266,11 @@ void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
                                f.open(fname.c_str());
                                std::string pname;
                                f >> pname;
+                               while(pname[0] == '#')
+                               {
+                                       getline(f, pname, '\n');
+                                       f >> pname;
+                               }
                                f.close();
 
                                bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
@@ -1279,6 +1403,16 @@ void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
        _tabsMgr->SetCategory(category);
 }
 
+//=========================================================================
+void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
+       _tabsMgr->SetMessageKind(kind); 
+}
+
+//=========================================================================
+void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
+       _tabsMgr->SetMessageLevel(level);       
+}
+
 //=========================================================================
 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
 {
@@ -1297,7 +1431,16 @@ std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
        return _tabsMgr->GetCategory();
 }
 
-       
+//=========================================================================
+std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
+       return _tabsMgr->GetMessageKind();
+}
+
+//=========================================================================
+std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
+       return _tabsMgr->GetMessageLevel();
+}
+
 //=========================================================================
 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
 {