Statistics
| Branch: | Revision:

root / src / tkenv / objinsp.cc @ e1750c09

History | View | Annotate | Download (5.33 KB)

1
//==========================================================================
2
//  OBJINSP.CC - part of
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//  Implementation of
8
//    inspectors
9
//
10
//==========================================================================
11

    
12
/*--------------------------------------------------------------*
13
  Copyright (C) 1992-2008 Andras Varga
14
  Copyright (C) 2006-2008 OpenSim Ltd.
15

16
  This file is distributed WITHOUT ANY WARRANTY. See the file
17
  `license' for details on this and other legal matters.
18
*--------------------------------------------------------------*/
19

    
20
#include <string.h>
21
#include <math.h>
22

    
23
#include "omnetpp.h"
24

    
25
#include "tkenv.h"
26
#include "tklib.h"
27
#include "inspfactory.h"
28
#include "objinsp.h"
29

    
30
USING_NAMESPACE
31

    
32

    
33
void _dummy_for_objinsp() {}
34

    
35
TGenericObjectInspector::TGenericObjectInspector(cObject *obj, int typ, const char *geom, void *dat) :
36
TInspector(obj,typ,geom,dat)
37
{
38
    hascontentspage = false;
39
    focuscontentspage = false;
40
}
41

    
42
TGenericObjectInspector::~TGenericObjectInspector()
43
{
44
}
45

    
46
void TGenericObjectInspector::createWindow()
47
{
48
   TInspector::createWindow(); // create window name etc.
49

    
50
   // create inspector window by calling the specified proc with
51
   // the object's pointer. Window name will be like ".ptr80003a9d-1"
52
   Tcl_Interp *interp = getTkenv()->getInterp();
53
   CHK(Tcl_VarEval(interp, "create_genericobjectinspector ", windowname, " \"", geometry, "\"", " ",
54
                   (hascontentspage ? "1" : "0"), " ",  (focuscontentspage ? "1" : "0"), " ", NULL));
55
}
56

    
57
void TGenericObjectInspector::update()
58
{
59
   TInspector::update();
60

    
61
   // refresh "fields" page
62
   Tcl_Interp *interp = getTkenv()->getInterp();
63
   CHK(Tcl_VarEval(interp, "refresh_fields2page ", windowname, NULL));
64

    
65
   // refresh "contents" page
66
   if (hascontentspage)
67
   {
68
       deleteInspectorListbox(".nb.contents");
69
       fillInspectorListbox(".nb.contents", object, false);
70
   }
71
}
72

    
73
void TGenericObjectInspector::writeBack()
74
{
75
   TInspector::writeBack();
76
}
77

    
78
int TGenericObjectInspector::inspectorCommand(Tcl_Interp *interp, int argc, const char **argv)
79
{
80
   return TCL_ERROR;
81
}
82

    
83
class TGenericObjectInspectorFactory : public cInspectorFactory
84
{
85
  public:
86
    TGenericObjectInspectorFactory(const char *name) : cInspectorFactory(name) {}
87

    
88
    bool supportsObject(cObject *obj) {return true;}
89
    int inspectorType() {return INSP_OBJECT;}
90
    double qualityAsDefault(cObject *object) {return 1.0;}
91

    
92
    TInspector *createInspectorFor(cObject *object, int type, const char *geom, void *data) {
93
        TGenericObjectInspector *insp = new TGenericObjectInspector(object, type, geom, data);
94
        bool showcontentspage =
95
            dynamic_cast<cArray *>(object) || dynamic_cast<cQueue *>(object) ||
96
            dynamic_cast<cMessageHeap *>(object) || dynamic_cast<cDefaultList *>(object) ||
97
            dynamic_cast<cSimulation *>(object) || dynamic_cast<cRegistrationList *>(object);
98
        bool focuscontentspage =
99
            dynamic_cast<cArray *>(object) || dynamic_cast<cQueue *>(object) ||
100
            dynamic_cast<cMessageHeap *>(object) || dynamic_cast<cDefaultList *>(object) ||
101
            dynamic_cast<cRegistrationList *>(object);
102
        insp->setContentsPage(showcontentspage, focuscontentspage);
103
        return insp;
104
    }
105
};
106

    
107
Register_InspectorFactory(TGenericObjectInspectorFactory);
108

    
109
//----
110

    
111
class TWatchInspectorFactory : public cInspectorFactory
112
{
113
  public:
114
    TWatchInspectorFactory(const char *name) : cInspectorFactory(name) {}
115

    
116
    bool supportsObject(cObject *obj) {
117
        // Return true if it's a watch for a simple type (int, double, string etc).
118
        // For structures, we prefer the normal TGenericObjectInspector.
119
        // Currently we're prepared for cStdVectorWatcherBase.
120
        return dynamic_cast<cWatchBase *>(obj) && !dynamic_cast<cStdVectorWatcherBase *>(obj);
121
    }
122
    int inspectorType() {return INSP_OBJECT;}
123
    double qualityAsDefault(cObject *object) {return 2.0;}
124
    TInspector *createInspectorFor(cObject *object,int type,const char *geom,void *data) {
125
        return new TWatchInspector(object, type, geom, data);
126
    }
127
};
128

    
129
Register_InspectorFactory(TWatchInspectorFactory);
130

    
131

    
132
TWatchInspector::TWatchInspector(cObject *obj,int typ,const char *geom,void *dat) :
133
    TInspector(obj,typ,geom,dat)
134
{
135
}
136

    
137
void TWatchInspector::createWindow()
138
{
139
   TInspector::createWindow(); // create window name etc.
140

    
141
   // create inspector window by calling the specified proc with
142
   // the object's pointer. Window name will be like ".ptr80003a9d-1"
143
   Tcl_Interp *interp = getTkenv()->getInterp();
144
   CHK(Tcl_VarEval(interp, "create_watchinspector ", windowname, " \"", geometry, "\"", NULL ));
145
}
146

    
147
void TWatchInspector::update()
148
{
149
   TInspector::update();
150

    
151
   cWatchBase *watch = static_cast<cWatchBase *>(object);
152
   setLabel(".main.name.l", (std::string(watch->getClassName())+" "+watch->getName()).c_str());
153
   setEntry(".main.name.e", watch->info().c_str());
154
}
155

    
156
void TWatchInspector::writeBack()
157
{
158
   Tcl_Interp *interp = getTkenv()->getInterp();
159
   cWatchBase *watch = static_cast<cWatchBase *>(object);
160
   const char *s = getEntry(".main.name.e");
161
   if (watch->supportsAssignment())
162
       watch->assign(s);
163
   else
164
      CHK(Tcl_VarEval(interp,"messagebox {Warning} {This inspector doesn't support changing the value.} warning ok", NULL));
165
   TInspector::writeBack();    // must be there after all changes
166
}
167

    
168