On Saturday 07 April 2007 12:10, Zach Welch wrote: > Hi all, > > The attached patch provides a new ControlPrinterWidget class that displays > the input control value inside the processing widget. Its design allows it > to be embedded into any Processing widget (e.g. for debugging purposes), > and it can handle any number of input controls. This will allow it to be > re-used without changes in a ControlPrinterArray class, or something > similar.
I went ahead and added a NumberOfInputs attribute to ControlPrinterConfig, with the default of 1. With the default of one input, the control preserves the exists behavior; however, it now supports printing a list of values. The previous widget patch should transparently handle this change. Altogether, this obviates the need for a separate ControlPrinterArray class. Cheers, Zach
Index: CLAM/src/Processing/Controls/ControlPrinter.cxx =================================================================== --- CLAM/src/Processing/Controls/ControlPrinter.cxx (revision 9977) +++ CLAM/src/Processing/Controls/ControlPrinter.cxx (working copy) @@ -1,6 +1,7 @@ #include "ControlPrinter.hxx" #include "Factory.hxx" #include <iostream> +#include <sstream> typedef CLAM::Factory<CLAM::Processing> ProcessingFactory; @@ -16,35 +17,60 @@ AddAll(); UpdateData(); SetIdentifier( "ControlPrinter" ); + SetNumberOfInputs(1.); } ControlPrinter::ControlPrinter() - : mInControl( "Control In", this ) { Configure( mConfig ); } ControlPrinter::ControlPrinter( const ControlPrinterConfig& cfg ) - : mInControl( "Control In", this ) { Configure( cfg ); } + ControlPrinter::~ControlPrinter() + { + RemoveOldControls(); + } bool ControlPrinter::ConcreteConfigure( const ProcessingConfig& cfg ) { + RemoveOldControls(); CopyAsConcreteConfig( mConfig, cfg ); + if (!mConfig.HasNumberOfInputs()) + mConfig.SetNumberOfInputs(1.); + int nInputs = int(mConfig.GetNumberOfInputs()); + if (nInputs < 1) nInputs = 1; + if (nInputs == 1) { + // preserve old port name + std::list<std::string> names; + names.push_back("In Control"); + mInControls.Resize(1, names, this); + } else { + // multi-port names share user-configured identifier + mInControls.Resize(nInputs, + mConfig.GetIdentifier(), this); + } return true; } bool ControlPrinter::Do() { - std::cout << mConfig.GetIdentifier() - << ": " - << mInControl.GetLastValue() - << std::endl; + std::string separator = ""; + std::stringstream values; + for (int i = 0; i < mInControls.Size(); i++) { + values << separator << mInControls[i].GetLastValue(); + separator = ", "; + } + std::cout << mConfig.GetIdentifier() << ": " + << values.str() << std::endl; return true; } - - + void ControlPrinter::RemoveOldControls() + { + mInControls.Clear(); + GetInControls().Clear(); + } } Index: CLAM/src/Processing/Controls/ControlPrinter.hxx =================================================================== --- CLAM/src/Processing/Controls/ControlPrinter.hxx (revision 9977) +++ CLAM/src/Processing/Controls/ControlPrinter.hxx (working copy) @@ -25,7 +25,7 @@ #include "DataTypes.hxx" #include "Processing.hxx" #include "ProcessingConfig.hxx" -#include "InControl.hxx" +#include "InControlArray.hxx" namespace CLAM { @@ -33,8 +33,9 @@ class ControlPrinterConfig : public ProcessingConfig { public: - DYNAMIC_TYPE_USING_INTERFACE (ControlPrinterConfig, 1, ProcessingConfig); + DYNAMIC_TYPE_USING_INTERFACE (ControlPrinterConfig, 2, ProcessingConfig); DYN_ATTRIBUTE (0, public, std::string, Identifier); + DYN_ATTRIBUTE (1, public, TData, NumberOfInputs); private: void DefaultInit(); @@ -43,7 +44,7 @@ class ControlPrinter : public Processing { ControlPrinterConfig mConfig; - InControl mInControl; + InControlArray mInControls; public: @@ -52,11 +53,14 @@ ControlPrinter(); ControlPrinter( const ControlPrinterConfig& cfg ); + ~ControlPrinter(); bool ConcreteConfigure( const ProcessingConfig& cfg ); const ProcessingConfig& GetConfig() const { return mConfig; } bool Do(); + protected: + void RemoveOldControls(); }; }
_______________________________________________ Clam-devel mailing list Clam-devel@llistes.projectes.lafarga.org https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel