Skip to content

Commit e842c56

Browse files
committed
Working on input settings
1 parent 4c65037 commit e842c56

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

src/Dataflow/Engine/Controller/PythonImpl.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ namespace
190190
return port_ ? port_->get_portname() : "<Null>";
191191
}
192192

193+
virtual std::string id() const override
194+
{
195+
return port_ ? port_->id().toString() : "<Null>";
196+
}
197+
193198
virtual std::string type() const override
194199
{
195200
return port_ ? port_->get_typename() : "<Null>";
@@ -287,6 +292,10 @@ namespace
287292
if (port != ports_.end())
288293
return *port;
289294

295+
port = std::find_if(ports_.begin(), ports_.end(), [&](boost::shared_ptr<PyPortImpl> p) { return name == p->id(); });
296+
if (port != ports_.end())
297+
return *port;
298+
290299
std::cerr << "Could not find port with name " << name << " on module " << modId_.id_ << std::endl;
291300
PyErr_SetObject(PyExc_KeyError, boost::python::object(name).ptr());
292301
throw boost::python::error_already_set();

src/Dataflow/Engine/Python/NetworkEditorPythonInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace SCIRun
7979
public:
8080
virtual ~PyPort() {}
8181
virtual std::string name() const = 0;
82+
virtual std::string id() const = 0;
8283
virtual std::string type() const = 0;
8384
virtual bool isInput() const = 0;
8485
virtual void connect(const PyPort& other) const = 0;

src/ExampleNets/pythonScripts/multipleStringOutputs.srn5

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@
4444
</module>
4545
<state>
4646
<stateMap>
47-
<count>12</count>
47+
<count>13</count>
4848
<item_version>0</item_version>
49+
<item>
50+
<first>
51+
<name>InputString:0</name>
52+
</first>
53+
<second>
54+
<name>InputString:0</name>
55+
<value>
56+
<which>2</which>
57+
<value>StringInput1</value>
58+
</value>
59+
</second>
60+
</item>
4961
<item>
5062
<first>
5163
<name>NumberOfRetries</name>
@@ -78,7 +90,7 @@
7890
<name>PythonCode</name>
7991
<value>
8092
<which>2</which>
81-
<value>sIn = scirun_get_module_input_value_by_index(&quot;InterfaceWithPython:1&quot;, 2)
93+
<value>sIn = scirun_get_module_input_value(&quot;InterfaceWithPython:1&quot;, &quot;InputString:0&quot;)
8294
s1 = sIn + &quot; from python 1!&quot;
8395
s2 = sIn + &quot; from python 2!&quot;
8496
s3 = sIn + &quot; from python 3!&quot;</value>

src/Modules/Python/InterfaceWithPython.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ std::vector<AlgorithmParameterName> InterfaceWithPython::outputNameParameters()
9999
Parameters::PythonOutputString1Name, Parameters::PythonOutputString2Name, Parameters::PythonOutputString3Name };
100100
}
101101

102-
std::string InterfaceWithPython::convertInputOutputSyntax(const std::string& code) const
102+
std::string InterfaceWithPython::convertOutputSyntax(const std::string& code) const
103103
{
104104
auto outputVarsToCheck = outputNameParameters();
105105

@@ -125,6 +125,19 @@ std::string InterfaceWithPython::convertInputOutputSyntax(const std::string& cod
125125
return code;
126126
}
127127

128+
std::string InterfaceWithPython::convertInputSyntax(const std::string& code) const
129+
{
130+
for (const auto& port : inputPorts())
131+
{
132+
if (port->nconnections() > 0)
133+
{
134+
auto inputName = get_state()->getValue(Name(port->id().toString())).toString();
135+
std::cout << "FOUND INPUT VARIABLE NAME: " << inputName << " for port " << port->id().toString() << std::endl;
136+
}
137+
}
138+
return code;
139+
}
140+
128141
void InterfaceWithPython::execute()
129142
{
130143
auto state = get_state();
@@ -138,7 +151,7 @@ void InterfaceWithPython::execute()
138151
boost::split(lines, code, boost::is_any_of("\n"));
139152
for (const auto& line : lines)
140153
{
141-
convertedCode << convertInputOutputSyntax(line) << "\n";
154+
convertedCode << convertInputSyntax(convertOutputSyntax(line)) << "\n";
142155
}
143156

144157
//std::cout << "HERE IS CODE:\n\n" << convertedCode.str() << std::endl;

src/Modules/Python/InterfaceWithPython.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ namespace SCIRun
8989
static std::vector<Core::Algorithms::AlgorithmParameterName> outputNameParameters();
9090
private:
9191
static Core::Thread::Mutex lock_;
92-
std::string convertInputOutputSyntax(const std::string& code) const;
92+
std::string convertInputSyntax(const std::string& code) const;
93+
std::string convertOutputSyntax(const std::string& code) const;
9394
};
9495

9596
}

0 commit comments

Comments
 (0)