1 /*---------------------------------------------------------------
3 -----------------------------------------------------------------*/
11 /*-----------------------------------------------------------------*/
13 //disable warnings on 255 char debug symbols
14 #pragma warning (disable : 4786)
17 #include "osgi/framework/Bundle.h"
18 #include "osgi/framework/BundleContext.h"
20 #include "MaracasTools.h"
21 #include "interface/wxWindows/widgets/wxManualSegmentation_MPRWidget.h"
27 /*----------------------------------------------------
28 Instance. Singleton pattern in this class
29 -----------------------------------------------------*/
30 MaracasTools* MaracasTools::INSTANCE = NULL;
33 /*----------------------------------------------------
35 -----------------------------------------------------*/
36 MaracasTools* MaracasTools::GetInstance(){
37 if (INSTANCE == NULL){
38 INSTANCE = new MaracasTools();
44 /*----------------------------------------------------
46 -----------------------------------------------------*/
47 MaracasTools::MaracasTools(){
48 framework = new Framework();
49 if(( logger=freopen("ToolsLogger.txt","w",stdout)) == NULL){
52 std::cout << "Framework Creado "<<std::endl;
56 currentToolPanel = NULL;
60 /*----------------------------------------------------
61 It must load all the bundles this class is going to use.
62 -----------------------------------------------------*/
63 wxFrame* MaracasTools::GetToolbox(wxWindow* parent){
66 //1. Install ToolboxBundle
67 //-----------------------------------------------------------------------------------------------
68 std::cout << "Cargando Toolbox..." <<std::endl;
69 Bundle* bundle = framework->InstallBundle("ToolboxBundle");
71 //-----------------------------------------------------------------------------------------------
76 //2. Query the OSGi framework for the IToolbox service (should be delivered in 1).
77 //-----------------------------------------------------------------------------------------------
78 BundleContext* ctx = bundle->getBundleContext();
79 const string interfaceName = "ToolboxService";
80 ServiceReference* ref = ctx->GetServiceReference(interfaceName);
82 toolbox = (IToolbox*)ctx->GetService(ref);
83 toolbox->SetClient(this); // ACTIVATE THE CALLBACK: WHEN TOOLBOX NEES TO KNOW ANY PARAMETER
84 // THE METHOD GetParameter ON THE CLIENT WILL BE CALLED.
86 //-----------------------------------------------------------------------------------------------
92 //TODO: Replace for discovery of bundles in the maracas' execute directory.
93 //-----------------------------------------------------------------------------------------------
94 Bundle* bundle1 = framework->InstallBundle("SimpleSegBundle");
97 Bundle* bundle2 = framework->InstallBundle("FM3DBundle");
99 //-----------------------------------------------------------------------------------------------
102 //4.Build Floating bar
103 //-----------------------------------------------------------------------------------------------
105 wxSize _size = wxSize(30,600);
106 toolsFrame = new wxFrame(parent,-1,_T("Maracas Tools"),wxDefaultPosition,_size);//,wxCAPTION | wxMINIMIZE | wxSTAY_ON_TOP | wxFRAME_TOOL_WINDOW | wxRESIZE_BORDER | wxCLOSE_BOX);
109 wxBoxSizer *sizer= new wxBoxSizer(wxVERTICAL);
112 wxButton* button = NULL;
115 int count = toolbox->GetToolsCount();
119 //4.1. MaracasTools asks IToolbox about registered ITools..
120 //-----------------------------------------------------------------------------------------------
124 for(i=0;i<count;i++){
126 string stName = toolbox->GetToolName(i);
127 sprintf(name,"%s",stName.c_str());
129 button = new wxButton(toolsFrame,-1,_T(name));
130 SetIndexForButton(button->GetId());
132 sizer->Add( button,1, wxALL, 0);
133 toolsFrame->Connect(button->GetId(),wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxToolsHandler::OnSelectToolEvent,NULL,this);
135 //-----------------------------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------------------------
141 toolsFrame->SetSize(25,600);
142 toolsFrame->SetAutoLayout(true);
143 toolsFrame->SetSizer(sizer);
144 toolsFrame->Layout();
147 //BUILD TOOLS OPTIONS FRAME
148 //-----------------------------------------------------------------------------------------------
149 wxSize optSize = wxSize(300,300);
150 optionsFrame = new wxFrame(toolsFrame,-1,_T("Tool"),wxDefaultPosition,optSize);//,wxCAPTION | wxMINIMIZE | wxSTAY_ON_TOP | wxRESIZE_BORDER | wxCLOSE_BOX );
161 void MaracasTools::OnSelectToolEvent(wxCommandEvent& event){
164 int id = event.GetId();
166 int idx = GetIndexForButton(id);
168 const string name = toolbox->GetToolName(idx);
170 wxSizer* sizer = optionsFrame->GetSizer();
173 sizer= new wxBoxSizer(wxBOTH);
174 optionsFrame->SetSizer(sizer);
178 if (currentToolPanel != NULL){
179 //bool t = sizer->Remove(currentToolPanel);
180 currentToolPanel->Destroy();
184 currentToolPanel = toolbox->GetToolPanel(optionsFrame,idx);
185 sizer->Add(currentToolPanel, 1, wxEXPAND, 0);
188 optionsFrame->SetTitle(_T(name.c_str()));
189 optionsFrame->Layout();
190 optionsFrame->Show();
197 int MaracasTools::GetIndexForButton(int _wxbuttonid){
199 for(int i=0; i < ids.size(); i++){
200 if (ids[i] == _wxbuttonid){
204 return -1; //NOT FOUND.
208 void MaracasTools::SetIndexForButton(int _wxbuttonid){
209 ids.push_back(_wxbuttonid);
210 int size = ids.size();
214 IParameter* MaracasTools::GetParameter(string name){
218 IParameter* parameter = NULL;
220 if (name == string("MARACAS_MPR_XYZ")){
222 double* xyz = new double[3];
223 xyz[0] =widget->GetVtkMPRBaseData()->GetX();
224 xyz[1] =widget->GetVtkMPRBaseData()->GetY();
225 xyz[2] =widget->GetVtkMPRBaseData()->GetZ();
226 parameter = new IParameter(xyz);
229 else if (name == string("MARACAS_MPR_RENDERER")){
230 vtkRenderer* renderer = widget->GetRenderer();
231 parameter = new IParameter(renderer);
234 else if (name == string("MARACAS_MPR_IMAGE")){
235 vtkImageData* image = widget->GetVtkMPRBaseData()->GetImageData();
236 parameter = new IParameter(image);
239 else if (name == string("MARACAS_MPR_REFRESH")){