1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11
12
13 #include "DXLInputNode.h"
14 #include "DXApplication.h"
15 #include "Network.h"
16 #include "Parameter.h"
17 #include "DXPacketIF.h"
18 #include "List.h"
19 #include "Ark.h"
20 #include "InfoDialogManager.h"
21 #include "ErrorDialogManager.h"
22
23 boolean DXLInputNode::Initializing = FALSE;
24
DXLInputNode(NodeDefinition * nd,Network * net,int instnc)25 DXLInputNode::DXLInputNode(NodeDefinition *nd, Network *net, int instnc) :
26 UniqueNameNode(nd, net, instnc)
27 {
28 }
initialize()29 boolean DXLInputNode::initialize()
30 {
31 char label[512];
32
33 if (!this->getNetwork()->isReadingNetwork()) {
34 sprintf(label,"%s_%d",this->getNameString(),this->getInstanceNumber());
35 DXLInputNode::Initializing = TRUE;
36 this->setLabelString(label);
37 DXLInputNode::Initializing = FALSE;
38 }
39
40 return TRUE;
41 }
42
~DXLInputNode()43 DXLInputNode::~DXLInputNode()
44 {
45 }
46
47
netNodeString(const char * prefix)48 char *DXLInputNode::netNodeString(const char *prefix)
49 {
50 char *string = new char[512], inputname[128], outputname[128];
51 const char *label = (char*)this->getLabelString();
52
53 this->getNetworkOutputNameString(1,outputname);
54
55 if (this->isInputConnected(1)) {
56 //
57 // Get the name of the output that is connected to first input
58 //
59 char srcoutputname[128];
60 List *l = (List*)this->getInputArks(1);
61 ASSERT(l);
62 Ark *a = (Ark*)l->getElement(1);
63 ASSERT(a);
64 int index;
65 Node *n = a->getSourceNode(index);
66 ASSERT(n);
67 this->getNetworkInputNameString(1,inputname);
68 n->getNetworkOutputNameString(index,srcoutputname);
69 sprintf(string, " %s = %s;\n"
70 " %s = %s;\n"
71 " %s = %s;\n",
72 inputname, srcoutputname,// This makes the Network catch the Ark
73 label, inputname,
74 outputname, label);
75 } else {
76 sprintf(string," %s = %s;\n", outputname,label);
77 }
78
79
80 return string;
81 }
82
83
84
valuesString(const char * prefix)85 char *DXLInputNode::valuesString(const char *prefix)
86 {
87 const char *label = this->getLabelString();
88 const char *value = this->getInputValueString(1);
89 char *vs = new char [STRLEN(label) + STRLEN(value) + 6];
90 sprintf(vs,"%s = %s;\n", label, value);
91 return vs;
92 }
93
sendValues(boolean ignoreDirty)94 boolean DXLInputNode::sendValues(boolean ignoreDirty )
95 {
96 DXPacketIF *pif = theDXApplication->getPacketIF();
97
98 if (!pif)
99 return TRUE;
100
101 Parameter *p = this->getInputParameter(1);
102
103 if (p->isNeededValue(ignoreDirty)) {
104 char *vs = this->valuesString("");
105 pif->send(DXPacketIF::FOREGROUND, vs);
106 delete vs;
107 }
108 return TRUE;
109 }
110
111 //
112 // Determine if this node is of the given class.
113 //
isA(Symbol classname)114 boolean DXLInputNode::isA(Symbol classname)
115 {
116 Symbol s = theSymbolManager->registerSymbol(ClassDXLInputNode);
117 if (s == classname)
118 return TRUE;
119 else
120 return this->UniqueNameNode::isA(classname);
121 }
122
123 //
124 // This is the same as the super-class except that we enforce restriction
125 // by default, and we make sure that it does not conflict with other nodes
126 // in the network (e.g. Transmitters).
127 //
setLabelString(const char * label)128 boolean DXLInputNode::setLabelString(const char *label)
129 {
130 if (EqualString(label, this->getLabelString()))
131 return TRUE;
132
133 Network *n = this->getNetwork();
134
135 if (!DXLInputNode::Initializing && !n->isReadingNetwork()) {
136 if (!this->verifyRestrictedLabel(label))
137 return FALSE;
138
139 const char* conflict = n->nameConflictExists(this, label);
140 if (conflict) {
141 ErrorMessage("A %s with name \"%s\" already exists.",
142 conflict, label);
143 return FALSE;
144 }
145 }
146
147
148 return this->UniqueNameNode::setLabelString(label);
149 }
150
assignNewInstanceNumber()151 int DXLInputNode::assignNewInstanceNumber()
152 {
153 int instnum = this->UniqueNameNode::assignNewInstanceNumber();
154
155 //
156 // Compare the existing label against DXLInput_%d
157 //
158 const char* cur_label = this->getLabelString();
159 const char* matchstr = "DXLInput_";
160 boolean change_label = EqualSubstring (cur_label, matchstr, strlen(matchstr));
161 if (change_label) {
162 char *new_label = new char [2+strlen(cur_label)];
163 sprintf (new_label, "%s%d", matchstr, instnum);
164 this->setLabelString (new_label);
165 delete new_label;
166 }
167
168 return instnum;
169 }
170
171
printAsBean(FILE * f)172 boolean DXLInputNode::printAsBean(FILE* f)
173 {
174 if (this->isInputConnected(1)) return TRUE;
175 if (this->isOutputConnected(1) == FALSE) return TRUE;
176
177 char* indent = " ";
178
179 char buf[128];
180 strcpy (buf, this->getLabelString());
181 char PropName[128], propName[128];
182 if ((buf[0] >= 'A') && (buf[0] <= 'Z'))
183 buf[0]+= ('a' - 'A');
184 strcpy (propName, buf);
185 buf[0]-= ('a' - 'A');
186 strcpy (PropName, buf);
187
188 fprintf (f, "%sprivate float %s;\n", indent, propName);
189 fprintf (f, "%spublic void set%s(float new_value) {\n", indent, PropName);
190 indent = "\t";
191 fprintf (f, "%sthis.%s = (float)new_value;\n", indent, propName);
192 fprintf (f, "%sif (this.rmi == null) return %s;\n", indent, propName);
193 fprintf (f, "%sthis.rmi.setScalar(\"%s\", new_value);\n", indent, this->getLabelString());
194 indent = " ";
195 fprintf (f, "%s}\n\n", indent);
196 fprintf (f, "%spublic float get%s() {\n", indent, PropName);
197 indent = "\t";
198 fprintf (f, "%sreturn (float)this.%s;\n", indent, propName);
199 indent = " ";
200 fprintf (f, "%s}\n\n", indent);
201
202 return TRUE;
203 }
204
printAsBeanInitCall(FILE * f)205 boolean DXLInputNode::printAsBeanInitCall(FILE* f)
206 {
207 if (this->isInputConnected(1)) return TRUE;
208 if (this->isOutputConnected(1) == FALSE) return TRUE;
209 const char* value = this->getInputValueString(1);
210 if ((value == NUL(char*)) || (value[0] == '\0')) return TRUE;
211 if (EqualString(value, "NULL")) return TRUE;
212 if (EqualString(value, "\"NULL\"")) return TRUE;
213
214 char* indent = "\t";
215
216 char buf[128];
217 strcpy (buf, this->getLabelString());
218 char PropName[128], propName[128];
219 if ((buf[0] >= 'A') && (buf[0] <= 'Z'))
220 buf[0]+= ('a' - 'A');
221 strcpy (propName, buf);
222 buf[0]-= ('a' - 'A');
223 strcpy (PropName, buf);
224
225 fprintf (f, "%sset%s((float)%s);\n", indent, PropName, value);
226
227 return TRUE;
228 }
229
230