[Kst] branches/work/kst/portto4/kst/src/libkstapp

Barth Netterfield netterfield at astro.utoronto.ca
Tue Feb 19 16:10:28 CET 2008


SVN commit 777054 by netterfield:

More command line functionality.



 M  +43 -7     commandlineparser.cpp  
 M  +6 -2      commandlineparser.h  
 M  +9 -1      document.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.cpp #777053:777054
@@ -38,6 +38,8 @@
 
   _fileNames.clear();
   _vectors.clear();
+  _plotNames.clear();
+  _plotItems.clear();
 }
 
 
@@ -157,7 +159,7 @@
     DataVectorPtr xv;
     bool found = false;
 
-    // check to see if an identicle vector already exists.  If so, use it.
+    // check to see if an identical vector already exists.  If so, use it.
     for (int i=0; i<_vectors.count(); i++) {
       xv = _vectors.at(i);
       if (field == xv->field()) {
@@ -229,10 +231,43 @@
     _plotItem->update();
 }
 
+void CommandLineParser::createOrFindPlot( const QString plot_name ) {
+    bool found = false;
+    PlotItem *pi;
+
+    // check to see if a plot with this name exists.  If so, use it.
+    for (int i=0; i<_plotItems.count(); i++) {
+      pi = _plotItems.at(i);
+      if (plot_name == pi->name()) {
+        found = true;
+        break;
+      }
+    }
+
+    if (!found) {
+      CreatePlotForCurve *cmd = new CreatePlotForCurve ( true,true );
+      cmd->createItem();
+      pi = static_cast<PlotItem*> ( cmd->item() );
+      pi->setName ( plot_name );
+      _plotNames.append(plot_name);
+      _plotItems.append(pi);
+    }
+    _plotItem = pi;
+}
+
+QString CommandLineParser::kstFileName() {
+  if (_fileNames.size()>0) {
+    return (_fileNames.at(0));
+  } else {
+    return QString();
+  }
+}
+
 bool CommandLineParser::processCommandLine() {
   QString arg, param;
   bool ok=true;
   bool new_fileList=true;
+  bool dataPlotted = false;
 
   while (1) {
     if (_arguments.count()<1) break;
@@ -254,10 +289,7 @@
       _setStringArg(plot_name,i18n("Usage: -P <plotname>\n"));
       _doConsecutivePlots=false;
 
-      CreatePlotForCurve *cmd = new CreatePlotForCurve(true,true);
-      cmd->createItem();
-      _plotItem = static_cast<PlotItem*>(cmd->item());
-      _plotItem->setName(plot_name);
+      createOrFindPlot(plot_name);
     } else if (arg == "-A") {
       _doConsecutivePlots = true;
     } else if (arg == "-d") {
@@ -278,7 +310,7 @@
     } else if (arg == "-x") {
       _setStringArg(_xField,i18n("Usage: -x <xfieldname>\n"));
     } else if (arg == "-e") {
-      _setStringArg(_errorField,i18n("Usage: -P <errorfieldname>\n"));
+      _setStringArg(_errorField,i18n("Usage: -e <errorfieldname>\n"));
     } else if (arg == "-r") {
       _setDoubleArg(&_sampleRate,i18n("Usage: -r <samplerate>\n"));
     } else if (arg == "-y") {
@@ -320,6 +352,7 @@
         }
 
         createCurveInPlot(tag, xv, yv, ev);
+        dataPlotted = true;
       }
 
       _errorField = QString();
@@ -372,6 +405,7 @@
         }
 
         createCurveInPlot(tag, powerspectrum->vX(), powerspectrum->vY(), ev);
+        dataPlotted = true;
       }
       new_fileList = true;
       _overrideStyle = false;
@@ -415,6 +449,7 @@
         }
 
         createCurveInPlot(tag, histogram->vX(), histogram->vY(), ev);
+        dataPlotted = true;
       }
 
       new_fileList = true;
@@ -424,6 +459,7 @@
       _setStringArg(field,i18n("Usage: -z <fieldname>\n"));
       //FIXME: Create the matrix, and the image
       new_fileList = true;
+      dataPlotted = true;
     } else { // arg is not an option... must be a file
       if (new_fileList) { // if the file list has been used, clear it.
         _fileNames.clear();
@@ -432,7 +468,7 @@
       _fileNames.append(arg);
     }
   }
-  return (true);
+  return (dataPlotted);
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.h #777053:777054
@@ -18,7 +18,6 @@
 
 #include <QStringList>
 namespace Kst {
-
 /**
 	@author Barth Netterfield <netterfield at physics.utoronto.ca>
 */
@@ -28,7 +27,7 @@
   ~CommandLineParser();
 
   bool processCommandLine();
-
+  QString kstFileName();
 private:
   bool _doAve;
   bool _doSkip;
@@ -48,6 +47,10 @@
   QStringList _fileNames;
   QStringList _arguments;
   PlotItem *_plotItem;
+  
+  // lists of command line named plot items (and their names).
+  QList<PlotItem*> _plotItems;
+  QStringList _plotNames;
 
   DataVectorList _vectors;
 
@@ -58,6 +61,7 @@
   void _setStringArg(QString &arg, QString Message);
   void usage(QString Message = "");
   DataVectorPtr createOrFindDataVector(QString field, DataSourcePtr ds);
+  void createOrFindPlot(const QString tagname);
   void createCurveInPlot(const ObjectTag &tag, VectorPtr xv, VectorPtr yv, VectorPtr ev=0);
 };
 
--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #777053:777054
@@ -131,7 +131,15 @@
 bool Document::initFromCommandLine() {
   CommandLineParser P(this);
 
-  return(P.processCommandLine());
+  bool dataPlotted = P.processCommandLine();
+
+  if (!dataPlotted) {
+    QString kstfile = P.kstFileName();
+    if (!kstfile.isEmpty()) {
+      dataPlotted = open(kstfile);
+    }
+  }
+  return(true);
 }
 
 bool Document::open(const QString& file) {


More information about the Kst mailing list