View | Details | Raw Unified | Return to bug 184
Collapse All | Expand All

(-)a/src/contrib/attribute-default-iterator.cc (-58 / +93 lines)
 Lines 1-15    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
 
1
#include "attribute-default-iterator.h"
20
#include "attribute-default-iterator.h"
2
#include "ns3/type-id.h"
3
#include "ns3/attribute.h"
21
#include "ns3/attribute.h"
4
#include "ns3/object-vector.h"
22
#include "ns3/object-vector.h"
5
#include "ns3/pointer.h"
23
#include "ns3/pointer.h"
6
#include "ns3/global-value.h"
24
#include "ns3/global-value.h"
7
#include "ns3/string.h"
25
#include "ns3/string.h"
8
26
9
namespace ns3 {
27
namespace ns3
28
{
10
29
11
AttributeDefaultIterator::~AttributeDefaultIterator ()
30
AttributeDefaultIterator::~AttributeDefaultIterator ()
12
{}
31
{
32
}
13
void 
33
void 
14
AttributeDefaultIterator::Iterate (void)
34
AttributeDefaultIterator::Iterate (void)
15
{
35
{
 Lines 17-88    Link Here 
17
    {
37
    {
18
      TypeId tid = TypeId::GetRegistered (i);
38
      TypeId tid = TypeId::GetRegistered (i);
19
      if (tid.MustHideFromDocumentation ())
39
      if (tid.MustHideFromDocumentation ())
20
	{
40
        {
21
	  continue;
41
          continue;
22
	}
42
        }
23
      bool calledStart = false;
43
      bool calledStart = false;
24
      for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
44
      for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
25
	{
45
        {
26
	  uint32_t flags = tid.GetAttributeFlags (j);
46
          uint32_t flags = tid.GetAttributeFlags (j);
27
	  if (!(flags & TypeId::ATTR_CONSTRUCT))
47
          if (!(flags & TypeId::ATTR_CONSTRUCT))
28
	    {
48
            {
29
	      // we can't construct the attribute, so, there is no
49
              // we can't construct the attribute, so, there is no
30
	      // initial value for the attribute
50
              // initial value for the attribute
31
	      continue;
51
              continue;
32
	    }
52
            }
33
	  Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
53
          Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
34
	  if (accessor == 0)
54
          //No accessor, go to next attribute
35
	    {
55
          if (accessor == 0)
36
	      continue;
56
            {
37
	    }
57
              continue;
38
	  if (!accessor->HasSetter ())
58
            }
39
	    {
59
          if (!accessor->HasSetter ())
40
	      continue;
60
            {
41
	    }
61
              //skip this attribute it doesn't have an setter
42
	  Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
62
              continue;
43
	  if (checker == 0)
63
            }
44
	    {
64
          Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
45
	      continue;
65
          if (checker == 0)
46
	    }
66
            {
47
	  Ptr<const AttributeValue> value = tid.GetAttributeInitialValue (j);
67
              //skip, it doesn't have a checker
48
	  if (value == 0)
68
              continue;
49
	    {
69
            }
50
	      continue;
70
          Ptr<const AttributeValue> value = tid.GetAttributeInitialValue (j);
51
	    }
71
          if (value == 0)
52
	  Ptr<const ObjectVectorValue> vector = DynamicCast<const ObjectVectorValue> (value);
72
            {
53
	  if (vector != 0)
73
              //No value, check next attribute
54
	    {
74
              continue;
55
	      continue;
75
            }
56
	    }
76
          Ptr<const ObjectVectorValue> vector = DynamicCast<const ObjectVectorValue> (value);
57
	  Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (value);
77
          if (vector != 0)
58
	  if (pointer != 0)
78
            {
59
	    {
79
              //a vector value, won't take it
60
	      continue;
80
              continue;
61
	    }
81
            }
62
	  if (!calledStart)
82
          Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (value);
63
	    {
83
          if (pointer != 0)
64
	      StartVisitTypeId (tid.GetName ());
84
            {
65
	    }
85
              //pointer value, won't take it
66
	  VisitAttribute (tid.GetAttributeName (j),
86
              continue;
67
			  value->SerializeToString (checker));
87
            }
68
	  calledStart = true;
88
          //We take only values, no pointers or vectors
69
	}
89
          if (!calledStart)
90
            {
91
              StartVisitTypeId (tid.GetName ());
92
            }
93
          VisitAttribute (tid, tid.GetAttributeName (j), value->SerializeToString (checker), j);
94
          calledStart = true;
95
        }
70
      if (calledStart)
96
      if (calledStart)
71
	{
97
        {
72
	  EndVisitTypeId ();
98
          EndVisitTypeId ();
73
	}
99
        }
74
    }
100
    }
75
}
101
}
76
102
77
void 
103
void 
78
AttributeDefaultIterator::StartVisitTypeId (std::string name)
104
AttributeDefaultIterator::StartVisitTypeId (std::string name)
79
{}
105
{
106
}
80
void 
107
void 
81
AttributeDefaultIterator::EndVisitTypeId (void)
108
AttributeDefaultIterator::EndVisitTypeId (void)
82
{}
109
{
110
}
111
83
void 
112
void 
84
AttributeDefaultIterator::VisitAttribute (std::string name, std::string defaultValue)
113
AttributeDefaultIterator::DoVisitAttribute (std::string name, std::string defaultValue)
85
{}
114
{
115
}
86
116
117
void 
118
AttributeDefaultIterator::VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index)
119
{
120
  DoVisitAttribute (name, defaultValue);
121
}
87
122
88
} // namespace ns3
123
} // namespace ns3
(-)a/src/contrib/attribute-default-iterator.h (-1 / +40 lines)
 Lines 1-6    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
 
1
#ifndef ATTRIBUTE_DEFAULT_ITERATOR_H
20
#ifndef ATTRIBUTE_DEFAULT_ITERATOR_H
2
#define ATTRIBUTE_DEFAULT_ITERATOR_H
21
#define ATTRIBUTE_DEFAULT_ITERATOR_H
3
22
23
#include "ns3/type-id.h"
4
#include <string>
24
#include <string>
5
25
6
namespace ns3 {
26
namespace ns3 {
 Lines 9-19    Link Here 
9
{
29
{
10
public:
30
public:
11
  virtual ~AttributeDefaultIterator () = 0;
31
  virtual ~AttributeDefaultIterator () = 0;
32
  /**
33
   * \brief This function will go through all the TypeIds and get only the attributes which are
34
   * explicit values (not vectors or pointer or arrays) and apply StartVisitTypeId
35
   * and VisitAttribute on the attributes in one TypeId. At the end of each TypeId
36
   * EndVisitTypeId is called.
37
   */
12
  void Iterate (void);
38
  void Iterate (void);
13
private:
39
private:
40
  /**
41
   * \brief Just an interface that needs to be implemented
42
   */
14
  virtual void StartVisitTypeId (std::string name);
43
  virtual void StartVisitTypeId (std::string name);
44
  /**
45
   * \brief Just an interface that needs to be implemented
46
   */
15
  virtual void EndVisitTypeId (void);
47
  virtual void EndVisitTypeId (void);
16
  virtual void VisitAttribute (std::string name, std::string defaultValue);
48
  /**
49
   * \brief This method can be implemented, otherwise, it will call DoVisitAttribute
50
   */
51
  virtual void VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index);
52
  /**
53
   * \brief This method is just an interface and needs to be implemented
54
   */
55
  virtual void DoVisitAttribute (std::string name, std::string defaultValue);
17
};
56
};
18
57
19
} // namespace ns3
58
} // namespace ns3
(-)a/src/contrib/attribute-iterator.cc (-76 / +105 lines)
 Lines 1-3    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
17
 */
18
 
1
#include "attribute-iterator.h"
19
#include "attribute-iterator.h"
2
#include "ns3/config.h"
20
#include "ns3/config.h"
3
#include "ns3/log.h"
21
#include "ns3/log.h"
 Lines 13-22    Link Here 
13
31
14
32
15
AttributeIterator::AttributeIterator ()
33
AttributeIterator::AttributeIterator ()
16
{}
34
{
35
}
17
36
18
AttributeIterator::~AttributeIterator ()
37
AttributeIterator::~AttributeIterator ()
19
{}
38
{
39
}
20
40
21
void 
41
void 
22
AttributeIterator::Iterate (void)
42
AttributeIterator::Iterate (void)
 Lines 38-46    Link Here 
38
  for (uint32_t i = 0; i < m_examined.size (); ++i)
58
  for (uint32_t i = 0; i < m_examined.size (); ++i)
39
    {
59
    {
40
      if (object == m_examined[i])
60
      if (object == m_examined[i])
41
	{
61
        {
42
	  return true;
62
          return true;
43
	}
63
        }
44
    }
64
    }
45
  return false;
65
  return false;
46
}
66
}
 Lines 74-101    Link Here 
74
94
75
void 
95
void 
76
AttributeIterator::DoStartVisitObject (Ptr<Object> object)
96
AttributeIterator::DoStartVisitObject (Ptr<Object> object)
77
{}
97
{
98
}
78
void 
99
void 
79
AttributeIterator::DoEndVisitObject (void)
100
AttributeIterator::DoEndVisitObject (void)
80
{}
101
{
102
}
81
void 
103
void 
82
AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> item)
104
AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> item)
83
{}
105
{
106
}
84
void 
107
void 
85
AttributeIterator::DoEndVisitPointerAttribute (void)
108
AttributeIterator::DoEndVisitPointerAttribute (void)
86
{}
109
{
110
}
87
void 
111
void 
88
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
112
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
89
{}
113
{
114
}
90
void 
115
void 
91
AttributeIterator::DoEndVisitArrayAttribute (void)
116
AttributeIterator::DoEndVisitArrayAttribute (void)
92
{}
117
{
118
}
93
void 
119
void 
94
AttributeIterator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
120
AttributeIterator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
95
{}
121
{
122
}
96
void 
123
void 
97
AttributeIterator::DoEndVisitArrayItem (void)
124
AttributeIterator::DoEndVisitArrayItem (void)
98
{}
125
{
126
}
99
127
100
void 
128
void 
101
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
129
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
 Lines 174-231    Link Here 
174
    {
202
    {
175
      NS_LOG_DEBUG ("store " << tid.GetName ());
203
      NS_LOG_DEBUG ("store " << tid.GetName ());
176
      for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
204
      for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
177
	{
205
        {
178
	  Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
206
          Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
179
	  const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
207
          const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
180
	  if (ptrChecker != 0)
208
          if (ptrChecker != 0)
181
	    {
209
            {
182
	      NS_LOG_DEBUG ("pointer attribute " << tid.GetAttributeName (i));
210
              NS_LOG_DEBUG ("pointer attribute " << tid.GetAttributeName (i));
183
	      PointerValue ptr;
211
              PointerValue ptr;
184
	      object->GetAttribute (tid.GetAttributeName (i), ptr);
212
              object->GetAttribute (tid.GetAttributeName (i), ptr);
185
	      Ptr<Object> tmp = ptr.Get<Object> ();
213
              Ptr<Object> tmp = ptr.Get<Object> ();
186
	      if (tmp != 0)
214
              if (tmp != 0)
187
		{
215
                {
188
		  StartVisitPointerAttribute (object, tid.GetAttributeName (i), tmp);
216
                  StartVisitPointerAttribute (object, tid.GetAttributeName (i),
189
		  m_examined.push_back (object);
217
                                              tmp);
190
		  DoIterate (tmp);
218
                  m_examined.push_back (object);
191
		  m_examined.pop_back ();
219
                  DoIterate (tmp);
192
		  EndVisitPointerAttribute ();
220
                  m_examined.pop_back ();
193
		}
221
                  EndVisitPointerAttribute ();
194
	      continue;
222
                }
195
	    }
223
              continue;
196
	  // attempt to cast to an object vector.
224
            }
197
	  const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
225
          // attempt to cast to an object vector.
198
	  if (vectorChecker != 0)
226
          const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
199
	    {
227
          if (vectorChecker != 0)
200
	      NS_LOG_DEBUG ("vector attribute " << tid.GetAttributeName (i));
228
            {
201
	      ObjectVectorValue vector;
229
              NS_LOG_DEBUG ("vector attribute " << tid.GetAttributeName (i));
202
	      object->GetAttribute (tid.GetAttributeName (i), vector);
230
              ObjectVectorValue vector;
203
	      StartVisitArrayAttribute (object, tid.GetAttributeName (i), vector);
231
              object->GetAttribute (tid.GetAttributeName (i), vector);
204
	      for (uint32_t j = 0; j < vector.GetN (); ++j)
232
              StartVisitArrayAttribute (object, tid.GetAttributeName (i), vector);
205
		{
233
              for (uint32_t j = 0; j < vector.GetN (); ++j)
206
		  NS_LOG_DEBUG ("vector attribute item " << j);
234
                {
207
		  Ptr<Object> tmp = vector.Get (j);
235
                  NS_LOG_DEBUG ("vector attribute item " << j);
208
		  StartVisitArrayItem (vector, j, tmp);
236
                  Ptr<Object> tmp = vector.Get (j);
209
		  m_examined.push_back (object);
237
                  StartVisitArrayItem (vector, j, tmp);
210
		  DoIterate (tmp);
238
                  m_examined.push_back (object);
211
		  m_examined.pop_back ();
239
                  DoIterate (tmp);
212
		  EndVisitArrayItem ();
240
                  m_examined.pop_back ();
213
		}
241
                  EndVisitArrayItem ();
214
	      EndVisitArrayAttribute ();
242
                }
215
	      continue;
243
              EndVisitArrayAttribute ();
216
	    }
244
              continue;
217
	  uint32_t flags = tid.GetAttributeFlags (i);
245
            }
218
	  Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (i);
246
          uint32_t flags = tid.GetAttributeFlags (i);
219
	  if ((flags & TypeId::ATTR_GET) && accessor->HasGetter () &&
247
          Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (i);
220
	      (flags & TypeId::ATTR_SET) && accessor->HasSetter ())
248
          if ((flags & TypeId::ATTR_GET) && accessor->HasGetter () && 
221
	    {
249
              (flags & TypeId::ATTR_SET) && accessor->HasSetter ())
222
	      VisitAttribute (object, tid.GetAttributeName (i));
250
            {
223
	    }
251
              VisitAttribute (object, tid.GetAttributeName (i));
224
	  else
252
            }
225
	    {
253
          else
226
	      NS_LOG_DEBUG ("could not store " << tid.GetAttributeName (i));
254
            {
227
	    }
255
              NS_LOG_DEBUG ("could not store " << tid.GetAttributeName (i));
228
	}
256
            }
257
        }
229
    }
258
    }
230
  Object::AggregateIterator iter = object->GetAggregateIterator ();
259
  Object::AggregateIterator iter = object->GetAggregateIterator ();
231
  bool recursiveAggregate = false;
260
  bool recursiveAggregate = false;
 Lines 233-254    Link Here 
233
    {
262
    {
234
      Ptr<const Object> tmp = iter.Next ();
263
      Ptr<const Object> tmp = iter.Next ();
235
      if (IsExamined (tmp))
264
      if (IsExamined (tmp))
236
	{
265
        {
237
	  recursiveAggregate = true;
266
          recursiveAggregate = true;
238
	}
267
        }
239
    }
268
    }
240
  if (!recursiveAggregate)
269
  if (!recursiveAggregate)
241
    {
270
    {
242
      iter = object->GetAggregateIterator ();
271
      iter = object->GetAggregateIterator ();
243
      while (iter.HasNext ())
272
      while (iter.HasNext ())
244
	{
273
        {
245
	  Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
274
          Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
246
	  StartVisitObject (tmp);
275
          StartVisitObject (tmp);
247
	  m_examined.push_back (object);
276
          m_examined.push_back (object);
248
	  DoIterate (tmp);
277
          DoIterate (tmp);
249
	  m_examined.pop_back ();
278
          m_examined.pop_back ();
250
	  EndVisitObject ();
279
          EndVisitObject ();
251
	}
280
        }
252
    }
281
    }
253
}
282
}
254
283
(-)a/src/contrib/attribute-iterator.h (+18 lines)
 Lines 1-3    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
17
 */
18
 
1
#ifndef ATTRIBUTE_ITERATOR_H
19
#ifndef ATTRIBUTE_ITERATOR_H
2
#define ATTRIBUTE_ITERATOR_H
20
#define ATTRIBUTE_ITERATOR_H
3
21
(-)80cd9b67a1bd (+594 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
#include "display-functions.h"
20
#include "raw-text-config.h"
21
#include "ns3/config.h"
22
#include "ns3/string.h"
23
#include "ns3/pointer.h"
24
25
namespace ns3 {
26
/**
27
 * This function includes the name of the attribute or the editable value
28
 * in the second column 
29
 */
30
void
31
cell_data_function_col_1 (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
32
                          GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
33
{
34
  ModelNode *node;
35
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
36
  if (node->type == ModelNode::NODE_ATTRIBUTE)
37
    {
38
      StringValue str;
39
      node->object->GetAttribute (node->name, str);
40
      g_object_set (renderer, "text", str.Get ().c_str (), (char*) 0);
41
      g_object_set (renderer, "editable", TRUE, (char*) 0);
42
    }
43
  else
44
    {
45
      g_object_set (renderer, "text", "", (char*) 0);
46
      g_object_set (renderer, "editable", FALSE, (char*) 0);
47
    }
48
}
49
/**
50
 * This function includes the name of the object, pointer, vector or vector item
51
 * in the first column
52
 */
53
void
54
cell_data_function_col_0 (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model,
55
                          GtkTreeIter *iter, gpointer user_data)
56
{
57
  ModelNode *node;
58
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
59
  g_object_set (renderer, "editable", FALSE, (char*) 0);
60
  switch (node->type)
61
    {
62
    case ModelNode::NODE_OBJECT:
63
      g_object_set (renderer, "text", node->object->GetInstanceTypeId ().GetName ().c_str (), (char*) 0);
64
      break;
65
    case ModelNode::NODE_POINTER:
66
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
67
      break;
68
    case ModelNode::NODE_VECTOR:
69
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
70
      break;
71
    case ModelNode::NODE_VECTOR_ITEM:
72
      {
73
        std::stringstream oss;
74
        oss << node->index;
75
        g_object_set (renderer, "text", oss.str ().c_str (), (char*) 0);
76
      }
77
      break;
78
    case ModelNode::NODE_ATTRIBUTE:
79
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
80
      break;
81
    }
82
}
83
84
/**
85
 * This is the callback called when the value of an attribute is changed
86
 */
87
void
88
cell_edited_callback (GtkCellRendererText *cell, gchar *path_string,
89
                      gchar *new_text, gpointer user_data)
90
{
91
  GtkTreeModel *model = GTK_TREE_MODEL (user_data);
92
  GtkTreeIter iter;
93
  gtk_tree_model_get_iter_from_string (model, &iter, path_string);
94
  ModelNode *node;
95
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
96
  NS_ASSERT (node->type == ModelNode::NODE_ATTRIBUTE);
97
  node->object->SetAttribute (node->name, StringValue (new_text));
98
}
99
100
/**
101
 * This function gets the column number 0 or 1 from the mouse
102
 * click
103
 */
104
int
105
get_col_number_from_tree_view_column (GtkTreeViewColumn *col)
106
{
107
  GList *cols;
108
  int num;
109
  g_return_val_if_fail (col != 0, -1);
110
  g_return_val_if_fail (col->tree_view != 0, -1);
111
  cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (col->tree_view));
112
  num = g_list_index (cols, (gpointer) col);
113
  g_list_free (cols);
114
  return num;
115
}
116
117
/**
118
 * This function displays the tooltip for an object, pointer, vector
119
 * item or an attribute
120
 */
121
gboolean
122
cell_tooltip_callback (GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, 
123
                       GtkTooltip *tooltip, gpointer user_data)
124
{
125
  GtkTreeModel *model;
126
  GtkTreeIter iter;
127
  GtkTreeViewColumn * column;
128
  if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), &x, &y,
129
                                          keyboard_tip, &model, 0, &iter))
130
    {
131
      return FALSE;
132
    }
133
  if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, 0, &column, 0, 0))
134
    {
135
      return FALSE;
136
    }
137
  int col = get_col_number_from_tree_view_column (column);
138
139
  ModelNode *node;
140
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
141
142
  switch (node->type)
143
    {
144
    case ModelNode::NODE_OBJECT:
145
      if (col == 0)
146
        {
147
          std::string tip = "This object is of type "
148
            + node->object->GetInstanceTypeId ().GetName ();
149
          gtk_tooltip_set_text (tooltip, tip.c_str ());
150
          return TRUE;
151
        }
152
      break;
153
    case ModelNode::NODE_POINTER:
154
      if (col == 0)
155
        {
156
          PointerValue ptr;
157
          node->object->GetAttribute (node->name, ptr);
158
          std::string tip = "This object is of type "
159
            + ptr.GetObject ()->GetInstanceTypeId ().GetName ();
160
          gtk_tooltip_set_text (tooltip, tip.c_str ());
161
          return TRUE;
162
        }
163
      break;
164
    case ModelNode::NODE_VECTOR:
165
      break;
166
    case ModelNode::NODE_VECTOR_ITEM:
167
      if (col == 0)
168
        {
169
          std::string tip = "This object is of type "
170
            + node->object->GetInstanceTypeId ().GetName ();
171
          gtk_tooltip_set_text (tooltip, tip.c_str ());
172
          return TRUE;
173
        }
174
      break;
175
    case ModelNode::NODE_ATTRIBUTE:
176
      {
177
        uint32_t attrIndex = 0;
178
        TypeId tid;
179
        for (tid = node->object->GetInstanceTypeId (); tid.HasParent (); tid
180
               = tid.GetParent ())
181
          {
182
            for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
183
              {
184
                if (tid.GetAttributeName (i) == node->name)
185
                  {
186
                    attrIndex = i;
187
                    goto out;
188
                  }
189
              }
190
          }
191
out: if (col == 0)
192
          {
193
            std::string tip = tid.GetAttributeHelp (attrIndex);
194
            gtk_tooltip_set_text (tooltip, tip.c_str ());
195
          }
196
        else
197
          {
198
            Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (
199
                attrIndex);
200
            std::string tip;
201
            tip = "This attribute is of type " + checker->GetValueTypeName ();
202
            if (checker->HasUnderlyingTypeInformation ())
203
              {
204
                tip += " " + checker->GetUnderlyingTypeInformation ();
205
              }
206
            gtk_tooltip_set_text (tooltip, tip.c_str ());
207
          }
208
        return TRUE;
209
      }
210
      break;
211
    }
212
  return FALSE;
213
}
214
215
/**
216
 * This is the main view opening the widget, getting tooltips and drawing the 
217
 * tree of attributes...
218
 */
219
GtkWidget *
220
create_view (GtkTreeStore *model)
221
{
222
  GtkTreeViewColumn *col;
223
  GtkCellRenderer *renderer;
224
  GtkWidget *view;
225
226
  view = gtk_tree_view_new ();
227
  g_object_set (view, "has-tooltip", TRUE, (char*) 0);
228
  g_signal_connect (view, "query-tooltip", (GCallback) cell_tooltip_callback, 0);
229
230
  gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH);
231
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
232
233
  col = gtk_tree_view_column_new ();
234
  gtk_tree_view_column_set_title (col, "Object Attributes");
235
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
236
  renderer = gtk_cell_renderer_text_new ();
237
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
238
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_0, 0, 0);
239
  g_object_set (renderer, "editable", FALSE, (char*) 0);
240
241
  col = gtk_tree_view_column_new ();
242
  gtk_tree_view_column_set_title (col, "Attribute Value");
243
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
244
  renderer = gtk_cell_renderer_text_new ();
245
  g_signal_connect (renderer, "edited", (GCallback) cell_edited_callback, model);
246
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
247
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_1, 0, 0);
248
249
  gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (model));
250
251
  g_object_unref (model); /* destroy model automatically with view */
252
253
  return view;
254
}
255
256
/**
257
 * This is the action done when the user presses on the save button.
258
 * It will save the config to a file.
259
 */
260
void
261
save_clicked (GtkButton *button, gpointer user_data)
262
{
263
  GtkWidget *parent_window = GTK_WIDGET (user_data);
264
  GtkWidget *dialog;
265
266
  dialog = gtk_file_chooser_dialog_new ("Save File", GTK_WINDOW (parent_window), GTK_FILE_CHOOSER_ACTION_SAVE,
267
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE,
268
                                        GTK_RESPONSE_ACCEPT, (char *) 0);
269
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
270
                                                  TRUE);
271
272
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "config.txt");
273
274
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
275
    {
276
      char *filename;
277
278
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
279
      RawTextConfigSave config;
280
      config.SetFilename (filename);
281
      config.Attributes ();
282
      g_free (filename);
283
    }
284
285
  gtk_widget_destroy (dialog);
286
}
287
288
/**
289
 * If the user presses the button load, it will load the config file into memory.
290
 */
291
void
292
load_clicked (GtkButton *button, gpointer user_data)
293
{
294
  GtkWidget *parent_window = GTK_WIDGET (user_data);
295
  GtkWidget *dialog;
296
297
  dialog = gtk_file_chooser_dialog_new ("Open File", GTK_WINDOW (parent_window), GTK_FILE_CHOOSER_ACTION_OPEN,
298
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
299
                                        GTK_RESPONSE_ACCEPT, (char *) 0);
300
301
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
302
    {
303
      char *filename;
304
305
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
306
      RawTextConfigLoad config;
307
      config.SetFilename (filename);
308
      config.Attributes ();
309
    }
310
311
  gtk_widget_destroy (dialog);
312
}
313
314
/**
315
 * Exit the window when exit button is pressed
316
 */
317
void
318
exit_clicked_callback (GtkButton *button, gpointer user_data)
319
{
320
  gtk_main_quit ();
321
  gtk_widget_hide (GTK_WIDGET (user_data));
322
}
323
324
/**
325
 * Exit the application
326
 */
327
gboolean
328
delete_event_callback (GtkWidget *widget, GdkEvent *event, gpointer user_data)
329
{
330
  gtk_main_quit ();
331
  gtk_widget_hide (GTK_WIDGET (user_data));
332
  return TRUE;
333
}
334
335
/**
336
 * Delete the tree model contents
337
 */
338
gboolean
339
clean_model_callback (GtkTreeModel *model, GtkTreePath *path,
340
                      GtkTreeIter *iter, gpointer data)
341
{
342
  ModelNode *node;
343
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, COL_NODE, &node, -1);
344
  delete node;
345
  gtk_tree_store_set (GTK_TREE_STORE (model), iter, COL_NODE, (ModelNode*) 0,
346
                      -1);
347
  return FALSE;
348
}
349
350
/**************************     display functions used by default configurator **********************/
351
/**
352
 * This function writes data in the second column, this data is going to be editable
353
 * if it is a NODE_ATTRIBUTE
354
 */
355
void
356
cell_data_function_col_1_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer, 
357
                                         GtkTreeModel *model, GtkTreeIter *iter,
358
                                         gpointer user_data)
359
{
360
  ModelTypeid *node;
361
  gtk_tree_model_get (model, iter, COL_TYPEID, &node, -1);
362
  if (node->type == ModelTypeid::NODE_ATTRIBUTE)
363
    {
364
      g_object_set (renderer, "text", node->defaultValue.c_str (), (char*) 0);
365
      g_object_set (renderer, "editable", TRUE, (char*) 0);
366
    }
367
  else
368
    {
369
      g_object_set (renderer, "text", "", (char*) 0);
370
      g_object_set (renderer, "editable", FALSE, (char*) 0);
371
    }
372
}
373
/**
374
 * This function writes the attribute or typeid name in the column 0
375
 */
376
void
377
cell_data_function_col_0_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, 
378
                                         GtkTreeIter *iter, gpointer user_data)
379
{
380
  ModelTypeid *node;
381
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
382
  g_object_set (renderer, "editable", FALSE, (char*) 0);
383
  switch (node->type)
384
    {
385
    case ModelTypeid::NODE_TYPEID:
386
      g_object_set (renderer, "text", node->tid.GetName ().c_str (), (char*) 0);
387
      break;
388
    case ModelTypeid::NODE_ATTRIBUTE:
389
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
390
      break;
391
    }
392
}
393
394
395
/**
396
 *  This functions is called whenever there is a change in the value of an attribute
397
 *  If the input value is ok, it will be updated in the default value and in the
398
 *  gui, otherwise, it won't be updated in both.
399
 */
400
void
401
cell_edited_callback_config_default (GtkCellRendererText *cell, gchar *path_string,
402
                                     gchar *new_text, gpointer user_data)
403
{
404
  GtkTreeModel *model = GTK_TREE_MODEL (user_data);
405
  GtkTreeIter iter;
406
  gtk_tree_model_get_iter_from_string (model, &iter, path_string);
407
  ModelTypeid *node;
408
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
409
  NS_ASSERT (node->type == ModelTypeid::NODE_ATTRIBUTE);
410
  if (Config::SetDefaultFailSafe (node->tid.GetAttributeFullName (node->index),StringValue (new_text)))
411
    {
412
      node->defaultValue = new_text;
413
    }
414
}
415
416
/**
417
 * This function is used to display a tooltip whenever the user puts the mouse
418
 * over a type ID or an attribute. It will give the type and the possible values of
419
 * an attribute value and the type of the object for an attribute object or a 
420
 * typeID object 
421
 */
422
gboolean
423
cell_tooltip_callback_config_default (GtkWidget *widget, gint x, gint y,
424
                                      gboolean keyboard_tip, GtkTooltip *tooltip, gpointer user_data)
425
{
426
  GtkTreeModel *model;
427
  GtkTreeIter iter;
428
  GtkTreeViewColumn * column;
429
  if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), &x, &y,
430
                                          keyboard_tip, &model, 0, &iter))
431
    {
432
      return FALSE;
433
    }
434
  if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, 0, &column, 0, 0))
435
    {
436
      return FALSE;
437
    }
438
  int col = get_col_number_from_tree_view_column (column);
439
440
  ModelTypeid *node;
441
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
442
443
  switch (node->type)
444
    {
445
    case ModelTypeid::NODE_TYPEID:
446
      if (col == 0)
447
        {
448
          std::string tip = "This object is of type " + node->tid.GetName ();
449
          gtk_tooltip_set_text (tooltip, tip.c_str ());
450
          return TRUE;
451
        }
452
      break;
453
    case ModelTypeid::NODE_ATTRIBUTE:
454
      {
455
        uint32_t attrIndex = node->index;
456
        if (col == 0)
457
          {
458
            std::string tip = node->tid.GetAttributeHelp (attrIndex);
459
            gtk_tooltip_set_text (tooltip, tip.c_str ());
460
          }
461
        else
462
          {
463
            Ptr<const AttributeChecker> checker = node->tid.GetAttributeChecker (attrIndex);
464
            std::string tip;
465
            tip = "This attribute is of type " + checker->GetValueTypeName ();
466
            if (checker->HasUnderlyingTypeInformation ())
467
              {
468
                tip += " " + checker->GetUnderlyingTypeInformation ();
469
              }
470
            gtk_tooltip_set_text (tooltip, tip.c_str ());
471
          }
472
        return TRUE;
473
      }
474
      break;
475
    }
476
  return FALSE;
477
}
478
479
/**
480
 * This is the action done when the user presses on the save button.
481
 * It will save the config to a file.
482
 */
483
void
484
save_clicked_default (GtkButton *button, gpointer user_data)
485
{
486
  GtkWidget *parent_window = GTK_WIDGET (user_data);
487
  GtkWidget *dialog;
488
489
  dialog = gtk_file_chooser_dialog_new ("Save File", GTK_WINDOW (parent_window), GTK_FILE_CHOOSER_ACTION_SAVE,
490
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE,
491
                                        GTK_RESPONSE_ACCEPT, (char *) 0);
492
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
493
                                                  TRUE);
494
495
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "config.txt");
496
497
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
498
    {
499
      char *filename;
500
501
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
502
      RawTextConfigSave config;
503
      config.SetFilename (filename);
504
      config.Default ();
505
      g_free (filename);
506
    }
507
508
  gtk_widget_destroy (dialog);
509
}
510
511
/**
512
 * If the user presses the button load, it will load the config file into memory.
513
 */
514
void
515
load_clicked_default (GtkButton *button, gpointer user_data)
516
{
517
  GtkWidget *parent_window = GTK_WIDGET (user_data);
518
  GtkWidget *dialog;
519
520
  dialog = gtk_file_chooser_dialog_new ("Open File", GTK_WINDOW (parent_window), GTK_FILE_CHOOSER_ACTION_OPEN,
521
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
522
                                        GTK_RESPONSE_ACCEPT, (char *) 0);
523
524
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
525
    {
526
      char *filename;
527
528
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
529
      RawTextConfigLoad config;
530
      config.SetFilename (filename);
531
      config.Default ();
532
    }
533
534
  gtk_widget_destroy (dialog);
535
}
536
537
/**
538
 * This is the main view opening the widget, getting tooltips and drawing the 
539
 * tree of attributes
540
 */
541
GtkWidget *
542
create_view_config_default (GtkTreeStore *model)
543
{
544
  GtkTreeViewColumn *col;
545
  GtkCellRenderer *renderer;
546
  GtkWidget *view;
547
548
  view = gtk_tree_view_new ();
549
  g_object_set (view, "has-tooltip", TRUE, (char*) 0);
550
  g_signal_connect (view, "query-tooltip", (GCallback) cell_tooltip_callback_config_default, 0);
551
552
  gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH);
553
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
554
555
  col = gtk_tree_view_column_new ();
556
  gtk_tree_view_column_set_title (col, "Object Attributes");
557
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
558
  renderer = gtk_cell_renderer_text_new ();
559
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
560
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_0_config_default, 0, 0);
561
  g_object_set (renderer, "editable", FALSE, (char*) 0);
562
563
  col = gtk_tree_view_column_new ();
564
  gtk_tree_view_column_set_title (col, "Attribute Value");
565
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
566
  renderer = gtk_cell_renderer_text_new ();
567
  g_signal_connect (renderer, "edited", (GCallback) cell_edited_callback_config_default, model);
568
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
569
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_1_config_default, 0, 0);
570
571
  gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (model));
572
573
  g_object_unref (model); /* destroy model automatically with view */
574
575
  return view;
576
}
577
578
/**
579
 * Delete the tree model contents
580
 */
581
gboolean
582
clean_model_callback_config_default (GtkTreeModel *model, GtkTreePath *path,
583
                                     GtkTreeIter *iter, gpointer data)
584
{
585
  ModelTypeid *node;
586
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, COL_TYPEID, &node, -1);
587
  delete node;
588
  gtk_tree_store_set (GTK_TREE_STORE (model), iter, COL_TYPEID, (ModelTypeid*) 0, -1);
589
  return FALSE;
590
}
591
592
593
}//end ns3 namespace
594
(-)80cd9b67a1bd (+150 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
#ifndef DISPLAY_FUNCTIONS_H
20
#define DISPLAY_FUNCTIONS_H
21
22
#include "model-node-creator.h"
23
#include "model-typeid-creator.h"
24
#include <gtk/gtk.h>
25
26
namespace ns3 {
27
/**
28
 * This function includes the name of the attribute or the editable value
29
 * in the second column 
30
 */
31
void
32
cell_data_function_col_1 (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
33
                          GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
34
/**
35
 * This function includes the name of the object, pointer, vector or vector item
36
 * in the first column
37
 */
38
void
39
cell_data_function_col_0 (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model,
40
                          GtkTreeIter *iter, gpointer user_data);
41
/**
42
 * This is the callback called when the value of an attribute is changed
43
 */
44
void
45
cell_edited_callback (GtkCellRendererText *cell, gchar *path_string,
46
                      gchar *new_text, gpointer user_data);
47
/**
48
 * This function gets the column number 0 or 1 from the mouse
49
 * click
50
 */
51
int
52
get_col_number_from_tree_view_column (GtkTreeViewColumn *col);
53
/**
54
 * This function displays the tooltip for an object, pointer, vector
55
 * item or an attribute
56
 */
57
gboolean
58
cell_tooltip_callback (GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, 
59
                       GtkTooltip *tooltip, gpointer user_data);
60
/**
61
 * This is the main view opening the widget, getting tooltips and drawing the 
62
 * tree of attributes...
63
 */
64
GtkWidget *
65
create_view (GtkTreeStore *model);
66
/**
67
 * This is the action done when the user presses on the save button.
68
 * It will save the config to a file.
69
 */
70
void
71
save_clicked (GtkButton *button, gpointer user_data);
72
/**
73
 * If the user presses the button load, it will load the config file into memory.
74
 */
75
void
76
load_clicked (GtkButton *button, gpointer user_data);
77
/**
78
 * Exit the window when exit button is pressed
79
 */
80
void
81
exit_clicked_callback (GtkButton *button, gpointer user_data);
82
/**
83
 * Exit the application
84
 */
85
gboolean
86
delete_event_callback (GtkWidget *widget, GdkEvent *event, gpointer user_data);
87
/**
88
 * Delete the tree model contents
89
 */
90
gboolean
91
clean_model_callback (GtkTreeModel *model, GtkTreePath *path,
92
                      GtkTreeIter *iter, gpointer data);
93
/**************************     display functions used by default configurator **********************/
94
/**
95
 * This function writes data in the second column, this data is going to be editable
96
 * if it is a NODE_ATTRIBUTE
97
 */
98
void
99
cell_data_function_col_1_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer, 
100
                                         GtkTreeModel *model, GtkTreeIter *iter,
101
                                         gpointer user_data);
102
/**
103
 * This function writes the attribute or typeid name in the column 0
104
 */
105
void
106
cell_data_function_col_0_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, 
107
                                         GtkTreeIter *iter, gpointer user_data);
108
/**
109
 * This is the action done when the user presses on the save button.
110
 * It will save the config to a file.
111
 */
112
void
113
save_clicked_default (GtkButton *button, gpointer user_data);
114
/**
115
 * If the user presses the button load, it will load the config file into memory.
116
 */
117
void
118
load_clicked_default (GtkButton *button, gpointer user_data);
119
/**
120
 *  This functions is called whenever there is a change in the value of an attribute
121
 *  If the input value is ok, it will be updated in the default value and in the
122
 *  gui, otherwise, it won't be updated in both.
123
 */
124
void
125
cell_edited_callback_config_default (GtkCellRendererText *cell, gchar *path_string,
126
                                     gchar *new_text, gpointer user_data);
127
/**
128
 * This function is used to display a tooltip whenever the user puts the mouse
129
 * over a type ID or an attribute. It will give the type and the possible values of
130
 * an attribute value and the type of the object for an attribute object or a 
131
 * typeID object 
132
 */
133
gboolean
134
cell_tooltip_callback_config_default (GtkWidget *widget, gint x, gint y,
135
                                      gboolean keyboard_tip, GtkTooltip *tooltip, gpointer user_data);
136
/**
137
 * This is the main view opening the widget, getting tooltips and drawing the 
138
 * tree of attributes
139
 */
140
GtkWidget *
141
create_view_config_default (GtkTreeStore *model);
142
/**
143
 * Delete the tree model contents
144
 */
145
gboolean
146
clean_model_callback_config_default (GtkTreeModel *model, GtkTreePath *path,
147
                                     GtkTreeIter *iter, gpointer data);
148
}//end namespace ns3
149
150
#endif
(-)a/src/contrib/gtk-config-store.cc (-470 / +72 lines)
 Lines 1-11    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
1
#include "gtk-config-store.h"
20
#include "gtk-config-store.h"
2
#include "attribute-iterator.h"
3
#include "raw-text-config.h"
21
#include "raw-text-config.h"
4
#include "ns3/config.h"
22
#include "display-functions.h"
5
#include "ns3/string.h"
6
#include "ns3/pointer.h"
7
#include "ns3/log.h"
23
#include "ns3/log.h"
8
#include <gtk/gtk.h>
9
#include <fstream>
24
#include <fstream>
10
25
11
26
 Lines 13-486    Link Here 
13
28
14
NS_LOG_COMPONENT_DEFINE ("GtkconfigStore");
29
NS_LOG_COMPONENT_DEFINE ("GtkconfigStore");
15
30
16
enum {
17
  COL_NODE = 0,
18
  COL_LAST
19
};
20
31
21
struct ModelNode
32
GtkConfigStore::GtkConfigStore ()
22
{
33
{
23
  enum {
24
    // store object + attribute name
25
    NODE_ATTRIBUTE,
26
    // store object + attribute name
27
    NODE_POINTER,
28
    // store object + attribute name
29
    NODE_VECTOR,
30
    // store index + value (object)
31
    NODE_VECTOR_ITEM,
32
    // store object
33
    NODE_OBJECT
34
  } type;
35
  std::string name;
36
  Ptr<Object> object;
37
  uint32_t index;
38
};
39
40
class ModelCreator : public AttributeIterator
41
{
42
public:
43
  ModelCreator ();
44
45
  void Build (GtkTreeStore *treestore);
46
private:
47
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
48
  virtual void DoStartVisitObject (Ptr<Object> object);
49
  virtual void DoEndVisitObject (void);
50
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
51
  virtual void DoEndVisitPointerAttribute (void);
52
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector);
53
  virtual void DoEndVisitArrayAttribute (void);
54
  virtual void DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item);
55
  virtual void DoEndVisitArrayItem (void);
56
  void Add (ModelNode *node);
57
  void Remove (void);
58
59
  GtkTreeStore *m_treestore;
60
  std::vector<GtkTreeIter *> m_iters;
61
};
62
63
ModelCreator::ModelCreator ()
64
{}
65
void 
66
ModelCreator::Build (GtkTreeStore *treestore)
67
{
68
  m_treestore = treestore;
69
  m_iters.push_back (0);
70
  Iterate ();
71
  NS_ASSERT (m_iters.size () == 1);
72
}
34
}
73
35
36
void
37
GtkConfigStore::ConfigureDefaults (void)
38
{
39
  //this function should be called before running the script to enable the user
40
  //to configure the default values for the objects he wants to use
41
  GtkWidget *window;
42
  GtkWidget *view;
43
  GtkWidget *scroll;
74
44
75
void
45
  gtk_init (0, 0);
76
ModelCreator::Add (ModelNode *node)
46
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
77
{
47
  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Default attributes.");
78
  GtkTreeIter *parent = m_iters.back ();
48
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
79
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
49
80
  gtk_tree_store_append (m_treestore, current, parent);
50
  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
81
  gtk_tree_store_set (m_treestore, current,
51
  GtkTreeStore *model = gtk_tree_store_new (COL_LAST, G_TYPE_POINTER);
82
		      COL_NODE, node,
52
  ModelTypeidCreator creator;
83
                     -1);
53
  creator.Build (model);
84
  m_iters.push_back (current);
54
55
  view = create_view_config_default (model);
56
  scroll = gtk_scrolled_window_new (0, 0);
57
  gtk_container_add (GTK_CONTAINER (scroll), view);
58
59
  GtkWidget *vbox = gtk_vbox_new (FALSE, 5);
60
  gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
61
  gtk_box_pack_end (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 0);
62
  GtkWidget *hbox = gtk_hbox_new (FALSE, 5);
63
  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
64
  GtkWidget *save = gtk_button_new_with_label ("Save");
65
  g_signal_connect (save, "clicked",  (GCallback) save_clicked_default, window);
66
  gtk_box_pack_end (GTK_BOX (hbox), save, FALSE, FALSE, 0);
67
  GtkWidget *load = gtk_button_new_with_label ("Load");
68
  g_signal_connect (load, "clicked",  (GCallback) load_clicked_default, window);
69
  gtk_box_pack_end (GTK_BOX (hbox), load, FALSE, FALSE, 0);
70
  GtkWidget *exit = gtk_button_new_with_label ("Run Simulation");
71
  g_signal_connect (exit, "clicked",  (GCallback) exit_clicked_callback, window);
72
  gtk_box_pack_end (GTK_BOX (hbox), exit, FALSE, FALSE, 0);
73
74
  gtk_container_add (GTK_CONTAINER (window), vbox);
75
76
  gtk_widget_show_all (window);
77
78
  gtk_main ();
79
80
  gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
81
                          clean_model_callback_config_default,
82
                          0);
83
84
  gtk_widget_destroy (window); 
85
}
85
}
86
void
87
ModelCreator::Remove (void)
88
{
89
  GtkTreeIter *iter = m_iters.back ();
90
  g_free (iter);
91
  m_iters.pop_back ();
92
}
93
94
void 
95
ModelCreator::DoVisitAttribute (Ptr<Object> object, std::string name)
96
{
97
  ModelNode *node = new ModelNode ();
98
  node->type = ModelNode::NODE_ATTRIBUTE;
99
  node->object = object;
100
  node->name = name;
101
  Add (node);
102
  Remove ();
103
}
104
void 
105
ModelCreator::DoStartVisitObject (Ptr<Object> object)
106
{
107
  ModelNode *node = new ModelNode ();
108
  node->type = ModelNode::NODE_OBJECT;
109
  node->object = object;
110
  Add (node);
111
}
112
void 
113
ModelCreator::DoEndVisitObject (void)
114
{
115
  Remove ();
116
}
117
void 
118
ModelCreator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
119
{
120
  ModelNode *node = new ModelNode ();
121
  node->type = ModelNode::NODE_POINTER;
122
  node->object = object;
123
  node->name = name;
124
  Add (node);
125
}
126
void 
127
ModelCreator::DoEndVisitPointerAttribute (void)
128
{
129
  Remove ();
130
}
131
void 
132
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
133
{
134
  ModelNode *node = new ModelNode ();
135
  node->type = ModelNode::NODE_VECTOR;
136
  node->object = object;
137
  node->name = name;
138
  Add (node);
139
}
140
void 
141
ModelCreator::DoEndVisitArrayAttribute (void)
142
{
143
  Remove ();
144
}
145
void 
146
ModelCreator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
147
{
148
  GtkTreeIter *parent = m_iters.back ();
149
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
150
  ModelNode *node = new ModelNode ();
151
  node->type = ModelNode::NODE_VECTOR_ITEM;
152
  node->object = item;
153
  node->index = index;
154
  gtk_tree_store_append (m_treestore, current, parent);
155
  gtk_tree_store_set (m_treestore, current,
156
		      COL_NODE, node,
157
                     -1);
158
  m_iters.push_back (current);
159
}
160
void 
161
ModelCreator::DoEndVisitArrayItem (void)
162
{
163
  GtkTreeIter *iter = m_iters.back ();
164
  g_free (iter);
165
  m_iters.pop_back ();  
166
}
167
168
static void
169
cell_data_function_col_1 (GtkTreeViewColumn *col,
170
			  GtkCellRenderer   *renderer,
171
			  GtkTreeModel      *model,
172
			  GtkTreeIter       *iter,
173
			  gpointer           user_data)
174
{
175
  ModelNode *node;
176
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
177
  if (node->type == ModelNode::NODE_ATTRIBUTE)
178
    {
179
      StringValue str;
180
      node->object->GetAttribute (node->name, str);
181
      g_object_set(renderer, "text", str.Get ().c_str (), (char*)0);
182
      g_object_set(renderer, "editable", TRUE, (char*)0);
183
    }
184
  else
185
    {
186
      g_object_set(renderer, "text", "", (char*)0);
187
      g_object_set(renderer, "editable", FALSE, (char*)0);
188
    }
189
}
190
191
static void
192
cell_data_function_col_0 (GtkTreeViewColumn *col,
193
			  GtkCellRenderer   *renderer,
194
			  GtkTreeModel      *model,
195
			  GtkTreeIter       *iter,
196
			  gpointer           user_data)
197
{
198
  ModelNode *node;
199
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
200
  g_object_set (renderer, "editable", FALSE, (char*)0);
201
  switch (node->type) {
202
  case ModelNode::NODE_OBJECT:
203
    g_object_set(renderer, "text", node->object->GetInstanceTypeId ().GetName ().c_str (), (char*)0);
204
    break;
205
  case ModelNode::NODE_POINTER:
206
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
207
    break;
208
  case ModelNode::NODE_VECTOR:
209
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
210
    break;
211
  case ModelNode::NODE_VECTOR_ITEM: {
212
    std::stringstream oss;
213
    oss << node->index;
214
    g_object_set(renderer, "text", oss.str ().c_str (), (char*)0);
215
  } break;
216
  case ModelNode::NODE_ATTRIBUTE:
217
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
218
    break;
219
  }
220
}
221
222
223
static void
224
cell_edited_callback (GtkCellRendererText *cell,
225
		      gchar               *path_string,
226
		      gchar               *new_text,
227
		      gpointer             user_data)
228
{
229
  GtkTreeModel *model = GTK_TREE_MODEL (user_data);
230
  GtkTreeIter iter;
231
  gtk_tree_model_get_iter_from_string (model, &iter, path_string);
232
  ModelNode *node;
233
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
234
  NS_ASSERT (node->type == ModelNode::NODE_ATTRIBUTE);
235
  node->object->SetAttribute (node->name, StringValue (new_text));
236
}
237
238
static int
239
get_col_number_from_tree_view_column (GtkTreeViewColumn *col)
240
{
241
  GList *cols;
242
  int   num;
243
  g_return_val_if_fail ( col != 0, -1 );
244
  g_return_val_if_fail ( col->tree_view != 0, -1 );
245
  cols = gtk_tree_view_get_columns(GTK_TREE_VIEW(col->tree_view));
246
  num = g_list_index(cols, (gpointer) col);
247
  g_list_free(cols);
248
  return num;
249
}
250
251
static gboolean
252
cell_tooltip_callback (GtkWidget  *widget,
253
		       gint        x,
254
		       gint        y,
255
		       gboolean    keyboard_tip,
256
		       GtkTooltip *tooltip,
257
		       gpointer    user_data)
258
{
259
  GtkTreeModel *model;
260
  GtkTreeIter iter;
261
  GtkTreeViewColumn * column;
262
  if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), 
263
					  &x, &y, keyboard_tip,
264
					  &model, 0, &iter))
265
    {
266
      return FALSE;
267
    }
268
  if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
269
				      x, y, 0, &column, 0, 0))
270
    {
271
      return FALSE;
272
    }  
273
  int col = get_col_number_from_tree_view_column (column);
274
275
  ModelNode *node;
276
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
277
278
  switch (node->type) {
279
  case ModelNode::NODE_OBJECT:
280
    if (col == 0)
281
      {
282
	std::string tip = "This object is of type " + node->object->GetInstanceTypeId ().GetName ();
283
	gtk_tooltip_set_text (tooltip, tip.c_str ());
284
	return TRUE;
285
      }
286
    break;
287
  case ModelNode::NODE_POINTER:
288
    if (col == 0)
289
      {
290
	PointerValue ptr;
291
	node->object->GetAttribute (node->name, ptr);
292
	std::string tip = "This object is of type " + ptr.GetObject ()->GetInstanceTypeId ().GetName ();
293
	gtk_tooltip_set_text (tooltip, tip.c_str ());
294
	return TRUE;
295
      }
296
    break;
297
  case ModelNode::NODE_VECTOR:
298
    break;
299
  case ModelNode::NODE_VECTOR_ITEM:
300
    if (col == 0)
301
      {
302
	std::string tip = "This object is of type " + node->object->GetInstanceTypeId ().GetName ();
303
	gtk_tooltip_set_text (tooltip, tip.c_str ());
304
	return TRUE;
305
      }
306
    break;
307
  case ModelNode::NODE_ATTRIBUTE: {
308
    uint32_t attrIndex = 0;
309
    TypeId tid;
310
    for (tid = node->object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ())
311
      {
312
	for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
313
	  {
314
	    if (tid.GetAttributeName (i) == node->name)
315
	      {
316
		attrIndex = i;
317
		goto out;
318
	      }
319
	  }
320
      }
321
    out:
322
    if (col == 0)
323
      {
324
	std::string tip = tid.GetAttributeHelp (attrIndex);
325
	gtk_tooltip_set_text (tooltip, tip.c_str ());
326
      }
327
    else
328
      {
329
	Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (attrIndex);
330
	std::string tip;
331
	tip = "This attribute is of type " + checker->GetValueTypeName ();
332
	if (checker->HasUnderlyingTypeInformation ())
333
	  {
334
	    tip += " " + checker->GetUnderlyingTypeInformation ();
335
	  }
336
	gtk_tooltip_set_text (tooltip, tip.c_str ());
337
      }
338
    return TRUE;
339
  } break;
340
  }
341
  return FALSE;
342
}
343
344
345
static GtkWidget *
346
create_view (GtkTreeStore *model)
347
{
348
  GtkTreeViewColumn   *col;
349
  GtkCellRenderer     *renderer;
350
  GtkWidget           *view;
351
352
  view = gtk_tree_view_new();
353
  g_object_set (view, "has-tooltip", TRUE, (char*)0);
354
  g_signal_connect (view, "query-tooltip", (GCallback) cell_tooltip_callback, 0);
355
  
356
  gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH);
357
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
358
359
  col = gtk_tree_view_column_new();
360
  gtk_tree_view_column_set_title(col, "Object Attributes");
361
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
362
  renderer = gtk_cell_renderer_text_new ();
363
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
364
  gtk_tree_view_column_set_cell_data_func(col, renderer, cell_data_function_col_0, 0, 0);
365
  g_object_set(renderer, "editable", FALSE, (char*)0);
366
367
  col = gtk_tree_view_column_new();
368
  gtk_tree_view_column_set_title(col, "Attribute Value");
369
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
370
  renderer = gtk_cell_renderer_text_new();
371
  g_signal_connect(renderer, "edited", (GCallback) cell_edited_callback, model);
372
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
373
  gtk_tree_view_column_set_cell_data_func(col, renderer, cell_data_function_col_1, 0, 0);
374
375
376
  gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL (model));
377
378
  g_object_unref(model); /* destroy model automatically with view */
379
380
381
  return view;
382
}
383
384
static void
385
save_clicked (GtkButton *button,
386
	      gpointer   user_data)
387
{
388
  GtkWidget *parent_window = GTK_WIDGET (user_data);
389
  GtkWidget *dialog;
390
391
  dialog = gtk_file_chooser_dialog_new ("Save File",
392
					GTK_WINDOW (parent_window),
393
					GTK_FILE_CHOOSER_ACTION_SAVE,
394
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
395
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
396
					(char *)0);
397
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
398
399
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "config.txt");
400
401
402
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
403
    {
404
      char *filename;
405
406
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
407
      RawTextConfigSave config;
408
      config.SetFilename (filename);
409
      config.Attributes ();
410
      g_free (filename);
411
    }
412
413
  gtk_widget_destroy (dialog);
414
}
415
416
static void
417
load_clicked (GtkButton *button,
418
	      gpointer   user_data)
419
{
420
  GtkWidget *parent_window = GTK_WIDGET (user_data);
421
  GtkWidget *dialog;
422
423
  dialog = gtk_file_chooser_dialog_new ("Open File",
424
					GTK_WINDOW (parent_window),
425
					GTK_FILE_CHOOSER_ACTION_OPEN,
426
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
427
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
428
					(char *)0);
429
430
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
431
    {
432
      char *filename;
433
434
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
435
      RawTextConfigLoad config;
436
      config.SetFilename (filename);
437
      config.Attributes ();
438
    }
439
440
  gtk_widget_destroy (dialog);
441
}
442
443
static void 
444
exit_clicked_callback (GtkButton *button,
445
		       gpointer   user_data)
446
{
447
  gtk_main_quit ();
448
  gtk_widget_hide (GTK_WIDGET (user_data));
449
}
450
451
static gboolean
452
delete_event_callback (GtkWidget *widget,
453
		       GdkEvent  *event,
454
		       gpointer   user_data)
455
{
456
  gtk_main_quit ();
457
  gtk_widget_hide (GTK_WIDGET (user_data));
458
  return TRUE;
459
}
460
461
static gboolean 
462
clean_model_callback (GtkTreeModel *model,
463
		      GtkTreePath *path,
464
		      GtkTreeIter *iter,
465
		      gpointer data)
466
{
467
  ModelNode *node;
468
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, 
469
		      COL_NODE, &node, 
470
		      -1);
471
  delete node;
472
  gtk_tree_store_set (GTK_TREE_STORE (model), iter,
473
		      COL_NODE, (ModelNode*)0,
474
		      -1);
475
  return FALSE;
476
}
477
478
GtkConfigStore::GtkConfigStore ()
479
{}
480
481
void 
482
GtkConfigStore::ConfigureDefaults (void)
483
{}
484
86
485
void 
87
void 
486
GtkConfigStore::ConfigureAttributes (void)
88
GtkConfigStore::ConfigureAttributes (void)
 Lines 494-500    Link Here 
494
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
96
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
495
  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Object attributes.");
97
  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Object attributes.");
496
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
98
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
497
  
99
498
  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
100
  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
499
101
500
102
 Lines 528-535    Link Here 
528
  gtk_main ();
130
  gtk_main ();
529
131
530
  gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
132
  gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
531
			  clean_model_callback, 
133
                          clean_model_callback,
532
			  0);
134
                          0);
533
135
534
  gtk_widget_destroy (window);
136
  gtk_widget_destroy (window);
535
}
137
}
(-)a/src/contrib/gtk-config-store.h (+19 lines)
 Lines 1-3    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
1
#ifndef GTK_CONFIG_STORE_H
20
#ifndef GTK_CONFIG_STORE_H
2
#define GTK_CONFIG_STORE_H
21
#define GTK_CONFIG_STORE_H
3
22
(-)80cd9b67a1bd (+130 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
 
20
#include "model-node-creator.h"
21
namespace ns3 {
22
23
ModelCreator::ModelCreator ()
24
{
25
}
26
void
27
28
ModelCreator::Build (GtkTreeStore *treestore)
29
{
30
  m_treestore = treestore;
31
  m_iters.push_back (0);
32
  //this function will go through all the objects and call on them
33
  //DoStartVisitObject, DoIterate and DoEndVisitObject
34
  Iterate ();
35
  NS_ASSERT (m_iters.size () == 1);
36
}
37
38
39
void
40
ModelCreator::Add (ModelNode *node)
41
{
42
  GtkTreeIter *parent = m_iters.back ();
43
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
44
  gtk_tree_store_append (m_treestore, current, parent);
45
  gtk_tree_store_set (m_treestore, current,
46
                      COL_NODE, node, -1);
47
  m_iters.push_back (current);
48
}
49
void
50
ModelCreator::Remove (void)
51
{
52
  GtkTreeIter *iter = m_iters.back ();
53
  g_free (iter);
54
  m_iters.pop_back ();
55
}
56
57
void 
58
ModelCreator::DoVisitAttribute (Ptr<Object> object, std::string name)
59
{
60
  ModelNode *node = new ModelNode ();
61
  node->type = ModelNode::NODE_ATTRIBUTE;
62
  node->object = object;
63
  node->name = name;
64
  Add (node);
65
  Remove ();
66
}
67
void 
68
ModelCreator::DoStartVisitObject (Ptr<Object> object)
69
{
70
  ModelNode *node = new ModelNode ();
71
  node->type = ModelNode::NODE_OBJECT;
72
  node->object = object;
73
  Add (node);
74
}
75
void 
76
ModelCreator::DoEndVisitObject (void)
77
{
78
  Remove ();
79
}
80
void 
81
ModelCreator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
82
{
83
  ModelNode *node = new ModelNode ();
84
  node->type = ModelNode::NODE_POINTER;
85
  node->object = object;
86
  node->name = name;
87
  Add (node);
88
}
89
void 
90
ModelCreator::DoEndVisitPointerAttribute (void)
91
{
92
  Remove ();
93
}
94
void 
95
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
96
{
97
  ModelNode *node = new ModelNode ();
98
  node->type = ModelNode::NODE_VECTOR;
99
  node->object = object;
100
  node->name = name;
101
  Add (node);
102
}
103
void 
104
ModelCreator::DoEndVisitArrayAttribute (void)
105
{
106
  Remove ();
107
}
108
void 
109
ModelCreator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
110
{
111
  GtkTreeIter *parent = m_iters.back ();
112
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
113
  ModelNode *node = new ModelNode ();
114
  node->type = ModelNode::NODE_VECTOR_ITEM;
115
  node->object = item;
116
  node->index = index;
117
  gtk_tree_store_append (m_treestore, current, parent);
118
  gtk_tree_store_set (m_treestore, current,
119
              COL_NODE, node,
120
                     -1);
121
  m_iters.push_back (current);
122
}
123
void 
124
ModelCreator::DoEndVisitArrayItem (void)
125
{
126
  GtkTreeIter *iter = m_iters.back ();
127
  g_free (iter);
128
  m_iters.pop_back ();  
129
}
130
}//end namespace ns3
(-)80cd9b67a1bd (+73 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
20
#include "attribute-iterator.h"
21
#include <gtk/gtk.h>
22
23
namespace ns3
24
{
25
26
enum
27
{
28
  COL_NODE = 0, COL_LAST
29
};
30
31
struct ModelNode
32
{
33
  enum
34
  {
35
    // store object + attribute name
36
    NODE_ATTRIBUTE,
37
    // store object + attribute name
38
    NODE_POINTER,
39
    // store object + attribute name
40
    NODE_VECTOR,
41
    // store index + value (object)
42
    NODE_VECTOR_ITEM,
43
    // store object
44
    NODE_OBJECT
45
  } type;
46
  std::string name;
47
  Ptr<Object> object;
48
  uint32_t index;
49
};
50
class ModelCreator : public AttributeIterator
51
{
52
public:
53
  ModelCreator ();
54
55
  void Build (GtkTreeStore *treestore);
56
private:
57
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
58
  virtual void DoStartVisitObject (Ptr<Object> object);
59
  virtual void DoEndVisitObject (void);
60
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
61
  virtual void DoEndVisitPointerAttribute (void);
62
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector);
63
  virtual void DoEndVisitArrayAttribute (void);
64
  virtual void DoStartVisitArrayItem (const ObjectVectorValue &vector,
65
                                      uint32_t index, Ptr<Object> item);
66
  virtual void DoEndVisitArrayItem (void);
67
  void Add (ModelNode *node);
68
  void Remove (void);
69
70
  GtkTreeStore *m_treestore;
71
  std::vector<GtkTreeIter *> m_iters;
72
};
73
}
(-)80cd9b67a1bd (+81 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 */
18
19
#include "model-typeid-creator.h"
20
21
namespace ns3 {
22
23
ModelTypeidCreator::ModelTypeidCreator ()
24
{
25
}
26
void
27
28
ModelTypeidCreator::Build (GtkTreeStore *treestore)
29
{
30
  m_treestore = treestore;
31
  m_iters.push_back (0);
32
  Iterate ();
33
  NS_ASSERT (m_iters.size () == 1);
34
}
35
36
void
37
ModelTypeidCreator::Add (ModelTypeid *node)
38
{
39
  GtkTreeIter *parent = m_iters.back ();
40
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
41
  gtk_tree_store_append (m_treestore, current, parent);
42
  gtk_tree_store_set (m_treestore, current, COL_TYPEID, node, -1);
43
  m_iters.push_back (current);
44
}
45
46
void
47
ModelTypeidCreator::Remove (void)
48
{
49
  GtkTreeIter *iter = m_iters.back ();
50
  g_free (iter);
51
  m_iters.pop_back ();
52
}
53
54
void 
55
ModelTypeidCreator::VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index)
56
{
57
  ModelTypeid *node = new ModelTypeid ();
58
  node->type = ModelTypeid::NODE_ATTRIBUTE;
59
  node->tid = tid;
60
  node->name = name;
61
  node->defaultValue = defaultValue;
62
  node->index = index;
63
  Add (node);
64
  Remove ();
65
}
66
67
void 
68
ModelTypeidCreator::StartVisitTypeId (std::string name)
69
{
70
  ModelTypeid *node = new ModelTypeid ();
71
  node->type = ModelTypeid::NODE_TYPEID;
72
  node->tid = TypeId::LookupByName (name);
73
  Add (node);
74
}
75
76
void 
77
ModelTypeidCreator::EndVisitTypeId (void)
78
{
79
  Remove ();
80
}
81
}//end namespace ns3
(-)80cd9b67a1bd (+82 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Moatamri Faker <faker.moatamri@sophia.inria.fr>
17
 */
18
19
#include "attribute-default-iterator.h"
20
#include "ns3/type-id.h"
21
#include <gtk/gtk.h>
22
#include <vector>
23
24
namespace ns3 {
25
26
enum
27
{
28
  COL_TYPEID = 0, COL_LASTID
29
};
30
31
struct ModelTypeid
32
{
33
  enum
34
  {
35
    // store TypeId + attribute name +defaultValue and index
36
    NODE_ATTRIBUTE,
37
    // store TypeId
38
    NODE_TYPEID
39
  } type;
40
  std::string name;
41
  std::string defaultValue;
42
  //The TypeId object and if it is an attribute, it's the TypeId object of the attribute
43
  TypeId tid;
44
  //stores the index of the attribute in list of attributes for a given TypeId
45
  uint32_t index;
46
};
47
class ModelTypeidCreator : public AttributeDefaultIterator
48
{
49
public:
50
  ModelTypeidCreator ();
51
  /**
52
   * \brief This method will iterate on typeIds having default attributes and create a model
53
   * for them, this model will be used by the view.
54
   */
55
  void Build (GtkTreeStore *treestore);
56
private:
57
  /**
58
   * \brief This method will add a ModelTypeid to the GtkTreeIterator
59
   */
60
  virtual void VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index);
61
  /**
62
   * \brief Add a node for the new TypeId object
63
   */
64
  virtual void StartVisitTypeId (std::string name);
65
  /**
66
   * \brief Remove the last gtk tree iterator
67
   */
68
  virtual void EndVisitTypeId (void);
69
  /**
70
   * \brief Adds a treestore iterator to m_treestore model
71
   */
72
  void Add (ModelTypeid *node);
73
  /**
74
   * Removes the last GtkTreeIterator from m_iters
75
   */
76
  void Remove (void);
77
  //this is the TreeStore model corresponding to the view
78
  GtkTreeStore *m_treestore;
79
  //This contains a vector of iterators used to build the TreeStore
80
  std::vector<GtkTreeIter *> m_iters;
81
};
82
}
(-)a/src/contrib/raw-text-config.cc (-1 / +1 lines)
 Lines 41-47    Link Here 
41
    virtual void StartVisitTypeId (std::string name) {
41
    virtual void StartVisitTypeId (std::string name) {
42
      m_typeId = name;
42
      m_typeId = name;
43
    }
43
    }
44
    virtual void VisitAttribute (std::string name, std::string defaultValue) {
44
    virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
45
      *m_os << "default " << m_typeId << "::" << name << " \"" << defaultValue << "\"" << std::endl;
45
      *m_os << "default " << m_typeId << "::" << name << " \"" << defaultValue << "\"" << std::endl;
46
    }
46
    }
47
    std::string m_typeId;
47
    std::string m_typeId;
(-)a/src/contrib/wscript (+3 lines)
 Lines 29-36    Link Here 
29
        'config-store.cc',
29
        'config-store.cc',
30
        'flow-id-tag.cc',
30
        'flow-id-tag.cc',
31
        'attribute-default-iterator.cc',
31
        'attribute-default-iterator.cc',
32
        'model-node-creator.cc',
33
        'model-typeid-creator.cc',
32
        'file-config.cc',
34
        'file-config.cc',
33
        'raw-text-config.cc',
35
        'raw-text-config.cc',
36
        'display-functions.cc',
34
        ]
37
        ]
35
38
36
    headers = bld.new_task_gen('ns3header')
39
    headers = bld.new_task_gen('ns3header')
(-)a/src/contrib/xml-config.cc (-1 / +1 lines)
 Lines 90-96    Link Here 
90
    virtual void StartVisitTypeId (std::string name) {
90
    virtual void StartVisitTypeId (std::string name) {
91
      m_typeid = name;
91
      m_typeid = name;
92
    }
92
    }
93
    virtual void VisitAttribute (std::string name, std::string defaultValue) {
93
    virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
94
      int rc;
94
      int rc;
95
      rc = xmlTextWriterStartElement(m_writer, BAD_CAST "default");
95
      rc = xmlTextWriterStartElement(m_writer, BAD_CAST "default");
96
       if (rc < 0) 
96
       if (rc < 0) 

Return to bug 184