summaryrefslogtreecommitdiffstats
path: root/src/flowparts/count.cpp
blob: e4bbdc3458906f9f9c3850cb6160b503c899cc7d (plain)
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
/***************************************************************************
 *   Copyright (C) 2003 by David Saxton                                    *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include "count.h"

#include "libraryitem.h"
#include "flowcode.h"

#include <klocale.h>

Item* Count::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
	return new Count( (ICNDocument*)itemDocument, newItem, id );
}

LibraryItem* Count::libraryItem()
{
	return new LibraryItem(
		TQString("flow/count"),
		i18n("Count"),
		i18n("Functions"),
		"ppcount.png",
		LibraryItem::lit_flowpart,
		Count::construct );
}

Count::Count( ICNDocument *icnDocument, bool newItem, const char *id )
	: FlowPart( icnDocument, newItem, (id) ? id : "count" )
{
	m_name = i18n("Count");
	m_desc = i18n("Count the number of pulses during a fixed interval. To avoid ambiguity, this increments the counter on either a rising or falling edge, as opposed to a high or a low.");
	initProcessSymbol();
	createStdInput();
	createStdOutput();
	
	createProperty( "0-trigger", Variant::Type::Select );
	property("0-trigger")->setAllowed( TQStringList::split(',',"rising,falling") );
	property("0-triger")->setValue("rising");
	property("0-trigger")->setCaption( i18n("Trigger") );
	
	createProperty( "1-length", Variant::Type::Double );
	property("1-length")->setUnit("sec");
	property("1-length")->setValue(10.0);
	property("1-length")->setCaption("Interval");
}

Count::~Count()
{
}

void Count::dataChanged()
{
	double count = dataDouble("1-length");
	setCaption( i18n("Count %1 for %2 sec").arg(dataString("0-trigger")).arg(TQString::number( count / getMultiplier(count), 'g', 3 ) + getNumberMag(count)) );
}

void Count::generateMicrobe( FlowCode *code )
{
	const double count_ms = dataDouble("1-length")*1e3;
	code->addCode( "count "+dataString("0-trigger")+" for "+TQString::number(count_ms)+"ms" );
	code->addCodeBranch( outputPart("stdoutput") );
}