~karl-qdh/nux/nux.gtkentry-wrapper

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
191
192
193
194
195
196
197
198
199
200
/*
 * Copyright 2010 Inalogic Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3, as
 * published by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 *
 */


#ifndef NODENETPROTOCOL_H
#define NODENETPROTOCOL_H

#include "NodeItem.h"
#include "NuxCore/TinyXML/tinyxml.h"

//#pragma pack(1)
//
//enum TypeHeader
//{
//    TRANSFER_ACK,
//    BYTE_HEADER,
//    INT_HEADER,
//    STRING_HEADER,
//};
//
//struct NUX_HEADER_PACKET
//{
//    NSockAddrIn     address;
//    unsigned long   Code;       // => 4 bytes (the header type or protocol)
//    unsigned long   Type;       // => 4 bytes (the service requested/packet type)
//    unsigned long   Handle;     // => 4 bytes (the client/connection handle)
//    unsigned long   Len;        // => 4 bytes (the data len)
//};
//
//
//struct NUX_DATA_PACKET
//{
//    //NSockAddrIn address;
//    BYTE data[1024];
//};
//
//struct NUX_DATA_HEADER
//{
//    BYTE data0[1024];
//    BYTE data1[1024];
//};
//
//#pragma pack()

#define NODE_XML_NET_PROTOCOL 1

namespace nux
{

  enum NodeParameterType
  {
    NODE_TYPE_UNDEFINED = 1,
    NODE_TYPE_FOLDER,
    NODE_TYPE_BOOL,
    NODE_TYPE_CHECKBOX,
    NODE_TYPE_SPINBOX,
    NODE_TYPE_DOUBLESPINBOX,
    NODE_TYPE_COMBOSIMPLE,
    NODE_TYPE_COMBOCOMPLEX,
    NODE_TYPE_VECTOR3,
    NODE_TYPE_VECTOR4,
    NODE_TYPE_RGB,
    NODE_TYPE_RGBA,
    NODE_TYPE_STATICTEXT,
    NODE_TYPE_SPLINE,
    NODE_TYPE_EDITTEXT,
    NODE_TYPE_RANGE,
    NODE_TYPE_RANGEINTEGER,
    NODE_TYPE_INTVALUATOR,
    NODE_TYPE_DOUBLEVALUATOR,
    NODE_TYPE_VECTORVALUATOR,
    NODE_TYPE_COLORPREVIEW,
    NODE_TYPE_MATRIX4PREVIEW,
    NODE_TYPE_MATRIX3PREVIEW,

    NODE_TYPE_FORCE_DWORD = 0x7fffffff,
  };

#if NODE_XML_NET_PROTOCOL
  bool QueryNodeXMLIntAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, int *Value, int searchid);
  bool QueryNodeXMLDoubleAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, double *Value, int searchid);
  bool QueryNodeXMLAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, std::string &Value, int searchid);
  bool QueryNodeXMLAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, std::string &Value, int searchid);
  bool QueryNodeXMLStringAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, tstring &Value, int searchid);
#endif

  class NodeNetCom: public NodeItem
  {
    NUX_DECLARE_OBJECT_TYPE (NodeNetCom, NodeItem);
  public:
    //! Search the ID in the whole tree below this node. Search also this node.
    NodeNetCom *FindNodeID (int id);
    //! Search the ID in the immediate children of this node.
    NodeNetCom *FindChildNodeID (int id);

#if NODE_XML_NET_PROTOCOL
    virtual TiXmlElement *ToXML() const;
    virtual bool FromXML (const TiXmlElement *elementxml);
    //! Used by client to create node from XML after initialization.
    virtual bool CreateFromXML (const TiXmlElement *elementxml);

    //! By default, when generating xml (ToXML) or creating from xml (FromXML), it may be necessary to skip the child of some elements because they
    // automatically take care of parsing in and out their own children. For instance, Vector3PropertyItem.
    virtual bool SkipChild() const
    {
      return false;
    }

//    virtual bool QueryNodeXMLIntAttribute(const TiXmlElement* elementxml, const char* attribute, int* Value, int id);
//    virtual bool QueryNodeXMLDoubleAttribute(const TiXmlElement* elementxml, const char* attribute, double* Value, int id);
//    virtual bool QueryNodeXMLAttribute(const TiXmlElement* elementxml, const char* attribute, std::string& Value, int id);
  protected:
    void SetNodeXMLAttributes (TiXmlElement *elementxml) const;
    void GetNodeXMLAttributes (const TiXmlElement *elementxml);

#endif

  public:
    void DeleteChildren();

    const TCHAR *GetName() const
    {
      return m_Name.GetTCharPtr();
    }
    void SetName (const TCHAR *str)
    {
      m_Name = str;
    }

  protected:
    NodeNetCom (const TCHAR *Name, NodeParameterType type = NODE_TYPE_UNDEFINED);
    virtual ~NodeNetCom() {};

    void SetParameterType (NodeParameterType t)
    {
      m_Type = t;
    }
    NodeParameterType GetParameterType() const
    {
      return m_Type;
    }
    int GetID() const
    {
      return m_ID;
    }
    void SetID (int id)
    {
      m_ID = id;
    }
    void SetEnable (bool b)
    {
      m_Enable = b ? 1 : 0;
    }
    int IsEnable() const
    {
      return m_Enable;
    }
    void SetVisible (bool b)
    {
      m_Visible = b ? 1 : 0;
    }
    int IsVisible() const
    {
      return m_Visible;
    }
  private:

    static int m_IDGenerator;
    NString m_Name;
    NodeParameterType m_Type;
    int m_Enable;  // true is client can change the value.
    int m_Visible; // true, if visible to the client.
    int m_ID;       // ID for network communications

    friend class ParameterManagerImpl;
  };


}

#endif // NODENETPROTOCOL_H