Isis 3 Programmer Reference
Strategy.h
Go to the documentation of this file.
1 #ifndef Strategy_h
2 #define Strategy_h
3 
27 // Qt library
28 #include <QList>
29 #include <QPair>
30 #include <QScopedPointer>
31 #include <QSharedPointer>
32 #include <QString>
33 
34 // SharedResource and ResourceList typedefs
35 #include "Resource.h"
36 #include "PvlObject.h"
37 
38 class QStringList;
39 
40 namespace Isis {
41 
42  class GisGeometry;
43  class Progress;
44 
45 
102  class Strategy {
103 
104  public:
105  Strategy();
106  Strategy(const PvlObject &definition, const ResourceList &globals);
107  virtual ~Strategy();
108 
109  QString name() const;
110  QString type() const;
111  QString description() const;
112 
113  // Not intended to be reimplemented but available for direct calls
114  int apply(ResourceList &resources);
115  int apply(SharedResource &resource);
116 
117  // Inheriting strategies must reimplement either one or both of these
118  virtual int apply(ResourceList &resources, const ResourceList &globals);
119  virtual int apply(SharedResource &resource, const ResourceList &globals);
120 
121  unsigned int totalProcessed() const;
122 
123  protected:
126 
127  // For default constructions
128  Strategy(const QString &name, const QString &type);
129 
130  void setName(const QString &name);
131  void setType(const QString &type);
132 
135  const ResourceList &globals) const;
136  const PvlObject &getDefinition() const;
138 
139 
140  void setApplyToDiscarded();
141  bool isApplyToDiscarded() const;
142  void setDoNotApplyToDiscarded(); // default
143 
144  int applyToResources(ResourceList &resources, const ResourceList &globals);
145  unsigned int processed();
146  void resetProcessed();
147 
148  int countActive(const ResourceList &resources) const;
149  int countDiscarded(const ResourceList &resources) const;
151  const QString &name) const;
152 
153  QString findReplacement(const QString &target, const ResourceList &globals,
154  const int &index = 0,
155  const QString &defValue = "") const;
156  QStringList qualifiers(const QString &keyspec,
157  const QString &delimiter = "::") const;
158  QString scanAndReplace(const QString &input, const QString &target,
159  const QString &replacement) const;
160  QString translateKeywordArgs(const QString &value,
161  const ResourceList &globals,
162  const QString &defValue = "") const;
163  QString processArgs(const QString &value, const QStringList &argKeys,
164  const ResourceList &globals,
165  const QString &defValue = "") const;
166 
167  void propagateKeys(SharedResource &source, SharedResource &target) const;
168  SharedResource composite(SharedResource &resourceA, SharedResource &resourceB,
169  const QPair<QString, QString> &keySuffix = qMakePair(QString("A"),QString("B"))) const;
170  bool importGeometry(SharedResource &resource,
171  const ResourceList &globals) const;
172 
173  ResourceList activeList(ResourceList &resources) const;
174  void activateList(ResourceList &resources) const;
175  void deactivateList(ResourceList &resources) const;
176  ResourceList copyList(const ResourceList &resources) const;
177  ResourceList cloneList(const ResourceList &resources,
178  const bool &withAssets = false) const;
179 
181  const ResourceList &globals);
182  bool isDebug() const;
183 
184  bool doShowProgress() const;
185  bool initProgress(const int &nsteps = 0, const QString &text = "");
186 
187  static void queryCallback(void *item, void *userdata);
188 
189  QStringList getObjectList(const PvlObject &object) const;
190 
191  template <class STRATEGYLIST, class STRATEGYFACTORY>
192  STRATEGYLIST LoadMinerStrategies(const QString &minerName,
193  const ResourceList &globals) const {
194  STRATEGYFACTORY *factory = STRATEGYFACTORY::instance();
195 
196  STRATEGYLIST miner;
197  QString config = translateKeywordArgs(minerName+"ConfigFile", globals);
198  if ( !config.isEmpty() ) {
199  miner = factory->buildRun(config, globals);
200  }
201  else if ( getDefinition().hasObject(minerName+"Miner") ) {
202  miner = factory->buildRun(getDefinition().findObject(minerName+"Miner"),
203  globals);
204  }
205 
206  return (miner);
207  }
208 
209  private:
221  QString m_name;
225  QString m_type;
229  unsigned int m_total;
236  bool m_debug;
239  QScopedPointer<Progress> m_progress;
240 
241  };
242 
245 
248 
249 } // Namespace Isis
250 
252 
253 #endif
254 
bool initProgress(const int &nsteps=0, const QString &text="")
Initializes strategy progress monitor if requested by user.
Definition: Strategy.cpp:1118
bool m_debug
Indicates whether to print debug messages.
Definition: Strategy.h:236
int apply(ResourceList &resources)
Apply algorithm to resource list.
Definition: Strategy.cpp:242
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:513
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:467
static void queryCallback(void *item, void *userdata)
Important GEOS query callback for class and overlap geometry.
Definition: Strategy.cpp:1066
QString m_type
A string containing the type of strategy.
Definition: Strategy.h:225
ResourceList cloneList(const ResourceList &resources, const bool &withAssets=false) const
Create a clone of a Resource list.
Definition: Strategy.cpp:899
QSharedPointer< PvlObject > SharedPvlObject
Definition for a SharedPvlObject, a shared pointer to a PvlObject.
Definition: Strategy.h:125
int countDiscarded(const ResourceList &resources) const
Counts the number of non-active (i.e.
Definition: Strategy.cpp:423
QString description() const
Return description for the strategy.
Definition: Strategy.cpp:218
void setApplyToDiscarded()
Sets Resource as discarded.
Definition: Strategy.cpp:320
virtual ~Strategy()
Destroys the Strategy object.
Definition: Strategy.cpp:109
void setName(const QString &name)
Allow derived strategies to reset name (mostly for default constructors)
Definition: Strategy.cpp:138
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:494
ResourceList m_globals
A shared pointer to the global Resource of keywords.
Definition: Strategy.h:210
bool doShowProgress() const
Definition: Strategy.cpp:1089
QSharedPointer< Strategy > SharedStrategy
Definition for a SharedStrategy, a shared pointer to a Strategy.
Definition: Strategy.h:244
SharedPvlObject m_definition
A shared pointer to the PvlObject that defines the strategy.
Definition: Strategy.h:216
Q_DECLARE_METATYPE(Isis::Cube *)
This allows Cube *&#39;s to be stored in a QVariant.
unsigned int totalProcessed() const
Accessor for the total number of resources processed.
Definition: Strategy.cpp:311
QScopedPointer< Progress > m_progress
Progress percentage monitor.
Definition: Strategy.h:239
void setType(const QString &type)
Allow derived strategies to reset type (mostly for default constructors)
Definition: Strategy.cpp:150
QString name() const
Accessor method to get the name of the strategy.
Definition: Strategy.cpp:118
ResourceList getGlobals(SharedResource &myGlobals, const ResourceList &globals) const
Definition: Strategy.cpp:175
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:650
bool isDebug() const
An accessor method so that inherited classes can determine whether to print debug messages for this o...
Definition: Strategy.cpp:1080
Provides a flat map of PvlKeywords.
Definition: PvlFlatMap.h:236
QString type() const
Accessor method to get the type of strategy.
Definition: Strategy.cpp:128
void deactivateList(ResourceList &resources) const
Deactivate all resources contained in the resource list.
Definition: Strategy.cpp:844
PvlFlatMap getDefinitionMap() const
Returns the keyword definitions found in the Strategy object.
Definition: Strategy.cpp:202
bool m_applyDiscarded
Indicates whether to apply strategy to discarded resources.
Definition: Strategy.h:233
int applyToIntersectedGeometry(ResourceList &resources, GisGeometry &geom, const ResourceList &globals)
Identify and apply Strategy to Resources that intersect a geometry.
Definition: Strategy.cpp:946
bool isApplyToDiscarded() const
Accessor for the apply discarded variable.
Definition: Strategy.cpp:332
ResourceList copyList(const ResourceList &resources) const
Make a copy of the resource list that is independently managed.
Definition: Strategy.cpp:871
QList< SharedStrategy > StrategyList
Definition for a StrategyList, a list of SharedStrategy types.
Definition: Strategy.h:247
void setDoNotApplyToDiscarded()
Disables the general application of Strategy algorithm for all Resources regardless of state...
Definition: Strategy.cpp:341
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:441
Strategy()
Constructs default Strategy object of name "Strategy" and type "Counter".
Definition: Strategy.cpp:50
void activateList(ResourceList &resources) const
Activate all resources contained in the resource list.
Definition: Strategy.cpp:832
unsigned int processed()
Increments the total number of resources processed and returns the incremented value.
Definition: Strategy.cpp:381
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:587
ResourceList activeList(ResourceList &resources) const
Get list of all active Resources only - no discarded Resources.
Definition: Strategy.cpp:817
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:539
Strategy - Supports algorithm development.
Definition: Strategy.h:102
void resetProcessed()
Resets the total number of processed resources to zero.
Definition: Strategy.cpp:394
void propagateKeys(SharedResource &source, SharedResource &target) const
Adds the PVL definition keywords from the source to the target.
Definition: Strategy.cpp:610
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
ResourceList getGlobalDefaults() const
Accessor method to get the global defaults.
Definition: Strategy.cpp:161
unsigned int m_total
The total number of resources processed.
Definition: Strategy.h:229
QString m_name
A string containing the name of the strategy.
Definition: Strategy.h:221
Encapsulation class provides support for GEOS-C API.
Definition: GisGeometry.h:67
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
int countActive(const ResourceList &resources) const
Counts the number of active (i.e.
Definition: Strategy.cpp:409
int applyToResources(ResourceList &resources, const ResourceList &globals)
Applies the strategy algorithms to the resources in the given list.
Definition: Strategy.cpp:354
bool importGeometry(SharedResource &resource, const ResourceList &globals) const
Imports a geometry from the given resource.
Definition: Strategy.cpp:721