#include #include "vtkObjectFactory.h" #include #include #include #include #include #include #include #include #include "vtkKWAnimationWidget.h" #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWSequencer ); vtkCxxRevisionMacro( vtkKWSequencer, "$Revision: 1.2 $"); //---------------------------------------------------------------------------- vtkKWSequencer::vtkKWSequencer() { this->TimerLog = vtkTimerLog::New(); this->TimeScaleSet = vtkKWScaleSet::New(); this->PlayButton = vtkKWPushButton::New(); this->StopButton = vtkKWPushButton::New(); this->PlayModeCheckbox = vtkKWCheckButtonWithLabel::New(); this->AnimationWidget = vtkKWAnimationWidget::New(); this->animation_frame = vtkKWFrameWithLabel::New(); this->SequencerStatus = vtkKWSequencer::STATUS_STOP; this->LinkScales = false; this->RealTimePlayModeState = true; this->ToolType = TOOL_HORIZONTAL; } //---------------------------------------------------------------------------- vtkKWSequencer::~vtkKWSequencer() { this->TimerLog->Delete(); this->PlayButton->Delete(); this->StopButton->Delete(); this->PlayModeCheckbox->Delete(); this->AnimationWidget->Delete(); this->animation_frame->Delete(); } //---------------------------------------------------------------------------- void vtkKWSequencer::Update() { if (!this->ParentObject || !this->ParentObject->GetDataManager() ) return; this->RemoveAllSequences(); std::vector metadatasetlist = this->ParentObject->GetDataManager()->GetMetaDataSetList(); for (unsigned int i=0; iAddSequence (sequence); } } double timemin = this->ParentObject->GetDataManager()->GetSequencesRangeMin(); double timemax = this->ParentObject->GetDataManager()->GetSequencesRangeMax(); double finestresolution = (timemax - timemin) / (double)this->ParentObject->GetDataManager()->GetSequencesMaxNumber(); this->AnimationWidget->SetSequenceRange(timemin, timemax, this->ParentObject->GetDataManager()->GetSequencesMaxNumber()); } //---------------------------------------------------------------------------- void vtkKWSequencer::AddSequence (vtkMetaDataSetSequence* sequence) { if (!sequence) return; vtkKWScale *scale = this->TimeScaleSet->AddWidget(this->TimeScaleSet->GetNumberOfWidgets()); scale->SetLength (200); scale->SetCommand (this, "TimeScaleCallback"); scale->SetRange(sequence->GetMinTime(), sequence->GetMaxTime()); scale->SetResolution(sequence->GetTimeResolution()); scale->SetLabelText(sequence->GetName()); scale->SetOrientationToHorizontal(); scale->SetBalloonHelpString(sequence->GetName()); } //---------------------------------------------------------------------------- void vtkKWSequencer::RemoveAllSequences() { this->TimeScaleSet->DeleteAllWidgets(); } //---------------------------------------------------------------------------- void vtkKWSequencer::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); } //---------------------------------------------------------------------------- void vtkKWSequencer::Start(void) { if (!this->ParentObject || !this->ParentObject->GetDataManager() ) return; if (!this->TimeScaleSet->GetNumberOfWidgets()) return; this->SequencerStatus = vtkKWSequencer::STATUS_PLAY; unsigned int Nmax = 0; double timemin = this->ParentObject->GetDataManager()->GetSequencesRangeMin(); double timemax = this->ParentObject->GetDataManager()->GetSequencesRangeMax(); double finestresolution = (timemax - timemin) / (double)this->ParentObject->GetDataManager()->GetSequencesMaxNumber(); double time = timemin; this->GetApplication()->ProcessPendingEvents(); while(Nmax < 10000 && this->SequencerStatus == vtkKWSequencer::STATUS_PLAY) { this->GetApplication()->ProcessPendingEvents(); TimerLog->StartTimer(); if (!this->RealTimePlayModeState) { time += finestresolution; } if (time > timemax) time = timemin; this->TimeScaleCallback (time); TimerLog->StopTimer(); if (this->RealTimePlayModeState) { double delay = TimerLog->GetElapsedTime(); time+=delay; } Nmax++; } this->SequencerStatus = vtkKWSequencer::STATUS_STOP; } //---------------------------------------------------------------------------- void vtkKWSequencer::Stop(void) { this->SequencerStatus = vtkKWSequencer::STATUS_STOP; } //---------------------------------------------------------------------------- void vtkKWSequencer::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->SetLabelText ("Sequencer"); this->TimeScaleSet->SetParent (this); this->TimeScaleSet->Create(); this->TimeScaleSet->SetBorderWidth(2); this->TimeScaleSet->SetReliefToGroove(); this->TimeScaleSet->PackHorizontallyOn(); this->TimeScaleSet->SetMaximumNumberOfWidgetsInPackingDirection(3); this->PlayModeCheckbox->SetParent(this); this->PlayModeCheckbox->Create(); this->PlayModeCheckbox->SetLabelText("Real-Time"); this->PlayModeCheckbox->GetWidget()->Select(); this->PlayModeCheckbox->GetWidget()->SetCommand(this, "PlayModeCheckboxCallback"); this->PlayButton->SetParent(this); this->PlayButton->Create(); this->PlayButton->SetImageToPixels(image_play, image_play_width, image_play_height, image_play_pixel_size, image_play_length); this->PlayButton->SetCommand(this, "Start"); this->PlayButton->SetBalloonHelpString("Start playing"); this->StopButton->SetParent(this); this->StopButton->Create(); this->StopButton->SetImageToPixels(image_pause, image_pause_width, image_pause_height, image_pause_pixel_size, image_pause_length); this->StopButton->SetCommand(this, "Stop"); this->StopButton->SetBalloonHelpString("Stop playing"); this->animation_frame->SetParent(this); this->animation_frame->Create(); this->animation_frame->SetWidth (200); this->animation_frame->SetLabelText("Create a movie"); this->AnimationWidget->SetParent(animation_frame->GetFrame()); this->AnimationWidget->Create(); this->AnimationWidget->SetWidth (200); this->AnimationWidget->SetAnimationTypeToSequence(); this->Script("pack %s -side top -fill x -anchor nw -expand n", this->AnimationWidget->GetWidgetName()); this->AnimationWidget->SetSequenceUpdateCommand (this, "TimeScaleCallback"); this->AnimationWidget->SetAnimationTypeToSequence(); this->AnimationWidget->SetParentObject (this->ParentObject); this->Pack(); } //---------------------------------------------------------------------------- void vtkKWSequencer::TimeScaleCallback (double time) { if (!this->ParentObject || !this->ParentObject->GetDataManager() ) return; for (int i=0; iTimeScaleSet->GetNumberOfWidgets(); i++) { vtkKWScale *scale = this->TimeScaleSet->GetWidget(i); if (scale) { vtkMetaDataSetSequence* sequence = vtkMetaDataSetSequence::SafeDownCast(this->ParentObject->GetDataManager()->GetMetaDataSet(scale->GetLabelText())); if (sequence) sequence->UpdateToTime(time); } } vtkKWPageView* page = this->ParentObject->GetCurrentPage(); if (page) page->Render(); } //---------------------------------------------------------------------------- void vtkKWSequencer::Pack (void) { if (this->StopButton->IsCreated()) { this->Script( "pack %s -side left -anchor nw -fill none -expand n -padx 2 -pady 2", this->StopButton->GetWidgetName()); } if (this->PlayButton->IsCreated()) { this->Script( "pack %s -side left -anchor nw -fill none -expand n -padx 2 -pady 2", this->PlayButton->GetWidgetName()); } if (this->PlayModeCheckbox->IsCreated()) { this->Script( "pack %s -side left -anchor nw -fill none -expand n -padx 2 -pady 2", this->PlayModeCheckbox->GetWidgetName()); } if (this->TimeScaleSet->IsCreated()) { this->Script( "pack %s -side left -anchor nw -fill none -expand n -padx 2 -pady 2", this->TimeScaleSet->GetWidgetName()); } if (this->animation_frame->IsCreated()) { this->Script( "pack %s -side left -anchor nw -fill none -expand n -padx 2 -pady 2", this->animation_frame->GetWidgetName()); } } //---------------------------------------------------------------------------- void vtkKWSequencer::PlayModeCheckboxCallback (int val) { if (val) this->RealTimePlayModeState = true; else this->RealTimePlayModeState = false; }