Skip to content

Commit 91080ee

Browse files
committed
More direct file type transmission
Issues with state map call in constructor...
1 parent 0e6f53e commit 91080ee

File tree

8 files changed

+59
-30
lines changed

8 files changed

+59
-30
lines changed

src/Dataflow/Network/ModuleStateInterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/// @todo Documentation Dataflow/Network/ModuleStateInterface.h
3030

3131
#ifndef DATAFLOW_NETWORK_MODULE_STATE_INTERFACE_H
32-
#define DATAFLOW_NETWORK_MODULE_STATE_INTERFACE_H
32+
#define DATAFLOW_NETWORK_MODULE_STATE_INTERFACE_H
3333

3434
#include <string>
3535
#include <iostream>
@@ -50,7 +50,7 @@ namespace Networks {
5050
{
5151
public:
5252
virtual ~ModuleStateInterface();
53-
53+
5454
typedef std::vector<SCIRun::Core::Algorithms::AlgorithmParameterName> Keys;
5555
typedef SCIRun::Core::Algorithms::AlgorithmParameterName Name;
5656
typedef SCIRun::Core::Algorithms::AlgorithmParameter Value;
@@ -105,7 +105,7 @@ namespace Networks {
105105
{
106106
return x ? any_cast_or_default_<T>(*x) : T();
107107
}
108-
108+
109109
class SCISHARE StateChangeObserver
110110
{
111111
public:

src/Dataflow/Serialization/Network/StateSerialization.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SimpleMapModuleStateXML::SimpleMapModuleStateXML()
3939

4040
SimpleMapModuleStateXML::SimpleMapModuleStateXML(const SimpleMapModuleState& state) : SimpleMapModuleState(state)
4141
{
42+
//std::cout << "SMMSxml copy" << std::endl;
4243
}
4344

4445
boost::shared_ptr<SimpleMapModuleStateXML> SCIRun::Dataflow::State::make_state_xml(SCIRun::Dataflow::Networks::ModuleStateHandle state)
@@ -47,4 +48,4 @@ boost::shared_ptr<SimpleMapModuleStateXML> SCIRun::Dataflow::State::make_state_x
4748
if (mapState)
4849
return boost::shared_ptr<SimpleMapModuleStateXML>(new SimpleMapModuleStateXML(*mapState));
4950
return boost::shared_ptr<SimpleMapModuleStateXML>();
50-
}
51+
}

src/Dataflow/State/SimpleMapModuleState.cc

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,26 @@ using namespace SCIRun::Dataflow::Networks;
3838
using namespace SCIRun::Core::Algorithms;
3939
using namespace SCIRun::Core::Logging;
4040

41-
SimpleMapModuleState::SimpleMapModuleState()
41+
SimpleMapModuleState::SimpleMapModuleState(const std::string& name) : name_(name)
4242
{
43+
//std::cout << "SMMS ctor " << name_ << std::endl;
4344
}
4445

4546
SimpleMapModuleState::SimpleMapModuleState(SimpleMapModuleState&& rhs)
46-
: stateMap_(std::move(rhs.stateMap_)),
47-
transientStateMap_(std::move(rhs.transientStateMap_))
47+
: stateMap_(std::move(rhs.stateMap_)),
48+
transientStateMap_(std::move(rhs.transientStateMap_)),
49+
name_(std::move(rhs.name_))
4850
{
51+
//std::cout << "SMMS move ctor " << name_ << std::endl;
4952
stateChangedSignal_.swap(rhs.stateChangedSignal_);
5053
}
5154

5255
SimpleMapModuleState::SimpleMapModuleState(const SimpleMapModuleState& rhs)
53-
: stateMap_(rhs.stateMap_),
54-
transientStateMap_(rhs.transientStateMap_) /// @todo: I think this is wrong, transient shouldn't be copied
56+
: stateMap_(rhs.stateMap_),
57+
transientStateMap_(rhs.transientStateMap_), /// @todo: I think this is wrong, transient shouldn't be copied
58+
name_(rhs.name_)
5559
{
60+
//std::cout << "SMMS copy ctor " << name_ << std::endl;
5661
}
5762

5863
SimpleMapModuleState& SimpleMapModuleState::operator=(const SimpleMapModuleState& rhs)
@@ -61,6 +66,8 @@ SimpleMapModuleState& SimpleMapModuleState::operator=(const SimpleMapModuleState
6166
{
6267
stateMap_ = rhs.stateMap_;
6368
transientStateMap_ = rhs.transientStateMap_; /// @todo: I think this is wrong, transient shouldn't be copied
69+
name_ = rhs.name_;
70+
//std::cout << "SMMS copy assign " << name_<< std::endl;
6471
/// @todo??
6572
//stateChangedSignal_.disconnect_all_slots();
6673
}
@@ -69,6 +76,7 @@ SimpleMapModuleState& SimpleMapModuleState::operator=(const SimpleMapModuleState
6976

7077
ModuleStateHandle SimpleMapModuleState::clone() const
7178
{
79+
//std::cout << "SMMS clone " << name_ << std::endl;
7280
return boost::make_shared<SimpleMapModuleState>(*this);
7381
}
7482

@@ -89,7 +97,7 @@ void SimpleMapModuleState::setValue(const Name& parameterName, const SCIRun::Cor
8997
bool newValue = oldLocation == stateMap_.end() || !(oldLocation->second.value() == value);
9098

9199
stateMap_[parameterName] = AlgorithmParameter(parameterName, value);
92-
100+
93101
if (newValue)
94102
{
95103
LOG_DEBUG("----signaling from state map: (" << parameterName.name_ << ", " << SCIRun::Core::to_string(value) << "), num_slots = " << stateChangedSignal_.num_slots() << std::endl);
@@ -112,15 +120,27 @@ ModuleStateInterface::Keys SimpleMapModuleState::getKeys() const
112120
return keys;
113121
}
114122

123+
void SimpleMapModuleState::print() const
124+
{
125+
std::cout << "Printing transient map: " << this << " name: " << name_ << std::endl;
126+
for (auto q = transientStateMap_.begin(); q != transientStateMap_.end(); ++q)
127+
{
128+
std::cout << "\t" << q->first << " : " << "any" << std::endl;
129+
}
130+
std::cout << "Done" << std::endl;
131+
}
132+
115133
SimpleMapModuleState::TransientValueOption SimpleMapModuleState::getTransientValue(const Name& name) const
116134
{
117-
TransientStateMap::const_iterator i = transientStateMap_.find(name.name());
135+
//print();
136+
auto i = transientStateMap_.find(name.name());
118137
return i != transientStateMap_.end() ? boost::make_optional(i->second) : TransientValueOption();
119138
}
120139

121140
void SimpleMapModuleState::setTransientValue(const Name& name, const TransientValue& value, bool fireSignal)
122141
{
123142
transientStateMap_[name.name()] = value;
143+
//print();
124144

125145
if (fireSignal)
126146
fireTransientStateChangeSignal();
@@ -133,5 +153,5 @@ void SimpleMapModuleState::fireTransientStateChangeSignal()
133153

134154
ModuleStateInterface* SimpleMapModuleStateFactory::make_state(const std::string& name) const
135155
{
136-
return new SimpleMapModuleState;
156+
return new SimpleMapModuleState(name);
137157
}

src/Dataflow/State/SimpleMapModuleState.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
namespace SCIRun {
3737
namespace Dataflow {
3838
namespace State {
39-
39+
4040
class SCISHARE SimpleMapModuleState : public SCIRun::Dataflow::Networks::ModuleStateInterface
4141
{
4242
public:
43-
SimpleMapModuleState();
43+
explicit SimpleMapModuleState(const std::string& name = "<dflt>");
4444
SimpleMapModuleState(SimpleMapModuleState&& rhs);
4545
SimpleMapModuleState(const SimpleMapModuleState& rhs);
4646
SimpleMapModuleState& operator=(const SimpleMapModuleState& rhs);
@@ -61,6 +61,9 @@ namespace State {
6161
typedef std::map<std::string, TransientValue> TransientStateMap;
6262
TransientStateMap transientStateMap_;
6363
state_changed_sig_t stateChangedSignal_;
64+
std::string name_;
65+
private:
66+
void print() const;
6467
};
6568

6669
class SCISHARE SimpleMapModuleStateFactory : public SCIRun::Dataflow::Networks::ModuleStateInterfaceFactory

src/ExampleNets/regression/readNrrdField.srn5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<name>FileTypeName</name>
3939
<value>
4040
<which>2</which>
41-
<value>NrrdFile</value>
41+
<value>NrrdFile[DataOnElements]</value>
4242
</value>
4343
</second>
4444
</item>

src/Interface/Modules/DataIO/ReadFieldDialog.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
#include <Interface/Modules/DataIO/ReadFieldDialog.h>
30+
#include <Modules/DataIO/ReadField.h>
3031
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
3132
#include <Dataflow/Network/ModuleStateInterface.h> //TODO: extract into intermediate
3233
#include <Core/ImportExport/GenericIEPlugin.h>
@@ -45,7 +46,7 @@ ReadFieldDialog::ReadFieldDialog(const std::string& name, ModuleStateHandle stat
4546
setupUi(this);
4647
setWindowTitle(QString::fromStdString(name));
4748
fixSize();
48-
49+
4950
connect(openFileButton_, SIGNAL(clicked()), this, SLOT(openFile()));
5051
connect(fileNameLineEdit_, SIGNAL(editingFinished()), this, SLOT(pushFileNameToState()));
5152
connect(fileNameLineEdit_, SIGNAL(returnPressed()), this, SLOT(pushFileNameToState()));
@@ -57,15 +58,15 @@ void ReadFieldDialog::pull()
5758
fileNameLineEdit_->setText(QString::fromStdString(state_->getValue(Variables::Filename).toString()));
5859
}
5960

60-
void ReadFieldDialog::pushFileNameToState()
61+
void ReadFieldDialog::pushFileNameToState()
6162
{
6263
auto file = fileNameLineEdit_->text().trimmed().toStdString();
6364
state_->setValue(Variables::Filename, file);
6465
}
6566

6667
void ReadFieldDialog::openFile()
6768
{
68-
auto types = state_->getValue(Variables::FileTypeList).toString();
69+
auto types = Modules::DataIO::ReadFieldModule::fileTypeList();
6970
QString selectedFilter;
7071
auto file = QFileDialog::getOpenFileName(this, "Open Field File", dialogDirectory(), QString::fromStdString(types), &selectedFilter);
7172
if (file.length() > 0)

src/Modules/DataIO/ReadField.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Copyright (c) 2011 Scientific Computing and Imaging Institute,
77
University of Utah.
88
9-
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
to deal in the Software without restriction, including without limitation
@@ -28,7 +28,7 @@
2828

2929

3030
///
31-
///@file ReadField.cc
31+
///@file ReadField.cc
3232
///@brief Read a persistent field from a file
3333
///
3434
///@author
@@ -56,19 +56,21 @@ class ReadField : public GenericReader<FieldHandle> {
5656
#endif
5757

5858
ReadFieldModule::ReadFieldModule()
59-
: my_base("ReadField", "DataIO", "SCIRun", "Field")
59+
: my_base("ReadField", "DataIO", "SCIRun", "Field")
6060
//gui_filename_base_(get_ctx()->subVar("filename_base"), ""),
6161
//gui_number_in_series_(get_ctx()->subVar("number_in_series"), 0),
6262
//gui_delay_(get_ctx()->subVar("delay"), 0)
6363
{
6464
INITIALIZE_PORT(Field);
65+
}
6566

67+
std::string ReadFieldModule::fileTypeList()
68+
{
6669
FieldIEPluginManager mgr;
67-
auto types = makeGuiTypesListForImport(mgr);
68-
get_state()->setValue(Variables::FileTypeList, types);
70+
return makeGuiTypesListForImport(mgr);
6971
}
7072

71-
bool ReadFieldModule::call_importer(const std::string& filename, FieldHandle& fHandle)
73+
bool ReadFieldModule::call_importer(const std::string& filename, FieldHandle& fHandle)
7274
{
7375
///@todo: how will this work via python? need more code to set the filetype based on the extension...
7476
FieldIEPluginManager mgr;
@@ -83,14 +85,14 @@ bool ReadFieldModule::call_importer(const std::string& filename, FieldHandle& fH
8385

8486
void
8587
ReadFieldModule::execute()
86-
{
88+
{
8789
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
88-
if (gui_types_.changed() || gui_filetype_.changed()) inputs_changed_ = true;
90+
if (gui_types_.changed() || gui_filetype_.changed()) inputs_changed_ = true;
8991
#endif
9092
my_base::execute();
9193
}
9294

93-
bool ReadFieldModule::useCustomImporter(const std::string& filename) const
95+
bool ReadFieldModule::useCustomImporter(const std::string& filename) const
9496
{
9597
return boost::filesystem::extension(filename) != ".fld";
96-
}
98+
}

src/Modules/DataIO/ReadField.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
namespace SCIRun {
4040
namespace Modules {
4141
namespace DataIO {
42-
42+
4343
class SCISHARE ReadFieldModule : public GenericReader<FieldHandle, FieldPortTag>
4444
{
4545
public:
@@ -49,8 +49,10 @@ namespace DataIO {
4949
virtual void setStateDefaults() {}
5050
virtual bool useCustomImporter(const std::string& filename) const override;
5151
virtual bool call_importer(const std::string& filename, FieldHandle& handle) override;
52-
52+
5353
OUTPUT_PORT(0, Field, LegacyField);
54+
55+
static std::string fileTypeList();
5456
};
5557

5658
}}}

0 commit comments

Comments
 (0)