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 // AttributeParameter.h -						    //
15 //                                                                          //
16 // Definition for the AttributeParameter class.				    //
17 //
18 // The AttributeParameter (Data-driven parameter) class is intended to be used
19 // with data-driven interactors, in which interactor attributes may also
20 // be parameters to the executive module that does the data-driving.
21 // In this class, we use the second value of the BinaryParameter class to
22 // hold the attribute value with the primary parameter value always taking
23 // presidence over the secondary value.
24 //                                                                          //
25 
26 
27 #ifndef _AttributeParameter_h
28 #define _AttributeParameter_h
29 
30 
31 #include "BinaryParameter.h"
32 
33 
34 //
35 // Class name definition:
36 //
37 #define ClassAttributeParameter	"AttributeParameter"
38 
39 class Node;
40 
41 //
42 // AttributeParameter class definition:
43 //
44 class AttributeParameter : public BinaryParameter
45 {
46   private:
47     //
48     // Private member data:
49     //
50   protected:
51 
52      Node 	*node;
53      int	index;
54      boolean	syncOnTypeMatch;
55 
56   public:
57 
58 
59     //
60     // Constructor:
61     //
62     AttributeParameter(ParameterDefinition *pd, Node *n, int index) ;
63 
64     //
65     // Destructor:
66     //
~AttributeParameter()67     ~AttributeParameter() { }
68 
69 
70 #if 0	// 6/10/93
71 // If we use this then DrivenNode::ioParameterValueChanged() needs to
72 // notifyVisualsOfStateChange() so that the displayed attribute is in
73 // sync with the internal value.
74     //
75     // If the super-class method succeeds then, copy the value into
76     // the attribute (the secondary parameter value).
77     //
78     virtual boolean 	setValue(const char *v, Type type, boolean coerce=TRUE)
79 		{  boolean r = this->BinaryParameter::setValue(v,type,coerce);
80 		   if (r && this->syncOnTypeMatch && (this->hasValue() &&
81 			     this->getValueType() == this->get2ndValueType())) {
82 			r = this->set2ndValue(this->getSetValueString(),
83 							type,FALSE);
84 			ASSERT(r);
85 		   }
86 		   return r;
87 		}
88 #endif
89 
90     //
91     // Copy the parameter value into the Attribute value.
92     //
93     boolean  syncAttributeValue();
94 
95     //
96     // Make sure that the primary parameter has the same value as the
97     // attribute when appropriate.  Appropriate is defined as the primary
98     // parameter having a value and a type which is the same as the attribute's.
99     //
100     boolean	syncPrimaryValue(boolean force = FALSE);
101 
102     void setSyncOnTypeMatch(boolean v = TRUE)
103 			{ this->syncOnTypeMatch = v; }
104 
105     //
106     // Determine if the attribute that shadows this parameter is writeable.
107     // Attributes are writeable if the primary parameter is not connected
108     // and (the primary parameter is defaulting or the value has the same
109     // type as the attribute value.
110     //
111     boolean  isAttributeVisuallyWriteable();
112 
113     boolean 	setAttributeValue(const char *val, boolean force = FALSE)
114 		{ return this->set2ndValue(val) &&
115 				this->syncPrimaryValue(force); }
116 
initAttributeValue(const char * val)117     boolean 	initAttributeValue(const char *val)
118 		{ return this->set2ndValue(val) &&
119 			 this->syncPrimaryValue(TRUE); }
120 
121 
122 
getAttributeValueString()123     const char	*getAttributeValueString()
124 		{  ASSERT(this->has2ndValue());
125 		   return this->get2ndValueString();
126 		}
getAttributeValueType()127     Type	getAttributeValueType()
128 		{  ASSERT(this->has2ndValue());
129 		   return this->get2ndValueType();
130 		}
131 
132     //
133     // S/Get the i'th component of a vector attribute.
134     //
setAttributeComponentValue(int index,double value)135     boolean setAttributeComponentValue(int index, double value)
136 		{ return this->set2ndComponentValue(index, value) &&
137 					this->syncPrimaryValue(); }
138 
getAttributeComponentValue(int index)139     double getAttributeComponentValue(int index)
140 		{ ASSERT(this->has2ndValue());
141 		  return this->get2ndComponentValue(index);
142 		}
143 
getAttributeComponentCount()144     int	getAttributeComponentCount()
145 		{ return (this->has2ndValue() ?
146 				this->get2ndComponentCount() : 0); }
147 
148     virtual boolean isA(Symbol classname);
149 
150     //
151     // Returns a pointer to the class name.
152     //
getClassName()153     const char* getClassName()
154     {
155 	return ClassAttributeParameter;
156     }
157 };
158 
159 
160 #endif // _AttributeParameter_h
161