OpenWalnut  1.5.0dev
WMWriteDendrogram.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 
28 #include "WMWriteDendrogram.h"
29 #include "WMWriteDendrogram.xpm"
30 #include "core/common/WPropertyHelper.h"
31 #include "core/dataHandler/io/WWriterDendrogram.h"
32 #include "core/kernel/WKernel.h"
33 
34 W_LOADABLE_MODULE( WMWriteDendrogram )
35 
37  WModule()
38 {
39 }
40 
42 {
43 }
44 
45 std::shared_ptr< WModule > WMWriteDendrogram::factory() const
46 {
47  return std::shared_ptr< WModule >( new WMWriteDendrogram() );
48 }
49 
50 const char** WMWriteDendrogram::getXPMIcon() const
51 {
52  return WMWriteDendrogram_xpm;
53 }
54 
55 const std::string WMWriteDendrogram::getName() const
56 {
57  return "Write Dendrogram";
58 }
59 
60 const std::string WMWriteDendrogram::getDescription() const
61 {
62  return "Writes Dendrogram";
63 }
64 
66 {
67  m_dendrogramIC = WModuleInputData< const WDendrogram >::createAndAdd( shared_from_this(), "dendrogramInput", "A the Dendrogram" );
68 
70 }
71 
73 {
74  m_savePath = m_properties->addProperty( "Save Path", "Where to save the result", boost::filesystem::path( "/no/such/file" ) );
76  m_run = m_properties->addProperty( "Save", "Start saving", WPVBaseTypes::PV_TRIGGER_READY );
77 
79 }
80 
82 {
83  m_moduleState.add( m_dendrogramIC->getDataChangedCondition() );
84  m_moduleState.add( m_run->getCondition() );
85 
86  ready();
87 
88  while( !m_shutdownFlag() )
89  {
90  infoLog() << "Waiting...";
92 
93  if( !m_dendrogramIC->getData() )
94  {
95  continue;
96  }
97 
98  if( m_run->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
99  {
100  WWriterDendrogram w( m_savePath->get(), true );
101  infoLog() << "Start saving to: " << m_savePath->get();
102  w.write( m_dendrogramIC->getData() );
103  infoLog() << "Saving done.";
104  m_run->set( WPVBaseTypes::PV_TRIGGER_READY, false );
105  }
106  }
107 }
virtual void wait() const
Wait for the condition.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
This module writes the Dendrogram.
virtual void properties()
Initialize the properties for this module.
virtual void connectors()
Initialize the connectors this module is using.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
virtual void moduleMain()
Entry point after loading the module.
WMWriteDendrogram()
Constructs an instance to write Dendrogram to a file.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropFilename m_savePath
Path where Dendrogram should be stored.
WPropTrigger m_run
Button to start saving.
virtual const std::string getName() const
Gives back the name of this module.
std::shared_ptr< WModuleInputData< const WDendrogram > > m_dendrogramIC
Input connector for writing the Dendrogram.
virtual ~WMWriteDendrogram()
Destructs this instance.
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this in data connector with proper type and add it to ...
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
void ready()
Call this whenever your module is ready and can react on property changes.
Definition: WModule.cpp:505
WConditionSet m_moduleState
The internal state of the module.
Definition: WModule.h:703
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
Definition: WModule.cpp:565
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Writes a Dendrogram file.
void write(std::shared_ptr< const WDendrogram > dendrogram) const
Writes finaly the given dendrogram to the previously specified file.
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.