#include "vtkKWMainWindowInteractor.h" #include "vtkObjectFactory.h" #include "vtkKWLoadSaveDialog.h" #include "vtkKWWidgetsPaths.h" #include "vtkKWNotebook.h" #include "vtkStringArray.h" #include #include #include "vtkKWApplication.h" #include "vtkKWPageView.h" #include #include "vtkKWAnimationWidget.h" //#include "vtkKWSequenceAnimationWidget.h" #include #include #include #include #include #include #include // #include #include #include #include #include #include #include #include #include #include // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "vtkKWInternationalization.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWMainWindowInteractor ); vtkCxxRevisionMacro( vtkKWMainWindowInteractor, "$Revision: 1.8 $"); //---------------------------------------------------------------------------- vtkKWMainWindowInteractor::vtkKWMainWindowInteractor() { this->DataManager = vtkDataManager::New(); this->DataManagerCallback = vtkDataManagerCallback::New(); this->MainCallback = vtkKWMainCallback::New(); this->ManagerWidget = vtkKWDataManagerWidget::New(); this->ManagerDialog = vtkKWTopLevel::New(); this->ToolboxNotebook = vtkKWNotebook::New(); this->DataManagerCallback->SetDataManager(this->DataManager); this->DataManager->AddObserver(vtkDataManager::MetaDataSetPickEvent, this->MainCallback); this->PanelSplitFrame = vtkKWSplitFrame::New(); } //---------------------------------------------------------------------------- vtkKWMainWindowInteractor::~vtkKWMainWindowInteractor() { std::cout<<"deleting mainframeinteractor"<DataManager->Delete(); this->DataManagerCallback->Delete(); this->MainCallback->Delete(); this->ManagerWidget->Delete(); this->ToolboxNotebook->Delete(); this->PanelSplitFrame->Delete(); this->ManagerDialog->Delete(); for (int i=this->GetViewNotebook()->GetNumberOfPages()-1; i>=0; i--) { vtkKWFrame* frame = this->GetViewNotebook()->GetFrame(i); if (frame) frame->RemoveAllChildren(); this->GetViewNotebook()->RemovePage (i); } for (int i=this->ToolboxNotebook->GetNumberOfPages()-1; i>=0; i--) { vtkKWFrame* frame = this->ToolboxNotebook->GetFrame(i); if (frame) frame->RemoveAllChildren(); this->ToolboxNotebook->RemovePage (i); } } vtkKWPageView* vtkKWMainWindowInteractor::CreateNewPage (const char* name, vtkImageData* image) { if (!name) return NULL; int id = this->GetViewNotebook()->AddPage (name); this->GetViewNotebook()->SetPageTag (id, 0); vtkKWPageView* viewframe = vtkKWPageView::New(); viewframe->SetParent(this->GetViewNotebook()->GetFrame (id)); viewframe->Create(); viewframe->SetTag (name); this->Script("pack %s -fill both -side top -expand t", viewframe->GetWidgetName()); viewframe->SetImage (image); this->GetViewNotebook()->RaisePage (id); viewframe->GetView4()->GetRenderWindowInteractor()->AddObserver(vtkCommand::LeftButtonPressEvent, this->DataManagerCallback); viewframe->Delete(); return this->GetPage (name); } void vtkKWMainWindowInteractor::RemovePage (const char* title) { vtkKWFrame* frame = this->GetViewNotebook()->GetFrame(title); if (frame) frame->RemoveAllChildren(); this->GetViewNotebook()->RemovePage (title); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::SetDataManager (vtkDataManager* manager) { if (this->DataManager == manager) { return; } if (this->DataManager) { this->DataManager->UnRegister(this); } this->DataManager = manager; if (this->DataManager) { this->DataManager->Register(this); } if (this->DataManager) { this->DataManagerCallback->SetDataManager(this->DataManager); this->DataManager->AddObserver(vtkDataManager::MetaDataSetPickEvent, this->MainCallback); } this->Update(); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::CreateWidget() { if (this->IsCreated()) { vtkErrorMacro("class already created"); return; } this->Superclass::CreateWidget(); // first creation : if (this->GetViewNotebook()->GetNumberOfPages() == 0 ) { this->CreateNewPage("General-View", NULL); } this->GetFileMenu()->InsertCommand(3, "Popup ...", this, "PopupManager"); this->MainCallback->SetApplication (this->GetApplication()); this->PanelSplitFrame->SetParent(this->GetMainPanelFrame()); this->PanelSplitFrame->Create(); this->PanelSplitFrame->SetOrientationToVertical(); this->PanelSplitFrame->SetReliefToFlat(); this->PanelSplitFrame->SetBorderWidth(2); this->PanelSplitFrame->SetExpandableFrameToBothFrames(); this->PanelSplitFrame->SetFrame1MinimumSize(250); this->PanelSplitFrame->SetFrame2MinimumSize(120); this->PanelSplitFrame->SetSeparatorPosition (1000); this->Script("pack %s -fill both -side top -anchor nw -expand yes", this->PanelSplitFrame->GetWidgetName()); vtkKWFrame* temp = vtkKWFrame::New(); temp->SetParent (this->PanelSplitFrame->GetFrame2()); temp->Create(); vtkKWLabel* label = vtkKWLabel::New(); label->SetParent (temp); label->Create(); label->SetText ("Data Manager"); vtkKWPushButton* button = vtkKWPushButton::New(); button->SetParent (temp); button->Create(); button->SetImageToPixels(image_popup, image_popup_width, image_popup_height, image_popup_pixel_size, image_popup_length); button->SetCommand (this, "PopupManager"); button->SetBalloonHelpString("Popup the Data Manager"); this->Script("pack %s -side left -anchor nw -expand n", label->GetWidgetName()); this->Script("pack %s -side right -anchor ne -expand n", button->GetWidgetName()); this->Script("pack %s -side top -fill x -anchor nw -expand n", temp->GetWidgetName()); this->ManagerWidget->SetParent(this->PanelSplitFrame->GetFrame2()); this->ManagerWidget->SetParentObject (this); this->ManagerWidget->Create(); this->ManagerWidget->SetHeight (60); this->ToolboxNotebook->SetParent(this->PanelSplitFrame->GetFrame1()); this->ToolboxNotebook->Create(); this->PackSelf(); vtkKWDataBrowser* databrowser = vtkKWDataBrowser::New(); this->LoadToolBox(databrowser, "Visualization"); databrowser->Delete(); vtkKWMeshTools* MeshTools = vtkKWMeshTools::New(); this->LoadToolBox(MeshTools, "Mesh Tools"); MeshTools->Delete(); vtkKWSequencer* Sequencer = vtkKWSequencer::New(); this->LoadToolBox(Sequencer, "Sequencer"); Sequencer->Delete(); } void vtkKWMainWindowInteractor::PackSelf() { this->Superclass::PackSelf(); if (this->ManagerWidget->IsCreated()) { this->Script("pack %s -fill both -side top -anchor nw -expand yes", this->ManagerWidget->GetWidgetName()); } if (this->ToolboxNotebook->IsCreated()) { this->Script( "pack %s -side top -anchor nw -fill both -expand yes -padx 2 -pady 2", this->ToolboxNotebook->GetWidgetName()); } for (unsigned int i=0; iToolBoxList.size(); i++) { if (this->ToolBoxList[i]->IsCreated()) { this->Script( "pack %s -side top -anchor nw -fill x -expand yes -padx 2 -pady 2", this->ToolBoxList[i]->GetWidgetName()); } } } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::CreateAliases () { vtkKWApplication *app = this->GetApplication(); app->Script("alias m_window %s", this->GetTclName()); if (this->GetCurrentPage()) { app->Script("alias m_multiviews [m_window GetCurrentPage]"); app->Script("alias m_v1 [m_multiviews GetView1]"); app->Script("alias m_v2 [m_multiviews GetView2]"); app->Script("alias m_v3 [m_multiviews GetView3]"); app->Script("alias m_v4 [m_multiviews GetView4]"); } app->Script("alias m_manager [m_window GetDataManager]"); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::OnMenuFileOpen() { vtkKWLoadSaveDialog *dialog = vtkKWLoadSaveDialog::New() ; dialog->SetParent(this); dialog->Create(); dialog->MultipleSelectionOn(); //dialog->GetFileBrowserWidget()->DirectoryExplorerVisibilityOff (); dialog->RetrieveLastPathFromRegistry("DataPath"); dialog->SetTitle ("Open a File"); dialog->SetFileTypes (kwsupportedformats.c_str()); if ( dialog->Invoke () == 0 ) { dialog->Delete(); return ; } for (int i=0; iGetNumberOfFileNames(); i++) { try { this->DataManager->ReadFile (dialog->GetFileNames()->GetValue (i)); } catch (vtkErrorCode::ErrorIds) { vtkKWMessageDialog::PopupMessage(this->GetApplication(), this->GetParentTopLevel(), "Error", "Cannot open file !\nPlease check the log window for details.", vtkKWMessageDialog::ErrorIcon); } } dialog->SaveLastPathToRegistry("DataPath"); dialog->Delete(); this->Update(); if (this->GetCurrentPage()) this->GetCurrentPage()->Render(); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::OnMenuFileOpen4D() { vtkKWSequenceImporter *dlg = vtkKWSequenceImporter::New(); dlg->SetApplication(this->GetApplication()); dlg->Create(); dlg->SetDisplayPositionToDefault(); dlg->SetPosition (100,100); dlg->Invoke(); if (dlg->GetStatus() == vtkKWDialog::StatusOK) { vtkMetaDataSetSequence* sequence = dlg->GetSequence(); this->DataManager->AddMetaDataSet(sequence); this->Update(); if (this->GetCurrentPage()) this->GetCurrentPage()->Render(); } // KWWidgets bug, deleting the importer provocate plenty of vtkErrors dlg->Delete(); } void vtkKWMainWindowInteractor::Update() { std::vector metadatasetlist = this->DataManager->GetMetaDataSetList(); for (unsigned int i=0; iGetPage(metadatasetlist[i]->GetTag ())) continue; // means the dataset hasn't been added if (metadatasetlist[i]->GetType() == vtkMetaDataSet::VTK_META_IMAGE_DATA) { vtkKWPageView* frame = this->CreateNewPage (metadatasetlist[i]->GetName(), vtkImageData::SafeDownCast (metadatasetlist[i]->GetDataSet()) ); metadatasetlist[i]->SetProperty (frame->GetView4()->GetVolumeProperty()); } else { metadatasetlist[i]->GetDataSet()->RequestExactExtentOn(); std::vector list = this->GetCurrentPage()->AddDataSet (metadatasetlist[i]->GetDataSet(), vtkProperty::SafeDownCast (metadatasetlist[i]->GetProperty()) ); for (unsigned int j=0; jAddActor (list[j]); } metadatasetlist[i]->SetTag (this->GetCurrentPage()->GetTag()); } for (unsigned int j=0; jToolBoxList.size(); j++) { this->ToolBoxList[j]->Update(); } if (this->ManagerDialog->IsCreated()) { vtkKWDataManagerWidget* wid = vtkKWDataManagerWidget::SafeDownCast (this->ManagerDialog->GetNthChild (0)); if (wid) wid->Update(); } this->ManagerWidget->Update(); } void vtkKWMainWindowInteractor::LoadToolBox (vtkKWToolBox* toolbox, const char* name) { if (!toolbox->IsCreated()) { toolbox->GetToolbar()->SetParent (this->GetMainToolbarSet()->GetToolbarsFrame()); toolbox->GetToolbar()->Create(); if (toolbox->GetToolType() == vtkKWToolBox::TOOL_HORIZONTAL) { int id = this->GetSecondaryNotebook()->AddPage (name); toolbox->SetParent (this->GetSecondaryNotebook()->GetFrame (id)); } else { int id = this->ToolboxNotebook->AddPage (name); toolbox->SetParent (this->ToolboxNotebook->GetFrame (id)); } toolbox->SetParentObject(this); toolbox->Create(); if ( toolbox->GetToolbar()->IsCreated() && (toolbox->GetToolbar()->GetNumberOfWidgets() > 0) ) { this->GetMainToolbarSet()->AddToolbar (toolbox->GetToolbar()); } } toolbox->SetMetaDataSetChangedCommand(this, "Update"); this->ToolBoxList.push_back (toolbox); this->Update(); this->PackSelf(); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::OnMenuFileOpenDICOM () { vtkKWDICOMImporter *dlg = vtkKWDICOMImporter::New(); dlg->SetApplication(this->GetApplication()); dlg->Create(); dlg->SetDisplayPositionToDefault(); dlg->SetPosition (100,100); dlg->Invoke(); if (dlg->GetStatus() != vtkKWDialog::StatusOK) { dlg->Delete(); return; } vtkKWWindowBase *win = this->GetApplication()->GetNthWindow(0); if (!win) return; win->SetStatusText(ks_("Progress|Importing DICOM volumes...")); win->GetProgressGauge()->SetValue(0); std::vector outputVolumes = dlg->GetGDCMImporter()->GetDICOMVolumeList(); for (unsigned int i=0; iGetProgressGauge()->SetValue((int)(100.0 * i / outputVolumes.size())); try { outputVolumes[i]->Build(); } catch (...) { vtkKWMessageDialog::PopupMessage(this->GetApplication(), this->GetParentTopLevel(), "Error", "An error occured when importing DICOMs, skipping the file !\nPlease check the log window for details.", vtkKWMessageDialog::ErrorIcon); continue; } vtkMetaImageData* metadataset = vtkMetaImageData::New(); try { typedef itk::Image FloatImageType; typedef itk::ImageToVTKImageFilter ConverterType; ConverterType::Pointer converter = ConverterType::New(); converter->SetInput (outputVolumes[i]->GetImage()); converter->Update(); // as the plug between ITK and VTK pipelines does not work // we have to copy the image vtkImageData* input = vtkImageData::New(); input->DeepCopy(converter->GetOutput()); metadataset->SetDataSet(input); input->Delete(); const char* defaultname = this->DataManager->CreateDefaultName(vtkMetaDataSet::VTK_META_IMAGE_DATA, outputVolumes[i]->GetDescription().c_str()); metadataset->SetName (defaultname); delete [] defaultname; this->DataManager->AddMetaDataSet (metadataset); metadataset->Delete(); } catch (...) { metadataset->Delete(); vtkKWMessageDialog::PopupMessage(this->GetApplication(), this->GetParentTopLevel(), "Error", "Error when converting image, skipping...\nPlease check the log window for details.", vtkKWMessageDialog::ErrorIcon); continue; } } vtksys_stl::string end_msg(win->GetStatusText()); end_msg += " -- "; end_msg += ks_("Progress|Done"); win->SetStatusText(end_msg.c_str()); win->GetProgressGauge()->SetValue(0); dlg->Delete(); this->Update(); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::OnDataSetAttributes(void) { std::cout<<"still not implemented"<ManagerWidget->GetSelectedMetaDataSet(); if (!metadataset) return; vtkKWLoadSaveDialog *dialog = vtkKWLoadSaveDialog::New() ; dialog->SetParent(this); dialog->Create(); dialog->MultipleSelectionOff(); if (vtkMetaDataSetSequence::SafeDownCast(metadataset)) dialog->ChooseDirectoryOn(); dialog->SaveDialogOn (); dialog->RetrieveLastPathFromRegistry("DataPath"); dialog->SetTitle ("Save dataset to file"); // int val = metadataset->GetType(); // std::string ext; // switch (val) // { // case vtkMetaDataSet::VTK_META_IMAGE_DATA : // ext = kwsupportedimageformats_global + kwsupportedimageformats; // break; // case vtkMetaDataSet::VTK_META_SURFACE_MESH : // case vtkMetaDataSet::VTK_META_VOLUME_MESH : // ext = kwsupportedmeshformats_global + kwsupportedmeshformats; // break; // default : // ext = kwsupportedformats; // break; // } // dialog->SetFileTypes (ext.c_str()); // dialog->SetDefaultExtension (this->defaultextensions.c_str()); if ( dialog->Invoke () == 0 ) { dialog->Delete(); return ; } const char* filename = dialog->GetFileName(); try { //metadataset->Write (filename); vtkDataManagerWriter* writer = vtkDataManagerWriter::New(); writer->SetInput(metadataset->GetDataSet()); writer->SetDataManager(this->DataManager); writer->SetFileName(filename); writer->Write(); } catch (...) { std::cout<<"cannot save file "<GetFileName()<SaveLastPathToRegistry("DataPath"); dialog->Delete(); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::OnDataSetDelete(void) { vtkMetaDataSet* metadataset = this->ManagerWidget->GetSelectedMetaDataSet(); if (!metadataset) return; if (this->GetPage(metadataset->GetTag())) { this->GetPage(metadataset->GetTag())->RemoveDataSet (metadataset->GetDataSet()); } if (metadataset->GetType() == vtkMetaDataSet::VTK_META_IMAGE_DATA) { this->RemovePage(metadataset->GetTag()); } this->DataManager->RemoveMetaDataSet (metadataset); this->Update(); if (this->GetCurrentPage()) this->GetCurrentPage()->Render(); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::PopdownManager () { this->PanelSplitFrame->Frame2VisibilityOn (); this->ManagerDialog->Withdraw(); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::PopupManager () { if (!this->ManagerDialog->IsCreated()) { this->ManagerDialog->SetMasterWindow(this); this->ManagerDialog->SetApplication(this->GetApplication()); this->ManagerDialog->Create(); this->ManagerDialog->SetTitle("The Data Manager"); this->ManagerDialog->SetDeleteWindowProtocolCommand(this, "PopdownManager"); vtkKWDataManagerWidget* widget = vtkKWDataManagerWidget::New(); widget->SetParent(this->ManagerDialog); widget->Create(); this->Script("pack %s -fill both -side top -expand t", widget->GetWidgetName()); widget->SetParentObject (this); widget->Update(); widget->Delete(); } // Get the position of the mouse, the size of the top level window. int px, py, tw, th, sw, sh; vtkKWTkUtilities::GetMousePointerCoordinates(this, &px, &py); vtkKWTkUtilities::GetWidgetRequestedSize(this->ManagerDialog, &tw, &th); vtkKWTkUtilities::GetScreenSize(this, &sw, &sh); px -= tw / 2; if (px + tw > sw) { px -= (px + tw - sw); } if (px < 0) { px = 0; } py -= th / 2; if (py + th > sh) { py -= (py + th - sh); } if (py < 0) { py = 0; } this->ManagerDialog->SetPosition(px, py); this->ManagerDialog->DeIconify(); this->ManagerDialog->Raise(); this->PanelSplitFrame->Frame2VisibilityOff (); } //---------------------------------------------------------------------------- void vtkKWMainWindowInteractor::OnLightProperties() { std::cout<<"still not implemented"<GetPage(metadataset->GetTag())) { this->GetPage(metadataset->GetTag())->RemoveDataSet (metadataset->GetDataSet()); } if (metadataset->GetType() == vtkMetaDataSet::VTK_META_IMAGE_DATA) { if (this->GetPage(metadataset->GetTag())) this->RemovePage(metadataset->GetTag()); } this->DataManager->RemoveMetaDataSet (metadataset); this->Update(); if (this->GetCurrentPage()) this->GetCurrentPage()->Render(); }