~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
////////////////////////////////////////////////////////////////////////////////
/*! @file ColorNodes.cpp   Цветовые объекты сети.
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
- Copyright(C) 2015, Viktor E. Bursian, St.Petersburg, Russia.
                     Viktor.Bursian@mail.ioffe.ru
*///////////////////////////////////////////////////////////////////////////////
#include "ColorNodes.h"
#include "Symbols.h"
#include <cstring>
#include <QMutexLocker>
namespace RA {
//------------------------------------------------------------------------------
//--------------------------------------------------------------- sColorNode ---

sColorNode::sColorNode (std::istream &  a_stream ,rcsVersion  version)
  :sTerminalNode(a_stream,version)
  ,TheValue(a_stream,version)
{
}


void sColorNode::Store (std::ostream &  a_stream) const
{
  sTerminalNode::Store(a_stream);
  TheValue.Store(a_stream);
}


sString  sColorNode::Text (eTextFormat        F
                          ,eTextDetalization  D)
{
  return Value().StyleTagRGBA()
        +( D==Laconic
         ? ""
         : ( F==HTML ? sString("<font color=")+Value().HexARGB()+">"
                     : sString() )
           +", i.e. "
           +( F==HTML ? "</font>" : "" )
           +Value().HexARGB()
         );
}


sColor  sColorNode::Value ()
{
  QMutexLocker                BodyLocker(&BodyMutex);
  return TheValue;
}


void  sColorNode::Assign (sColor  V)
{
  QMutexLocker                BodyLocker(&BodyMutex);
  if( TheValue != V ){
    TheValue = V;
    MarkAsEdited();
  }
}


void  sColorNode::CopyFrom (psNode  other)
{
  sTerminalNode::CopyFrom(other);
  psColorNode                 Other = dynamic_cast<psColorNode>(other);
  if( Other && (TheValue != Other->Value()) ){
    TheValue = Other->Value();
    MarkAsEdited();
  }
}


//------------------------------------------------------------ sColorSetNode ---

sColorSetNode::sColorSetNode (std::istream &  a_stream ,rcsVersion  version)
  :sTerminalNode(a_stream,version)
  ,TheValue(a_stream,version)
{
}


void sColorSetNode::Store (std::ostream &  a_stream) const
{
  sTerminalNode::Store(a_stream);
  TheValue.Store(a_stream);
}


sString  sColorSetNode::Text (eTextFormat        /*F*/
                             ,eTextDetalization  /*D*/)
{
  QMutexLocker                BodyLocker(&BodyMutex);
  sString                     T("set of ");
  T << TheValue.Size();
  T += " colors";
  return T;
}


sColorSet  sColorSetNode::Value ()
{
  QMutexLocker                BodyLocker(&BodyMutex);
  return TheValue;
}


void  sColorSetNode::Assign (sColorSet  V)
{
  QMutexLocker                BodyLocker(&BodyMutex);
  TheValue=V;
  MarkAsEdited();
}


bool sColorSetNode::Empty()
{
  QMutexLocker                BodyLocker(&BodyMutex);
  return TheValue.Empty();
}


sColor  sColorSetNode::CurrentColor ()
{
  QMutexLocker                BodyLocker(&BodyMutex);
  return TheValue.CurrentColor();
}


void  sColorSetNode::SetToFirst ()
{
  QMutexLocker                BodyLocker(&BodyMutex);
  TheValue.SetToFirst();
  MarkAsEdited();
}


void sColorSetNode::ShiftToNext ()
{
  QMutexLocker                BodyLocker(&BodyMutex);
  TheValue.ShiftToNext();
  MarkAsEdited();
}


void  sColorSetNode::CopyFrom (psNode  other)
{
  sTerminalNode::CopyFrom(other);
  psColorSetNode              Other = dynamic_cast<psColorSetNode>(other);
  if( Other ){
    TheValue = Other->Value();
    MarkAsEdited();
  }
}

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