9#include "PipelineApplication.h"
11#include "IException.h"
12#include "Application.h"
123 const QString &outNameModifier,
const QString &outFileExtension) {
164 if(modString ==
"") {
165 string msg =
"Can not add empty branch to pipeline";
184 for(
int outBranch =
p_outBranches.size() - 1; outBranch >= 0; outBranch --) {
195 for(
unsigned int inBranch = 0; inBranch <
p_inBranches.size(); inBranch ++) {
213 if(ui.WasEntered(inputParamName)) {
231 if(ui.WasEntered(inputParamName)) {
247 for(
unsigned int i = 0; !added && i <
p_params.size(); i++) {
317 bool needList =
false;
333 if(!runOnce &&
p_input.size() == 1) {
338 for(
int param = 0; param < (int)
p_params.size() && runOnce; param++) {
346 for(
int branch = 0; branch < (int)
p_inBranches.size(); branch ++) {
347 if(runOnce && branch > 0) {
352 QString tmpBranch(branch);
370 needList = (inputParam.IsSpecial() && inputParam.Special() ==
LastAppOutputList);
372 for(
int param = 0; param < (int)
p_params.size() && !needList; param++) {
379 QString listName = outputFile;
381 if(listName.isEmpty()) {
389 params =
">>LIST " + input +
" ";
393 while(prev != NULL && infile < (
int)
p_inBranches.size()) {
394 for(
int i = 0; i < (int)prev->OutputBranches().size(); i++) {
395 if(prev->BranchEnabled(i)) {
396 params +=
" " + prev->GetOutputs()[i];
400 prev = prev->Previous();
432 for(
unsigned int outBranch = 0; outBranch <
p_outBranches.size(); outBranch ++) {
434 bool outputSet =
false;
444 for(
unsigned int outParam = 0; outParam <
p_output.size(); outParam++) {
445 if(
p_output[outParam].AppliesToBranch(outBranch)) {
449 QString message =
"Application [" +
Name() +
"] in the pipeline branches with an ";
450 message +=
"output parameter for each branch, but branch [" +
p_outBranches[outBranch];
451 message +=
"] has multiple output files specified.";
460 QString message =
"Application [" +
Name() +
"] in the pipeline branches with an ";
461 message +=
"output parameter for each branch, but branch [" +
p_outBranches[outBranch];
462 message +=
"] has no output files specified.";
468 bool foundBranch =
false;
471 for(
unsigned int outputParam = 0; outputParam <
p_output.size(); outputParam++) {
472 if(
p_output[outputParam].AppliesToBranch(branch)) {
473 params +=
" " +
p_output[0].Name() +
"=\"" + outputFile +
"\"";
478 if(!foundBranch)
continue;
484 if(
p_params[i].AppliesToBranch(branch)) {
492 params +=
" " +
p_params[i].Name() +
"=\"" + listFile +
"\"";
497 if(inputFile.isEmpty()) {
498 QString message =
"There was a problem with calculating the inputs for program [" +
Name();
499 message +=
"]. Please verify your program is not setting outputs for branches that ";
500 message +=
"don't have input.";
526 if(branch < (
int)prev->GetOutputs().size() && prev->BranchEnabled(branch)) {
527 file = prev->GetOutputs()[branch];
530 while (prev != NULL && file==
"") {
531 if(prev->Branches()){
532 if (!prev->BranchEnabled(branch)) {
533 string msg =
"Application branches but branch is disabled";
549 if(prev->BranchEnabled(branch)) {
550 if(branch < (
int)prev->GetOutputs().size()) {
551 file = prev->GetOutputs()[branch];
556 prev = prev->Previous();
564 if (file.isEmpty()) {
571 for(
int i = 0; i < (int)
p_input.size(); i++) {
572 if(
p_input[i].AppliesToBranch(branch) &&
p_input[i].IsSpecial()) {
596 bool usedBranch =
false;
597 unsigned int usedBranchIndex = 0;
598 unsigned int numUsedBranches = 0;
600 for(
unsigned int outputBranch = 0; outputBranch <
p_outBranches.size(); outputBranch++) {
601 bool outBranchUsed =
false;
603 for(
unsigned int outputParam = 0; outputParam <
p_output.size(); outputParam ++) {
604 if(
p_output[outputParam].AppliesToBranch(outputBranch)) {
605 outBranchUsed =
true;
610 if(outputBranch < (
unsigned int)branch) {
614 if((
unsigned int)branch == outputBranch) {
622 if(!usedBranch)
return "";
626 outputFile = outFolder +
"/" +
630 outputFile = outFolder +
"/" +
647 if(
p_outputs.size() == usedBranchIndex) {
665 outputFile = realOut;
670 if(
p_outputs.size() == usedBranchIndex) {
734 for(
int i = 0; i < (int)
p_input.size(); i++) {
735 if(
p_input[i].AppliesToBranch(branch)) {
741 QString msg =
"Application [" +
Name() +
"] in the pipeline does not have an input for branch [" +
p_inBranches[branch] +
"]";
745 QString msg =
"Application [" +
Name() +
"] in the pipeline does not have an input";
764 while(!found && branchIndex < (
int)
p_inBranches.size()) {
785 QString msg =
"Branch [" + name +
"] does not exist in the pipeline application [" +
Name() +
"]";
803 for(
int i = 0; i < (int)
p_outputs.size(); i++) {
static UserInterface & GetUserInterface()
Returns the UserInterface object.
File name manipulation and expansion.
QString path() const
Returns the path of the file name.
QString baseName() const
Returns the name of the file without the path and without extensions.
@ Programmer
This error is for when a programmer made an API call that was illegal.
This class represents one application in the pipeline.
void SetVirtualBands(std::vector< QString > bands)
Set the virtual bands that this application is to apply.
bool Merges()
Returns true if this application does merge branches (multiple input branches, one output)
std::vector< bool > p_enableBranch
Branch enabled/disabled.
const QString & Name() const
Get the name of this pipeline application.
Pipeline * GetPipeline()
Returns the pipeline.
NameModifierType
This is used for branches.
std::vector< QString > p_outBranches
Output branches.
QString p_outputExtension
Output file name extension.
PipelineApplication * Previous() const
This returns the last enabled pipeline application or null.
QString CalculateOutputFile(int branch)
This method calculates the output file for the specified branch.
bool p_supportsVirtualBands
This application supports virtual bands?
bool SupportsVirtualBands()
Returns true if virtual bands are supported.
QString p_outputMod
Output file name modifier.
std::vector< QString > p_virtualBands
Virtual bands string to add (empty if none)
Pipeline * p_pipeline
The pipeline.
QString GetRealLastOutput(bool skipOne=false)
This method is used to calculate the value for CustomParameterValue::LastOutput.
bool BranchEnabled(int branch)
Check whether a branch is enabled given branch index.
std::vector< QString > p_paramString
Built parameter strings.
bool p_enabled
This application enabled?
bool p_continue
Continue the pipeline execution even if an error is encountered by this app.
std::vector< PipelineParameter > p_input
Input parameters.
PipelineApplication * Next() const
This returns the next enabled pipeline application or null.
bool FutureOutputFileCreated()
Returns true if a future application creates output.
void AddParameter(const QString &inputParamName, const QString &appParamName)
This method adds knowledge of a parameter to the application.
void BuildParamString()
This method calculates the inputs, outputs and necessary calls to this program for the pipeline.
PipelineApplication * p_next
Next pipeline application.
std::vector< PipelineParameter > p_output
Output parameters.
CustomParameterValue
This is used to set custom values that must be calculated on the fly.
@ LastAppOutputListNoMerge
A list of files from the last run application's output.
@ LastOutput
The very last output file. Do not use this for input parameters if it's not necessary,...
@ LastAppOutputList
A list of files from the last run application's output.
QString CalculateInputFile(int branch)
This method calculates the input file for the specified branch.
PipelineApplication(QString appName, Pipeline *pipe)
Constructs the first pipeline application.
const bool & Enabled() const
Returns true if this program will be run.
void AddBranch(const QString &modString, NameModifierType type)
This method adds branch to this program.
std::vector< QString > & GetOutputs()
This returns this application's output files. Only valid after BuildParamString is called.
PipelineApplication * p_previous
Previous pipeline application.
PipelineParameter & GetInputParameter(int branch)
This gets the input parameter for the specified branch.
std::vector< PipelineParameter > p_params
Regular parameters.
QString p_name
Name of this application.
void AddConstParameter(const QString &appParamName, const QString &appParamValue)
This method adds a parameter to this application with a known value (does not get it from the user in...
bool Branches()
Return true is this application does branch (one input branch, multiple output)
void SetOutputParameter(const QString &outputParamName, const QString &outNameModifier, const QString &outFileExtension="cub")
Set the output parameter for this application and it's naming convention.
std::vector< QString > TemporaryFiles()
This method returns a list of the temporary files generated by this program.
bool LastApplicationWithOutput()
Returns true if this is the last application with output.
void SetNext(PipelineApplication *next)
Link to the next application in the pipeline.
int FindBranch(QString name, bool input=true)
The method, given a string, finds the index of a branch.
void SetInputParameter(const QString &inputParamName, bool supportsVirtualBands)
Set the input parameter for this application and whether or not this application supports the virtual...
bool StringStartsWith(QString from, QString compare)
String comparison helper, returns true if from starts with compare bool.
std::vector< QString > p_outputs
Actual output files.
std::vector< QString > p_inBranches
Input branches.
const std::vector< QString > & OutputBranches() const
Get the branches this program has as output.
std::vector< QString > p_tempFiles
Actial temporary files.
This class helps to call other Isis Applications in a Pipeline.
int OriginalInputSize()
Returns the number of input files.
int OriginalBranchesSize()
Returns the total number of input branches Original branches = Number of input files * Number of bran...
QString FinalOutput(int branch=0, bool addModifiers=true)
This gets the final output for the specified branch; this is necessary for the PipelineApplications t...
QString TemporaryFolder()
This method returns the user's temporary folder for temporary files.
QString OriginalInput(unsigned int branch)
Returns the initial input file for the pipeline.
std::vector< QString > OriginalBranches()
Returns the names of the original branches of the pipeline (input files * branches if any)
This class represents a parameter of some type for the PipelineApplication.
QString Name()
Name of the parameter.
Command Line and Xml loader, validation, and access.
This is free and unencumbered software released into the public domain.
bool IsSpecial(const double d)
Returns if the input pixel is special.
Namespace for the standard library.