count.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "count.h"
00012 
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015 
00016 #include <klocale.h>
00017 
00018 Item* Count::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00019 {
00020         return new Count( (ICNDocument*)itemDocument, newItem, id );
00021 }
00022 
00023 LibraryItem* Count::libraryItem()
00024 {
00025         return new LibraryItem(
00026                 QString::QString("flow/count"),
00027                 i18n("Count"),
00028                 i18n("Functions"),
00029                 "ppcount.png",
00030                 LibraryItem::lit_flowpart,
00031                 Count::construct );
00032 }
00033 
00034 Count::Count( ICNDocument *icnDocument, bool newItem, const char *id )
00035         : FlowPart( icnDocument, newItem, (id) ? id : "count" )
00036 {
00037         m_name = i18n("Count");
00038         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.");
00039         initProcessSymbol();
00040         createStdInput();
00041         createStdOutput();
00042         
00043         createProperty( "0-trigger", Variant::Type::Select );
00044         property("0-trigger")->setAllowed( QStringList::split(',',"rising,falling") );
00045         property("0-triger")->setValue("rising");
00046         property("0-trigger")->setCaption( i18n("Trigger") );
00047         
00048         createProperty( "1-length", Variant::Type::Double );
00049         property("1-length")->setUnit("sec");
00050         property("1-length")->setValue(10.0);
00051         property("1-length")->setCaption("Interval");
00052 }
00053 
00054 Count::~Count()
00055 {
00056 }
00057 
00058 void Count::dataChanged()
00059 {
00060         double count = dataDouble("1-length");
00061         setCaption( i18n("Count %1 for %2 sec").arg(dataString("0-trigger")).arg(QString::number( count / getMultiplier(count), 'g', 3 ) + getNumberMag(count)) );
00062 }
00063 
00064 void Count::generateMicrobe( FlowCode *code )
00065 {
00066         const double count_ms = dataDouble("1-length")*1e3;
00067         code->addCode( "count "+dataString("0-trigger")+" for "+QString::number(count_ms)+"ms" );
00068         code->addCodeBranch( outputPart("stdoutput") );
00069 }
00070 

Generated on Tue May 8 17:05:28 2007 for KTechLab by  doxygen 1.5.1