/*--------------------------------------------------------------- INCLUDES WXWIDGETS -----------------------------------------------------------------*/ #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif /*-----------------------------------------------------------------*/ //disable warnings on 255 char debug symbols #pragma warning (disable : 4786) #include "osgi/framework/Bundle.h" #include "osgi/framework/BundleContext.h" #include "MaracasTools.h" #include "interface/wxWindows/widgets/wxManualSegmentation_MPRWidget.h" #include using namespace std; /*---------------------------------------------------- Instance. Singleton pattern in this class -----------------------------------------------------*/ MaracasTools* MaracasTools::INSTANCE = NULL; /*---------------------------------------------------- GetInstance method -----------------------------------------------------*/ MaracasTools* MaracasTools::GetInstance(){ if (INSTANCE == NULL){ INSTANCE = new MaracasTools(); } return INSTANCE; } /*---------------------------------------------------- Constructor -----------------------------------------------------*/ MaracasTools::MaracasTools(){ framework = new Framework(); if(( logger=freopen("ToolsLogger.txt","w",stdout)) == NULL){ exit(-1); } std::cout << "Framework Creado "<InstallBundle("ToolboxBundle"); bundle->Start(); //----------------------------------------------------------------------------------------------- //2. Query the OSGi framework for the IToolbox service (should be delivered in 1). //----------------------------------------------------------------------------------------------- BundleContext* ctx = bundle->getBundleContext(); const string interfaceName = "ToolboxService"; ServiceReference* ref = ctx->GetServiceReference(interfaceName); if (ref != NULL){ toolbox = (IToolbox*)ctx->GetService(ref); toolbox->SetClient(this); // ACTIVATE THE CALLBACK: WHEN TOOLBOX NEES TO KNOW ANY PARAMETER // THE METHOD GetParameter ON THE CLIENT WILL BE CALLED. } //----------------------------------------------------------------------------------------------- //3.Install tools //TODO: Replace for discovery of bundles in the maracas' execute directory. //----------------------------------------------------------------------------------------------- Bundle* bundle1 = framework->InstallBundle("SimpleSegBundle"); bundle1->Start(); Bundle* bundle2 = framework->InstallBundle("FM3DBundle"); bundle2->Start(); //----------------------------------------------------------------------------------------------- //4.Build Floating bar //----------------------------------------------------------------------------------------------- //FRAME wxSize _size = wxSize(30,600); toolsFrame = new wxFrame(parent,-1,_T("Maracas Tools"),wxDefaultPosition,_size);//,wxCAPTION | wxMINIMIZE | wxSTAY_ON_TOP | wxFRAME_TOOL_WINDOW | wxRESIZE_BORDER | wxCLOSE_BOX); //SIZER wxBoxSizer *sizer= new wxBoxSizer(wxVERTICAL); //BUTTONS wxButton* button = NULL; int count = toolbox->GetToolsCount(); //Storyboard //4.1. MaracasTools asks IToolbox about registered ITools.. //----------------------------------------------------------------------------------------------- int i=0; // char* name = ""; char name[255]=""; for(i=0;iGetToolName(i); sprintf(name,"%s",stName.c_str()); button = new wxButton(toolsFrame,-1,_T(name)); SetIndexForButton(button->GetId()); sizer->Add( button,1, wxALL, 0); toolsFrame->Connect(button->GetId(),wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxToolsHandler::OnSelectToolEvent,NULL,this); } //----------------------------------------------------------------------------------------------- //CONFIG FRAME //----------------------------------------------------------------------------------------------- toolsFrame->SetSize(25,600); toolsFrame->SetAutoLayout(true); toolsFrame->SetSizer(sizer); toolsFrame->Layout(); //BUILD TOOLS OPTIONS FRAME //----------------------------------------------------------------------------------------------- wxSize optSize = wxSize(300,300); optionsFrame = new wxFrame(toolsFrame,-1,_T("Tool"),wxDefaultPosition,optSize);//,wxCAPTION | wxMINIMIZE | wxSTAY_ON_TOP | wxRESIZE_BORDER | wxCLOSE_BOX ); return toolsFrame; } void MaracasTools::OnSelectToolEvent(wxCommandEvent& event){ int id = event.GetId(); int idx = GetIndexForButton(id); const string name = toolbox->GetToolName(idx); wxSizer* sizer = optionsFrame->GetSizer(); if (sizer == NULL){ sizer= new wxBoxSizer(wxBOTH); optionsFrame->SetSizer(sizer); } if (currentToolPanel != NULL){ //bool t = sizer->Remove(currentToolPanel); currentToolPanel->Destroy(); } currentToolPanel = toolbox->GetToolPanel(optionsFrame,idx); sizer->Add(currentToolPanel, 1, wxEXPAND, 0); sizer->Layout(); optionsFrame->SetTitle(_T(name.c_str())); optionsFrame->Layout(); optionsFrame->Show(); } int MaracasTools::GetIndexForButton(int _wxbuttonid){ for(int i=0; i < ids.size(); i++){ if (ids[i] == _wxbuttonid){ return i; } } return -1; //NOT FOUND. } void MaracasTools::SetIndexForButton(int _wxbuttonid){ ids.push_back(_wxbuttonid); int size = ids.size(); } IParameter* MaracasTools::GetParameter(string name){ IParameter* parameter = NULL; if (name == string("MARACAS_MPR_XYZ")){ double* xyz = new double[3]; xyz[0] =widget->GetVtkMPRBaseData()->GetX(); xyz[1] =widget->GetVtkMPRBaseData()->GetY(); xyz[2] =widget->GetVtkMPRBaseData()->GetZ(); parameter = new IParameter(xyz); } else if (name == string("MARACAS_MPR_RENDERER")){ vtkRenderer* renderer = widget->GetRenderer(); parameter = new IParameter(renderer); } else if (name == string("MARACAS_MPR_IMAGE")){ vtkImageData* image = widget->GetVtkMPRBaseData()->GetImageData(); parameter = new IParameter(image); } else if (name == string("MARACAS_MPR_REFRESH")){ widget->Refresh(); } return parameter; }