1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/**************************************************************************\
*
* This file is part of the Coin 3D visualization library.
* Copyright (C) by Kongsberg Oil & Gas Technologies.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.GPL at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using Coin with software that can not be combined with the GNU
* GPL, and for taking advantage of the additional benefits of our
* support services, please contact Kongsberg Oil & Gas Technologies
* about acquiring a Coin Professional Edition License.
*
* See http://www.coin3d.org/ for more information.
*
* Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
* http://www.sim.no/ sales@sim.no coin-support@coin3d.org
*
\**************************************************************************/
/*!
\class SoCounter SoCounter.h Inventor/engines/SoCounter.h
\brief The SoCounter class is an integer counter engine.
\ingroup engines
The engine counts from its \a min value to its \a max value, adding
the value of \a step each time \a trigger is touched.
SoCounter provides a convenient way of keeping track of the number
of times some event in your application is triggered.
*/
/*!
\var SoSFShort SoCounter::min
Minimum value for counter.
*/
/*!
\var SoSFShort SoCounter::max
Maximum value for counter.
*/
/*!
\var SoSFShort SoCounter::step
Counter step value.
*/
/*!
\var SoSFTrigger SoCounter::trigger
Increment counter (using step).
*/
/*!
\var SoSFShort SoCounter::reset
Reset counter to this value. The value will be clamped between min
and max, and step will be accounted for.
*/
/*!
\var SoEngineOutput SoCounter::output
(SoSFShort) Output which contains the current counter value.
*/
/*!
\var SoEngineOutput SoCounter::syncOut
(SoSFTrigger) Triggers every time counter restarts at SoCounter::min.
*/
#include <Inventor/engines/SoCounter.h>
#include <Inventor/lists/SoEngineOutputList.h>
#include "engines/SoSubEngineP.h"
SO_ENGINE_SOURCE(SoCounter);
/*!
Default constructor.
*/
SoCounter::SoCounter(void)
{
SO_ENGINE_INTERNAL_CONSTRUCTOR(SoCounter);
SO_ENGINE_ADD_INPUT(min, (0));
SO_ENGINE_ADD_INPUT(max, (1));
SO_ENGINE_ADD_INPUT(step, (1));
SO_ENGINE_ADD_INPUT(trigger, ());
SO_ENGINE_ADD_INPUT(reset, (0));
SO_ENGINE_ADD_OUTPUT(output, SoSFShort);
SO_ENGINE_ADD_OUTPUT(syncOut, SoSFTrigger);
this->syncOut.enable(FALSE); // Disable notification
this->value = 0;
this->numsteps = 0;
}
/*!
Destructor.
Protected, as engines are not supposed to be explicitly deleted, but
rather take care of their own destiny by monitoring their reference
count.
*/
SoCounter::~SoCounter()
{
}
// Documented in superclass.
void
SoCounter::initClass()
{
SO_ENGINE_INTERNAL_INIT_CLASS(SoCounter);
}
// doc in parent
void
SoCounter::evaluate()
{
SO_ENGINE_OUTPUT(output,SoSFShort,setValue(this->value));
}
// doc in parent
void
SoCounter::inputChanged(SoField *which)
{
// Default to not notifying fields connected to the syncOut output.
this->syncOut.enable(FALSE);
if (which == &this->trigger) {
this->numsteps += 1;
this->value += this->step.getValue();
if (this->value > this->max.getValue()) {
this->value = this->min.getValue();
this->numsteps = 0;
this->syncOut.enable(TRUE);
}
else if (this->value < this->min.getValue()) {
this->value = this->max.getValue();
this->numsteps = 0;
this->syncOut.enable(TRUE);
}
}
else if (which == &this->reset) {
short minval = this->min.getValue();
short maxval = this->max.getValue();
short resetval = this->reset.getValue();
if (resetval < minval) {
this->numsteps = 0;
this->value = minval;
}
else {
if (resetval > maxval) resetval = maxval;
short stepval = this->step.getValue();
this->numsteps = (resetval - minval) / stepval;
this->value = minval + this->numsteps * stepval;
}
}
else if (which == &this->max) {
if (this->max.getValue() < this->min.getValue()) {
this->min.setValue(this->max.getValue());
this->value = this->max.getValue();
this->numsteps = 0;
}
if (this->max.getValue() < this->value) {
this->value = this->min.getValue();
this->numsteps = 0;
}
}
else if (which == &this->min) {
if (this->max.getValue() < this->min.getValue()) {
this->max.setValue(this->min.getValue());
this->numsteps = 0;
}
this->value = this->min.getValue() + this->step.getValue() * this->numsteps;
if (this->value > this->max.getValue()) {
this->numsteps = 0;
this->value = this->min.getValue();
}
}
else if (which == &this->step) {
this->value = this->min.getValue() + this->step.getValue() * this->numsteps;
if (this->value > this->max.getValue()) {
this->numsteps = 0;
this->value = this->min.getValue();
}
}
}
|