#include "vtkKWSequenceImporter.h" #include "vtkObjectFactory.h" #include "vtkKWApplication.h" #include "vtkKWWizardWidget.h" #include "vtkKWWizardStep.h" #include "vtkKWWizardWorkflow.h" #include "vtkKWLabel.h" #include "vtkKWIcon.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWSequenceImporter ); vtkCxxRevisionMacro(vtkKWSequenceImporter, "$Revision: 1.3 $"); //---------------------------------------------------------------------------- vtkKWSequenceImporter::vtkKWSequenceImporter() { this->Page1 = vtkKWSequenceImporterPage1::New(); this->Page2 = vtkKWSequenceImporterPage2::New(); this->Page1Step = vtkKWWizardStep::New(); this->Page2Step = vtkKWWizardStep::New(); this->Sequence = vtkMetaDataSetSequence::New(); } //---------------------------------------------------------------------------- vtkKWSequenceImporter::~vtkKWSequenceImporter() { std::cout<<"deleting sequence importer"<Sequence->Delete(); this->Page1->Delete(); this->Page1Step->Delete(); this->Page2->Delete(); this->Page2Step->Delete(); if (this->GetWizardWidget() && this->GetWizardWidget()->GetClientArea()) this->GetWizardWidget()->GetClientArea()->RemoveAllChildren(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::CreatePage1() { vtkKWWizardWidget *wizard_widget = this->GetWizardWidget(); this->Page1Step->SetName("Page1Step"); this->Page1Step->SetDescription("import and reorder your sequence dataset files"); this->Page1Step->SetShowUserInterfaceCommand( this, "ShowPage1UserInterfaceCallback"); this->Page1Step->SetHideUserInterfaceCommand(wizard_widget, "ClearPage"); this->Page1Step->SetValidateCommand(this, "ValidatePage1Callback"); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::CreatePage2() { vtkKWWizardWidget *wizard_widget = this->GetWizardWidget(); this->Page2Step->SetName("Page2Step"); this->Page2Step->SetDescription("Sum up !"); this->Page2Step->SetShowUserInterfaceCommand( this, "ShowPage2UserInterfaceCallback"); this->Page2Step->SetHideUserInterfaceCommand(wizard_widget, "ClearPage"); this->Page2Step->SetValidateCommand(this, "ValidatePage2Callback"); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::CreateWidget() { // Check if already created if (this->IsCreated()) { vtkErrorMacro("class already created"); return; } // Call the superclass to create the whole widget this->Superclass::CreateWidget(); this->SetSize(550,400); this->SetTitle("Sequence Importer"); this->CreatePage1(); this->CreatePage2(); vtkKWWizardWorkflow *wizard_workflow = this->GetWizardWorkflow(); vtkKWWizardWidget *wizard_widget = this->GetWizardWidget(); wizard_widget->GetTitleIconLabel()->SetImageToPixels( image_mplayer, image_mplayer_width, image_mplayer_height, image_mplayer_pixel_size, image_mplayer_length); // ----------------------------------------------------------------- // steps wizard_workflow->AddNextStep(this->Page1Step); wizard_workflow->AddNextStep(this->Page2Step); wizard_workflow->CreateGoToTransition(this->Page1Step, this->Page2Step); // ----------------------------------------------------------------- // Initial and finish step wizard_workflow->SetInitialStep(this->Page1Step); wizard_workflow->SetFinishStep(this->Page2Step); wizard_workflow->SetNavigationStackedChangedCommand (this, "NavigationStackedChangeCallback"); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::NavigationStackedChangeCallback() { vtkKWWizardWorkflow *wizard_workflow = this->GetWizardWorkflow(); vtkKWWizardStep* current_step = wizard_workflow->GetCurrentStep(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::ShowPage1UserInterfaceCallback() { if (!this->Page1->IsCreated()) { this->Page1->SetParent(this->GetWizardWidget()->GetClientArea()); this->Page1->Create(); } this->Script("pack %s -side top -expand y -fill both ", this->Page1->GetWidgetName()); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::ShowPage2UserInterfaceCallback() { if (!this->Page2->IsCreated()) { this->Page2->SetParent(this->GetWizardWidget()->GetClientArea()); this->Page2->Create(); } this->Page2->SetSequence (this->Sequence); this->Script("pack %s -side top -expand y -fill both ", this->Page2->GetWidgetName()); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::ValidatePage1Callback() { vtkKWWizardWorkflow *wizard_workflow = this->GetWizardWorkflow(); if (!this->Page1->AreAllFilesValid()) { this->GetWizardWidget()->SetErrorText("some files are not valid \nplease remove them !"); wizard_workflow->PushInput(vtkKWWizardStep::GetValidationFailedInput()); wizard_workflow->ProcessInputs(); return; } std::cout<<"building sequence ..."<Page1->GetDataSetType(); this->Sequence->RemoveAllMetaDataSets(); //this->Sequence->SetType(type); this->Sequence->SetName(this->Page1->GetSequenceName()); this->Sequence->SetSequenceDuration(this->Page1->GetEnlapsedTime()); this->Sequence->SetSameGeometryFlag (this->Page1->GetSameGeometryFlag()); if (this->Page1->GetIncomingMode() == vtkKWSequenceImporterPage1::ONEGEOMETRY_MODE) { std::vector< std::pair > list = this->Page1->GetValidFileList(); if (list.size() != 1) { this->GetWizardWidget()->SetErrorText("cannot build from one geometry : multiple files !"); wizard_workflow->PushInput(vtkKWWizardStep::GetValidationFailedInput()); wizard_workflow->ProcessInputs(); return; } std::string filename = list[0].first; double time = list[0].second; vtkKWSimpleEntryDialog* dialog = vtkKWSimpleEntryDialog::New(); dialog->SetApplication (this->GetApplication()); dialog->Create(); dialog->SetTitle ("Attempt to build from one geometry"); dialog->GetEntry()->GetWidget()->SetRestrictValueToInteger(); dialog->GetEntry()->SetLabelPositionToTop(); dialog->GetEntry()->SetLabelText ("Set the amount of time steps."); if ( dialog->Invoke () == 0 ) { dialog->Delete(); this->GetWizardWidget()->SetErrorText("cannot build from one geometry : multiple files !"); wizard_workflow->PushInput(vtkKWWizardStep::GetValidationFailedInput()); wizard_workflow->ProcessInputs(); return; } int Number = dialog->GetEntry()->GetWidget()->GetValueAsInt(); dialog->Delete(); try { this->Sequence->BuildSequenceFromGeometry (list[0].first.c_str(), Number); } catch (vtkErrorCode::ErrorIds) { this->GetWizardWidget()->SetErrorText("cannot build sequence !\nPlease check the log window for details."); wizard_workflow->PushInput(vtkKWWizardStep::GetValidationFailedInput()); wizard_workflow->ProcessInputs(); return; } } else if (this->Page1->GetIncomingMode() == vtkKWSequenceImporterPage1::NORMAL_MODE) { std::vector< std::pair > list = this->Page1->GetValidFileList(); if (list.size() < 2) { this->GetWizardWidget()->SetErrorText("not enought files to build sequence !"); wizard_workflow->PushInput(vtkKWWizardStep::GetValidationFailedInput()); wizard_workflow->ProcessInputs(); return; } for (unsigned int i = 0; i < list.size(); i++) { vtkMetaDataSet* metadataset = NULL; std::string filename = list[i].first; double time = list[i].second; switch(type) { case vtkMetaDataSet::VTK_META_SURFACE_MESH: metadataset = vtkMetaSurfaceMesh::New(); break; case vtkMetaDataSet::VTK_META_VOLUME_MESH: metadataset = vtkMetaVolumeMesh::New(); break; case vtkMetaDataSet::VTK_META_IMAGE_DATA: metadataset = vtkMetaImageData::New(); break; } try { metadataset->Read(filename.c_str()); metadataset->SetTime (time); metadataset->SetName((vtksys::SystemTools::GetFilenameName (filename.c_str())).c_str()); this->Sequence->AddMetaDataSet(metadataset); metadataset->Delete(); } catch (...) { metadataset->Delete(); } } } else if (this->Page1->GetIncomingMode() == vtkKWSequenceImporterPage1::IMPORT_MODE) { std::vector list = this->Page1->GetImportedMetaDataSetList(); for (unsigned int i = 0; i < list.size(); i++) { vtkMetaDataSet* metadataset = list[i]; this->Sequence->AddMetaDataSet(metadataset); } } std::cout<<"done.\n"<PushInput(vtkKWWizardStep::GetValidationSucceededInput()); wizard_workflow->ProcessInputs(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporter::ValidatePage2Callback() { } //--------------------------------------------------------------------------- void vtkKWSequenceImporter::UpdateEnableState() { this->Superclass::UpdateEnableState(); }