]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
some memory leaks
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
index 848ca2efe6a9909775bc6b60efddceaf07643ac4..57ef4b2ddb7227c2e99960907c2547cb50ba68db 100644 (file)
@@ -39,8 +39,6 @@ Version:   $Revision$
 
 #include <InterpreterBBS.h>
 
-
-
 namespace bbtk
 {
 
@@ -91,6 +89,10 @@ namespace bbtk
 //EED02JUIN2010                delete _tabsMgr;
 
            _frameAUIMgr->UnInit();
+               // FCY memory leaks
+               delete _frameAUIMgr;
+               delete _notebook;
+               delete _tabsMgr;
 
 
        }
@@ -182,6 +184,8 @@ namespace bbtk
                // Create Help menu and its items
                wxMenu *helpMenu = new wxMenu;
                helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
+               helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
+               Connect(ID_HELP_BBEDITOR,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
 
                // Append the created menu to the menu bar
                wxMenuBar *menuBar = new wxMenuBar();
@@ -346,25 +350,27 @@ namespace bbtk
 
        void wxGUIEditorGraphicBBS::executeScript(std::string script)
        {
-               std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
-               std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
-               std::string filename = dir + separator + "tmp_bbtk.bbs";
+               std::string separator   = ConfigurationFile::GetInstance().Get_file_separator ();
+               std::string dir                 = ConfigurationFile::GetInstance().Get_default_temp_dir();
+               std::string filename    = dir + separator + "tmp_bbtk.bbs";
 
                ofstream tempFile;
                tempFile.open(filename.c_str());
                tempFile << script;
                tempFile.close();
 
-               std::string command = "\""+ crea::System::GetExecutablePath();
+               std::string command = "";
+
+               #ifdef WIN32
+                       command += "\"";
+               #endif
+               command += "\""+ crea::System::GetExecutablePath();
 
 
 #ifdef MACOSX
                command += separator + "../../../bbi.app/Contents/MacOS";
 #endif
 
-               #ifdef WIN32
-                       command += "\"";
-               #endif
 
                /*
 
@@ -386,7 +392,9 @@ namespace bbtk
                        command += "\"";
                #endif
 
-               command += " & ";
+        #ifndef WIN32
+            command += " & ";
+               #endif
 
                printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
                system( command.c_str() );
@@ -426,7 +434,7 @@ namespace bbtk
                        wxString fileName = openFileDialog->GetPath(  );
 
 
-                       _tabsMgr->addNewTab();
+                       _tabsMgr->addNewTab(  openFileDialog->GetFilename()  );
 
                        bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory());
 
@@ -438,100 +446,152 @@ namespace bbtk
                refreshGUIControls();
        }
 
+
+
+    void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename)
+       {
+        ofstream file;
+
+//EED          file.open(fileName.c_str());
+        file.open( filename.c_str() );
+        std::string content="";
+        // writing file header
+        content += "# ----------------------------------\n";
+        content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
+        content += "# - ";
+        content += filename;
+        content += "\n";
+        content += "# ----------------------------------\n";
+        content += "\n";
+        content += _tabsMgr->getActualDiagramBBS();
+        file << content;
+        file.close();
+       }
+
+
        void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
        {
                wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
                if (saveFileDialog->ShowModal() == wxID_OK)
                {
                        wxString fileName = saveFileDialog->GetPath(  );
+            SaveActualBBS( (const char*) (fileName.mb_str())  );
+               }
+
+       }
+
 
-                       ofstream file;
+    void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration()
+    {
+               std::string cbName = _tabsMgr->GetCbName();
+               std::string paName = _tabsMgr->GetCbPackageName();
 
-//EED                  file.open(fileName.c_str());
-                       file.open( (const char*) (fileName.mb_str()) );
+               wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,wxT("Complex Box name"));
+               wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,wxT("Package name"));
+
+               cbNameDialog->SetValue( wxString(cbName.c_str(),wxConvUTF8) );
+               paNameDialog->SetValue( wxString(paName.c_str(),wxConvUTF8) );
+
+               if (cbNameDialog->ShowModal() == wxID_OK)
+               {
+                       wxString complexboxname = cbNameDialog->GetValue();
+                       cbName=(const char*) (complexboxname.mb_str());
+               }
 
-                       std::string content="";
 
-                       // writing file header
-                       content += "# ----------------------------------\n";
-                       content += "# - BBTKGEditor v 1.0 BBS BlackBox Script\n";
-                       content += "# ----------------------------------\n";
-                       content += "\n";
-                       content += _tabsMgr->getActualDiagramBBS();
-                       file << content;
-                       file.close();
+               if (paNameDialog->ShowModal() == wxID_OK)
+               {
+                       wxString packagename = paNameDialog->GetValue();
+                       paName=(const char*) (packagename.mb_str());
                }
 
+        _tabsMgr->SetCbName(cbName);
+        _tabsMgr->SetCbPackageName(paName);
+    }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename)
+       {
+        ofstream file;
+        file.open( filename.c_str() );
+
+        std::string content="";
+
+        // writing file header
+        content += "# ----------------------------------\n";
+        content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
+        content += "# - ";
+        content += filename;
+        content += "\n";
+        content += "# ----------------------------------\n";
+        content += "\n";
+        content += _tabsMgr->getActualComplexBoxBBS();
+        file << content;
+        file.close();
        }
 
        //=========================================================================
 
        void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
        {
-               wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of complex box"));
-               std::string cbName="";
-               if (nameDialog->ShowModal() == wxID_OK)
-               {
-                       wxString fileName = nameDialog->GetValue();
-                       cbName=(const char*) (fileName.mb_str());
-               }
+        wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, _T("ComplexBoxName") ,wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
+        if (saveFileDialog->ShowModal() == wxID_OK)
+        {
+            wxString fileName = saveFileDialog->GetPath();
+            SaveActualComplexBox( (const char*) (fileName.mb_str()) );
+        }
+       }
 
-               if(!cbName.empty())
-               {
-                       wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, wxString( cbName.c_str(), wxConvUTF8),wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
-                       if (saveFileDialog->ShowModal() == wxID_OK)
-                       {
-                               wxString fileName = saveFileDialog->GetPath();
+       //=========================================================================
+       void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename)
+       {
+        ofstream file;
+        file.open( filename.c_str() );
 
-                               ofstream file;
-                               file.open( (const char*) (fileName.mb_str()) );
+        std::string content="";
 
-                               std::string content="";
+        // writing file header
+        content += "# ----------------------------------\n";
+        content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
+        content += "# - ";
 
-                               // writing file header
-                               content += "# ----------------------------------\n";
-                               content += "# - BBTKGEditor v 1.1 BBS BlackBox Script (Complex Box)\n";
-                               content += "# ----------------------------------\n";
-                               content += "\n";
-                               content += _tabsMgr->getActualComplexBoxBBS(cbName);
-                               file << content;
-                               file.close();
-                       }
-               }
+        content += filename;
 
-       }
+        content += "\n";
+        content += "# ----------------------------------\n";
+        content += "\n";
+        content += "APP_START\n";
+        _tabsMgr->saveActualDiagram(content);
+        content += "APP_END\n";
+        file << content;
+        file.close();
+    }
 
-       //=========================================================================
 
+       //=========================================================================
        void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
        {
                wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
                if (saveFileDialog->ShowModal() == wxID_OK)
                {
-                       wxString fileName = saveFileDialog->GetPath();
-
-                       ofstream file;
-                       file.open( (const char*) (fileName.mb_str()) );
-
-                       std::string content="";
-
-                       // writing file header
-                       content += "# ----------------------------------\n";
-                       content += "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file\n";
-                       content += "# - ";
-
-                       content += (const char*) (fileName.mb_str());
+            _tabsMgr->SetNameTabPanel( saveFileDialog->GetFilename() );
 
-                       content += "\n";
-                       content += "# ----------------------------------\n";
-                       content += "\n";
-                       content += "APP_START\n";
-                       _tabsMgr->saveActualDiagram(content);
-                       content += "APP_END\n";
-                       file << content;
-                       file.close();
-               }
+                       wxString pathfileName       = saveFileDialog->GetPath();
+                       std::string pathfilename    = (const char*) (pathfileName.mb_str());
+            std::string pathfilenamebbs = pathfilename;
+            pathfilenamebbs[pathfilenamebbs.length()-1]='s';
 
+            if (_tabsMgr->isActualDiagramComplexBox()==false)
+            {
+                SaveActualDiagram( pathfilename );
+                SaveActualBBS(pathfilenamebbs);
+            } else {
+                AskComplexBoxConfiguration();
+                SaveActualDiagram( pathfilename );
+                SaveActualComplexBox(pathfilenamebbs);
+            } //if isActualDiagramComplexBox
+               } // if saveFileDialog
        }
 
        //=========================================================================
@@ -590,22 +650,17 @@ namespace bbtk
 
        //=========================================================================
 
-
        void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
        {
                wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
                if (openFileDialog->ShowModal() == wxID_OK)
                {
                        wxString fileName = openFileDialog->GetPath();
-
                        ifstream inputStream;
+                       std::string fName=(const char*) (fileName.mb_str());
+                       inputStream.open( fName.c_str() );
+                       _tabsMgr->addNewTab( openFileDialog->GetFilename() );
 
-//EED                  inputStream.open(fileName.c_str());
-                       inputStream.open( (const char*) (fileName.mb_str()) );
-
-
-
-                       _tabsMgr->addNewTab();
                        _tabsMgr->loadDiagram(inputStream);
 
                        inputStream.close();
@@ -618,8 +673,7 @@ namespace bbtk
 
        void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
        {
-
-               BlackBoxDescriptor      *bbDes          = _pkgBrowser->GetActualSelected();
+               BlackBoxDescriptor      *bbDes = _pkgBrowser->GetActualSelected();
         if (bbDes!=NULL)
         {
             std::string                        typeName        = bbDes->GetTypeName();
@@ -694,6 +748,14 @@ namespace bbtk
                _tabsMgr->copySelectedBBoxesToComplexDiagram();
        }
 
+
+       void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
+       {
+               printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ......\n");
+       }
+
+
+
        //=========================================================================
 
        void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
@@ -701,6 +763,8 @@ namespace bbtk
                Close(true);
        }
 
+
+
        //=========================================================================
 
 }  // EO namespace bbtk