File indexing completed on 2024-12-01 11:20:29

0001 /***************************************************************************
0002  *   Copyright (C) 2003 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "count.h"
0012 
0013 #include "flowcode.h"
0014 #include "libraryitem.h"
0015 #include "icndocument.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 Item *Count::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new Count(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *Count::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("flow/count")), i18n("Count"), i18n("Functions"), "ppcount.png", LibraryItem::lit_flowpart, Count::construct);
0027 }
0028 
0029 Count::Count(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : FlowPart(icnDocument, newItem, id ? id : "count")
0031 {
0032     m_name = i18n("Count");
0033     initProcessSymbol();
0034     createStdInput();
0035     createStdOutput();
0036 
0037     createProperty("0-trigger", Variant::Type::Select);
0038     property("0-trigger")->setAllowed((QStringList("rising") << "falling"));
0039     property("0-triger")->setValue("rising");
0040     property("0-trigger")->setCaption(i18n("Trigger"));
0041 
0042     createProperty("1-length", Variant::Type::Double);
0043     property("1-length")->setUnit("sec");
0044     property("1-length")->setValue(10.0);
0045     property("1-length")->setCaption("Interval");
0046 }
0047 
0048 Count::~Count()
0049 {
0050 }
0051 
0052 void Count::dataChanged()
0053 {
0054     double count = dataDouble("1-length");
0055     setCaption(i18n("Count %1 for %2 sec", dataString("0-trigger"), QString::number(count / getMultiplier(count), 'g', 3) + getNumberMag(count)));
0056 }
0057 
0058 void Count::generateMicrobe(FlowCode *code)
0059 {
0060     const double count_ms = dataDouble("1-length") * 1e3;
0061     code->addCode("count " + dataString("0-trigger") + " for " + QString::number(count_ms) + "ms");
0062     code->addCodeBranch(outputPart("stdoutput"));
0063 }