~vbursian/research-assistant/intervers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
////////////////////////////////////////////////////////////////////////////////
/*! @file ExpressionNode.cpp Class sExpressionNode.
- Part of RANet - Research Assistant Net Library.
- Copyright(C) 2014-2015, Viktor E. Bursian, St.Petersburg, Russia.
                          Viktor_dot_Bursian_at_mail_dot_ioffe_dot_ru
*///////////////////////////////////////////////////////////////////////////////
#include "ExpressionNode.h"
#include "NetMath.h"
#include "Functions.h"
namespace RA {
//------------------------------------------------------------------------------

//---------------------------------------------------------- sExpressionNode ---

sExpressionNode::~sExpressionNode ()
{
  if( TheResult ){ delete TheResult; TheResult=NULL; };
}

sExpressionNode::sExpressionNode (sString  source)
    :sFolderNode(source)
    ,sGraphObject()
    ,TheResult(NULL)
{
}


sExpressionNode::sExpressionNode (std::istream &  a_stream
                                 ,rcsVersion      version)
    :sFolderNode(a_stream,version)
    ,sGraphObject(a_stream,version)
    ,TheResult(NULL)
{
  bool                        ValueIsStored;
  a_stream.READ_INTO(ValueIsStored);
}


void  sExpressionNode::Store (std::ostream & a_stream) const
{
  sFolderNode::Store(a_stream);
  sGraphObject::Store(a_stream);
  bool                        ValueIsStored = false;
  a_stream.WRITE_FROM(ValueIsStored);
}


psMathValue  sExpressionNode::MathValue ()
{
  if( Result() )
    return TheResult->Replica();
  return NULL;
}


sString  sExpressionNode::Text (eTextFormat        F
                               ,eTextDetalization  D)
{
  sString                     T;
  T = sFolderNode::Text(F,D);
  if( ! Result() ){
    if( ! Docket().Empty() ){
      if( F == HTML )  T += "<font color=red>";
      T += " = ERR!!!";
      if( F == HTML )  T += "</font>";
    }
  }else{
    sString                     R(TheResult->Text(F,D));
    if( sMath::Valid(TheResult) ){
      if( ! R.Empty() )
        (T += " = ") += R;
    }else{
      psMathError               E = psMathError(TheResult);
      T = Docket().Substr(0,E->Cursor1)
          + "<font color=red>"
          + Docket().Substr(E->Cursor1,E->Cursor2-E->Cursor1)
          + "</font>"
          + Docket().Tail(E->Cursor2)
          + "<font color=red>"
          + " = ERROR: " + E->Message
          + "</font>";
    }
  }
  return T;
}


void  sExpressionNode::SetDocket (rcsString  new_docket)
{
  if( TheResult ){ delete TheResult; TheResult=NULL; }
  sFolderNode::SetDocket(new_docket);
}


sString  sExpressionNode::Hint ()
{
  return  Text(Plain,Casual);
}


//pcsAppearance  sExpressionNode::Appearance () const
//{
//  QMutexLocker                BodyLocker(&BodyMutex);
//  if( TheResult ){
//    psFunction                  F = dynamic_cast<psFunction>(TheResult);
//    if( F  )
//      return F->Appearance();
//  }
//  return NULL;
//}


void  sExpressionNode::SetAppearance (psAppearance  appearance)
{
  QMutexLocker                BodyLocker(&BodyMutex);
  sGraphObject::SetAppearance(appearance);
  if( TheResult ){
    psFunction                  F = dynamic_cast<psFunction>(TheResult);
    if( F  ){
      F->SetAppearance(new sCurveAppearance( * dynamic_cast<psCurveAppearance>
                                                           (appearance) ) );
    }
  }
  MarkAsEdited();
}


psMathValue  sExpressionNode::Result ()
{
  if( Docket().Empty() ){
    if( TheAppearance ){ delete TheAppearance; TheAppearance=NULL; }
    if( TheResult ){ delete TheResult; TheResult=NULL; }
  }else{
    if( ! TheResult ){
      sNetMath                E(sNodePtr(this),Docket());
      TheResult = E.Calculate();
      if( psFunction F =  dynamic_cast<psFunction>(TheResult) ){
        if( dynamic_cast<psCurveAppearance>(TheAppearance) ){
          F->SetAppearance(new sCurveAppearance( * dynamic_cast
                                                     <psCurveAppearance>
                                                     (TheAppearance)     ));
        }
      }
    }
  }
  return TheResult;
}


void  sExpressionNode::CopyFrom (psNode  other)
{
  sFolderNode::CopyFrom(other);
  psExpressionNode            Other = dynamic_cast<psExpressionNode>(other);
  if( Other ){
//    TheStartTime = Other->TheStartTime;
//    TheDuration = Other->TheDuration;
//    MarkAsEdited();
  }
}


sBoundaries  sExpressionNode::Boundaries ()
{
  psFunction                  F = dynamic_cast<psFunction>(Result());
  if( F )
    return F->Boundaries();
  return sGraphObject::Boundaries();
}


sBoundaries  sExpressionNode::Boundaries () const
{
  psFunction                  F = dynamic_cast<psFunction>(TheResult);
  if( F )
    return F->Boundaries();
  return sGraphObject::Boundaries();
}


int  sExpressionNode::Distance (rcsIntPoint  position
                               ,rcsScales    scales  )
{
  psFunction                  F = dynamic_cast<psFunction>(Result());
  if( F )
    return F->Distance(position,scales);
  return sGraphObject::Distance(position,scales);
}

//------------------------------------------------------------------------------
} //namespace RA