Program Listing for File DataPlotter.cc

Program Listing for File DataPlotter.cc#

Return to documentation for file (doxygen_docs/GeneralKModels/DataPlotter.cc)

#include"Karana/GeneralKModels/DataPlotter.h"
#include"Karana/KCore/Allocator.h"


namespaceKarana::Models{

namespaceku=Karana::KUtils;
namespacekm=Karana::Math;

DataPlotter::DataPlotter(std::string_viewname,
constkc::ks_ptr<kd::ModelManager>&mm,
constkc::ks_ptr<ku::PlotData>&plot_data)
:KModel<DataPlotter,DataPlotterParams>(name,mm)
,_plot_data(plot_data){
params=std::allocate_shared<DataPlotterParams>(kc::Allocator<DataPlotterParams>{},
std::format("{}_params",name));
};

kc::ks_ptr<DataPlotter>DataPlotter::create(std::string_viewname,
constkc::ks_ptr<kd::ModelManager>&mm,
constkc::ks_ptr<ku::PlotData>&plot_data){
kc::ks_ptr<DataPlotter>dl=
std::allocate_shared<DataPlotter>(kc::Allocator<DataPlotter>{},name,mm,plot_data);
mm->registerModel(dl);
returndl;
}

voidDataPlotter::postModelStep(constkm::Ktime&,constkm::Vec&){_plot_data->update();}

DataPlotterParams::DataPlotterParams(std::string_viewname)
:KModelParams(name){}

boolDataPlotterParams::isReady()const{returntrue;}

kc::ks_ptr<ku::PlotData>DataPlotter::getPlotData(){return_plot_data;}

voidDataPlotter::_registerModel(){
//Calltheparent.Thiswilldothenormalregistration.
KModel<DataPlotter, DataPlotterParams>::_registerModel();

kc::ks_ptr<Base>dark=shared_from_this();
autot=kc::static_pointer_cast<DataPlotter>(dark);

//Alsoregisteratimedeventnowifweshouldlogthefirststep.
kc::ks_ptr<kd::StatePropagator>sp=
kc::dynamic_pointer_cast<kd::StatePropagator>(model_manager);
if(spandparams->log_first_step){
autote=kd::TimedEvent::create(
std::format("{}_first_step",name()),
model_manager->getTime(),
[t](constkm::Ktime&){t->_plot_data->update();},
true);
sp->registerTimedEvent(te);
}
}

voidDataPlotter::_unregisterModel(){
//Calltheparent.Thiswilldothenormalunregistration.
KModel<DataPlotter, DataPlotterParams>::_unregisterModel();

//Tryandunregisterthiseventregardlessoftheparametersetting.
//It'spossibletheparameterhasbeenchangedsincethelastregistration.
kc::ks_ptr<kd::StatePropagator>sp=
kc::dynamic_pointer_cast<kd::StatePropagator>(model_manager);
if(sp){
sp->unregisterTimedEvent(std::format("{}_first_step",name()),true,true);
}
}

//DestructorincludedforMacOSbuilds.Musthaveakey-functionout-of-linetoavoiddulpicate
//symbols.
DataPlotter::~DataPlotter(){};

}//namespaceKarana::Models