KWWidgets
vtkKWMatrixWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWMatrixWidget.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWMatrixWidget - matrix widget
15 // .SECTION Description
16 // vtkKWMatrixWidget is a widget containing entries that help view and
17 // edit a matrix.
18 // .SECTION Thanks
19 // This work is part of the National Alliance for Medical Image
20 // Computing (NAMIC), funded by the National Institutes of Health
21 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
22 // Information on the National Centers for Biomedical Computing
23 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
24 
25 #ifndef __vtkKWMatrixWidget_h
26 #define __vtkKWMatrixWidget_h
27 
28 #include "vtkKWCompositeWidget.h"
29 
30 class vtkKWEntrySet;
31 
33 {
34 public:
35  static vtkKWMatrixWidget* New();
36  vtkTypeRevisionMacro(vtkKWMatrixWidget,vtkKWCompositeWidget);
37  void PrintSelf(ostream& os, vtkIndent indent);
38 
39  // Description:
40  // Set/Get the matrix size. Default to 1x1.
41  virtual void SetNumberOfColumns(int col);
42  vtkGetMacro(NumberOfColumns, int);
43  virtual void SetNumberOfRows(int col);
44  vtkGetMacro(NumberOfRows, int);
45 
46  // Description:
47  // Set/Get the value of a given element.
48  virtual void SetElementValue(int row, int col, const char *val);
49  virtual const char* GetElementValue(int row, int col);
50  virtual void SetElementValueAsInt(int row, int col, int val);
51  virtual int GetElementValueAsInt(int row, int col);
52  virtual void SetElementValueAsDouble(int row, int col, double val);
53  virtual double GetElementValueAsDouble(int row, int col);
54 
55  // Description:
56  // The width is the number of charaters each element can fit.
57  virtual void SetElementWidth(int width);
58  vtkGetMacro(ElementWidth, int);
59 
60  // Description:
61  // Set/Get readonly flag. This flags makes each element read only.
62  virtual void SetReadOnly(int);
63  vtkBooleanMacro(ReadOnly, int);
64  vtkGetMacro(ReadOnly, int);
65 
66  // Description:
67  // Restrict the value of an element to a given type
68  // (integer, double, or no restriction).
69  //BTX
70  enum
71  {
72  RestrictNone = 0,
73  RestrictInteger,
74  RestrictDouble
75  };
76  //ETX
77  vtkGetMacro(RestrictElementValue, int);
78  virtual void SetRestrictElementValue(int);
79  virtual void SetRestrictElementValueToInteger();
80  virtual void SetRestrictElementValueToDouble();
81  virtual void SetRestrictElementValueToNone();
82 
83  // Description:
84  // Specifies a command to be invoked when the value of an element in the
85  // matrix has changed.
86  // The 'object' argument is the object that will have the method called on
87  // it. The 'method' argument is the name of the method to be called and any
88  // arguments in string form. If the object is NULL, the method is still
89  // evaluated as a simple command.
90  // The following parameters are also passed to the command:
91  // - the element location, i.e. its row and column indices: int, int
92  // - the element's new value: const char*
93  virtual void SetElementChangedCommand(vtkObject *object, const char *method);
94 
95  // Description:
96  // Events. The ElementChangedEvent is triggered when the value of an
97  // element in the matrix has changed.
98  // The following parameters are also passed as client data:
99  // - the element location, i.e. its row and column indices: int, int
100  // - the element's new value: const char*
101  // Note that given the heterogeneous nature of types passed as client data,
102  // you should treat it as an array of void*[3], each one a pointer to
103  // the parameter (i.e., &int, &int, &const char*).
104  //BTX
105  enum
106  {
107  ElementChangedEvent = 10000
108  };
109  //ETX
110 
111  // Description:
112  // Specify when ElementChangedCommand should be invoked. Default to losing
113  // focus and return key in the entry.
114  //BTX
115  enum
116  {
117  TriggerOnFocusOut = 1,
118  TriggerOnReturnKey = 2,
119  TriggerOnAnyChange = 4
120  };
121  //ETX
122  vtkGetMacro(ElementChangedCommandTrigger, int);
123  virtual void SetElementChangedCommandTrigger(int);
124  virtual void SetElementChangedCommandTriggerToReturnKeyAndFocusOut();
125  virtual void SetElementChangedCommandTriggerToAnyChange();
126 
127  // Description:
128  // Update the "enable" state of the object and its internal parts.
129  // Depending on different Ivars (this->Enabled, the application's
130  // Limited Edition Mode, etc.), the "enable" state of the object is updated
131  // and propagated to its internal parts/subwidgets. This will, for example,
132  // enable/disable parts of the widget UI, enable/disable the visibility
133  // of 3D widgets, etc.
134  virtual void UpdateEnableState();
135 
136  // Description:
137  // Callbacks.
138  virtual void ElementChangedCallback(int id, const char *value);
139 
140 protected:
142  virtual ~vtkKWMatrixWidget();
143 
144  int NumberOfColumns;
145  int NumberOfRows;
146 
147  int ElementWidth;
148  int ReadOnly;
149  int RestrictElementValue;
150  int ElementChangedCommandTrigger;
151 
152  // Description:
153  // Create the widget.
154  virtual void CreateWidget();
155  virtual void UpdateWidget();
156 
157  vtkKWEntrySet *EntrySet;
158 
159  char *ElementChangedCommand;
160  void InvokeElementChangedCommand(int row, int col, const char *value);
161 
162 private:
163  vtkKWMatrixWidget(const vtkKWMatrixWidget&); // Not implemented
164  void operator=(const vtkKWMatrixWidget&); // Not implemented
165 };
166 
167 #endif
168