MaracasTools.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------
00002    INCLUDES WXWIDGETS
00003 -----------------------------------------------------------------*/
00004 #include "wx/wxprec.h"
00005 #ifdef __BORLANDC__
00006 #pragma hdrstop
00007 #endif
00008 #ifndef WX_PRECOMP
00009 #include "wx/wx.h"
00010 #endif
00011 /*-----------------------------------------------------------------*/
00012 
00013 //disable warnings on 255 char debug symbols
00014 #pragma warning (disable : 4786) 
00015 
00016 
00017 #include "osgi/framework/Bundle.h"
00018 #include "osgi/framework/BundleContext.h"
00019 
00020 #include "MaracasTools.h"
00021 #include "interface/wxWindows/widgets/wxManualSegmentation_MPRWidget.h"
00022 
00023 #include <iostream>
00024 
00025 using namespace std;
00026 
00027 /*----------------------------------------------------
00028 Instance. Singleton pattern in this class
00029 -----------------------------------------------------*/
00030 MaracasTools* MaracasTools::INSTANCE = NULL;
00031 
00032 
00033 /*----------------------------------------------------
00034 GetInstance method
00035 -----------------------------------------------------*/
00036 MaracasTools* MaracasTools::GetInstance(){
00037         if (INSTANCE == NULL){
00038                 INSTANCE = new MaracasTools();
00039         }
00040         return INSTANCE;
00041 }
00042 
00043 
00044 /*----------------------------------------------------
00045 Constructor
00046 -----------------------------------------------------*/
00047 MaracasTools::MaracasTools(){
00048         framework = new Framework();
00049         if(( logger=freopen("ToolsLogger.txt","w",stdout)) == NULL){
00050                 exit(-1);
00051         }
00052         std::cout << "Framework Creado "<<std::endl;
00053         
00054         toolsFrame = NULL;
00055         optionsFrame = NULL;
00056         currentToolPanel = NULL;
00057 }
00058 
00059 
00060 /*----------------------------------------------------
00061 It must load all the bundles this class is going to use.
00062 -----------------------------------------------------*/
00063 wxFrame* MaracasTools::GetToolbox(wxWindow* parent){
00064         
00065         
00066         //1. Install ToolboxBundle
00067         //-----------------------------------------------------------------------------------------------
00068         std::cout << "Cargando Toolbox..." <<std::endl;
00069         Bundle* bundle = framework->InstallBundle("ToolboxBundle");
00070         bundle->Start(); 
00071         //-----------------------------------------------------------------------------------------------
00072 
00073         
00074         
00075         
00076         //2. Query the OSGi framework for the IToolbox service (should be delivered in 1).
00077         //-----------------------------------------------------------------------------------------------
00078         BundleContext* ctx = bundle->getBundleContext();
00079         const string interfaceName = "ToolboxService";
00080         ServiceReference* ref = ctx->GetServiceReference(interfaceName); 
00081         if (ref != NULL){
00082                 toolbox = (IToolbox*)ctx->GetService(ref);
00083                 toolbox->SetClient(this); // ACTIVATE THE CALLBACK: WHEN TOOLBOX NEES TO KNOW ANY PARAMETER
00084                                                                   // THE METHOD GetParameter ON THE CLIENT WILL BE CALLED.
00085         }
00086         //-----------------------------------------------------------------------------------------------
00087 
00088 
00089         
00090 
00091         //3.Install tools
00092         //TODO: Replace for discovery of bundles in the maracas' execute directory.
00093         //-----------------------------------------------------------------------------------------------
00094         Bundle* bundle1 = framework->InstallBundle("SimpleSegBundle");
00095         bundle1->Start();
00096 
00097         Bundle* bundle2 = framework->InstallBundle("FM3DBundle");
00098         bundle2->Start();
00099         //-----------------------------------------------------------------------------------------------
00100 
00101 
00102         //4.Build Floating bar
00103         //-----------------------------------------------------------------------------------------------
00104         //FRAME
00105         wxSize _size = wxSize(30,600);
00106         toolsFrame = new wxFrame(parent,-1,_T("Maracas Tools"),wxDefaultPosition,_size);//,wxCAPTION | wxMINIMIZE | wxSTAY_ON_TOP | wxFRAME_TOOL_WINDOW | wxRESIZE_BORDER | wxCLOSE_BOX);
00107 
00108         //SIZER
00109         wxBoxSizer *sizer= new wxBoxSizer(wxVERTICAL);
00110         
00111         //BUTTONS
00112         wxButton* button = NULL;
00113 
00114 
00115         int count = toolbox->GetToolsCount();
00116         
00117                 
00118         //Storyboard
00119         //4.1. MaracasTools asks IToolbox about registered ITools..
00120         //-----------------------------------------------------------------------------------------------
00121         int i=0;
00122 //      char* name = "";
00123         char name[255]="";
00124         for(i=0;i<count;i++){
00125 
00126                 string stName = toolbox->GetToolName(i);
00127                 sprintf(name,"%s",stName.c_str());
00128         
00129                 button = new wxButton(toolsFrame,-1,_T(name));
00130                 SetIndexForButton(button->GetId());
00131 
00132             sizer->Add( button,1, wxALL, 0);
00133                 toolsFrame->Connect(button->GetId(),wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxToolsHandler::OnSelectToolEvent,NULL,this);
00134         }
00135         //-----------------------------------------------------------------------------------------------
00136         
00137         
00138 
00139         //CONFIG FRAME
00140         //-----------------------------------------------------------------------------------------------
00141         toolsFrame->SetSize(25,600);
00142         toolsFrame->SetAutoLayout(true);
00143         toolsFrame->SetSizer(sizer);
00144         toolsFrame->Layout();
00145         
00146 
00147         //BUILD TOOLS OPTIONS FRAME
00148         //-----------------------------------------------------------------------------------------------
00149         wxSize optSize = wxSize(300,300);
00150         optionsFrame = new wxFrame(toolsFrame,-1,_T("Tool"),wxDefaultPosition,optSize);//,wxCAPTION | wxMINIMIZE |  wxSTAY_ON_TOP  | wxRESIZE_BORDER | wxCLOSE_BOX );
00151         
00152 
00153         return toolsFrame;
00154         
00155 }
00156 
00157 
00158 
00159 
00160 
00161 void MaracasTools::OnSelectToolEvent(wxCommandEvent& event){
00162 
00163 
00164         int id = event.GetId();
00165 
00166         int idx = GetIndexForButton(id);
00167         
00168         const string name = toolbox->GetToolName(idx);
00169 
00170         wxSizer* sizer = optionsFrame->GetSizer();
00171 
00172         if (sizer == NULL){
00173                 sizer= new wxBoxSizer(wxBOTH);
00174                 optionsFrame->SetSizer(sizer);
00175         }
00176 
00177 
00178         if (currentToolPanel != NULL){
00179                 //bool t = sizer->Remove(currentToolPanel);
00180                 currentToolPanel->Destroy();
00181         }
00182         
00183 
00184         currentToolPanel = toolbox->GetToolPanel(optionsFrame,idx);
00185         sizer->Add(currentToolPanel, 1, wxEXPAND, 0);
00186         sizer->Layout();
00187         
00188         optionsFrame->SetTitle(_T(name.c_str()));
00189         optionsFrame->Layout();
00190         optionsFrame->Show();
00191 
00192 
00193 }
00194 
00195 
00196 
00197 int MaracasTools::GetIndexForButton(int _wxbuttonid){
00198         
00199         for(int i=0; i < ids.size(); i++){
00200                 if (ids[i] == _wxbuttonid){
00201                         return i;
00202                 }
00203         }
00204         return -1; //NOT FOUND.
00205 }
00206 
00207 
00208 void MaracasTools::SetIndexForButton(int _wxbuttonid){
00209         ids.push_back(_wxbuttonid);
00210         int size = ids.size();
00211 }
00212 
00213 
00214 IParameter* MaracasTools::GetParameter(string name){
00215         
00216         
00217 
00218         IParameter* parameter = NULL;
00219 
00220         if (name == string("MARACAS_MPR_XYZ")){
00221 
00222                 double* xyz = new double[3];
00223                 xyz[0] =widget->GetVtkMPRBaseData()->GetX();
00224                 xyz[1] =widget->GetVtkMPRBaseData()->GetY();
00225                 xyz[2] =widget->GetVtkMPRBaseData()->GetZ();
00226                 parameter = new IParameter(xyz);
00227         }
00228 
00229         else if (name == string("MARACAS_MPR_RENDERER")){
00230                 vtkRenderer* renderer = widget->GetRenderer();
00231                 parameter = new IParameter(renderer);
00232         }
00233 
00234         else if (name == string("MARACAS_MPR_IMAGE")){
00235                 vtkImageData* image = widget->GetVtkMPRBaseData()->GetImageData();
00236                 parameter = new IParameter(image);
00237         }
00238 
00239         else if (name == string("MARACAS_MPR_REFRESH")){
00240                 widget->Refresh();
00241         }
00242 
00243          
00244         return parameter;
00245 }

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1