1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 /*---------------------------------------------------------------
28 -----------------------------------------------------------------*/
29 #include "wx/wxprec.h"
36 /*-----------------------------------------------------------------*/
38 //disable warnings on 255 char debug symbols
39 #pragma warning (disable : 4786)
42 #include "osgi/framework/Bundle.h"
43 #include "osgi/framework/BundleContext.h"
45 #include "MaracasTools.h"
46 #include "interface/wxWindows/widgets/wxManualSegmentation_MPRWidget.h"
52 /*----------------------------------------------------
53 Instance. Singleton pattern in this class
54 -----------------------------------------------------*/
55 MaracasTools* MaracasTools::INSTANCE = NULL;
58 /*----------------------------------------------------
60 -----------------------------------------------------*/
61 MaracasTools* MaracasTools::GetInstance(){
62 if (INSTANCE == NULL){
63 INSTANCE = new MaracasTools();
69 /*----------------------------------------------------
71 -----------------------------------------------------*/
72 MaracasTools::MaracasTools(){
73 framework = new Framework();
74 if(( logger=freopen("ToolsLogger.txt","w",stdout)) == NULL){
77 std::cout << "Framework Creado "<<std::endl;
81 currentToolPanel = NULL;
85 /*----------------------------------------------------
86 It must load all the bundles this class is going to use.
87 -----------------------------------------------------*/
88 wxFrame* MaracasTools::GetToolbox(wxWindow* parent){
91 //1. Install ToolboxBundle
92 //-----------------------------------------------------------------------------------------------
93 std::cout << "Cargando Toolbox..." <<std::endl;
94 Bundle* bundle = framework->InstallBundle("ToolboxBundle");
96 //-----------------------------------------------------------------------------------------------
101 //2. Query the OSGi framework for the IToolbox service (should be delivered in 1).
102 //-----------------------------------------------------------------------------------------------
103 BundleContext* ctx = bundle->getBundleContext();
104 const string interfaceName = "ToolboxService";
105 ServiceReference* ref = ctx->GetServiceReference(interfaceName);
107 toolbox = (IToolbox*)ctx->GetService(ref);
108 toolbox->SetClient(this); // ACTIVATE THE CALLBACK: WHEN TOOLBOX NEES TO KNOW ANY PARAMETER
109 // THE METHOD GetParameter ON THE CLIENT WILL BE CALLED.
111 //-----------------------------------------------------------------------------------------------
117 //TODO: Replace for discovery of bundles in the maracas' execute directory.
118 //-----------------------------------------------------------------------------------------------
119 Bundle* bundle1 = framework->InstallBundle("SimpleSegBundle");
122 Bundle* bundle2 = framework->InstallBundle("FM3DBundle");
124 //-----------------------------------------------------------------------------------------------
127 //4.Build Floating bar
128 //-----------------------------------------------------------------------------------------------
130 wxSize _size = wxSize(30,600);
131 toolsFrame = new wxFrame(parent,-1,_T("Maracas Tools"),wxDefaultPosition,_size);//,wxCAPTION | wxMINIMIZE | wxSTAY_ON_TOP | wxFRAME_TOOL_WINDOW | wxRESIZE_BORDER | wxCLOSE_BOX);
134 wxBoxSizer *sizer= new wxBoxSizer(wxVERTICAL);
137 wxButton* button = NULL;
140 int count = toolbox->GetToolsCount();
144 //4.1. MaracasTools asks IToolbox about registered ITools..
145 //-----------------------------------------------------------------------------------------------
149 for(i=0;i<count;i++){
151 string stName = toolbox->GetToolName(i);
152 sprintf(name,"%s",stName.c_str());
154 button = new wxButton(toolsFrame,-1,_T(name));
155 SetIndexForButton(button->GetId());
157 sizer->Add( button,1, wxALL, 0);
158 toolsFrame->Connect(button->GetId(),wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxToolsHandler::OnSelectToolEvent,NULL,this);
160 //-----------------------------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------------------------
166 toolsFrame->SetSize(25,600);
167 toolsFrame->SetAutoLayout(true);
168 toolsFrame->SetSizer(sizer);
169 toolsFrame->Layout();
172 //BUILD TOOLS OPTIONS FRAME
173 //-----------------------------------------------------------------------------------------------
174 wxSize optSize = wxSize(300,300);
175 optionsFrame = new wxFrame(toolsFrame,-1,_T("Tool"),wxDefaultPosition,optSize);//,wxCAPTION | wxMINIMIZE | wxSTAY_ON_TOP | wxRESIZE_BORDER | wxCLOSE_BOX );
186 void MaracasTools::OnSelectToolEvent(wxCommandEvent& event){
189 int id = event.GetId();
191 int idx = GetIndexForButton(id);
193 const string name = toolbox->GetToolName(idx);
195 wxSizer* sizer = optionsFrame->GetSizer();
198 sizer= new wxBoxSizer(wxBOTH);
199 optionsFrame->SetSizer(sizer);
203 if (currentToolPanel != NULL){
204 //bool t = sizer->Remove(currentToolPanel);
205 currentToolPanel->Destroy();
209 currentToolPanel = toolbox->GetToolPanel(optionsFrame,idx);
210 sizer->Add(currentToolPanel, 1, wxEXPAND, 0);
213 optionsFrame->SetTitle(_T(name.c_str()));
214 optionsFrame->Layout();
215 optionsFrame->Show();
222 int MaracasTools::GetIndexForButton(int _wxbuttonid){
224 for(int i=0; i < ids.size(); i++){
225 if (ids[i] == _wxbuttonid){
229 return -1; //NOT FOUND.
233 void MaracasTools::SetIndexForButton(int _wxbuttonid){
234 ids.push_back(_wxbuttonid);
235 int size = ids.size();
239 IParameter* MaracasTools::GetParameter(string name){
243 IParameter* parameter = NULL;
245 if (name == string("MARACAS_MPR_XYZ")){
247 double* xyz = new double[3];
248 xyz[0] =widget->GetVtkMPRBaseData()->GetX();
249 xyz[1] =widget->GetVtkMPRBaseData()->GetY();
250 xyz[2] =widget->GetVtkMPRBaseData()->GetZ();
251 parameter = new IParameter(xyz);
254 else if (name == string("MARACAS_MPR_RENDERER")){
255 vtkRenderer* renderer = widget->GetRenderer();
256 parameter = new IParameter(renderer);
259 else if (name == string("MARACAS_MPR_IMAGE")){
260 vtkImageData* image = widget->GetVtkMPRBaseData()->GetImageData();
261 parameter = new IParameter(image);
264 else if (name == string("MARACAS_MPR_REFRESH")){