Commit 8544b9f8 authored by Aleksandr Bakhshiev's avatar Aleksandr Bakhshiev
Browse files

Merge with DataSrcs

......@@ -1926,8 +1926,8 @@ bool UApplication::LoadModelFromFile(int channel_index, const std::string &file_
if(!data.empty())
{
MModel_Destroy(channel_index);
MModel_LoadComponent(channel_index, "",data.c_str());
return true;
if(MModel_LoadComponent(channel_index, "",data.c_str()) == RDK_SUCCESS)
return true;
}
return false;
}
......
......@@ -22,20 +22,21 @@ namespace RDK {
//
// --------------------------
UController::UController(void)
: Component(0)
{
Enabled=false;
}
UController::~UController(void)
{
UnLinkAll();
UnLink();
}
// --------------------------
// --------------------------
//
// --------------------------
//
//
bool UController::IsEnabled(void) const
{
return Enabled;
......@@ -49,32 +50,24 @@ bool UController::IsEnabled(bool value)
Enabled=value;
return true;
}
// --------------------------
// --------------------------
//
// --------------------------
//
size_t UController::GetNumComponents(void) const
{
return Components.size();
}
//
UContainer* UController::GetComponents(size_t index)
//
std::string UController::GetComponentName(void) const
{
return Components[index];
std::string result;
if(Component)
{
result=Component->GetFullName();
result=result.substr(result.find_first_of(".")+1);
}
return result;
}
//
int UController::FindComponent(UContainer* component) const
std::string UController::GetComponentName(UContainer *level) const
{
vector<UContainer*>::const_iterator I=find(Components.begin(),Components.end(),component);
if(I != Components.end())
return int(I-Components.begin());
return -1;
if(Component)
return Component->GetLongName(level);
return std::string("");
}
// --------------------------
......@@ -84,16 +77,19 @@ int UController::FindComponent(UContainer* component) const
//
bool UController::Link(UContainer* component, bool forchilds)
{
if(find(Components.begin(),Components.end(),component) != Components.end())
if(!component)
return false;
if(Component == component)
return true;
Components.push_back(component);
component->AddController(this,forchilds);
Component=component;
Component->AddController(this,forchilds);
if(!ALink(component))
{
component->DelController(this,forchilds);
Components.erase(Components.begin()+(Components.size()-1));
Component=0;
return false;
}
......@@ -101,50 +97,302 @@ bool UController::Link(UContainer* component, bool forchilds)
}
//
bool UController::UnLink(int index, bool forchilds)
bool UController::UnLink(bool forchilds)
{
if(index<0 || index> int(Components.size()))
if(!AUnLink(forchilds))
return false;
if(!AUnLink(index,forchilds))
return false;
Components[index]->DelController(this,forchilds);
Components.erase(Components.begin()+index);
if(Component)
Component->DelController(this,forchilds);
Component=0;
return true;
}
bool UController::UnLink(UContainer* component, bool forchilds)
//
bool UController::Update(void)
{
int index=FindComponent(component);
if(!Enabled)
return true;
if(index < 0)
if(!Component)
return true;
return UnLink(index, forchilds);
return AUpdate();
}
//
bool UController::ALink(UContainer* component, bool forchilds)
{
return true;
}
//
bool UController::AUnLink(bool forchilds)
{
return true;
}
// --------------------------
UControllerData::UControllerData(void)
: NumPoints(1)
{
}
///
void UControllerData::SetNumPoints(int value)
{
if(value<0)
return;
NumPoints=value;
}
std::string UControllerData::GetPropertyName(void) const
{
if(Property)
return Property->GetName();
return std::string("");
}
///
const type_info& UControllerData::GetDataType(void) const
{
if(Property)
return Property->GetLanguageType();
// TODO:
}
bool UController::UnLinkAll(bool forchilds)
// *****************************************************************
UControllerDataReader::UControllerDataReader(void)
: MRow(0), MCol(0), PropertyType(0)
{
bool res=true;
while(Components.begin() != Components.end())
}
///
void UControllerDataReader::SetTimeInterval(double value)
{
TimeInterval=value;
if(value>0)
SetNumPoints(value*Component->GetTimeStep());
else
SetNumPoints(100000);
}
///
void UControllerDataReader::SetMatrixCoord(int row, int col)
{
MRow=row;
MCol=col;
}
//
bool UControllerDataReader::AUnLink(bool forchilds)
{
PropertyType=0;
return UControllerData::AUnLink(forchilds);
}
///
bool UControllerDataReader::AUpdate(void)
{
if(!Property)
return false;
double x(0.0), y(0.0);
if(PropertyType == 1)
{
const double *data=reinterpret_cast<const double*>(Property->GetMemoryArea());
if(!data)
return false;
y=*data;
}
else
if(PropertyType == 2)
{
const int *data=reinterpret_cast<const int*>(Property->GetMemoryArea());
if(!data)
return false;
y=*data;
}
else
if(PropertyType == 3)
{
const MDMatrix<double> *data=reinterpret_cast<const MDMatrix<double>*>(Property->GetMemoryArea());
if(!data)
return false;
if(data->GetCols()<=MCol)
return false;
if(data->GetRows()<=MRow)
return false;
y=(*data)(MRow,MCol);
}
else
if(PropertyType == 4)
{
res &= UnLink(int(Components.size())-1,forchilds);
const MDMatrix<int> *data=reinterpret_cast<const MDMatrix<int>*>(Property->GetMemoryArea());
if(!data)
return false;
if(data->GetCols()<=MCol)
return false;
if(data->GetRows()<=MRow)
return false;
y=(*data)(MRow,MCol);
}
else
return false;
return res;
x=Component->GetTime().GetDoubleTime();
XData.push_back(x);
YData.push_back(y);
if(int(XData.size())>NumPoints)
XData.erase(XData.begin());
if(int(YData.size())>NumPoints)
YData.erase(YData.begin());
return true;
}
///
void UControllerDataReader::Clear(void)
{
XData.clear();
YData.clear();
}
//
bool UController::Update(void)
///
bool UControllerDataReader::Configure(UContainer *container, UEPtr<UIProperty> property)
{
if(!Enabled)
if(Property == property && Component == container)
return true;
return AUpdate();
UnLink();
Clear();
if(!Link(container))
return false;
if(!property)
{
UnLink();
return false;
}
if(property->GetLanguageType() == typeid(double))
{
PropertyType=1;
}
else
if(property->GetLanguageType() == typeid(double))
{
PropertyType=2;
}
else
if(property->GetLanguageType() == typeid(MDMatrix<double>))
{
PropertyType=3;
}
else
if(property->GetLanguageType() == typeid(MDMatrix<int>))
{
PropertyType=4;
}
else
{
UnLink();
return false;
}
Property=property;
Enabled=true;
return true;
}
// --------------------------
///
void UControllerDataReader::SetNumPoints(int value)
{
UControllerData::SetNumPoints(value);
}
// *********************************************************************
UControllerDataReaderTimeEvents::UControllerDataReaderTimeEvents(void)
{
}
///
void UControllerDataReaderTimeEvents::SetMatrixCoord(int row, int col)
{
UControllerDataReader::SetMatrixCoord(row, col);
}
///
bool UControllerDataReaderTimeEvents::AUpdate(void)
{
if(!Property)
return false;
if(PropertyType != 3)
return false;
double x(0.0), y(0.0);
const MDMatrix<double> *data=reinterpret_cast<const MDMatrix<double>*>(Property->GetMemoryArea());
if(!data)
return false;
if(data->GetCols()>0 && data->GetRows()>0)
{
for(int i=0;i<data->GetCols();i++)
{
x=(*data)(0,i);
std::list<double>::iterator I=XData.begin();
bool check(false);
for(;I != XData.end();I++)
{
if(*I == x)
{
check=true;
break;
}
}
if(check)
continue;
XData.push_back(x);
YData.push_back(0);
XData.push_back(x+0.00001);
YData.push_back(1);
XData.push_back(x+0.00002);
YData.push_back(0);
if(int(XData.size())>NumPoints)
XData.erase(XData.begin());
if(int(YData.size())>NumPoints)
YData.erase(YData.begin());
}
//
if(XData.size()>1)
{
double t1=XData.front();
double t2=XData.back();
while(t2-t1>TimeInterval && !XData.empty())
{
XData.erase(XData.begin());
YData.erase(YData.begin());
t1=XData.front();
}
}
}
return true;
}
}
......
......@@ -13,21 +13,29 @@ See file license.txt for more information
#define UControllerH
#include <vector>
#include <map>
#include <typeinfo>
#include <list>
#include "UModule.h"
#include "UEPtr.h"
#include "../Math/MDMatrix.h"
namespace RDK {
class UContainer;
class UIProperty;
using namespace std;
class RDK_LIB_TYPE UController: public RDK::UModule
{
protected: //
//
//
bool Enabled;
protected: //
//
std::vector<UContainer*> Components;
UContainer* Component;
public:
// --------------------------
......@@ -40,22 +48,13 @@ virtual ~UController(void);
// --------------------------
//
// --------------------------
//
//
bool IsEnabled(void) const;
bool IsEnabled(bool value);
// --------------------------
// --------------------------
//
// --------------------------
//
size_t GetNumComponents(void) const;
//
UContainer* GetComponents(size_t index);
//
int FindComponent(UContainer* component) const;
//
std::string GetComponentName(void) const;
std::string GetComponentName(UContainer *level) const;
// --------------------------
// --------------------------
......@@ -66,9 +65,7 @@ public:
virtual bool Link(UContainer* component, bool forchilds=false);
//
virtual bool UnLink(int index, bool forchilds=false);
virtual bool UnLink(UContainer* component, bool forchilds=false);
virtual bool UnLinkAll(bool forchilds=false);
virtual bool UnLink(bool forchilds=false);
//
virtual bool Update(void);
......@@ -79,16 +76,223 @@ virtual bool Update(void);
// --------------------------
protected:
//
virtual bool ALink(UContainer* component, bool forchilds=false)=0;
virtual bool ALink(UContainer* component, bool forchilds=false);
//
virtual bool AUnLink(int index, bool forchilds=false)=0;
virtual bool AUnLink(bool forchilds=false);
//
virtual bool AUpdate(void)=0;
// --------------------------
};
///
struct UControllerData: public UController
{
/// -
UEPtr<UIProperty> Property;
///
//std::string PropertyName;
///
int NumPoints;
///
UControllerData(void);
///
void SetNumPoints(int value);
///
std::string GetPropertyName(void) const;
///
virtual bool AUpdate(void)=0;
///
virtual void Clear(void)=0;
///
virtual bool Configure(UContainer *container, UEPtr<UIProperty> property)=0;
///
virtual const type_info& GetDataType(void) const;
};
struct UControllerDataReader: public UControllerData
{
/// ()
double TimeInterval;
///
/// 0 -
/// 1 - double
/// 2 - int
/// 3 - MDMatrix<double>
/// 4 - MDMatrix<int>
int PropertyType;
///
int MRow, MCol;
///
std::list<double> XData;
std::list<double> YData;
public:
///
UControllerDataReader(void);
///
virtual void SetTimeInterval(double value);
///
virtual void SetMatrixCoord(int row, int col);
//
virtual bool AUnLink(bool forchilds=false);
///
virtual bool AUpdate(void);
///
virtual void Clear(void);
///
virtual bool Configure(UContainer *container, UEPtr<UIProperty> property);
protected:
///
void SetNumPoints(int value);
};
/// , ,
/// MDMatrix<double>, .
/// :
///
struct UControllerDataReaderTimeEvents: public UControllerDataReader
{
public:
UControllerDataReaderTimeEvents(void);
protected:
///
virtual void SetMatrixCoord(int row, int col);
///
virtual bool AUpdate(void);
};
/*
template <class T>
struct UDataSourceT: public UControllerData
{
///
std::map<double, MDMatrix<T> > Data;
UDataSourceT(void);
///