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 
14 // ToggleNode.h -						    //
15 //                                                                          //
16 // Definition for the ToggleNode class.			    //
17 //
18 /*
19  This node implements an interactor that outputs one of two values.  The
20  output is either considered 'set' (on) or 'reset' (off).  Methods are
21  provided to change the values that are output for set and reset, to
22  retrieve the set/reset values and to change the output set/reset state.
23  Because we need to keep track of the set/reset state, one should NOT
24  call this->setOutputValue() without EXTREME caution.  Instead use set()
25  and reset(), which keep track of the set/reset state,  to change the
26  output values of this node.
27 */
28 
29 #ifndef _ToggleNode_h
30 #define _ToggleNode_h
31 
32 
33 #include "InteractorNode.h"
34 
35 
36 //
37 // Class name definition:
38 //
39 #define ClassToggleNode	"ToggleNode"
40 
41 
42 //
43 // ToggleNode class definition:
44 //
45 class ToggleNode : public InteractorNode
46 {
47   private:
48     //
49     // Private member data:
50     //
51 
52     //
53     // Set the output and send it if requested.
54     // If setit is TRUE, then set the output to the first of the toggle values
55     // otherwise the 2nd of toggle values.
56     // If how is 1, then send the value.
57     // If how is 0,  then don't send the value.
58     // If how is -1, then send the value quietly.
59     //
60     boolean setTheToggle(boolean setit, int how);
61 
62     //
63     // Set the two potential output values.  The 1st corresponds to the
64     // set (toggle down) state and the second to the reset state (toggle up).
65     // If how is 1, then send the values.
66     // If how is 0,  then don't send the values.
67     // If how is -1, then send the values quietly.
68     //
69     boolean changeToggleValues(const char *set, const char *reset,
70 							int how);
71   protected:
72     //
73     // Protected member data:
74     //
75     Type	outputType;
76     boolean	is_set;
77 
78     //
79     //
80     //
81     int  handleInteractorMsgInfo(const char *line);
82 
83 
84     //
85     // Set the output to and send it.
86     // If setit is TRUE, then set the output to the first of the toggle values
87     // otherwise the 2nd of toggle values.
88     // If send is TRUE, then send it.
89     //
90     boolean setToggle(boolean setit, boolean send);
91     boolean setToggleQuietly(boolean setit);
92 
93     //
94     // Get the values that are output for the set and reset states.
95     // The returned string must be freed by the caller.
96     //
97     char *getToggleValue(boolean setval);
98 
99     //
100     // Initialize the two potential output values.  The 1st corresponds to the
101     // set (toggle down) state and the second to the reset state (toggle up).
102     // This (init) is called at creation, where as setToggleValues() is called
103     // after initialization.
104     //
105     boolean initToggleValues(const char *set, const char *reset);
106 
107     //
108     // Create a new interactor instance for this class.
109     //
110     virtual InteractorInstance *newInteractorInstance();
111 
112     //
113     // Print/Parse standard comments and add/parse a line with
114     // the 'toggle: %d, set = %s, reset = %s' comment.
115     // Only print/parse the ', set =....' part if includeValues is set.
116     //
117     boolean printToggleComment(FILE *f, const char *indent,
118 					boolean includeValues);
119     boolean parseToggleComment(const char* comment, const char* filename,
120 					int lineno, boolean includeValues);
121 
122     virtual boolean netPrintAuxComment(FILE *f);
123     virtual boolean netParseAuxComment(const char* comment,
124 					 const char* filename, int lineno);
125     virtual boolean cfgPrintInteractorComment(FILE *f);
126     virtual boolean cfgParseInteractorComment(const char* comment,
127 					const char* filename, int lineno);
128 
129 
130     virtual int getShadowingInput(int output_index);
131 
132 #if SYSTEM_MACROS // 3/13/95 - begin work for nodes to use system macros
133 
134     virtual char *netNodeString(const char *prefix);
135     virtual char *netBeginningOfMacroNodeString(const char *prefix);
136 #endif
137 
138 
139   public:
140     //
141     // Constructor:
142     //
143     ToggleNode(NodeDefinition *nd, Network *net, int instnc);
144 
145     //
146     // Destructor:
147     //
148     ~ToggleNode();
149 
150     //
151     // Called after allocation is complete.
152     // The work done here is to assigned default values to the InteractorNode
153     // inputs so that we can use them later when setting the attributes for the
154     // Interactor.
155     //
156     virtual boolean initialize();
157 
158 #if SYSTEM_MACROS // 3/13/95 - begin work for nodes to use system macros
159     virtual boolean     sendValues(boolean     ignoreDirty = TRUE);
160     virtual boolean     printValues(FILE *f, const char *prefix, PrintType dest);
161 #endif
162 
163 
164     //
165     // Determine if this node is a node of the given class
166     //
167     virtual boolean isA(Symbol classname);
168 
169     //
170     // Set the two potential output values.  The 1st corresponds to the
171     // set (toggle down) state and the second to the reset state (toggle up).
172     // The output is changed (without being sent to the executive) to match
173     // the new set of set/reset values.
174     //
175     boolean setToggleValues(const char *set, const char *reset);
176 
177     //
178     // Change the output value of the toggle.
179     //
180     boolean set(boolean send = TRUE) 	{ return this->setToggle(TRUE, send); }
181     boolean reset(boolean send = TRUE) 	{ return this->setToggle(FALSE, send); }
182 
183     //
184     // Get the values that are output for the set and reset states.
185     // The returned string must be freed by the caller.
186     //
getSetValue()187     char *getSetValue() 	{ return this->getToggleValue(TRUE); }
getResetValue()188     char *getResetValue() 	{ return this->getToggleValue(FALSE); }
189 
190     //
191     // Determine if the toggle is currently set.
192     //
isSet()193     boolean isSet()	{ return this->is_set; }
194 
195     boolean isSetAttributeVisuallyWriteable();
196     boolean isResetAttributeVisuallyWriteable();
197 
getJavaNodeName()198     virtual const char* getJavaNodeName() { return "ToggleNode"; }
199     virtual boolean printJavaType (FILE*, const char*, const char*);
200     virtual boolean printJavaValue(FILE*);
201 
202 
203     //
204     // Returns a pointer to the class name.
205     //
getClassName()206     const char* getClassName()
207     {
208 	return ClassToggleNode;
209     }
210 };
211 
212 #endif // _ToggleNode_h
213