Isis 3 Programmer Reference
Strategy.h
1 #ifndef Strategy_h
2 #define Strategy_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 // Qt library
11 #include <QList>
12 #include <QPair>
13 #include <QScopedPointer>
14 #include <QSharedPointer>
15 #include <QString>
16 
17 // SharedResource and ResourceList typedefs
18 #include "Resource.h"
19 #include "PvlObject.h"
20 
21 class QStringList;
22 
23 namespace Isis {
24 
25  class GisGeometry;
26  class Progress;
27 
28 
85  class Strategy {
86 
87  public:
88  Strategy();
89  Strategy(const PvlObject &definition, const ResourceList &globals);
90  virtual ~Strategy();
91 
92  QString name() const;
93  QString type() const;
94  QString description() const;
95 
96  // Not intended to be reimplemented but available for direct calls
97  int apply(ResourceList &resources);
98  int apply(SharedResource &resource);
99 
100  // Inheriting strategies must reimplement either one or both of these
101  virtual int apply(ResourceList &resources, const ResourceList &globals);
102  virtual int apply(SharedResource &resource, const ResourceList &globals);
103 
104  unsigned int totalProcessed() const;
105 
106  protected:
109 
110  // For default constructions
111  Strategy(const QString &name, const QString &type);
112 
113  void setName(const QString &name);
114  void setType(const QString &type);
115 
118  const ResourceList &globals) const;
119  const PvlObject &getDefinition() const;
121 
122 
123  void setApplyToDiscarded();
124  bool isApplyToDiscarded() const;
125  void setDoNotApplyToDiscarded(); // default
126 
127  int applyToResources(ResourceList &resources, const ResourceList &globals);
128  unsigned int processed();
129  void resetProcessed();
130 
131  int countActive(const ResourceList &resources) const;
132  int countDiscarded(const ResourceList &resources) const;
134  const QString &name) const;
135 
136  QString findReplacement(const QString &target, const ResourceList &globals,
137  const int &index = 0,
138  const QString &defValue = "") const;
139  QStringList qualifiers(const QString &keyspec,
140  const QString &delimiter = "::") const;
141  QString scanAndReplace(const QString &input, const QString &target,
142  const QString &replacement) const;
143  QString translateKeywordArgs(const QString &value,
144  const ResourceList &globals,
145  const QString &defValue = "") const;
146  QString processArgs(const QString &value, const QStringList &argKeys,
147  const ResourceList &globals,
148  const QString &defValue = "") const;
149 
150  void propagateKeys(SharedResource &source, SharedResource &target) const;
151  SharedResource composite(SharedResource &resourceA, SharedResource &resourceB,
152  const QPair<QString, QString> &keySuffix = qMakePair(QString("A"),QString("B"))) const;
153  bool importGeometry(SharedResource &resource,
154  const ResourceList &globals) const;
155 
156  ResourceList activeList(ResourceList &resources) const;
157  void activateList(ResourceList &resources) const;
158  void deactivateList(ResourceList &resources) const;
159  ResourceList copyList(const ResourceList &resources) const;
160  ResourceList cloneList(const ResourceList &resources,
161  const bool &withAssets = false) const;
162 
164  const ResourceList &globals);
165  bool isDebug() const;
166 
167  bool doShowProgress() const;
168  bool initProgress(const int &nsteps = 0, const QString &text = "");
169 
170  static void queryCallback(void *item, void *userdata);
171 
172  QStringList getObjectList(const PvlObject &object) const;
173 
174  template <class STRATEGYLIST, class STRATEGYFACTORY>
175  STRATEGYLIST LoadMinerStrategies(const QString &minerName,
176  const ResourceList &globals) const {
177  STRATEGYFACTORY *factory = STRATEGYFACTORY::instance();
178 
179  STRATEGYLIST miner;
180  QString config = translateKeywordArgs(minerName+"ConfigFile", globals);
181  if ( !config.isEmpty() ) {
182  miner = factory->buildRun(config, globals);
183  }
184  else if ( getDefinition().hasObject(minerName+"Miner") ) {
185  miner = factory->buildRun(getDefinition().findObject(minerName+"Miner"),
186  globals);
187  }
188 
189  return (miner);
190  }
191 
192  private:
204  QString m_name;
208  QString m_type;
212  unsigned int m_total;
219  bool m_debug;
222  QScopedPointer<Progress> m_progress;
223 
224  };
225 
228 
231 
232 } // Namespace Isis
233 
235 
236 #endif
237 
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::Strategy::processArgs
QString processArgs(const QString &value, const QStringList &argKeys, const ResourceList &globals, const QString &defValue="") const
Processes the given string value using the given argument list, resource and default resource.
Definition: Strategy.cpp:570
Isis::Strategy::initProgress
bool initProgress(const int &nsteps=0, const QString &text="")
Initializes strategy progress monitor if requested by user.
Definition: Strategy.cpp:1101
QList< SharedResource >
Isis::Strategy::activeList
ResourceList activeList(ResourceList &resources) const
Get list of all active Resources only - no discarded Resources.
Definition: Strategy.cpp:800
Isis::Strategy::deactivateList
void deactivateList(ResourceList &resources) const
Deactivate all resources contained in the resource list.
Definition: Strategy.cpp:827
Isis::PvlFlatMap
Provides a flat map of PvlKeywords.
Definition: PvlFlatMap.h:218
Isis::Strategy::cloneList
ResourceList cloneList(const ResourceList &resources, const bool &withAssets=false) const
Create a clone of a Resource list.
Definition: Strategy.cpp:882
Isis::Strategy::copyList
ResourceList copyList(const ResourceList &resources) const
Make a copy of the resource list that is independently managed.
Definition: Strategy.cpp:854
Isis::Strategy::propagateKeys
void propagateKeys(SharedResource &source, SharedResource &target) const
Adds the PVL definition keywords from the source to the target.
Definition: Strategy.cpp:593
Isis::Strategy::getGlobals
ResourceList getGlobals(SharedResource &myGlobals, const ResourceList &globals) const
Definition: Strategy.cpp:158
Isis::Strategy::getGlobalDefaults
ResourceList getGlobalDefaults() const
Accessor method to get the global defaults.
Definition: Strategy.cpp:144
Isis::Strategy::applyToIntersectedGeometry
int applyToIntersectedGeometry(ResourceList &resources, GisGeometry &geom, const ResourceList &globals)
Identify and apply Strategy to Resources that intersect a geometry.
Definition: Strategy.cpp:929
Isis::Strategy::Strategy
Strategy()
Constructs default Strategy object of name "Strategy" and type "Counter".
Definition: Strategy.cpp:33
Isis::Strategy::m_definition
SharedPvlObject m_definition
A shared pointer to the PvlObject that defines the strategy.
Definition: Strategy.h:199
QSharedPointer
Definition: JigsawWorkOrder.h:28
Isis::Strategy::setDoNotApplyToDiscarded
void setDoNotApplyToDiscarded()
Disables the general application of Strategy algorithm for all Resources regardless of state.
Definition: Strategy.cpp:324
Isis::Strategy::processed
unsigned int processed()
Increments the total number of resources processed and returns the incremented value.
Definition: Strategy.cpp:364
QStringList
Isis::Strategy::SharedPvlObject
QSharedPointer< PvlObject > SharedPvlObject
Definition for a SharedPvlObject, a shared pointer to a PvlObject.
Definition: Strategy.h:108
Isis::Strategy::resetProcessed
void resetProcessed()
Resets the total number of processed resources to zero.
Definition: Strategy.cpp:377
Isis::Strategy
Strategy - Supports algorithm development.
Definition: Strategy.h:85
Isis::Strategy::importGeometry
bool importGeometry(SharedResource &resource, const ResourceList &globals) const
Imports a geometry from the given resource.
Definition: Strategy.cpp:704
Isis::Strategy::activateList
void activateList(ResourceList &resources) const
Activate all resources contained in the resource list.
Definition: Strategy.cpp:815
Isis::Strategy::composite
SharedResource composite(SharedResource &resourceA, SharedResource &resourceB, const QPair< QString, QString > &keySuffix=qMakePair(QString("A"), QString("B"))) const
Create a composite Resource from a pair by merging keywords.
Definition: Strategy.cpp:633
Isis::GisGeometry
Encapsulation class provides support for GEOS-C API.
Definition: GisGeometry.h:50
Isis::Strategy::m_progress
QScopedPointer< Progress > m_progress
Progress percentage monitor.
Definition: Strategy.h:222
Isis::Strategy::m_name
QString m_name
A string containing the name of the strategy.
Definition: Strategy.h:204
Isis::Strategy::m_globals
ResourceList m_globals
A shared pointer to the global Resource of keywords.
Definition: Strategy.h:193
Isis::Strategy::applyToResources
int applyToResources(ResourceList &resources, const ResourceList &globals)
Applies the strategy algorithms to the resources in the given list.
Definition: Strategy.cpp:337
Isis::Strategy::isDebug
bool isDebug() const
An accessor method so that inherited classes can determine whether to print debug messages for this o...
Definition: Strategy.cpp:1063
Isis::StrategyList
QList< SharedStrategy > StrategyList
Definition for a StrategyList, a list of SharedStrategy types.
Definition: Strategy.h:230
Isis::Strategy::m_applyDiscarded
bool m_applyDiscarded
Indicates whether to apply strategy to discarded resources.
Definition: Strategy.h:216
Isis::Strategy::countActive
int countActive(const ResourceList &resources) const
Counts the number of active (i.e.
Definition: Strategy.cpp:392
Isis::Strategy::qualifiers
QStringList qualifiers(const QString &keyspec, const QString &delimiter="::") const
Splits the given keyspec string into a list using the given delimiter string.
Definition: Strategy.cpp:477
Isis::Strategy::countDiscarded
int countDiscarded(const ResourceList &resources) const
Counts the number of non-active (i.e.
Definition: Strategy.cpp:406
Isis::Strategy::doShowProgress
bool doShowProgress() const
Definition: Strategy.cpp:1072
Isis::Strategy::m_debug
bool m_debug
Indicates whether to print debug messages.
Definition: Strategy.h:219
Isis::Strategy::findReplacement
QString findReplacement(const QString &target, const ResourceList &globals, const int &index=0, const QString &defValue="") const
Find keyword replacement value in globals list.
Definition: Strategy.cpp:450
Isis::Strategy::apply
int apply(ResourceList &resources)
Apply algorithm to resource list.
Definition: Strategy.cpp:225
Isis::SharedStrategy
QSharedPointer< Strategy > SharedStrategy
Definition for a SharedStrategy, a shared pointer to a Strategy.
Definition: Strategy.h:227
Isis::Strategy::queryCallback
static void queryCallback(void *item, void *userdata)
Important GEOS query callback for class and overlap geometry.
Definition: Strategy.cpp:1049
Isis::Strategy::scanAndReplace
QString scanAndReplace(const QString &input, const QString &target, const QString &replacement) const
Performs a case insensitive scan of the input string for a substring matching the target string and r...
Definition: Strategy.cpp:496
Isis::Strategy::m_type
QString m_type
A string containing the type of strategy.
Definition: Strategy.h:208
QPair
This is free and unencumbered software released into the public domain.
Definition: CubeIoHandler.h:23
Isis::Strategy::getDefinitionMap
PvlFlatMap getDefinitionMap() const
Returns the keyword definitions found in the Strategy object.
Definition: Strategy.cpp:185
Isis::Strategy::m_total
unsigned int m_total
The total number of resources processed.
Definition: Strategy.h:212
Isis::Strategy::~Strategy
virtual ~Strategy()
Destroys the Strategy object.
Definition: Strategy.cpp:92
Isis::Strategy::name
QString name() const
Accessor method to get the name of the strategy.
Definition: Strategy.cpp:101
Isis::Strategy::type
QString type() const
Accessor method to get the type of strategy.
Definition: Strategy.cpp:111
Isis::Strategy::description
QString description() const
Return description for the strategy.
Definition: Strategy.cpp:201
Isis::Strategy::setName
void setName(const QString &name)
Allow derived strategies to reset name (mostly for default constructors)
Definition: Strategy.cpp:121
Isis::Strategy::isApplyToDiscarded
bool isApplyToDiscarded() const
Accessor for the apply discarded variable.
Definition: Strategy.cpp:315
Isis::Strategy::setApplyToDiscarded
void setApplyToDiscarded()
Sets Resource as discarded.
Definition: Strategy.cpp:303
Isis::Strategy::setType
void setType(const QString &type)
Allow derived strategies to reset type (mostly for default constructors)
Definition: Strategy.cpp:133
Isis::Strategy::assetResourceList
ResourceList assetResourceList(const SharedResource &resource, const QString &name) const
Searches the given resource for an asset with the given name and converts it to a ResourceList,...
Definition: Strategy.cpp:424
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(Isis::PlotWindow *)
We have plot windows as QVariant data types, so here it's enabled.
Isis::Strategy::totalProcessed
unsigned int totalProcessed() const
Accessor for the total number of resources processed.
Definition: Strategy.cpp:294
Isis::Strategy::translateKeywordArgs
QString translateKeywordArgs(const QString &value, const ResourceList &globals, const QString &defValue="") const
Translates the arguments of the PVL keyword in the PVL definition object.
Definition: Strategy.cpp:522