wxGEditorTabPanel.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 Program:   bbtk
00003 Module:    $RCSfile: wxGEditorTabPanel.cxx,v $
00004 Language:  C++
00005 Date:      $Date: 2012/05/25 12:55:15 $
00006 Version:   $Revision: 1.38 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and
00015 *  abiding by the rules of distribution of free software. You can  use,
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability.
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */
00030 
00037 #include "wxGEditorTabPanel.h"
00038 #include "creaWx.h"
00039 
00040 namespace bbtk
00041 {
00042 
00043         //=========================================================================
00044         wxGEditorTabPanel::wxGEditorTabPanel()
00045         {
00046                 printf ("EED %p wxGEditorTabPanel 1 ()\n" , this );
00047         }
00048 
00049         //=========================================================================
00050         wxGEditorTabPanel::wxGEditorTabPanel(wxWindow *parent,int id):wxPanel(parent),wxTextDropTarget()
00051         {
00052 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 0\n");
00053                 printf ("EED %p wxGEditorTabPanel 2 ()\n" , this );
00054                 _id=id;
00055                 _panelAUIMgr = new wxAuiManager(this);
00056                 _sceneManager = NULL;
00057                 _actualdo = states.begin();
00058                 _sactualdo = sstates.begin();
00059                 initWxVtkCanvas();
00060 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 1\n");
00061         }
00062 
00063         //=========================================================================
00064         wxGEditorTabPanel::~wxGEditorTabPanel()
00065         {
00066 printf ("EED %p ~wxGEditorTabPanel() START \n" , this );
00067 //ED02JUIN2010          _sceneManager->disconnectDrop();
00068 
00069         _panelsManager->VerifyLastTabPanel();
00070                 //FCY memory leaks
00071                 delete _panelAUIMgr;
00072                 delete _sceneManager;
00073 
00074                 printf ("EED %p ~wxGEditorTabPanel() END\n" , this );
00075 
00076         }
00077 
00078         //=========================================================================
00079         void wxGEditorTabPanel::initWxVtkCanvas()
00080         {
00081 printf("EED wxGEditorTabPanel::initWxVtkCanvas 0\n");
00082                 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this);
00083                 baseview->Configure();
00084                 _sceneManager=new wxVtkSceneManager(this,baseview,_id);
00085 
00086 
00087 //EED02JUIN2010
00088                 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
00089                 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
00090 
00091                 _panelAUIMgr->Update();
00092 printf("EED wxGEditorTabPanel::initWxVtkCanvas 1\n");
00093         }
00094 
00095         //=========================================================================
00096 
00097         bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
00098         {
00099                 std::string packageName="";
00100                 std::string boxType="";
00101 
00102                 wxString foo( (data) );
00103                 char str[150];
00104                 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
00105 
00106                 char delims[] = ":";
00107                  char *result = NULL;
00108                  result = strtok( str, delims );
00109                  packageName += result;
00110 
00111                  result = strtok( NULL, delims );
00112                  boxType += result;
00113 
00114                 _sceneManager->createGBlackBox(x,y,packageName, boxType);
00115                 saveTempandUpdate("drop box");
00116           return true;
00117         }
00118 
00119         //=========================================================================
00120         void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
00121         {
00122                 _panelsManager->saveTempandUpdate(action);
00123         }
00124         //=========================================================================
00125 
00126         void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
00127         {
00128                 _panelsManager = panelsManager;
00129         }
00130 
00131         //=========================================================================
00132 
00133         void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
00134         {
00135                 _panelsManager->displayBlackBoxInfo(packageName,boxName);
00136         }
00137 
00138         //=========================================================================
00139 
00140         void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
00141         {
00142                 _panelsManager->updateStatusBar(textStatus);
00143         }
00144 
00145         //=========================================================================
00146 
00147         std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
00148         {
00149                 return _sceneManager->getDiagramBBS(wln);
00150         }
00151 
00152         //=========================================================================
00153 
00154         std::string wxGEditorTabPanel::saveComplexBoxBBS()
00155         {
00156                 return _sceneManager->saveComplexBoxBBS();
00157         }
00158 
00159         //=========================================================================
00160 
00161         void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
00162         {
00163                 _panelsManager->editBlackBox(bbmodel);
00164         }
00165 
00166         //=========================================================================
00167 
00168         void wxGEditorTabPanel::deleteAllBoxes()
00169         {
00170                 _sceneManager->deleteAllBoxes();
00171         }
00172 
00173         //=========================================================================
00174 
00175         void wxGEditorTabPanel::centerView()
00176         {
00177                 if(_sceneManager)
00178                 {
00179                         _sceneManager->centerView();
00180                 }
00181         }
00182 
00183         //=========================================================================
00184 
00185         void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
00186         {
00187                 this->SetFullPath(path);
00188                 _sceneManager->saveDiagram(content);
00189         }
00190 
00191         //=========================================================================
00192 
00193         void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
00194         {
00195                 std::string content = "";
00196                 // writing file header
00197                 content += "# ----------------------------------\n";
00198                 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
00199                 content += "# - ";
00200                 content += "temp";
00201                 content += "\n";
00202                 content += "# ----------------------------------\n";
00203                 content += "\n";
00204                 content += "APP_START\n";
00205                 _sceneManager->saveDiagram(content);
00206                 content += "APP_END\n"; //put here to avoid mistakes
00207                 if(_actualdo == states.end() ) // same size, write to the end
00208                 {
00209                         states.push_back (content);
00210                         saveStringAction(action);
00211                 }
00212                 else
00213                 {
00214                         std::vector<std::string>::iterator it = _actualdo+1;
00215                         states.erase(it, states.end());
00216                         states.push_back(content);
00217 
00218                         std::vector<std::string>::iterator sit = _sactualdo+1;
00219                         sstates.erase(sit, sstates.end());
00220                         saveStringAction(action);
00221                 }
00222                 _actualdo = states.end();
00223                 _sactualdo = sstates.end();
00224                         
00225         }
00226 
00227         //=========================================================================
00228 
00229         void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
00230         {
00231                 this->SetFullPath(path);
00232                 stringstream ss;
00233                 ss << inputStream.rdbuf() ;
00234                 _sceneManager->loadDiagram(ss);
00235         }
00236 
00237         //=========================================================================
00238         unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
00239         {
00240                 stun = "Undo";
00241                 if(states.size()>0)
00242                 {
00243                         if(_actualdo == states.begin() )
00244                         {
00245                                 
00246                                 return 0;
00247                         }
00248                         else
00249                         {
00250                                 stun +=" - ";
00251                                 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
00252                                 _sactualdo++;
00253                                 return 1;
00254                         }
00255                 }
00256         }
00257 
00258         unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
00259         {
00260                 stre = "Redo";
00261                 if(states.size()>0)
00262                 {
00263                         if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
00264                                 return 0;
00265                         else
00266                         {
00267                                 stre +=" - ";
00268                                 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
00269                                 --_sactualdo;
00270                                 return 1;
00271                         }
00272                 }
00273         }
00274 
00275         //=========================================================================
00276         void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
00277         {
00278                 unsigned short res = 1;
00279                 deleteAllBoxes();
00280                 std::stringstream ss;
00281                 if (un == 0) //undo
00282                 {
00283                         if(_actualdo == states.end() ) // same size, write to the end
00284                         {
00285                                 (_actualdo--);
00286                                 (_sactualdo--);
00287                         }
00288                         if(_actualdo != states.begin() )
00289                         {
00290                                 ss << *(--_actualdo);
00291                                 _sactualdo--;
00292                         }
00293                         else
00294                         {
00295                                 ss << *_actualdo;
00296                                 res = 0;
00297                         }
00298                 }
00299                 else //redo
00300                 {
00301                         _actualdo++;
00302                         _sactualdo++;
00303                         if(_actualdo != states.end())
00304                         {
00305                                 ss << *_actualdo;
00306                         }
00307                         else
00308                         {
00309                                 res = 0;
00310                         }
00311                 }
00312                 _sceneManager->loadDiagram(ss);
00313         
00314         }
00315 
00316         void wxGEditorTabPanel::saveStringAction(const std::string &action)
00317         {
00318                 char temp[50];
00319                 sprintf(temp,".%d", sstates.size());
00320                 sstates.push_back(action + temp);
00321         }
00322 
00323         //=========================================================================
00324 
00325         int wxGEditorTabPanel::getPanelId()
00326         {
00327                 return _id;
00328         }
00329         
00330 
00331 
00332         //=========================================================================
00333 
00334         bool wxGEditorTabPanel::isComplexBox()
00335         {
00336                 return _sceneManager->isComplexBox();
00337         }
00338 
00339         //=========================================================================
00340 
00341         void wxGEditorTabPanel::setComplexBox(bool val)
00342         {
00343                 _sceneManager->setComplexBox(val);
00344         }
00345 
00346         //=========================================================================
00347 
00348         void wxGEditorTabPanel::addComplexInputPort(std::string portName)
00349         {
00350                 _sceneManager->createGComplexBoxInputPort(portName);
00351         }
00352 
00353         //=========================================================================
00354 
00355         void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
00356         {
00357                 _sceneManager->createGComplexBoxOutputPort(portName);
00358         }
00359 
00360         //=========================================================================
00361 
00362         std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
00363         {
00364                 return _sceneManager->getSelectedObjects();
00365         }
00366 
00367         //=========================================================================
00368 
00369         void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
00370         {
00371                 _sceneManager->addObjects(objectsMap);
00372         }
00373 
00374         //=========================================================================
00375 
00376         int wxGEditorTabPanel::getNumSelectedObjects()
00377         {
00378                 return _sceneManager->getNumSelectedObjects();
00379         }
00380 
00381         //=========================================================================
00382 
00383 
00384         wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
00385         {
00386                 return _sceneManager;
00387         }
00388 
00389         //=========================================================================
00390     std::string wxGEditorTabPanel::GetCbName()
00391         {
00392             return _sceneManager->GetCbName();
00393         }
00394 
00395 
00396         //=========================================================================
00397     std::string wxGEditorTabPanel::GetCbPackageName()
00398         {
00399             return _sceneManager->GetCbPackageName();
00400         }
00401 
00402         //=========================================================================
00403     std::string wxGEditorTabPanel::GetAuthor()
00404         {
00405             return _sceneManager->GetAuthor();
00406         }
00407 
00408         //=========================================================================
00409     std::string wxGEditorTabPanel::GetDescription()
00410         {
00411             return _sceneManager->GetDescription();
00412         }
00413 
00414         //=========================================================================
00415     std::string wxGEditorTabPanel::GetCategory()
00416         {
00417             return _sceneManager->GetCategory();
00418         }
00419 
00420         //=========================================================================
00421     void wxGEditorTabPanel::SetCbName(std::string cbName)
00422     {
00423         _sceneManager->SetCbName( cbName );
00424     }
00425 
00426         //=========================================================================
00427     void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
00428     {
00429         _sceneManager->SetCbPackageName( packagename );
00430     }
00431 
00432 
00433         //=========================================================================
00434     void wxGEditorTabPanel::SetAuthor(std::string author)
00435     {
00436         _sceneManager->SetAuthor( author );
00437     }
00438 
00439 
00440         //=========================================================================
00441     void wxGEditorTabPanel::SetCategory(std::string category)
00442     {
00443         _sceneManager->SetCategory( category );
00444     }
00445 
00446 
00447         //=========================================================================
00448     void wxGEditorTabPanel::SetDescription(std::string description)
00449     {
00450         _sceneManager->SetDescription( description );
00451     }
00452     //=========================================================================
00453         //DFCH
00454         void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
00455         {
00456                 this->_fullPath = fullpath;
00457         }
00458         //=========================================================================
00459         //DFCH
00460         void wxGEditorTabPanel::SetFileName( const std::string& filename )
00461         {
00462                 this->_fileName = filename;
00463         }
00464         //=========================================================================
00465         //DFCH
00466         std::string wxGEditorTabPanel::GetFullPath( )
00467         {
00468                 return( this->_fullPath );
00469         }
00470         //=========================================================================
00471         //DFCH
00472     std::string wxGEditorTabPanel::GetFileName( )
00473     {
00474                 return( this->_fileName );
00475         }
00476 
00477 
00478 
00479 
00480 }  // EO namespace bbtk
00481 
00482 // EOF

Generated on Thu May 31 15:12:19 2012 for bbtkGEditor by  doxygen 1.5.7.1